# 03 - Kinect Input and Skeleton Pipeline ## Scope and address convention `gamekdm.dll`'s own import table statically imports `Kinect10.dll` (`re/importlibs/Kinect10.def`), Microsoft's external Kinect-for-Windows NUI v1 runtime — not a module shipped in `contents/modules/`, but an external dependency gamekdm.dll's import table requires and which a real cabinet satisfies from the installed Kinect runtime [`../../.omo/scope/official-scope.md`](../../.omo/scope/official-scope.md). This reconstruction's own test shim stands in for that runtime off-cabinet: it delivers a 20-joint skeleton through the same `Kinect10.dll` import surface, after which gamekdm performs selection/validation and feeds the menu cursor system (`game-internals.md:15-24`). The reconstruction's own test tracker publishes synthetic depth, color, and skeleton data through shared memory to that shim (`game-internals.md:7-10`); this synthetic data path is part of the reconstruction's test harness, not the shipped game. See [the overview](./00-overview.md), [companion APIs](./07-companion-apis.md), and [the reconstruction codebase](./09-reconstruction-codebase.md). Addresses written as `FUN_100...` or `DAT_103...` are preferred virtual addresses (VAs); the image base is `0x10000000`, so `FUN_1000f510` has RVA `0x0000f510`. This distinguishes the VA-style `rva=` comments in the reconstructed source from the relative values in the database (`game-internals.md:5`; `src/game/nui_elevation.cpp:5`; `re/rvadb.json`, fields `image_base` and function `rva`). ## Kinect10.dll boundary The inspected game binary statically imports five Kinect10.dll ordinals. The following is the Kinect import block from `objdump -p` of `/mnt/f/Users/Aaron Thapa/Downloads/KDM-2016021900/contents/gamekdm.dll`: ```text DLL Name: Kinect10.dll vma: Ordinal Hint Member-Name Bound-To 002181d4 5 002181d8 6 002181dc 20 002181e0 9 002181e4 22 ``` This import block is read from the official `gamekdm.dll` binary's own PE import table. `Kinect10.dll` is Microsoft's external Kinect-for-Windows NUI v1 runtime, not a module shipped in `contents/modules/`; gamekdm.dll's import table requires it, and on a cabinet it is satisfied by the installed Kinect runtime, never by a game-shipped file [`../../.omo/scope/official-scope.md`](../../.omo/scope/official-scope.md). The reconstruction's own test shim pins those ordinals to `NuiGetSensorCount` (5), `NuiCreateSensorByIndex` (6), `NuiImageGetColorPixelCoordinatesFromDepthPixel` (9), `NuiTransformSmooth` (20), and `NuiSetDeviceStatusCallback` (22) (`/home/athapa/kinect/fallback/windows-nui/Kinect10.def:4-21`). The repository import-library definition lists decorated names and explicitly requires `--kill-at`; its `@4`/`@8` name suffixes must not be read as the shim's export ordinals (`re/importlibs/Kinect10.def:5-34`). ### Full declared surface The following table covers all 25 named entries and the anonymous slot in the repository definition. Presence here establishes the declared ABI surface, not that gamekdm calls every entry (`re/importlibs/Kinect10.def:8-34`). | Group | Entries, without decoration | Evidence | | --- | --- | --- | | Anonymous slot | `ord_1 @1 NONAME` | `re/importlibs/Kinect10.def:9` | | Discovery | `NuiGetSensorCount`, `NuiCreateSensorByIndex`, `NuiCreateSensorById` | `re/importlibs/Kinect10.def:10-11,26` | | Lifecycle/events | `NuiInitialize`, `NuiSetFrameEndEvent`, `NuiShutdown`, `NuiSetDeviceStatusCallback` | `re/importlibs/Kinect10.def:19-21,27` | | Elevation | `NuiCameraElevationGetAngle`, `NuiCameraElevationSetAngle` | `re/importlibs/Kinect10.def:12-13` | | Pixel mapping | `NuiImageGetColorPixelCoordinatesFromDepthPixel`, `NuiImageGetColorPixelCoordinatesFromDepthPixelAtResolution` | `re/importlibs/Kinect10.def:14-15` | | Image frames | `NuiImageStreamGetNextFrame`, `NuiImageStreamOpen`, `NuiImageStreamReleaseFrame` | `re/importlibs/Kinect10.def:16-18` | | Stream flags | `NuiImageStreamSetImageFrameFlags`, `NuiImageStreamGetImageFrameFlags` | `re/importlibs/Kinect10.def:28-29` | | Skeleton frames | `NuiSkeletonGetNextFrame`, `NuiSkeletonTrackingDisable`, `NuiSkeletonTrackingEnable`, `NuiTransformSmooth` | `re/importlibs/Kinect10.def:22-25` | | Skeleton selection/orientation | `NuiSkeletonSetTrackedSkeletons`, `NuiSkeletonCalculateBoneOrientations` | `re/importlibs/Kinect10.def:31-32` | | Other | `NuiGetAudioSource`, `NuiCreateCoordinateMapperFromParameters`, `NuiCreateDepthFilter` | `re/importlibs/Kinect10.def:30,33-34` | The reconstruction's test-shim interface declares initialization, image-stream, skeleton, and elevation methods on `INuiSensor` as well as providing flat exports; the game's reconstructed elevation routine specifically calls a sensor interface pointer. Thus absence from the five flat imports does not establish absence of functionality (`/home/athapa/kinect/fallback/windows-nui/include/nui_interfaces.h:41-103`; `src/game/nui_elevation.h:7-27`; `src/game/nui_elevation.cpp:8,20`). The exact dispatch path for every other method is **UNVERIFIED** here. ### Recorded initialization A saved shim trace records sensor enumeration, creation of sensor index 0, initialization with flags `0x0000000B`, and a frame-end event (`/home/athapa/kinect/.re/shim_log_init.txt:2-6`). Those flags combine depth/player index `0x1`, color `0x2`, and skeleton `0x8` according to the shim declarations (`/home/athapa/kinect/fallback/windows-nui/include/nui_abi.h:45-50`). The same trace records depth at **320x240, 2 bytes/pixel**, color at **640x480, 4 bytes/pixel**, and `ring=3` for both, with separate image events. Skeleton tracking is enabled with `0x2`, declared as `TITLE_SETS_TRACKED_SKELETONS` (`/home/athapa/kinect/.re/shim_log_init.txt:7-11`; `/home/athapa/kinect/fallback/windows-nui/include/nui_abi.h:52-56`). These are observations of that capture, not proof of all operating modes. `game-internals.md` section 1 describes 4:3 images and says depth/color are 640x480 (`game-internals.md:21-22`). Both captured stream sizes are 4:3, but the captured depth size differs. A later transition to 640x480 depth is **UNVERIFIED**; this section does not resolve the discrepancy by assuming a boot-versus-steady-state change (`/home/athapa/kinect/.re/shim_log_init.txt:7-8`). ## NuiThread and skeleton transfer ### Function identification The retained diagnostic names can be tied to function bodies through their actual instruction references. The table distinguishes function entry RVAs from the string RVAs loaded by those functions; the database confirms each function's `globals_touched` reference (`re/rvadb.json`, function records `0x0000f0a0`, `0x0000f300`, and `0x000103d0`, and corresponding data-symbol records). | Routine | Entry RVA / preferred VA | String RVA | Instruction evidence | | --- | --- | --- | --- | | `NuiThread::updateFrame` | `0x0000f0a0` / `0x1000f0a0` | `0x002a48a0` | VA `0x1000f0db` loads `0x102a48a0` | | `NuiThread::updateSkeleton` | `0x0000f300` / `0x1000f300` | `0x002a48b8` | VA `0x1000f33b` loads `0x102a48b8` | | `hid::Natal::copySkeleton` | `0x000103d0` / `0x100103d0` | `0x002a4918` | VA `0x10010421` loads `0x102a4918` | The instruction evidence is preserved in `/home/athapa/kinect/.re/gamekdm.asm:18351-18371,18555-18575,19865-19892`. The database records `FUN_1000ebd0 -> FUN_1000ef50`, with the latter calling the frame, skeleton, stream (`0x0000f400`), and elevation (`0x0000f510`) routines (`re/rvadb.json`, function records at RVAs `0x0000ebd0` and `0x0000ef50`). ### Event dispatch and skeleton acquisition The dispatcher at RVA `0x0000ef50` checks the sensor pointer at `thread+0x15fc`, then calls `WaitForMultipleObjects` with five handles starting at `thread+0x50`, wait-all false, and timeout `0x7530` (30,000 ms). An absent sensor writes state value 3; an out-of-range wait result writes state value 6. These are numeric states, without inferred enum names (VAs `0x1000ef61-0x1000ef99`, `0x1000f07f`; `re/rvadb.json`, RVA `0x0000ef50`, `external_callees`; `/home/athapa/kinect/.re/gamekdm.asm:18232-18266,18323-18328`). Wait result 3 tests bit 0 of `thread+0x2c`: when enabled, it calls `updateSkeleton` and then `updateFrame`; otherwise it resets the event at `thread+0x5c` and still calls `updateFrame`. Results 1 and 2 call the stream routine with index `result-1` before `updateFrame`. Result 4 also calls `updateFrame`. Thus publication is event-driven, and these branches do not establish a fixed refresh rate (VAs `0x1000ef9f-0x1000f02c`; `/home/athapa/kinect/.re/gamekdm.asm:18266-18318`). `updateSkeleton` passes zero wait time and destination `thread+0x68` to sensor vtable offset `0x4c`, matching `INuiSensor::NuiSkeletonGetNextFrame`. On a nonnegative return it writes state 7; if `thread+0x15f8` is set, it calls vtable offset `0x48` with the tracking-ID array at `thread+0x15f0`, matching `NuiSkeletonSetTrackedSkeletons`. Returns `0x80070015` and `0x8007048f` write state 4; the shown code does not give every failed read that state (VAs `0x1000f36b-0x1000f3b8`; `/home/athapa/kinect/.re/gamekdm.asm:18585-18612`; `/home/athapa/kinect/fallback/windows-nui/include/nui_interfaces.h:41-103`). ### Frame publication and consumer copy `updateFrame` copies `0x29a` DWORDs, or `0xa68` bytes, from `thread+0x68` to `thread+0xb30`. This matches the declared NUI skeleton-frame size: 48 bytes of frame metadata plus six 436-byte skeleton records. The metadata includes timestamp, frame number, flags, floor plane, and gravity; each skeleton includes identity, position, 20 joint vectors, 20 joint states, and quality flags (VAs `0x1000f11b-0x1000f129`; `/home/athapa/kinect/fallback/windows-nui/include/nui_abi.h:26-36,145-165`). Publication brackets the copy with conditional calls through imports at VAs `0x10218414` and `0x10218418`, and increments/decrements `thread+0x4c`. The database identifies those imports as AVS ordinals 17 and 18; their precise synchronization contract is **UNVERIFIED** here. After processing two image-frame slots, it signals the event at `thread+0x64`. The image-slot loop releases a previous frame through sensor vtable offset `0x28` before copying the next frame descriptor (VAs `0x1000f107-0x1000f1c9`; `re/rvadb.json`, RVA `0x0000f0a0`, `external_callees`; `/home/athapa/kinect/fallback/windows-nui/include/nui_interfaces.h:58-62`). The consumer-side `FUN_1000fa20` calls `copySkeleton` at RVA `0x000103d0`; its database record also references the manager-pointer global at RVA `0x003cf1b4`. The notes identify the live manager as `*(gamekdm+0x3cf1b4)` (`re/rvadb.json`, RVA `0x0000fa20`, `callees` and `globals_touched`; `game-internals.md` section 1, lines 23-24). `copySkeleton` has both coordinate-copy and coordinate-transform branches: it tests bit 1 of its object's `+0x08` flags, loads joint vectors, and either performs floating-point products/sums or copies coordinates directly. It also checks skeleton tracking state against 2 and writes zero joint state when that check fails. This is processing of supplied joint data; section 1's statement that the game receives the skeleton directly should not be interpreted as a promise of a raw `memcpy` throughout the pipeline (VAs `0x10010439-0x10010446`, `0x100105e2-0x10010605`, `0x10010893-0x100108b9`; `/home/athapa/kinect/.re/gamekdm.asm:19895-19904,20000-20022,20167-20183`; `game-internals.md:17-20`). The full semantics of that optional transform and the intervening manager buffer ownership are **UNVERIFIED** here. At the reconstructed validity boundary, `UpdateValidityCandidates` explicitly reads `manager.skeleton_frame.skeletons[index]` (`src/game/validity.cpp:23-27`). ## Camera elevation reconstruction `UpdateCameraElevation` reconstructs VA `0x1000f510` / RVA `0x0000f510`. The header associates its logical fields with original object offsets; these comments do not make the compact reconstructed struct a byte-for-byte original object layout (`src/game/nui_elevation.h:19-34`). | Logical field | Original offset | Meaning in reconstruction | | --- | --- | --- | | `desired_angle` | `+0x38` | Requested setting | | `applied_angle` | `+0x3c` | Last setting issued | | `smoothed_angle` | `+0x40` | Published estimate | | `accumulator` | `+0x44` | IIR state, sentinel `-0x168` | | `sensor` | `+0x15fc` | Sensor control interface | Field evidence is `src/game/nui_elevation.h:23-31`. The two-method `ICameraElevation` is a reconstruction interface; the header records original sensor dispatch offsets `0x3c` for Get and `0x38` for Set. It does not claim the two-method interface duplicates the complete original sensor vtable (`src/game/nui_elevation.h:7-16`). On successful `GetAngle` (`status >= 0`), the routine seeds a sentinel accumulator from the reading, then computes `averaged = (current + 2 * accumulator) / 3`, publishing and retaining it. The source ties signed truncation toward zero to instructions at VA `0x1000f53c`; the sentinel comparison is at VA `0x1000f527` (`src/game/nui_elevation.cpp:7-18`; `src/game/nui_elevation.h:30-31`). When desired and applied values differ, it calls `SetAngle` and updates `applied_angle` without checking that call's result. This branch is outside the successful-Get branch (`src/game/nui_elevation.cpp:19-22`). ## Depth-to-skeleton projection The reconstruction's test-shim mapping implementation uses `kDepthProjectionScale = 3.501e-3f`. The RE notes identify this with the nominal inverse focal-length constant and report Kinect-compatible projection; that historical compatibility claim is not a fresh physical-sensor measurement here (`/home/athapa/kinect/core/mapping/mapping.cpp:9`; `game-internals.md:69-71`). For pixel coordinates `(u,v)`, image dimensions `(W,H)`, and packed depth `d`, the implementation computes the following before clamping (`/home/athapa/kinect/core/mapping/mapping.cpp:142-157`): ```text s = 3.501e-3 z = (d >> 3) / 1000 x = (u - W/2) * (320/W) * s * z y = -(v - H/2) * (240/H) * s * z w = 1 ``` The low three bits encode player index; the shift removes them. The shim declares joint coordinates in metres and a player-index shift of 3 (`/home/athapa/kinect/fallback/windows-nui/include/nui_abi.h:26-40`). The mapping clamps x to `[-2.2,2.2]`, y to `[-1.6,1.6]`, and z to `[0,4]` (`/home/athapa/kinect/core/mapping/mapping.cpp:9-15,100-106`). Its inverse divides by the same scale and a guarded depth, and rounds back to pixel/depth integers (`/home/athapa/kinect/core/mapping/mapping.cpp:159-180`). The golden harness documents five depth-projection fixtures derived from this mapping and round-trip inputs; their expected coordinates are computed, not independent raw Kinect measurements (`tests/golden/README.md:20-23`; `tests/golden/gen_fixtures.py:7-18`). For example, evaluating the fixture generator's formula at 640x480 gives `(0,0,2.5)` for `(320,240,20000)` and `(-0.448128,0.336096,0.8)` for `(0,0,6400)` (`tests/golden/gen_fixtures.py:51-67`). ## From skeleton frame to validity The shim initializes all six slots as untracked and fills slot 0 when it has a player. Slot 0 receives the source tracking ID and hip-center position; its skeleton and all copied joints are marked tracked (`/home/athapa/kinect/fallback/windows-nui/src/sensor.cpp:895-943`; `/home/athapa/kinect/fallback/windows-nui/include/nui_abi.h:34-36`). It supplies `vNormalToGravity = (0,1,0,0)` and `vFloorClipPlane = (0,1,0,1-hip.y)` (`/home/athapa/kinect/fallback/windows-nui/src/sensor.cpp:888-893`). The RE notes identify VA `0x10018570` / RVA `0x00018570` as the transform builder. With sentinel gravity at `manager+0x2c`, it derives orientation from tracked joints: weighted tracked coverage must exceed `0.85`, then five limb-direction dot products must exceed `0.9`. The provided up-gravity vector takes the simpler gravity branch (`game-internals.md:31-36`). These thresholds are cited from prior RE; that transform builder was not re-decompiled for this document. The candidate consumer is VA `0x100e4140` / RVA `0x000e4140`, calling the box-distance helper at VA `0x101ab6d0` / RVA `0x001ab6d0` (`re/rvadb.json`, function records at those RVAs; `src/game/validity.h:17-22`). The reconstructed consumer reads each skeleton's tracking ID, clears validity when identity changes, and chooses a tracked position or a missing-position sentinel (`src/game/validity.cpp:26-43`). It compares squared distance with squared tolerance, using separate entry and retained tolerances; missing positions are invalid (`src/game/validity.cpp:44-61`; `src/game/validity.h:11-14`). The distance helper clamps a point against center-plus/minus-extent bounds and sums squared residuals. Despite the struct field names `minimum` and `maximum`, their roles here are center and extent (`src/game/box_distance.cpp:6-28`). The documented captured gate uses center `A=(0,1,0)`, extent `B=(1.22,1,0.675)`, and distance tolerance `0.05`; the tolerance is Euclidean distance to the box, not three independent axis margins (`game-internals.md:37-42`; `src/game/box_distance.cpp:14-28`). For the documented level-gravity configuration, the notes reduce the first transform to `P1=(-px, py+m13, -pz+m14)`, with `m14=2.5` and `m13` taken from the floor plane's w component. This is a recorded configuration, not the general matrix formula implemented by the consumer (`game-internals.md:37-42`; `src/game/validity.cpp:8-17`). Setting the floor offset to `1-hip.y` makes `P1.y=1`; a hip depth of `2.5` makes `P1.z=0`. X bounds and depth placement still matter (`game-internals.md:43-46`; `tests/golden/gen_fixtures.py:24-30`). For an accepted candidate, the reconstruction stores the original source position and deliberately applies the matrix a second time for the stored transformed position (`src/game/validity.cpp:54-57`). The selection notes link passing the orientation/validity gate with visible skeleton rendering (`game-internals.md:28-29,43-46`). ## Handedness, cursor reach, and limits The shim swaps left/right joint indices with `{0,1,2,3,8,9,10,11,4,5,6,7,16,17,18,19,12,13,14,15}`, then applies calibrated arm amplification (`/home/athapa/kinect/fallback/windows-nui/src/sensor.cpp:934-946`). The notes attribute these corrections to mirrored tracker input and compressed arm reach, and say the hip/center-of-mass stays unchanged (`game-internals.md:69-85`). The unchanged hip explains unchanged candidate-position math; it does not prove limb changes are irrelevant to the sentinel-gravity orientation branch, which explicitly examines limbs (`game-internals.md:31-36`). Arm gain defaults are `3.2` horizontally and `2.6` vertically; the reconstruction's test-shim calibration document gives environment overrides precedence over saved calibration and then defaults (`/home/athapa/kinect/docs/calibration.md:25-39`). The menu hand-cursor mapping is attributed by the RE notes to the Flash/Natal runtime; detailed cursor handling belongs with [the validity and cursor section](./04-validity-cursor.md) (`game-internals.md:60-66`). Six ABI skeleton slots do not establish six tracked players: the shim declares at most two tracked skeletons, and the documented tracker is single-person. The optional second-slot probe duplicates a pose rather than tracking a second person (`/home/athapa/kinect/fallback/windows-nui/include/nui_abi.h:34-36`; `game-internals.md:89-113`). ## Verification and remaining unknowns The reproducible replay command is `source ~/.nix-profile/etc/profile.d/nix.sh && source ./activate.sh && python3 tests/golden/golden_harness.py`. It checks projection, validity, and a recorded hip midpoint against committed fixtures. Projection expectations are derived from reconstruction math; passing them does not independently establish fidelity to physical Kinect hardware (`tests/golden/golden_harness.py:1-23`; `tests/golden/gen_fixtures.py:7-18`; `tests/golden/README.md:20-24`). The named routine mappings can be checked without decompilation: inspect the function and data-symbol records listed above in `re/rvadb.json`, then disassemble the three string-load addresses with `objdump -d` against `/mnt/f/Users/Aaron Thapa/Downloads/KDM-2016021900/contents/gamekdm.dll`. The flat import block is separately inspectable with `objdump -p` against that same absolute game-binary path. **UNVERIFIED:** complete synchronization and ownership rules, fixed update frequency, the optional copy transform's full semantics, a later depth-resolution change, and whether gamekdm calls `NuiSkeletonCalculateBoneOrientations`. The evidence above establishes specific branches and data transfers, a captured stream size, or an available export rather than those stronger claims (VAs `0x1000ef50`, `0x1000f0a0`, `0x100103d0`; `/home/athapa/kinect/.re/shim_log_init.txt:7`; `re/importlibs/Kinect10.def:32`).