Friday, August 11, 2017

What is a fake star post?

First, an overview of how star posts work. Each star post in a level is numbered sequentially, more or less according to their relative placement in the level. This number is stored in the star post object's subtype. When an inactive star post is touched, it writes its number to the Last_star_post_hit RAM address. The numbering starts at 1, and 0 serves as a sentinel value meaning "no star posts hit in the current level."

However, a star post's number isn't actually used when respawning the player; all it does is cause every star post with a number lower or equal to Last_star_post_hit already be activated on spawn. Instead, the player's position, as well as a bunch more information, is stored to a backup area in RAM. Note that this is different from the backup area used for big rings, because we still want the player to respawn at the last star post even after entering a Special Stage.
sub_2D164:
    move.b  $2C(a0),(Last_star_post_hit).w
    move.w  $10(a0),(Saved_X_pos).w
    move.w  $14(a0),(Saved_Y_pos).w

Save_Level_Data:
    move.b  (Last_star_post_hit).w,(Saved_last_star_post_hit).w
    move.w  (Current_zone_and_act).w,(Saved_zone_and_act).w
    move.w  (Apparent_zone_and_act).w,(Saved_apparent_zone_and_act).w
    move.w  (Player_1+art_tile).w,(Saved_art_tile).w
    move.w  (Player_1+top_solid_bit).w,(Saved_solid_bits).w
    move.w  (Ring_count).w,(Saved_ring_count).w
    move.b  (Extra_life_flags).w,(Saved_extra_life_flags).w
    move.l  (Timer).w,(Saved_timer).w
    move.b  (Dynamic_resize_routine).w,(Saved_dynamic_resize_routine).w
    move.w  (Camera_max_Y_pos).w,(Saved_camera_max_Y_pos).w
    move.w  (Camera_X_pos).w,(Saved_camera_X_pos).w
    move.w  (Camera_Y_pos).w,(Saved_camera_Y_pos).w
    move.w  (Mean_water_level).w,(Saved_mean_water_level).w
    move.b  (Water_full_screen_flag).w,(Saved_water_full_screen_flag).w
    rts
Here we can see that the code which saves the player's state is split into two sections: first, a bit where the star post's subtype and X/Y position are backed up, falling directly into Save_Level_Data, which backs up everything else. When a level starts, the game checks the value of Last_star_post_hit: if it is non-zero, it initializes everything to the contents of the backup RAM area.

So what is a fake star post? A fake star post is any other code that writes to Last_star_post_hit, saves a custom set of X/Y positions, and then calls Save_Level_Data. There are six such spots in the game, mostly to permanently skip over lengthy cutscenes. All fake star posts in the game occur at the start of the level and set Last_star_post_hit to 1, with the actual star post numbering in those levels starting at 2 instead.

  • The first one occurs in Angel Island 1, when you leave the starting area and enter the main level. This skips over the Knuckles cutscene when playing as Sonic.
  • The next one is in Mushroom Hill 1, but only in Sonic 3 & Knuckles. It happens when the cutscene showing Knuckles leaving the big ring room ends, and skips it on subsequent times.
  • Also in Mushroom Hill 1, but only in standalone Sonic & Knuckles. When Knuckles' intro ends, a star post is activated and the level restarts in order to spawn Knuckles in the main level rather than the intro area.
  • In Mushroom Hill 2, when Sonic and Tails are blasted up into the autumn section of the level. This does end up making a couple of rings permanently missable.
  • In Sky Sanctuary as Sonic and Tails, the same fake star post is activated twice for some reason: once when the bridge off the intro section extends, and another once Knuckles dissappears.

And now, although I've already told you the locations of five of the six fake star posts in the game, I'm delaying the last one over to next week. Sorry about that; as a consolation, please enjoy this video of a cat playing the piano.

No comments:

Post a Comment