From 0c913d15aa9e07c40eb27a6d3d541d81e40bb292 Mon Sep 17 00:00:00 2001 From: Cristian Cerroni Date: Tue, 3 Nov 2026 21:25:54 -0500 Subject: [PATCH] Implement Grappler scalar component with original-code references --- AGENTS.md | 25 +- docs/architecture.md | 5 + docs/compatibility.md | 7 + docs/decisions.md | 6 + docs/gameplay/grappler-component.md | 100 ++++ docs/gameplay/grappler.md | 3 + docs/orbit-camera.md | 5 + docs/progress.md | 17 + docs/reverse-engineering.md | 6 + docs/tasks.md | 9 +- scripts/test.sh | 1 + src/GamePort/Game/GrapplerMotion.cs | 64 +++ .../GamePort.GrapplerTests.csproj | 9 + tests/GamePort.GrapplerTests/Program.cs | 59 ++ .../original-scalar-reference.json | 515 ++++++++++++++++++ tests/test_grappler_motion.py | 38 ++ tools/binary/grappler_motion.py | 63 +++ tools/binary/grappler_scalar_probe.c | 96 ++++ 18 files changed, 1014 insertions(+), 14 deletions(-) create mode 100644 docs/gameplay/grappler-component.md create mode 100644 src/GamePort/Game/GrapplerMotion.cs create mode 100644 tests/GamePort.GrapplerTests/GamePort.GrapplerTests.csproj create mode 100644 tests/GamePort.GrapplerTests/Program.cs create mode 100644 tests/GamePort.GrapplerTests/original-scalar-reference.json create mode 100644 tests/test_grappler_motion.py create mode 100644 tools/binary/grappler_motion.py create mode 100644 tools/binary/grappler_scalar_probe.c diff --git a/AGENTS.md b/AGENTS.md index 2d6a3d7..24f2dc1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -46,20 +46,23 @@ changes. Current gadget controls/resources/primary-fire findings belong in docs/gameplay/. Distinguish static recovery, implementation, port tests and original runtime evidence. Main owns integration/runtime; gadget investigators have exclusive named files, not shared directories. -Latest continuation: docs/gameplay/rocketship-live.md. Rocketship is live in bounded -VR02. The modern inspector's world-mirroring correction is docs/orbit-camera.md: -same handedness as gameplay,36 matrix cases/GPU/native input+resize checks pass, -packages identify clean d8f1b51. The gadget continuation remains bounded -VR02; follow-up docs/gameplay/rocketship-impact-render.md corrects wall-hit -material RGBA previously misread as scale. Packages identify clean62e908e; -13 managed/22 Python checks and final native Linux flight replay pass. -The live scope remains bounded -VR02: source body/callbacks, registration-ordered input, maneuvers/camera, original +Latest gadget continuation: docs/gameplay/grappler-component.md. GrapplerMotion +is isolated:30 copied-original scalar observations,5 managed/14 Python groups, +existing25 movement/15 gadget groups and main build pass. Ray/body/camera/helper +gates remain before liveVR08. Source and REA artifacts are retained under +artifacts/grappler-{ray,motion,resources,scalars}/; all ownership returned after +investigator usage limits. No approximate hook/pull mechanic is enabled. +The user clarified orbit's remaining issue was inverted Left/Right; Left/A and +Right/D azimuth mappings are corrected, Up/Down unchanged. Playable packages +identify clean70cba65; native input/resize/validation passes. See docs/orbit-camera.md. +Rocketship remains live in boundedVR02: source body/callbacks, +registration-ordered input, maneuvers/camera, original driver/Goddard/flame resources and F1 grant.96 isolated original component cases support the source contracts; full pair discovery, other levels, special mission/ hazard/RNG effects and whole-original/native Windows comparison remain open. -Grappler source is in -docs/gameplay/grappler.md; no approximate hook/pull mechanic is enabled. Friend +Its wall-impact material RGBA correction is docs/gameplay/rocketship-impact-render.md; +13 managed/22 Python checks and final native Linux flight replay pass. +Grappler source is in docs/gameplay/grappler.md. Friend research assessment is docs/reviews/jn-engine-survey.md; use its decompiler leads with REA/source checks, not its tuned C gameplay. All ownership has returned. Preserve baseline69d0187 and parked35a2a66/0272f7b collision checkpoints. Latest diff --git a/docs/architecture.md b/docs/architecture.md index 8f66f5d..dac2345 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -285,3 +285,8 @@ unresolved lifetime/pair/camera boundaries are in gameplay/rocketship-live.md. Grappler's distinct source ownership and geometry/material/swing contract is in gameplay/grappler.md; it is not a simple player movement mode or nearest-tag interaction. + +GrapplerMotion implements the isolated attachment/reel/damping arithmetic and +independent fire/jump detach predicate, compared with30 copied-original cases. +It owns no body/ray/camera/helper lifetime and is not called by live simulation; +integration gates and retained source/REA findings are in gameplay/grappler-component.md. diff --git a/docs/compatibility.md b/docs/compatibility.md index 6e3c211..b0da2b2 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -3,6 +3,13 @@ Compilation, native runtime, original behavior and full feature completion are separate evidence categories. **The game is not fully reconstructed/playable yet.** +Grappler scalar checkpoint:30 copied-original Wine32 observations match5 managed +groups,14 Python source/projection checks,25 movement/15 gadget groups and main +build pass. No live Grappler, new Vulkan path or original/native Windows gameplay +comparison is claimed. See gameplay/grappler-component.md. Playable packages +remain70cba65 with the orbit horizontal-input correction, verified by native +Linux SDL input/resize and zero enabled Vulkan validation errors. + Orbit inspector follow-up: corrected right-handed inspection view/perspective to gameplay's positive-Z left-handed convention.36 camera/aspect cases and all existing projection checks pass. Enabled-validation llvmpipe captures confirm diff --git a/docs/decisions.md b/docs/decisions.md index fa5ead2..cde04a5 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -270,3 +270,9 @@ left-handed view/projection; apply the shared Vulkan Y correction only once. Regress screen right/up and depth across camera poses, not frame presence alone. The modern inspector is separate from recovered original camera logic. +46. **Keep Grappler cursor/attachment and input/normal gates distinct.** Cursor + distance/material rejection does not prevent attachment on a ray hit. + Attached input may return early while ordinary Jimmy frame publication still + runs. Compare isolated sqrt/first-scale/reel/damping with original snippets + before composing body/camera/helper ownership; do not invent250 clamps or a + detach impulse. GrapplerMotion remains isolated until those gates close. diff --git a/docs/gameplay/grappler-component.md b/docs/gameplay/grappler-component.md new file mode 100644 index 0000000..dc938f0 --- /dev/null +++ b/docs/gameplay/grappler-component.md @@ -0,0 +1,100 @@ +# Grappler scalar checkpoint + +2026-11-03. Continues user-requested gadgets after the Rocketship/orbit fixes. +The latest playable packages include the orbit Left/Right correction70cba65. +GrapplerMotion is an isolated component; no live equip/ray/swing/camera path is +enabled. Originals and supplied friend files remain untouched. All investigator +ownership returned after their usage limits; primary integrated retained results. + +## Implemented coverage + +| Original span, exclusive end | File offset | Managed coverage / verification | +| --- | --- | --- | +|426BE8..426C70|26BE8|Explicit x87 sqrt distance minus100, first-length sentinel and initial rope Z scale.8 native cases, including reattach, fractions and short/negative lengths.| +|426DAC..426DD5|26DAC|Held reel: old length strictly>250, subtract250*dt without final clamp.6 native cases; loop-audio branches are outside the snippet.| +|429DC9..429DF5|29DC9|Fast reel: target=double.2, clamp50 and350 damping boundary, subtract float.2 once.10 native cases; no body constraint/position execution.| + +`tools/binary/grappler.py` guards the authoritative EXE identity and enclosing +source spans; `grappler_motion.py` records the four exact span hashes/offsets and +imports completed probe results. The numeric fixture in +`tests/GamePort.GrapplerTests/original-scalar-reference.json` includes source, +generator, executable and log hashes. Eight attachment observations measure only +length/initial-length/scale callback; managed velocityY100 and reel target are +supported by the separate guarded426CDE..426D4D source, not those observations. +Independent jump/fire detach is retained from the prior source contract. + +42A0C2 stores Z while retaining its unrounded x87 value until damping; the new +managed helper preserves a double intermediate there. X is reloaded after its +float store. Both are bounded projections; general x87 bit identity is unclaimed. +Neither negative lengths nor250/target overshoot are silently repaired. + +## Probe boundary and verification + +`grappler_scalar_probe.c` copies the hashed EXE into private memory, relocates +only whitelisted absolute scalar operands in the four slices, seeds synthetic +frame/root/state, stubs the rope shape's scale callback and exits at bounded +slice boundaries. It never invokes the original entrypoint, ray/body dispatch, +audio or renderer. Separate copied Wine32 installation/prefix runs with no +network or Original mount. Thirty cases finish with GRAPPLER_SCALARS_COMPLETE. + +The initial fresh Wine prefix exceeded an8-second allowance and could not load +kernel32 on retry; those failures are retained. A copied previously working +prefix resolved startup. A fixed original-image allocation was unavailable; +the final successful probe uses private image relocation instead. Earlier map +failure logs are retained, and no results from failed runs enter the fixture. +The initial C build collided with Windows' byte typedef; emitter naming was +corrected before successful compilation. + +Five managed groups compare all30 native observations within.0002 and cover +first-length retention, source-only velocity/target, overshoot, one-step damping, +simultaneous fire/jump and bounded inputs.14 Python source/projection checks, +existing25 movement/15 gadget groups and the main .NET10 build pass. This is +component execution/port compilation, not original or modern Grappler gameplay. +Evidence is under artifacts/grappler-scalars/{source.json,probe-ready/wine.log, +probe-ready/capture.json,managed.log,python.log,movement.log,gadgets.log,build.log}. + +## Retained source investigation and remaining integration gates + +The following source evidence narrows the next work; it is not a live adapter: + +- Aim cursor and attachment have different gates.426A70 attaches on a successful + ray hit without repeating429D00's450-distance/material rejection. Both query + root→full-Euler local(0,2400,2400) using47C210(false). The aim path refreshes + root at42A384, discarding the earlier swing pivot+116. VR08 game vtable4D00D0 + slot134 at4D0204→475CD0(false) supports static filter admission, but selected + material/global context and attached callback composition remain to implement. +- 429D00 returning true only ends the remaining active input426030. Ordinary + Jimmy437940 still dispatches437C40/437F90, publishing velocity independently + after swing root work; do not skip normal movement wholesale. Swing constraint + normalization uses OMT quick_magnitude, unlike attachment's explicit sqrt. +- Constructor/helper bindings point to HIROPE→rope01.ASE/jimycarl.png and the + owned cursor's retainedsprites.omt8. Cursor constructor4453B0 includes misleading + shadow debug strings; full draw/size/material consumers and helper retention + remain gates before an exact resource exporter/live visuals. + +Retained REA replies, export bundles and closed snapshots: + +| Artifact / procedure | REA Evidence | +| --- | --- | +|grappler-ray/rea/01.json47C210|ev_ff5aab3bdc275e6626753743a3567a556f698209ad9f65689cf49a4b5f56107d| +|grappler-ray/rea/02.json469A10|ev_03ea52bd4de36f296429073b5478032e7e55f7dc64c8545de8151bb893dd3542| +|grappler-motion/rea-base/00.json43AA40|ev_4f2a6aa666451db831efd46f5c587573e22d8072315626b8bc2f844f9c6f0cae| +|grappler-motion/rea-base/01.json47B4B0|ev_d45e078c585d3773494c0e0dfb1696178dd0b8ce8b696caf133892ff070e552e| +|grappler-resources/rea-constructors/00.json41EEB0|ev_307511ff899b91988b77796923fdfc31fa0f1bda5549f13b34c775fdc4917591| +|grappler-resources/rea-constructors/01.json4453B0|ev_423e61df2143a9dd441abffb09540b8c4ce401a0a05774d59221db623c2a7007| +|grappler-resources/rea-constructors/02.json445540|ev_76d17159215638e5e200985b3b83fa917c484805543a80a6b0ec2b86d466a488| +|grappler-resources/rea-constructors/03.json41F030|ev_2c7479a578411c7248c48387125c005db3241e79a3cb91254f1c81bff267957f| + +All artifact paths are under artifacts/. The unrecognized475CD0 pseudocode +request has a retained provider error; raw vtable/code supplies that leaf's +evidence. Prior unrecognized429D00/426A70 calls were not repeated. No provider +configuration changed. Source disassembly supplements successful recognized +helpers; no whole-function pseudocode success is attributed to missing entries. + +Next: selected polygon/material context and exact original attached constraint / +collision callback42A660; helper model/cursor draw+reset/cleanup and shared follow +camera ownership. Then boundedVR08 integration with simultaneous jump/fire, +reattach, control loss, menu, noclip and RETURN tests. No nearest-hook/direct-pull +substitute, invented launch impulse, generic helper persistence or original/native +Windows gameplay claim is enabled by this checkpoint. diff --git a/docs/gameplay/grappler.md b/docs/gameplay/grappler.md index 8d7e3e1..c5c1240 100644 --- a/docs/gameplay/grappler.md +++ b/docs/gameplay/grappler.md @@ -1,5 +1,8 @@ # Grappler source contract and integration gate +Continuation: [scalar implementation and30 copied-original cases](grappler-component.md). +The component remains isolated; live ray/body/camera/helper gates below still apply. + 2026-11-03. Item7/raw7, using the supplied target6 decompiler bodies as leads, then independently reading the hashed EXE instructions. No friend gameplay code imported. Static recovery and twelve Python source/projection tests only: no live diff --git a/docs/orbit-camera.md b/docs/orbit-camera.md index c634f27..e16af6c 100644 --- a/docs/orbit-camera.md +++ b/docs/orbit-camera.md @@ -4,6 +4,11 @@ Follow-up: the user clarified that the remaining issue was inverted Left/Right input; Up/Down was correct. Orbit Left/A now increases azimuth, Right/D decreases it, matching the corrected view. Elevation, projection and gameplay controls are unchanged. This is a two-line modern input mapping correction. +Both executables republished from clean70cba65 using the unchanged verified +packaged assets. Standalone native Linux GTX1070/private Xvfb input/resize smoke +passes with enabled Vulkan validation and zero errors; evidence is +artifacts/orbit-camera/horizontal-{build-linux.log,build-windows.log,native.log}. +Native Windows runtime testing remains pending. 2026-11-03. User reports the world flips when using orbit inspection. This is a modern camera bug; no new original-binary interpretation is needed. diff --git a/docs/progress.md b/docs/progress.md index d0dd6b6..154b3b0 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -1,5 +1,22 @@ # Progress — 2026-11-03 +## Grappler scalar checkpoint + +Implemented isolated GrapplerMotion attachment length/first-scale, held/fast reel, +damping and jump/fire detach predicates. Thirty copied-original Wine32 scalar +observations match5 managed groups;14 Python guards/projections, existing25 +movement/15 gadget groups and main .NET10 build pass. Source/log/generator/binary +hashes and source offsets are committed with the fixture. No live mode7, ray, +attached body, rope/cursor rendering or camera is enabled. Scope and retained +REA findings: [grappler-component.md](gameplay/grappler-component.md). + +Current playable Linux/Windows packages identify clean70cba65, including the +user-clarified orbit Left/Right correction; native Linux input/resize validation +passes. Grappler component source is a later local checkpoint, not a new gameplay +package claim. All investigator ownership returned. Next: selected material ray +context, original attached collision composition, helper rendering/lifetime and +shared camera, then explicit boundedVR08/control-loss/RETURN integration. + ## Orbit horizontal input follow-up and Grappler continuation User clarified the remaining orbit issue is Left/Right control inversion, with diff --git a/docs/reverse-engineering.md b/docs/reverse-engineering.md index a0641eb..76e480b 100644 --- a/docs/reverse-engineering.md +++ b/docs/reverse-engineering.md @@ -5,6 +5,12 @@ offsets, virtual addresses, API symbols or observed behavior. Decompiled output evidence, not original source. Original gameplay has not yet been observed successfully; isolated original DLL probes and modern runtime checks are recorded separately. +- `gameplay/grappler-component.md`:30 copied-original attachment/reel/damping + observations, isolated managed component and retained ray/body/resource REA + evidence. Cursor rejection differs from attach acceptance, and input swing + short-circuit does not suppress ordinary Jimmy frame publication. Live gates + remain explicit. + - `gameplay/rocketship-live.md`, `rocketship-body.md`, `rocketship-motion-camera.md` and `rocketship-lifecycle.md`: owned/reused3ROC, body flags/callbacks, registry input order, source Euler/maneuvers/shared-eye camera, rider/Goddard/fire/audio diff --git a/docs/tasks.md b/docs/tasks.md index 9716221..6ce688e 100644 --- a/docs/tasks.md +++ b/docs/tasks.md @@ -48,7 +48,9 @@ compile, runtime and original-fidelity verification are separate. - [x] User-clarified orbit Left/Right inversion: reverse horizontal azimuth mapping while preserving correct Up/Down and gameplay controls. -- [ ] Grappler next: integrate retained REA/source findings from +- [x] Grappler isolated attachment/reel/damping component:30 copied-original + observations,5 managed/14 Python checks plus25 movement/15 gadget groups pass. +- [ ] Grappler next: complete retained REA/source findings from artifacts/grappler-{ray,motion,resources}/, close body/camera/helper contracts and compare original components before enabling boundedVR08. Investigators reached usage limits; all file ownership returned to primary. @@ -90,7 +92,8 @@ compile, runtime and original-fidelity verification are separate. - [ ] Close Grappler ray/material context, attached dispatcher/camera/Euler and helper lifetime before live mode7. No substitute hook/pull behavior. -No live Rocketship/Grappler or new package claim; d6ca417 remains playable baseline. +Historical component-only claims are superseded for liveVR02 Rocketship. +Grappler scalar checkpoint is gameplay/grappler-component.md; it remains isolated. **Supplied friend's decomp assessment completed2026-11-03.** See [assessment](reviews/jn-engine-survey.md), independent gameplay/capture @@ -149,7 +152,7 @@ the resume backlog, not prerequisites imposed on this user-directed gadget work. 539 originals verify after packaging. Native Windows comparison remains open. - [x] Save Scooter separate actor/mount/vehicle and original asset contracts; wheel body/support lifecycle remains a gate before faithful live integration. -- [ ] Rocketship, Scooter, Remote and Grappler; full enemy AI and +- [ ] Rocketship other-level/special consumers, Scooter, Remote and live Grappler; full enemy AI and original/native Windows comparison. Retain collision/camera/retained-helper gates. Details: [Baseball continuation](gameplay/baseball-implementation.md). Investigators diff --git a/scripts/test.sh b/scripts/test.sh index 4e2521a..26a5576 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -21,6 +21,7 @@ dotnet run --project tests/GamePort.BaseballTests dotnet run --project tests/GamePort.BaseballVisualTests dotnet run --project tests/GamePort.RocketFlightTests dotnet run --project tests/GamePort.RocketshipTests +dotnet run --project tests/GamePort.GrapplerTests dotnet run --project tests/GamePort.HeadingTests dotnet run --project tests/GamePort.BlendTests dotnet run --project tests/GamePort.CameraRayTests diff --git a/src/GamePort/Game/GrapplerMotion.cs b/src/GamePort/Game/GrapplerMotion.cs new file mode 100644 index 0000000..79419ef --- /dev/null +++ b/src/GamePort/Game/GrapplerMotion.cs @@ -0,0 +1,64 @@ +using System.Numerics; + +namespace GamePort.Game; + +public readonly record struct GrapplerAttachment(float Length,float InitialLength,float? RopeScaleZ, + float FastReelTarget,Vector3 Velocity); +public readonly record struct GrapplerSwing(float X,float Z,float Elapsed); + +/// Isolated426BE8/426DAC/429DC9/42A077 scalar contracts. Does not +/// perform ray queries, body constraint, camera/visual ownership or live equip. +public static class GrapplerMotion +{ + public static GrapplerAttachment Attach(Vector3 root,Vector3 anchor,Vector3 velocity,float initialLength=0) + { + Finite(root);Finite(anchor);Finite(velocity);Finite(initialLength); + double x=(double)anchor.X-root.X,y=(double)anchor.Y-root.Y,z=(double)anchor.Z-root.Z; + float length=(float)(Math.Sqrt(x*x+y*y+z*z)-100); + return new(length,initialLength==0?length:initialLength, + initialLength==0?(float)((double)length*.0016666667070239782f):null, + (float)((double)anchor.Y-root.Y-200),velocity with{Y=100}); + } + + public static float HeldReel(float length,float seconds) + { + Finite(length);Time(seconds); + return length>250?(float)(length-(double)seconds*250):length; + } + + public static float FastReel(float length,float target,float seconds) + { + Finite(length);Finite(target);Time(seconds); + return target=.2) + { + float gain=length<350?.95f:.98f; + x=(float)(Math.Clamp(x,-50,50)*(double)gain); + z=Math.Clamp(z,-50,50)*gain; + time-=.2f; + } + return new(x,(float)z,time); + } + + public static bool JumpDetaches(bool jumpHeld,bool fireHeld,bool attached)=>jumpHeld&&!fireHeld&&attached; + + private static void Time(float value) + { + if(!float.IsFinite(value)||value<0||value>=1)throw new ArgumentOutOfRangeException(nameof(value)); + } + private static void Finite(float value) + { + if(!float.IsFinite(value))throw new ArgumentOutOfRangeException(nameof(value)); + } + private static void Finite(Vector3 value){Finite(value.X);Finite(value.Y);Finite(value.Z);} +} diff --git a/tests/GamePort.GrapplerTests/GamePort.GrapplerTests.csproj b/tests/GamePort.GrapplerTests/GamePort.GrapplerTests.csproj new file mode 100644 index 0000000..1b502cf --- /dev/null +++ b/tests/GamePort.GrapplerTests/GamePort.GrapplerTests.csproj @@ -0,0 +1,9 @@ + + Exenet10.0 + enableenablefalse + + + + + + diff --git a/tests/GamePort.GrapplerTests/Program.cs b/tests/GamePort.GrapplerTests/Program.cs new file mode 100644 index 0000000..74ae50d --- /dev/null +++ b/tests/GamePort.GrapplerTests/Program.cs @@ -0,0 +1,59 @@ +using System.Numerics; +using System.Text.Json; +using GamePort.Game; + +using var document=JsonDocument.Parse(File.ReadAllText(Path.Combine(AppContext.BaseDirectory,"original-scalar-reference.json"))); +var cases=document.RootElement.GetProperty("cases").EnumerateArray().ToArray(); +Check(cases.Length==30,"thirty copied-original observations"); +foreach(var c in cases) +{ + var p=c.GetProperty("input").EnumerateArray().Select(x=>x.GetSingle()).ToArray(); + var observed=c.GetProperty("observed").EnumerateArray().Select(x=>x.GetSingle()).ToArray(); + var name=c.GetProperty("kind").GetString()+"/"+c.GetProperty("name").GetString(); + switch(c.GetProperty("kind").GetString()) + { + case "attach": + var a=GrapplerMotion.Attach(new(p[0],p[1],p[2]),new(p[3],p[4],p[5]),new(11,-222,33),p[6]); + Near(a.Length,observed[0],name+" length");Near(a.InitialLength,observed[1],name+" first length"); + Check(a.RopeScaleZ.HasValue==(observed[3]==1),name+" scale write ownership"); + if(a.RopeScaleZ is{} scale)Near(scale,observed[2],name+" scale"); + break; + case "held":Near(GrapplerMotion.HeldReel(p[0],p[2]),observed[0],name);break; + case "fast":Near(GrapplerMotion.FastReel(p[0],p[1],p[2]),observed[0],name);break; + case "swing": + var s=GrapplerMotion.Swing(new(p[0],p[1],p[2]),p[3],p[4],p[5],p[6]); + Near(s.X,observed[0],name+" X");Near(s.Z,observed[1],name+" Z");Near(s.Elapsed,observed[2],name+" elapsed");break; + default:throw new Exception("Unknown native reference kind"); + } +} +Console.WriteLine("PASS all30 copied-original attachment/reel/damping scalar observations"); + +var first=GrapplerMotion.Attach(Vector3.Zero,new(0,300,400),new(10,-200,20)); +Check(first.Velocity==new Vector3(10,100,20)&&first.FastReelTarget==100,"source attachment velocity/reel target"); +var second=GrapplerMotion.Attach(Vector3.Zero,new(0,600,800),Vector3.Zero,first.InitialLength); +Check(second.InitialLength==400&&second.Length==900&&second.RopeScaleZ==null,"reattach retains first rope length/scale"); +Console.WriteLine("PASS first-length retention and independent velocity/scalar publication"); + +Check(GrapplerMotion.HeldReel(251,.1f)==226&&GrapplerMotion.HeldReel(250,.1f)==250,"strict held-reel gate without final250 clamp"); +Check(GrapplerMotion.FastReel(251,250,.1f)==156&&GrapplerMotion.FastReel(250,250,.1f)==250,"strict fast-reel target without final clamp"); +var shortRope=GrapplerMotion.Swing(new(100,-100,.2f),0,0,0,349); +var longRope=GrapplerMotion.Swing(new(100,-100,.2f),0,0,0,350); +Check(shortRope.X==47.5f&&longRope.X==49,"350 damping boundary after50 clamp"); +var tick=GrapplerMotion.Swing(new(50,50,0),.6f,0,0,400); +Near(tick.X,49,"one damping per callback");Near(tick.Elapsed,.4f,"remainder retained"); +Console.WriteLine("PASS strict overshoot, clamp/damping threshold and one-step timing"); + +Check(GrapplerMotion.JumpDetaches(true,false,true),"jump detaches"); +Check(!GrapplerMotion.JumpDetaches(true,true,true)&&!GrapplerMotion.JumpDetaches(false,false,true) + &&!GrapplerMotion.JumpDetaches(true,false,false),"independent fire/jump/attached predicates"); +Console.WriteLine("PASS simultaneous fire prevents jump detach"); + +Reject(()=>GrapplerMotion.HeldReel(300,-.1f));Reject(()=>GrapplerMotion.FastReel(300,0,float.NaN)); +Reject(()=>GrapplerMotion.Attach(new(float.PositiveInfinity,0,0),Vector3.Zero,Vector3.Zero)); +Reject(()=>GrapplerMotion.Swing(new(0,0,float.NaN),.1f,0,0,400)); +Console.WriteLine("PASS nonfinite and unsupported timestep boundaries"); +Console.WriteLine("Grappler:5 scalar groups; ray/body/camera/lifetime and live VR08 integration remain separate gates."); + +static void Check(bool ok,string message){if(!ok)throw new Exception(message);} +static void Near(float actual,float expected,string message)=>Check(float.IsFinite(actual)&&MathF.Abs(actual-expected)<.0002f,$"{message}: {actual} != {expected}"); +static void Reject(Action action){try{action();throw new Exception("Invalid scalar state accepted");}catch(ArgumentOutOfRangeException){}} diff --git a/tests/GamePort.GrapplerTests/original-scalar-reference.json b/tests/GamePort.GrapplerTests/original-scalar-reference.json new file mode 100644 index 0000000..1440f7f --- /dev/null +++ b/tests/GamePort.GrapplerTests/original-scalar-reference.json @@ -0,0 +1,515 @@ +{ + "source_sha256": "f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8", + "ranges": [ + { + "kind": "attach", + "va": "0x426be8", + "end_va": "0x426c70", + "file_offset": "0x26be8", + "sha256": "afefa8d85ac6fb17d71ad2841570e88819b4159e911f037cd5e1f5edab127a7b" + }, + { + "kind": "held", + "va": "0x426dac", + "end_va": "0x426dd5", + "file_offset": "0x26dac", + "sha256": "b59ca8ba618e4ae7b5486e850ef97b353bc12254c03274bf41159fa70e5df4c5" + }, + { + "kind": "fast", + "va": "0x429dc9", + "end_va": "0x429df5", + "file_offset": "0x29dc9", + "sha256": "51e8557c6f1183ba5bb7d125ad48aba9cdcae3698ef93308e47e0cf4e83ac3aa" + }, + { + "kind": "swing", + "va": "0x42a077", + "end_va": "0x42a1a2", + "file_offset": "0x2a077", + "sha256": "5599448797384fa4c5be142d41e1592d0e71db9ecafe7a235d18636033699415" + } + ], + "scope": "Isolated scalar prefixes/suffixes; no ray, body, camera, renderer or original gameplay execution", + "generator_sha256": "c51cc1ecefaf7a90e69a40624fd0e8cd7e01500359c4e67aee6213bb36f4a810", + "executable_sha256": "6168b4ed3e65c094a9d28a79a9a5e2f13b499e487d631081b57c708569ad2b88", + "log_sha256": "83814ffeb801e329126a00677f680d159dc2ab44e540843571233004f8565db5", + "cases": [ + { + "kind": "attach", + "name": "first", + "input": [ + 0.0, + 0.0, + 0.0, + 0.0, + 300.0, + 400.0, + 0.0 + ], + "observed": [ + 400.0, + 400.0, + 0.666666687, + 1.0 + ] + }, + { + "kind": "attach", + "name": "retained", + "input": [ + 0.0, + 0.0, + 0.0, + 0.0, + 600.0, + 800.0, + 400.0 + ], + "observed": [ + 900.0, + 400.0, + 12345.0, + 0.0 + ] + }, + { + "kind": "attach", + "name": "fraction", + "input": [ + 1.25, + -30.75, + 48.125, + 634.625, + 413.75, + -95.125, + 0.0 + ], + "observed": [ + 686.933716, + 686.933716, + 1.14488959, + 1.0 + ] + }, + { + "kind": "attach", + "name": "short", + "input": [ + 0.0, + 0.0, + 0.0, + 0.0, + 50.0, + 0.0, + 0.0 + ], + "observed": [ + -50.0, + -50.0, + -0.0833333358, + 1.0 + ] + }, + { + "kind": "attach", + "name": "zero", + "input": [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "observed": [ + -100.0, + -100.0, + -0.166666672, + 1.0 + ] + }, + { + "kind": "attach", + "name": "negative", + "input": [ + -130.0, + 315.0, + -490.0, + -530.0, + -285.0, + 310.0, + 0.0 + ], + "observed": [ + 977.032959, + 977.032959, + 1.62838829, + 1.0 + ] + }, + { + "kind": "attach", + "name": "same_first", + "input": [ + 0.0, + 0.0, + 0.0, + 0.0, + 300.0, + 400.0, + 400.0 + ], + "observed": [ + 400.0, + 400.0, + 12345.0, + 0.0 + ] + }, + { + "kind": "attach", + "name": "negative_first", + "input": [ + 0.0, + 0.0, + 0.0, + 0.0, + 300.0, + 400.0, + -100.0 + ], + "observed": [ + 400.0, + -100.0, + 12345.0, + 0.0 + ] + }, + { + "kind": "held", + "name": "above", + "input": [ + 251.0, + 0.0, + 0.100000001 + ], + "observed": [ + 226.0 + ] + }, + { + "kind": "held", + "name": "equal", + "input": [ + 250.0, + 0.0, + 0.100000001 + ], + "observed": [ + 250.0 + ] + }, + { + "kind": "held", + "name": "below", + "input": [ + 249.0, + 0.0, + 0.100000001 + ], + "observed": [ + 249.0 + ] + }, + { + "kind": "held", + "name": "negative", + "input": [ + -100.0, + 0.0, + 0.100000001 + ], + "observed": [ + -100.0 + ] + }, + { + "kind": "held", + "name": "long", + "input": [ + 300.0, + 0.0, + 0.600000024 + ], + "observed": [ + 150.0 + ] + }, + { + "kind": "held", + "name": "tick", + "input": [ + 950.0, + 0.0, + 0.0166666675 + ], + "observed": [ + 945.833313 + ] + }, + { + "kind": "fast", + "name": "above", + "input": [ + 251.0, + 250.0, + 0.100000001 + ], + "observed": [ + 156.0 + ] + }, + { + "kind": "fast", + "name": "equal", + "input": [ + 250.0, + 250.0, + 0.100000001 + ], + "observed": [ + 250.0 + ] + }, + { + "kind": "fast", + "name": "below", + "input": [ + 249.0, + 250.0, + 0.100000001 + ], + "observed": [ + 249.0 + ] + }, + { + "kind": "fast", + "name": "negative_target", + "input": [ + 50.0, + -200.0, + 0.100000001 + ], + "observed": [ + -45.0 + ] + }, + { + "kind": "fast", + "name": "long", + "input": [ + 300.0, + 0.0, + 0.600000024 + ], + "observed": [ + -270.000031 + ] + }, + { + "kind": "fast", + "name": "tick", + "input": [ + 950.0, + 0.0, + 0.0166666675 + ], + "observed": [ + 934.166687 + ] + }, + { + "kind": "swing", + "name": "free", + "input": [ + 10.0, + 20.0, + 0.0, + 0.100000001, + 100.0, + -200.0, + 400.0 + ], + "observed": [ + 8.30000019, + 23.3999996, + 0.100000001 + ] + }, + { + "kind": "swing", + "name": "equal", + "input": [ + 50.0, + -50.0, + 0.0, + 0.200000003, + 0.0, + 0.0, + 400.0 + ], + "observed": [ + 49.0, + -49.0, + 0.0 + ] + }, + { + "kind": "swing", + "name": "short", + "input": [ + 100.0, + -100.0, + 0.200000003, + 0.0, + 0.0, + 0.0, + 349.0 + ], + "observed": [ + 47.5, + -47.5, + 0.0 + ] + }, + { + "kind": "swing", + "name": "long", + "input": [ + 100.0, + -100.0, + 0.200000003, + 0.0, + 0.0, + 0.0, + 350.0 + ], + "observed": [ + 49.0, + -49.0, + 0.0 + ] + }, + { + "kind": "swing", + "name": "one_damping", + "input": [ + 50.0, + 50.0, + 0.0, + 0.600000024, + 0.0, + 0.0, + 400.0 + ], + "observed": [ + 49.0, + 49.0, + 0.400000036 + ] + }, + { + "kind": "swing", + "name": "offset", + "input": [ + 60.0, + -55.0, + 0.189999998, + 0.0199999996, + 102.0, + -73.0, + 349.899994 + ], + "observed": [ + 47.5, + -47.5, + 0.00999999046 + ] + }, + { + "kind": "swing", + "name": "near_clamp", + "input": [ + 49.9999886, + -49.9999886, + 0.189999998, + 0.0199999996, + -9.99999975e-05, + 9.99999975e-05, + 400.0 + ], + "observed": [ + 48.9999886, + -48.9999886, + 0.00999999046 + ] + }, + { + "kind": "swing", + "name": "tick", + "input": [ + 4.125, + -2.75, + 0.189999998, + 0.0166666675, + 170.125, + -333.75, + 350.0 + ], + "observed": [ + 3.57011962, + -1.76828754, + 0.00666666031 + ] + }, + { + "kind": "swing", + "name": "below_time", + "input": [ + 8.0, + 9.0, + 0.189999998, + 0.00899999961, + 90.0, + -65.0, + 800.0 + ], + "observed": [ + 7.86229992, + 9.09945011, + 0.199000001 + ] + }, + { + "kind": "swing", + "name": "negative_length", + "input": [ + 5.0, + -6.0, + 0.100000001, + 0.200000003, + -200.0, + 90.0, + -5.0 + ], + "observed": [ + 11.21, + -8.60700035, + 0.100000009 + ] + } + ] +} diff --git a/tests/test_grappler_motion.py b/tests/test_grappler_motion.py new file mode 100644 index 0000000..b4dee05 --- /dev/null +++ b/tests/test_grappler_motion.py @@ -0,0 +1,38 @@ +"""Copied-original scalar observations, separate from body/visual/gameplay parity.""" +import json +from pathlib import Path +import sys +import unittest + +ROOT=Path(__file__).resolve().parents[1] +sys.path.insert(0,str(ROOT/'tools/binary')) +from grappler import attach_scalars,held_reel,fast_reel,swing_scalars +from grappler_motion import collect + + +class GrapplerScalarReferences(unittest.TestCase): + def test_hashed_scalar_ranges_and_reference_identity(self): + source=collect(ROOT.parent/'Original') + fixture=json.loads((ROOT/'tests/GamePort.GrapplerTests/original-scalar-reference.json').read_text()) + self.assertEqual(fixture['source_sha256'],source['source_sha256']) + self.assertEqual(fixture['ranges'],source['ranges']) + self.assertEqual(len(fixture['cases']),30) + self.assertEqual([r['kind'] for r in source['ranges']],['attach','held','fast','swing']) + + def test_all_thirty_native_scalar_observations(self): + fixture=json.loads((ROOT/'tests/GamePort.GrapplerTests/original-scalar-reference.json').read_text()) + for case in fixture['cases']: + with self.subTest(case['kind']+'/'+case['name']): + p=case['input'];observed=case['observed'] + if case['kind']=='attach': + a=attach_scalars(p[:3],p[3:6],initial_length=p[6]) + actual=[a.length,a.initial_length] + self.assertEqual(a.scale_z is not None,observed[3]==1) + if a.scale_z is not None:actual.append(a.scale_z) + elif case['kind']=='held':actual=[held_reel(p[0],p[2])] + elif case['kind']=='fast':actual=[fast_reel(*p)] + else:actual=swing_scalars(*p) + for a,b in zip(actual,observed):self.assertAlmostEqual(a,b,delta=.0002) + + +if __name__=='__main__':unittest.main() diff --git a/tools/binary/grappler_motion.py b/tools/binary/grappler_motion.py new file mode 100644 index 0000000..010110d --- /dev/null +++ b/tools/binary/grappler_motion.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +"""Guarded Grappler scalar spans and copied-original reference import. + +No target execution here. Probe execution uses reference_capture.py with a +generated Win32 harness and copied installation in a separate namespace. +""" +import argparse +from collections import Counter +import hashlib +import json +from pathlib import Path +import re + +from grappler import collect as source_contract +from checkpoint_script_state import find_case, read_va +from pe_inspect import PE + +RANGES=(('attach',0x426be8,0x426c70),('held',0x426dac,0x426dd5), + ('fast',0x429dc9,0x429df5),('swing',0x42a077,0x42a1a2)) + + +def collect(original): + contract=source_contract(original) + pe=PE(find_case(Path(original),'Neutron.exe')) + return dict(source_sha256=contract['sha256'],ranges=[dict(kind=kind,va=hex(start), + end_va=hex(end),file_offset=hex(pe.offset(start-pe.base)), + sha256=hashlib.sha256(read_va(pe,start,end-start)).hexdigest()) for kind,start,end in RANGES], + scope='Isolated scalar prefixes/suffixes; no ray, body, camera, renderer or original gameplay execution') + + +def reference(original,log,executable): + result=collect(original) + log=Path(log);text=log.read_text() + if 'GRAPPLER_SCALARS_COMPLETE' not in text:raise ValueError('Probe did not finish') + cases=[] + for line in text.splitlines(): + m=re.fullmatch(r'CASE (attach|held|fast|swing) (\w+) in=([^ ]+) out=([^ ]+)',line) + if not m:continue + kind,name,inputs,outputs=m.groups() + cases.append(dict(kind=kind,name=name,input=[float(x) for x in inputs.split(',')], + observed=[float(x) for x in outputs.split(',')])) + if Counter(c['kind'] for c in cases)!=dict(attach=8,held=6,fast=6,swing=10): + raise ValueError('Incomplete or duplicate scalar cases') + result.update(generator_sha256=hashlib.sha256(Path(__file__).with_name('grappler_scalar_probe.c').read_bytes()).hexdigest(), + executable_sha256=hashlib.sha256(Path(executable).read_bytes()).hexdigest(), + log_sha256=hashlib.sha256(log.read_bytes()).hexdigest(),cases=cases) + return result + + +if __name__=='__main__': + cli=argparse.ArgumentParser(description=__doc__) + cli.add_argument('original',type=Path);cli.add_argument('--log',type=Path) + cli.add_argument('--executable',type=Path);cli.add_argument('--output',type=Path) + args=cli.parse_args() + if bool(args.log)!=bool(args.executable):cli.error('--log and --executable are required together') + if args.output: + source=args.original.resolve();target=args.output.resolve() + if target.is_relative_to(source) or source.is_relative_to(target): + cli.error('Output must be separate from originals') + result=reference(args.original,args.log,args.executable) if args.log else collect(args.original) + text=json.dumps(result,indent=2)+'\n' + if args.output:args.output.parent.mkdir(parents=True,exist_ok=True);args.output.write_text(text) + else:print(text,end='') diff --git a/tools/binary/grappler_scalar_probe.c b/tools/binary/grappler_scalar_probe.c new file mode 100644 index 0000000..1087bfa --- /dev/null +++ b/tools/binary/grappler_scalar_probe.c @@ -0,0 +1,96 @@ +/* Isolated copied EXE scalar slices. No game entrypoint, ray, body or renderer. + Absolute scalar operands are relocated into the private copied image. */ +#include +#include +#include +#include +#include +#define TC __attribute__((thiscall)) +static unsigned char*mapped; +#define AT(a) (mapped+(a)-0x400000) +#define F(a) (*(float*)AT(a)) +static unsigned char object[0x1f00],hook[0x600],shape[16]; +static uintptr_t shape_table[0x40/4]; +static float scale_z;static int scale_calls; +static void require(int ok,const char*why){if(!ok){fprintf(stderr,"FAIL %s\n",why);exit(2);}} +static void TC scale(void*self,float x,float y,float z){require(self==shape&&x==1&&y==1,"shape scale arguments");scale_z=z;scale_calls++;} +static void map_source(void){ + FILE*f=fopen("Neutron.exe","rb");require(f!=NULL,"generated EXE copy");fseek(f,0,SEEK_END);long size=ftell(f);rewind(f); + require(size==1019904,"EXE size");unsigned char*d=malloc(size);require(d!=NULL,"buffer");require(fread(d,1,size,f)==(size_t)size,"read");fclose(f); + require(*(uint16_t*)d==IMAGE_DOS_SIGNATURE,"DOS");uint32_t off=*(uint32_t*)(d+0x3c); + require(off<(uint32_t)size-sizeof(IMAGE_NT_HEADERS32),"NT bounds");IMAGE_NT_HEADERS32*nt=(void*)(d+off); + require(nt->Signature==IMAGE_NT_SIGNATURE&&nt->FileHeader.Machine==IMAGE_FILE_MACHINE_I386&&nt->OptionalHeader.ImageBase==0x400000&&nt->OptionalHeader.SizeOfImage==0x299000,"PE identity"); + unsigned char*m=VirtualAlloc(NULL,0x299000,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);require(m!=NULL,"private source map");mapped=m; + IMAGE_SECTION_HEADER*s=IMAGE_FIRST_SECTION(nt);require((unsigned char*)(s+nt->FileHeader.NumberOfSections)<=d+size,"sections"); + for(unsigned i=0;iFileHeader.NumberOfSections;i++){ + require((uint64_t)s[i].PointerToRawData+s[i].SizeOfRawData<=(uint64_t)size&&(uint64_t)s[i].VirtualAddress+s[i].SizeOfRawData<=0x299000,"section bounds"); + memcpy(m+s[i].VirtualAddress,d+s[i].PointerToRawData,s[i].SizeOfRawData); + }free(d); + shape_table[0x34/4]=(uintptr_t)scale;*(void**)shape=shape_table;*(void**)(hook+0x57c)=shape;*(void**)(object+0xb0c)=hook; +} +static void relocate(uint32_t start,uint32_t end){ + const uint32_t operands[]={0x48d96c,0x48d914,0x4a3e5c,0x4f82b8,0x4f82b4,0x4a3e58,0x4f82c8,0x4a3e88, + 0x4f82bc,0x4f82c0,0x4f82c4,0x4a3e80,0x4a2ad0,0x48d400,0x4a3e78,0x49fae4,0x4a3e74,0x4a3e70,0x4a3e6c}; + for(uint32_t a=start;a+4<=end;a++){ + uint32_t value;memcpy(&value,AT(a),4); + for(unsigned i=0;i