Recover Grappler aim gating and implement verified ray constraint components

This commit is contained in:
UnixNight committed 2026-11-03 22:22:45 -05:00
1 parent 0c913d15aa
commit ffea678e90
21 files changed
+1604 -16

No files matched your search

@@ -3,7 +3,15 @@
<ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><EnableDefaultCompileItems>false</EnableDefaultCompileItems></PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs"/>
<Compile Include="QueryReferences.cs"/>
<Compile Include="../../src/GamePort/Game/GrapplerMotion.cs"/>
<Compile Include="../../src/GamePort/Game/GrapplerGeometry.cs"/>
<Compile Include="../../src/GamePort/Game/GrapplerRay.cs"/>
<Compile Include="../../src/GamePort/Game/OriginalCameraRay.cs"/>
<Compile Include="../../src/GamePort/Game/OriginalBodySupport.cs"/>
<Compile Include="../../src/GamePort/Game/RocketOrientation.cs"/>
<Compile Include="../../src/GamePort/Assets/*.cs"/>
<None Include="original-scalar-reference.json" CopyToOutputDirectory="PreserveNewest"/>
<None Include="original-query-reference.json" CopyToOutputDirectory="PreserveNewest"/>
</ItemGroup>
</Project>
+2 -1
View File
@@ -52,7 +52,8 @@ Reject(()=>GrapplerMotion.HeldReel(300,-.1f));Reject(()=>GrapplerMotion.FastReel
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.");
QueryReferences.Run();
Console.WriteLine("Grappler:10 groups,72 original component observations; body composition/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}");
@@ -0,0 +1,76 @@
using System.Numerics;
using System.Text.Json;
using GamePort.Assets;
using GamePort.Game;
static class QueryReferences
{
public static void Run()
{
using var doc=JsonDocument.Parse(File.ReadAllText(Path.Combine(AppContext.BaseDirectory,"original-query-reference.json")));
var cases=doc.RootElement.GetProperty("cases").EnumerateArray().ToArray();Check(cases.Length==42,"42 query/constraint/contact cases");
foreach(var c in cases)
{
var p=c.GetProperty("input").EnumerateArray().Select(x=>x.GetSingle()).ToArray();
var o=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 "aim":
var a=GrapplerGeometry.Aim(Vector3.Zero,new(0,2400,2400),p[0]!=0?new Vector3(0,p[1],0):null,
new(p[2]!=1,p[2]!=2,p[2]!=3,(int)p[3]),p[4]!=0,p[5]!=0,p[6],p[7]);
Check(a.EndsActiveInput==(o[0]!=0)&&a.CursorVisible==(o[1]==0),name+" caller/visibility");
if(a.CursorVisible)Near(a.CursorPosition,new(o[3],o[4],o[5]),name+" cursor");
Near(a.Length,o[6],name+" length");break;
case "constraint":
var constraint=GrapplerGeometry.Constrain(new(p[0],p[1],p[2]),new(p[3],p[4],p[5]),new(p[6],p[7],0),p[8],p[9]);
Near(constraint.Offset,new(o[0],o[1],o[2]),name+" offset");
Near(constraint.DesiredRoot,new(o[3],o[4],o[5]),name+" root");break;
case "impact":
var impact=GrapplerGeometry.Contact(new(p[0],p[1],.75f));
Check(impact.Swing==new GrapplerSwing(o[0],o[1],.75f)&&impact.Detach==(o[2]!=0)
&&o[2]==o[3],name+" post-base clear/detach/latch");break;
default:throw new Exception("Unknown original query reference");
}
}
Console.WriteLine("PASS42 copied-original aim/constraint/post-base contact observations");
var blocked=GrapplerGeometry.Aim(Vector3.Zero,new(0,2400,2400),new(0,700,0),new(true,true,true,60),true,false,300,.1f);
Check(blocked.EndsActiveInput&&!blocked.CursorVisible&&blocked.Length==275,"blocked aim reels then skips later primary attachment");
var near=GrapplerGeometry.Aim(Vector3.Zero,new(0,2400,2400),new(0,449,0),new(true,true,true,0),true,false,300,.1f);
Check(near.EndsActiveInput&&near.Length==300,"close aim skips primary without blocked-material reel");
Console.WriteLine("PASS enclosing input gate distinguishes close/blocked aim from attachment helper acceptance");
CameraRayPolygon Wall(int shape,float z,int material)=>new(new(new(-100,-100,z),new(200,0,z),new(-100,100,z),shape,0),-Vector3.UnitZ,"wall","wall",material);
var query=new OriginalCameraRay([Wall(1,300,170),Wall(2,200,0)]);
var selected=query.TraceSelectedGeometry(Vector3.Zero,new(0,0,450));
Check(selected is{Polygon.MaterialId:170,Hit.ShapeId:1},"selected metadata follows first source hit, not nearer/allowed polygon");
query.Enabled=false;
Check(query.Trace(Vector3.Zero,new(0,0,450))==null&&query.TraceSelectedGeometry(Vector3.Zero,new(0,0,450))==selected,
"gameplay ray remains active when camera debug query is disabled");
Console.WriteLine("PASS first-hit material snapshot and camera-debug separation");
var world=Mesh.LoadSceneJson("artifacts/extracted/VR08/scene.json");
var level=GamLevel.Load("../Original/gam/VR08.gam");var root=level.FindStart()!.Position;var ray=new GrapplerRay(world,level.Code);
Check(ray.Endpoint(root,Vector3.Zero)==root+new Vector3(0,2400,2400),"aim uses actual root, not swing pivot+116");
int hits=0;
foreach(float yaw in new[]{0,90,180,270})
{
var rotation=new Vector3(0,yaw,0);var hit=ray.Trace(root,rotation);if(hit is not{} h)continue;
hits++;Check(h.Polygon.MaterialId is 0 or 2 or 3 or 4,"actual VR08 material context");
var aim=ray.Aim(root,rotation,true,false,0,1f/60);
Check(aim.CursorVisible||aim.EndsActiveInput,"actual ray reaches valid or close-surface gate");
}
Check(hits>0,"actual VR08 geometry produces authored-start aiming hits");
Console.WriteLine($"PASS actual VR08 root/Euler ray/filter/material integration ({hits} cardinal hits)");
Reject(()=>GrapplerGeometry.Constrain(Vector3.Zero,new(0,116,0),default,100,.1f));
Reject(()=>new GrapplerRay(world,"LV1B"));
Reject(()=>new GrapplerRay(world with{HasCollisionMaterialIds=false},"VR08"));
Console.WriteLine("PASS explicit zero-normalization and unsupported scene/profile boundaries");
}
static void Check(bool ok,string message){if(!ok)throw new Exception(message);}
static void Near(float a,float b,string name)=>Check(float.IsFinite(a)&&MathF.Abs(a-b)<.004f,$"{name}: {a} != {b}");
static void Near(Vector3 a,Vector3 b,string name){Near(a.X,b.X,name+" X");Near(a.Y,b.Y,name+" Y");Near(a.Z,b.Z,name+" Z");}
static void Reject(Action action){try{action();throw new Exception("Unsupported boundary accepted");}catch(NotSupportedException){}}
}
@@ -0,0 +1,971 @@
{
"source_sha256": "f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8",
"dll_sha256": "3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943",
"vr08_filter": {
"table": "0x4d00d0",
"slot": "0x134",
"target": "0x475cd0"
},
"ranges": [
{
"kind": "aim",
"va": "0x42a406",
"end_va": "0x42a652",
"file_offset": "0x2a406",
"sha256": "d0b7a01bce82ef7c94141f852a1886afe491953cbbf3d332382516fed58b6d79"
},
{
"kind": "constraint",
"va": "0x429ea0",
"end_va": "0x429fa4",
"file_offset": "0x29ea0",
"sha256": "ba61e38497f86c45071284b983e3709ea0ba9112b49d04295566ef8d58996097"
},
{
"kind": "impact_post_base",
"va": "0x42a69b",
"end_va": "0x42a6f1",
"file_offset": "0x2a69b",
"sha256": "14a425d42ab7cfe4c9fb754dc1c149dd0d91101a8d29ca568fbf3e5b89e1c1aa"
},
{
"kind": "input_gate",
"va": "0x426030",
"end_va": "0x4260a6",
"file_offset": "0x26030",
"sha256": "bf3bcca296c7fc5d3c7dd5e79bdd9311b5fcee7606842978346706dbdab9d1b7"
},
{
"kind": "input_return",
"va": "0x4269c3",
"end_va": "0x4269cd",
"file_offset": "0x269c3",
"sha256": "4602fb15bfda7c8828f0eb9f79612ce3fa9171720ad9b6751b2e982ead958c8a"
},
{
"kind": "primary_poll",
"va": "0x42a7a0",
"end_va": "0x42a7d6",
"file_offset": "0x2a7a0",
"sha256": "c8fa10f42eefe68a195d9980f1a57558a240cd7877bfeab567e7868c0ddf419f"
},
{
"kind": "consuming_enter",
"va": "0x46a3e0",
"end_va": "0x46a3fb",
"file_offset": "0x6a3e0",
"sha256": "3ed68398af88462b66579038c4687d79d2b00a0486babd28f8a5bdc33533a060"
},
{
"kind": "aim_return",
"va": "0x42a652",
"end_va": "0x42a660",
"file_offset": "0x2a652",
"sha256": "4c01c1dfa18487526b9b74e484c24ac294b19d80a8bcb403c12978c5965a99ba"
}
],
"scope": "Synthetic ray/material/cursor accessors; original DLL magnitude; constraint before body and contact after stubbed base; no game entrypoint",
"cases": [
{
"kind": "aim",
"name": "miss",
"input": [
0.0,
700.0,
0.0,
0.0,
1.0,
0.0,
300.0,
0.100000001
],
"observed": [
0.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "near",
"input": [
1.0,
449.0,
0.0,
0.0,
1.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "equal",
"input": [
1.0,
450.0,
0.0,
0.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
0.0,
0.0,
1.0,
0.0,
379.289307,
-70.7106781,
300.0
]
},
{
"kind": "aim",
"name": "far",
"input": [
1.0,
700.0,
0.0,
0.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
0.0,
0.0,
1.0,
0.0,
629.289307,
-70.7106781,
300.0
]
},
{
"kind": "aim",
"name": "material_60",
"input": [
1.0,
700.0,
0.0,
60.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "material_69",
"input": [
1.0,
700.0,
0.0,
69.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "material_70",
"input": [
1.0,
700.0,
0.0,
70.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
0.0,
0.0,
1.0,
0.0,
629.289307,
-70.7106781,
300.0
]
},
{
"kind": "aim",
"name": "material_80",
"input": [
1.0,
700.0,
0.0,
80.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "material_89",
"input": [
1.0,
700.0,
0.0,
89.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "material_90",
"input": [
1.0,
700.0,
0.0,
90.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
0.0,
0.0,
1.0,
0.0,
629.289307,
-70.7106781,
300.0
]
},
{
"kind": "aim",
"name": "material_210",
"input": [
1.0,
700.0,
0.0,
210.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "material_219",
"input": [
1.0,
700.0,
0.0,
219.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "material_220",
"input": [
1.0,
700.0,
0.0,
220.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
0.0,
0.0,
1.0,
0.0,
629.289307,
-70.7106781,
300.0
]
},
{
"kind": "aim",
"name": "material_-1",
"input": [
1.0,
700.0,
0.0,
-1.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "material_170",
"input": [
1.0,
700.0,
0.0,
170.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "no_polygon",
"input": [
1.0,
700.0,
1.0,
60.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
0.0,
0.0,
1.0,
0.0,
629.289307,
-70.7106781,
300.0
]
},
{
"kind": "aim",
"name": "no_material",
"input": [
1.0,
700.0,
2.0,
0.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "no_definition",
"input": [
1.0,
700.0,
3.0,
60.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
0.0,
0.0,
1.0,
0.0,
629.289307,
-70.7106781,
300.0
]
},
{
"kind": "aim",
"name": "blocked_fire",
"input": [
1.0,
700.0,
0.0,
60.0,
1.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
275.0
]
},
{
"kind": "aim",
"name": "blocked_enter",
"input": [
1.0,
700.0,
0.0,
60.0,
0.0,
1.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
275.0
]
},
{
"kind": "aim",
"name": "blocked_idle",
"input": [
1.0,
700.0,
0.0,
60.0,
0.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "aim",
"name": "blocked_equal",
"input": [
1.0,
700.0,
0.0,
60.0,
1.0,
0.0,
250.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
250.0
]
},
{
"kind": "aim",
"name": "near_fire",
"input": [
1.0,
449.0,
0.0,
60.0,
1.0,
0.0,
300.0,
0.100000001
],
"observed": [
1.0,
1.0,
1.0,
12345.0,
12345.0,
12345.0,
300.0
]
},
{
"kind": "constraint",
"name": "vertical",
"input": [
0.0,
0.0,
0.0,
0.0,
1000.0,
0.0,
0.0,
0.0,
600.0,
0.0166666675
],
"observed": [
0.0,
600.0,
0.0,
0.0,
284.0,
0.0
]
},
{
"kind": "constraint",
"name": "diagonal",
"input": [
0.0,
0.0,
0.0,
300.0,
800.0,
400.0,
0.0,
0.0,
600.0,
0.0166666675
],
"observed": [
212.447495,
484.38028,
283.263306,
87.5525055,
199.61972,
116.736694
]
},
{
"kind": "constraint",
"name": "perturbed",
"input": [
125.0,
320.0,
-210.0,
-150.0,
1200.0,
450.0,
12.0,
-23.0,
700.0,
0.0166666675
],
"observed": [
-181.472336,
515.408447,
437.490021,
31.4723358,
568.591553,
12.5099792
]
},
{
"kind": "constraint",
"name": "long_tick",
"input": [
0.0,
0.0,
0.0,
300.0,
800.0,
400.0,
50.0,
-50.0,
350.0,
0.600000024
],
"observed": [
285.845215,
162.931763,
-119.102173,
14.1547852,
521.068237,
519.102173
]
},
{
"kind": "constraint",
"name": "short",
"input": [
-40.0,
300.0,
15.0,
280.0,
500.0,
-120.0,
-20.0,
35.0,
125.0,
0.100000001
],
"observed": [
118.232071,
38.1980553,
-13.6421614,
161.767929,
345.801941,
-106.357841
]
},
{
"kind": "constraint",
"name": "negative",
"input": [
0.0,
0.0,
0.0,
300.0,
800.0,
400.0,
10.0,
20.0,
-50.0,
0.100000001
],
"observed": [
-18.5824604,
-38.5163727,
-25.9028244,
318.582458,
722.516357,
425.902832
]
},
{
"kind": "constraint",
"name": "fraction",
"input": [
12.125,
-37.25,
89.625,
317.875,
982.125,
-211.375,
3.25,
-1.75,
463.125,
0.0170000009
],
"observed": [
142.231491,
417.974121,
-139.67981,
175.643509,
448.150879,
-71.6951904
]
},
{
"kind": "constraint",
"name": "horizontal",
"input": [
0.0,
0.0,
0.0,
600.0,
116.0,
0.0,
0.0,
0.0,
400.0,
0.100000001
],
"observed": [
400.0,
0.0,
0.0,
200.0,
0.0,
0.0
]
},
{
"kind": "constraint",
"name": "zero_length",
"input": [
0.0,
0.0,
0.0,
300.0,
800.0,
400.0,
1.0,
2.0,
0.0,
0.100000001
],
"observed": [
0.0,
0.0,
0.0,
300.0,
684.0,
400.0
]
},
{
"kind": "constraint",
"name": "large",
"input": [
-13000.0,
900.0,
-12000.0,
14000.0,
19000.0,
18000.0,
-40.0,
20.0,
23000.0,
0.0166666675
],
"observed": [
14044.2402,
9361.43848,
15621.4834,
-44.2402344,
9522.56152,
2378.5166
]
},
{
"kind": "impact",
"name": "zero",
"input": [
0.0,
0.0
],
"observed": [
0.0,
0.0,
0.0,
0.0
]
},
{
"kind": "impact",
"name": "below",
"input": [
59.9000015,
0.0
],
"observed": [
0.0,
0.0,
0.0,
0.0
]
},
{
"kind": "impact",
"name": "equal_x",
"input": [
60.0,
0.0
],
"observed": [
0.0,
0.0,
0.0,
0.0
]
},
{
"kind": "impact",
"name": "equal_z",
"input": [
0.0,
60.0
],
"observed": [
0.0,
0.0,
0.0,
0.0
]
},
{
"kind": "impact",
"name": "pythagoras",
"input": [
36.0,
48.0
],
"observed": [
0.0,
0.0,
0.0,
0.0
]
},
{
"kind": "impact",
"name": "above",
"input": [
36.0,
48.0000992
],
"observed": [
0.0,
0.0,
1.0,
1.0
]
},
{
"kind": "impact",
"name": "diagonal",
"input": [
45.0,
45.0
],
"observed": [
0.0,
0.0,
1.0,
1.0
]
},
{
"kind": "impact",
"name": "negative",
"input": [
-60.0,
0.0
],
"observed": [
0.0,
0.0,
0.0,
0.0
]
},
{
"kind": "impact",
"name": "negative_above",
"input": [
0.0,
-60.0999985
],
"observed": [
0.0,
0.0,
1.0,
1.0
]
}
],
"generators": {
"grappler_query_probe.c": "c712653e89d506e622e77240b4fd0e3368d34c6c1ceb3f24093645fed8bf6741",
"grappler_scalar_probe.c": "c51cc1ecefaf7a90e69a40624fd0e8cd7e01500359c4e67aee6213bb36f4a810"
},
"executable_sha256": "5387d7523c6ff717e1c2f3587ec9e7adc53be63c184c664f8ac7e3ca4ba3b7ec",
"log_sha256": "9219572b31ff2b784d85aa964b876cc564d9238c3e9a67de70ba37505868b031"
}
+47
View File
@@ -0,0 +1,47 @@
"""Original source gates and retained native component observations."""
from collections import Counter
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_query import collect
class GrapplerQueryEvidence(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.source=collect(ROOT.parent/'Original')
cls.fixture=json.loads((ROOT/'tests/GamePort.GrapplerTests/original-query-reference.json').read_text())
cls.cases={(c['kind'],c['name']):c for c in cls.fixture['cases']}
def test_hashes_ranges_caller_return_and_vr08_filter(self):
for key in ('source_sha256','dll_sha256','ranges','vr08_filter'):
self.assertEqual(self.source[key],self.fixture[key])
self.assertEqual(self.source['vr08_filter']['target'],'0x475cd0')
self.assertEqual(len(self.source['ranges']),8)
self.assertEqual(Counter(c['kind'] for c in self.fixture['cases']),dict(aim=23,constraint=10,impact=9))
def test_native_close_and_blocked_paths_consume_input_with_distinct_reel_behavior(self):
close=self.cases['aim','near']['observed'];blocked=self.cases['aim','blocked_fire']['observed']
self.assertEqual(close[:3],[1,1,1]);self.assertEqual(close[-1],300)
self.assertEqual(blocked[:3],[1,1,1]);self.assertEqual(blocked[-1],275)
self.assertEqual(self.cases['aim','blocked_enter']['observed'][-1],275)
self.assertEqual(self.cases['aim','blocked_equal']['observed'][-1],250)
def test_native_selected_polygon_material_and_definition_are_distinct(self):
for name in ('no_polygon','no_definition'):
self.assertEqual(self.cases['aim',name]['observed'][:3],[0,0,1])
self.assertEqual(self.cases['aim','no_material']['observed'][:3],[1,1,1])
self.assertEqual(self.cases['aim','equal']['observed'][:3],[0,0,1])
def test_native_contact_equality_stays_attached_and_above60_detaches(self):
for name in ('zero','below','equal_x','equal_z','pythagoras','negative'):
self.assertEqual(self.cases['impact',name]['observed'],[0,0,0,0])
for name in ('above','diagonal','negative_above'):
self.assertEqual(self.cases['impact',name]['observed'],[0,0,1,1])
if __name__=='__main__':unittest.main()