Resident Evil 4 (GameCube) – complete byte-identical decompilation to C/C++
Posted by metrofun 21 hours ago
Comments
Comment by groundzeros2015 19 hours ago
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;
}Comment by dezgeg 18 hours ago
Comment by groundzeros2015 17 hours ago
Comment by corysama 18 hours ago
Comment by vivzkestrel 3 minutes ago
- can someone skilled and passionate look into doing some of the older ubi titles?
- like maybe rainbow six vegas 1/2 or
- splinter cell games?
Comment by LaurensBER 20 hours ago
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.
Comment by NobodyNada 18 hours ago
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.
Comment by redox99 14 hours ago
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.
Comment by easyThrowaway 5 hours ago
We're ten years too early to do what you're suggesting. You need a really, really good understanding of the decompiled codebase and the original game and platform to port or implement new features.
You can't really ask "Claude, make Ocarina Of Time Widescreen" and expect it to work.
Comment by StilesCrisis 2 hours ago
Also, "widescreen OOT" is probably tweaking a pair of projection matrix floats in the binary so that might not be a great example :)
Comment by someonebaggy 2 hours ago
Comment by redox99 4 hours ago
Comment by yeoyeo42 51 minutes ago
Comment by NobodyNada 12 hours ago
To what end? The biggest benefit of tinkering with 40-year-old hardware is the experience of doing so. The knowledge and intuition you learn about how computers really work; the friendships you develop through collaboration with others, through asking for help with your projects and helping others with theirs; and the relaxing Saturday afternoons spent investigating and debugging and experimenting. The "benefit" of having a game that's been recompiled to a native executable for your PC or whatever is marginal compared to the benefit of the process to get to that point. That end goal is just a lighthouse to keep you on track, and when you get there maybe you'll play the recompiled game once to celebrate a job well done before moving on to another project.
If writing software is a means to an end, then there's value in anything that reduces the effort to get to that end. But as I see it, retro gaming projects are mostly an end to a means.
> Seems pretty egoistical when nobody's forcing you to use AI in any way, it provides an objective benefit to other people.
I have three fundamental claims:
- There is little to no positive benefit to using AI for hobby projects whose completion provides little to no intrinsic value.
- Choosing to do so has a negative impact on you, as it bypasses an incredibly valuable learning experience.
- Choosing to do so has a negative impact on others, as it takes away someone else's project opportunity (there are a finite amount of popular retro games, and many people prefer to work on novel projects rather than recreating something that has already been done).
I'm not sure what's "egoistical" about that, and I'd love if you could elaborate on that because I'm still wrestling with the ethics and implications of all this myself. The way I see it, it's better if I choose to forgo the use of AI on my projects, and I think others should choose the same.
---
Many years back, one retro gaming community I'm a part of had a prolific contributor who was extremely knowledgeable about the game, but also incredibly abrasive. He was the most knowledgeable person in the community at the time, and held this over others; discrediting their achievements, discouraging their attempts to learn, constantly starting fights and driving many good people out of the community. Yet he was allowed to remain in the community for many years, because everyone thought we needed his expertise.
Eventually the community came to the realization that it's just a video game and we don't "need" anything at all. None of the long-term community members are really here for the game anymore; we're here for the experience and the camaraderie. So we should make decisions (like kicking out this member) that are technically suboptimal for the game (at least in the short term), but better for fostering the community.
In a similar vein, using AI within these sorts of hobby spaces may allow faster progress on such projects, but it takes away the value of completing the projects in the first place, to the detriment of both the individual and the community.
Comment by redox99 11 hours ago
The biggest benefit to you. Other people, most people in fact, just like the game and want to enjoy it in new ways. They don't care about the code or reverse engineering itself. That people now benefit that it's easy to decompile because otherwise outside of really big titles like sm64, probably nobody is going to take the effort to manually decompile a less popular game.
That's the egoistical part.
Nobody is forcing you to use AI. And it's not really any different to how people would build their own NES emulators to learn instead of just grabbing whatever best NES emulator already exist.
Comment by NobodyNada 10 hours ago
My perspective is biased by the fact that such communities are an important part of my life. I don't want to see my years-long collaborations and friendships made obsolete by someone looking for an afternoon of nostalgia. And maybe everything will be fine, and the AI-users and the community-builders will go their separate ways and leave each other alone. But communities which exist today are having to ask how we should relate to AI, and my conclusion is that it's best kept out of hobbyist spaces if we want those spaces to continue to exist.
Comment by icantevenhold 4 hours ago
Why does it always need to be so complicated - I have zero interest in learning about these legacy platforms but I definitely want to play some nostalgic games.
Mindboggling that you see this as a negative and even want to kick out people to “protect” the community
Comment by Yokolos 9 hours ago
Comment by StilesCrisis 2 hours ago
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.
Comment by braiamp 2 hours ago
Comment by anakaine 15 hours ago
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.
Comment by tempoponet 44 minutes ago
This might be a product vs. eng split, but "whole point of the endeavor" isn't the same for everyone.
Comment by easyThrowaway 5 hours ago
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...
Comment by mw888 13 hours ago
You are clearly a wizard of a prior era. But it is a new era.
Comment by breezybottom 12 hours ago
Comment by cassonmars 8 hours ago
https://www.historyofinformation.com/detail.php?id=3439
"For this invention will produce forgetfulness in the minds of those who learn to use it, because they will not practice their memory. Their trust in writing, produced by external characters which are no part of themselves, will discourage the use of their own memory within them. You have invented an elixir not of memory, but of reminding; and you offer your pupils the appearance of wisdom, not true wisdom, for they will read many things without instruction and will therefore seem [275b] to know many things, when they are for the most part ignorant and hard to get along with, since they are not wise, but only appear wise."
Comment by card_zero 7 hours ago
It's also a critique of writing, written by Plato, to impress on us that Socrates was great orator (or arguer) and was better that way. But it's not somebody's reaction to the invention of writing. It's an imagined reaction to the invention of writing.
Comment by breezybottom 3 hours ago
Comment by shakna 4 hours ago
This is a political critique, on the rule of law (writing) over attempting to treat things on a case by case basis (philosophy).
Quoting it, without understanding it, is part of that author's complaint.
Comment by qwerpy 19 hours ago
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.
Comment by NobodyNada 12 hours ago
Comment by rtpg 16 hours ago
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.
Comment by qwerpy 15 hours ago
I looked at https://github.com/adonis-singh/re4/blob/master/src/wep/objM...
Can't really decipher what line 21 is saying so I concede there could be some slop in there. But the comments on lines 27-30 seem to be informative and give some context that the code doesn't have.
Granted, I'm not an expert on RE4's source code, but the comments look helpful enough.
Comment by rtpg 15 hours ago
Every company works in their own way, but I highly doubt the original source would have a big paragraph at the top instead of a more "structured" comment. Or maybe even nothing at all!
Here's a "counterexample": the pistol code for half life 2[0]. Comments are pretty sparse because it's all relatively self explanatory. The comments that are present are to point out things that are not so.
You end up with something that's easy to work with and where you're not trying to read a paragraph of text that enumerates a bunch of properties of the code in the file in no particular order.
Some things are important context for the whole file. Some things are important context for a fragment of code. Some things ... are simply not that important to note.
[0]: https://github.com/ValveSoftware/source-sdk-2013/blob/master...
Comment by brettermeier 5 hours ago
Comment by dwroberts 3 hours ago
Comment by ronnier 19 hours ago
Comment by phatfish 16 hours ago
Comment by bigyabai 18 hours ago
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.
Comment by StilesCrisis 44 minutes ago
Sure there were smaller emulators which didn't work well, that's understandable. But gamers didn't need more than one or two emulators to play every game that existed; you just needed to pick the right ones.
Comment by easyThrowaway 4 hours ago
Well... it sorta did, on the other hand the scope of the project is just too big for any of those forks to survive more than a few releases. There's a multitude of various Proton releases with a single-game support. The android-oriented builds are even a bigger of a mess.
Comment by 12397 19 hours ago
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.
Comment by qwerpy 19 hours ago
Comment by 12387a 2 hours ago
Comment by wk_end 20 hours ago
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.
Comment by brandonpelfrey 19 hours ago
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.
Comment by Tiberium 19 hours ago
Comment by jchw 19 hours ago
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..
Comment by StilesCrisis 11 hours ago
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!
Comment by jchw 11 hours ago
There are plenty of examples where two very semantically different source codes can have the same output, which is really counter-intuitive when combined with the difficulty that often comes with trying to find a single source code that does match.
This is just another reason why debug information is such a godsend; having symbol names for C++ code will usually give you most of the function signature, and type information will give you the rest. That greatly enriches the disassembly, and the automated decompilation output, and no doubt constrains the number of possible source codes that could match both the output and the debug information, somewhat alleviating this issue.
Comment by StilesCrisis 2 hours ago
It's a huge benefit that things like the OS and SDK are known and predictable. This got me a foothold. Otherwise I would have gotten nowhere.
I'm still impressed that this decomp has macros (fully lost in the assembly) and nearly-100% meaningful variable names and struct layouts. That's not easy!
Comment by jchw 2 hours ago
Comment by StilesCrisis 1 hour ago
Comment by jchw 1 hour ago
Comment by StilesCrisis 25 minutes ago
Comment by Pannoniae 17 hours ago
Comment by jchw 17 hours ago
I haven't tried this, but I also suspect that once you have a lot of code fully matching, it might make it possible to ratchet your way up further into builds that you don't have debug information for, that may have more aggressive compilation options. I am not sure if you would manage to get /LTCG builds fully matching even with this advantage, but it's going to be the best shot at it. You're possibly 90% of the way there already.
Comment by Pannoniae 17 hours ago
And yes if you have a pdb / an Od build then things are much easier, I was assuming arbitrary game i.e. release binaries.
The "knowledge laundering" approach you describe might help in reconstructing headers, class layouts and function names which is a godsend although I don't think it would be enough to get a match. Getting functionally equivalent code is muuuch easier (although there's the problem of "how do you verify that without running every function")
Comment by jchw 15 hours ago
AI is pretty powerful for decompilation, especially because you can also just have an LLM go and start reverse engineering bits of the linker and compiler if you want. (I suspect this decomp is AI assisted if the Clauded out README is any indication.) Maybe future models will be able to come up with clever and novel ways to reduce the number of possibilities and converge faster on possible matching source codes. Or maybe not; I think Astra is the best LLMs have ever been at decompilation and yet I find LLMs frustrating and prone to getting deeply stuck in local maxima in my experimentation.
Comment by Pannoniae 6 hours ago
Comment by Pannoniae 20 hours ago
Comment by mitxela 18 hours ago
Comment by Pannoniae 17 hours ago
"get the order of local variables in this function right, otherwise the register allocation doesn't match. Oh and there's 150 local variables just in this function, good luck trying them all"
"Find out the translation unit boundaries exactly (assume there's no pdb otherwise this is trivial) and after doing so, figure out the order they were compiled in, otherwise it won't match"
"brute force the compilation flags for the project and if you're done, also bruteforce it for the CRT or any other middleware which usually came prebuilt so it doesn't match the main game"
Should I continue;)
Comment by mitxela 16 hours ago
Comment by Pannoniae 16 hours ago
So these are mostly problems with more advanced compilers yk
Comment by dezgeg 7 hours ago
On the other hand, I have heard even old MSVC is a nightmare. Various things are affected by hash table ordering (so the names of variables matter in some situations), stuff like order of #includes mattering, etc.
Comment by Pannoniae 6 hours ago
Comment by mitxela 18 hours ago
Comment by Sesse__ 1 hour ago
Comment by toast0 20 hours ago
Maybe someone else comes and helps out here and there.
Comment by ErroneousBosh 19 hours ago
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.
Comment by shakna 18 hours ago
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.
Comment by throwaway888777 2 hours ago
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.
Comment by mitxela 17 hours ago
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.
Comment by shakna 4 hours ago
If you are "significantly similar", you are probably infringing.
Feel free to explore the myriad of precedent setting cases in the music remix community.
Comment by mikae1 20 hours ago
Too bad all the cool decompilation is happening for games on early 3D centric consoles. I say this a Quake fanatic. Low res textures combined with that blurry bilinear style filtering is a look that's not easy to love. It's just a generational thing I guess.
Comment by toast0 20 hours ago
Doesn't mean I liked them, or that they wouldn't have been better as a 2D game. But IMHO the graphics stopped distracting from fun games... OTOH, I played plenty of games on the Atari 2600 were the player character wasn't much more than a chonky pixel :p
Comment by chocochunks 19 hours ago
There has been some 2D decomps too, Pokemon Red/Blue being the biggest I can think of. I can also imagine they make more sense for the 3D consoles where games tended to be written in higher level languages than raw assembly.
Comment by mitxela 17 hours ago
Comment by mikae1 19 hours ago
Comment by chocochunks 19 hours ago
Comment by saturn8601 20 hours ago
Comment by mitxela 18 hours ago
Comment by ricardobeat 20 hours ago
Comment by moduspwnens14 15 hours ago
Comment by Tiberium 20 hours ago
Comment by sharktheone 19 hours ago
Comment by sick_of_slop 13 hours ago
Comment by devinprater 13 hours ago
Comment by mw888 13 hours ago
The unceremonious use of (what I speculate is) AI-assistance is becoming more normal. I think a lot of people who were die-hard skeptics will just quietly protest less and less. Also, for people who use it well and poorly alike, the urge to not advertise any AI-use at all is common today. People who know how to use it well don't feel the need to explain themselves to unreasonable absolutist skeptics.
Comment by Dwedit 18 hours ago
Comment by davikr 20 hours ago
Comment by sick_of_slop 20 hours ago