Patch:Sprites (Keen 1)

From KeenWiki
Jump to navigation Jump to search

This page lists all the sprites in Keen 1, providing links to their pages. It also contains all the patches that apply to several sprites or cannot be placed under one of the main sprite pages. An extensive tutorial on sprite patching is available at Patch:Patching Vorticon Sprites. Patches that affect many sprites may also be under Patch:Keen (Keen 1) if they are not here.


List of Sprites

These are the sprites in Keen 1, each with their own pages of patches.


Add\Remove Sprites From the Game

This patch allows you to add as many different sprite types as you can find space for in Keen 1, if you can find code space for them. It also allows different patch files (Say Easy, Medium, Hard) to use the same levels and spawn more or less of an enemy, like in Keen Galaxy. First the default patch (No effect on the game) will be listed, then a tutorial where a new sprite is created.


Basic Patch

This patch consists of a number of sections. The first is the core switch statement. This is a rewrite to give us space. It points to section 2, the sprite list. This list uses 10 sprites by default (1 more than the blue $09 in section 1) but it can hold up to 19 as-is. To add a new sprite change that blue value by 1

The second section shows the location of primary sprite code. It is in essence a list. To add a new sprite as a new $xxxxW value to the list. It has space for a maximum of 19 entries.

The third section is the primary sprite code. Notice that each line is located where it says in section 2. (The ice cube code is special.) There are two brown values per line, the second one always points to the same palce. The first one however jumps to the sprites secondary code and will have to be changed when adding new sprites.

The fourth section is the actual sprite spawning code that sets all the sprite variables. This is the last and largest section. What code is used depends on what needs to be set when the sprite is placed. All sprites need their behavior, death behavior, type, and animation set, otherwise they will crash. Different sprites may have their strength, speed and other variables set as well. Each spawn code has three brown values that will need to be adjusted when new sprites are added.

Keen 1

#SECTION 1: Re-write the core switch statement. (Note $168AW is where our sprite list is)
%patch $161D $4B $83 $FB [$09] $76 $0A $81 $FB $FE $00 $0F $84 $A0 $00 $E9 $C1
             $00 $D1 $E4 $2E $D1 $E3 $2E $FF $A7 {$168AW}
#Combine the ice-launchers
%patch $16B1 $D1 $EB $83 $EB $05 $53

#SECTION 2: Locations of primary sprite code
%patch $168A {$1656W} #Yorp
             {$1661W} #Garg
             {$166CW} #Vorticon
             {$1676W} #Butler
             {$1680W} #Tank
             {$16B1W} #Ice Launcher 1
             {$16B1W} #Ice Launcher 2
             {$16B1W} #Ice Launcher 3
             {$16B1W} #Ice Launcher 4
             {$16C1W} #Falling Block

#SECTION 3: Primary sprite spawn code
%patch $1656 $57 $56 $E8 {$0225W}  $83 $C4 $04 $E9 {$008EW} 		#Yorp (Code at $1656 + $225 + $5 = $1880)
%patch $1661 $57 $56 $E8 {$01DDW}  $83 $C4 $04 $E9 {$0083W} 		#Garg (Code at $1661 + $1DD + $5 = $1843)
%patch $166C $57 $56 $E8 {$0164W}  $83 $C4 $04 $EB {$79}			#Vorticon (Code at $166C + $164 + $5 = $17D5)
%patch $1676 $57 $56 $E8 {$00FCW}  $83 $C4 $04 $EB {$6F}			#Butler Bot (Code at $1676 + $FC + $5 = $1777)
%patch $1680 $57 $56 $E8 {$008EW}  $83 $C4 $04 $EB {$65}			#Tank Bot (Code at $1680 + $8E + $5 = $1713)
%patch $16B7 $57 $56 $E8 {$0264W}  $83 $C4 $06 $EB {$2E}			#Ice 4 (Code at $16B7 + $264 + $5 = $1920)
%patch $16C1 $57 $56 $E8 {$021DW}  $83 $C4 $04 $EB {$24}			#Falling block (Code at $16C1 + $21D + $5 = $18E3)

#SECTION 4: Sprite spawning code
#Yorp
%patch $1880 $55 $8B $EC $56 $E8 {$10AEW}  $8B $F0 $C7 $04 [$0002W]  $8B $46 $04 #Sprite type = 2
             $99 $B1 $0C $E8 {$C8BBW}  $89 $44 $04 $89 $54 $06 $8B $46 $06 $99
             $B1 $0C $E8 {$C8ACW}  $05 $00 $08 $83 $D2 $00 $89 $44 $08 $89 $54
             $0A $C7 $44 $32 [$194FW]  $8B $44 $06 $8B $54 $04 $3B $06 $E0 $6E #Start behavior is at $194F
             $7F $0F $7C $06 $3B $16 $DE $6E $73 $07 $C7 $44 $20 [$003CW]  $EB #If left of Keen speed = $3C else is $FFC4 (+\-60)
             $05 $C7 $44 $20 [$FFC4W]  $C7 $44 $34 [$1A68W]  $C7 $44 $28 [$0030W]  #Death at $1A68, start animation = $30 = 48
             $5E $5D $C3

#Garg
%patch $1843 $55 $8B $EC $56 $E8 {$10EBW}  $8B $F0 $C7 $04 [$0003W]  $8B $46 $04 #Sprite type = 3
             $99 $B1 $0C $E8 {$C8F8W} $89 $44 $04 $89 $54 $06 $8B $46 $06 $99
             $B1 $0C $E8 {$C8E9W} $89 $44 $08 $89 $54 $0A $C7 $44 $32 [$1B51W]   #Start behavior at $1B51
             $C7 $44 $34 [$1BCEW] $C7 $44 $28 [$003CW]  $5E $5D $C3              #Death at $1BCE; start animation = $3C = 60

#Vorticon
%patch $17D5 $55 $8B $EC $56 $E8 {$1159W}  $8B $F0 $C7 $04 [$0004W]  $8B $46 $04 #Sprite type = 4
             $99 $B1 $0C $E8 {$C966W} $89 $44 $04 $89 $54 $06 $8B $46 $06 $99
             $B1 $0C $E8 {$C957W} $89 $44 $08 $89 $54 $0A $C7 $44 $32 [$1C0EW]   #Behavior at $1C0E
             $C7 $44 $34 [$1D6EW]  $C7 $44 $24 [$0003W]  $83 $3E $04 $83 {$10} $75 #Death at $1D6E; strength = 3 unless level = $10 = 16
             $05 $C7 $44 $24 [$0068W]  $8B $44 $06 $8B $54 $04 $3B $06 $E0 $6E #THEN strength = $68 = 104
             $7C $0F $7F $06 $3B $16 $DE $6E $76 $07 $C7 $44 $20 [$FFA6W]  $EB #If right of Keen speed = $FFA6 = -90
             $05 $C7 $44 $20 [$005AW]  $C7 $44 $28 [$004EW]  $5E $5D $C3         #Else speed = $5A = +90; start animation = $4E = 78

#Butler Robot
%patch $1777 $55 $8B $EC $56 $E8 {$11B7W}  $8B $F0 $C7 $04 [$0005W]  $8B $46 $04 #Sprite type = 5
             $99 $B1 $0C $E8 {$C9C4W}  $89 $44 $04 $89 $54 $06 $8B $46 $06 $99
             $B1 $0C $E8 {$C9B5W}  $89 $44 $08 $89 $54 $0A $C7 $44 $20 [$005AW]  #Speed = $5A = 90
             $8B $44 $06 $8B $54 $04 $3B $06 $E0 $6E $7F $10 $7C $06 $3B $16
             $DE $6E $73 $08 $8B $44 $20 $F7 $D8 $89 $44 $20 $C7 $44 $32 
         [$1DC7W]  $C7 $44 $34 [$1E94W]  $C7 $44 $28 [$0060W]  $5E $5D $C3         #Behavior $1DC7; death $1E94; animation = $60 = 96

#Tank Robot
%patch $1713 $55 $8B $EC $56 $E8 {$121BW}  $8B $F0 $C7 $04 [$0006W]  $8B $46 $04 #Sprite type = 6
             $99 $B1 $0C $E8 {$CA28W}  $89 $44 $04 $89 $54 $06 $8B $46 $06 $99
             $B1 $0C $E8 {$CA19W} $05 $00 $08 $83 $D2 $00 $89 $44 $08 $89 $54
             $0A $C7 $44 $20 [$005AW]  $8B $44 $06 $8B $54 $04 $3B $06 $E0 $6E #Speed = $5A = 90
             $7F $10 $7C $06 $3B $16 $DE $6E $73 $08 $8B $44 $20 $F7 $D8 $89
             $44 $20 $C7 $44 $32 [$1F75W]  $C7 $44 $34 [$2045W]  $C7 $44 $28     #Behavior $1F75; death $2045
          [$006AW] $5E $5D $C3                                                 #Animation = $6A = 106

#Ice Cubes (Notice only behavior set)
%patch $1920 $55 $8B $EC $56 $E8 {$1057W}  $8B $F0 $C7 $44 $08 [$0003W]  $C7 $44
             $22 [$204AW]  $8B $46 $08 $89 $44 $0A $8B $46 $04 $99 $89 $04 $89 #Behavior $204A
             $54 $02 $8B $46 $06 $99 $89 $44 $04 $89 $54 $06 $5E $5D $C3

#Falling Block Chain
%patch $18E3 $55 $8B $EC $56 $E8 {$104BW}  $8B $F0 $C7 $04 [$0008W]  $8B $46 $04 #Sprite type = 8
             $99 $B1 $0C $E8 {$C858W}  $89 $44 $04 $89 $54 $06 $8B $46 $06 $99
             $B1 $0C $E8 {$C849W}  $89 $44 $08 $89 $54 $0A $C7 $44 $32 [$3360W]  #Behavior $3360
             $C7 $44 $34 [$22BBW]  $C7 $44 $28 [$0072W]  $5E $5D $C3             #Death $22BB; animation $72 = 114

The sprite behavior and death code can be considered section 5 of such a patch; but this is even loner and more complex and is best detailed on each sprite's page. (A list of which can be found at the top of this page.)


Tutorial

This tutorial will show how the above patch can be used to add a new sprite, a second Butler Robot that moves at a different speed, to the game. The patch will be shorter than the one above as default lines do not need to be included. This patch, and all that are built on it is incompatible with all other $0AF2 using patches.

For this patch the free space at $0AF2-$0C50 will be used to store the sprite code. The first and second sections are vital. First we increase the number of possible sprites from $09 to $0A and add a new value to the second section, $0AF2W.

In section 3 we add a new line at that location to point to the new sprite spawning code. The first brown value is easy enough to calculate, our sprite spawn code will be at $0AFD ($0AF2 plus the 11 bytes of patch.) And $0AFD - $0AF2 - $5 = $6. The second brown value is harder, it must point to the same place as all others. To find its value here we take a value from a known location above (Say the Yorp, $008E at $1656) then add the 'old' location and subtract the 'new' location. (In this case $008E + $1656 - $0AF2 = $BF2, this is a larger jump, which makes sense since the patch is further away from the jump location than originally.)

For the sprite spawning code, a copy of the Butler Robot spawning code is used, since it does what we want (Setting a starting speed.) It is important the three brown values be changed in the same way we changed the second brown value in section 2. The sprite type is changed to 9, and the speed to $90 (Fast!) The new sprite will use the same animation anddeath as the original Butler Robot, but will use different behavior.

Keen 1

#SECTION 1: Re-write the core switch statement. (Note $168AW is where our sprite list is)
%patch $161D $4B $83 $FB [$0A] $76 $0A $81 $FB $FE $00 $0F $84 $A0 $00 $E9 $C1
             $00 $D1 $E4 $2E $D1 $E3 $2E $FF $A7 {$168AW}
#Combine the ice-launchers
%patch $16B1 $D1 $EB $83 $EB $05 $53

#SECTION 2: Locations of primary sprite code
%patch $168A {$1656W} #Yorp
             {$1661W} #Garg
             {$166CW} #Vorticon
             {$1676W} #Butler
             {$1680W} #Tank
             {$16B1W} #Ice Launcher 1
             {$16B1W} #Ice Launcher 2
             {$16B1W} #Ice Launcher 3
             {$16B1W} #Ice Launcher 4
             {$16C1W} #Falling Block
             {$0AF2W} #New sprite

#SECTION 3: Primary sprite spawn code
%patch $0AF2 $57 $56 $E8 {$0006W}  $83 $C4 $04 $E9 {$0BF2W} 		#New sprite (Code at $1656 + $225 + $5 = $0AFD)

#SECTION 4: New sprite code
%patch $0AFD $55 $8B $EC $56 $E8 {$1E31W}  $8B $F0 $C7 $04 [$0009W]  $8B $46 $04 #Sprite type = 9
             $99 $B1 $0C $E8 {$D63EW}  $89 $44 $04 $89 $54 $06 $8B $46 $06 $99
             $B1 $0C $E8 {$D62FW}  $89 $44 $08 $89 $54 $0A $C7 $44 $20 [$0090W]  #Speed = $90 = 144
             $8B $44 $06 $8B $54 $04 $3B $06 $E0 $6E $7F $10 $7C $06 $3B $16
             $DE $6E $73 $08 $8B $44 $20 $F7 $D8 $89 $44 $20 $C7 $44 $32 
         [$1DC7W]  $C7 $44 $34 [$1E94W]  $C7 $44 $28 [$0060W]  $5E $5D $C3         #Behavior $1DC7; death $1E94; animation = $60 = 96