don't click here

MoDule's bugfix guides Vol. 1

Discussion in 'Engineering & Reverse Engineering' started by MoDule, May 16, 2011.

  1. MoDule

    MoDule

    Tech Member
    327
    24
    18
    Procrastinating from writing bug-fix guides
    During my hacking escapades I tend to be reminded of bugs I've known for a long time. Sometimes I can find their sources and try to fix them. Here's a few guides I put together for common bugs I haven't seen fixed anywhere.

    How-to:Fix bugs relating to Super Sonic
    This is a big one. Here you'll find fixes for a whole bunch of Super Sonic related bugs, the most important one being the one where you get stuck in the air after completing a level. Most of the others are mostly cosmetic, but do make the game behave the way it was supposed to.

    How-to:Use correct height when roll jumping
    I posted about this before. Basically, when you jump while rolling Sonic might jerk upward a few pixels upon landing. When this happens you can't jump until he lands again. This one has been annoying me for a while.

    How-to:Fix jump height bug when exiting water
    This one's been bothering me ever since I was a kid. Sometimes when you try to jump out of water Sonic only jumps really low. After I finally figured out what causes it, fixing it was pretty easy.

    I also added explanations of every bug for your reading pleasure.
    This should hopefully be educational.

    There's more to come, I've just spent multiple hours writing these and it's really late.

    Edit: Next batch:

    How-to:Fix camera y position for Tails
    This one's always really bothered me and I don't even use Tails that often. The camera's vertical position is pretty jerky for Tails. The way this fix is done, no special code will ever be necessary to handle the character changing height, at least as far as the camera is concerned.

    How-to:Fix bug in ARZ Boss arrow's platform behavior
    Not that noticeable or problematic, but it's still nice to have it fixed. The arrows that the ARZ boss fires trigger the walking in air bug that happens when Sonic doesn't get released from a platform properly.

    How-to:Collide with water after being hurt
    When Sonic gets hurt he doesn't interact with the water surface. I put this one down as a design choice, since it's debatable weather the original behavior was intentional or not. The Advance series indicates that at least one person thought it wasn't.
     
  2. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    Nice to see these all collected, it should really help the beginners.

    I did spot an error in your error correction guides: in the Super Sonic part, on the deceleration bug, you substitute a value that is too low (3) compared to what it is for normal Sonic (6).
     
  3. Travelsonic

    Travelsonic

    Member
    822
    17
    18
    Hello Sonic CD's Tidal Tempest Zone - the only place where I've noticed it, bugs the living hell out of me.
     
  4. ICEknight

    ICEknight

    Researcher Researcher
    Thanks for posting those. The explanations were a nice read even for those of us who haven't worked much with disassemblies.

    Are you going to include any Sonic 3 fixes? I hope somebody can eventually fix those annoying moonjumps when Sonic gets off the underwater rotating cylinders.
     
  5. MoDule

    MoDule

    Tech Member
    327
    24
    18
    Procrastinating from writing bug-fix guides
    Fixed, thanks. For some reason I thought 6 was the normal value and divided that by 2.

    Me, too. You can't imagine my joy when I finally figured out what was causing it.

    Thanks, that's what I was going for. I like for people to understand what's going on rather than just giving a series of instructions. Especially in the case of the water jump height bug I wanted to show just how convoluted the whole thing is.

    Some of these do also apply to Sonic 3, I just haven't written the specific code yet. As for the rotating cylinders, it's essentially the same bug as with anything that changes your speed under water, so it should be really easy to fix.
     
  6. LOst

    LOst

    Tech Member
    4,891
    8
    18
    Nice read MoDule! I have suffered from the low jump out of water many times in my simulator(s), where the water height causes my Knuckles player troubles as his jump height is already low, it is almost impossible to jump out of the water.

    I am a little scared of applying any fixes regarding the stand/roll difference change, as changing those causes other things to go crazy. A new way of handling the difference (that 5 pixels offset change on Y pos) was introduced in Sonic 3 to fix the Sonic 2 spindash bug (when spindashing, and aborting the spindash during the charge, either by jumping and releasing direction at the right moment (causing the player to jump straight up in the air), or spindashing directly against a wall), the player get stuck 5 pixels into the ground. This fix must be applied before applying any other fixes regarding that area, or your fixes are not Sonic 3 compatible. In Sonic 3, the SST bytes $44 and $45 holds the original bounding box (I have never seen them change, so I call them original values, however, knowing Sonic 3, they are probably changed at some point from some other object dusing some special moment, BUT ANYHOW they can be hardcoded in Sonic 1 and 2), and when the player is restored from rolling state, look what they do.

    + - Nice to see some bug fixes that are actually bug fixes, and not prefered-by-some-guy fixes (roll jumping enable direction controls because I like it, have no idea game might actually break because of it), nor Sonic-was-supposed-to-do-this-because-I-can-program-asm fixes (jumping with angle forces in S1 special stage), nor fixes-changing-the-original-play-is-not-meant-to-be (spindash rev counter overflow, sure a mistake in the code, but changing that now will mess up the timings of every level designed for the original behaviour). Very sorry you guys who I directly said my opinion against without naming you. MoDule is doing a great job, nailing the real issues of the Sonic player, bringing them up like this.  
     
  7. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    $44 and $45 are the standing half-height and half-width; I can attest that they are only ever set during player initialization, and are henceforth ever only read from. I know this by two different routes: 1) a couple years ago, I wrote a minor LUA script which I used in Gens rerecording to track changes to SST variables for Sonic and Tails, and proceeded to test all objects with it, trying to find more TAS-worthy bugs; 2) more recently, I went through the S3&K SVN disassembly and checked that these 2 are only written to at initialization or when the memory written to is neither Sonic's/Knuckles' nor Tails'.

    As for the rest, do you mean plain S3? Because I tested MoDule's in S3&K and it did not show the behavior you mentioned (with or without the fix).

    Hrm. Maybe I should contribute my own fix to the infamous spindash cancel bug when you spindash at the edges of the camera...
     
  8. MoDule

    MoDule

    Tech Member
    327
    24
    18
    Procrastinating from writing bug-fix guides
    I just checked s3k again, because I couldn't reproduce the height bug. Just to be sure I checked the disassembly and found that the bug is technically still unfixed, but it's circumvented. Instead of moving Sonic by a fixed amount when he lands the game calculates the difference from the current height and default height and uses that. So, in s3k it's not an essential fix.
     
  9. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    That is what LOst said, basically; what I was saying is that your fix did not cause any of the issues he feared. There is a benefit to using your fix anyway, though: the character's hitbox will be the correct size when jumping from rolling, instead of suddenly increasing to standing hitbox.
     
  10. Master3k

    Master3k

    Member
    278
    0
    0
    I love you.

    Can those be applied to Sonic 1, though (except the roll jump one, as Sonic 1 doesn't use this standing height thing)? Or these glitches are present only on S2? Just wondering.
     
  11. MoDule

    MoDule

    Tech Member
    327
    24
    18
    Procrastinating from writing bug-fix guides
    The code looks identical, save for the different styles between disassemblies, so yes, I think so.
     
  12. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    MoDule: do you mind if I add another Super Sonic bug fix to your collection? There is one more bug related to end-of-level transformation that still happens even with the S3&K fix. This bug requires more bad luck than anything, but it does happen: if you trigger the transformation on the very same frame when the timer is stopped by the signpost, Sonic will begin transforming and get stuck on air again. This happens because Sonic's object code runs before the collision with the signpost is checked; thus, the transformation will begin and then be halted when the signpost code runs and stops the timer. But since the transformation never ends, the object control flags are still set and Sonic still gets stuck on air.

    If you are wondering: the same issue happens in S3&K if you trigger the transformation at the very same frame when Tails hits the boss (either act) the final time. It is even rarer, but it has happened.
     
  13. MoDule

    MoDule

    Tech Member
    327
    24
    18
    Procrastinating from writing bug-fix guides
    Never knew about that one, but it makes sense.
    By all means, add to the guide! I was hoping to get people interested, so this certainly helps.
     
  14. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    After looking a bit more into it, I see that the bug I mentioned is S3&K-specific -- it is not possible to trigger it in S2 unless you have a hack that either enables Tails to end the level or enables multiple characters to trigger the transformation, in which case you will need special code to prevent graphical glitches. I will make an entry at the S3&K section about the bug.

    In any case, the fix for the screen boundary spindash bug is done.
     
  15. MoDule

    MoDule

    Tech Member
    327
    24
    18
    Procrastinating from writing bug-fix guides
    It actually is possible in s2; Tails can end a level with the prison capsule. Although it's almost impossible to trigger without debug mode and not game breaking, since Sonic doesn't need to move after that.
    I've found a sort-of fix for this. I'm not quite satisfied, because for some reason it makes Sonic's transformation animation play twice. Go to Sonic_RevertToNormal and add these two lines at the beginning:
    Code (ASM):
    1.     cmpi.b  #1,(Super_Sonic_palette).w
    2.     beq.s   return_1AC3C
    This makes sure Sonic's revert code doesn't interrupt the transformation sequence.

    Nice work on the guide, btw.
     
  16. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    The fix I have for that Super Sonic problem is this: find Sonic_RevertToNormal and modify the code so that this:
    Code (ASM):
    1. Sonic_RevertToNormal:
    2.     move.b  #2,(Super_Sonic_palette).w  ; Remove rotating palette
    3.     move.w  #$28,(Palette_frame).w
    4.     move.b  #0,(Super_Sonic_flag).w
    5.     move.b  #1,next_anim(a0)    ; Change animation back to normal ?
    6.  
    becomes this:
    Code (ASM):
    1. Sonic_RevertToNormal:
    2.     tst.b   (Super_Sonic_palette).w     ; Are we interrupting a transformation to Super Sonic?
    3.     bmi.s   +               ; branch if not
    4.     move.b  #0,obj_control(a0)      ; restore Sonic's movement if yes
    5.     bra.s   ++              ; Do not change current palette index, which will be less than $28
    6. +
    7.     move.w  #$28,(Palette_frame).w      ; Fade out from Super Sonic palette
    8. +
    9.     move.b  #2,(Super_Sonic_palette).w  ; Remove rotating palette
    10.     move.b  #0,(Super_Sonic_flag).w
    11.  
    This restores normal movement from an unfinished transformation (Super_Sonic_palette >= 0 means the transformation hasn't finished). It changes the code to also fade out from super palette only if it is needed: it fades from current palette index instead of flashing to full super palette before fading. This works because Palette_frame is less than $28 if Super_Sonic_palette >= 0. The next_anim line can be (and was) removed without any ill effects; all it does is reset the animation (except for the running animation, which is not reset).

    "next_anim" is a misnomer, by the way; "prev_anim" or "last_anim" are better names: if you look at Sonic_Animate, you will see that if anim(a0) != next_anim(a0), then next_anim(a0) is set to anim(a0) and the animation is reset. This clearly is not the behavior you expect from the name.
     
  17. MoDule

    MoDule

    Tech Member
    327
    24
    18
    Procrastinating from writing bug-fix guides
    Hmm, removing that next_anim line fixes my fix. I also moved it up to Sonic_Super, which has the added effect of delaying Super Sonic's ring drain until his transformation is done. Here it is:
    Code (ASM):
    1. ; loc_1ABA6:
    2. Sonic_Super:
    3.     tst.b   (Super_Sonic_flag).w    ; Ignore all this code if not Super Sonic
    4.     beq.w   return_1AC3C
    5.  
    6.     cmpi.b  #1,(Super_Sonic_palette).w  ; <-- is Super Sonic's transformation sequence finished?
    7.     beq.s   return_1ABA4            ; if not, branch
    8.  
    9.     tst.b   (Update_HUD_timer).w
    10.     beq.s   Sonic_RevertToNormal ; ?
    11.  
    12.     [...]
    13.  
    14. ; loc_1ABF2:
    15. Sonic_RevertToNormal:
    16.  
    17.     move.b  #2,(Super_Sonic_palette).w  ; Remove rotating palette
    18.     move.w  #$28,(Palette_frame).w
    19.     move.b  #0,(Super_Sonic_flag).w
    20. ;   move.b  #1,next_anim(a0)    ; <-- Change animation back to normal ?
     
  18. Eduardo Knuckles

    Eduardo Knuckles

    Not a loved one, but the most hated person. Banned
    414
    10
    18
    Someplace somewhere
    Project S.A.M.G.
    Is there any Hivebrain disassembler's version of these guides? They are greatly useful, but I'm not using the SVN source and I'm too lazy for convert the values.
     
  19. Mercury

    Mercury

    His Name Is Sonic Tech Member
    1,740
    21
    18
    Location Location
    AeStHete
    I'm obligated to post this again, no matter how annoying it's probably getting.
     
  20. MoDule

    MoDule

    Tech Member
    327
    24
    18
    Procrastinating from writing bug-fix guides
    I'd like to have versions for the different disassemblies, but since I don't use them myself I can't do much towards providing them. Someone else will have to take care of that.

    After some procrastination, I have a few more guides ready:
    How-to:Fix camera y position for Tails
    This one's always really bothered me and I don't even use Tails that often. The way this fix is done, no special code will ever be necessary to handle the character changing height, at least as far as the camera is concerned.
    How-to:Fix bug in ARZ Boss arrow's platform behavior
    Not that noticeable or problematic, but it's still nice to have it fixed.
    How-to:Collide with water after being hurt
    I put this one down as a design choice, since it's debatable weather the original behavior was intentional or not. The Advance series indicates that at least one person thought it wasn't.

    I kind of screwed up moving the articles to the guides section. The name on the page is wrong and there's a redirect on top. I tried my best to fix it, but couldn't figure out what to do, so if anyone knows how, I'd be very grateful.

    I've got three more in the pipeline and then I'll be done for now.