Some door stuff

Completed patches for Keen1.
Post Reply
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Some door stuff

Post by levellass »

Originally patched by LL in January, can you believe it?

The door opening involves 3 tiles; one 3 below the door top, one 2 below the door top, and the door top (And the tile that follows it in the tileset) There are also 2 tiles that replace the door when it is opened. For the opening door, it is possible to change where in the level these tiles are taken from; normally the tile displayed is the same as that already there, but this can be changed.

Thus when Keen opens a door the door top tiles is copied from the level, and it and the tile after it are pasted in FRONT of Keen and these lower, making it appear that the door is sinking into the ground. To see this try this patch:

Code: Select all

#Insane doors
%patch $28D6 $00
Since the doors have to disappear into the ground, the ground tiles must also be copied and pasted so Keen doesn't see the sinking door. The locations of where all these tiles are copied from can be changed, making for some interesting stuff. At the same time two tiles are picked from the tileset and used to replace the two door tiles, this is why Keen can walk through a door as soon as it opens. Only the vertical locations are alterable because there's no point including a horizontal location that's always going to be zero is there?

The following patch allows you to change what tiles replace the doors when they're opened, and what tiles are displayed as the door 'sinks into the ground' Fiddle about with it and see what you get! (If you can see where the little patches at the bottom go you can fit them into the big patch all in one clean block.)

Code: Select all

#Ultimate door versatility patch; set default door code:
%patch $28A1 $C7 $05 $02 $00 $F7 $2E $08 $6C $03 $46 $04 $D1 $E0 $C4 $1E $48 #1
%patch $28B1 $6C $03 $D8 $26 $8B $07 $89 $44 $0E $8B $C7 $05 $00 $00 $F7 $2E #3-4
%patch $28C1 $08 $6C $03 $46 $04 $D1 $E0 $C4 $1E $48 $6C $03 $D8 $26 $8B $07
%patch $28D1 $89 $44 $10 $8B $5E $FE $D1 $E3 $C7 $87 $9A $AA $00 $00 $8B $C7
%patch $28E1 $05 $00 $00 $F7 $2E $08 $6C $03 $46 $04 $D1 $E0 $C4 $1E $48 $6C #3-7
%patch $28F1 $03 $D8 $26 $C7 $07 $8F $00 $8B $C7 $05 $01 $00 $F7 $2E $08 $6C #2-9
%patch $2901 $03 $46 $04 $D1 $E0 $C4 $1E $48 $6C $03 $D8 $26 $C7 $07 $8F $00
%patch $2911 $5F $5E $8B $E5 $5D $C3 $90 $90

#Adjustable stuff:
%patch $2889 $03 $00 #Tile for 4 below doortop is picked from... [Vert location]
%patch $28A3 $02 $00 #Tile for 3 below doortop is picked from...
%patch $28BD $00 $00 #Doortop is picked from...
%patch $28E2 $00 $00 #First replacement tile vert location
%patch $28FB $01 $00 #Second replacement tile vert location
%patch $28F6 $8F $00 #First replacement tile
%patch $290F $8F $00 #Second replacement tile
This stuff is pointless, but may have some unseen uses, you never know; the last one is exactly what Spleen is looking for, but sadly ALL door ties become the same.

Code: Select all

#Probbably poinmtless stuff:
%patch $289F $12 #Make 4 below tile always tile 0
%patch $28B9 $12 #Make 3 below tile always tile 0
%patch $28D3 $12 #Make descending door tiles always tile 0
Finally, here's some misc stuff LL seems to have found:

Code: Select all

#Door opening sound
%patch $2801 $21 $00

#Only blue door takes key
%patch $28D7 $A0
#Doors don't take keys
%patch $28D7 $00

#Doors don't open, Keen can just walk right through them
#If he has the right key- over and over. (Doesn't take Keen's key.)
%patch $27F8 $C3
User avatar
CommanderSpleen
Posts: 1017
Joined: Sun Aug 31, 2003 12:11 pm
Location: The Land of Sparkly Things
Contact:

Post by CommanderSpleen »

Here's one to add to the list:

Code: Select all

#Doors disappear instantly instead of sliding
%patch $286B $90 $90 $90
There are a few ways of doing this, so I get the feeling it might cause some side-effects like a memory leak, but I've no way to test it at this point.

By the way, it looks like you already posted this some time ago.
User avatar
Shadow Master
Posts: 129
Joined: Fri Oct 20, 2006 3:14 pm
Location: Santiago, Chile
Contact:

Post by Shadow Master »

CommanderSpleen wrote:There are a few ways of doing this, so I get the feeling it might cause some side-effects like a memory leak, but I've no way to test it at this point.
You know $90 is the NOP (no operation) instruction in x86 processors. Well, in theory it shouldn't cause memory leaks unless you're removing instructions that handle the stack (pop, push, etc.) or that modify the registers in order to handle the stack later according to their value. In the last case, it should be less likely to cause memory leaks anyway.
User avatar
CommanderSpleen
Posts: 1017
Joined: Sun Aug 31, 2003 12:11 pm
Location: The Land of Sparkly Things
Contact:

Post by CommanderSpleen »

Shadow Master wrote:You know $90 is the NOP (no operation) instruction in x86 processors.
Yep, and thus it's a very versatile means of patching and discovering by trial-and-error what specific bits of code do (unless they're interconnected in a complex manner).
Shadow Master wrote:Well, in theory it shouldn't cause memory leaks unless you're removing instructions that handle the stack (pop, push, etc.) or that modify the registers in order to handle the stack later according to their value.
Aye, that's what I mean. I'm not sure how these commands interact with memory, so as far as I know there could be any number of side effects that aren't immediately obvious.

The affected line in this case is:

Code: Select all

:0001.286B E8E3B8                 call E151
...which calls:

Code: Select all

:0001.E151 5B                     pop bx
:0001.E152 0E                     push cs
:0001.E153 53                     push bx
:0001.E154 80F910                 cmp cl, 10
:0001.E157 7310                   jnb E169
:0001.E159 8BD8                   mov bx, ax
:0001.E15B D3E0                   shl ax, cl 
:0001.E15D D3E2                   shl dx, cl 
:0001.E15F F6D9                   neg cl
:0001.E161 80C110                 add cl, 10
:0001.E164 D3EB                   shr bx, cl 
:0001.E166 0BD3                   or dx, bx
:0001.E168 CB                     retf
This function is called twice in the door-opening routine, and I have no idea what it does. All I know is that by removing one of its references, the sliding door sprite(?) is not created properly.

Here's the full disassembled door opening code, to make it a bit more convenient for others to h4xx0r the doors in future.

Code: Select all

* Referenced by a (U)nconditional or (C)onditional Jump at Address:
|:0001.2851(U)
|
:0001.2856 E82501                 call 297E
:0001.2859 8BF0                   mov si, ax
:0001.285B C744080100             mov word ptr [si+08], 0001
:0001.2860 C744223D27             mov word ptr [si+22], 273D
:0001.2865 8B4604                 mov ax, [bp+04]
:0001.2868 99                     cwd
:0001.2869 B10C                   mov cl, 0C
:0001.286B E8E3B8                 call E151               ## patched
:0001.286E 8904                   mov [si], ax
:0001.2870 895402                 mov [si+02], dx
:0001.2873 8BC7                   mov ax, di
:0001.2875 99                     cwd
:0001.2876 B10C                   mov cl, 0C
:0001.2878 E8D6B8                 call E151
:0001.287B 894404                 mov [si+04], ax
:0001.287E 895406                 mov [si+06], dx
:0001.2881 C7440A0000             mov word ptr [si+0A], 0000
:0001.2886 8BC7                   mov ax, di
:0001.2888 050300                 add ax, 0003
:0001.288B F72E086C               imul word ptr [6C08]
:0001.288F 034604                 add ax, [bp+04]
:0001.2892 D1E0                   shl ax, 01
:0001.2894 C41E486C               les bx, [6C48]
:0001.2898 03D8                   add bx, ax
:0001.289A 268B07                 mov ax, es:[bx]
:0001.289D 89440C                 mov [si+0C], ax
:0001.28A0 8BC7                   mov ax, di
:0001.28A2 40                     inc ax
:0001.28A3 40                     inc ax
:0001.28A4 F72E086C               imul word ptr [6C08]
:0001.28A8 034604                 add ax, [bp+04]
:0001.28AB D1E0                   shl ax, 01
:0001.28AD 8B1E486C               mov bx, [6C48]
:0001.28B1 03D8                   add bx, ax
:0001.28B3 268B07                 mov ax, es:[bx]
:0001.28B6 89440E                 mov [si+0E], ax
:0001.28B9 8BC7                   mov ax, di
:0001.28BB F72E086C               imul word ptr [6C08]
:0001.28BF 034604                 add ax, [bp+04]
:0001.28C2 D1E0                   shl ax, 01
:0001.28C4 8B1E486C               mov bx, [6C48]
:0001.28C8 03D8                   add bx, ax
:0001.28CA 268B07                 mov ax, es:[bx]
:0001.28CD 894410                 mov [si+10], ax
:0001.28D0 8B5EFE                 mov bx, [bp-02]
:0001.28D3 D1E3                   shl bx, 01
:0001.28D5 C7879AAA0000           mov word ptr [bx-5566], 0000
:0001.28DB 8BC7                   mov ax, di
:0001.28DD F72E086C               imul word ptr [6C08]
:0001.28E1 034604                 add ax, [bp+04]
:0001.28E4 D1E0                   shl ax, 01
:0001.28E6 8B1E486C               mov bx, [6C48]
:0001.28EA 03D8                   add bx, ax
:0001.28EC 26C7078F00             mov word ptr es:[bx], 008F
:0001.28F1 8BC7                   mov ax, di
:0001.28F3 40                     inc ax
:0001.28F4 F72E086C               imul word ptr [6C08]
:0001.28F8 034604                 add ax, [bp+04]
:0001.28FB D1E0                   shl ax, 01
:0001.28FD 8B1E486C               mov bx, [6C48]
:0001.2901 03D8                   add bx, ax
:0001.2903 26C7078F00             mov word ptr es:[bx], 008F
:0001.2908 5F                     pop di
:0001.2909 5E                     pop si
:0001.290A 8BE5                   mov sp, bp
:0001.290C 5D                     pop bp
:0001.290D C3                     ret
Post Reply