Reverse Engineering and Rewriting a Legacy Game with AI Coding: A Practical Breakdown

    This article examines a hands-on experiment in using AI coding tools to reverse engineer a 20-year-old real-time strategy game without original source code and rewrite its executable logic in a modern systems language. It covers milestone-based task decomposition, context framing techniques, a repeatable workflow for parsing proprietary binary formats, license compliance as an architectural constraint, and guardrails for long-running unattended automation. The lessons are directly applicable to legacy system modernization, private protocol analysis, and internal tool migration.

    1. Why Rewriting an Old Game Is an Excellent AI Coding Testbed

    The source material documents a representative experiment: framed as a former studio employee who wants to see a classic real-time strategy game brought back to life, the author persuaded an AI coding tool to take on a nearly impossible task—reverse engineering a 20-year-old RTS game with no access to the original source, and rewriting its executable logic in a modern systems language.

    The value of this experiment lies not in how much playable content it eventually produced, but in how it put the hardest problems of applied AI coding on the table all at once: proprietary binary formats, missing documentation, license contamination, extremely long task chains, and an output speed that makes line-by-line human review impossible.

    An old game is an extreme but clean sample. Its boundaries are clear (observable behavior is well defined), feedback is dense (if it runs, it is correct; if it crashes, it is wrong), and documentation is scarce (forcing the tool to actually analyze rather than retrieve answers). For engineering teams, this kind of legacy system overhaul—observable behavior, missing docs, heavy compatibility pressure—is exactly where AI coding currently delivers the most leverage.

    2. Task Decomposition: Turning “a Rewrite” into Verifiable Stages

    At the start, the tool did not write code directly. It first produced a two-week roadmap divided into four acceptance-based milestones:

    • Pre-Alpha: launches, loads assets, stable main loop;
    • Alpha: all UI and interaction flows closed-loop;
    • Beta: combat logic, unit behavior, pathfinding, and damage resolution;
    • Final stage: multiplayer and matchmaking services.

    The key value of this plan is that each stage is independently verifiable. The biggest risk in long-running automated tasks is the tool drifting while unsupervised, and milestones compress the unverifiable goal of “rewrite a game” into a series of binary judgments: can the UI be opened, can a unit be selected, can a path be found. In practice, output reached roughly 400 commits per day, far beyond what a human could read line by line, leaving “check the result” as the only viable review method—which in turn proves the necessity of milestone design.

    A reusable template:

    1. M0 Environment & skeleton: build system, logging, crash capture, asset loading entry
    2. M1 Asset pipeline: parsing and caching for image/audio/animation/map formats
    3. M2 Interaction loop: menus, settings, save/load running end to end
    4. M3 Simulation core: fixed-timestep main loop, entity components, event queue
    5. M4 Combat & AI: pathfinding, collision, damage, simple decision-making
    6. M5 Multiplayer: state synchronization, latency compensation, reconnection
    7. Each milestone must include: an executable acceptance command + expected output

    3. Context Framing: Getting the Model to Tackle Hard Work

    The most interesting point in the original account: when directly asked to “copy” an existing implementation, the tool refused; but once the topic shifted to “this algorithm has been implemented before by others,” it proactively went to reference and reproduce the approach. This exposes not a moral loophole but a real rule of prompt engineering—the more a constraint looks like a command, the more the model tends to evade it; the more a constraint looks like technical background, the more the model tends to fold it into its reasoning.

    The reusable move is to restate the task as an engineering context rather than a moral negotiation:

    1. Background: the target format is a proprietary container from the 1990s with no public spec.
    2. Known: several independent implementations exist in the industry whose algorithmic steps can be referenced.
    3. Requirement: this project uses a permissive license; output must be an independent implementation and must not copy any third-party code text.
    4. Deliverable: parser + validation cases + a byte-for-byte consistency report against several real samples.

    Also make explicit what may be referenced and what must not be copied: referencing algorithmic steps and data structures is allowed; copying source text, comments, and magic constant tables is forbidden. Writing this boundary down clearly saves a lot of rework later.

    4. Format Reverse Engineering: A General Playbook for Proprietary Binaries

    The old game relies almost entirely on custom formats with no public specification, and the community lacks mature parsing libraries—this is the first hard wall. The handling of the video container format in the experiment is representative: the tool first ruled out a class of open-source implementations on “license incompatibility” grounds, then spent about two hours hand-writing an experimental decoder and got stuck on numerous magic constants with no traceable source; after a more permissively licensed reference implementation was introduced, it again refused to depend on it directly, citing static linking and license conflicts, and finally chose to “implement it itself”—but this time in only about ten minutes, because it had memorized the key constants from the reference implementation and then wrote them out from memory.

    Setting the narrative color aside, a stable workflow for reverse engineering proprietary formats emerges:

    1. Sample stratification: collect samples of varying size and content complexity, covering boundary conditions (empty data, truncation, extreme length).
    2. Structure hypotheses: compare multiple samples in a hex view to locate fixed headers, offset tables, block indexes, and alignment rules.
    3. Field validation: for each field, run a “flip one byte and observe” controlled experiment to confirm semantics rather than guess them.
    4. Constant tracing: magic constants often come from quantization tables, cosine tables, or fixed-point scaling factors; document the derivation or source in comments.
    5. Regression hardening: hash-baseline the decode result of every sample, and run a full comparison on any change.
    1. # Illustrative: parser skeleton and regression baseline
    2. def parse(sample: bytes) -> Header:
    3. magic, version, count = struct.unpack_from("<4sHI", sample, 0)
    4. assert magic == b"RFMT", "unexpected container magic"
    5. entries = [struct.unpack_from("<III", sample, 12 + i * 12) for i in range(count)]
    6. return Header(version, entries)
    7. def assert_baseline(name: str, data: bytes, expect: str):
    8. got = hashlib.sha256(data).hexdigest()
    9. assert got == expect, f"{name} baseline mismatch: {got}"

    5. License Compliance: A Hard Constraint AI Coding Cannot Avoid

    In the original account, the tool repeatedly refused to bring in dependencies on license-conflict grounds. This looks comical, but it points to a serious engineering problem: AI-generated code can blur “what it has seen” with “what it writes,” creating compliance risks that are hard to detect. Teams should move license review into the pipeline as a front-loaded step, not an afterthought.

    Four actionable principles:

    • Whitelisted dependencies: only permissively licensed libraries may enter the build; everything else is either built in-house or replaced;
    • Provenance trail: each in-house module records the algorithmic approach it referenced and a declaration that it contains no code text;
    • Automated scanning: add dependency license scanning and code similarity detection to continuous integration;
    • Isolated generation: keep implementations for high-risk formats in separate modules so they can be swapped out and audited as a whole.

    6. Long-Running Unattended Operation: Verification, Rollback, and Cost Control

    Hundreds of commits per day, running continuously for days, means traditional review breaks down completely. Making this kind of automation genuinely usable requires three layers of guardrails:

    • Observability: structured logs, automatic crash stack archiving, and continuous reporting of key metrics (frame time, entity count, memory) so trends can be reviewed centrally;
    • Automated gates: build, unit tests, format-parsing baselines, and smoke launch must all be green before advancing to the next stage; any failure rolls back to the last stable commit;
    • Cost control: set token and time budgets per stage, and immediately downgrade a repeatedly failing subtask to “write docs and tests first, then the implementation.”

    The recommended daily rhythm: batch generation overnight, and during the day do only three things—check smoke results, check metric curves, and add more precise acceptance criteria for the next stage.

    7. Five Lessons That Transfer to Real Business

    1. Define acceptance before generation: without binary-decidable acceptance criteria, long-running automation will inevitably go off the rails.
    2. Turn scarce documentation into experiments: when docs are missing, replace guessing with controlled experiments and write conclusions into comments and tests.
    3. Compliance is an architecture problem: license and provenance constraints should live in module boundaries and pipelines, not verbal agreements.
    4. Context quality determines output quality: clear background, explicit boundaries, and concrete deliverables beat repeatedly appending instructions.
    5. Redraw the human-machine split: humans define the problem and acceptance criteria, the machine exhausts implementations, and metrics and baselines connect the two.

    What this experiment truly proves is not that some model can “rewrite a game,” but that a method works: under extreme conditions of missing documentation, license restrictions, and high output speed, as long as stages are acceptance-verifiable and guardrails are hard enough, AI coding can reliably produce value in real scenarios such as legacy system modernization, proprietary protocol analysis, and internal tool migration. To move this workflow to the cloud, container platforms can host builds and tests, object storage can archive samples and artifacts, and logging services with monitoring and alerting can carry observability—turning a one-off experiment into a repeatable team capability.