don't click here

Sonic CD decompilation

Discussion in 'Engineering & Reverse Engineering' started by BenoitRen, Jul 17, 2023.

  1. Devon

    Devon

    La mer va embrassé moi et délivré moi lakay. Tech Member
    1,491
    1,829
    93
    your mom
    Nope. It checks for when you let go of the button mid-jump, so that the jump height gets shortened. All peelout related logic is in "levermove", starting at around "label4". Spindash related logic can be found in "balllmove", above "label1". The timers are handled at the beginning of "play00", though.
     
    • Informative Informative x 3
    • Like Like x 1
    • List
  2. BenoitRen

    BenoitRen

    Tech Member
    861
    468
    63
    That explains why Sonic always rebounded so high after bouncing on enemies, as if I was holding a jump button down. I now also remember not being able to control his jump height.

    Both of these issues are no longer present after the bugfix. :)
     
  3. BenoitRen

    BenoitRen

    Tech Member
    861
    468
    63
    I've added sound effects! I had never implemented sound in any of my SDL projects before. It turned out to be surprisingly easy. Didn't need SDL_mixer.

    Here's hoping it's just as easy to add background music.
     
  4. synchronizer

    synchronizer

    Member
    2,348
    130
    43
    What would some cross-platform equivalents be? I couldn’t find anything for “lz compression.”
     
  5. Devon

    Devon

    La mer va embrassé moi et délivré moi lakay. Tech Member
    1,491
    1,829
    93
    your mom
    The first one is known as "SZDD", which was what Microsoft used for COMPRESS.EXE and EXPAND.EXE in MS-DOS. A proper Windows version of EXPAND.EXE can still be found in modern Windows today, and does work with the compressed files in Sonic CD's PC port. You can find a format specification and pseudo code here, alongside BenoitRen's implementation for their own shell for the decompilation here.
     
  6. synchronizer

    synchronizer

    Member
    2,348
    130
    43
    Okay. The idea would’ve been to create a macOS / Linux / UNIX-like platform layer as well, so Windows-only libraries won’t work. I guess the pseudocode could make it easy enough to recreate though. Thanks for clarifying where everything came from.

    Actually, does the game really need to compress anything on modern hardware? I can imagine skipping that step optionally and keeping everything decompressed.
     
    Last edited: Dec 31, 2024
  7. BenoitRen

    BenoitRen

    Tech Member
    861
    468
    63
    I'm using SDL to create the replacement executable, so the end result should be a compilation away from working on other platforms. If you want to create an executable of your own, feel free to use my code. The license is CC0, making it essentially public domain.

    There's no need to keep the assets compressed, but unless you're going to distribute them yourself (not recommended for copyright reasons), users won't like having to decompress them to be able to use them. :)
     
  8. synchronizer

    synchronizer

    Member
    2,348
    130
    43
    I saw some Windows-only audio code too. Hmm.

    I guess someone could create a compressor/decompressor for other platforms?

    It’s a little unclear without things being in one spot.
     
  9. BenoitRen

    BenoitRen

    Tech Member
    861
    468
    63
    Where are you seeing Windows-only code? If you're looking in the WINEXE folder, that's the decompiled code of the original Windows executable.
     
  10. synchronizer

    synchronizer

    Member
    2,348
    130
    43
    Yes. Don’t you need that to run the game if you were to modify the other game files?
     
  11. BenoitRen

    BenoitRen

    Tech Member
    861
    468
    63
    No, you don't. It's for educational purposes only.
     
  12. BenoitRen

    BenoitRen

    Tech Member
    861
    468
    63
    As many of you know, Sonic CD consists of many submodules. Most of them are levels, as each level has its own submodule. This resulted in a lot of duplicate code and data.

    Not content with just making a cross-platform control program, I decided to merge the duplicate code and data.

    This meant I had to go back to looking at Sonic CD's *shudders* scrolling code. Each level has its own file for it, resulting in several versions of each function. I compared all versions and created one that worked with all levels where possible.

    Merging the data was easy. But I also had to duplicate a lot of sprite data, as many levels have their own sprite indexes for various objects. This created a lot of extra work.

    The result so far is a fully playable Palmtree Panic, including time travel!

    Also new is the addition of background music, thanks to ADX decoding code donated by CKDEV. To be able to play both the music and the sound effects, however, I have to upsample the 22500 Hz sound effects to 48000 Hz. Currently I'm using SDL's convertion routines for that, and the result is not good. This is most obvious with the ring collection sound.

    With all that said, enjoy the update video!



    (Apologies for the low quality. If anyone knows how to stop YouTube from butchering it like this, please let me know.)
     
  13. Devon

    Devon

    La mer va embrassé moi et délivré moi lakay. Tech Member
    1,491
    1,829
    93
    your mom
    Upscale the video before uploading it. YouTube destroys the quality of lower res videos.
     
  14. BenoitRen

    BenoitRen

    Tech Member
    861
    468
    63
    Here's a better video:



    Because this is a more extensive project now than a simple replacement control program, it got a separate repo: Sonic CD Respinned.
     
  15. Greenknight9000

    Greenknight9000

    Member
    20
    2
    3
    This is incredible progress in such a short amount of time! And as a bonus, we have insta-time travel, whether intended or not hahaha. This is no doubt going to be a wonderful way to play SCD when this gets completed, since the remaster, although good, isn't 100% accurate.
     
  16. Clownacy

    Clownacy

    OCs are for the weak Tech Member
    1,116
    728
    93
    I was testing your executable with the SDL1-on-SDL2 compatibility layer, and I have some feedback on the 'audio.c' file:
    • Code (Text):
      1. g_sounds[i].size = cvt.len * cvt.len_ratio;
      should be
      Code (Text):
      1. g_sounds[i].size = cvt.len_cvt;
      , otherwise static briefly plays after the sound ends.
    • 'play_sound' and 'stop_sounds' should lock the audio device.
    • 'SDL_BuildAudioCVT' can return -1 to indicate failure, but this is not accounted for.
    • 'unload_sounds' should call 'stop_sounds', to prevent a segmentation fault when the game is closed.
     
    • Informative Informative x 2
    • Useful Useful x 1
    • List
  17. synchronizer

    synchronizer

    Member
    2,348
    130
    43
    Isn't SDL up to v3 now? It might be worth switching.
     
  18. Clownacy

    Clownacy

    OCs are for the weak Tech Member
    1,116
    728
    93
    SDL1 runs on legacy platforms like Windows 98 and the Dreamcast. The features of later SDL versions, such as hardware accelerated 3D rendering and high-DPI support, may not be useful for a port of Sonic CD.
     
    Last edited: Jan 11, 2025
    • Agree Agree x 1
    • Useful Useful x 1
    • List
  19. synchronizer

    synchronizer

    Member
    2,348
    130
    43
    The utility is not using a deprecated API, but I missed the part where you're using a compatibility layer. Maybe eventually if that gets ported on top of SDL3 as well (seems totally possible.)
     
  20. BenoitRen

    BenoitRen

    Tech Member
    861
    468
    63
    SDL1 not only runs on legacy platforms; it runs on more computers.

    An old project of mine, Rockman Copy System, can use both SDL1 and SDL2. A couple years ago, I tried it on a computer at work. The SDL2 version didn't run. The SDL1 version did.

    It's trivial to support both SDL1 and SDL2, so I intend to make both options available.

    I have no experience with SDL3.
     
    • Like Like x 1
    • Informative Informative x 1
    • List