Modifications to prince.exe (hex editing)

Are you creating new levels/mods for DOS or did you finish your work? Tell us here!

Moderator: English Moderator Team

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

Re: Modifications to prince.exe (hex editing)

Post by David » September 4th, 2013, 10:32 am

Norbert wrote:I would like to disable the mirror reflection in the palace environment.
This will disable the mirror image altogether.
Is it important to keep it on dungeon levels?

Code: Select all

seg003:0798 ; int __pascal far check_mirror()
seg003:0798 check_mirror    proc far                ; CODE XREF: jump_mirror↓P
seg003:0798 
seg003:0798 clip_top        = word ptr -2
seg003:0798 
seg003:0798                 push    bp
seg003:0799                 mov     bp, sp
seg003:079B                 sub     sp, 2
seg003:079E                 cmp     jumped_through_mirror, 0FFFFh
seg003:07A3                 jnz     loc_4F9B
seg003:07A5                 push    cs
seg003:07A6                 call    near ptr jump_through_mirror
seg003:07A9                 jmp     short loc_4FF6
seg003:07AB ; ───────────────────────────────────────────────────────────────────────────
seg003:07AB 
seg003:07AB loc_4F9B:                               ; CODE XREF: check_mirror+B↑j
seg003:07AB                 call    get_tile_at_char
seg003:07B0                 cmp     al, tiles_13_mirror
seg003:07B2                 jnz     loc_4FF6 ; <- here
seg003:07B4                 call    loadkid
seg003:07B9                 call    load_frame
seg003:07BE                 push    cs
seg003:07BF                 call    near ptr check_mirror_image
seg003:07C2                 cmp     byte_1E9FA, 0
seg003:07C7                 jl      loc_4FF6
seg003:07C9                 call    load_frame_to_obj ; from this line: mirror image
seg003:07CE                 call    set_top_rect
seg003:07D3                 mov     al, char_curr_row
seg003:07D6                 cbw
seg003:07D7                 mov     bx, ax
seg003:07D9                 shl     bx, 1
seg003:07DB                 mov     ax, (y_clip+2)[bx]
seg003:07DF                 mov     [bp+clip_top], ax
seg003:07E2                 mov     cl, obj_y
seg003:07E6                 sub     ch, ch
seg003:07E8                 cmp     ax, cx
seg003:07EA                 jnb     loc_4FF6
seg003:07EC                 mov     obj_clip_top, ax
seg003:07EF                 mov     al, char_curr_col
seg003:07F2                 cbw
seg003:07F3                 mov     cl, 5           ; 1<<5=32=width of a tile
seg003:07F5                 shl     ax, cl
seg003:07F7                 add     ax, 9           ; distance of mirror from left edge of tile
seg003:07FA                 mov     obj_clip_left, ax
seg003:07FD                 mov     ax, 4
seg003:0800                 push    ax
seg003:0801                 call    add_objtable
seg003:0806 
seg003:0806 loc_4FF6:                               ; CODE XREF: check_mirror+11↑j
seg003:0806                                         ; check_mirror+1A↑j ...
seg003:0806                 mov     sp, bp
seg003:0808                 pop     bp
seg003:0809                 retf
seg003:0809 check_mirror    endp

Code: Select all

00005188:i55                             push      bp
00005189:i8BEC                           mov       bp,sp
0000518B:i83EC02                         sub (w)   sp,+02
0000518E:i833EA042FF                     cmp (w)   [+42A0],-01
00005193:i7506                           jne       file:0000519B
00005195:i0E                             push      cs
00005196:iE86100                         calln     file:000051FA
00005199:iEB5B                           jmps      file:000051F6
0000519B:i9A0D07CB06                     callf     file:000073BD
000051A0:i3C0D                           cmp       al,0D
000051A2:i7552                           jne       file:000051F6 ; <- here
000051A4:i9A4F04CB06                     callf     file:000070FF
000051A9:i9A5A01CB06                     callf     file:00006E0A
000051AE:i0E                             push      cs
000051AF:iE89900                         calln     file:0000524B
000051B2:i803E1A3D00                     cmp       [+3D1A],00
000051B7:i7C3D                           jl        file:000051F6
000051B9:i9A4824C209                     callf     file:0000C068
000051BE:i9A0705CB06                     callf     file:000071B7
000051C3:iA0273D                         mov       al,[+3D27]
000051C6:i98                             cbw
000051C7:i8BD8                           mov       bx,ax
000051C9:iD1E3                           shl (w)   bx,1
000051CB:i8B879422                       mov       ax,[bx+2294]
000051CF:i8946FE                         mov       [bp-02],ax
000051D2:i8A0E1346                       mov       cl,[+4613]
000051D6:i2AED                           sub       ch,ch
000051D8:i3BC1                           cmp       ax,cx
000051DA:i731A                           jnc       file:000051F6
000051DC:iA3C642                         mov       [+42C6],ax
000051DF:iA0263D                         mov       al,[+3D26]
000051E2:i98                             cbw
000051E3:iB105                           mov       cl,05
000051E5:iD3E0                           shl (w)   ax,cl
000051E7:i050900                         add       ax,0009
000051EA:iA3A642                         mov       [+42A6],ax
000051ED:iB80400                         mov       ax,0004
000051F0:i50                             push      ax
000051F1:i9A8823C209                     callf     file:0000BFA8
000051F6:i8BE5                           mov       sp,bp
000051F8:i5D                             pop       bp
000051F9:iCB                             retf
Search: 3C 0D 75 52, replace 75 with EB

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3139
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Modifications to prince.exe (hex editing)

Post by Norbert » September 4th, 2013, 2:04 pm

Cool, thanks. :)

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

Re: Modifications to prince.exe (hex editing)

Post by David » September 6th, 2013, 9:19 am

To fix this bug with stacked gates: viewtopic.php?p=13913#p13913
(See also here: viewtopic.php?f=68&t=3368)

Code: Select all

seg008:17C1                 mov     ax, gate_bottom_y
seg008:17C4                 add     ax, 12
seg008:17C7                 cmp     ax, draw_main_y
seg008:17CB                 jge     loc_B402
seg008:17CD                 mov     ax, id_chtab_6_environment

; the original target
seg008:17E2 loc_B402:
seg008:17E2                 mov     ax, id_chtab_6_environment
seg008:17E5                 push    ax              ; chtab_id
seg008:17E6                 mov     al, byte ptr tile_table[(12*tiles_4_gate+piece.right_id)]

; the new target
seg008:1822                 mov     ax, id_chtab_6_environment
seg008:1825                 push    ax              ; chtab_id
seg008:1826                 mov     ax, 51

Code: Select all

0000B5E1:iA16C43                         mov       ax,[+436C]
0000B5E4:i050C00                         add       ax,000C
0000B5E7:i3B062643                       cmp       ax,[+4326]
0000B5EB:i7D15                           jnl       file:0000B602 ; the jump
0000B5ED:iB80600                         mov       ax,0006

; the original target
0000B602:iB80600                         mov       ax,0006
0000B605:i50                             push      ax
0000B606:iA0CF25                         mov       al,[+25CF]

; the new target
0000B642:iB80600                         mov       ax,0006
0000B645:i50                             push      ax
0000B646:iB83300                         mov       ax,0033
Search 7D 15 B8 06 00, change 15 to 55
Attachments
gate_bug_before_after.png
gate_bug_before_after.png (4.26 KiB) Viewed 1078 times

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3139
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Modifications to prince.exe (hex editing)

Post by Norbert » September 19th, 2014, 2:51 am

David wrote:Allow triggering of any tile

[...]

search: 83 7E 0C 10 75 18, change 75 18 to 90 90
Out of curiosity, is there any reason you decided to use 75 13 (JNZ five less) instead of 90 90 (see above; NOP NOP) as the 'to value' for CusPop?
Is there any difference between the two? What I mean is, I'm curious why you decided to change your initial solution.
(By the way, apoplexy also uses 75 13, like CusPop.)

zethholyblade
Sheikh
Sheikh
Posts: 38
Joined: September 6th, 2014, 11:04 pm

Re: Modifications to prince.exe (hex editing)

Post by zethholyblade » September 19th, 2014, 6:18 am

Hmm I'm just curious. How do you guys learn and understand this whole thing? It's almost as if you guys were able to read the Matrix or something.

It's really impressive :)

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

Re: Modifications to prince.exe (hex editing)

Post by David » September 19th, 2014, 9:00 am

Norbert wrote:Out of curiosity, is there any reason you decided to use 75 13 (JNZ five less) instead of 90 90 (see above; NOP NOP) as the 'to value' for CusPop?
Is there any difference between the two? What I mean is, I'm curious why you decided to change your initial solution.
The difference is:
- With 90 90 the triggered tile must have modifier=0 (if it's not a gate).
- With 75 13 there is no such restriction. (Level doors are still required to have modifier=0, just like in the original.)

I wrote about this here: viewtopic.php?p=13823#p13823

Look at trigger_1() in seg007.c.
- The first is same as removing the "if (target_type == tiles_16_level_door_left)" part.
- The second is same as adding "else result = 1;" before the return. (Or as changing the initial value of result.)
Or, merging the two nested ifs like this: "if (target_type == tiles_16_level_door_left && curr_room_modif[tile] != 0)"

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3139
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Modifications to prince.exe (hex editing)

Post by Norbert » September 19th, 2014, 1:37 pm

zethholyblade wrote:How do you guys learn and understand this whole thing?
("you guys") Compared to David (and htamas) I know nothing about assembly/hex editing. ;)
Back in the DOS days I used some inline assembler under Pascal, to make the screen fade and the cursor disappear, things like that.
A couple of the courses of my Informatics study were about assembly. Those were the courses I disliked the most, because it seemed to have no practical use whatsoever. They could've been so much more interesting. We used a Motorola 68000 or Freescale 68HC11 or something, and instead of working with cool code (like PoP) we created our own pointless programs. I remember thinking 'when am I ever going to use any of this?' about the registers and whatnot.
How to learn and understand it? Taking classes, reading documentation, on-line discussions, Q&As (at Stack Overflow), code of others, and experimenting with code (change things, see what the outcome is), asking questions on IRC and forums.
Those who don't know a high-level programming language should probably start with that.
David wrote:I wrote about this here: viewtopic.php?p=13823#p13823
Oh, apparently that post slipped my mind.

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

Re: Modifications to prince.exe (hex editing)

Post by David » February 23rd, 2015, 10:46 pm

Continued from viewtopic.php?p=16134#p16134
(Allowing exit doors in the starting room)

Show stairs in exit door after it was opened:
(But don't show stairs in a closing door)

Code: Select all

seg008:1D6E A0 C4 57                             mov     al, start_room
seg008:1D71 2A E4                                sub     ah, ah
seg008:1D73 3B 06 9E 40                          cmp     ax, drawn_room
seg008:1D77 74 25                                jz      loc_B9BE
seg008:1D79 38 26 CC 4C                          cmp     modifier_left, ah
seg008:1D7D 74 1F                                jz      loc_B9BE
Search: 74 25 38 26 CC 4C
Replace: 90 90 38 26 9C 40

Then the stairs become visible only after the door opens, so you also need this:

Treat exit door as opened immediately after it starts opening:
(Show stairs immediately)

Code: Select all

seg007:064E 80 3E 28 43 2B                       cmp     curr_modifier, 43
seg007:0653 72 41                                jb      loc_8BE6
seg007:0655 83 3E 9C 40 00                       cmp     leveldoor_open?, 0
seg007:065A 74 07                                jz      loc_8BB3
seg007:065C 83 3E 9C 40 02                       cmp     leveldoor_open?, 2
seg007:0661 75 41                                jnz     loc_8BF4
Search: 80 3E 28 43 2B 72 41 83 3E 9C 40 00 74 07 83 3E 9C 40 02 75 41
Replace: C6 3E 9C 40 01 90 90 80 3E 28 43 2B 72 3A 90 90 90 90 90 90 90
Beware! This hack conflicts with one of the other leveldoor-related hacks, namely "Stop the second level door from acting weird".
This hack includes the effects of that one, though, so you don't need that.
Note: There are some special events that happen only if the level door is open. This hack might change their behaviour.

You also need the "Disable entering a closed level door" hack.
It's available in CusPoP and here: viewtopic.php?p=13128#p13128

The game shuts the first level door in the starting room.
But the kid might start at another level door of the room.
This case will need yet another hack.

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3139
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Modifications to prince.exe (hex editing)

Post by Norbert » February 23rd, 2015, 10:55 pm

Thanks for this information.

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

Re: Modifications to prince.exe (hex editing)

Post by David » January 16th, 2016, 11:22 am

mickey96 wrote:I have those lost posts. It's rared and it is roughly 5mb.
Go here for the link: viewtopic.php?f=67&t=561&p=3125#p3125 :lol:
That link is broken: "The requested topic does not exist." What happened?
Anyway, I still have the file (POP_Hex_Exe_Dumps.rar, 6 MB) if someone needs it.

Andrew
Wise Scribe
Wise Scribe
Posts: 313
Joined: July 16th, 2009, 4:39 pm

Re: Modifications to prince.exe (hex editing)

Post by Andrew » January 16th, 2016, 12:54 pm

David wrote:Anyway, I still have the file (POP_Hex_Exe_Dumps.rar, 6 MB) if someone needs it.
If you can split the archive and attach the parts here that would be nice (or upload the whole file to the site if you can as a mod).

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

Re: Modifications to prince.exe (hex editing)

Post by David » January 17th, 2016, 11:32 am

the forum wrote: The attachment’s file size is too large, the maximum upload size is 2 MB.
Please note this is set in php.ini and cannot be overridden.
So I have to split it...

You probably have to rename the files to be able to use them:
POP_Hex_Exe_Dumps.zip.001, etc.
This is how 7-zip created them, but I had to rename them because the forum does not allow such extensions.
Attachments
POP_Hex_Exe_Dumps_part_3.zip
(1.77 MiB) Downloaded 14 times
POP_Hex_Exe_Dumps_part_2.zip
(2 MiB) Downloaded 12 times
POP_Hex_Exe_Dumps_part_1.zip
(2 MiB) Downloaded 16 times


Post Reply