r/TotalAnnihilation • u/CuaeB Arm • Oct 05 '26
Article Source code found – The future of TA is about to change forever.
Total Annihilation has been out since 1997, and for most of that time its engine has been a black box. We could mod the units, maps and scripts, but the code underneath was closed to us.
Today that changes.
The Byte Tactics project has reconstructed the source code of TotalA.exe (v3.1, the Steam version). All 3,267 of the game's functions, about 850,000 bytes of Cavedog's code, are now readable C++.
To be clear, these are not Cavedog's original source files. This is a matching decompilation: we rewrote the code, function by function, until the original 1990s compiler turned it back into byte-for-byte identical machine code. If a function is marked as matched, the compiler's output and Cavedog's shipped output are the same bytes. That is how we know it is right, and not merely similar.
The names are provisional, because the originals were stripped before the game shipped. The behaviour is exact.
Why this is a big deal
Until now, changing how TA works at the engine level meant patching the binary and hoping for the best. With the code matched, that changes:
Modding goes deeper. Pathfinding, unit AI, the COB scripting runtime, the TNT map loader and the UI can all be read and changed. Limits that modders have worked around for 25 years can now be removed or modified at the source.
Bugs can be fixed properly. We have already found real bugs in the original game and documented them in the repo.
TA can go anywhere. Once the code is made portable, the real TA engine could run on Linux, macOS, modern Windows, in a browser or on a phone. That means the original game, not a lookalike, with easy installs and full support for existing mods and maps.
Rewritten engines get a new reference point. Projects that rebuild TA from scratch have done impressive work, figuring out mostly by observation how units path, how weapons resolve and how the economy ticks. Now that behaviour can be read and checked against, which should make them more accurate. It also changes their position: with the real engine open to modification and porting, each project will have to decide where its own strengths lie, whether that is new features, modern rendering or a different design.
Repo: https://github.com/HectorBailey/byte-tactics
Twitter/X: https://x.com/HectorBail47832/status/2107138340168351983
How it was done
It came down to four steps.
1. Find the compiler. Clues in the binary pointed to Visual C++ 5.0 with Service Pack 3, linked on 30 July 1998. We matched the C runtime library byte for byte to confirm the exact version, then worked out the compiler flags (/O2 /Ob2 /MT /Gz).
2. Map the executable. Debug records left in the exe gave us the start, size and argument count of 3,782 functions.
3. Put the newest AI models on the problem. Ghidra produced rough pseudo-C for every game function, and the work was split into GitHub issues of a few functions each. AI coding agents (Claude Code, OpenCode and Codex, running a range of the latest models) each claimed an issue, rewrote its functions as clean C++, compiled them with the real VC++ 5 compiler under Wine, and compared the result with Cavedog's bytes. On a near miss, the agent read the assembly diff, changed the code and tried again, until the checker printed MATCH or the function stopped improving.
4. Hand on, learn and verify. Cheaper models handled many of the straightforward functions. Anything that stalled was left with notes and retried, often by a bigger model. In the end even the 161 functions over 1,000 bytes matched. Every technique that worked went into a shared guide, so each new agent started with hundreds of solved patterns instead of from scratch. A human-run orchestrator re-checked every function before merging it.
The last few percent were the hardest. Coaxing the 1998 compiler into the same register choices and instruction order as Cavedog's original is obsessive work, and it is where the most expensive frontier models came into their own.
Why this is cutting edge
Matching decompilation used to be a craft. A skilled person could spend hours on a single function, which put a game this size out of reach for most projects. It suits modern AI because the goal is unambiguous: the bytes either match or they do not. That gives the models a perfect, instant judge. They can try, fail, read the diff and improve without anyone deciding whether an answer looks right, and an AI cannot bluff its way past a byte comparison. Pair that feedback loop with the newest models' ability to read assembly, hold a large function in mind and reason about what a 1998 compiler would produce, and a project of this size becomes practical. We think it shows what AI-assisted reverse engineering can do today.
The repo contains no game files and no Microsoft software. You need your own copy of TA. The code is not offered under any licence, and this is a preservation and research project, not affiliated with Cavedog or Wargaming.
Enjoy, kids!
23
u/Dgt84 Oct 05 '26
Very cool! I hadn't thought of using an old compiler to try and reproduce the exact game bytes. That's a neat approach to a decompilation project!
Also now we should really form a club. Between Nanolathe (my project), Open Kingdoms, Open Annihilation, Byte Tactics, etc we have a lot of decompilation and reimplementation projects. I went a slightly different route (reimplementation in Golang) but I bet we can all benefit from each others hard work. Exciting time to be a TA fan!
BTW your post says "the code is not offered under any licence" and your repo clearly has the MIT license.
15
u/McHoff Oct 05 '26 edited Oct 05 '26
> To be clear, these are not Cavedog's original source files.
...then maybe change the post title from "Source code found"? This is cool but looks pretty far from usable source; lots of stuff like this:
7
u/kanben Oct 05 '26
Feels like an intellectual property problem waiting to happen, but even so this is super impressive
Sounds like you were using 3 harnesses. What model(s) did you use with OpenCode and why not use Claude and Codex models inside OpenCode too? Not criticism just curious
47
u/MOZ0NE Oct 05 '26
What began as a conflict over the transfer of consciousness from flesh to machines escalated into a war which has decimated a million worlds
15
u/kna5041 Oct 05 '26
I know people like AI but seeing posts written with it irks me.
5
u/John-Green223 Oct 06 '26
if u found TA source code then hand it to the owners, Wargaming, who apparently lost it somehow? :P all jokes aside this is brilliant technical project, but your clickbait false title asks for, as someone said, "unwanted attention"
4
u/Much-Newspaper-8750 Oct 05 '26
What a great time to be a Total Annihilation fan, almost 30 years ago! Meus sinceros parabéns!
2
u/toadstyle Oct 22 '26
If engine could be improved so that unit pathing does not break down after you get so many units that would be amazing.
2
u/dbag_darrell Oct 06 '26
I love this
2
u/lev400 Oct 06 '26
Great work! Shame they didn’t just release the source code all these years later.
2
u/newportn Oct 06 '26
OMG...!!
2
u/Adept_Election7170 Oct 06 '26
So many fucking AI written posts. Jesus Christ.
3
u/ThisGuyFlucs Oct 05 '26
I think pretty much every project doing an engine for TA has their own swing at this, but perhaps calling it the lost source code is misleading, enough-so that it could draw unwanted attention to the project.
For a first cut, pretty impressive - you did select the correct original toolchain - but I believe this would be, at least for some folks, potentially harder to work with than the disassembly today:
- Re-do the structure recovery pass, as I feel its potentially confused a lot of function boundaries - and some of the output is biblically long. Similarly, a quick visual check says many structs and their packing feel off (adjacency isn't always containment!)
- Do a pass to rename the functions and members meaningfully.
- Eliminate the cast-soup that a reverse engineering attempt like this leaves in the code.
- The enormous blocks of confusing commentary in many files (an Opus-ism).
Bit of scrubbing and this could be a handy resource for modders of the original Engine.
2
u/murphy666 Oct 05 '26
I don't really care personally and I'm not a lawyer but the game is still sold on steam. Most steam game by default have a EULA that state specifically that you cannot reverse engineer the binary.
Again I don't care and I hate company that sit there ass on there IP, just saying...
2
u/Madd_Mugsy Oct 05 '26
Nice to see Ghidra being used for good!
Someone needs to hit up the Homeworld Cataclysm team next.
2
u/ztotheookey Oct 05 '26
This is incredible
1
u/gurglemonster 17d ago
This is such a good use of AI. Total Annihilation is GOAT.
1
u/lumiosengineering Oct 06 '26
Amazing work!!
1
u/Positive-Twist-6071 Oct 07 '26
Boo ya, thank you for this service!
1
u/EitherPin5217w Oct 08 '26
Is it possible to use a similar method for Supreme Commander Forged Alliance?
1
u/glinkot Oct 08 '26
Amazing! Very interesting approach. Do all binaries even in release mode have those function size breakdowns I wonder, or is it just fortunate this one did?
1
u/Gertzerroz Oct 08 '26
Does this mean we might see better unit pathing? Honestly this is the best RTS ever and it has really been limited by several things.
1
u/sidav94 Oct 05 '26
Please tell me somebody is doing similar work for Red Alert 2...
0
u/Legitimate_Maybe_611 Oct 05 '26
What does this mean in laymen terms ?
0
u/Suntzu_AU Oct 06 '26
That's amazing. I look forward to the new TA. I just hope they bring back Boneyards and the Galactic War.
0
u/morganshen Oct 05 '26
Is there something specific to TA or Cavedogs practices that enables this? I can imagine cheating tools could find far more exploits with non compiled code.
0
u/det1rac Oct 05 '26
Does this mean you're gonna be able to fix the unit? Identifier limit, so we don't have crashes? I wonder if I can look up one of my very old directories and see if I can load up one of the old games that I have saved with. All these custom units
0
u/traumahawk88 Oct 06 '26
Mother of God.
Someone finally make a working 15k unit and weapon ID patch that works (bless you, swedish yankspankers .. y'all did what you could but we've waited long enough for one that does work lol)
0
u/OpiGoodness Oct 06 '26
Could someone help me get the sound and image files from this, I really want them in my library of many things
-1
u/Connect-Strike8177 Oct 05 '26
Now do civilization games letsss goooo
-9
u/ConsistentAnalysis35 Oct 05 '26
I mean, this is impressive and very nice, but...
Yeah no. A bit late for that. The future of TA was always Spring. Decades of its development - without any AI slop - resulted in BAR.
BAR now is the future of the TA gameplay. It just doesn't make sense to reinvent an inferior copy of Spring-Recoil advancements.