Reverse Engineering · Binary Patching
Wizardry Gold High-Roll Patch
A legacy x86 Windows game binary, read instruction by instruction. Found a developer-only code path the shipped game keeps switched off, turned it back on with a six-byte patch, and fixed a timing bug that has been in the original release since the 1990s.
Problem
In Wizardry 7: Crusaders of the Dark Savant (the “Wizardry Gold” Windows re-release), character creation rolls a pool of bonus points. A Faery Ninja needs a roll around 21 to 23, against a normal range of roughly 5 to 11. Players re-roll for hours to get one.
The obvious approach, editing the value in memory, does nothing. Profession eligibility is computed from the roll at the instant you pick a gender and never re-read afterward. Pinning the value, and even injecting it with a hardware breakpoint, failed for the same reason (the breakpoint version crashed the game). The only fix that works is changing what the generator produces.
Before and after
Approach
The fix came out of four investigations in the disassembly.
-
Where do rolls come from?
The roll generator has a dormant developer branch: when a flag word equals 1 it rolls
random(10)+21, 21 to 30. The shipped game hard-codes that flag to 0. Replacing the guarding jump with NOPs, six bytes, makes it fire every time while the game still rolls with its own code. -
Why is pacing erratic?
About 30 throttles stamp a shared timestamp in 55 ms units (the DOS 18.2 Hz tick) while the main step timer reads it in 128 ms units. One timestamp, two time bases. The fix moves both stamps to the 55 ms idiom inside the original instruction bytes.
-
Why do patches vanish?
Unpacking the UPX-packed launcher showed it runs a different executable per resolution setting. Patches had been landing on an exe the launcher wasn’t running, so now both copies get patched.
-
How do I find code that runs constantly?
A read-only call-stack sampler suspends the game, reads the instruction pointer and stack, and resumes. Sampling showed where the timing code lives without attaching a debugger.
Architecture
Scroll sideways to see the full diagram.
Key decisions
-
Change the generator
over editing the value in memory
Memory edits, value pinning, and a hardware-breakpoint injector all failed, because eligibility is computed once at gender selection. Patching what the generator produces is the only approach where everything downstream (eligibility, stats, saves) behaves normally.
-
Fit inside the original bytes
over adding a code cave
The timer fix fits exactly in the original instruction bytes, with no new code and no changed branch targets. The smallest possible change is the easiest to verify and to undo.
-
Refuse unknown builds
over best-effort patching
Each patch site is located by signature and checked before any write. It runs on other people’s machines, so failing safely beats patching an unfamiliar file.
Results & status
- Four patches released and verified in-game: high rolls, text pacing, screen-wipe delay, and the timer fix.
- Round-trip tested: patch then revert returns the original file byte for byte, checked by automated tests.
- Open source on GitHub under MIT, with a full technical write-up and a plain-English version.
Stack
- x86 disassembly
- Capstone
- Python
- Rust
- eframe
- Tauri v2
- UPX unpacking
FAQ
Is it OK to publish this?
The patchers edit a local copy of a game you already own. They redistribute no game files, make no network calls, and collect no telemetry. It is for personal use with a single-player, offline game, and is not affiliated with the rights holders of Wizardry. Use at your own risk.
Why three front ends?
The Python CLI is for people comfortable in a terminal. The standalone Rust GUI is one click and needs no Python installed. The Tauri app carries the same logic with a web-style interface and its own round-trip tests.