Open reimplementation · in progress

Lords of the Realm II

An incremental open engine for the 1996 Sierra/Impressions strategy game, built the way OpenXcom was: new code, original data files. The shipped Lords2.exe is kept as an oracle — ground truth to verify each reimplemented system against, not a thing to patch.

Updated 12 Oct 2026 Repo E:\dev\lords2 Game GOG build, 21 Jul 2009 Battle runs and draws itself Oracle Ghidra 12.1.3 · 1,464 functions named

Progress

Test suite
3,345
identical counts in debug and release, with and without the install
Binary decompiled
2,452
every function, greppable · rebuilt in 22 seconds
Functions named
1,464
60% of 2,452 · the rest is mostly CRT and DirectDraw glue
Asset formats
5 / 7
PL8 (291/291), palettes, maps, .skr battles, .eng text

Working set

In progress
  • ●Nothing. Every agent has reported; the tree is clean
Next — and it is all one thing
  • ○l2-game — the application spine nothing is plugged into yet
  • ○Menus, screens, input — none of which exist at all
  • ○A campaign map you can click, and an end-turn button
  • ○Missiles: the rules resolve a hit, nothing fires one
Recently closed
  • ✓The AI drives the battle — units, formations, 200-frame thinking
  • ✓Simulation state moved out of the renderer into l2-sim
  • ✓The shipped save reads — and the scenario was wrong in our tests
  • ✓Every kingdom rule is now something a mod can change

Established facts

Image base · ASLR
0x00400000 · disabled
Addresses are therefore
stable across every run
Code section
.text 0x401000–0x4CFB06
Game state (uninitialised globals)
~955 KB in .data
DirectPlayCreate call site
0x004B826E
DirectPlayEnumerateA call site
0x004B7FCE
Pathfinding charges terrain
by weight and deferral — never relaxed
The whole battle AI turns on
one global: strength advantage ± jitter
Blocked cells are two values
998 friendly figure · 999 impassable
Kingdom rules live in
the .exe, not data — 0x4D6300, 0x4D8900
Palette format
768 B, 256×RGB, 6-bit VGA
The game logs its own startup
status.txt, next to the exe
PL8 frame renderer
0x0040A21A(buf, frame, x, y)
Blitters are clip variants, not modes
none 0x004B43B1 · left 0x004B446D · right 0x004B44D2
Generic file reader
0x004AF8D9(name, buf, len, off)
Transparent colour
palette index 0, in every blitter
Clip state set by
0x0040464C(left, right)
Family 2 is isometric map tiles
diamond rows 2, 6, 10 … total h²
Encoding is per frame, not per file
record byte 0x0C: 0 rect, 1–4 diamond
Header byte 1
map zoom — 58×30 / 26×14 / 10×6
Framebuffer stride
640 (0x280 − width)
Map slot stride
32,961 B = 6×(64×64) + 65×129
Map slots
80 total · 44 used, 36 empty
Map plane 5 / plane 0
county id / flag bitfield
Injection verified from inside
image base 00400000, DirectDrawCreate S_OK
Driving the game by UI
blocked — needs focus, screen reads black
The header family byte
vestigial — the engine never reads it
Isometric lattice mapping
row = x+y+1, col = (x−y+64)>>1
Map tile banks
resource table at 0x004DA050
Map plane 3
dx + W·dy within a tile block
Map loader
0x00467770 · lattice 0x0046797D

Roadmap

00

Foundations

Done

Know the target, and be able to watch it run.

  • ✓Locate install; confirm no ASLR, unpacked, fixed base
  • ✓PE tooling — imports, exports, headers, call-site xrefs
  • ✓MSVC x86 toolchain, verified building 32-bit DLLs
  • ✓Observability — live memory reads, window capture, synthetic input
  • ✓Git repository; game assets excluded from version control
01

Asset formats

In progress

The gate for everything downstream. Each format is validated across the whole corpus, not one lucky sample — PL8 self-verifies because every frame must end exactly on the next frame's declared offset.

  • ✓PL8 header, frame table, RLE and raw storage — 291/291
  • ✓.256 palettes — 6-bit VGA, scaled to 8-bit
  • ✓PL8 isometric family — all five per-frame shapes — 2502/2502 frames
  • ✓Hit-test region maps recognised structurally, not by filename
  • ✓Every PL8 file decodes — 291/291, 21,344 frames
  • ✓“Raw sub-mode 2” dissolved — the per-frame shape byte decides, not the header
  • ○Which palette pairs with which sprite set
  • ✓L2_maps.dat container — 80 slots of 32,961 bytes, 44 used
  • ●Map tile→lattice mapping — best fit only 72%
  • ✓.eng text — three unrelated formats sharing an extension
  • ✓.skr battle scenarios — arithmetic closes exactly
  • ○CASTLES.DAT and .SAF
02

Rust foundation

In progress

Where the project proper starts. Everything so far is Node prototyping, kept deliberately disposable until the formats were known.

  • ✓rustup 1.98.1 + MSVC toolchain
  • ✓l2-formats crate — PL8 and palette decoders ported
  • ✓Corpus validation is the crate’s test suite — 291 files, 27 palettes
  • ✓A workspace of six crates, each testable on a bare checkout
  • ✓3,345 tests, and the same count in release — a debug-only pass is a desync waiting to happen
  • ○Asset extraction CLI — sprites to PNG, in bulk
03

Renderer and container

In progress

A palettised framebuffer mirrors how a 1996 software renderer thinks, so porting drawing code stays close to mechanical.

  • ✓winit 0.30 window + pixels 0.17 framebuffer
  • ✓Indexed 640×480 canvas expanded through the palette
  • ✓Compositing that honours index-0 transparency
  • ✓l2-view — renders real game screens in our own window
  • ✓Campaign maps render — slot 0 is a recognisable England
  • ○Scaling, and a proper asset browser
04

Battle sandbox

In progress

The first milestone that is genuinely a piece of the finished engine rather than scaffolding — and where the pathing work lives. A battle now runs and draws itself: real .skr terrain, auto-tiled river banks, a bridge, and both liveries of men walking, fighting and falling, stepping the simulation tick by tick.

  • ✓Unit and figure data structures — 80-figure ceiling, stable indices
  • ✓Movement, elevation rules, cell swapping
  • ✓Pathfinding — weighted and deferred, deliberately not Dijkstra
  • ✓Melee and missile resolution — every ranking the manual states, asserted
  • ✓Melee table checked against the binary — 11/11 rows exact
  • ✓Battlefield terrain, auto-tiling, sprites, facings, animation
  • ✓All 20 shipped battlefields build — 128,000 cells, every index valid
  • ✓Units, formations, and the AI driving them — all 17 handlers reachable
  • ✓Sieges — the wall, the gate, the way in, and the 14 siege orders — the castle’s layout is ours and says so
  • ✓Missiles fly — a shot traverses, and hits whoever is in the cell it enters
  • ✓“Will you take the field?” — screens 0x12 and 0x13; the turn suspends until the player answers
05

Oracle and differential testing

Started early

Turns the original binary into a test fixture — and the big lesson of this phase is that the binary is the fixture, not the running game. Reading the executable answers nearly everything, instantly and with no window to steal focus. Launching the original turned out to be the last resort, not the second.

  • ✓Ghidra 12.1.3 + headless analysis pipeline
  • ✓Whole binary decompiled and greppable — 2,452 functions in 22 seconds
  • ✓Symbol database shared between Ghidra and the docs — 1,464 functions, 596 globals
  • ✓Battle tables read from the executable — disk and live memory identical
  • ✓Runtime constants recovered from the MOV immediates that write them
  • ✓Kingdom economy tables checked — every value right, two layouts wrong
  • ✓ddraw.dll proxy and hard-link sandbox — install untouched
  • ○Pixel diff against the original's framebuffer — never yet attempted
06

Kingdom layer

In progress

The turn-based half: the larger and less charted body of rules, and the one place the printed manual has been caught wrong twice. Every economic constant lives in the executable rather than a data file, which is much of the reason to build an open engine at all.

  • ✓Counties, population, happiness, taxation
  • ✓Seasons, weather, crops, livestock, food stores
  • ✓Weapons manufacture, wages, industry
  • ✓The seven-phase turn machine — a 23-entry pipeline the driver walks
  • ✓Shipped save reproduced end to end — five stages, nothing adjusted
  • ○Stubs left honest: AI handlers, bankruptcy stages, the event table
  • ✓Sieges on the campaign map — engines, seasons, the assault gate; five real snapshots reproduced
  • ○The castle designer — which is not in this executable
07

Netcode

In progress

The original's networking is abandoned rather than studied — it is replaced outright, not reimplemented. What matters is determinism, which is a property of the simulation and was designed in from its first line.

  • ✓Deterministic primitives — frozen PRNG, Q16.16 fixed point, one canonical encoding
  • ✓Lockstep session — command ordering, checksums, desync dumps, replay
  • ✓TCP transport, non-blocking, no threads and no clock
  • ✓The battle simulation run over a real socket — two peers, identical every tick
  • ○Lobby, host and join
  • ○Beyond loopback — real loss, NAT, MTU, head-of-line blocking
08

Modding platform

Started

The actual destination. Designed in from the first crate rather than retrofitted: rules live in data files, and assets load through an overlay filesystem. Assets shadow; rules accumulate — the asymmetry is deliberate.

  • ✓Virtual filesystem with mod-directory overlay — proven with synthetic art
  • ●Data-driven rulesets replacing hardcoded constants
  • ○Mod packaging, load order, conflict reporting
  • ○Format and ruleset documentation for mod authors

Tooling built so far

ToolDoesVerified by
ddraw-proxyInjects our code into the original gameVerified: attach, forward, S_OK
l2-formatsRust crate — PL8, palettes, maps, .skr291/291 files; 180,224/180,224 tile invariant
l2-simBattle rules — figures, melee, missiles, movement, pathingEvery ranking the manual states, asserted
l2-kingdomThe turn-based economy — 7 phases, 30-pass pipeline895 tests; the shipped save reproduced
l2-netLockstep, canonical encoding, TCP transportTwo peers bit-identical over a real socket
l2-modsOverlay filesystem — assets shadow, rules accumulateOverride proven with synthetic art
l2-viewViewer — sprite sheets and campaign mapsSlot 0 renders as England and Wales
ghidra_scripts/Headless binary analysis — find loaders, decompile to CFound the renderer at 0x0040A21A
symbols.jsonOne symbol database, applied to Ghidra and rendered to docs1,464 functions, 596 globals, 0 failures
xref.jsFinds call sites of imported functionsLocated both DirectPlay calls
peimp / peexp / pehdr / pefunPE imports, exports, headers, per-DLL functionsResolved imports-by-ordinal
probe.ps1Reads memory from a live processRead the game at 0x400000
screen.ps1Window capture via PrintWindowOcclusion-proof
input.ps1Synthetic mouse and keyboardDrove a real GUI
windows.ps1Enumerates a process's top-level windowsFound hidden dialogs
How this page stays current. It is rewritten whenever a phase changes state, a verified count moves, a defect is found or closed, or a roadmap item is added or dropped — not on a clock. The roadmap below phase 2 is an assumption and will be wrong in places; that is expected, and revisions get made here rather than argued for. Windowed mode is not on it: the original only needs to be observable, and our own renderer brings its own window.