Reverse Engineering a Classic RTS Game with AI: A Layered, Milestone-Driven Approach

    This article explains how to use AI coding tools to reconstruct a classic real-time strategy game whose original source code has been lost. It covers a four-layer architecture (assets, data, simulation, presentation), practical techniques for reverse engineering undocumented binary formats, extracting gameplay values, building deterministic simulation, and handling pathfinding, combat, and lockstep networking. It also outlines a milestone-based delivery plan with automated gates and six hard-won lessons for working with AI coding agents. The core takeaway is a transferable methodology: turn an uncontrollable, oversized goal into a pipeline where formats are verifiable, data is traceable, simulation is replayable, and experience is regression-tested. All reverse engineering must be based on legal authorization and used only for learning and interoperability.

    1. Why Rebuilding a Classic RTS Game Without Source Code Is an Excellent Test Bed

    The original engineering projects of many classic real-time strategy games have long been lost, leaving only the release executables and massive asset packs. These projects are well suited as a capability test bed for AI coding tools for three reasons:

    1. Extremely clear boundaries: win/loss conditions, unit attributes, and build orders are observable and enumerable, so there is no “ambiguous requirements” problem.
    2. Extremely cheap feedback: run it, look at the screen, play a match, check the numbers, and you can tell right from wrong. This naturally forms a closed loop.
    3. Extremely realistic difficulty: it involves binary reverse engineering, proprietary format parsing, real-time simulation, pathfinding, network synchronization, and graphics/audio, covering almost the entire engineering surface of a large client project.

    One thing must be stated upfront: reverse engineering and reimplementation must be based on legal authorization and limited to learning and interoperability purposes. You must not distribute the original assets or copy protected code. Technical feasibility does not equal legal permission. This is the first constraint of the entire project, not an afterthought patch.

    2. Overall Technical Route: Split the Rewrite into Four Verifiable Layers

    The rational approach is not to have the model “write an entire game in one go,” but to first define a layered architecture and then give each layer its own acceptance criteria.

    • Asset layer: read-only parsing of the original asset packs, extracting images, animations, audio, maps, and videos into an intermediate format.
    • Data layer: extract the numeric configuration of units, buildings, weapons, armor, and the tech tree into structured data tables.
    • Simulation layer: fixed-timestep deterministic simulation covering economy, production, combat, pathfinding, and collision.
    • Presentation layer: rendering, UI, input, and audio playback, consuming only the state snapshots produced by the simulation layer.

    The value of layering is this: the presentation layer can be rewritten repeatedly without affecting the logic; the simulation layer can run headless batch regression tests without graphics; and once the asset layer is extracted, it can be cached and reused, avoiding repeated compute consumption.

    3. Phase One (Around Day 1): Proprietary Format Reverse Engineering Is the Real Bottleneck

    The asset formats of these old projects often have no public specification and no mature parsing library. Their characteristics are “field meanings guessed, offsets tried, constants like magic numbers.” The efficient practical path is as follows.

    3.1 Do Format Fingerprinting First, Not Parser Writing

    Use a hex view to compare multiple sample files, find the fixed file header, version number, block identifiers, and alignment patterns, then cross-validate with file size and the entry count declared in the header. The output of this step is a “format hypothesis list,” not code.

    1. offset size guess
    2. 0x00 4 magic
    3. 0x04 4 entry_count
    4. 0x08 4*n index_table (offset,length)
    5. ...

    3.2 Use Differential Analysis to Determine Field Semantics

    Change one unit in the same image, swap one frame in the same animation, then compare the binary differences. This gradually pins down “which bytes are coordinates, which is the frame count, and which is the palette index.” This is the most reliable and compute-efficient method.

    3.3 Checksums Are Often a Hidden Level

    Many formats carry a simple additive or table-based checksum at the end. If you ignore it, the extracted data will “look right but behave wrong.” Be sure to reverse-engineer the checksum algorithm from a known-correct sample first, then write the parser.

    3.4 License Compliance Must Come First, Not Be Argued Afterward

    A recurring real-world conflict is that available reference implementations often use terms incompatible with the project license, which is especially sensitive in static linking scenarios. The safe strategy is:

    • Fix the output license at project initialization and establish a dependency whitelist;
    • Read external implementations only as a behavioral specification; understand the algorithm and the meaning of constants, then implement independently;
    • Keep design notes on “why I implemented it this way,” using documentation to prove the independent creation process;
    • For dependencies that truly cannot be avoided, switch to dynamic isolated process calls rather than linking them into the main program.

    In other words, read the spec, understand the principles, and write it yourself. This is the only path that both moves forward and avoids burying landmines.

    4. Phase Two: “Excavate” the Numbers from the Binary

    Whether the combat feel is faithfully reproduced depends 80% on the data tables rather than the code. The recommended extraction process:

    1. Establish a configuration schema, first defining the required fields for units, weapons, armor, and buildings;
    2. Write batch export scripts to convert binary configuration into a readable intermediate format, with manual sampling and proofreading;
    3. For parameters that cannot be determined statically (such as frame delay and hit priority), infer them from observable behavior;
    4. Put all values under version control, so any change can be traced to “which observation it was based on.”
    1. unit:
    2. id: harvester
    3. hp: 1000
    4. armor: heavy
    5. speed: 4
    6. weapon: none
    7. role: economy

    5. Phase Three: Deterministic Simulation Is the Foundation of Testability

    The core of a real-time strategy game is not rendering but a replayable deterministic state machine.

    • Fixed timestep: logic advances in fixed time slices; render interpolation only affects appearance;
    • Fixed-point or controlled floating-point: avoid cross-platform floating-point differences that cause replay inconsistency;
    • Commands as input: all player operations are serialized into a command stream; replay means replaying commands;
    • Seedable RNG: incorporate the random source into the simulation state to guarantee the same seed produces the same result.
    1. def step(state, commands, dt=FIXED_DT):
    2. for c in commands:
    3. state.apply(c)
    4. state.economy.tick(dt)
    5. state.production.tick(dt)
    6. state.combat.resolve(dt)
    7. state.pathfinder.tick(dt)
    8. return state.snapshot()

    With this layer, regression testing becomes extremely cheap: run ten thousand steps of headless simulation and compare the state hash to determine whether a change introduced a deviation.

    6. Phase Four: The Realistic Hard Parts of Pathfinding, Combat, and Network Synchronization

    • Pathfinding: large numbers of units cannot use per-unit A*. The common industry approach is hierarchical pathfinding plus local avoidance, then caching the results into a shared flow field, significantly reducing per-frame overhead.
    • Combat resolution: hits, armor counters, splash damage, and facing need to be unified into a fixed priority table; otherwise “same configuration, different results” will occur.
    • Multiplayer synchronization: prefer lockstep synchronization, transmitting only commands and not state; you must handle latency compensation, reconnection, and command queue limits to prevent “slow expansion” and deadlocks.
    • Spectating and replays: because the input is a command stream, replay files are extremely small. This is an extra bonus of the deterministic architecture.

    7. Progress Management: Why a Two-Week Plan Must Be Cut into Acceptable Milestones

    Cutting a long-cycle task into Pre-Alpha, Alpha, and Beta phases, each with hard acceptance criteria, is the key to keeping this kind of project from spiraling out of control:

    Phase Goal Acceptance Criteria
    Pre-Alpha Get assets and formats working Maps, animations, and audio can be exported offline and are correct on sampling
    Alpha Close the UI and interaction loop Building, production, selection, and commands all work
    Beta Combat and multiplayer Replay is consistent; lockstep synchronization supports stable matches

    Supporting automation is equally important: every commit runs format-parsing unit tests, headless simulation regression, and a license scan. High-frequency commits (for example, hundreds per day) will only amplify problems without gates, so the “commit-build-test-archive” pipeline must exist before feature development. If you use a cloud container platform and object storage for build caching and artifact archiving, you can split long tasks into parallel jobs, and use logging services and monitoring alerts to locate failure points.

    8. Six Hard-Won Lessons for AI Coding Tool Users

    1. Define contracts before generating: write interfaces, data structures, and acceptance criteria clearly, and generation quality immediately steps up a level.
    2. Commit in small steps and keep it rollback-able: break big goals into small tasks verifiable in half a day.
    3. Let tests read the code for you: humans do not need to review line by line, but must be able to look at metrics and the screen.
    4. Compliance is a design constraint: write licenses, sources, and citations into the documentation to avoid late rework.
    5. Model uncertainty explicitly: annotate guessed fields with confidence levels and verification methods.
    6. Keep human decision points: subjective goals like feel, balance, and experience must be decided by humans.

    9. Conclusion

    The real takeaway from this kind of experiment is not “whether a model can write a game,” but that it validates a transferable methodology: breaking an uncontrollable, oversized goal into an engineering pipeline where formats are verifiable, data is traceable, simulation is replayable, and experience is regression-tested. Whether you are modernizing a legacy system, migrating old data formats, or building an automated build and verification system in a cloud environment such as Baidu AI Cloud, this “layering + milestones + gates” approach applies equally well.