10 grounded sections (overview, runtime/boot, DLL architecture, Kinect/skeleton, validity+cursor, data formats, gamekdm subsystem map, companion APIs, ABI/structs, reconstruction codebase) + master index, mined from the RVA DB / Ghidra / game dir / reconstructed slices. Independently grounding-reviewed (13/20 sample resolved on first pass; 7 contradicted claims then corrected and re-verified).
18 KiB
04 - Player Validity Gate and Menu Hand Cursor
This section covers the two gates gamekdm.dll applies to whatever skeleton
the NUI stack hands it: the validity/selection gate that decides whether a
tracked body is allowed to render and drive gameplay, and the separate
Flash/afp hand cursor that drives menu navigation. The two are unrelated
code paths with unrelated math, and the reconstruction treats them as such
(src/game/validity.{h,cpp}, src/game/box_distance.cpp). All RVAs are
against image base 0x10000000 (confirmed by re/rvadb.json
image_base = "0x10000000", 00-overview.md). Background
on how both gates were discovered — in-process live-memory introspection
against the running game, reimplemented in Python from a dump rather than
guessed — is in game-internals.md §5.
1. The three functions
| Function | RVA | Role |
|---|---|---|
FUN_10018570 |
0x10018570 |
Builds the gravity/floor-relative transform M used to project a candidate skeleton's hip position into validity-box space. |
FUN_100e4140 |
0x100e4140 |
Per-skeleton-slot driver: for each of the 6 NUI skeleton slots, transforms the candidate position and calls the box-distance metric to decide valid/not valid. |
FUN_101ab6d0 |
0x101ab6d0 |
The box-distance metric itself: squared distance from a point to an axis-aligned box, after clamping to the box's extent. |
FUN_100e4140 and FUN_101ab6d0 are both named explicitly in the task's
scope, and both are confirmed live: metric.out (Ghidra dump_metric.py
output against the once-analyzed gkproj project) decompiles FUN_101ab6d0
at 101ab6d0, and filter.out (dump_filter.py) decompiles FUN_100e4140
at 100e4140 and shows it calling FUN_101ab6d0 directly
(ghidra/filter.out:291: fVar9 = (float10)FUN_101ab6d0();). FUN_10018570
is documented in game-internals.md §2 and
§6 (game-internals.md:31,141) but was not re-dumped for this section; its
listing there is taken as given per the task's reading list.
2. FUN_101ab6d0 — box-distance metric
The raw decompile (ghidra/metric.out:195-206):
float10 FUN_101ab6d0(void)
{
float *pfVar1;
float *unaff_EDI;
FUN_101ab640();
pfVar1 = (float *)FUN_101ab5b0();
return (float10)((unaff_EDI[2] - pfVar1[2]) * (unaff_EDI[2] - pfVar1[2]) +
(*unaff_EDI - *pfVar1) * (*unaff_EDI - *pfVar1) +
(unaff_EDI[1] - pfVar1[1]) * (unaff_EDI[1] - pfVar1[1]));
}
EDI (unaff_EDI) carries the transformed point, and the return value of
FUN_101ab5b0 carries a clamped point (ghidra/metric.out:201-202). The
Ghidra decompiler surfaces FUN_101ab6d0 as having no visible parameters
because the x86 cdecl register/stack args were optimized into caller-set
EAX/EDI, matching the header comment in the reconstruction
(src/game/validity.h:17: // original inputs EAX=box, EDI=point). The two
helpers it calls are per-axis min/max:
FUN_101ab640(ghidra/metric.out:212-240) is a 3-wide max (NaN-aware, per-axisif (a < b != (NAN(a)||NAN(b))) a = b;).FUN_101ab5b0(ghidra/metric.out:246-...) is a 3-wide min (if (*param_2 < fVar1) fVar1 = *param_2;).
Together these clamp the point into [center-extent, center+extent] per axis
before squaring the per-axis delta and summing — a standard point-to-AABB
squared-distance routine, just with Ghidra's register allocation obscuring
which operand is "box" and which is "point" at the call site. The
reconstruction (src/game/box_distance.cpp:6-26) makes this explicit and
documents the surprising field-naming inversion it found during RE:
// T7's field names are misleading: the instructions use center +/- extent,
// not minimum/maximum corners. Preserve its verified binary layout.
const float center[] = {box.minimum.x, box.minimum.y, box.minimum.z};
const float extent[] = {box.maximum.x, box.maximum.y, box.maximum.z};
i.e. the struct fields named minimum/maximum in ValidityState::box
(src/game/validity.h:10, ValidityBox box; // DAT_103d3230) actually hold
center and half-extent, not corners — BoxDistanceSquared reconstructs the
corners (lower = center - extent, upper = center + extent) on every call
rather than storing them pre-computed, matching the original's live
clamp-then-subtract sequence. The volatile qualifiers on lower/upper/
difference in box_distance.cpp:15-20 mark DWORD spill points the original
x87/SSE code forced through memory — kept to pin FP rounding behavior exactly,
not for correctness of the algorithm.
3. FUN_100e4140 — the per-slot validity filter
ghidra/filter.out:193-306 is the full decompile. The function walks the 6
NUI skeleton slots (do { ... uVar5 = uVar5 + 1; ... } while (uVar5 < 6);,
filter.out:296-301), and per slot:
- Takes
DAT_103d4a80as the 4x4 transformM(filter.out:236:pfVar6 = (float *)&DAT_103d4a80;copied into 16 locals — this is the transformFUN_10018570builds, persrc/game/validity.h:9:Matrix4x4 transform; // DAT_103d4a80). - Picks the source position: either the slot's own tracked position, or
DAT_103d32c4(the "missing" sentinel position) if the slot is not tracked (filter.out:247-256,src/game/validity.h:11:Vec3 missing_position; // DAT_103d32c4). - Transforms that position through
Mwith no perspective divide (filter.out:257-260: three dot-products againstM's rows plus translation — this isTransformPositioninsrc/game/validity.cpp:8-18). - If the source position differs from the sentinel (the tracking-state
check), computes
BoxDistanceSquaredagainst the box and compares it to a squared tolerance:DAT_10299294if the slot was not already valid,DAT_10299298if it was (hysteresis —filter.out:282,284:local_80 = DAT_10299294; if (*pcVar7 != '\0') { local_80 = DAT_10299298; }). These map directly tosrc/game/validity.h:12-13:float entry_tolerance; // DAT_10299294/float retained_tolerance; // DAT_10299298. - On a pass, re-applies
Ma second time to the already-transformed point and stores that as the "transformed" candidate position (filter.out:297-302;src/game/validity.cpp:56-57: "The original deliberately applies the matrix a second time"). This double-apply is preserved deliberately in the reconstruction rather than treated as a bug, because the original binary clearly re-invokes the same transform rather than caching the first result.
The reconstruction's UpdateValidityCandidates (src/game/validity.cpp:23-63)
mirrors this slot loop 1:1, including the integer-vs-float tracking-ID
reinterpretation the original performs (validity.cpp:33-36, matching the
T7-style struct where a tracking ID is stored in a field declared float but
read/written as raw uint32_t bits) and the "entry" vs "retained" tolerance
split (validity.cpp:48-49).
4. The validity box and tolerance
Per game-internals.md §2 and §6
(game-internals.md:38-42,142), the box global DAT_103d3230 holds:
A = (0, 1, 0)— box center.B = (1.22, 1, 0.675)— half-extent, giving boundsx ∈ [-1.22, 1.22],y ∈ [0, 2],z ∈ [-0.675, 0.675]in the transform's output space.
The candidate point fed into the check is
P1 = (-px, py + m13, -pz + m14) with no perspective divide, where
m14 = 2.5 (a constant inside the transform matrix, chosen in the shim to
match the published z0) and m13 is taken straight from the skeleton
frame's vFloorClipPlane.w (game-internals.md:38-41). The tolerance is
0.05 (compared as tolerance² against BoxDistanceSquared's output, per
§3 above and validity.cpp:50-53) — this is one entry_tolerance/
retained_tolerance pair (DAT_10299294/DAT_10299298), and
game-internals.md records the combined entry behavior as "within 0.05 of
the box" without the sourced values distinguishing the two constants at the
byte level; the reconstruction keeps them as two distinct fields
(validity.h:12-13) so a divergence between entry and retained tolerance, if
one exists in the binary, is representable without re-deriving the whole
struct.
Floor-clip rule. Because P1.y = py + m13 and the box is centered at
y = 1 with half-extent 1 (so y ∈ [0, 2] is a very loose band but z and
x are tight), the floor-clip term m13 = vFloorClipPlane.w is what anchors
a player's vertical position into the box regardless of absolute camera
height. The shim's fix sets vFloorClipPlane = {0, 1, 0, 1.0 - hip.y} every
frame, which forces P1.y = hip.y + (1.0 - hip.y) = 1.0 — the exact box
center on the y-axis — so the gate's y-component is unconditionally satisfied
every frame regardless of where the hip tracks (game-internals.md:43-46,
commit 36035cc, sensor.cpp BuildSkeletonFrame). This, combined with
vNormalToGravity = (0,1,0,0) steering FUN_10018570 onto its simpler
"gravity sentinel" branch instead of deriving gravity from tracked-joint
geometry (game-internals.md:31-36), is the entire mechanism by which the
shim's synthetic skeleton reliably clears the validity gate.
5. The afp/Flash PhIZ menu hand cursor
The menu cursor is architecturally separate from the validity gate above: it
is not computed by gamekdm.dll native code at all. Per
game-internals.md §3:
afpis the Flash/ActionScript runtime (libafp-win32.dll, exportingflash.display.InteractiveObject,flash.ui.MouseCursor,useHandCursor—game-internals.md:52-53). Menu UI, including the cursor sprite, is compiled Flash packed into.ifsarchives underGAME-DIR/data/bm2d/*.ifs(game-internals.md:55).- The live cursor-controller object pointer is the global
DAT_103d2bb8(game-internals.md:57,game-internals.md:139). The reconstruction's scope list names this thecursor controller global. - 1P cursor coordinates live at
(*DAT_103d2bb8)+0x108/+0x10c; 2P at+0x110/+0x114, in screen pixels (1280x720) (game-internals.md:57-58). This is independently confirmed by the decompile of the cursor-hit-test function:ghidra/cursor.out:222-224writes*(float*)(iVar1+0x108)/+0x10cfor the 1P branch (param_1 == 0), andghidra/cursor.out:315-317writes*(float*)(iVar1+0x110)/+0x114for the 2P branch (the trailingelseof the same function, gated on*(int*)(iVar1+0x30)and*(int*)(iVar1+0x44)both being non-zero). - That function is
FUN_1007fbf0(ghidra/cursor.out:193-320, confirmed by the==== FUN_1007fbf0 @ 1007fbf0 ====header in the dump). It reads the live cursor position viaFUN_101d84c0, called in pairs (ghidra/cursor.out:217-218:FUN_101d84c0(&local_4,&local_c); FUN_101d84c0(¶m_1,&local_8);) — one call for the cursor, one for a button's reference position — and snaps to an OK button when the squared distance is under the threshold. For the 1P/2P "not yet near a button" branches the comparison is0x1fa3 < dist_sq(reject above0x1fa3= 8099, i.e. accept atdist_sq <= 8099,ghidra/cursor.out:219-221,283-285,312-314); for the "already locked to a specific OK button" branches it isdist_sq < 0x1fa4(accept strictly below0x1fa4= 8100,ghidra/cursor.out:236-238,251-253,269-270). Both thresholds bracket the same value —game-internals.md:59-60rounds this to "dist² < 0x1fa4(~90 UI units)", consistent withsqrt(8100) = 90exactly. FUN_101d71e0("_but_ok_1p_usr")/"_but_ok_2p_usr"(ghidra/cursor.out:266,280) resolve the OK-button objects by name beforeFUN_101d78e0reads their position andFUN_101d84c0compares again (ghidra/cursor.out:264-290) — these are the OK-button icons, not the cursor itself, matchinggame-internals.md:61's note that_icon_1p/2p/ only_usrstrings are button icons.- No gamekdm code writes the cursor position from a hand joint.
game-internals.md:63-64states this was checked by searching for anyafp_mc_set_paramcall with the0x1008parameter ID across 53 decompiled menu ActionScript scripts, finding none.FUN_1007fbf0andFUN_101d84c0only read the cursor (afp_mc_get_param(ctrl+8, 0x1008)pergame-internals.md:59); they never set it. The hand -> cursor mapping (the "PhIZ", body-relative and reach-normalized) is internal to the Flash/Natal runtime insidelibafp-win32.dll, which gamekdm does not control (game-internals.md:65-66). This is why the fix for cursor behavior lives entirely on the shim side (skeleton joint positions handed to the NUI layer), not in any gamekdm patch.
Shim-side cursor fixes
Because the mapping from hand position to cursor position cannot be patched
in gamekdm.dll or libafp-win32.dll, the only lever is the skeleton data
the shim publishes (game-internals.md:67, all changes land in
sensor.cpp BuildSkeletonFrame):
- Handedness. The tracker mirrors the camera (selfie view, matching a
real Kinect's mirrored depth image), which swaps MediaPipe's left/right
joint labels; the shim swaps them back via a
kSwap[]table so the player's right hand lands inHAND_RIGHTwith the sign convention real Kinect recordings show (game-internals.md:69-77). - Reach compression. MediaPipe reports the hand roughly 1.6x (x) / 1.3x
(y) closer to the shoulder than a real Kinect does, measured against
UTKinect/MSR-Action3D reference recordings; the shim amplifies each arm
outward from its shoulder by
kArmGainX/kArmGainY(tuned to 3.2/2.6) without touching the hip/center-of-mass, so the validity box (§4 above) stays centered while the cursor gets full screen coverage (game-internals.md:78-85).
6. Two-player handling
Both gates are structurally two-player-capable in the shipped binary, but the emulator side is single-person end to end:
- Validity gate:
FUN_100e4140's slot loop iterates all 6 NUI skeleton slots unconditionally (§3 above,filter.out:296-301), so a second tracked skeleton in slot 1 is evaluated by the exact same box/tolerance logic as slot 0 — there is no special-cased "player 2" branch in the validity math itself; slot index is the only distinguishing input. - Cursor:
FUN_1007fbf0'sparam_1 == 0vsparam_1 != 0/*(int*)(iVar1+0x30)/+0x44branches (ghidra/cursor.out:215,226,309) are the 1P/2P split, writing to the independent+0x108/+0x10c(1P) and+0x110/+0x114(2P) cursor fields identified in §5.game-internals.md:89also citesNuiSkeletonSetTrackedSkeletons([id0, id1])and NUI's 6-slot skeleton array as evidence the game expects real dual tracking. - Emulator limitation: the contract carries a single
SkeletonFrame, and the shim only fillsSkeletonData[0]; the tracker itself runs single-person BlazePose (game-internals.md:91-93). The reproducible evidence for this istracker-native/build/two_person_probe, which composes a 24-frame two-person synthetic sequence from the committedtestdata/sample_rgb.binand drives the shippingPoseEstimator::acquire/runselection policy; the 2026-11-27 run it records tracked exactly one skeleton in all 24 frames, with the selected region-of-interest switching identity twice (frame 14, frame 22) rather than tracking two people at once (game-internals.md:93-99). - Experimental
CUR2probe. SettingKINECT_SHIM_2P=1makesBuildSkeletonFramecopy slot 0 intoSkeletonData[1], horizontally offset, with a distinct tracking ID, purely to exercise whether DEA lights itsCUR2UI state — explicitly not a real second-player claim, since both slots share the same pose and depth mask. The gating logic lives in one sharedPopulateSecondSkeletonFromEnvfunction called by both the production path and atwo_person_shim_probeunit test, which asserts the real environment-variable gate (unset/0/empty/2-> off,1-> on, the on-to-off transition, and that slot 0's bytes are unchanged) rather than a re-implementation of it (game-internals.md:100-112). Real two-player support would need a multi-person pose stage and a two-skeleton tracker contract, neither of which exists yet.
7. Reconstruction mapping
| Original | Reconstruction |
|---|---|
FUN_101ab6d0 (0x101ab6d0) |
gk::game::BoxDistanceSquared (src/game/box_distance.cpp:6) |
FUN_100e4140 (0x100e4140) |
gk::game::UpdateValidityCandidates (src/game/validity.cpp:23) |
FUN_10018570 (0x10018570) |
not yet reconstructed into src/game/validity.*; ValidityState::transform (validity.h:9) is the slot it will populate. |
DAT_103d3230 |
ValidityState::box (validity.h:10) |
DAT_103d4a80 |
ValidityState::transform (validity.h:9) |
DAT_103d32c4 |
ValidityState::missing_position (validity.h:11) |
DAT_10299294 |
ValidityState::entry_tolerance (validity.h:12) |
DAT_10299298 |
ValidityState::retained_tolerance (validity.h:13) |
DAT_103e29b0 |
ValidityState::candidates[kSkeletonCount] (validity.h:14) |
No reconstruction currently exists for FUN_1007fbf0/FUN_101d84c0/
DAT_103d2bb8 (the cursor path): §5 documents the live mechanism from the
decompile and game-internals.md, but the fix for cursor behavior is
entirely shim-side (§5, "Shim-side cursor fixes"), so no gamekdm cursor code
needs reimplementing for the emulator to work correctly.
See also
- 00-overview.md — module stack and image base.
- 08-abi-conventions.md — calling-convention and
struct-layout conventions referenced by
src/game/validity.h'sGK_CDECLannotations. - 09-reconstruction-codebase.md — how
src/game/*fits into the overall reconstruction build. - game-internals.md — the primary RE notes this section draws from (§2 validity, §3 cursor, §4 two-player, §5 tooling, §6 jump-start references for Ghidra and bemaniutils).