/gameframe:re-emulatefrom gameframe
Runs individual functions from Windows x64, x86, or DOS/NE binaries under the Unicorn emulator to capture exact ground truth for reimplementations. Use for random number generators, math, procedural generation, simulation, pathfinding, or parsers where bit-for-bit accuracy is required.
Ships in gameframe. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Reading code tells you the shape of a computation; only running it tells you the exact result. In a simulation, one bit of difference in a float or one random draw out of order grows until the reimplementation's world no longer matches. The emulator runs a single original function, many times, with inputs you choose, without starting the game.
import sys; sys.path.insert(0, 'tools/emu')
from pe_emu import Emu, F32
emu = Emu('game/Game.exe', ['game/Engine.dll']) # loads, relocates, links imports by name
CRT_STUBS: malloc, free, memset, memcpy, strlen, critical sections...).
An import with no stand-in stops the run with its name: add one (stubs={'Name': handler}).emu.call(addr, *args) uses the Windows x64 convention: integers and pointers in rcx, rdx,
r8, r9, floats wrapped in F32(...) or F64(...) in xmm0-3, the rest on the stack. It returns
rax; call_f32 returns xmm0, call_i32 a signed int.malloc(size) (zeroed), write(addr, bytes), read(addr, n), u8/u32/i32/u64,
f32s(addr, n), cstr(addr), bytes_in(data) (copy bytes in, get the address).export(module, name), or va(module, 0x1400be770) for a Ghidra address (it
follows a relocated module).hook_function(addr, name, handler) replaces any function, original or imported, with Python:
use it for callees that touch files, threads, the GPU, or that you want to observe.re-trace): know the function's arguments, the layout of the objects it
reads (offsets and types), the globals it needs (a singleton pointer at DAT_...), and its
callees that must be stubbed.malloc each object, struct.pack the fields at
their offsets, link pointers. Point globals at your objects with write(va(...), pack('<Q', ptr)).
Build the smallest object graph that works; the emulator reports every invalid access with
the address and the code position, which tells you the next field to fill.tools/emu/<topic>.py in the project, modelled on
examples/sample-game/ground_truth.py): a docstring with usage and outputs; a fresh Emu
per independent case; many inputs (every cell of a small map, seeds 1 to 50, edge cases such
as zero, negatives and borders); raw little-endian outputs into derived/emu/<topic>/
(ignored by git, because ground truth is derived from the game).from call_trace import CallTrace
trace = CallTrace(emu, {emu.va('engine.dll', 0x180012340): 'Rand',
emu.va('engine.dll', 0x180012380): 'RandFloat'}, args=1)
emu.call(target, ...)
trace.write('derived/emu/ai/seed-1.trace') # "Rand(10)<TAB>game.exe+0x9be55" per draw
Only outermost calls are logged, so a float draw that calls the integer draw counts once.re-verify (bitcompare.py, seqdiff.py).
Not exact? Emulate intermediate functions separately and compare stage by stage, until the
first stage that differs is small enough to read instruction by instruction.IsDerivedFrom, dynamic_cast) fails on a synthetic object. Hook the check to answer
yes when the object is the type the code expects.__declspec(thread)
variables also needs the TLS slot array (TEB+0x58) pointing at a block for the module.timeout_insns and emulate them whole rather
than porting blind; dump intermediate state with hooks to compare in stages.tools/emu/pe32_emu.py: Emu32('GAME.EXE'), then
call(addr, args=[...]) for cdecl and stdcall, or call(addr, esi=..., edi=...) for
hand-written routines that take registers. MMX and x87 work. Every import stops the run with
its name until you give it a handler (stubs=). It has no TEB at FS and does not set this
in ecx for you: pass ecx= for thiscall. docs/ABI.md lists the conventions, and
docs/hardware/simd.md shows it on MMX code. call(..., fpu_cw=0x037f) loads an x87
control word first (NEAREST 0x037f, CHOP 0x0f7f), and emu.fpu_modes(addr, cases) lists
the cases whose result depends on the rounding mode. call(..., until=ADDR) stops at an
address, such as a call to sprintf that needs the C runtime, and returns stack, the
call's arguments (docs/knowhow/x87-magic-add-rounding.md). Linux ELF and macOS Mach-O
binaries need a different loader; the calling convention is System V (rdi, rsi, rdx, rcx, r8,
r9; floats in xmm0-7).import sys; sys.path.insert(0, 'tools/emu')
from dos_emu import DosEmu, Long, FarPtr
emu = DosEmu('game/GAME.EXE') # NE: 16-bit protected mode; MZ: real mode
emu.call('1000:873a', 5, Long(100000)) # Ghidra's address or an export name; AX
emu.call_long('RANDOM_LONG', 1000) # DX:AX as one 32-bit value
p = emu.bytes_in(open('game/LEVEL.DAT', 'rb').read(512)); emu.call('LOADLEVEL', p, 512)
emu.u16(FarPtr(0x1048, 0x12de)) # read a global afterwards
emu.trace({'1040:0a12': 'Random'}, args=1); emu.write_trace('derived/rng.trace')
1000 + 8 * (N - 1), MZ loads at 1000.
The emulator uses the same numbers, so pseudocode addresses work unchanged.Long(v) two words, FarPtr/(seg, off) a far pointer. conv='cdecl' for C code.var parameter is a far pointer pushed segment first: pass the variable's
address, as in emu.call('1008:2026', 1, 0x1048, 0xa2f4, 0x1048, 0xa2ee) for
P(n: Byte; var A, B). When the real callers always pass the same globals, port it
with a choice between them (player 1 or 2), not a pointer.[bp + 4], the
static link) cannot be called alone: call the parent with states that reach it.regs={'ds': ...}.stubs={'KERNEL.3': fn} (handler returns the bytes to pop) or interrupts={0x21: fn}.screen = emu.new_segment(), put its selector in the global the code loads into
ES (VgaScreenSeg), fill the screen with a sentinel byte (0xEE) so skipped transparent
pixels show, set the globals, call, and compare all 64 KB with the port's output. Load the
data blocks it reads (megadata, sprite banks) the same way, built by the port's own loader,
so one test checks the loader's layout and the renderer together.emu.run_range('1000:cab1', '1000:ccac') runs from one address until execution reaches the
other. Pick a fragment that leaves the stack balanced and uses globals, not the enclosing
procedure's locals (or set bp in regs). Near procedures end in ret: stop at its address.
run_range starts on the start-up stack; to carry on a program that is running (the next
frame), use emu.run_to(address), which keeps every register.tools/emu/dos_env/ adds DOS files, the BIOS, a DPMI
host, timer interrupts and a key queue, so a DOS game starts and runs in dos_emu, frame by
frame, with its memory open to you (docs/DOS.md section 5b). When it stops on something
missing, add that to dos_env with a test, not a workaround in the game project.
To save the state before and after chosen fragments of the main loop, frame after frame,
use tools/emu/fragments.py (re-verify, "Capturing fragments of a main loop").scripts/dosbox-run.sh) and read memory with the debugger (tools/dos/dbx_control.py):
docs/DOS.md sections 6 and 7.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub tanepiper/game-frame --plugin gameframe16 skills in this plugin
/re-browseBuild and grow a resource viewer for a game - first the catalogue (tools/formats/catalog.py, a static HTML page and JSON manifest of every file, its kind, entropy, hex and what the Python decoders make of it, with pictures), then the project's own viewer app on the port's readers (pictures, palettes, sound, 3D models, text, hex; native and browser; a file output mode for agents). Use at the start of a project, right after the inventory, and after every new decoder, so the person and the agent can check decoded content by looking at it./re-cleanroomRun a source-visible specification and source-blind implementation workflow when a project wants independent reimplementation from a neutral behavior contract./re-formatOther plugins' skills for the same job