Skip to content

Decompiling Hitman: Blood Money

The matching build compiles IOI’s game code and compares its instructions and referenced data with the PAL executable. Run make progress for the current totals. The remaining game fallback is ProgressHandler.

The loop

  1. Locate a symbol or address with python3 tools/find_function.py NAME. Pass the resulting ID to tools/lines.py for assembly annotated with the original source lines. Use tools/debug_context.py for typed locals and scopes.
  2. Check the owning unit and its headers. Recover the original names, field types and layout before writing the body. The pinned C++ compiler is ee-gcc 3.2 040921. Use --compiler ee-gcc3.2-030926 for a comparison. The matching tools preload the Windows-compatible qsort so tied operands sort in the original order.
  3. Compare a candidate with python3 tools/diff_function.py ID. For a guarded draft add --non-matching. Use python3 tools/check_unit.py ID to check the other functions and any data chunks placed by this unit.
  4. Verify symbol binding with readelf -sW extracted/HITMAN3.ELF. A reference can resolve by name even when its definition has the wrong linkage. Run python3 tools/elf_only_data.py after the full build to identify data still supplied by the reference.
  5. Format with make format. Run make match, make match-scripts and make test. Set OPENBLOOD_STRICT_DATA=1 for referenced data checks. After changing matching sources, run make digests and include the resulting digests. The host zactor test needs definitions in tools/tests/zactor_behavior.cpp for any newly referenced static members.

Reading the diff

Register differences score 1, immediates 2 and changed, added or missing instructions 5. Look at the first differing use of a value, its live range and the source line before altering expression order. The score weights are in tools/diff_function.py.

Generated functions

GCC emits startup and teardown functions from global definitions in source order. Constructor and destructor variants, thunks and local statics follow from the class declarations and lifetimes. See Generated functions.

The first externally visible definition determines the name of a unit’s _GLOBAL__I_ initializer. For a missing vtable, check the unit defining the class’s first eligible out-of-line virtual method. For ZSerializable this is LoadObject in serializerlib/serializable.cpp.

STL template instantiations

Use the mangled symbol and c++filt to identify the template and its arguments. IOI’s containers and algorithm definitions live in src/common/zstl/. The bundled STLport headers live under src/libraries/STLport-4.6.1/stlport/. Check the source object’s provenance before assigning ownership. Two immediate differences in the upper and lower halves of a call target can indicate a different template instantiation. Compare demangled parameter types, including their signedness.

Source shapes that change codegen

Each of these was found by measurement, not intuition. They are the kind of detail that decides a match.

Recurring shape families

The same body turns up across units with only the member names changed. Recover one, then look for its siblings — this is the cheapest way to finish a batch of small units. Found so far:

  • Three-axis bounds test. ZAbs(p[i]) <= m_Axis[i] - fDotDist for i = 0,1,2, written with a named bool bResult that is returned, not as a && chain. Appears in ZFriskBox, ZDummy (m_vDimensions), ZBoxPrimitive and ZPathfinderDoorMarker (m_vScale), and ZDummyCylinder (radius for x and z, height for y, the radius value reused across the two comparisons). ZDummyArrow is the same test against a 10.0f literal triple rather than a member. All six matched on the first attempt once the shape was known.
  • Base-class forwarding. In a void function, an explicit return; after the base call can keep the call as jal. Class-type temporaries and destructed locals can also prevent a tail call.

Cache a member in a local reference to pin register allocation. The TStructEvent destructor rematerialised the global's address after the delete loop until the container was bound to a local reference:

~TStructEvent() {
    ContainerT<IStructEventCall *, AllocT<IStructEventCall *> > &calls = m_EventCalls;
    IStructEventCall **end = calls.end();
    for (IStructEventCall **i = calls.begin(); i != end; ++i)
        delete *i;
    calls.clear();
}

Without the calls local, the address is reloaded after the loop and the register allocation diverges. With it, the 172-byte initializer matched.

Declare a loop counter before the loop, not in the for init. for (char i = 0; ...) makes GCC 3.2 swap $s0/$s1; declaring char i; first fixed ZHM3BriefingControl::~ZHM3BriefingControl (9 registers).

return x; versus break in a bounded search changes allocno priority and can move two pseudos between $s7 and $fp, changing the frame size.

*pList++ matches where pList[i++] does not — the latter keeps a live base pointer and costs a callee-saved register.

Separate early returns are not one combined condition. Write them separately.

Loops exit on !=.

IOI's float abs is ZAbs() from engine/system/abs.h, with an early-clobber constraint ("=&f") so the output gets a fresh register. The same header family provides ZSqrt, ZCountLeadingSignBits.

A header inline is inlined only at its first use in a unit; later uses call the out-of-line copy. So a function's shape can depend on whether an earlier function in the same unit is already C++.

Compiled-out debug code. A debug-message buffer can account for an otherwise unused 128-byte stack area. For the evidence required for other dead locals and assertions, see the readability standard.

Compiler flags

The defaults are -Os -G0 -fno-exceptions -fno-rtti -fno-elide-constructors -funsafe-math-optimizations. Return objects naturally and use ordinary comparisons for clamps. The toolchain configuration records the five function-specific exceptions and the two units built with -fno-gcse. The TIMETYPE case study explains how to reproduce the reload without an extra compiler flag.