Disassemblies of PoP2

Second part of the best game ever made.

Moderator: English Moderator Team

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

Disassemblies of PoP2

Postby David » January 3rd, 2014, 8:31 pm

Here is a disassembly of PoP2 IR.
(I already mentioned that I started this, here: viewtopic.php?p=14176#p14176 )
Note that this EXE is overlaid, that is, different parts are loaded at the same place at different times.
Since IDA can't handle this, there is a huge empty area in the middle of the disassembly. (Between non-overlaid code and data.)
Attachments
pop2_ida.zip
(1.94 MiB) Downloaded 43 times

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

Re: Disassembly of PoP2 IR

Postby Norbert » June 10th, 2014, 4:22 pm

So, the 0011 file is the overlay? How did you extract it manually? I'm also wondering how you managed to get output with things like "cmp level_type, caverns". Was that altered/added by hand? I am a (dis)assembly noob and used ndisasm, but didn't get any of that information. I also tried using various unpackers first, but got nothing better.

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

Re: Disassembly of PoP2 IR

Postby Norbert » June 10th, 2014, 5:38 pm

On a somewhat related note. I'm trying to figure out for which rooms the EXE overrides what happens when you leave the room, for a future document about PoP2 events. Sometimes leaving to the bottom will have the prince falling/screaming down a pit; sometimes leaving to a side will have the prince end up in another room than the room links specify. Figuring this out by hand is a lot of work, so I'm looking at the disassembly.

In level 6, room 27 always has room 3 to its left. I found mentions of "room_left" but nothing interesting nearby, and searched for 1Bh (27) and then 3 nearby but didn't find anything.

Down in room 13 of level 13 is a pit. So, I searched for 13 and eventually found "seg003:019B cmp shown_room, 13; level 13, room 13: chasm". Then I searched for "chasm" and found several other hits...

Code: Select all

seg003:17C6            cmp        level_number, 9 ; level 9 room 16: chasm
seg003:17D7            cmp        level_number, 6 ; level 6 room 27: chasm
seg010:0674            cmp        level_number, 9 ; level 9 room 16: chasm

...but this is incomplete. Several are still missing, like the flame room (level 13, room 4) and several rooms of level 1 (rooftops).

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

Re: Disassembly of PoP2 IR

Postby David » June 10th, 2014, 7:21 pm

Norbert wrote:So, the 0011 file is the overlay?

Yes, it is *an* overlay, though it's not in a separate file (originally).
This overlay is different from the others in this exe, because it is always loaded.

The other overlays contain code that is loaded only in some cases, for example, depending on the type of the level.

Norbert wrote:How did you extract it manually?

There is a part in the file that stores where the overlays are in the file, and where are they loaded. In the disassembly I marked it with the label "ovl_segments".
Note that sizes and addresses have to be multiplied by 16.

Norbert wrote:I'm also wondering how you managed to get output with things like "cmp level_type, caverns". Was that altered/added by hand? I am a (dis)assembly noob and used ndisasm, but didn't get any of that information.

Yes, all names (and comments) were added by me. (Of course this means that some of them may be wrong or misleading.)

Norbert wrote:I also tried using various unpackers first, but got nothing better.

PRINCE.EXE of PoP2 is not compressed.

Norbert wrote:Sometimes leaving to the bottom will have the prince falling/screaming down a pit;

Norbert wrote:Several are still missing, like the flame room (level 13, room 4) and several rooms of level 1 (rooftops).

Level 13, room 4 has no room linked at the bottom, so it does not need any special events. Same is the case with level 1, except with room 11.
Some other rooms, however, have another room linked at their bottom, but treated as having nothing below.
Examples are: level 13 room 13, level 5 room 10, level 14 room 5.

Norbert wrote:In level 6, room 27 always has room 3 to its left. I found mentions of "room_left" but nothing interesting nearby, and searched for 1Bh (27) and then 3 nearby but didn't find anything.

I tried something: I changed the level type of level 6 to temple. After that, this special event did not work anymore.
But I can't find where is this event specified.
I tried these: (after restoring the level type, of course!)
* To zero out all the modifiers so that the custom background is not loaded.
* To delete the CUST resource for this room.
* Scan the exe for all instances of "cmp <something>,27" (and 28) and replaced 27/28 with 0.
Next step would be using the DOSBox debugger... (To catch the moment when the kid is moved to room 3.)

salvadorc17
Calif
Calif
Posts: 428
Joined: August 27th, 2011, 2:04 am

Re: Disassembly of PoP2 IR

Postby salvadorc17 » June 10th, 2014, 9:19 pm

This means, that will be more easy to create a prince of persia 2 editor and mods??

realXCV
Sheikh
Sheikh
Posts: 26
Joined: November 4th, 2011, 12:04 am
Location: Right here
Contact:

Re: Disassembly of PoP2 IR

Postby realXCV » June 11th, 2014, 2:18 am

David wrote:I tried these: (after restoring the level type, of course!)
* To zero out all the modifiers so that the custom background is not loaded.
* To delete the CUST resource for this room.
* Scan the exe for all instances of "cmp <something>,27" (and 28) and replaced 27/28 with 0.
Next step would be using the DOSBox debugger... (To catch the moment when the kid is moved to room 3.)

Maybe it's done using a variable. Something like:
mov variable, 1Bh
(...)
cmp something, variable

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

Re: Disassembly of PoP2 IR

Postby Norbert » June 11th, 2014, 3:27 am

Interesting. I think I will check one level a day by hand. Then I should be done in 14 days (or, inc. gameplay, 28), which is totally doable.

salvadorc17 wrote:This means, that will be more easy to create a prince of persia 2 editor and mods??


The latest apoplexy (ZIP for Windows) should be fairly usable for that.
Levels 1, 2 and 14 are difficult for PoP2, so if you're new to level editing, I suggest you start with level 3 through 13.
If you haven't used apoplexy before, it may be best to first watch the old instructional video (here) and then its supplement (here).
[Edit: Or maybe you mean for the SNES version?]

salvadorc17
Calif
Calif
Posts: 428
Joined: August 27th, 2011, 2:04 am

Re: Disassembly of PoP2 IR

Postby salvadorc17 » June 12th, 2014, 2:03 am

Yes i mean the snes version, but dont know if there is a difference, the main problem for me with pc is that windows is not so compatible with the dos versions...

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

Re: Disassembly of PoP2 IR

Postby Norbert » June 12th, 2014, 11:13 am

salvadorc17 wrote:[...] windows is not so compatible with the dos versions...


I'm not sure I understand what you mean there.
If you mean that the DOS program won't run on Windows, you can use DOSBox for that (which is also included with apoplexy for Windows).

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

Re: Disassembly of PoP2 IR

Postby David » June 12th, 2014, 6:25 pm

Meanwhile I found where is the level 6 event checked. (Entering the ruins.)
It is not in the current disassembly, but in overlay 0x0003. (It is loaded only when in-game, and not loaded when in the intro. In the intro, overlay 0x0002 is loaded instead.)

So I also added that overlay to the disassembly.
I tried to find and mark every place where something is done depending on the current level or room.
Though I am not always sure what happens.

I attached the new version to this post.
Attachments
pop2_ida.zip
(2.36 MiB) Downloaded 22 times

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

Re: Disassembly of PoP2 IR

Postby David » December 19th, 2015, 7:52 pm

Here is the newest disassembly.
I added many names and comments since the last one.

the forum wrote:The attachment’s file size is too large, the maximum upload size is 2 MB.

I removed some things:
* The overlays folder: It's the same as before.
* PRINCE_ingame.asm: It's not really needed, it's the same as PRINCE_ingame.lst but without the offsets and hex codes.
* An area in PRINCE_ingame.lst that contained only uninitialized bytes.
Attachments
pop2_IR_ida.zip
(1.97 MiB) Downloaded 13 times

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

Re: Disassembly of PoP2 IR

Postby Norbert » December 19th, 2015, 8:38 pm

the forum wrote:The attachment’s file size is too large, the maximum upload size is 2 MB.


It's 5 MB. People have uploaded >2 MB things recently.
I'm going to ignore the forum error, just because phpBB is already causing me enough discomfort.
(Unless someone has very specific instructions to make the thing that is already 5 MB really 5 MB for everyone everywhere.)
PS: I already checked if the "Prince Of Persia 2: The Shadow And The Flame" board has any settings that override the global setting and as far as I can tell there are no such settings.
Attachments
attach.png
5 MB


Return to “Prince Of Persia 2: The Shadow And The Flame”

Who is online

Users browsing this forum: No registered users and 1 guest