Sega PC Reloaded

Discussion in 'Engineering & Reverse Engineering' started by Korama, Apr 2, 2015.

  1. Korama

    Korama

    Tech Member
    272
    0
    0
    What is it?

    I wrote a program that is an installer, launcher, and patcher for a few Sega PC
    games that were originally released for Windows 95/98. The games had issues or
    broke entirely on newer versions of Windows. Now they work again, with a few
    minor improvements even.
    So far, these games are supported:
    • Ecco the Dolphin PC
    • Sonic CD 1996
    • Sonic & Knuckles Collection
    • Sonic 3D Blast

    [​IMG]

    Some boring technical details:
    Those games use DirectDraw and 8 bit / 256 color palettized video modes. Both are
    obsolete nowadays, and while the compatibility layer of Windows still supports/emulates
    them, it doesn't always work for whatever reason (e.g. buggy game code).
    So I wrote custom implementations of the necessary DirectDraw interfaces (IDirectDraw,
    IDirectDrawSurface, etc.), and a few other Windows API functions, that either
    wrap or replicate what the games expect.
    That code is packaged in a "ddraw.dll" file that looks like the real one from Microsoft.
    However, some of the games load ddraw.dll dynamically, after executing some "bad" code
    (e.g. checking if a 256 color mode is active). That's why a launcher is necessary, it
    ensures that my ddraw.dll gets loaded and run right at the start of the game, so that
    it can perform the necessary patches in memory. I could also patch the files on disk,
    of course, but I've decided against that. It is just too messy and gets complicated if
    I need to undo or update patches. Keeping the original files unmodified on disk and
    doing all the patching in RAM is the best solution.



    What exactly does it change?

    Many little things that I can't be bothered to write down. Some important ones:
    • Flexible window handling (free resizing, preset sizes, try Alt+0..9), quick fullscreen toggling... (all games except Ecco).
    • Music playback from file instead of CD, bass.dll and streaming plugin
      support for all kinds of formats. Custom loop points supported for ogg and flac.
    • All registry and ini file operations of the games get redirected to a single ini
      file that also holds the patcher configuration. The file is <exename>.ini, so
      if you'd like to have several configurations for a single game, just make a
      copy (or hardlink) of the exe and call it <exename>.whatever.exe (e.g. "sonic3k.2.exe").
    • Mapping joystick / gamepad POV hat / dpad to analog axes in all games.
    • Skipping annoying intro logos and videos.
    • Palette blending; mainly for Ecco, still experimental in SCD and particularly S3K.
    • Freely configurable keyboard and gamepad bindings (not fully implemented yet).
    • Midiout.dll of S&K Collection caused an access violation on termination,
      keeping sonic3k.exe in memory...
    • Diagonal key input for Sonic CD. Only worked for gamepad.
    • Savegame dialogs and several graphics modes were totally broken in Ecco.
    • and more...




    Why?

    Yes, I know you can emulate most of those games, and Taxman's rebuilt Sonic CD is great.
    I started this project last year, specifically for Ecco PC, because unlike the Sonic games,
    that game did never receive any official re-release. Yet it is pretty much
    the best version of Ecco 1 available. If you're interested in that game, you can find a
    great bundle here.

    After that was done, I generalized the code a bit and applied it to the old
    Sonic games I had lying around. It took some restructuring/refactoring, but it
    worked rather well.
    Also, it's not like I'm new to this. I've made Sonic CD and Ecco PC "XP ready"
    a decade ago already (does anyone remember SonicCDfix? I reused some code from that.).
    But the patches back then were rather simple and superficial compared to this.


    Where?

    Download here.

    A little extra for Sonic CD 1996.
    - higher quality sound effects and Xvid-encoded intro movie. The original uses Indeo, which is no longer included in Windows. All other videos use Cinepak, which is still there.

    [​IMG]

    To do...

    There are a few minor issues I still need to resolve.
    Palette blending tends to get stuck in SCD and S3K; you can turn if off and on via Alt+B. Should probably also be gamma-corrected.
    Key/gamepad binding needs to be finished... you can already assign various stuff to buttons in SCD,
    but only by editing the ini file directly. If you go to the "[JoystickControls]" section and add "JoyButton11=menu503" and "JoyButton12=menu201", for example,
    then button 11 will toggle debug mode and button 12 will toggle fullscreen (as 503 and 201 are the menu command IDs for those actions).
    Some upscaling algorithms and dedithering would be nice to have, but that's a pipe dream for now.

    Comments, suggestions, and bug reports are welcome.
     
  2. Dark Sonic

    Dark Sonic

    I'll find the old avatar eventually Member
    12,315
    72
    28
    Working on my art!
    oooh interesting. Any plans on adding Sonic R support?
     
  3. Korama

    Korama

    Tech Member
    272
    0
    0
    I've thought about Sonic R, but haven't really looked into it yet.
    It's probably not going to be as easy, because it uses 3D and 16 bit video modes. It does support DirectDraw and an ugly 8 bit output mode, though. And you can get it more or less running with DxWnd, but not in fullscreen or Direct3D mode, as far as I know.
     
  4. Billy

    Billy

    RIP Oderus Urungus Member
    1,868
    10
    18
    Colorado, USA
    Indie games
    Just tested it out with my copy of S&K collection, it works really well! Have you ever looked into the Windows port of Bug? I'd love to get that game working again.
     
  5. Korama

    Korama

    Tech Member
    272
    0
    0
    Thanks for the feedback!
    "Bug!" should be doable. I don't have it, but a friend as mentioned it to me as another candidate before.
    Do you happen to have an original CD for it? To implement the installation function, I need to know the file layout of that.
     
  6. Billy

    Billy

    RIP Oderus Urungus Member
    1,868
    10
    18
    Colorado, USA
    Indie games
    Check your PM inbox.
     
  7. amphobius

    amphobius

    doing more important things with my life Member
    2,121
    0
    16
    life
    This is cool, great job, man! Gonna have to play around with this later, particularly with S3D. Would be nice to play the version I grew up playing on modern computers with it actually working and stuff haha
     
  8. GerbilSoft

    GerbilSoft

    RickRotate'd. Administrator
    2,889
    20
    18
    USA
    rom-properties
    Sonic R worked fine last time I tried it... on Wine, that is. S&K Collection did as well. (CD and 3D did not.)

    It might be worth checking out Wine's ddraw and seeing if any of your paatches could be applied there to improve compatibility with these games.
     
  9. Just ran Sonic 3D Blast and played a bit of Green Grove Zone 1, and I've gotta say, it runs way better using this tool than by itself on Windows 7. How does the music folder work, though? Is there some way to make it play on specific stages?
     
  10. MainMemory

    MainMemory

    Have no fear...Amy Rose is here! Tech Member
    4,351
    34
    28
    SonLVL
    I got S3D and S&KC to install fine, but when I try installing Sonic CD, it just dings when I click the "Select Folder" button in the dialog, regardless of whether I'm choosing my existing install or the CD. Even manually editing the registry doesn't work.

    Also, speaking of music, would it be possible to use angryzor's bass_vgmstream.dll to play ADX/AAX/BRSTM/etc music?
     
  11. Korama

    Korama

    Tech Member
    272
    0
    0
    Thanks for the suggestion. I've been told that Ecco doesn't work on Wine, with or without patches. Unfortunately I have zero experience with Wine, so I won't be contributing to the project anytime soon.
    S&K collection is the least broken of the bunch, still works in Windows, too. But as I said, it doesn't terminate properly, and has an inconsistent frame rate in windowed mode.


    The music folder can be anywhere, though I suggest making a "MUSIC" subfolder in the game's base folder. The files are expected to be named either "Track##.ext" or "##whatever.ext" - e.g. "Track02.mp3" or "02 Title Theme.flac". Remember that audio tracks start at number 02 for those mixed mode data + audio game CDs. For best results, get bass.dll from http://www.un4seen.com/ and put it in the game folder, or somewhere in the search path (e.g. the Windows folder). You can additionally use add-on DLLs for bass, like bassflac.dll to support even more formats. They'll be loaded automatically, if they are in the search path and if they are "stream" plugins (as opposed to effects or other types of plugins).


    The launcher tries to verify the validity of the game folders. There isn't an error message for every circumstance, hence the "ding" warning sound. Do you perhaps have the older 16 bit version of Sonic CD (the one that came with pcm.cmp)? It's not supported, and never will be.
    You can look at soniccd.exe with a hex editor, exe files start with an "MZ" DOS header, followed either by an "NE" (16 bit) or "PE" (32 & 64 bit) header.
    Furthermore, if you have my old SonicCDfix patch applied (sign: there's an "lzxx.dll" file, and soniccd.exe contains the string "LZXX"), then you need to uninstall that first with the original SonicCDfix program.

    I didn't know about bass_vgmstream.dll before. If it is a standard bass stream plugin, then yes, it should work.
     
  12. MainMemory

    MainMemory

    Have no fear...Amy Rose is here! Tech Member
    4,351
    34
    28
    SonLVL
    You probably should have mentioned that the old SCD fixes have to be removed.

    But even then, there's still something it doesn't like about my copy of SCD. As I said before, even selecting the disc doesn't work. And yes, it is the 32-bit version.
     
  13. Korama

    Korama

    Tech Member
    272
    0
    0
    Yes, I should have made that clearer. I did mention that original unmodified game files are involved, though.

    Hmm, you might have a different release of SCD than I do. Could you please send me a dump of the directory structure? A simple "dir /s" should suffice.
    At the moment, a valid install source for SCD needs to have "GAME" and "RDX" subfolders. "GAME" needs to contain at least one valid soniccd*.exe and at least the "TITLE" subfolder. "RDX" must have dino2d.dll and dmix.dll.
    Alternatively, the "GAME" and "RDX" folders can be absent, in which case the other mentioned characteristics are expected to be all present in the selected folder.
     
  14. MainMemory

    MainMemory

    Have no fear...Amy Rose is here! Tech Member
    4,351
    34
    28
    SonLVL
    The disc: http://pastebin.com/x1UmGkwL
    My installed copy: http://pastebin.com/SbTZ54i7
     
  15. Korama

    Korama

    Tech Member
    272
    0
    0
    Thanks. My disc doesn't have that "Expert" folder, but appears to be pretty much identical otherwise.
    I uploaded a new version of the launcher that should at least give you an error message. I suspect your soniccd.exe might be different, although it is the same size as mine. If you upload it, I'll take a look.
    In your installed folder, the two RDX libraries dmix.dll and dino2d.dll should be placed next to soniccd.exe, otherwise everything is there.
     
  16. MainMemory

    MainMemory

    Have no fear...Amy Rose is here! Tech Member
    4,351
    34
    28
    SonLVL
  17. ICEknight

    ICEknight

    Researcher Researcher
    This is really useful, great work!

    Any plans on supporting Garfield Caught in the Act? The nuances it has on current systems are the following:

    -Requires to copy and paste wing32.dll into c:/windows/system32
    -Requires the CD for music
    -Fullscreen doesn't work anymore
    -You can't hit the fifth hole in the bonus stage using the regular cursor keys (I think it requires the center numerical key to be pressed?)
     
  18. Korama

    Korama

    Tech Member
    272
    0
    0
    The file is identical, as I expected. Something strange must be going on. I uploaded a new build that should tell you exactly what fails in the soniccd.exe validity check. Thanks for your patience.


    Thanks! I'm open to suggestions, but I can't promise that I'll be able to include each and every game, of course.
    I just started looking into Bug!, Earthworm Jim and Comix Zone have also been mentioned, and now Garfield is on the list as well.
     
  19. ICEknight

    ICEknight

    Researcher Researcher
    Let's check the fullscr--YIKES!
    [​IMG]

    Also, for some reason, I can't move the window to my secondary screen.
     
  20. MainMemory

    MainMemory

    Have no fear...Amy Rose is here! Tech Member
    4,351
    34
    28
    SonLVL
    ---------------------------
    Error
    ---------------------------
    No valid executable found!
    Name/Version mismatch (name=SONIC_P, ver=0)
    ---------------------------
    OK
    ---------------------------

    Edit: as long as I'm here how about Sonic's Schoolhouse? :v: