I need help with custom hacks

Discussions about all other tools (CusPop, SAV/HOF editors) and hex editing.
User avatar
Emiliano
Wizard Scribe
Wizard Scribe
Posts: 718
Joined: July 31st, 2019, 8:53 pm
Location: Mexico
Contact:

Re: I need help with custom hacks

Post by Emiliano »

Thank you David, Thank you very much :D
65536
User avatar
Emiliano
Wizard Scribe
Wizard Scribe
Posts: 718
Joined: July 31st, 2019, 8:53 pm
Location: Mexico
Contact:

Re: I need help with custom hacks

Post by Emiliano »

Hi again, there's another problem
Probably you have seen that the time counter appears every minute that finishes in 5 or 0 and at the begining of every level, it is well like this.
But the problem is with the timeless mods, here the time counter appears more frequently (less than 5 minutes) showing a TIME HAS EXPIRED! when we already know this, I would like to keep the auto showing at the beginning of every level and by pressing space

Original feature :arrow: Time counter appears at the begining of every level, every 5 minutes and by pressing space
Custom hack :arrow: Time counter will only appear at the beginning of every level and by pressing space

Hope you can help me.
Thanks a lot for your work and knowledge :)
65536
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1782
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: I need help with custom hacks

Post by atrueprincefanfrom18 »

If so, can we make the repetition of mouse possible? Maybe changing something to false that remain false and mouse appears again after 12.5 (or any custom) value?
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: I need help with custom hacks

Post by David »

Emiliano Fierro wrote: August 26th, 2020, 2:05 am Probably you have seen that the time counter appears every minute that finishes in 5 or 0 and at the begining of every level, it is well like this.
But the problem is with the timeless mods, here the time counter appears more frequently (less than 5 minutes) showing a TIME HAS EXPIRED! when we already know this, I would like to keep the auto showing at the beginning of every level and by pressing space

Original feature :arrow: Time counter appears at the begining of every level, every 5 minutes and by pressing space
Custom hack :arrow: Time counter will only appear at the beginning of every level and by pressing space
(For the record: in unpacked v1.0, starting minutes can be set at offset 0x60D3.)

First of all, you should know why does the game show "TIME HAS EXPIRED!" if you set the starting minutes to something between 32768 and 65535.
The game interprets the number of minutes as a two's complement integer, which means that 0xFFFF will actually mean -1.
If you set the starting minutes to 0xFFFF (-1) and start the game with cheats on, the "+" key will increase the minutes to 0 and game will show the bad ending.

The code which automatically shows the remaining time looks like this in SDLPoP:

Code: Select all

		// Time passes
		--rem_tick;
		if (rem_tick == 0) {
			rem_tick = 719; // 720=12*60 ticks = 1 minute
			--rem_min;
#ifndef ALLOW_INFINITE_TIME
			if (rem_min != 0 && (rem_min <= 5 || rem_min % 5 == 0)) {
				is_show_time = 1;
			}
#else
That is, the time is shown at a minute boundary, if the minutes are divisible by 5 *or* there are no more than 5 minutes left.
-1 is less than 5 so the time will be shown in every minute if "TIME HAS EXPIRED!".

The solution: change rem_min != 0 to rem_min > 0.

Search: FF 0E 7E 4F 74 3D
Change: 74 to 7E
(offset in unpacked v1.0: 0xD9B3)

You might also want to change the "TIME HAS EXPIRED!" text to something else.

Details:

Code: Select all

seg008:24D3 FF 0E 82 4F                       dec   rem_tick  ; time passes
seg008:24D7 75 28                             jnz   loc_C121
seg008:24D9 C7 06 82 4F CF 02                 mov   rem_tick, 719  ; 720=12*60 ticks = 1 minute
seg008:24DF FF 0E 7E 4F                       dec   rem_min
seg008:24E3 74 3D                             jz    loc_C142 ; <-- change to JLE
seg008:24E5 83 3E 7E 4F 05                    cmp   rem_min, 5
seg008:24EA 7C 0D                             jl    loc_C119
seg008:24EC A1 7E 4F                          mov   ax, rem_min
seg008:24EF 99                                cwd
seg008:24F0 B9 05 00                          mov   cx, 5      ; if remaining minutes divisible by 5, show it
seg008:24F3 F7 F9                             idiv  cx
seg008:24F5 0B D2                             or    dx, dx
seg008:24F7 75 29                             jnz   loc_C142
seg008:24F9                        loc_C119:
seg008:24F9 C7 06 1C 43 01 00                 mov  is_show_time, 1
seg008:24FF EB 21                             jmp  short loc_C142
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: I need help with custom hacks

Post by David »

atrueprincefanfrom18 wrote: August 19th, 2020, 6:34 am Wow! Actually, even I had an idea. Why is it that the chomper is on the left of the tile and the gate is on the right, can we shift them both? Somehow?
The left and right "margins" for those tiles are set at the following places:

In SDLPoP:

Code: Select all

in seg004.c:

// These two arrays are indexed with the return value of wall_type.
// data:24BA
const sbyte wall_dist_from_left[] = {0, 10, 0, -1, 0, 0};
// data:24C0
const sbyte wall_dist_from_right[] = {0, 0, 10, 13, 0, 0};

The wall types (barrier types) are defined in seg006.c:

// seg006:0FC3
int __pascal far wall_type(byte tiletype) {
	switch (tiletype) {
		case tiles_4_gate:
		case tiles_7_doortop_with_floor:
		case tiles_12_doortop:
			return 1; // wall at right
		case tiles_13_mirror:
			return 2; // wall at left
		case tiles_18_chomper:
			return 3; // chomper at left
		case tiles_20_wall:
			return 4; // wall at both sides
		default:
			return 0; // no wall
	}
}
In the DOS disassembly:

Code: Select all

data:24BA 00 0A 00 FF 00 00    wall_dist_from_left db 0, 10, 0, 255, 0, 0
data:24C0 00 00 0A 0D 00 00    wall_dist_from_right db 0, 0, 10, 13, 0, 0
In unpacked v1.0, the first table (left) starts at 0x1EA4A, and the next table (right) is right after the first one.


Let's put those numbers into a table:

Code: Select all

left right   type of barrier
  margins
   0    0    0 = none (not used)
  10    0    1 = gate and doortop
   0   10    2 = mirror
  -1   13    3 = chomper
   0    0    4 = wall
   0    0    5 = (not used)
Graphically they look like this:

Code: Select all

 00000000001111
 01234567890123 -- Each tile is 14 units wide.
           |--| gate and doortop
 |--|           mirror
||              chomper
 |------------| wall
Note how the gate and the doortop are on the right side of the tile, while the mirror and the chomper are on the left side.
And of course, the wall occupies the whole tile.

By editing these numbers, you can change how these tiles behave for collision detection.
Remember that this won't affect the graphics.
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1782
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: I need help with custom hacks

Post by atrueprincefanfrom18 »

Interesting, I'll try this it out if I get time, maybe this weekend.
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
User avatar
Emiliano
Wizard Scribe
Wizard Scribe
Posts: 718
Joined: July 31st, 2019, 8:53 pm
Location: Mexico
Contact:

Re: I need help with custom hacks

Post by Emiliano »

David wrote: August 26th, 2020, 10:37 am If you set the starting minutes to 0xFFFF (-1) and start the game with cheats on, the "+" key will increase the minutes to 0 and game will show the bad ending.
I will deactivate “+” and “-” to make sure that nobody tries anything with the time
David wrote: August 26th, 2020, 10:37 am You might also want to change the "TIME HAS EXPIRED!" text to something else
I will see, but I will need another exe from CusPoP

Thanks for your time and knowledge :)
65536
User avatar
Emiliano
Wizard Scribe
Wizard Scribe
Posts: 718
Joined: July 31st, 2019, 8:53 pm
Location: Mexico
Contact:

Re: I need help with custom hacks

Post by Emiliano »

Hi there, as I told in a previous post, I want to enable again the music of Meet Jaffar and Jaffar waiting some ticks before attacking (as the original game)
I don't know if is this possible because you arrive by the bottom, but help me making it like the original as most as possible
These are the definitive coordinates, Level 13, Room 3, Tile 9 *in RoomShaker
If this is useful for you, I used only one Jaffar in level 13, not more than one.
Thanks.
This is the last custom hack for the current in progress mod, but I will need them for SDLPoP too, however that would be in another topic.
Attachments
Definitive Jaffar Position (202008302116).png
65536
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: I need help with custom hacks

Post by David »

Emiliano Fierro wrote: August 31st, 2020, 4:21 am Hi there, as I told in a previous post, I want to enable again the music of Meet Jaffar and Jaffar waiting some ticks before attacking (as the original game)
I don't know if is this possible because you arrive by the bottom, but help me making it like the original as most as possible
I found a way to do this, but with a possible problem:
This hack will also change the special event which removes the sword from the shadow's room on level 12.
Originally, the sword disappears when the prince leaves room 18 to the right.
With this hack, that event will be triggered by exiting a room at the top instead to the right.
That's the same change that this hack does with the "meet Jaffar" event.
That's because the game checks the exit direction together for these two events.

I don't know if your mod uses the disappearing sword event.
I know you asked for a hack which completely removes the shadow from level 12 (Seventh here), but I don't know if it was for this mod or a different one.
But you also asked for a hack which changes the shadow fight (here), but again I don't know which mod is it.

If the mod uses that event then please tell me, and I will try to find a solution which does not affect the disappearing sword event.

If your mod does not use that event then here is what to edit:

Search: 3D 01 00 75 03 E9 CE 00
Change: 01 to 02
(The offset of the byte to change is 0x547F in unpacked v1.0)

Search: 80 3E 2B 3D 03 75 0F B8 1D 00
Change: 03 to the number of the room where the prince is coming from. On your screenshot it's room 13, which is 0D in hex.
(The offset of the byte to change is 0x55F0 in unpacked v1.0)

Details:

Code: Select all

seg002:054E 3D 01 00                             cmp     ax, 1 ; = right ; <-- change to 2 = up
seg002:0551 75 03                                jnz     loc_3BD6
seg002:0553 E9 CE 00                             jmp     leave_right

seg002:0624                      leave_right:                            ; CODE XREF: leave_room+4Fj
seg002:0624 0E                                   push    cs
seg002:0625 E8 58 00                             call    near ptr sword_disappears
seg002:0628 0E                                   push    cs
seg002:0629 E8 82 00                             call    near ptr meet_Jaffar
seg002:062C EB EA                                jmp     short loc_3C98

seg002:06AE                      ; void __pascal far meet_Jaffar()
seg002:06AE                      meet_Jaffar     proc far                ; CODE XREF: leave_room+125p
seg002:06AE 83 3E 9E 0F 0D                       cmp     current_level, 13 ; Special event: play music
seg002:06B3 75 1D                                jnz     locret_3D52
seg002:06B5 83 3E 9C 40 00                       cmp     leveldoor_open, 0
seg002:06BA 75 16                                jnz     locret_3D52
seg002:06BC 80 3E 2B 3D 03                       cmp     char.room, 3 ; <-- change to the number of the room where the prince is coming from
seg002:06C1 75 0F                                jnz     locret_3D52
seg002:06C3 B8 1D 00                             mov     ax, sound_29_meet_Jaffar
seg002:06C6 50                                   push    ax              ; sound_id
seg002:06C7 9A C5 12 00 00                       call    play_sound
seg002:06CC C7 06 34 3D 1C 00                    mov     guard_notice_timer, 28 ; Special event: Jaffar waits a bit (28/12=2.33 seconds)
seg002:06D2
seg002:06D2                      locret_3D52:                            ; CODE XREF: meet_Jaffar+5j
seg002:06D2                                                              ; meet_Jaffar+Cj ...
seg002:06D2 CB                                   retf
seg002:06D2                      meet_Jaffar     endp
User avatar
Emiliano
Wizard Scribe
Wizard Scribe
Posts: 718
Joined: July 31st, 2019, 8:53 pm
Location: Mexico
Contact:

Re: I need help with custom hacks

Post by Emiliano »

The level 12 keeps shadow fight and sword remove special event, what I removed for this level is the exit in Room 23 and show shadow's HPs, also both prince and shadow get hurt if one strikes the other
If it helps you I will post a screenshot of Room 15 of level 12
*By the Room position you don't see the sword dissapear, unless you use H, J, N, U in the cheats mode
If is this useful, here is the detailed structure.
Attachments
Level 12 detailed structure.png
Level 12 structure.png
Custom Room 15.png
65536
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: I need help with custom hacks

Post by David »

Emiliano Fierro wrote: September 5th, 2020, 7:29 pm *By the Room position you don't see the sword dissapear, unless you use H, J, N, U in the cheats mode
Do you mean that the player cannot see the shadow's room when the sword is still there?

If that's the case then you could simply remove the sword with the level editor.
The shadows appears if the sword is not there, but it does not matter if the sword has ever been in the room.
User avatar
Emiliano
Wizard Scribe
Wizard Scribe
Posts: 718
Joined: July 31st, 2019, 8:53 pm
Location: Mexico
Contact:

Re: I need help with custom hacks

Post by Emiliano »

David wrote: September 12th, 2020, 12:35 pm
Emiliano Fierro wrote: September 5th, 2020, 7:29 pm *By the Room position you don't see the sword dissapear, unless you use H, J, N, U in the cheats mode
Do you mean that the player cannot see the shadow's room when the sword is still there?
Yes, this is what I mean
65536
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: I need help with custom hacks

Post by David »

Emiliano Fierro wrote: September 12th, 2020, 2:47 pm
David wrote: September 12th, 2020, 12:35 pm Do you mean that the player cannot see the shadow's room when the sword is still there?
Yes, this is what I mean
Then you can do what I wrote in my previous post.
T0mmiTheGreat
Sheikh
Sheikh
Posts: 25
Joined: February 22nd, 2021, 8:48 pm
Location: Czech Republic

Re: I need help with custom hacks

Post by T0mmiTheGreat »

Greetings, I have a (hopefully) simple question:
Is it possible to set a checkpoint to be triggered by leaving room 7 to the right?

Apparently, the checkpoint in Level 3 is triggered by moving from room 7 to room 2 to the left. CusPop doesn't allow modifying this, and other tools are way too complicated for me. My goal is to set the checkpoint in Level 7, triggered by moving from room 7 to 2 to the right, the Prince should respawn in room 2, at location 20, facing right, and the tile to clear can be in room 22, location 0.

I am hoping for a similar answer like all the previous – both hex and tasm format (if possible) :)
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1782
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: I need help with custom hacks

Post by atrueprincefanfrom18 »

T0mmiTheGreat wrote: February 22nd, 2021, 11:09 pm Is it possible to set a checkpoint to be triggered by leaving room 7 to the right?
In SDLPoP, you could move this line after this line. And change the checkpoint conditions as you want... You can change the level number, and also the room number.

I don't know how you can do it with Hex Editing. Maybe David will help you?

I think you need to get the CusPoP file and just edit the hex where it says to activate the checkpoint when you move to left, instead activate it when you move to the right. But I can't confirm, David would be the one helping you out sooner ;)
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
Post Reply