Killability of skeletons

Discussions about all other tools (CusPop, SAV/HOF editors) and hex editing.
Post Reply
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Killability of skeletons

Post by Norbert »

CusPop has a "Set up guard types" section, but those settings only change the enemy appearances. I would like to make skeletons unkillable regardless the levels they appear on. (And, make the prince die if he skills customly placed shadows, regardless the levels they appear on.) In the seg002.c file of David's conversion I found a comment "// You can't hurt skeletons" with a reference to loc_4276, that is also mentioned in the disassembly, as "cmp char_charid, charid_4_skeleton" plus "jz loc_42D6" (jump if/on zero). If I'm not mistaken this means it skips the hit point deduction if char_charid is equal to a skeleton. But where in PRINCE.EXE does the game set those char_charids for the enemies in each level?
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Killability of skeletons

Post by David »

Norbert wrote: "cmp char_charid, charid_4_skeleton" plus "jz loc_42D6" (jump if/on zero).
If I'm not mistaken this means it skips the hit point deduction if char_charid is equal to a skeleton.
Correct.
Norbert wrote: But where in PRINCE.EXE does the game set those char_charids for the enemies in each level?
It's in enter_guard(), in seg002.c:

Code: Select all

	// level 3 has skeletons with infinite lives
	if (current_level == 3) {
		Char.charid = charid_4_skeleton;
	} else {
		Char.charid = charid_2_guard;
	}
"current_level == 3" should be replaced with "tbl_guard_type[current_level] == 2".
That is, invincibility should depend on the level's guard type, not the level number.

The relevant part of the disassembly: (I deleted some empty lines)

Code: Select all

seg002:0196 EB 06                                jmp     short loc_381E
seg002:0198                      loc_3818:
seg002:0198 C7 06 88 58 00 00                    mov     curr_guard_color, 0 ; non-plain guards have only one color
seg002:019E                      loc_381E:
seg002:019E 83 3E 9E 0F 03                       cmp     current_level, 3 ; level 3 has skeletons with infinite lives
seg002:01A3 75 07                                jnz     loc_382C
seg002:01A5 C6 06 2D 3D 04                       mov     char_charid, charid_4_skeleton ; skeleton
seg002:01AA EB 05                                jmp     short loc_3831
seg002:01AC                      loc_382C:
seg002:01AC C6 06 2D 3D 02                       mov     char_charid, charid_2_guard ; guard
seg002:01B1                      loc_3831:
After some tries, I came up with this replacement:

Code: Select all

1556:0196 EB0F          JMP     01A7
1556:0198 C70688580000  MOV     WORD PTR [5888],0000
1556:019E B004          MOV     AL,04
1556:01A0 83BFD40302    CMP     WORD PTR [BX+03D4],+02
1556:01A5 7402          JZ      01A9
1556:01A7 B002          MOV     AL,02
1556:01A9 A22D3D        MOV     [3D2D],AL
1556:01AC 90            NOP
1556:01AD 90            NOP
1556:01AE 90            NOP
1556:01AF 90            NOP
1556:01B0 90            NOP
Search: EB 06 C7 06 88 58 00 00 83 3E 9E 0F 03 75 07 C6 06 2D 3D 04 EB 05 C6 06 2D 3D 02
Replace with: EB 0F C7 06 88 58 00 00 B0 04 83 BF D4 03 02 74 02 B0 02 A2 2D 3D 90 90 90 90 90
Norbert wrote: And, make the prince die if he skills customly placed shadows, regardless the levels they appear on.
(I guess you meant "kills".)

Do you mean guards (placed in the editor) on levels with guard type=shadow (set with CusPoP), or the special shadow appearing on levels 5,6,12?
And maybe make shadow-guards placed in the editor look like the shadow? (Currently they look like the kid.)
This might require further changes to the part above.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Killability of skeletons

Post by Norbert »

David wrote:Search: EB 06 C7 06 88 58 00 00 83 3E 9E 0F 03 75 07 C6 06 2D 3D 04 EB 05 C6 06 2D 3D 02
Replace with: EB 0F C7 06 88 58 00 00 B0 04 83 BF D4 03 02 74 02 B0 02 A2 2D 3D 90 90 90 90 90
Thanks for this information, with my limited assembly skills I would've never been able to come up with that.

Any idea why there's no match for this in version 1.3 and 1.4?

Code: Select all

norbert@stimpy ~/Desktop/CusPop-2.1/src/vers $ curl -L 'https://github.com/tmbinc/bgrep/raw/master/bgrep.c' | gcc -O2 -x c -o bgrep -
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   127    0   127    0     0    254      0 --:--:-- --:--:-- --:--:--   254
100  4357  100  4357    0     0   6872      0 --:--:-- --:--:-- --:--:--  6872
norbert@stimpy ~/Desktop/CusPop-2.1/src/vers $ ./bgrep 'EB 06 C7 06 88 58 00 00 83 3E 9E 0F 03 75 07 C6 06 2D 3D 04 EB 05 C6 06 2D 3D 02' *
bin.p0: 00003a16
bin.u0: 000050c6
norbert@stimpy ~/Desktop/CusPop-2.1/src/vers $ 
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Killability of skeletons

Post by David »

Norbert wrote:Any idea why there's no match for this in version 1.3 and 1.4?
This is a common problem for many hacks.
I already wrote about that here: viewtopic.php?p=14678#p14678

This part of the code contains addresses of global (static) variables, and their addresses are different in each version.
Although you could use "??" instead of those bytes (in bgrep's argument), the *replacement* still needs concrete addresses. (At least in this case.)

I think it's time to start the disassembly of 1.3 and 1.4. Most names would be copy-pasted from 1.0.

(Wow, curl | gcc ! :) )
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Killability of skeletons

Post by Norbert »

David wrote:(Wow, curl | gcc ! :) )
I cannot take credit for that though, it's from its README.
Also made me smile. :)
Post Reply