Sonic Generations Hacking (and More!)

Discussion in 'Engineering & Reverse Engineering' started by Andrew75, Jun 23, 2011.

  1. DustArma

    DustArma

    Member
    1,338
    10
    18
    Santiago, Chile
    Learning Python.
    In general, Sonic has a slower initial speed, both the 3D and 2D jump dash (controlled by separate values) are shorter, the air dash covers less ground but he keeps both aerial and ground momentum better (This is the reason why badnik chain bouncing is possible in Generations but not in Unleashed)
     
  2. Korama

    Korama

    Tech Member
    272
    2
    0
    Alright then. After some more reverse engineering of sonicgenerations.exe, some hardcore coding and research of the CPK file format, I've managed to make the game load external files. However, as of now, my project is still too buggy, so I won't release it yet.

    To inject my code into the game, I've decided to hijack imagehlp.dll (just like x360ce hijacks xinput1_3.dll, for example). That DLL seemed convenient, as Sonic Generations imports only a single function from it, which apparently doesn't even get called ever. There's a slight catch, though. Unfortunately, imagehlp.dll is a KnownDLL, which means that Windows will always load the file from the system folder, even if there's a local copy of the file in the application's folder. Most other DLLs used by the game are KnownDLLs too, no luck there either.
    So, what does that mean? You have to remove imagehlp.dll from the KnownDLLs list (probably not a good idea) or patch a few bytes in sonicgenerations.exe (change the "imagehlp.dll" string to the name of my substitute). Maybe I'll find a better injection vector, but changing some bytes in the exe isn't too bad, I think.

    Anyway, there are several limitations to my approach. You'll always need the original CPK files (or modified CPK files with the same structure). They are used as a fallback whenever some file doesn't exist externally.
    You also won't be able to modify external files while the game is running. Unless the file size stays identical, perhaps. The reason for that lies in the nature of the CRI file system. The table of content (TOC), which includes the expected file sizes, is only read at the very beginning of a CPK file mounting process and never again after. I supply the game with a TOC that gets patched on the fly in memory to reflect the sizes of the external files, but after the initial read I can't update that information anymore until the program gets restarted.

    If someone is working on an alternative, please continue. I hope I can fix the remaining issues of my project, but I'm not sure it'll really work properly in the end.
     
  3. Dario FF

    Dario FF

    Tech Support Hotline Tech Member
    Either injection or exe modification will be fine(I mean it's like just a few bytes anyway that could be easily replaced in any version of the exe). Replacing a common DLL on the system would provoke issues probably for other applications and is quite suspicious as well. My plan for mod distribution is you either get the patcher for the exe/mod loader, or just download the big ass CPKs. Besides, this would be terribly useful for testing.


    My question here is, does it need to be exactly the same file structure? For example, ghz200/Packed/ghz200.ar.05 could exist in the original, but perhaps my mod uses even more AR files. Does that mean the CPK would need to have a similar structure with the extra ar files(even if null) existing there? While it might sound annoying, the easy way to overcome it is to just forget about split AR files and pack it into single AR files(which seriously there's no reason why they're split at 10 MB IMO), and the game wouldn't be confused too much either because the ARL says how many split files there are, so it would just load the first one.


    Oh please don't worry about this, it's not annoying at all to re-run the game. That would just be asking too much. :v:

    All in all that's some really impressive work. As I said before, don't worry too much about unnecessary comfort stuff. As long as it can just load files from a folder instead of inside the CPKs each time the game runs, we're in a far better position to test.

    As for me I'm trying to crack the light field format(the stuff that reflects colors into dynamic objects and sonic). It's a weird format but it's some sort of linked list of cubes with RGB on each edge. The game interpolates the cube to get the lighting effect onto objects. Quite interesting really, and the data is just extracted out of the rendered GIA so generating our own light fields shouldn't be that hard. Just need to figure out how to read the list of cubes.
     
  4. Twilightzoney

    Twilightzoney

    Tech Member
    353
    0
    16
    Elgin, IL And Hampshire
    Unleashed and Generations Stuff and Custom Works
    All we would need now, is to have the exe open up more level ID's and have Camera movement support on the second analog and we'd be perfectly set.
     
  5. DustArma

    DustArma

    Member
    1,338
    10
    18
    Santiago, Chile
    Learning Python.
    So I messed a bit with the air drag.

    http://www.youtube.com/watch?v=nv2aVR6dHoU
     
  6. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    Been playing abit much super sonic in SADX I see...
     
  7. Felik

    Felik

    Member
    1,860
    82
    28
    There's two question bothering me really much. Are you going to port Unleashed DLC stages either? Some of them were really good. And how about Eggmanland? I do understand that you need to do something with werehog parts of the stage but still it feels like a waste to not port that level to Gens.
     
  8. Falk

    Falk

    Member
    1,570
    15
    18
    Actually, re: Eggmanland, most of the swaps are self-contained, using doors and such to physically cut off the different sections. If we get the JJ teleporter working, I'm thinking the level could be retrofitted so that it ports from lever to lever, and with the level editor all the unnecessary geometry could be taken out, etc.

    I honestly see no way to make the interior/Werehog sections work with modern Sonic - way too much swingies/balancing/etc. except maybe the last set of pipes that could be turned into a quickstep section with proper splines.

    It'd result in a neat 3-4min stage at least. Longer if you miss the first area's massive shortcut.
     
  9. Iggy for Short

    Iggy for Short

    Member
    820
    183
    43
    Something tells me that Eggmanland might have a few too many level gimmicks that would be hard to find suitable Generations replacements for.

    EDIT: This is just a hunch on my part; I don't actually know myself. As happy as I am to give feedback/ideas/etc., I'm not myself a modder, and therefore don't quite know the more complex inner workings involved with such a project.
     
  10. Korama

    Korama

    Tech Member
    272
    2
    0
    Yes, that would be a problem. So far, only files that are mentioned in the CPK's TOC are considered. I can patch the file sizes in-place, but adding more entries would complicate things quite a bit. But I'll probably have to rebuild the entire TOC anyway to get rid of the remaining bugs. (A bit more on that later.)

    Thanks! I hope it'll make your amazing work a bit more easy then. :)

    Sounds great! I remember seeing screenshots of Sonic Unleashed in debug mode with those light field cubes, I think they are on the wiki here somewhere.



    Ok, I got an early test release ready! As always, with these things, use at your own risk. Although the worst thing that should happen is that the game crashes during startup. ;)
    And it WILL crash with the original CPK files. That's because those use compression. I've narrowed my problems down to that. Looks like the game doesn't like my patched TOC that claims all files are uncompressed when in fact there were compressed files. I hope I'll be able to fix that.
    In the meantime, if you want to use this, the first step is to extract and rebuild all CPK files you want to redirect, WITHOUT compression.

    Then, open SonicGenerations.exe with your favorite hex editor, search for the string "imagehlp.dll" and replace it with "cpkredir.dll".
    Place cpkredir.dll in the same directory as SonicGenerations.exe, so that it'll get loaded when the game starts.
    You can also create a .ini file in the same place and with the same file name, to configure some settings.
    It should look like this:
    Code (Text):
    1. [CPKREDIR]
    2. Enabled=1
    3. ShowLog=1
    4. BaseDir="C:\Games\Sonic Generations\redir"
    "Enabled" enables or disables the redirection.
    ShowLog enables or disables the console logging window (I use DxWnd2 to force Sonic Generations to run in windowed mode and prevent it from noticing task switches, really useful for testing).
    BaseDir specifies the redirection base directory that will be used for all CPK files. If you'd rather have separate folders for each CPK, you can leave BaseDir blank (which is the default). In that case, external files for disk\bb3.cpk will be expected in the folder disk\bb3, for example.

    Download here

    [​IMG]
     
  11. Korama

    Korama

    Tech Member
    272
    2
    0
    Sorry, I forgot to mention that this will only work with the latest (I believe) version of SonicGenerations.exe, namely v1.0.0.5.
    I'll add support for other versions I can find.
     
  12. Dario FF

    Dario FF

    Tech Support Hotline Tech Member
    I've tried several modified files, like say, PFDs, or even a different Sonic.ar file with a green texture and it just crashes for me on most cases. I'm using basefolder="".

    However it does work if the file size in bytes stays the same. In any other cases it crashes for me. Should I provide a file for testing?
     
  13. Korama

    Korama

    Tech Member
    272
    2
    0
    Yes, some test files would be great!
    I've only used a few basic mods that I found, such as the no HUD mod or some character swaps, and they worked fine.
    I'm guessing this problem is related to my compression issue - if the external file is larger than the CPK internal representation for it, then it'll crash.

    Edit: And I guess it'll also crash if you have Sonic.ar as a single file externally when the CPK still uses split .ar files internally.
    So far, this is just a "dumb" redirection from internal CPK files to external ones. I'll try to overcome that limitation, but it'll be tricky.
     
  14. Dario FF

    Dario FF

    Tech Support Hotline Tech Member
    I placed the following files in the bb folder.

    Hope you can fix this issue, because having to have the same file size would make the loader a bit pointless. :v: I've seen it work though with just modifying say, the pull radius in sonic's boost via hex, so it's indeed working! Just needs some extended support.
     
  15. Chimera

    Chimera

    I'm not a furry. Tech Member
    1,272
    17
    18
    Castlevania prettyness
    Perhaps you can have your dll program, when called, check the .arl files of the archives in the game, and if they don't match with the table of contents, update the ToC to support the arl file and the new ar.00 files, adding the new files, removing ones that aren't there anymore, and changing the file sizes? Of course, I have no idea how the ToC works, so this might very well be impossible, but hey, anything that might make the workflow more bearable, right? :P
     
  16. Korama

    Korama

    Tech Member
    272
    2
    0
    Not just the same size, smaller files should work, too! ;)
    But yeah, I'm aware that at this stage, the redirector is too limited.

    That's good to know.


    I thought I could be cheap and reuse the CPK file's original TOC, just updated with the true sizes of the external files. But as it turned out, the CRI libs in Sonic Generations don't like that very much. And even if they did, that would still leave the problem that unsplit .ar files wouldn't work, or in general that files whose names weren't listed in the TOC to begin with could never be accessed.
    So, yeah, to get everything working as intended, I have to generate a completely new, virtual CPK file in memory, each time the game is started. That is, a header and TOC for it, not the data, that'll be read from disk.

    I've improved my patching method with some heuristics, now it works with all past and present versions of SonicGenerations.exe, and most likely with future ones too, should there ever be any. I won't provide a download link for this small update, unless somebody really wants it.
     
  17. Azu

    Azu

    I must be stupid. Member
    This isn't Sonic Generations, but this funny as hell.

    http://www.youtube.com/watch?v=xweLnNHDqbQ
     
  18. KuroBit

    KuroBit

    Member
    38
    0
    0
    Hahah I saw this. I totally thought I was watching Generations at first.
     
  19. Iggy for Short

    Iggy for Short

    Member
    820
    183
    43
    Apparently, so did someone down at Sonic Stadium. The story that featured the video originally mistakenly said that it was related to the Generations Unleashed project.

    OT: So has anybody figured out anything about the Egg Dragoon teleport?
     
  20. Mastered Realm

    Mastered Realm

    Member
    3,831
    558
    93
    -
    Sorry because I'm lazy and don't want to read the entire 107 pages but

    Is it possible to make a mod specifically to make the camera roam? Like some button that would move the camera and it's interest point without changing the fov, because I'd REALLY like to explore the scenery more closely! Sky Sanctuary is so well modeled!!