Enchancing Sonic 2

Discussion in 'Discussion and Q&A Archive' started by Machenstein, May 20, 2012.

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

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    I want my first hack to be a simple enchancement of the original Sonic 2. I aim to include various features that would add to the experience plus fix some design flaws that were in the original. Such features include the ability to fly and swim as Tails, save data and manual Super Sonic transformation as seen in Sonic 3. While I figure out how to implement those features, I would also like to discuss what level design flaws that were in the original Sonic 2 such as that inescapable spike pit in Mystic Cave Zone. I want this project to be a learning experience, not just for myself, but other newcomers as well.


    So while I figure out how to make Tails fly in Sonic 2, post about any level design flaws that were present in the original Sonic 2 so I can whip out SonED2 and rectify them.
     
    Last edited by a moderator: May 20, 2012
  2. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    One of the most common flaws is in Oil Ocean Zone Act 2, there's a section with 4 platform plame pipes (two of which have a boost device above them in mid air), the second boost device, if holding right while being shot up, you can land on a set of spikes to the right of the sphere shooting device (this will cause Sonic/Tails to go into hurt mode), as they fly back in hurt mode, they will land inside the sphere shooting device and it'll activate, but because hurt mode is active, it doesn't follow through correctly, and coincidentally the correct flags are cleared/set in such a way that it causes Sonic/Tails' acceleration and movement to become the speed of the sphere's performance, while not actually running through the pipes, hence Sonic/Tails is able to run, jump, and move at high speeds, that of which often go faster than the screen itself.


    I cannot think of many off the top of my head (I haven't played Sonic 2 in so long), however, you could perhaps take a look at this TAS:



    These guys cause a whole range of game breaking methods to complete them at high speeds.
     
  3. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    I am also going to fix minor issues such as this one.


    Before:


    [​IMG]


    After:


    [​IMG]


    On top of fixing that broken tile, I also fixed EHZ's deformation bug as well as other bugs covered in the tutorials. If any of you see any broken or misplaced tiles such as the one I fixed above, tell me.
     
    Last edited by a moderator: May 23, 2012
  4. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    Sorry for the double post, but I need a little help. Everytime I edit anything in Metropolis Zone with SonED2, Sonic ends up falling through the lava instead of standing on its surface as usual. I'm using the project files that come with the SVN disassembly. Could they be the problem?
     
  5. MainMemory

    MainMemory Well-Known Member Member

    Joined:
    Mar 29, 2011
    Messages:
    922
    Does SonLVL do the same thing?
     
  6. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    Nope, I just tried it. Also, I had a bit of a brain fart; I'm using the project files that come with the Hg version, not the SVN one. I don't even think an SVN disassembly exists for Sonic 2, but that's beside the point. I've already made so many changes with SonED2. Is there a way I can use SonLVL in conjunction with SonED2?
     
  7. MainMemory

    MainMemory Well-Known Member Member

    Joined:
    Mar 29, 2011
    Messages:
    922
    There is nothing preventing you from using both, as long as you have the project files for both.
     
  8. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    It works. With the help of the Sonic 2 SVN INIs, I can use both SonED2 and SonLVL simultaneously. The next thing I want to do now is use ASM hacking to implement manual Super Sonic transformation as seen in Sonic 3 Complete. I read MarkeyJester's ASM tutorial, but I still don't know how the instructions covered in the tutorial effect the mechanics in the Sonic games. Would manual Super Sonic transformation be a good place to start?


    EDIT: I assume these are the subroutines I have to edit.



    ; loc_1AAF0:
    Sonic_JumpHeight:


    tst.b jumping(a0) ; is Sonic jumping?


    beq.s Sonic_UpVelCap ; if not, branch


    move.w #-$400,d1


    btst #6,status(a0) ; is Sonic underwater?


    beq.s + ; if not, branch


    move.w #-$200,d1


    +


    cmp.w y_vel(a0),d1 ; is Sonic going up faster than d1?


    ble.s + ; if not, branch


    move.b (Ctrl_1_Held_Logical).w,d0


    andi.b #button_B_mask|button_C_mask|button_A_mask,d0 ; is a jump button pressed?


    bne.s + ; if yes, branch


    move.w d1,y_vel(a0) ; immediately reduce Sonic's upward speed to d1


    +


    tst.b y_vel(a0) ; is Sonic exactly at the height of his jump?


    beq.s Sonic_CheckGoSuper ; if yes, test for turning into Super Sonic


    rts





    ; ---------------------------------------------------------------------------
    ; Subroutine called at the peak of a jump that transforms Sonic into Super Sonic


    ; if he has enough rings and emeralds


    ; ---------------------------------------------------------------------------


    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||


    ; loc_1AB38: test_set_SS:


    Sonic_CheckGoSuper:


    tst.b (Update_HUD_timer).w ; has Sonic reached the end of the act?


    beq.w return_1ABA4 ; if yes, branch


    tst.b (Super_Sonic_flag).w ; is Sonic already Super?


    bne.w return_1ABA4 ; if yes, branch


    cmpi.b #7,(Emerald_count).w ; does Sonic have exactly 7 emeralds?


    bne.s return_1ABA4 ; if not, branch


    cmpi.w #50,(Ring_count).w ; does Sonic have at least 50 rings?


    blo.s return_1ABA4 ; if not, branch


    move.b #1,(Super_Sonic_palette).w


    move.b #$F,(Palette_timer).w


    move.b #1,(Super_Sonic_flag).w


    move.b #$81,obj_control(a0)


    move.b #AniIDSupSonAni_Transform,anim(a0) ; use transformation animation


    move.b #ObjID_SuperSonicStars,(SuperSonicStars+id).w ; load Obj7E (super sonic stars object) at $FFFFD040


    move.w #$A00,(Sonic_top_speed).w


    move.w #$30,(Sonic_acceleration).w


    move.w #$100,(Sonic_deceleration).w


    btst #6,status(a0) ; Check if underwater, return if not


    beq.s +


    move.w #$500,(Sonic_top_speed).w


    move.w #$18,(Sonic_acceleration).w


    move.w #$80,(Sonic_deceleration).w


    +


    move.w #0,invincibility_time(a0)


    bset #1,status_secondary(a0) ; make Sonic invincible


    move.w #SndID_SuperTransform,d0


    jsr (PlaySound).l ; Play transformation sound effect.


    move.w #MusID_SuperSonic,d0


    jmp (PlayMusic).l ; load the Super Sonic song and return


    ; ---------------------------------------------------------------------------


    return_1ABA4:


    rts


    ; End of subroutine Sonic_CheckGoSuper



    What do I have to edit here to implement manual Super Sonic transformation?
     
    Last edited by a moderator: May 27, 2012
  9. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    Here:



    tst.b y_vel(a0) ; is Sonic exactly at the height of his jump?
    beq.s Sonic_CheckGoSuper ; if yes, test for turning into Super Sonic



    This is a condition for transformation exactly. I guess comments explain it well enough.


    So, if you replace it with any condition that checks buttons, like "A+C (or whatever) are held? If yes, go to Sonic_CheckGoSuper", Sonic will only transform if both these buttons are pressed in a jump.

    They do effect directly! They do the mechanics. I'm not good in explaining such complicated things in English, but I'll do what I can:


    Once you learn how Sonic engine works (or at least part of it), you will see how instructions (code logic) effect 'game mechanics'. It's impossible to understand when you don't see the whole thing.


    Knowledge of ASM isn't the main criteria here (but of course, you can't do without it), what's more important is that you can also understand code logic itself. You may know every instruction and see how the code will behave, but you may have no idea what it does. That's the hardest part about it: find out what different parts of engine do and how they are connected with each other. Sonic's engine is very big and complicated. It's a puzzle with hundreds of pieces. Start making up this puzzle and in time you'll see it.


    I must say, this is really hard stuff. But it's good to see someone aiming for such a high target: understanding how the game engine works. If you do it, you will become a real pro. Even if you don't, you will gain a lot of experience. It's good that you that you began to learn ASM properly, using tutorials.


    Start with understanding small subroutines of objects (like ones you showed in your post), it's the easiest way to begin with and the best to learn how game mechanics work.
     
  10. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    I figured that was the solution, so I replaced that condition with this instead:



    tst.b #button_A_mask|button_C_mask,d0 ; is A or C being pressed?
    beq.s Sonic_CheckGoSuper ; if yes, test for turning into Super Sonic


    rts



    But I got a build error.

     
    Last edited by a moderator: May 27, 2012
  11. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    TST instruction can have only 1 operand, so assembler says it right.


    This instruction can't work like you expect it in that line: all it does is tests memory address or register to check if their values are zero or not, positive or negative. That's it.


    In your case, it should be CMP if you want both buttons to be held, or AND if you want either of them:



    cmpi.b #button_A_mask|button_C_mask,d0



    D0 can be used here, because there was loaded joypad buttons bitfield in this line:



    move.b (Ctrl_1_Held_Logical).w,d0



    But be careful about one thing. After this line:



    andi.b #button_B_mask|button_C_mask|button_A_mask,d0 ; is a jump button pressed?



    You can check D0 for only A/B/C buttons. Bits that correspond other buttons were cleared (masked) by AND instruction. This was done to check if the resulting number that has only bits for A/B/C is not zero. If it's not zero, then at least one of A/B/C bits is 1, so we can say that at least one of these buttons is held.
     
  12. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    Here is what I have now:



    and.b #button_A_mask|button_C_mask,d0 ; is A or C being pressed?
    beq.s Sonic_CheckGoSuper ; if yes, test for turning into Super Sonic


    rts



    While there are no build errors, Sonic now transforms into Super Sonic the instant you push the jump button. And yes, this happened when I pushed B as well.


    I have a feeling my trial period is going to end soon, so here is what I have for my hack so far.


    http://www.mediafire...6o5jsxe3bjztxdo


    It's not much at the moment, but with all of the bug fixes and level layout changes, it's currently the best version of Sonic 2 vanilla so far.
     
    Last edited by a moderator: May 27, 2012
  13. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    Replace BEQ (branch if zero) with BNE (branch if not zero).


    AND instructions clears everything except for bit of A and C buttons. You want to branch if at least one of these buttons is held, therefore if at lest one of bits is set. But if bits are set, the result number after AND worked will be non-zero, while you branch if the result is zero.


    When will BEQ branch? It will branch if A and C are not pressed (their bits clear), more over, it will branch if nothing is pressed (when you release jump button). If you press B, it will branch as well.
     
  14. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    I replaced BEQ with BNE and got the same result, except pushing B now allows Sonic to jump without going Super. A and C still make Sonic turn Super instantaneously on the ground. Is there additional code I have to add?
     
    Last edited by a moderator: May 27, 2012
  15. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    Ah, now I see the problem. Do this:



    move.b (Ctrl_1_Press_Logical).w,d0
    and.b #button_A_mask|button_C_mask,d0 ; is A or C being pressed?


    bne.s Sonic_CheckGoSuper ; if yes, test for turning into Super Sonic


    rts



    The reason transformation worked immediately is because you were checking held buttons, and if you jump using A or C, they will be held from the very beginning.


    If you will check pressed buttons instead, it will work exactly like you expected: when you press one of these buttons in mid-jump.
     
  16. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    Eureka, it works! Let's see if I can apply the knowledge I learned to allow Sonic revert back to normal while Super.
     
  17. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    Sorry to double post again, I want to post what I have so far to commemorate my membership.


    http://www.mediafire...plpta22csa26u24


    Level layouts have been improved further upon the original Sonic 2 and the ability to go super at will has been added thanks to vladikcomper's help. The A button has been assigned to make Sonic transform and revert at any time.


    The next thing I want to do is fix the Spin Dash code. While there is a guide on Retro to do that, it appears to be written for an earlier Sonic 2 disassembly, perhaps the 2007 one by Xenowhirl. Is there a more up-to-date version or will we have to make an Hg equivilent for it?
     
    Last edited by a moderator: May 31, 2012
  18. MainMemory

    MainMemory Well-Known Member Member

    Joined:
    Mar 29, 2011
    Messages:
    922
    Somebody will have to translate it for use with the Hg disassembly.
     
  19. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    In that case, I want to tackle another bug that isn't addressed anywhere. When holding left or right while using some of the teleporters in Metropolis Zone, Sonic falls through the floor for some reason. Is there any way to fix that?


    EDIT: This issue seems to pertain only to Super Sonic, but if it happens when using normal Sonic, tell me.
     
    Last edited by a moderator: May 31, 2012
  20. Machenstein

    Machenstein Active Member Member

    Joined:
    Aug 10, 2011
    Messages:
    34
    Double posting once again to ask for an opinion. Should I reduce Metropolis Zone down to two acts? If so, which act should I keep, Act 2 or Act 3? If I choose Act 2, I would have to put the boss at the end of it somehow. If I choose Act 3, then it would only be a matter of changing the "3" in the title card.


    I plan to compensate for the lack of a third act in Metropolis Zone with making Death Egg Zone into a full level, complete with two acts. Would this be something acceptable in an "enhanced" version of Sonic 2?
     
    Last edited by a moderator: Jun 2, 2012
Thread Status:
Not open for further replies.