Resident Evil 4 (GameCube, G4BE08 debug build) — complete byte-identical decompilation to C/C++ - adonis-singh/re4
99 comments
void Em1eWeaponSet(cEm10* em) { Em10Work* w = EM10_WK(em);
w->mot[41] = 0;
w->mot[42] = 0;
…
w->mot[62] = 0;
w->mot[63] = ARC(0x26C);
w->mot[64] = ARC(0x26D);
w->mot[65] = ARC(0x276);
w->mot[66] = ARC(0x277);
w->mot[67] = 0;
w->mot[68] = 0;
w->mot[69] = ARC(0x26A);
w->mot[70] = ARC(0x26B);
w->mot[71] = ARC(0x270);
w->mot[72] = ARC(0x271);
w->mot[73] = ARC(0x272);
w->mot[74] = ARC(0x273);
w->mot[75] = ARC(0x274);
w->mot[76] = ARC(0x275);
w->mot[77] = 0;
w->mot[78] = 0;
}The puzzle is then trying to piece the context back together by probing the game to recover something that approximately resembles what the original code might have looked like.
Eventually you can do things like Dusklight for advanced modding and feature implementation.
From a technical perspective emulation is absolutely amazing, it requires deep technical knowledge, an excellent understanding of the source system and the optimisations are on another level.
So having Claude one-shot a NES emulator is almost pointless to me. You're using and looking at source code for an emulator you didn't write -- and you can learn from that, but it's not the same thing and doesn't require you to really understand a CPU the way you would by, say, observing a deviation in game behavior and staring at trace logs to figure out the exact instruction you emulated incorrectly.
It's not all bad -- AI is a great research tool and can automate some of the tedious parts (writing out an instruction decoder by hand is miserable). But using it to just...skip over the effort of doing a project defeats the whole purpose of doing those projects in the first place.
I don't want to be gatekeepy or curmudgeonly or "back in my day..." about it. But for me, my entire career path is due to skills and knowledge I learned spending several years of my life as a teenager figuring out how to write an NES emulator as a relative beginner to programming. And so I feel like using AI for this is depriving the next generation of that learning process. In addition, there are only so many retro games, and fewer popular ones. There's only so much unexplored territory to discover, and doing it with AI deprives another person of that experience and deprives that game's community of someone who might have been able to find a "home" working on projects related to that game.
There's nothing stopping you from making an emulator without using AI or whichever way you think is best for your own learning.
AI allows players to have decompiled and in turn ports of games to new platforms, enhanced versions of the game, etc.
Seems pretty egoistical when nobody's forcing you to use AI in any way, and it provides an objective benefit to other people.
Yes people will lazy their way out of it. Many of us program, but few of us ever bothered to learn, with fluency, assembly. Those who wanted to did, and those who didnt stuck to higher level languages.
Personally, I think it's fascinating to see how the industry greats actually made the magic happen. Everyone talks about the endless fine-tuning of controls that Miyamoto asked for in SM64: now we get to see what that actually looks like! Or maybe the game had a hidden secret debug menu that no one's ever seen in 20 years, or an unfinished character is hiding in the code.
Maybe my perspective is different because I've worked on games for most of my career, so seeing how _other_ teams solved the hard challenges is exciting for me.
MAME is doing some amazing reverse engineering work on some more recent arcade boards by using AI[1] that would've taken decades to do so by hand, and it's being conflated with some rando committing to github the result of 5 hours of Claude stirring over the Golden Eye N64 rom and then publishing on twitter "Done, here's my Patreon link, please and thank you".
[1]https://mamedev.emulab.it/haze/2026-working-with-what-we-hav...
Boggles my mind that there is hate for AI in retro-gaming. It's all about making existing things work. If it works and plays well, who cares if Claude did it in an afternoon or some human who spent a year of his life. In fact, I'd rather have Claude do it. Humans will get bored, get involved in community drama, disappear, etc. Unfortunate for the humans who are seeing their life's contribution to the scene made obsolete by a few kilowatt-hours in a datacenter, but good for the rest of us.
This isn't to say it's impossible to guide good context-aware commenting style from.an AI, but there would be much terser/usable comments on all of the weapons source for example.
The biggest problem with this stuff is, as usual, that the people guiding the AI don't know what "good" decomps etc look like IMO. AI tool usage tends to reflect ones own tastes and understanding.
We live in a golden age of emulation because that attitude died out. With more powerful computers (and less hack-oriented development) it became possible to properly emulate a complete console with a high level of accuracy. For preservationist purposes, accurate emulation is much more important than being the first to emulate a game, or even being able to decompile it. The only reason that we can point and laugh at low-quality efforts like Nintendo Switch Online is because the community cares even more than Nintendo did. The reason Wine/DXVK/Proton works so well is because it didn't fracture itself into a thousand downstream forks to fix one specific game. It's a holistic effort.
A lot of the hand-wringing comes from a justified place that doesn't want to see emulation backslide into a bazaar-like community. You're free to disagree with their logic and vibe-code a thousand game decomps, but in all likelihood emulation will be a more popular choice for the foreseeable future. Lots of people emulate stuff on their iPhone or Steam Deck, almost nobody is playing a game decomp on it though. I can't imagine AI tipping the scales on decomp popularity, especially among average Joes.
You could put an Einstein paper on a photocopier, mask the author, put your name in the place and publish. Except everyone would have thought you are an idiot.
You could clone the Linux kernel, erase all copyrights and release under Idiux. Except everyone would have thought you are an idiot.
Now that there are laundering machines financed with unlimited printed and previously stolen money a large number of developers affirms and praises the idiots.
Made using the leaked debug build and its symbols, which shows how meaningful the work the game preservation community that acquires and distributes these things is.
OTOH this is pretty off-putting:
> Where the compiler needed a particular source shape to reproduce a register choice or a schedule and no natural spelling was found, the construct is marked with a // COMPILER-DIFF: comment (644 of them: dead tests, empty asm("") launders and anchors, register T x asm("rN") pins, padding statements).
To me the value of a decomp isn't reproducing the original bytes per se (we already have the original bytes after all) - it's about reconstructing the understanding of the original game as represented by human-readable source code; getting byte-for-byte is just an indication that you've gotten it right. Needing to add a bunch of slop to force the compiler to match the original output is actually just an indication that you've gotten it wrong - and it's a demonstration of the danger of Goodhart's law, especially as it applies to AI.
The reason I’m finding this is much faster than a traditional decomp is that while it’d be nice for the bytes to match, finding the perfect blend of compiler version, compiler args, permitting variables etc to try and find the perfect register assignments, etc is all very time consuming. My ultimate goal is not a byte for byte match, that’s just one way to ensure correctness. I’ve found agents are much faster and effective at reading the original assembly and understanding what’s going on then writing semantically equivalent C.
There is also value in decomps beyond just understanding and general interest. They can also be used to make more advanced mods, better translation patches, etc. The fidelity here matters, like having asm code accessing structures makes it hard to modify structures, but any fidelity improvement beyond pure asm is very welcome.
Of course I still prefer to try to recover the original code that caused the compiler to do what it did, but it's a really challenging problem sometimes. I've been working on decompiling code from old versions of MSVC for literally years now and you accumulate some knowledge of what things impact register allocation or the order of symbols but some of it comes from things that get fully erased from the source. Like for example, debug builds generally seem to retain symbols that aren't actually referenced anywhere, but those symbols only actually make it into an object file if they are. For functions that were only ever inlined and not actually referenced anywhere... They still wind up in the object files and thus in debug builds, despite nothing referencing them. They are also COMDAT any'd because they can appear in multiple objects legally, which means the exact object that winds up retaining it in the final linked executable is arbitrary (and the compilation flags of the object containing it, too - I bet that was fun for developers to debug.) This is incredibly useful but very challenging, needless to say. It may even be feasible to construct examples that would be legitimately infeasible to simply guess back to equivalent source, which I suspect is a major reason why until it was finally shown to be possible in larger scale projects many people wrote fully matching decomps off as a fool's errand..
void foo() { bar(); }
int foo(int x, float y) { return bar(x, y); }
This is because parameter-passing and return-value handling can sometimes be done in zero instructions in PPC, if the values are already in the right registers. So you need to continually go back and reassess old functions once you learn the signatures of newer ones!
Heh. I was just looking at the RE family on Steam. Nothing over a fiver.
I guess they really did make it more convenient than piracy.
You inherit the copyright from the original, as this is derivative.
There's a reason decompilation has always been a grey area of seeing whether or not the copyright holder cares.
You took a copyrighted work, did some lossless mathematical transformations on it, and have created an artifact that reproduces the original copyrighted work with perfect fidelity every time. From a legal perspective, this is effectively identical to zipping and unzipping a copyrighted file. You won't have much luck claiming that the intermediate Zip file is somehow free of copyright.
The legal problem is the original taint of using a copyrighted work (expressly contrary to its license), and the fact that nothing transformative is occurring here sufficient to enliven the defense of fair use. (Not even close, and no, this is nowhere near the realm of being arguable. The fact that this spits out a copyrighted work 'byte for byte' is a stake through the heart of any such argument.)
Decomp projects are cool, but if you work on them, please be aware that you're taking a risk, and some video game companies are famously litigious, even for old games.
There are also creative choices made in reverse engineering because there are many possible source codes that could compile to the same executable output. The author has to make countless choices around how to interpret assembly as higher level language constructs, and code organization in terms of functions and variables used. This isn't anything like zipping and unzipping some file, it's not a one to one transformation. As you can see we can absolutely have byte for byte identical output without having access to the original source code.
I agree that it would be copyright infringement if you distribute the original game assets (sounds, fonts, textures, models), but I strongly disagree when it comes to the source code because of above factors. And clearly distributing reversed source code without those assets would not enable someone to even obtain the original binary. They'd need to already have them in the first place (e.g. by buying the game and dumping them).
Also this is anecdotal but Nintendo is known for being quite belligerent with their copyright enforcement, they will take down various fan games in the name of protecting their IP. However to this day there are multiple full byte for byte decomps of Pokémon GBC games available on GitHub that haven't received so much as a DMCA takedown. Why wouldn't they care to take them down unless they couldn't do anything about reverse engineering? Nintendo still profits from reselling their old games after all (under their "Virtual Console" releases). The pattern repeats with Nintendo game console emulators, the only reason Nintendo is able to take some of them down is when these emulators include decryption keys for ROMs, they have never had a case for taking down an emulator on the basis of it behaving identically to the hardware they sell.
Both in theory and in practice I fail to see why you would be right that game decomps are illegal or even in the gray area.
The main reason you'd avoid this is to stop the first copyright holder from wanting to sue you - not because it's actually invalid.
If you are "significantly similar", you are probably infringing.
Feel free to explore the myriad of precedent setting cases in the music remix community.
Read the full thread on Hacker News →
Related stories
- Ars Technica · 0 points · 8 days ago
- Hacker News · 1 points · 1 day ago
- Complete Production Webapp in Leangithub.comHacker News · 1 points · 10 days ago
- Hacker News · 1 points · 9 days ago
- DEV Community · 3 points · 11 days ago
- A 256-byte Commodore 64 demo (2017)linusakesson.netHacker News · 1 points · 10 days ago