Patch:Custom Actions

From KeenWiki
Jump to navigation Jump to search

This page contains a brief tutorial on constructing custom actions for Keen Galaxy sprites. This is part of the Patching Galaxy Sprites tutorial. First a brief description of the structure of an action will be shown before a guide on how to create a custom action from scratch.

Structure of an action

The structure of an action can be seen on the Sprite actions page. It is also reproduced here. Ts shows the location and provides links to explanations of the various components of an action.

Int     Description		Values
Int 0:  Left sprite		Valid animations only
Int 2:  Right sprite		Valid animations only
Int 4:  Action type		0-4
Int 6:  Deprotect		0/1
Int 8:  Stick to ground		0/1
Int 10: Delay (Anim speed)	0-8000
Int 12: H anim move amount	+- any value
Int 14: V anim move amount	+- any value
Int 16: Behavior		Start of behavior codes only
Int 20: Check sprites		Start of check sprite codes only
Int 24: Check tiles		Start of check tile code only
Int 30: Next action		Valid actions only

Custom action

#      Action  Sprite L  Sprite R  Action type  Deprotect  Stick ground  Anim. speed  move H   move V
%patch $2EFDA  [$00E3W    $00E4W]    $0003W       $0000W     $0000W        $0008W       [$0040W]   [$0000W]
               {$0FA80493RL}  {$0FA804BERL}  {$0FA804ECRL}       $0188W
#              Behavior     Collision    Tile interaction  Next action: $2EFF8

Creating a custom action

The first step to creating a custom action is to decide where it will be placed. All actions are placed in the data segment of the game. (For Keen 4 this starts at $2EE70 for example.) The simplest option is simply to completely replace an existing action.

An example would be replacing the Skypest's preening actions. The action's address is at the same location as the Skypest's first preening animation, in this case $31350 the action's address is simply the same as the first preening action's. (In this case $24E0W. This has a side effect however that it will destroy as many actions as it creates.

A more complex approach is to seek space in the executable itself. This is more difficult as it not only requires knowledge of patching but of hex editing as well. In Keen 4 for example significant space can be found at $2EF8F which contains the errors for the Egagraph check, something that should never be used by the game. In this case the action's address is this value less the start of the data segment. ($2EF8F -$2EE70 = $011FW in this case.) This has the advantage that new actions can be created without destroying old ones.

The next step is to create a basic action that has the least chance of causing problems. An example is given below; it uses the standing Keen animations (Which should prevent a cache error in most situations.) and just sits there. The action type is 2 (Don't animate), it's behavior is stunned and its tile collision 'be drawn'

Keen 4

%patch $2EF8F $008EW $008EW $0002W $0000W $0000W $0000W $0000W $0000W
              $09DC16C9RL   $00000000L    $09DC1913RL   $0000W

From this base the action can be inserted into a patch and tested. If it works then it can be tweaked to be more like the required action. (For example the animations can be changed to those desired.) After some practice it will become a simple matter to mostly or completely skip this step and simply construct the action as desired.