Modifications to prince.exe (hex editing)

David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Modifications to prince.exe (hex editing)

Post by David »

4DPlayer wrote: September 16th, 2019, 5:05 pm Is there any place that the red potion bubbles are stored in prince.exe so that they can be edited?
Palette slot 12 (0x0C) is used for their color.
The color of that slot is overridden in PRINCE.EXE, here:

Code: Select all

seg000:027B B8 0C 00                             mov     ax, colors_12_red_pot_blood_flash_hurt
seg000:027E 50                                   push    ax              ; index
seg000:027F B8 38 00                             mov     ax, 38h ; '8'
seg000:0282 50                                   push    ax              ; red
seg000:0283 2B C0                                sub     ax, ax
seg000:0285 50                                   push    ax              ; green
seg000:0286 B8 0C 00                             mov     ax, 0Ch
seg000:0289 50                                   push    ax              ; blue
seg000:028A B8 01 00                             mov     ax, 1           ; RGB(38h,0,0Ch) = #E00030 = red
seg000:028D 50                                   push    ax              ; vsync
seg000:028E 9A DF 92 79 0C                       call    set_pal
You have many choices, pick only one of them:

Note that this color is also used for other things like the red flash or the blood on chompers, so a) and b) are not good if you want to keep those as red.

a) Change the override, similarly to this hack for changing the color of the palace wall patterns.

Search: B8 38 00 50 2B C0 50 B8 0C 00 50
Change: 38 to the red component, 2B to B0, C0 to the green component, 0C to the blue component.
Note that most programs display RGB in the range 00h..FFh (0..255), but PoP uses 00h..3Fh (0..63), so you need to divide the values by 4.

b) Disable the override:

Search: B8 0C 00 50 B8 38
Change: 0C to FF
Then the game will use whatever color is configured in CusPop for slot 12, called "Losing life or die flashing".

c) Make the game use a different palette slot for red potions:

Search: C7 46 CE 00 00 C7 46 CC 0C 00
Change: 0C to a value between 0x00 and 0x0F. See "Set up colours" in CusPop for the possible colors.
You can either use an existing color as-is, or pick an unused slot and change the assigned color.
4DPlayer

Re: Modifications to prince.exe (hex editing)

Post by 4DPlayer »

David wrote: September 21st, 2019, 2:11 pm b) Disable the override:

Search: B8 0C 00 50 B8 38
Change: 0C to FF
Then the game will use whatever color is configured in CusPop for slot 12, called "Losing life or die flashing".

This one sounds the best and easiest. For example, if I set flashing to yellow, the red potion bubbles will be yellow also, which is nice. Thanks, David!
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Modifications to prince.exe (hex editing)

Post by Norbert »

Norbert wrote: September 16th, 2019, 10:59 pmIf you mean the color, see this.
They cannot be edited.
David wrote: September 21st, 2019, 2:11 pmYou have many choices, pick only one of them: [...]
...unless David says otherwise. :)
4DPlayer

Re: Modifications to prince.exe (hex editing)

Post by 4DPlayer »

Norbert wrote: September 21st, 2019, 5:03 pm
Norbert wrote: September 16th, 2019, 10:59 pmIf you mean the color, see this.
They cannot be edited.
David wrote: September 21st, 2019, 2:11 pmYou have many choices, pick only one of them: [...]
...unless David says otherwise. :)
;)
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Modifications to prince.exe (hex editing)

Post by Norbert »

David, you wrote here:
David wrote: July 16th, 2012, 11:21 amA=action
Which is not used, correct? Because each 2-byte number is always 0, and the actions are determined differently (e.g. l5 has its own automatic moves, and l6 reacts to the prince with simulated Shift+forward). And, follow-up question based on the aforementioned, I'm guessing you know/guess it's - was originally intended to contain - an action based on the disassembly?
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Modifications to prince.exe (hex editing)

Post by David »

Norbert wrote: July 17th, 2020, 8:29 pm David, you wrote here:
David wrote: July 16th, 2012, 11:21 amA=action
Which is not used, correct? Because each 2-byte number is always 0, and the actions are determined differently (e.g. l5 has its own automatic moves, and l6 reacts to the prince with simulated Shift+forward).
And, follow-up question based on the aforementioned, I'm guessing you know/guess it's - was originally intended to contain - an action based on the disassembly?
The name "action" is indeed misleading without knowing the inner workings of PoP.
It does not tell the game what the shadow should do when you enter the room.
Instead it is a variable which is (usually) set by the sequence table, to tell which category of actions is a character doing right now.
(Note that this "action" is different from the actions I listed under "Automatic moves" in the same post.)

It's declared here, in char_type: https://github.com/NagyD/SDLPoP/blob/ma ... pes.h#L299
Its possible values are: https://github.com/NagyD/SDLPoP/blob/ma ... pes.h#L396
It is used for example here: https://github.com/NagyD/SDLPoP/blob/ma ... 006.c#L801

The bytes I've shown there are copied into the first 7 bytes of Char here, in do_init_shad(): https://github.com/NagyD/SDLPoP/blob/ma ... g002.c#L41
That's how I know that the "A" column ends up in Char.action.

The name "action" in SDLPoP and the disassembly comes from Mechner's PoP1 notes, page 15. That page also lists the possible values.
On page 17 it's mentioned again, as CharAction.
On page 20, under "Shadow man", CSPS is what I called do_init_shad().
The document says there are 8 bytes of data; in the Apple II version, sequence table index (db stand, etc.) is indeed after the 7 bytes; but in the DOS version and in SDLPoP it's a second parameter of do_init_shad(), called seq_index.

By the way, the action is only a single byte.
The 8th (always zero) byte in the DOS version at the end of the byte arrays is not used.
I'm not sure why are the arrays 8 byte long if only their first 7 bytes are used.
Maybe they were entered into the DOS source as string constants and this added a terminating zero byte?
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Modifications to prince.exe (hex editing)

Post by Norbert »

Thanks for the explanation.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Modifications to prince.exe (hex editing)

Post by Norbert »

Two more questions...
David wrote: July 16th, 2012, 11:21 amD=direction (00=right, FF=left)
Is another possible value 0x56?
I'm asking because right above the actions enumeration is this:

Code: Select all

enum directions {
	dir_0_right = 0x00,
	dir_56_none = 0x56,
	dir_FF_left = -1
};
David wrote: July 16th, 2012, 11:21 amC=column (not really used)
You write it's not really used, but do you know what are the possible values and their effect?
I'm asking because "not really used" is a bit vague, and not the same as not used. I see 0x00 and 0xFF...
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Modifications to prince.exe (hex editing)

Post by David »

Sorry, it seems I forgot to answer this.
Norbert wrote: July 26th, 2020, 5:10 pm
David wrote: July 16th, 2012, 11:21 amD=direction (00=right, FF=left)
Is another possible value 0x56?
Yes, Guard.direction is 0x56 if there is no guard present.
If you use this for the shadow then he won't appear, but any regular guard placed in the shadow's room will still be erased as usual.
Norbert wrote: July 26th, 2020, 5:10 pm
David wrote: July 16th, 2012, 11:21 amC=column (not really used)
You write it's not really used, but do you know what are the possible values and their effect?
I think the column is not used at all, because it's recalculated in every frame from the X coordinate by determine_col().


The row behaves rather strangely as well.

For example, set the level 6 shadow to the top row:
(In v1.0 unpacked) at 0x1D48A write: 0F 51 E8 00 00 00 00 00

The shadow will still appear in the middle row because of the Y coordinate.
Jump over the pit to make the shadow step forward.
The shadow will start falling into the floor, then he lands on the same row where he started.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Modifications to prince.exe (hex editing)

Post by Norbert »

David wrote: April 11th, 2021, 10:55 amSorry, it seems I forgot to answer this.
Well, you're not obligated to answer anything, so no apology necessary. ;)
David wrote: April 11th, 2021, 10:55 amFor example, set the level 6 shadow to the top row:
(In v1.0 unpacked) at 0x1D48A write: 0F 51 E8 00 00 00 00 00
Or, use apoplexy, press F3, and set the relevant row to "1". :)
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1782
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: Modifications to prince.exe (hex editing)

Post by atrueprincefanfrom18 »

Norbert wrote: April 11th, 2021, 11:23 am Or, use apoplexy, press F3, and set the relevant row to "1". :)
It doesn't seem to work... Had you tested it?
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Modifications to prince.exe (hex editing)

Post by Norbert »

atrueprincefanfrom18 wrote: April 11th, 2021, 12:33 pm
Norbert wrote: April 11th, 2021, 11:23 am Or, use apoplexy, press F3, and set the relevant row to "1". :)
It doesn't seem to work... Had you tested it?
Make sure to pick the right game level.
In this case, the row in the "l. 6" (level 6) section of that screen.
User avatar
Shauing
Calif
Calif
Posts: 431
Joined: April 5th, 2018, 10:38 pm
Contact:

Re: Modifications to prince.exe (hex editing)

Post by Shauing »

I'm not sure if this can be done on Apoplexy where you have a wall that has a floor function instead of a wall, or a wall that is empty (meaning you can go through it)? Or graphics have to be changed? If so, what can be used to change the graphics?
NEW UPDATE! Prince Of Persia: 30th Anniversary Port v1.1.5. Download it today!: viewtopic.php?p=29053#p29053
NEW UPDATE! Prince Of Persia: The Queen Of Light v2.6. Download it today! viewtopic.php?p=33174#p33174
dmitry_s
Developer
Developer
Posts: 148
Joined: July 27th, 2021, 7:22 am

Re: Modifications to prince.exe (hex editing)

Post by dmitry_s »

David wrote: July 19th, 2020, 11:16 am I'm not sure why are the arrays 8 byte long if only their first 7 bytes are used.
Maybe they were entered into the DOS source as string constants and this added a terminating zero byte?
I just found this thread and I do find it interesting. Those array bytes are getting copied into the Char (char_type) variable to create a guard of type shadow. Bytes 8 and 9 would have populated fall_x and fall_y fields but the 8th value was probably meant to be some sort of end-of-array value.

In my mod, I was able to make shadow moon walk by assigning 1 into the direction. It flipped sprite images to the left but the forward movement was happening to the right. Jordan Mechner did a great job with frame animations so it looks like it was designed to work that way. There was a side effect to this hack that caused the fall_y speed to be set to some value that caused the shadow to fall, then appear at the top of the screen, then fall again. It might be a good idea to ensure those 2 bytes are set to 0 during a shadow initialization. But for standard use-cases it is not going to be a problem.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Modifications to prince.exe (hex editing)

Post by Norbert »

Shauing wrote: September 12th, 2021, 7:36 am I'm not sure if this can be done on Apoplexy where you have a wall that has a floor function instead of a wall, or a wall that is empty (meaning you can go through it)? Or graphics have to be changed? If so, what can be used to change the graphics?
Press "x" (or Ctrl+click on a tile) to go to the native tiles screen.
It has tiles that only work with SDLPoP/MININIM.
The first tab has all the fake tiles, including floors/spaces that look like walls.
Post Reply