don't click here

How to fix Tails' respawn speeds

Discussion in 'Engineering & Reverse Engineering' started by redhotsonic, May 26, 2012.

  1. redhotsonic

    redhotsonic

    Also known as RHS Tech Member
    1,587
    9
    18
    United Kingdom
    YouTuber
    I couldn't see a topic about this subject, or I couldn't see it on the bug list, or anywhere else, so I thought I'd post my fix here


    How to fix Tails' respawn speeds




    The problem


    [​IMG]

    Bye, Tails! I'm leaving you behind.



    [​IMG]

    Oh, Tails! You're back!



    [​IMG]

    Keep up, Tails! Oh wait, you can't, you still think you're underwater!




    The problem here is when you and Tails enter the water, your speed, acceleration and deceleration are decreased, to give you the underwater physics. The problem is, if you lose Tails when underwater, when he next respawns (in Sonic 2, he only respawns when you've come out of water), he will still have his underwater speeds. Hence why Tails suddenly cannot keep up. This bug only occurs when you lose Tails underwater, and his underwater speed will remain this way until he enters/exits water again (no matter how many times you lose him and he respawns).


    The bug is NOT fixed in S3K either, but to fix it, you have to do an extra check, so follow the S3K fix.




    The fix



    Sonic 2


    This can be done in Xenowhirl's 2007 disassembly or the SVN disassembly.


    Go to "loc_1BC68:" and you'll see this:

    Code (ASM):
    1. loc_1BC68:
    2.     lea (Sonic_Stat_Record_Buf).w,a2
    3.     move.b  2(a2,d3.w),d2
    4.     andi.b  #$D2,d2
    5.     bne.s   return_1BCDE
    6.     or.w    d0,d1
    7.     bne.s   return_1BCDE
    8. ;   etc...

    Right after the 2nd "bne.s return_1BCDE" command, insert this:

    Code (ASM):
    1.     move.w  #$600,(Tails_top_speed).w   ; set Tails' top speed
    2.     move.w  #$C,(Tails_acceleration).w  ; set Tails' acceleration
    3.     move.w  #$80,(Tails_deceleration).w ; set Tails' deceleration

    So, you have something like this:

    Code (ASM):
    1. loc_1BC68:  ; Fix for Tails' underwater respawn
    2.     lea (Sonic_Stat_Record_Buf).w,a2
    3.     move.b  2(a2,d3.w),d2
    4.     andi.b  #$D2,d2
    5.     bne.s   return_1BCDE
    6.     or.w    d0,d1
    7.     bne.s   return_1BCDE
    8.     move.w  #$600,(Tails_top_speed).w   ; set Tails' top speed
    9.     move.w  #$C,(Tails_acceleration).w  ; set Tails' acceleration
    10.     move.w  #$80,(Tails_deceleration).w ; set Tails' deceleration
    11. ;   etc...

    Done



    Sonic 3 and Knuckles


    This can be done in SVN disassembly.


    Go to "loc_13CD2:" and you'll see this:

    Code (ASM):
    1. loc_13CD2:
    2.         lea (Stat_table).w,a2
    3.         move.b  2(a2,d3.w),d2
    4.         andi.b  #$80,d2
    5.         bne.s   loc_13D42
    6.         or.w    d0,d1
    7.         bne.s   loc_13D42
    8. ;       etc...

    Right after the 2nd "bne.s loc_13D42" command, insert this:

    Code (ASM):
    1.         btst    #6,$2A(a0)      ; test underwater flag
    2.         bne.s   +
    3.         move.w  #$600,($FFFFFEC0).w ; set Tails' top speed
    4.         move.w  #$C,($FFFFFEC2).w   ; set Tails' acceleration
    5.         move.w  #$80,($FFFFFEC4).w  ; set Tails' deceleration
    6. +

    So, you have something like this:

    Code (ASM):
    1. loc_13CD2:      ; Fix for Tails' underwater respawn
    2.         lea (Stat_table).w,a2
    3.         move.b  2(a2,d3.w),d2
    4.         andi.b  #$80,d2
    5.         bne.s   loc_13D42
    6.         or.w    d0,d1
    7.         bne.s   loc_13D42
    8.         btst    #6,$2A(a0)      ; test underwater flag
    9.         bne.s   +
    10.         move.w  #$600,($FFFFFEC0).w ; set Tails' top speed
    11.         move.w  #$C,($FFFFFEC2).w   ; set Tails' acceleration
    12.         move.w  #$80,($FFFFFEC4).w  ; set Tails' deceleration
    13. +
    14. ;       etc...

    Done




    The bug explained

    Now, when you lose Tails, he goes through lots of commands to move him about and to respawn him on certain conditions. BUT, none of these commands reset Tails' speeds. Because of this, when Tails respawns, he has the exact same speeds as when you lost him. So, if you lose him underwater, when he respawns, he will still have underwater speeds. So, all we've done here is added the command to reset his speeds. So...

    In Sonic 2, all we've done is set Tails to use his normal speeds no matter what when he respawns. This is fine because he only respawns when you're not in water, so he will always be out of water when he arrives. So we want his normal speed.

    In Sonic 3 and Knuckles, we have to do a check first to see if Tails is respawning in water or not. If not, do not bother resetting the speeds because he's going to spawn in water. On the other hand, if not in water, it will reset to his normal speeds because he's going to respawn out of water.



    That's it. If anyone wants to add this to the hacking guide, feel free.

    Enjoy

    redhotsonic
     
  2. MoDule

    MoDule

    Tech Member
    324
    6
    18
    Procrastinating from writing bug-fix guides
    Odd that people don't seem too interested in this.
    After a quick glance at Tails's respawning code, I'd personally do it like this:
    Code (ASM):
    1. loc_1BC68:      ; Fix for Tails' underwater respawn
    2.         lea     (Sonic_Stat_Record_Buf).w,a2
    3.         move.b  2(a2,d3.w),d2
    4.         andi.b  #$D2,d2
    5.         bne.s   return_1BCDE
    6.         or.w    d0,d1
    7.         bne.s   return_1BCDE
    8.         move.w  #$600,(Tails_top_speed).w       ; set Tails' top speed
    9.         move.w  #$C,(Tails_acceleration).w      ; set Tails' acceleration
    10.         move.w  #$80,(Tails_deceleration).w     ; set Tails' deceleration
    11. ;       etc...
    12.  
    That way, his stats only get overwritten once. Otherwise I think it would be setting his stats every frame.
     
  3. redhotsonic

    redhotsonic

    Also known as RHS Tech Member
    1,587
    9
    18
    United Kingdom
    YouTuber
    Yeah, I'd thought I'd get more reception on this topic, but meh.


    Anyway, that never crossed my mind. Thanks for that; I have edited both S2 and S3K guides in my first post. Anyone who has already applied this to their hack may want to have a quick revision.


    EDIT: Spellings.
     
  4. RetroKoH

    RetroKoH

    Member
    1,661
    17
    18
    Project Sonic 8x16
    Sorry about that RHS, I am usually on top of getting it posted. Been busy as of late with the new job and all. I can get to it as soon as I get some free time.

    Here you go. Report any omissions and mistakes, and I'll get on it when I can tomorrow. Or I'm sure you can handle it instead.
    Cheers!
     
  5. redhotsonic

    redhotsonic

    Also known as RHS Tech Member
    1,587
    9
    18
    United Kingdom
    YouTuber
    Cheers, mate. It's just the indexes that needs to be made under Sonic 2 and Sonic 3K. I would do it, but I don't know to wiki-editing much =P



    EDIT: And your wiki edits still says 1! Mine says 24 (for some reason).
     
  6. ICEknight

    ICEknight

    Researcher Researcher
    I can't stress enough how much I love all these explained fixes you guys keep posting. Great work!
     
  7. LockOnTommy11

    LockOnTommy11

    Member
    2,611
    132
    43
    UK
    Awesome work, I'd never noticed that Tails became slower after respawning after dying underwater, so your technical stuff may not have made a difference to me, but the well explained and very informative post was pretty damn interesting, and I learned something else about the game I've been playing for 16 years!
     
  8. RetroKoH

    RetroKoH

    Member
    1,661
    17
    18
    Project Sonic 8x16
    Ill take care of that, and the template addition today... (Speaking of which, we should have a Sonic3K template put together soon... I could ask Tiddles about working together on compiling one... I'm sure he has a lot of info to put in there)

    And yes... alas. My wiki edits count. I gave up on that and went with the new addition to my signature. I love that thing. Maybe yours says 24, because they see that the guides are from you and they assume you put the pages in. LOL :D Anyway I concur with the others... keep up the awesome work with the hacking contributions. I've said it before, give this guy that green membership bar already...
     
  9. redhotsonic

    redhotsonic

    Also known as RHS Tech Member
    1,587
    9
    18
    United Kingdom
    YouTuber
    This guide was only an easy fix, so that's not going to help much. But my other guides haven't really got me anywhere either, and I thought I did well with them =P



    I see you put links on the index at the bottom. But there isn't any here. I looked myself, but I don't know how it works =P