The spell lessons ask the player to draw a shape with the mouse, and two native functions of Engine.dll score the drawing against the lesson's template: UGesture::CompareGesture (native 426, the whole drawing) and UGesture::CompareGesturePoint (native 427, one point). The decompiler cannot read either body (each reserves a frame of about 16 KB and the output loses calls and arguments), so the numbers come from the instruction stream. 426 contains a real bug of the original that reads uninitialised memory; the port deliberately takes the "no discards" reading, which a live capture of the running original supports. The second half of this note records how keyboard and mouse events travel through the original's engine, as far as the repo has traced it.
UGesture::execCompareGesture: body0x103a3f60(export thunk0x103035ee, ordinal 2226).UGesture::execCompareGesturePoint: body0x103a3cc0(thunk0x10301244, ordinal 2227). Shared scorer:0x103a39c0(thunk0x1030342c). (port:UELevelRuntime.GestureNatives.cs,CompareGestureNative,CompareGesturePointNative)- Call order in a lesson: the drawing state only records points and switches to the judge state; the judge state's first step calls 426 once, and its tick then calls 427. So the first 426 of an attempt has no 427 before it.
- Both bodies clamp their point counts to
0x400before looping (0x103a3fed,0x103a409d,0x103a3d2d): a longer array is truncated, not rejected.
- Drawn set. Points with
z == -1.0fexactly (0x103a401b) are unused slots and are skipped. All kept points are flattened to z = 0. - Template densified eight times. Each template point emits itself followed by seven interpolations toward the next one, at fractions 0.125 to 0.875 (doubles in
.rdata,0x104765e8..0x10476588), computed as(next - cur) * f + curon the x87 stack and stored as float. The last template point emits only itself, so the count handed to the scorer ism*8 - 7(0x103a41ce). - Distance and running minimum. The squared sum is built on the register stack, stored to a double and passed to
appSqrt; it is then compared with a float running minimum that starts at 1.0 and is stored back as float. - Score (
0x103a39c0). Pass 1 over the template: a template point with a drawn point withinaccuracyadds 2 to the total only; otherwise its cost istrunc(d / (accuracy * 5) + 1)capped at 2, added to both penalty and total (the quotient lives in a register and must not be rounded to float; rounding it makes 1.99999994 become 2). Pass 2 over drawn points: one farther thanaccuracyfrom every template point coststrunc(d / accuracy)capped at 3, added to both. Fewer than 10 drawn points adds a flat 500 to both. Score isclamp(1 - penalty/total, 0, 1);total == 0yields infinity or NaN on the x87 and the lower clamp returns 0. - Casts use
_ftolsemantics: NaN, infinities and out-of-range values give the 64-bit integer indefinite, whose low dword is zero. Withaccuracy == 0the division gives infinity and every missed point adds zero to both sums, so the outcome depends on the parity of such terms. See x87-precision.md. - Point native (427). It densifies the same way but is different code: the difference
next - curis computed once and kept on the register stack, with x kept wide for all seven steps while y is stored as float after the first step and re-read narrowed for steps 0.25 to 0.875. The result is the raw minimum distance, or 1.0 if nothing is nearer.accuracyis evaluated by the exec and never read (no reference to its slot after0x103a3e44).
- The second filter of the drawn set is meant to drop duplicates. Its inner loop (
0x103a402c..0x103a4077) compares each candidate with[edx-4]and[edx], whereedxis the write cursor, advanced only after a store (0x103a4088); the pointer is not indexed by the loop counter. So a candidate is compared with the slot 8 bytes ahead of the last written one: memory the call has not written yet, holding whatever earlier code left in the stack (about 4 KB below the entry stack pointer). The answer is not a function of the arguments alone. - The densify loop also overruns: the template buffer holds 128 points of 8 bytes and the write is unchecked (
0x103a40b7). Measured: 128 template points give 0.4377880096, 129 give 0.6610058546 because the extra slot lands on the first drawn point. The longest shipped pattern has 32 points (the Alohomora one), so the port stops loudly beyond 128 instead of imitating the overrun. - Live capture (decision 426). The running 1.53 original was probed at the dedup loop and the result store (
0x103a4203) on the Alohomora and Wingardium Leviosa lessons: 3 cold starts, 10 attempts. Replaying each capture on the real body is bit exact, the port matches the game bitwise 10 of 10, and no drops occurred in any attempt. The decision (author, 2026-09-29, closed 2026-10-09) is option 1: no discards. "Fixing" the comparison to check all saved points is forbidden, because it changes scores: on sets shorter than ten points it moves the penalty by 500 and flips the lesson outcome. (port:GestureDedupDrawn) - Open: the live capture covers the campaign's lessons; on synthetic input the original's answer genuinely depends on stack residue (a constructed repeat of the call changed the answer in 48 of 144 cases, 23 of them with real campaign patterns). A live playthrough of the lessons is listed separately as not done in that record.
This part comes from an audit of the Windows driver (WinDrv.dll) and engine input code against the port. The port side is a snapshot and some differences listed there are still open.
- Everything is synchronous between ticks. The main loop (
HP.exeMainLoop0x10914a60) alternates the engine tick and the OS message pump (order taken from a comment, not re-verified). Each input event runs the console script and bindings inside the window procedure, in OS message order. Nothing is queued per frame. Inside the tick,AActor::Tick(around0x103b414a) callsPlayer->ReadInput(dt), thenPlayerInput,PlayerTick, andReadInput(-1.0). UViewport::ReadInput(0x10385d20): ifdt != -1it callsUpdateInput(0), thenInput->ReadInput(dt).UWindowsViewport::UpdateInput(0)only releases: for each virtual key whose entry is inKeyDownTablebut whoseGetKeyStatesays up, it sends a Release (final loop0x11109c52..0x11109cf6). Presses come fromUpdateInput(1), called byUInput::ResetInput(0x103a5f30..0x103a60a1).- Events.
WM_KEYDOWNsends a Press on every message, autorepeat included; Alt+Enter toggles fullscreen and sends no event (0x1110b2ec,0x1110b2fa);WM_KEYUPsends Release (0x1110b38b).WM_CHAR(control characters too: Backspace, Tab, Escape) goes toUEngine::Key, so the order is Press then KeyType. The shipped ini hasUseDirectInput=False; the mouse arrives asWM_MOUSEMOVE, drained per batch into one MouseX and one MouseY axis event. EachWM_MOUSEWHEELsends a MouseW axis (raw plus or minus 120) and a Press and Release of MouseWheelUp or Down (0x1110bec9..0x1110bf15). UEngine::InputEvent(0x10393a08..0x10393a8b): the console script'sKeyEventruns first. If it consumes the event, a Release still goes toUInput::PreProcess(clearing the down table) but the binding is not executed; otherwisePreProcessthenProcessrun the binding.PreProcessdrops a Press on a key already down and a Release on a key not down.UInput::ReadInput(dt): for keys 0 to 254 in index order, a down key gets a Hold through the bindings; then every input float property of the pawn is multiplied by20/dt(withdt == -1, by 0, which zeroes them). Smoothing of the mouse is script (PlayerInputbytecode). Mouse chain: pixels, then theAxisbinding withSpeed=6.0,+= delta * speed * 0.01, then20/dt, then the sensitivity setting in script.- Reset points.
ResetInputis called on focus gained and lost (0x1110add4,0x1110ad08) and byLoadMapfor each viewport; it clears the table and input properties then callsUpdateInput(1), which re-sends a Press for every key down, never a Release. Opening or closing the menu does not reset input. - Menu consequence. The console script owns Escape (
HPConsole.KeyEvent, then the menu book). Keys held when the menu opens stay in the down table; their Release is consumed by the console, so onlyPreProcessruns and the binding's release half never does. A button held across the opening of the menu and released inside it stays pressed after the menu closes until pressed and released again.
- The audit lists 30 rows. Matches: console-first dispatch, dedup,
Execforms, the20/dtscaling, Alt+Enter handling and the Enter filter onWM_CHAR. Mismatches: hold loop order (the port iterates a hash set instead of key index order, which can change the last bit when two held keys feed one axis);ReadInputis called by the frontend before the tick instead of inside the player's actor tick; the menu half bypassesUEngine::InputEvent; Escape release and middle mouse never reach the menu console; per-frame mouse sums instead of one axis per batch; wheel as one Press and Release per frame without the axis event (invisible with shipped data, since the bindings are empty). - Improvements (not original): Alt+Enter autorepeat does not toggle again; the mouse wheel scrolls combo lists in the menu (D-70).
- Open: whether the original's "stuck AltFire after a menu release" is wanted (author to see an original and port pair); the effect on native Windows of the mouse speed setting the original installs while the mouse is captured (
{0,0,0x10000}, viaSystemParametersInfo); windowed-mode mouse capture is not traced; the main loop order (tick then pump) is taken from a comment, not re-verified. The proposed redesign (the frontend sends raw device events and Core owns the window-procedure logic) is a spec, not implemented as of this note. (port:UEInput.cs,hpengine/Input/)