Files
kdm-re/docs/re/gamemain-binding.md
ulw-execute 3910630c25 docs: mark release-difference facts verified; fix doc inconsistencies
Owner confirmed the differing sizes/export counts/RVAs are just a different
release of the same official game. Remove the "pending re-check against
clean-release binary" / "contaminated install" caveats throughout and state
those numbers (module sizes, export counts, gameMain RVA 0x9e20) as verified
facts. Drop the stale 3,369,104-byte gamekdm figure in favor of the
consistent 3.19 MB. Genuine format/behavior UNVERIFIED markers (undecoded
.arc/.ifs/.ttc/etc. formats, Kinect dispatch/sync) are preserved.
2026-11-28 21:01:37 -05:00

5.0 KiB

gamekdm.dll gameMain binding and hInstance provenance

Scope: the official binding path from the AVS2 runtime's entry into arkkdm.dll to the call of gamekdm.dll's exported gameMain. The evidence described here comes from the official game modules' PE metadata, strings, and disassembly.

Binary facts

The verified binary facts are:

  • arkkdm.dll exports dll_entry_init by name at ordinal 253, RVA 0x767c0.
  • arkkdm.dll exports dll_entry_main by name at ordinal 254, RVA 0x767b0.
  • gamekdm.dll exports gameMain at RVA 0x9e20 / VA 0x10009e20.
  • gameMain is cdecl and takes one void * argument.

(a) Hop 1: AVS2 runtime to arkkdm.dll

The AVS2 runtime enters arkkdm.dll through its standard AVS2 entry exports:

arkkdm.dll!dll_entry_init  ordinal 253  RVA 0x767c0
arkkdm.dll!dll_entry_main  ordinal 254  RVA 0x767b0

Both symbols are present in arkkdm.dll's PE name-pointer table, so they are by-name exports rather than ordinal-only exports. The ordinals identify their export-table entries; they do not imply an ordinal-only call.

After initialization, the AVS2 runtime calls arkkdm.dll!dll_entry_main. Everything from that point through the invocation of gameMain is implemented inside arkkdm.dll.

(b) Hop 2: arkkdm.dll to gameMain

arkkdm.dll contains a two-candidate payload resolver. Its production candidate is gamekdm.dll; its test-build fallback is arkkdmtest.dll. Conceptually, the official code performs:

HMODULE candidate = LoadLibraryA("gamekdm.dll");
if (candidate == NULL) {
    candidate = LoadLibraryA("arkkdmtest.dll");
}

if (candidate != NULL) {
    gameMain = GetProcAddress(candidate, "gameMain");
    if (gameMain != NULL) {
        gameMain(g_MainDllInfo.dllHMODULE);
    }
}

The actual implementation loops over the two literal module names. For each candidate it calls LoadLibraryA; after a successful load it passes the literal string "gameMain" to GetProcAddress. It invokes only a successfully resolved pointer.

This is standard Win32 dynamic linking with a production/test-build fallback. There is no custom export protocol between arkkdm.dll and the payload DLL.

(c) hInstance is arkkdm.dll's own module handle

The single argument passed to gameMain is not the handle returned while loading gamekdm.dll. It is arkkdm.dll's own HINSTANCE / HMODULE.

The value's provenance is:

  1. The Windows loader calls arkkdm.dll's DllMain.
  2. On DLL_PROCESS_ATTACH, DllMain captures its hinstDLL argument.
  3. dll_entry_init relays that captured value into the internal g_MainDllInfo.dllHMODULE field.
  4. The dll_entry_main path gives the g_MainDllInfo structure to the internal payload resolver.
  5. The resolver reads field zero, pushes that one value, and indirectly calls the resolved gameMain pointer.
arkkdm.dll DllMain hinstDLL
  -> captured module-instance global
  -> g_MainDllInfo.dllHMODULE
  -> dll_entry_main payload resolver
  -> gameMain(hInstance)

The adjacent diagnostic strings identify the structure as MainDllInfo and its first field as dllHMODULE. The initialization logic treats the value as set-once module identity: it stores the captured handle on the first initialization and has a warning path if a later value differs.

Consequently, gameMain receives the module instance assigned to arkkdm.dll. It does not receive gamekdm.dll's module handle.

(d) gameMain signature and calling convention

gameMain is at RVA 0x9e20 / VA 0x10009e20 in gamekdm.dll. Its callable shape is:

/* cdecl; one argument */
gameMain(void *hInstance);

The arkkdm.dll call site pushes exactly one argument before the indirect call. gameMain reads that pointer as its first stack argument. Its return paths use a bare ret, leaving argument cleanup to the caller; the caller resets its own stack frame after the call. Those two sides agree on cdecl.

(e) Complete official binding chain

AVS2 runtime
  -> arkkdm.dll!dll_entry_init
       captures/relays arkkdm.dll's HINSTANCE
  -> arkkdm.dll!dll_entry_main
  -> arkkdm.dll internal candidate resolver
  -> LoadLibraryA("gamekdm.dll")
       fallback: LoadLibraryA("arkkdmtest.dll")
  -> GetProcAddress(candidate, "gameMain")
  -> gameMain(g_MainDllInfo.dllHMODULE)

This establishes the two important boundaries:

  • AVS2 calls the official AVS2 entry export in arkkdm.dll.
  • arkkdm.dll itself loads the payload, resolves gameMain, and supplies its own captured module instance.

Open behavioral questions

The following details do not affect the binding contract:

  • whether g_MainDllInfo.dllHMODULE is reset across repeated entry calls;
  • the purpose of surrounding generic initialization and logging guards;
  • a live cabinet observation of the pointer value received by gameMain.

Cross-references