don't click here

I've got Tails flying in Sonic 2, but...

Discussion in 'Engineering & Reverse Engineering' started by Tets, Aug 5, 2008.

Thread Status:
Not open for further replies.
  1. Tets

    Tets

    one rude dude Oldbie
    905
    72
    28
    I more or less successfully ported the flying code from S3K, but something has gone tragically wrong with it. It seems to work well for the most part, but behaves strangely around certain objects. For example, while flying over some springs, Tails will immediately fall to the ground, or in some cases, right through it. It happens with a number of other objects, including the rotating and breakable blocks in CPZ.

    My best guess as to what might be causing this is one or more mistranslated SST offsets, but I can't pin it down. I know that a number of other people here have done the same thing, so I'm hoping someone might have encountered this before and know what's going on.
     
  2. Alriightyman

    Alriightyman

    I am back... from the dead! Tech Member
    357
    11
    18
    Somewhere in hot, death Florida
    0101001101101111011011100110100101100011 00000010: 0101001100000011 01000101011001000110100101110100011010010110111101101110
    I would say it has to be a mistranslated sst or something. My port works great, I just don't have the carry code. I would just re-port it again, maybe a little more carefully. That way you might correct your mistake. Good luck.
     
  3. Tets

    Tets

    one rude dude Oldbie
    905
    72
    28
    I was thinking of just re-porting it myself. I went through all of the code earlier and nothing really jumps out at me as being wrong, so I'll probably have to. Shouldn't be a problem now, though, since I've already done it once.

    I was beginning to suspect that I might have to port over some subroutines that had changed one way or another in S3K, but it looks like this isn't the case. Thanks for the input.

    Quick update: Looks like I got it. Strangely enough, it didn't start working right until I re-ported the double jump routine referenced by tails_jumpheight. I wouldn't have thought it'd be in there. Weird, but I'm not complaining.
     
  4. Tets

    Tets

    one rude dude Oldbie
    905
    72
    28
    This makes me a dirty double-posting motherfucker, but I've got a question to ask. I thought it would be a relatively simple matter to make Tails able to damage enemies while flying, but quickly realized I don't even know how collision between objects works in the Sonic engine. Would anyone mind helping me out with this?

    Otherwise, I think my flying port is almost perfect. I even managed to get the sound effects from S3K working with surprising ease.
     
  5. Alriightyman

    Alriightyman

    I am back... from the dead! Tech Member
    357
    11
    18
    Somewhere in hot, death Florida
    0101001101101111011011100110100101100011 00000010: 0101001100000011 01000101011001000110100101110100011010010110111101101110
    I just don't understand music/sound effect porting......
     
  6. Tets

    Tets

    one rude dude Oldbie
    905
    72
    28
    I had no idea what I was getting into trying to port the sounds. I started with comparing identical sounds from S2 and S3K, and I realized the only real differences between them were some bytes swapped in the sample. At that point, porting was as simple as making identical byte swaps in the sample used by both of the flying sound effects. I wasn't sure that they would work, but all the same I copied them over two unused sound effects and all was well.

    That was a lucky break though. I'm still at a loss as to how S3K Tails can damage enemies while flying.
     
  7. Object collision is handled by the routine known as TouchResponse in Xeno's disasm, and the equivalent routine in S&K can be found at $FE8E. The part of this routine which handles collisions with enemies is known as Touch_Enemy. The equivalent of that in S&K looks like:
    Code (ASM):
    1. Touch_Enemy:        
    2.         btst    #1,$2B(a0)      ; is the character invincible?
    3.         bne.s   Touch_HarmEnemy ; if yes, branch
    4.         cmpi.b  #9,$20(a0)      ; is the character charging a spindash?
    5.         beq.s   Touch_HarmEnemy ; if yes, branch
    6.         cmpi.b  #2,$20(a0)      ; is the character rolling?
    7.         beq.s   Touch_HarmEnemy ; if yes, branch
    8.         cmpi.b  #2,$38(a0)      ; is the character Knuckles?
    9.         bne.s   loc_100F0       ; if not, branch
    10.         cmpi.b  #1,$2F(a0)      ; is Knuckles gliding?
    11.         beq.s   Touch_HarmEnemy ; if yes, branch
    12.         cmpi.b  #3,$2F(a0)      ; is Knuckles sliding across the ground?
    13.         beq.s   Touch_HarmEnemy ; if yes, branch
    14.         bra.w   Touch_ChkHurt   ; check if the player is hurt
    15. ; ---------------------------------------------------------------------------
    16.  
    17. loc_100F0:        
    18.         cmpi.b  #1,$38(a0)      ; is the character Tails?
    19.         bne.w   Touch_ChkHurt   ; if not, branch
    20.         tst.b   $2F(a0)         ; is Tails flying?
    21.         beq.w   Touch_ChkHurt   ; if not, branch
    22.         btst    #6,$2A(a0)      ; is Tails underwater?
    23.         bne.w   Touch_ChkHurt   ; if he is, branch
    24.         move.w  $10(a0),d1
    25.         move.w  $14(a0),d2
    26.         sub.w   $10(a1),d1
    27.         sub.w   $14(a1),d2
    28.         jsr     (CalcAngle).l
    29.         subi.b  #$20,d0
    30.         cmpi.b  #$40,d0
    31.         bcc.w   Touch_ChkHurt
    32.  
    33. Touch_HarmEnemy:        
    34.         tst.b   $29(a1)         ; is this object a boss or a multiple-hit enemy?
    35.         beq.s   Touch_KillEnemy ; if not, branch
    36.         neg.w   $18(a0)
    37.         neg.w   $1A(a0)
    38.         neg.w   $1C(a0)
    39.         move.b  $28(a1),$25(a1)
    40.         move.w  a0,d0
    41.         move.b  d0,$1C(a1)
    42.         move.b  #0,$28(a1)
    43.         subq.b  #1,$29(a1)
    44.         bne.s   loc_1015E
    45.         bset    #7,$2A(a1)
    46.  
    47. loc_1015E:        
    48.         cmpi.b  #2,$38(a0)      ; is the character Knuckles?
    49.         bne.s   locret_10198    ; if not, branch
    50.         cmpi.b  #1,$2F(a0)      ; is Knuckles gliding?
    51.         bne.s   locret_10198    ; if not, return
    52.         move.b  #2,$2F(a0)      ; stop Knuckles' glide
    53.         move.b  #$21,$20(a0)
    54.         bclr    #0,$2A(a0)      ; clear orientation
    55.  
    56. loc_10180:
    57.         tst.w   $18(a0)
    58.         bmi.s   loc_1018C
    59.         bset    #0,$2A(a0)
    60.  
    61. loc_1018C:
    62.         move.b  $44(a0),$1E(a0)
    63.         move.b  $45(a0),$1F(a0)
    64.  
    65. locret_10198:
    66.         rts    
    The part which handles Tails' tails killing enemies is loc_100F0, which you can see is called only when Tails isn't doing any of the normal killing animations. I'm not sure what the logic is behind the angle test, but if it's successful the enemy is harmed or killed, otherwise Tails gets hurt.
     
  8. muteKi

    muteKi

    Fuck it Member
    7,851
    131
    43
    Probably it's because Tails can only hit things from underneath.
     
  9. Tets

    Tets

    one rude dude Oldbie
    905
    72
    28
    Thanks for the help, shobiz. I've been looking all over the disassembly for such a routine, I'm not sure why I never came across TouchResponse on my own. I've got it working perfectly now though.
     
Thread Status:
Not open for further replies.