add new .dat file with guard

Discussions about all other tools (CusPop, SAV/HOF editors) and hex editing.
Post Reply
User avatar
jjur
Efendi
Efendi
Posts: 13
Joined: February 7th, 2015, 10:56 pm
Location: Slovakia
Contact:

add new .dat file with guard

Post by jjur »

Is possible add new guard .dat file?
I need all existing (vizer.dat, guard.dat, skel.dat, fat.dat shadow.dat) and i need to add 6th guard resource. How i can add it? Which file i have to modify?
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: add new .dat file with guard

Post by David »

You need to hex-edit prince.exe...
...but first I have to figure out what to modify. :)

First, I assume you are using version 1.0 of PoP.
In the EXE, there is a table with the names of guard DAT files.
It is immediately followed by other string tables, and finally the "guard type per level" table:

Code: Select all

data:03BA 4F 03 59 03 61 03 tbl_guard_dat   dw offset guard_dat, offset fat_dat, offset skel_dat
          6A 03 75 03                       dw offset vizier_dat, offset shadow_dat
data:03C4 80 03 81 03 83 03 tbl_envir_gr    dw offset env_none, offset env_cga1, offset env_cga2
          85 03 87 03 89 03                 dw offset env_ega1, offset env_ega2, offset env_vga
data:03D0 8B 03 93 03       tbl_envir_ki    dw offset dungeon, offset palace
data:03D4 00 00 00 00 00 00 tbl_guard_type  dw 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 4, 3, 0FFFFh, 0FFFFh
          02 00 00 00 00 00
          01 00 00 00 00 00
          ...
Guard types 0..4 are the existing types, 5..12 could be the new types.
The easiest option is to use as filenames the strings that are already there:

Code: Select all

5="" (useless)
6 or 7="C"
8 or 9="E"
10="V"
11="DUNGEON"
12="PALACE"
This means you can use files named "C", "E", "V", "DUNGEON" or "PALACE" as a guard DAT.
(Yes, these names look odd, but it's easier to use what is already there.)
Note that there is no .DAT after the names.

To use the new types, you need to hex-edit the "guard type per level" table (in PRINCE.EXE).
(CusPop has this feature, but it allows only the "normal" types.)
It looks like this: (Search for the second row with the hex editor.)

Code: Select all

0     1     2     3     4     5     6     7     8     9     10    11    12    13    14    15 <- levels
00 00 00 00 00 00 02 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 03 00 FF FF FF FF
Choose the level where you want the new guard type: from the first 00, go right levelnumber*2 bytes.
Then write the number of the new guard type.
For example, if you want level 2 to use a file called "C", then from the first 00, go right 2*2=4 bytes, and change that byte to 06 (or 07).

To make a new DAT file with these new names, you can make it with PR using the filename of an existing type, and then rename the file.
4DPlayer

Re: add new .dat file with guard

Post by 4DPlayer »

This looks very interesting.

Is there any offset that you can start with to locate the other levels and which guards appear in them?
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: add new .dat file with guard

Post by David »

4DPlayer wrote: August 15th, 2019, 8:22 pm Is there any offset that you can start with to locate the other levels and which guards appear in them?
First you need to unpack PRINCE.EXE. Apoplexy will do that for you.

The offsets of the guard type table are are:
Unpacked 1.0: 0x1C964
Unpacked 1.3: 0x1C702
Unpacked 1.4: 0x1905E

At that offset you will find the table which I mentioned in my previous post.
The table contains two bytes for each level from 0 (demo) to 15 (potions).

Code: Select all

[ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10] [ 11] [ 12] [ 13] [ 14] [ 15] <- levels, just for explanation
00 00 00 00 00 00 02 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 03 00 FF FF FF FF <- this is in PRINCE.EXE
4DPlayer

Re: add new .dat file with guard

Post by 4DPlayer »

David wrote: August 18th, 2019, 12:16 pm
4DPlayer wrote: August 15th, 2019, 8:22 pm Is there any offset that you can start with to locate the other levels and which guards appear in them?
First you need to unpack PRINCE.EXE. Apoplexy will do that for you.

The offsets of the guard type table are are:
Unpacked 1.0: 0x1C964
Unpacked 1.3: 0x1C702
Unpacked 1.4: 0x1905E

At that offset you will find the table which I mentioned in my previous post.
The table contains two bytes for each level from 0 (demo) to 15 (potions).

Code: Select all

[ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10] [ 11] [ 12] [ 13] [ 14] [ 15] <- levels, just for explanation
00 00 00 00 00 00 02 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 03 00 FF FF FF FF <- this is in PRINCE.EXE
Thank you. It sounds like a very good idea :)
4DPlayer

Re: add new .dat file with guard

Post by 4DPlayer »

I've tried this and here are my results.
Whenever I modify the bytes to include let's say PALACE.DAT in level 1 or 2, I get some errors.
First of all, Apoplexy treats it as if there is no enemy at all in the level:
Capture2.JPG
Capture2.JPG (18.57 KiB) Viewed 2477 times
Now, depending on the .DAT I'm using, I will get a different sort of error.
Into Drive B...
Into Drive B...
The usual
The usual
The closest I ever get to actually having a guard in the room.
The closest I ever get to actually having a guard in the room.
Capture4.JPG (33.51 KiB) Viewed 2477 times
Now, maybe it's what I'm doing that's the problem. I followed your instructions by locating the guard type table in offset 0x1C964. (I made sure I had the right thing by changing level 3 to guard which worked).
I took the second set of bytes of the table (level 1's bytes) and replaced them with the number 12, then took a FAT.DAT into a separate folder from the game and renamed it to PALACE.DAT. Then I moved PALACE.DAT into the "prince" folder of Apoplexy with the result above. I tried the same with other files and made a full set of DAT files: C,V,DUNGEON,PALACE,E.
All came to the same conclusion.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: add new .dat file with guard

Post by David »

Now I realized that my original post had some misleading parts.
Sorry about that!

First of all, I wrote the numbers of the new guard types in decimal, while you need to enter them in hexadecimal in the hex editor.
Here are they in hexadecimal:

Code: Select all

05 = "" (useless)
06 or 07 = "C"
08 or 09 = "E"
0A = "V"
0B = "DUNGEON"
0C = "PALACE"
Secondly, you need to create the new files without the .DAT extension.
So your "PALACE.DAT" should be named just "PALACE".

I attached an example to my post.
To try it, you need to add the missing files from the original PoP.
I changed level 2 to use the birdman from here: https://www.popot.org/custom_levels.php?action=FAT.DAT
Attachments
more_guard_types.zip
(76.15 KiB) Downloaded 79 times
4DPlayer

Re: add new .dat file with guard

Post by 4DPlayer »

David wrote: September 14th, 2019, 10:42 am Now I realized that my original post had some misleading parts.
Sorry about that!

First of all, I wrote the numbers of the new guard types in decimal, while you need to enter them in hexadecimal in the hex editor.
Here are they in hexadecimal:

Code: Select all

05 = "" (useless)
06 or 07 = "C"
08 or 09 = "E"
0A = "V"
0B = "DUNGEON"
0C = "PALACE"
Secondly, you need to create the new files without the .DAT extension.
So your "PALACE.DAT" should be named just "PALACE".

I attached an example to my post.
To try it, you need to add the missing files from the original PoP.
I changed level 2 to use the birdman from here: https://www.popot.org/custom_levels.php?action=FAT.DAT
THANK YOU DAVID! I was beginning to give up for awhile. :? :D
Post Reply