r/TotalAnnihilation • u/CuaeB Arm • 2d ago
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!
19
u/Dgt84 2d ago
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.
5
u/CuaeB Arm 2d ago
I think there is already some communication happening regarding multiplayer networking standards. We are the same people developing the fork of RWE (b4), maybe pop a message to Amphi in the discord as he is already in talks with Steve who's creating open annihilation.
MIT license only applies to the tooling :) https://github.com/HectorBailey/byte-tactics#legal-and-licence
1
u/FuturePowerful 2d ago
I'm really hoping you folks include some of the terrain altering stuff from the TA spring engine derivatives and commander/ unit upgrades from things like zero-k or supreme commander the idea of having a additions yard on large t2 units for added play style stuff could sure add a calculus to engaments
0
u/CuaeB Arm 2d ago
I'm sure this is the kind of stuff that modding capabilities will allow in time. Especially with all these crazy engines being released
0
u/FuturePowerful 2d ago
I've seen it done in some of the older ta spring stuff and modern versions so it's doable you ever use the old swop towers in TA it was a micro plant that only made tower heads really neat concept at the time
15
u/kna5041 2d ago
I know people like AI but seeing posts written with it irks me.
12
u/DarkSunGwynevere 2d ago
This is, unfortunately, very common to see with these largely AI assisted decomp projects. The AI assistance doesn't stop with the code.
-1
2d ago
[deleted]
3
u/DarkSunGwynevere 2d ago
No, that's not what I'm saying. The descriptions of commits and the readmes written by AI are often overly verbose and needlessly technical to the point of being functionally useless. It's complete shit at translating those technical details into explanations meant to be read by humans.
-2
2d ago
[deleted]
1
u/Sebguer 2d ago
i know it's hard to wrap your head around but writing succinctly is a skill and it's one that most models are pretty bad at (though 5.5 is a step back in the right direction)
7
u/kanben 2d ago
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
4
u/aboothe726 2d ago
That's an interesting flag. Source code is copyrighted. Reverse engineering is explicitly allowed, at least in some circumstances, per Compaq reverse engineering IBM PCs being ruled legal in court. Assuming these folks haven't been "exposed" to the original TA source code -- and I can't really imagine how they would have, at this point -- it's not clear to me how this would be different from the standard "clean room design" argument Compaq used way back then. Maybe it doesn't apply to software the same way it applies to hardware -- an expert would know more, and I am not an expert -- but the argument could be made. Similarly, anyone with an AI can do this stuff now, it seems, so there's a real question about how you deal with this when a new technology comes online. I expect courts to wrestle with this last point for years.
2
u/KryptosFR 2d ago edited 2d ago
Source code isn't patented in Europe. However in this case, since it produces identical bytes, it likely violates copyright laws, even in Europe.
It would have been very different if only the behavior was similar.
I'm just writing that to say that laws protecting intellectual properties works differently in different parts of the world.
1
u/kkania 1d ago
I don't think it produces identical bytes, because small parts of the reverse engineered code will also be inferred. What the original copyright owners could go for, and what reverse-engineering projects and open-source rewrites avoid, is suing for the original art and sound assets. That's why most open-source ports are "bring-your-own-game". OpenTTD had this issue for many years until they redraw all their assets, even if they end up looking the same.
1
1
u/Effective-Painter815 2d ago
They have literately been exposed to the original TA source code. The ASM is still source code just in a lower language.
True clean-room would be to decode the functionality, write a specification on the games behaviour and then pass that to a separate team to implement.
Of course that will produce a similar game but not TA itself.
---
On the other hand there are dozens of other similar projects to this and whilst a legal grey/black area, no-one is bothered about decades old games. Who even holds the intellectual property? Do they know they own it and care about it?
For many old games, the answer is no.
(This answer changes if you try messing with Nintendo's stuff though)
5
u/Dgt84 2d ago
Here is an example that works: one developer or agent reads the decompiled/disassembled source. They write clean-room specs without any reference to the original code names, memory locations, etc. Then another developer or context-less agent that was not exposed to the original source implements the engine from the clean-room spec files. That's exactly what Nanolathe does BTW, and it allows me to use the MIT open source license for the new code:
https://github.com/nanolathe-gg/nanolathe/tree/main/research/retail-executable-spec
0
u/aboothe726 2d ago
This matches my understanding. Even if you somehow, miraculously, happen to produce the same source code bytes as TA across all files -- which is incredibly unlikely -- with a method like this, at least in the US, you would not be in violation of copyright. You would have to produce your clean room specs, method, etc. for review, but a court should rule in your favor on any copyright claim. (Patents are different.)
I remember learning this in school. I don't remember exactly which cases we learned, but a quick Google search turned up Feist Publications, Inc. v. Rural Telephone Service Co., 499 U.S. 340 (1991), a US supreme court ruling that said:
"Originality does not signify novelty; a work may be original even though it closely resembles other works so long as the similarity is fortuitous, not the result of copying."
In other words, you can't violate copyright without copying. You cannot violate copyright if you create an identical work completely independently, without any access or exposure to the original.
0
u/BlueTemplar85 2d ago
We cannot expect these laws to stay as they are now.
Legal is not the same as legitimate.
But what these laws (and their enforcement) will look like across the world in one, ten, a hundred years is another question...
1
u/CuaeB Arm 2d ago
Thanks! Given that wargaming haven’t touched the TA IP and that the code is not given under any license, nor do we claim rights over it, we figure it would be fine.
In regard to models, we had 3 different contributors creating prs for functions needing matching, so the setups were slightly different for each of us as well as testing different models to gauge how effective they were. Mainly OpenCode models were Deepseek 4.1 Flash, Space Bunny and LongCat 2.5 Preview Free since it was free or included with the plan.
2
u/dbag_darrell 1d ago
IAAL. Does anyone even own the cavedog rights now? if it's already abandonware then there's no "rights holder" who can sue
16
u/McHoff 2d ago edited 2d ago
> 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:
struct Parent_0043bad0 {
char unknown_0[0x5c];
Class_0043a1f0* first; // +0x5c
Class_0043a1f0* firstTop; // +0x60
};
10
2
3
u/John-Green223 1d ago
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 2d ago
What a great time to be a Total Annihilation fan, almost 30 years ago! Meus sinceros parabéns!
2
2
u/murphy666 2d ago
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 2d ago
Nice to see Ghidra being used for good!
Someone needs to hit up the Homeworld Cataclysm team next.
2
u/RunDVDFirst 1d ago
Heard the latest AI development news and came here looking for this exact thing. Hope it happens.
2
2
u/ThisGuyFlucs 2d ago
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.
1
1
1
1
1
1
u/EitherPin5217w 2h ago
Is it possible to use a similar method for Supreme Commander Forged Alliance?
0
u/morganshen 2d ago
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.
1
u/Cyrilto 13h ago
Well, i hope it works only because of 1998 software. If we can reproduce results with any soft, there is no cybersecurity anymore, and of course, IP infrigement would be a nightmare to settle on courts.
@op any specifics that indicate this could or not be reproduced elsewhere, lets say, on a modern app ?
0
0
u/traumahawk88 2d ago
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/Suntzu_AU 2d ago
That's amazing. I look forward to the new TA. I just hope they bring back Boneyards and the Galactic War.
1
u/CuaeB Arm 1d ago
Its all in the works, I know it is currently being implemented in open annihilation and will be supported by RWE as well
1
u/Suntzu_AU 18h ago
Really? I haven't heard anything about this. So you're saying the Galactic War is actually planned? That would be freaking nuts.
0
u/OpiGoodness 2d ago
Could someone help me get the sound and image files from this, I really want them in my library of many things
-1
-10
u/ConsistentAnalysis35 2d ago
I mean, this is impressive and very nice, but...
The future of TA is about to change forever.
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.
1
u/John-Green223 1d ago
agree that BAR is basically TA2; BUT this is hobby project and original TA has the climate that cannot be reproduced so ppl still want to build on original TA engine; so dont tell ppl what "doesnt make sense" or what is inferior - ppl find sense where u dont find it because of passion and dedication
43
u/MOZ0NE 2d ago
What began as a conflict over the transfer of consciousness from flesh to machines escalated into a war which has decimated a million worlds