Sonic and Sega Retro Message Board: Sonic R Hacking - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
  • 18 Pages +
  • ◄ First
  • 12
  • 13
  • 14
  • 15
  • 16
  • Last ►
    Locked
    Locked Forum

Sonic R Hacking Because somebody should.

#196 User is offline MainMemory 

Posted 15 February 2017 - 03:26 PM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4005
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339

View PostInvisibleUp, on 15 February 2017 - 02:15 PM, said:

Oh. I should have noticed that beforehand. That actually sounds like exactly what I need.

...I really should have brought up my need for this earlier. Making my mod loader was a definite learning experience I needed, just for the sake of knowing C and Win32 enough to work on Sonic R or whatever else, and also making a decently size project.

I guess I just forged ahead in that direction because I had no idea how to make your mod loader work with Sonic R. Also, I assumed mine would have taken significantly less time to make.

I'm not sure what to do now... I'll release mine anyways, as I still think it's neat, but I'm not sure if I should actually use it or not considering all the limitations it has.

I can definitely appreciate the work you've put in to what you have, since I've basically just given up on this game and gone back to what I know. It's fine to release what you have, it'd be a shame to just throw it away, and you've said it works for more than just Sonic R, so maybe someone will find some use for it. If you are interested in the DLL injection angle, perhaps we could find some way to adapt the SADX Mod Loader framework to Sonic R.
This post has been edited by MainMemory: 15 February 2017 - 03:28 PM

#197 User is offline DetoNtn 

Posted 15 February 2017 - 05:13 PM

  • Layout Master
  • Posts: 14
  • Joined: 28-January 17
  • Gender:Male
  • Location:Virginia

View PostChibisteven, on 14 February 2017 - 09:30 PM, said:

Actually my 1998 (Expert Software) version works just fine with all the patches I have for it.


I checked, and I have the Expert Software version that was included in the Sonic Action Pack. I suppose the only patch I need is the No-CD patch..? I guess I'm not understanding the concept of that, seeing as I have the physical disc.

View PostInvisibleUp, on 15 February 2017 - 02:06 AM, said:

(Hey, look, I'm not dead) The annoying thing about the 2004 version is that it needs to be properly installed. You can't just copy the files over and apply some patches and have it run. You need to actually install it, which leaves a nasty InstallShield Updater sitting there in your control panel, taunting you for all eternity.


Note taken on the lingering InstallShield. Now, are your mods that you've made only for the 1998 or 2004 version? Or is there any significant differences between the two?


View PostInvisibleUp, on 15 February 2017 - 02:06 AM, said:

If you're using the 1998 version, you'll probably want a No-CD patch. Don't use this to pirate the game, please. Replace 0x00C13C3 through 0x00C13C5 with bytes 9090 Replace 0x00C13EA through 0x00C13ED with bytes 9090EB---


Don't worry, I don't have any reason to pirate the game.



View PostInvisibleUp, on 15 February 2017 - 02:06 AM, said:

You'll miss out on the music, but I'm working on a fix for that. Honest. Already got a DLL coded and everything. It plays BRSTM and OGG files like a dream. What's the hold up? I have to inject initialization routines into the game's initialization function. It's a tightly packed thing, so I have to throw out the few lines of code that just clear unused memory and replace it with something. For just the music hack, that's fine. Just throw the new code in some unused area (like the old Network code), make a jmp to that, and that's that. Cool.However, when it comes to adding custom characters with custom abilities and more polygons than the original (something I can't do just by changing out files), I have to dynamically allocate some memory large enough to fit all the models (the original was statically allocated to a certain size I can't change at all) and then replace every single reference to the old, static block of memory to the new dynamic block, which annoyingly is one byte larger so I have to shuffle code around and yeah... (I've counted 84 places I have to fix that. So far.) Plus, any change in character physics or abilities whatsoever requires a complete rewrite of the core physics routine to go and route actions and attribute modifiers to dedicated functions for each character. (By default it's a monolithic nightmare of nested if statements where each character is hardcoded in.) If I want to draw something new to the screen (a boost bar, perhaps), I've got to rewrite the entire HUD display code to allow for more code.---Point is, hacking this game without a split disassembly is no fun, and doing all of that by hand with a hex editor is simply not possible. Instead, I've been working on a custom mod loader (with the super-original name "Sonic R Mod Loader", but it's by no means limited to that) that lets me compile C or ASM "patches" with GCC (or simply hand-code the hex), convert it into a "mod", and then install that mod. (The C/ASM functionality requires a Linux machine, fyi)The "patches" (individual blocks of data or files) can reference other patches or "variables" (values set by a mod that can be updated my other mods) to determine where to patch and what should be patched there. For example, a mod for a character can have a patch that has a Jump function, and then another patch that registers that function (by inserting into a jump table) with an earlier mod that rewrites the physics code as described. Then, during execution, the game with the modified physics code can just use the jump table populated by all the other character mods to automatically go to the right subroutine. In addition, I can write these new functions in C and reference other functions either from other mods (or the base game, if you're fine dealing with old Watcom fastcall conventions which no compiler supports.) The base game functions (needed for library calls among other things) are provided by an external script that takes an IDC file from and IDA disassembly, finds every subroutine and named memory address, and copies it's locations to a "game definition file" that the mod loader later parses and sets up support for.What I'm saying is that it's neat and does a lot of cool things.---Here's the manual for the mod loader if you want to get a taste. Note that this isn't final, but it's pretty close.It's been in development for a while (well over a year), mostly because before I started I had no idea how C, any sort of GUI programming, SQL, or project management in general worked. My decision early on to program it in raw C with an old copy of Borland C++ 5.5 (with no debugger) in the vain hope of achieving Windows 95 compatibility didn't help much. (I've since upgraded to Visual C++ 6. For some reason. But it's using CMake as it's makefile, so it also compiles just fine on 2015 as well.)Right now I'm almost ready for release. Every function I've described works except for the ability to alter mods installed before a variable was changed. (That's important for, say, reallocating blocks depending on how many elements exist). I'm rather proud of it, even if there might be a few things out there that do its job better. Hopefully you'll see something cool from me for the SHC.---That was a really long post that got off topic fast. But hey, at least you know how not-dead I've been. //forums.sonicretro.org/public/style_emoticons/default/smile.png


Your work on Sonic R is nothing short of amazing. I'm definitely happy about a mod to make the music run cleanly, because it's probably the best sonic soundtrack out there. Keep up the ingenious work.

View PostChibisteven, on 15 February 2017 - 03:10 AM, said:

Does it include FLAC support?Anyway my method for disabling the CD check was to copy a file "SONR_CPY.txt" and "XXXX" from the CD-ROM. Removed drive letters "ABDEFGHIJKLMNOPQRSTUVWXZ" in one part of the executable (readable strings) and replaced it with this path "C:\Sega\SonicR\" (DO NOT USE THIS TO PIRATE GAME!). So I could use custom Audio CD that fixed the bizarre glitch I was having.I then rip the game's soundtrack and adjusted the sample offset (it was awfully large offset, never seen something authored like that before with any PC game) until things lined up and then splitted it into separate audio tracks. Burned an audio CD-R with 15 seconds gaps between tracks and added an extra track at the end to avoid a CD playback glitch. Works like a charm for me.


I'm assuming you did the audio fix with 1998 version? Also, it's a very clever fix. Definitely will try once I get my Sonic R to run.

#198 User is offline Morph 

Posted 15 February 2017 - 05:53 PM

  • AKA SonicFreak94.
  • Posts: 758
  • Joined: 01-August 08
  • Gender:Male
  • Location:Utah
  • Project:SA1/2 hax
  • Wiki edits:11

View PostInvisibleUp, on 15 February 2017 - 01:36 PM, said:

When I first started working on this, I looked at yours. No offense, but it just doesn't seem like it would work. Please correct me if I'm wrong, but your mod loader seems to mostly work by acting as a debugger and modifying RAM values. Sonic Adventure DX is a much better (or at least more generically) programmed that lets you get away with this stuff. With Adventure, I imagine you can just swap out files and play with memory addresses to get most things working, like custom characters or stages. That SA2 network mod program, for example,just injects a new player object into the game and updates its attributes on each packet. The core game is largely unmodified, and what modifications are there are trivial.


This is a massive misinterpretation of how any of this works. Did you even look at the code? I'm honestly not sure how you came to this conclusion. Debugger? What?

For example, my recent palette lighting mod required me to hijack various functions throughout the game's rendering pipeline so I can feed information to my shader. Not to mention I had to hook stage management objects to handle things like palette interpolation for Sky Deck and the Mystic Ruins Past on fire.

I also wouldn't consider SADX any more generic by any means. It's written in C, and wherever they could get away with using a union, they did. It's the most infuriating thing to work with. One object could use the field of a structure as a byte, another uses that and the next three as a pointer, and another uses it arbitrarily as a float.

SA2 Battle Network in its current form straight up replaces in-game functions to perform networking, it doesn't just "inject a new player object". Did you even know it has a two player mode? :psyduck:

#199 User is offline InvisibleUp 

Posted 20 February 2017 - 02:01 PM

  • Posts: 98
  • Joined: 10-November 12
  • Gender:Not Telling
  • Project:Sonic Redux (Sonic R hack)
Yes, I did read the source code. I'm not trying to belittle your efforts or anything (no, seriously, that mod is really impressive). I made a mistake. I fucked up. I'm glad it happened with something petty like Sonic hacking. I've learned that I should probably ask people how their code works when I'm not sure. I've learned, from making that mod loader, how a larger project is structured, how a GUI is programmed, and a lot of stuff about programming in general. I did not have that experience when I started. It was dumb of me to not build off of existing work, but I honestly tried to understand MainMemory's mod loader, and a lot of what I saw flew over my head.

I came to the conclusion I did with MM's loader from the Wiki article and trying to read the source code. I didn't have the 2004 version of SADX or the PC version of SA2, so I couldn't test out these features myself. I came to the conclusions I did from the Wiki page and the source on GitHub. I was aware that it touted features like "Data Patching" and "Call Insertion", which sounded like things I wanted, but I couldn't figure out to what extent they worked. Looking at the source code. I looked at the "SADXModLoader.h" file, which is the public API for mods. In sadx-mod-loader/SADXModLoader/include/SADXModLoader/SADXFunctions.h, for instance, I see a lot of specialized functions like "PlaySound" or "GiveLives". That seemed to be a list of internal functions within SADX that I could call from my DLL. Fine, but not what I need. I can see that sadx-mod-loader/SADXModLoader/include/ModLoader/MemAccess.h did include a WriteCall() and WriteJump(). In hindsight, I should have noticed that. But looking at all the functions above, I came to the incorrect conclusion that only dealt with memory stuff. I'm not sure why I came to this conclusion. I made a really dumb mistake. I apologize for it. I came to the "it acts like a debugger" conclusion because debuggers do exactly what this mod loader is doing. It writes memory in running processes. It can even rewrite code. (That's a feature of the Cheat Engine I've used extensively during file format research.) I'm pretty sure it even uses the Win32 debugging API for hooks and WriteProcessMemory and the like. My only guess as to how I missed this blatantly obvious thing was that, when I started working on my mod loader, I had no idea how large code bases worked. I had no idea how to read a large code base. I had no idea where to even start looking. Even if I wanted to use a debugger, it wasn't like I could test it with anything. Not understanding what I was looking at was a bad reason to draw these conclusions.

I should have looked at the source code of other mods. I did not follow the SADX mod community closely, because I didn't own SADX. I had no idea how much wonderful effort they were pouring into that game.
As far as your SA2 multiplayer mod, yes, obviously I'm aware that it supports 2 players. I am not diminishing the effort you put into your work at all. That is an amazing technical achievement. I just assumed you went around doing it a different way. I read from the mod's GitHub page that it used to be a separate program, and then it used the mod loader to leverage player input values for synchronization. I assumed, from this, that it did all the networking stuff in it's DLL and it used the mod loader's (and previously just raw memory writing through the Win32 API) abilities to update it's position, animation, and rotation values of the 2P object when the game was in 2P mode. (Not sure why I said "inject a new object".) From the YouTube video on your forum thread, it didn't seem to present any new UI features or otherwise appear to be modifying the game's original code in any way. I will admit I did not look closely at the mod's source code. This was a mistake. I was not aware of the fact that it needed to hook in calls. I assumed that it was using the memory writing function calls I was aware of to do it's work. I was also not aware of the existence of your palette lighting mod. I apologize for dragging you into this mess, Morph.

I had no way of testing either the mod loader or any mods, so I did not know what MM's mod loader was capable of. It was dumb of me to not trust the Wiki article. It was dumb of me to not even see what was capable by checking out other mods. I assumed that my weird solution would have been more capable and simpler to implement. At it turns out, none of those things were true. I underestimated the effort that my mod loader would require. Look, I messed up. I sucked at reading source code. There is absolutely no defense for everything I've overlooked and I apologize because of it.

But before doing this, I had never written a program longer than 500 lines or so. I think, even if I knew that MainMemory's mod loader would have worked perfectly, that I would have tried my own way anyways. At the time, I had no idea where to even start hacking on a large code base. I had no clue how to port MM's mod loader to a new game. The code base was daunting to me. I even tried compiling it, but for some reason I couldn't get that to work. Even if I really wanted to use MainMemory's mod loader, I don't think I had the ability to do so. (I mean, look, I somehow managed to consistently overlook exactly what I was looking for.) I'm doing this Sonic R hacking stuff as a learning exercise, as recreation. Even if I'm doing this in the dumbest way humanly possible, I'm learning from it. I'm not trying to insult anyone here. I'm not intentionally making it sound like these things aren't impressive, or capable. I just made some really, really dumb assumptions, but I've learned from my mistakes. This mod loader has taught me how GUI programming works, how to track bugs, how to use version control, how to use a debugger, how to manage projects with multiple files... I needed do something like this.

I'll try to keep you guys more in the loop with what I'm doing in the future. I'll research my options before jumping onto the not-invented-here bandwagon. I'll ask if need help understanding somebody's code. And, probably most importantly, I won't fabricate dumb assumptions that put down other people's work. I feel incredibly sorry for my actions. I will, however, keep working on this Sonic R stuff. ...mostly because I'm too deep into it to quit now. Also, apologies for causing a drama storm. I just want to move on.

EDIT: Cut out some text, rephrased, etc.

This post has been edited by InvisibleUp: 20 February 2017 - 02:06 PM

#200 User is offline Morph 

Posted 20 February 2017 - 03:29 PM

  • AKA SonicFreak94.
  • Posts: 758
  • Joined: 01-August 08
  • Gender:Male
  • Location:Utah
  • Project:SA1/2 hax
  • Wiki edits:11
oh god

Hey man, I didn't mean that to come off so harshly (although I'll be the first to admit that that's a recurring problem; I should more carefully consider my posts :v:). I was just legitimately trying to figure out how you came to the debugger conclusion, because as far as I know that's actually more complex than what we're doing now. I could be wrong though, because I've never tried to implement a debugger from scratch. Might be fun to mess around with, thinking about it...

That and you gave me a little too much credit on the SA2 netplay thing. Convincing the game to inject a new character object by just poking at memory would be pretty amazing, honestly, but all I did was take advantage of the game's existing two player mode. I'd say most people are out of the loop when it comes to Sonic Adventure hacking though, so I really don't blame you or anything.

On the note of the code injection and all that: had you hypothetically asked us about how the mod loader worked but were still interested in implementing your own, I would have absolutely said to go for it anyway. As you mentioned, fantastic learning experience (if not fun). Plus, I'm always more than happy to explain how something works, especially if it helps somebody else expand their experience and programming knowledge.

With all that said, I don't know if you've come across it, but you might be interested in my "trampoline" implementation present in the mod loader (Trampoline.h & cpp), which allows you to hook a function and still run the original, mostly-unmodified version of the code that was replaced. There are much more robust implementations out there (like in minhook, for example), but it was definitely fun to implement.

p.s. I didn't take offense or anything, I was just surprised is all.
This post has been edited by Morph: 20 February 2017 - 03:29 PM

#201 User is offline InvisibleUp 

Posted 20 February 2017 - 09:30 PM

  • Posts: 98
  • Joined: 10-November 12
  • Gender:Not Telling
  • Project:Sonic Redux (Sonic R hack)
It's fine. I just read your comment as a little harsh and got overly defensive because of it. (Actually, rereading that, ...yeah that was a little too much.) I'm nowhere near as miffed as you think I am. I guess if one thing is clear, it's that it's hard to express emotions in words.

Glad we're all on good terms. Let's move on.
This post has been edited by InvisibleUp: 20 February 2017 - 09:31 PM

#202 User is offline MainMemory 

Posted 20 February 2017 - 11:20 PM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4005
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339
I wonder if it would be possible to integrate DLL injection into your mod loader, or if it would be simpler to just port the SADX Mod Loader as a separate project.

#203 User is offline InvisibleUp 

Posted 10 March 2017 - 02:01 AM

  • Posts: 98
  • Joined: 10-November 12
  • Gender:Not Telling
  • Project:Sonic Redux (Sonic R hack)
So. Cool new thing to show off.



What you're seeing off to the side is some debug text the devs left in. Normally all of these strings are assembled like a standard printf() input, then thrown out via a stub function. What I did is replace that stub function with a function that calls vprintf(). I also needed an init function that made sure it all got redirected to stdout. (It's supposed to also create a console, but I guess that's behind the game or something...) I did this with my mod loader, for the record.

This debug text mostly seems to be graphics related. What textures are loaded, what display mode is used, etc. There's also some random information like window events and how many rings are on the track. Some important functions also announce when they're being called. Not quite as useful as I thought it would be, but still pretty neat.

#204 User is offline Overlord 

Posted 10 March 2017 - 09:53 AM

  • Substitute Meerkovo IT Chief
  • Posts: 16617
  • Joined: 12-January 03
  • Gender:Male
  • Location:Berkshire, England
  • Project:VGDB
  • Wiki edits:3,204
That's pretty cool. Find anything interesting in the text that you weren't expecting?

#205 User is offline MainMemory 

Posted 28 October 2017 - 04:55 PM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4005
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339
So... it's been a while. I was asked on IRC if I could make a mod loader for Sonic R to make music load from the main game folder. I asked InvisibleUp if he had plans to release his loader, and he said he didn't, so yesterday I started working on porting my standard mod loader.

Here is my version of a mod loader for the 2004 version of Sonic R. It has all the standard features: file replacement, DLL injection (untested), and cheat codes (untested). It also patches the game to load music from the main game folder, in order to support custom music in mods. As a side effect of this, the game cannot load music from the CD, and the game no longer requires the CD to function.

I will add custom resolution support in the next version.

As always, the source code is available on GitHub.

#206 User is offline InvisibleUp 

Posted 28 October 2017 - 08:34 PM

  • Posts: 98
  • Joined: 10-November 12
  • Gender:Not Telling
  • Project:Sonic Redux (Sonic R hack)
Coming to a hacking contest near you!
Spoiler


#207 User is offline Shaddy the guy 

Posted 29 October 2017 - 12:07 AM

  • Head chef at the crap cafe
  • Posts: 173
  • Joined: 27-September 16
  • Gender:Male
  • Location:Beaverton OR
  • Project:One Piece English filler-free cut
Spoiler tags are broken for me, what is it?

#208 User is offline InvisibleUp 

Posted 29 October 2017 - 12:36 AM

  • Posts: 98
  • Joined: 10-November 12
  • Gender:Not Telling
  • Project:Sonic Redux (Sonic R hack)
Screenshot of a new character select screen with new characters

#209 User is offline MainMemory 

Posted 29 October 2017 - 12:48 AM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4005
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339
Usually when spoiler tags don't work, it's because you need to wait until every image and YouTube embed has finished loading before you can click on the button.

Well, this is certainly more impressive than anything I could've come up with.

#210 User is offline Shaddy the guy 

Posted 29 October 2017 - 04:17 AM

  • Head chef at the crap cafe
  • Posts: 173
  • Joined: 27-September 16
  • Gender:Male
  • Location:Beaverton OR
  • Project:One Piece English filler-free cut
That's an annoying way for it to work. Why can't it just load after I open it so I at least know it's doing something? Disregarding the fact that half the time it's just text anyway.

Anyway, that's a real cool lookin' mod you got there. I like low-poly stuff and it's not often done for post-genesis era characters, so I hope they look good.

  • 18 Pages +
  • ◄ First
  • 12
  • 13
  • 14
  • 15
  • 16
  • Last ►
    Locked
    Locked Forum

3 User(s) are reading this topic
0 members, 3 guests, 0 anonymous users