Settings

Theme

Show HN: Civ 1 period accurate decompilation

github.com

11 points by crc32 · 6 comments · 1 min read

Reader

I've used LLMs to decompile Civ 1 and put the reconstructed C source on GitHub, along with a technical book and story.

The reconstructed source builds with what i'm pretty sure is the original Microsoft C compiler and toolchain. It produces a byte-for-byte match with the original executable, aside from a four-byte correction for what appears to be a patch applied after linking. So it should be pretty close to how the original game was made; although it can't be said that this is the "original source code".

I've also used that source to create a modern build of the game, in the `reciv` repository.

Like most people, I'm in two minds about the benefits and downsides of LLMs. This work also builds on OpenCiv1, which probably deserves most of the credit - not only did I direct the LLM to use that work; but it was almost certainly in the training data.

Qualms aside - I couldn't resist having a look inside one of my all-time favourite games. There's a few attempts at Civ 1 including recent LLM ones. But i'm not aware of any that publicise the resulting source code.

2 threads
technovader

very cool! I grabbed your reciv and made a wasm version

source https://github.com/awkto/civ-wasm

play in browser https://awkto.github.io/civ-wasm/ you will need to provide your own game files in a zip

I actually started decompiling civ1 a few weeks ago but gave up. so this was like a surprise and a gift.

tuomas2

Cool! Is this an approach that you could in theory use to other games / programs too? What about license, is this legal?

  • crc32OP

    The approach really boils down to just giving the LLM the clear target of 100% binary compatibility with the same toolchain. It makes it easy for it to check its work and iterate towards it.

    It's probably a couple of months of intermittently using £15pm subscriptions between OpenAI, Anthropic and Google; nowhere near maxing them out.

    MSC 5.1 is a relatively simple compiler; and there's lots of prior art on Civ 1. I've set them off on a slightly more obscure and recent game now; so we'll see how well they manage on that!

    Regarding legality - IANAL so perhaps we'll see. I just wanted to see how the sausage was made.

    • tuomas2

      So essentially the source code is LLM's best guess what the original might look like, as long as it compiles the same binary the goal is met.

      • crc32OP

        Exactly yes.

        Interestingly; the way that MSC51 and LINK 5 lay out the binary depends on identifier names. There's also length restrictions due to memory limitations. So although the names aren't going to be historically accurate; the possibilities are at least bounded!

    • muzani

      I love the curiosity despite the possible legal consequences. It's in the spirit of Hacker News.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection