# Patch:Level exit

These patches affect what happens when Keen exits a level. Often this is a lot of checks and the loss of some items. For patches related to the actual exit tiles and how they work (for Keen Vorticons), see Patch:Exit_Door. For similar patches, related to when Keen dies and exits a level see Patch:Keen dying (Vorticons). Note that several patches here will occur when Keen dies, while others will necessitate use of death patches.

Broadly speaking all the patches on this page are quite simple, altering what Keen has or does not have when the level is exited. As an example, by default, Keen loses all his keycards\gems when he exits a level. The page is divided into Vorticons and Galaxy\Dreams sections due to the similar way games in a series treat exiting levels.

# Keen Vorticons

In keen Vorticons the main way to exit the level is run when the player contacts the exit door tiles, a special kind of tile. The player can also exit via death, or via the teleporter.

## Level state variable

The level state variable controls was 'mode' the game is in. There are four possible modes in Vorticons, normal, exiting, teleporting and Tantalus. In order these are normal gameplay; exiting and winning the level; teleporting to the secret level on the map; and flipping the Tantalus switch thereby causing a Game Over. All four of these modes are set in the game.

There are three other references to the level state as well; two of these are checks in the main gameplay loop to see if normal gameplay should be exited. The third tracks the level state for other uses.

 Patch: Keen 1 #Level state on exiting level %patch $41EE$C7 $06$6C60W $0001W #Level state when teleporting %patch$4572 $C7$06 $6C60W$0002W #Level state after flipping a Tantalus switch %patch $36B3$C7 $06$6C60W $0003W #Set level state to 0 after exiting a level %patch$4BCC $6C60W #Check level state when running game to teleport %patch$4F2E $6C60W$00 $75 #Check level state when dying and removing parts %patch$4F60 $6C60W$00 $75 #Level state -unknown %patch$4FA1 $6C60W  Patch: Keen 2 #Keen 2 exit level variable %patch$7030 $C7$06 $6C3CW$0001W

 Patch: Keen 3 #Keen 3 exit level variable %patch $7894$C7 $06$6E8CW $0001W ## Exiting levels and keycards This is the default code responsible for removing all of Keen's keycards when he dies or exits the level. The brown value is the game stat to start at, the first blue value is what it is set to, and the second blue value the number of following stats to also set. By default then the game sets Keen's yellow card and the following three variables (red, blue and green cards) to zero on level exit. Changing the first value to 1 makes the game give Keen all the cards while making the second value 0 doesn't affect cards at all.  Patch: Keen 1 #Default keycard code %patch$4F43 $C7$46 $FC$0000W $EB$0E $8B$5E $FC$D1 $E3$C7 $87$AA9EW $0000W$FF $46$FC $83$7E $FC$04 $7C$EC

 Patch: Keen 2 #Default keycard code %patch $7C9A$C7 $46$FC $0000W$EB $0E$8B $5E$FC $D1$E3 $C7$87 $9AB4W$0000W $FF$46 $FC$83 $7E$FC $04$7C $EC  Patch: Keen 3 #Default keycard code %patch$8617 $C7$46 $FC$0000W $EB$0E $8B$5E $FC$D1 $E3$C7 $87$9D1EW $0000W$FF $46$FC $83$7E $FC$04 $7C$EC

### Change several things instead of keycards on level win

There is a more efficient way to change variables on level exit; the following code sets six things to zero, with space for a seventh. In this case all of Keen's keycards, plus his ammo, plus his pogo are set to 0 on level exit. In the patch $31$C0 means 'zero'; the brown values are in the following order, keycards, pogo, ammo.

Note that as a side effect of this patch, these things are not altered when Keen exits the level by dying or using the teleporter. This can break the game. To reenable losing keycards on death see Patch:Keen dying (Vorticons), though the patches there have side effects also.

 Patch: Keen 1 #Set ammo, pogo and all keycards to zero after exiting each level %patch $4F43$31 $C0$A3 $AA9EW$A3 $AAA0W$A3 $AAA2W$A3 $AAA4W$A3 $AA9AW$A3 $AAC8W$EB $05 #### Examples These three examples show how the above patch can be altered. In the first$31 $C0 has been changed to$B8 $0001W$50, meaning that now Keen will be given all keycards, 1 pogo and 1 ammo on level exit. Notice that $EB$05 has been decreased by two to fit the bigger patch. (Note it is possible to add one more variable here, changing the final two bytes to $EB$00.)

 Patch: Keen 1 example 1 #Set ammo, pogo and all keycards to 1 after exiting each level %patch $4F43$B8 $0001W$50 $A3$AA9EW $A3$AAA0W $A3$AAA2W $A3$AAA4W $A3$AA9AW $A3$AAC8W $EB$03

The second example decreases the number of things changed, in this case not affecting Keen's pogo or ammo, just his keycards. This is done by removing two $A3$xxxxW game stats and increasing $EB$05 by six (2x3)

 Patch: Keen 1 example 2 #Set all keycards to 1 after exiting each level %patch $4F43$31 $C0$A3 $AA9EW$A3 $AAA0W$A3 $AAA2W$A3 $AAA4W$EB $0B The third example just alters Keen's ammo to 0 on level exit.  Patch: Keen 1 example 3 #Let Keen keep keycards when exiting a level, and set his shots to zero: %patch$4F43 $31$C0 $A3$AAC8W $EB$14

## Change things when Keen exits levels

This patch is more versatile as it works when Keen exits the level via winning, teleporter or death. However it can only set two variables, and then only to 0. (It can set one variable to a nonzero value however.) It works similarly to the keycard patches above, the two brown values in this patch are Keen's ammo and pogo, but this can be changed.

The second line makes this patch work when Keen exits a level via the teleporter, removing it means Keen will not be affected by this patch if he exits the level via teleporting. It also means that that line should be removed if using the in-level teleporters patch, with which it is obviously incompatible.

 Patch: Keen 1 #Set pogo AND ammo to 0 when Keen exits levels %patch $55EF$EB $4A$33 $C0$A3 $AAC8W$A3 $AA9AW$A3 $6EC0W$C3 %patch $7D01$E8 $D8EDW$90 $90$90

## Affecting Ship parts

These are the levels the parts are found in by default. If Keen dies in these levels after getting a part, the part will be removed, thus preventing Keen from getting a part and not completing the level. This can come as a shock to modders who find parts they have 'disappearing' when they die in a custom level.

It is possible to make more than one level remove a part on death by altering the brown jumps in the first set of patches, though care is required. Changing the level to something 'impossible' such as level 100 will mean that no level Keen can enter in the game will remove his ship parts. (Or there is a patch to ignore ship part removal entirely.)

This patch can be modified so that Keen loses other things in special levels, like his ammunition. It can also be altered to give Keen things. Only one thing can be changed per level. See also Patch:Ship Parts

 Patch: Keen 1 parts level stuff #Parts levels (Part removed if you die in this level) %patch $4F69$0008W $74 #Joystick %patch$4F70 $0003W$74 #Battery %patch $4F75$0004W $74 #Vacuum %patch$4F7C $0010W$74 #Whiskey #What happens in special levels; set brown to value blue %patch $4F8C$AA94W $0000W #Joystick %patch$4F84 $AA9CW$0000W #Battery %patch $4F94$AA96W $0000W #Vacuum %patch$4F9C $AA98W$0000W #Whiskey

 Patch: #Don't ever remove Keen's ship parts %patch $4F73$EB

## Keycards exit the level

These three patches cause Keen to exit the level when he obtains a keycard. The first patch simply fuses the two tile codes. When Keen obtains a keycard the exit door code is run, including the sound and the alteration of level tiles. This will only happen if Keen is standing on ground however, in midair the keycard will simply vanish and play the keycard sound. (This can be used to create two different types of keycard.)

The second patch is identical, except Keen can exit in midair and using the keycard got sound. This means all keycards will exit the level. Again the exit door tile changes will occur.

The third patch simply wins the level when the keycard is obtained. The game will pause for a short while while the keycard sound plays, then the level will be exited and won. The keycard itself will not vanish, unlike in the previous two patches.

 Patch: Keen 1 #Keycards call exit code after got %patch $4529$A8

 Patch: Keen 1 #Keycards make Keen exit walk when got %patch $4529$BC

 Patch: Keen 1 #Keycards make Keen win the level when got %patch $4513$C7 $06$6C60W $0001W$EB $5C # Keen Galaxy\Dreams In Keen Galaxy exiting the level is very closely related to the 'level state'. The level state is a value in memory that gives the current 'state' of the level. Each tick of game scan this is read and something done. Usually he level state is zero, if it is not then normal level gameplay is disrupted. This is usually some manner of exiting the level. ## Keen 4 ### Level State Pointer List This is a pointer list that takes the value of the level state and decides what to do. Most of the results involve ending the level in some manner. Some of these options will do things such as taking lives from the player or running a game over. It is possible to insert custom codes and values, allowing interesting things to happen. It is also possible for the level state to change rapidly in succession; the 'Didn't make it past' window is triggered when the state is 1, and then proceeds to change the state to 2 or 5 depending on the player's choice. The 'complete level' code wins the level, marking it as done on the map. The 'Change level' moves Keen to another level without marking the 'old' level as done. (This is what moves Keen to the map when he quits a level.) The 'restart level' code begins the level again, clearing e.g. Keen's gems, but does not take a life from Keen. The council member message code is also the code that wins the game, disabling it will make the game unwinnable unless another patch is used. The 'high scores' code is used when the game is quit, game over occurs or the game is won. It allows the player to enter a high score if they have one. Certain level states appear to be the same as others, for example both exiting a level normally and getting the Foot will win the level, but the Foot will also trigger the Foot-on-map sequence.  Patch: Keen 4 #Location of state list %patch$6AAA $0F81W #At$6BC1 #Length of list %patch $6A9F$0C #Level state list (Offset 5C40) %patch $6BC1$0E71W #Didn't make it past (At $6AB1) %patch$6BC3 $0EDEW #Complete level (At$6B1E) %patch $6BC5$0E78W #Council Member (At $6AB8) %patch$6BC7 $0F5CW #Load new level (At$6B9C, don't lose a life) %patch $6BC9$0D8CW #Change level (At $69CC) %patch$6BCB $0E06W #Slow motion ON (At 6A46) %patch$6BCD $0EDEW #Complete level (At$6B1E; used when Keen gets the Foot) %patch $6BCF$0F54W #Go to high scores, finish game (At $6B94) %patch$6BD1 $0F5CW #Restart level (At$6B9C) %patch $6BD3$0F5CW #Restart level (At $6B9C) %patch$6BD5 $0F5CW #Restart level (At$6B9C) %patch $6BD7$0F5CW #Restart level (At $6B9C) %patch$6BD9 $0EDEW #Complete level (At$6B1E)

#### Council Members win the game

This patch alters the third level state pointer to go straight to the win game code, not displaying the member windows. This means rescuing just one member will immediately trigger winning the game.

#### Oracle Janitor wins the level

This patch changes things so that instead of vanishing the Janitor wins the level. Keen will not however be credited with saving a member. This patch works by changing the level state to 2, or 'win level'. Changing that value to other things can result in Keen doing things like losing the level or getting a Wetsuit.

 Patch: Keen 4 #Oracle Janitor wins level %patch $CD9E$C7 $06$7A70W $0002W$90 $90$90

#### Being eaten by Dopefish wins the game

This patch makes Keen win the game when he is eaten by a Dopefish. It works by making a new level state that wins the game and then changing the level state in eaten Keen's behavior to that instead of 1.

 Patch: Keen 4 #Being eaten wins the game %patch $6BD9$0EB2W %patch $12120$000DW

### Level state code

These patches are the entire code for various level states. (That is the code run whenever the level state is set to something.)

#### State 2, 7 or 13: Complete level

This code is run in several circumstances, all of which result in Keen completing the level and returning to the map. Primarily this involves walking off the left or right sides of the level, but also occurs when Keen acquires the Wetsuit or uses the F10 E Cheat.

This code is slightly tricky as it runs into other pieces of code and also does different things in different circumstances.

## Keen 5

### Level State Pointer List

This is a pointer list that takes the value of the level state and decides what to do. Most of the results involve ending the level in some manner. Some of these options will do things such as taking lives from the player or running a game over. It is possible to insert custom codes and values, allowing interesting things to happen. It is also possible for the level state to change rapidly in succession; the 'Didn't make it past' window is triggered when the state is 1, and then proceeds to change the state to 2 or 5 depending on the player's choice.

The 'complete level' code wins the level, marking it as done on the map. The 'Change level' moves Keen to another level without marking the 'old' level as done. (This is what moves Keen to the map when he quits a level.) The 'restart level' code begins the level again, clearing e.g. Keen's gems, but does not take a life from Keen. The win game code wins the game, disabling it will make the game unwinnable unless another patch is used. The 'high scores' code is used when the game is quit, game over occurs or the game is won. It allows the player to enter a high score if they have one.

 Patch: Keen 5 #Location of state list %patch $6A6B$0F62W #At $6BC1 #Length of list %patch$6A60 $0E #Level state list (Offset 5C10) %patch$6B72 $0E62W #Didn't make it past (At$6A72) %patch $6B74$0EBEW #Complete level (At $6ACE) %patch$6B76 $0F3CW #Restart level (At$6B4C) %patch $6B78$0F3CW #Restart level (At $6B4C) %patch$6B7A $0D77W #Restarts level but unknown (At$6987) %patch $6B7C$0DF1W #Re-center screen (At $6A01) %patch$6B7E $0EBEW #Complete level (At$6ACE) %patch $6B80$0F34W #Go to high scores (At $6B44) %patch$6B82 $0F3CW #Restart level (At$6B4C) %patch $6B84$0F3CW #Restart level (At $6B4C) %patch$6B86 $0F3CW #Restart level (At$6B4C) %patch $6B88$0F3CW #Restart level (At $6B4C) %patch$6B8A $0EBEW #Complete level (At$6ACE) %patch $6B8C$0E69W #Smash fuse dialogue (At $6A79) %patch$6B8E $0E95W #Win game (At$6AA5)

#### State 2, 7 or 13: Complete level

This code is run in several circumstances, all of which result in Keen completing the level and returning to the map. Primarily this involves walking off the left or right sides of the level, but also occurs when Keen uses the F10 E Cheat.

This code is slightly tricky as it runs into other pieces of code and also does different things in different circumstances.

### When level states are changed

This is an incomplete list of when level states are changed in Keen 5 and to what they are changed to. It thus affects many things.

 Patch: Keen 5 #Unknown, checks for demo mode %patch $7448$0002W #When F10-E cheat is used %patch $7471$0002W #When Keen walks left\right out of a level %patch $8646$0002W #When E-N-D cheat is used %patch $90A6$000FW #When Keen smashes a Fuse\Q.E.D. %patch $FFD0$000FW #In level 12 %patch $FFD8$000EW #In other levels

## Keen 6

### Level State Pointer List

This is a pointer list that takes the value of the level state and decides what to do. Most of the results involve ending the level in some manner. Some of these options will do things such as taking lives from the player or running a game over. It is possible to insert custom codes and values, allowing interesting things to happen. It is also possible for the level state to change rapidly in succession; the 'Didn't make it past' window is triggered when the state is 1, and then proceeds to change the state to 2 or 5 depending on the player's choice.

The 'complete level' code wins the level, marking it as done on the map. The 'Change level' moves Keen to another level without marking the 'old' level as done. (This is what moves Keen to the map when he quits a level.) The 'restart level' code begins the level again, clearing e.g. Keen's gems, but does not take a life from Keen. The win game code wins the game, disabling it will make the game unwinnable unless another patch is used. The 'high scores' code is used when the game is quit, game over occurs or the game is won. It allows the player to enter a high score if they have one.

 Patch: Keen 6 #Location of state list %patch $689B$0F80W #At $6990 #Length of list %patch$6890 $0C #Level state list (Offset 5A10) %patch$6990 $0E92W #Didn't make it past (At$68A2) %patch $6992$0EC4W #Complete level (At $68D4) %patch$6994 $0F44W #Restart level (At$6954) %patch $6996$0F44W #Restart level (At $6954) %patch$6998 $0DADW #Loose level (At$67BD) %patch $699A$0E27W #Re-center screen (At $6837) %patch$699C $0EC4W #Complete level (At$68D4) %patch $699E$0F3BW #Goto highscores (At $694B) %patch$69A0 $0EA0W #Get Sandwich (At$68B0) %patch $69A2$0E99W #Get Rope (At $68A9) %patch$69A4 $0EA7W #Get Rocket Pass (At$68B7) %patch $69A6$0EAEW #Molly (Win game) (At $68BE) %patch$69A8 $0EC4W #Complete level (At$68D4)

### Level state code

These patches are the entire code for various level states. (That is the code run whenever the level state is set to something.)

#### State 2, 7 or 13: Complete level

This code is run in several circumstances, all of which result in Keen completing the level and returning to the map. Primarily this involves walking off the left or right sides of the level, but also occurs when uses the F10 E Cheat.

This code is slightly tricky as it runs into other pieces of code and also does different things in different circumstances.

The first segment of code deals with completing the level. On the first line the game checks if 'mapon' ($A97BW) is zero. This is complex, but basically if Keen is on the map level (Level 0) the game skips to the One Moment Window. (This is most easily seen by going to the map and using the F10 E Cheat. This is because if Keen is in the same level as his destination (That is, the map) no level entry text will appear, leaving the screen blank. Otherwise sound 13 is played (This can be stopped by replacing the bytes$B8 $000DW with$EB $0A$90.) On the next line the current level is set to 0 (The map, this means later when the level is reloaded, the map level will be loaded.) On the third line the level is marked as done in memory. ($7556W is the memory address of level 0, this plus current level is marked as done. Setting this to 0 will stop any levels being marked as done.) On the same line the 'demo switch' is checked ($75AEW) and if this is zero the code jumps to 'load new level' (The same code used for level state = 4) If not, then mapon ($A97BW) is checked (Again) and if it is 2 then again the code jumps to 'load level' The net result of this is that if Keen is playing in demo mode he will end the game and got to the high scores when he exits a level. The second section is the One Moment Window that almost never appears but is included for completeness. Is is a$08x$1A sized window that reads text from D.S:$02CF ($30FFF, see Patch:Text patches.) At the end of the window code is a small jump over some other code to the same location as the 'complete level' code, the 'load new level' code. This causes the map level to be reloaded.  Patch: Keen 6 #Win level code %patch$68D4 $83$3E $A97BW$00 $74$3D $B8$000DW $50$9A $183B09F1RL #If level 0, skip, play sound$83 $C4$02 $C7$06 $75A4W$0000W $A1$A97BW $A3$A950W $8B #Set current level = 0$1E $A97BW$D1 $E3$C7 $87$7556W $0001W$83 $3E$75AEW $00 #Mark level done, check demo$74 $4E$83 $3E$A97BW $02$75 $47$9A $141308A9RL$5F $5E #If demo end game, highscores$5D $CB$EB $3C$8B $36$A942W $A1$A940W $A3$A942W $B8 #Display 'One Moment' window$0008W $50$B8 $001AW$50 $9A$18F81070RL $83$C4 $04$83 $06$A6C3W $19$B8 $02CFW$50 $9A$18F80EBDRL $83$C4 $02$89 $36$A942W $EB$0B $EB$09

#### State 9: Get Sandwich

The code for level state 9 is quite simple; the Sandwich window code is called then the game jumps to the 'win level' code.

#### State 11: Get Rocket Pass

The code for level state 11 is quite simple; the Rocket Pass window code is called then the game jumps to the 'win level' code.

 Patch: Keen 6 #Level state 11 code - get Rocket Pass %patch $68B7$9A $0E420B18RL$EB $16 #### State 12: Find Molly, win game The code for level state 12 is relatively simple but more complex than the other item's codes. Three (currently unknown) calls are made to various segments of code and the game then jumps to the end of the level state code. (As the game is won.) The last call,$9A $0DBE0702RL displays the game won ending text (as well as taking care of things such as the background music.)  Patch: Keen 6 #Level state 12 code - Find Molly %patch$68BE $0E$E8 $F158W$9A $1608012ARL$9A $1CF709A3RL$9A $0DBE0702RL$E9 $008EW ## Keen Dreams ### Level State Pointer List This is a pointer list that takes the value of the level state and decides what to do. Most of the results involve ending the level in some manner. Some of these options will do things such as taking lives from the player or running a game over. It is possible to insert custom codes and values, allowing interesting things to happen. It is also possible for the level state to change rapidly in succession. The Keen Dreams pointer list is the simplest of all Galaxy-type games. Currently it is unsure exactly what each value does. The second value will complete a level, returning Keen to the map. The last value wins the game, this simply pauses the action for a time then runs the ending sequence.  Patch: Keen Dreams #Location of state list %patch$5DF1 $19ADW #At$5E7D #Length of list %patch $5DE9$04 #Level state list (Offset 44D0) %patch $5E7D$19A7W #Do nothing (At $5E77) %patch$5E7F $1929W #Complete level (At$5DF9) %patch $5E81$183DW #Normal game state? (At $5D0D) %patch$5E83 $1923W #Didn't make it past? (At$5DF3) %patch $5E85$1956W #Win game (At $5E26) ### State 1: Complete level This is the complete code for state 1, winning the level. On the first line the game checks whether Keen is on the map. If so it skips playing the complete level sound,$0D. On the second line it marks a level as done, changing a variable relative to level 0's stat. Finally on line 3 the game again checks to see whether Keen is in the map and, if not, the current level variable is set to 0 (The map) and the level reloaded, effectively moving Keen back to the map.

 Patch: Keen Dreams #Complete level code %patch $5DF9$83 $3E$8F3EW $00$74 $0B$B8 $000DW$50 $9A$10BB1282RL $44$44 $8B$1E $3E$8F $D1$E3 $C7$87 $70F2W$0001W $83$3E $8F3EW$00 $74$0E $C7$06 $7124W$0000W $EB$06

### State 4: Lose level

This is the complete code for state 4, losing the level. It is exceedingly simple, simply calling the You didn't make it past window. This lets the player choose if they want to retry the level or exit to the map. It also checks for a game over, skipping the window code if this is the case. (The actual game over code occurs after the jump at the end of the code here and occurs if the player has run out of lives.)

 Patch: Keen Dreams #Lose level code %patch $5DF3$0E $E8$FBD4W $EB$33

### Level Keen goes to on exiting level

When Keen wins a level he returns to the map by default, but this can be changed. This will cause Keen to enter a regular level. (Keen will then be stuck in that level as exiting will return him to it. Only death will return him to the map.)

 Patch: Keen Dreams #Level Keen goes to on exiting level (Map) %patch $5E22$0000W

### Keen goes to the next level on winning, not the map

This patch alters the 'complete level' code so that Keen plays the next level instead of returning to the map. He will do this until the game runs out of levels, whereupon it will crash. The blue value is the 'complete level' sound.

The second patch is identical, however on exiting level 16 ($10) the game will be won, preventing a crash.  Patch: Keen Dreams #Keen goes to the next level instead of the map - no max level %patch$5DF9 $FF$06 $7124W$B8 $000DW$50 $9A$10BB1282RL $44$44 $EB$22 #Keen goes to the next level instead of the map -max level is level 15 %patch $5DF9$83 $3E$7124W $10$73 $26$FF $06$7124W $B8$000DW $50$9A $10BB1282RL$44 $44$EB $1B ## What happens when Keen leaves the level top or bottom In Keen Galaxy the level is 'lost' if the player sprite falls out of the bottom or top of the level. What actually happens is that the level state is set to 1, which as noted above causes the level to be lost. This is an exception to the usual state of affairs which removes a sprite that leaves the level. If this was the case for the player a 'tried to remove the player' error would result. The check involved is that of the sprite's type with payer types (Type 2) triggering level loss rather than removal. See also Patch:Jump conditions.  Patch: Keen 4 #Sprite type that triggers level loss %patch$8FFC $02$75 #Level state set %patch $9003$0001W

 Patch: Keen 5 #Sprite type that triggers level loss %patch $8F6E$02 $75 #Level state set %patch$8F6E $0001W  Patch: Keen 6 #Sprite type that triggers level loss %patch$8DD6 $02$75 #Level state set %patch $8DDD$0001W