permadeath

xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

permadeath

Post by xhul »

Hello there...

Finally, i just registered.
Actually, i used to be there in the old popuw forums by the alias "the_mad_joob", for those who remember me.
Back in the days, i made a few gfx for pop1, which are currently available in pop1tp.

Now, i decided to use them in a dedicated mod.
I have almost everything.
But still, there is something i'd like to implement, a way to exit the game as soon as the prince dies.
More specifically, and to make it look not dirty, make it happen after the death music has been played, or maybe after the user had pressed a button (I would replace "press button to continue" by something else, then.).
Currently, i have absolutely no idea how to do it, and i must confess i want to avoid having to dig in the executable by myself.
Another tricky way would be to reduce the time to zero when he dies, but i'm not sure what would happen then.

In other words, i'm looking for help from someone who already has a decent knowledge of prince.exe structure.

Thx in advance for your time and long life to this forum =]
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5786
Joined: April 9th, 2009, 10:58 pm

Re: permadeath

Post by Norbert »

xhul wrote:Finally, i just registered.
Well, you were here in 2010 for a moment. :)
I do recognize your old nick from the The Dragon Temple graphics (listed here) and the Endless tomb graphics (listed here).
Your old avatar is still available here.
xhul wrote:In other words, i'm looking for help from someone who already has a decent knowledge of prince.exe structure.
David should see your post sooner or later. ;)
xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: permadeath

Post by xhul »

Yeah, that's me.
I had also designed a custom prince & jaffar, which took me quite some time.
Good to see some old faces =]

EDIT :
I guess i'll probably have to overwrite 2 separate jumps, that normally lead to a level restart.
One when a key is pressed, and the other when the mini-timer ends.
Then, use either an exit interrupt, or a jump to the code that is processed when [Ctrl]+[Q] is pressed.
Sounds quite possible if i manage to find the jump locations...
David
The Prince of Persia
The Prince of Persia
Posts: 2877
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: permadeath

Post by David »

xhul wrote: i want to avoid having to dig in the executable by myself.
Don't worry, I'll help you. :)
xhul wrote: to exit the game as soon as the prince dies
I'm not sure how will players feel about that... It depends on how hard/long the levels are.
xhul wrote: Another tricky way would be to reduce the time to zero when he dies, but i'm not sure what would happen then.
Then you'd see the bad ending, I guess.
It would be more annoying than quitting, because it is shown for a few seconds and you can't interrupt it.
xhul wrote: I guess i'll probably have to overwrite 2 separate jumps, that normally lead to a level restart.
One when a key is pressed, and the other when the mini-timer ends.
When "the mini-timer ends" there is no level restart. Instead, the game is restarted from the intro.

What should happen if the user presses Ctrl-A?
This means two cases: when the kid is alive, and when not.

And what about Ctrl-R, Ctrl-L to reload a saved game? (Or do you want to disable save/load?)
xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: permadeath

Post by xhul »

Hello David...
David wrote:Don't worry, I'll help you. :)
Sounds pretty great =]
David wrote:I'm not sure how will players feel about that... It depends on how hard/long the levels are.
Actually, my mod will only deal with the original levels.dat.
It will feature a bunch of difficulty levels, including the last one, called "master".
I wanted it to be very hard and i think it should wear its name properly =P
David wrote:Then you'd see the bad ending, I guess.
It would be more annoying than quitting, because it is shown for a few seconds and you can't interrupt it.
You always have to consider spare solutions, and what's true in life in general somehow particularly applies to hacking.
I was just wondering if you see the text or not, great you have that info.
Maybe the ultimate spare option then XD
David wrote:When "the mini-timer ends" there is no level restart. Instead, the game is restarted from the intro.
Oh, you're right, i forgot that.
So in my case, that should make things even easier =]
David wrote:What should happen if the user presses Ctrl-A?
This means two cases: when the kid is alive, and when not.
Nice catch.
I guess i need to find a way to disable it, cause it would indeed represent a significant way to cheat.
I think the easiest way would be to disable it in both cases, if possible.
Anyway, i don't think the game bothers to handle it differently in the two cases, does it ?
If things are logically done, there must be a jump to some kind of level initialisation address somewhere...
David wrote:And what about Ctrl-R, Ctrl-L to reload a saved game? (Or do you want to disable save/load?)
[Ctrl]+[R] would be considered a suicide.
Hopefully, pop handles free will.
No need to worry about that.
[Ctrl]+[L] will do nothing in that difficulty, since i intend to disable [Ctrl]+[G].
[Shift]+[L] will be disabled as well.

So, if we sum up things, here is what i need :
> after any form of death, redirect the button pressing to a program exit
> disable level restart ([Ctrl]+[A])
I am using packed 1.4, and i really hope it's not too hard to decypher...
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5786
Joined: April 9th, 2009, 10:58 pm

Re: permadeath

Post by Norbert »

xhul wrote:So, if we sum up things, here is what i need :
> after any form of death, redirect the button pressing to a program exit
> disable level restart ([Ctrl]+[A])
I am using packed 1.4, and i really hope it's not too hard to decypher...
CusPop can already assist you in changing the "Restart level key" from "Control+A" to "None (deactivate)".
I guess CusPop could use is an additional entry for the "Press Button to Continue" 'any key' in that section.
xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: permadeath

Post by xhul »

Nice !
CusPop seems to have been way improved since the last time i checked it, a few years back.
Thx a lot for the link =]

I only miss a way to redirect the level restart after death, then.
I was thinking, maybe a jump to the intro sequence would be more appropriate than just being kicked out of the game (less frustrating and faster to do a new attempt).
David
The Prince of Persia
The Prince of Persia
Posts: 2877
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: permadeath

Post by David »

Norbert wrote: Well, you were here in 2010 for a moment.
@xhul, why did you register again with a new name? Did you forget about the old one?
xhul wrote: > after any form of death, redirect the button pressing to a program exit
This is the part that restarts the level it you press enter (or shift) when the kid died: (from the disassembly)

Code: Select all

seg000:0538 83 3E 7E 4F 00                       cmp     rem_min, 0
seg000:053D 74 19                                jz      loc_558
seg000:053F 80 3E 65 43 06                       cmp     kid_alive, 6
seg000:0544 7E 12                                jle     loc_558
seg000:0546 80 3E C6 4C 00                       cmp     control_shift, 0
seg000:054B 75 06                                jnz     loc_553
seg000:054D 83 7E FA 0D                          cmp     [bp+key], 0Dh   ; enter
seg000:0551 75 05                                jnz     loc_558
seg000:0553                      loc_553:
seg000:0553 C7 46 FA 01 00                       mov     [bp+key], 1     ; ctrl-a
seg000:0558                      loc_558:
seg000:0558 83 7E FA 00                          cmp     [bp+key], 0
seg000:055C 75 05                                jnz     loc_563
seg000:055E 2B C0                                sub     ax, ax
seg000:0560 E9 84 03                             jmp     return
Search C7 46 FA 01 00 83 7E FA 00, replace 01 with the code of the key whose action you want instead.
The default, 01, is the code of Ctrl-A.
Ctrl-R is 12.
Ctrl-Q would be 11, but it does not work here, because Ctrl-Q is checked elsewhere.
However, it might be possible to replace the whole MOV with a quit.
xhul wrote: > disable level restart ([Ctrl]+[A])
xhul wrote: [Ctrl]+[L] will do nothing in that difficulty, since i intend to disable [Ctrl]+[G].
[Shift]+[L] will be disabled as well.
These can be done with CusPoP.
Though you might need to disable Ctrl-L in case someone copies a prince.sav from elsewhere. :)
(Ctrl-L is not in CusPoP.)
And of course disable cheat mode.
xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: permadeath

Post by xhul »

Wow, that was fast !
I see the code has already some kind of dedicated events related to keys, great (only one byte to overwrite is nice).
FAT THX !
Be sure that if my prog allows a credit section, you'll be there =]
Also, thx for the [Ctrl]+[L] thing, i didn't think of that potential breach. Nice catch again.
About my old pseudo, i wasn't sure i had created one, and didn't take enough time to verify that.
It's fun to read me back in 2010 XD
I'm gonna try everything as soon as possible, and i'll leave a feedback here.
You rock.
xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: permadeath

Post by xhul »

I took a more in-depth look at cuspop (web version), and it appears that [Ctrl]+[L] isn't handled =/
I guess there's a reason for that (must be an annoying hack or something).

Also, i wanted to completely disable cheats and it seems cuspop only allow to modify the parameter name.
I tried an empty field and didn't get any error.
No sure it didn't break anything, though.
David
The Prince of Persia
The Prince of Persia
Posts: 2877
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: permadeath

Post by David »

xhul wrote: I took a more in-depth look at cuspop (web version), and it appears that [Ctrl]+[L] isn't handled =/
I guess there's a reason for that (must be an annoying hack or something).
Probably because it is handled at a different place than the other keys (because it can be used at other times; actually it is handled at *two* places).

Disabling Ctrl-L:
Note 1: You could use other values if you wanted to assign this functionality to another key.
Note 2: Ctrl-L will be treated just like any other key, i.e. load first level. (But it's possible to disable that.)

Part 1: (everywhere except the demo level)

Code: Select all

seg000:04F2 83 7E FA 0C                          cmp     [bp+key], 0Ch   ; ctrl-l
seg000:04F6 75 0B                                jnz     loc_503
seg000:04F8 0E                                   push    cs
seg000:04F9 E8 3C 19                             call    near ptr load_game
seg000:04FC 0B C0                                or      ax, ax
seg000:04FE 75 09                                jnz     loc_509
seg000:0500 E9 E4 03                             jmp     return
Search 83 7E FA 0C 75 0B, replace 0C with FF.
(This is not Alt-255, because FF will be sign-extended to FFFF.)
(If you use 00: shift will load the game!)

Part 2: (demo level)

Code: Select all

seg006:0D05 9A 33 0E 79 0C                       call    key_test_quit
seg006:0D0A 89 46 FE                             mov     [bp+key], ax
seg006:0D0D 3D 0C 00                             cmp     ax, 0Ch         ; ctrl-L
seg006:0D10 75 10                                jnz     loc_79D2
seg006:0D12 9A 38 1E 00 00                       call    load_game
seg006:0D17 0B C0                                or      ax, ax          ; did the user press a key while demo?
seg006:0D19 74 2A                                jz      return
Search 89 46 FE 3D 0C 00, replace 0C 00 with FF FF.
(00 00 won't work, because here it means "if no key is pressed".)
xhul wrote: Also, i wanted to completely disable cheats and it seems cuspop only allow to modify the parameter name.
I tried an empty field and didn't get any error.
No sure it didn't break anything, though.
That means that any parameter will activate cheats, because of how parameter checking works:
A parameter is considered matching if it *starts* with the given string.

In Arabian Nightmares, it seems that all cheat keys were disabled one-by-one.
But there is another way to disable cheats:

Disabling cheat mode:

Code: Select all

seg000:0179 B8 7D 00                             mov     ax, offset param_megahit ; "megahit"
seg000:017C 50                                   push    ax              ; param
seg000:017D 9A 54 0E 79 0C                       call    check_param
seg000:0182 3D 01 00                             cmp     ax, 1
seg000:0185 1B C9                                sbb     cx, cx          ; to bool
seg000:0187 41                                   inc     cx
seg000:0188 89 0E 9C 00                          mov     cheats_enabled, cx
Search 3D 01 00 1B C9 41 89 0E, replace 1B C9 41 with B9 00 00.
xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: permadeath

Post by xhul »

A room has already been reserved for you in the credits, thx again =]
I'll create a dedicated topic for my mod as soon as it's finished (should come fast).
But you've been warned, it is old-school =P
xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: permadeath

Post by xhul »

Everything seems to work like a charm, as far as what i've tested.
Looks like i may need one more thing, though.
In one of my difficulties, i would like to turn off auto life regen between levels.
Not sure if it's hard to do or not, but i ask just in case...
David
The Prince of Persia
The Prince of Persia
Posts: 2877
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: permadeath

Post by David »

xhul wrote: i would like to turn off auto life regen between levels.
Disabling HP regeneration:

The game already has a mechanism for disabling HP regeneration between level 12 and 13.
(I called it "seamless". It also disables showing the level number.)
We just have to change it so that it is activated on every level after level 1 (instead of activated by the "seamless" flag).
(Note that showing the level number is checked elsewhere, so it's not affected by this hack.)

Code: Select all

seg003:021F 83 3E 86 58 00                       cmp     seamless, 0
seg003:0224 75 1D                                jnz     loc_4A33
seg003:0226 83 3E 9E 0F 00                       cmp     current_level, 0 ; HP on demo level
seg003:022B 74 08                                jz      loc_4A25
seg003:022D A1 08 46                             mov     ax, hitp_beg_lev
seg003:0230 89 46 FE                             mov     [bp+hitpoints], ax
seg003:0233 EB 05                                jmp     short loc_4A2A
seg003:0235                      loc_4A25:
seg003:0235 C7 46 FE 04 00                       mov     [bp+hitpoints], 4 ; HP on demo level
seg003:023A                      loc_4A2A:
seg003:023A 8B 46 FE                             mov     ax, [bp+hitpoints]
seg003:023D A3 98 4C                             mov     hitp_curr, ax
seg003:0240 A3 F2 5F                             mov     hitp_max, ax
seg003:0243                      loc_4A33:
This hack is different for different versions of PoP:
1.0: Search 83 3E 86 58 00 75 1D, replace with 83 3E 9E 0F 01 7F 1D
1.3: Search 83 3E 78 5A 00 75 1D, replace with 83 3E B0 10 01 7F 1D
1.4: Search 83 3E 4A 58 00 75 1D, replace with 83 3E AA 10 01 7F 1D
(cmp current_level,1 & jg loc_....)

Note: This also disables the setting of HP when loading a saved game. (But you disabled ctrl-L, so it's not a problem.)
---
By the way, are you going to disable the potions level?
I bumped into it while I was testing this hack with PoP 1.4.
xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: permadeath

Post by xhul »

Wow, thanks.
I think i'm good with prince.exe.

If you're interested, here is how it will work in my mod.
Let's spoil a little bit...

DEFAULT CHANGES (all difficulties)

custom graphics : kid.dat , pv.dat , vdungeon.dat , vizier.dat , vpalace.dat

level 15 removed (copy protection)
warping removed ([shift]+[L])
default level palette in all levels
cheating removed ("improved" parameter)
saving removed ([Ctrl]+[G])
loading removed ([Ctrl]+[L])

SPECIFIC CHANGES

soldier : no restrictions (only no save/load compared to the original pop)
knight : no big life potions (levels.dat)
warrior : no small life potions (levels.dat)
lord : no regen between levels (prince.exe)
prince : 1 life at start (prince.exe)
king : permadeath (prince.exe)

All restrictions will be cumulative, so, for example, the last difficulty has all of those at once.
Now, let's just hope all the changes won't interfer with each other...
Additionally, you cannot play a difficulty if you haven't completed the previous one.
With such system, i intend to exploit the "die and retry" aspect of the game as much as possible.
Of course, prince.hof files will be handled separately for each diff.

ABOUT LEVELS.DAT

The idea in this mod was to rediscover the original levels in a different (more difficult) way, in order to actually extend the life of the game.
Only the small & big life potions will be altered (see above).
I was just wondering about something in level 5, though.
Instead of just removing it, i thought of replacing the big pot stoled by the shadow by an empty one.
That way, the shadow animation would still be coherent.
And, in case the player manages to actually drink it, he won't be able to bypass the restriction.
That is probably the best way to handle it "correctly", i guess.

MOD NAME

I thought of many different titles, and finally came up with "king of persia" (i know, not very original, but that fits the whole mod idea so much).
According to my quick web researchs, no mod is already called like that.
There is a user with that name, though.
Post Reply