Implement verified Grappler body camera and helpers in VR08

This commit is contained in:
UnixNight committed 2026-11-04 11:27:03 -05:00
1 parent ffea678e90
commit 43806fe862
39 files changed
+2429 -40

No files matched your search

+2 -1
View File
@@ -84,7 +84,8 @@ var allGadgetsView=menu.View(new("LV1B","STARTEXP",Vector3.Zero,0,0,true,20,0,30
Require(allGadgetsView.Lines.Length<=32 && allGadgetsView.Lines[allGadgetsView.SelectedLine]=="GIVE ALL GADGETS",
"Last player action remains visible within the widescreen overlay capacity");
menu.Key(81);Require(menu.Key(40)==DebugAction.GiveRocketship,"Player tools expose Rocketship after Give All Gadgets");
menu.Key(81); Require(menu.Selected==0,"Player navigation wraps after Rocketship");
menu.Key(81); Require(menu.Key(40)==DebugAction.GiveGrappler,"Player tools expose Grappler after Rocketship");
menu.Key(81); Require(menu.Selected==0,"Player navigation wraps after Grappler");
Console.WriteLine("PASS Give All Gadgets navigation, repeat handling and overlay bounds");
var original = Path.GetFullPath(args.Length == 1 ? args[0] : "../Original");
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><EnableDefaultCompileItems>false</EnableDefaultCompileItems></PropertyGroup>
<ItemGroup><Compile Include="Program.cs"/><Compile Include="../../src/GamePort/Assets/*.cs"/>
<Compile Include="../../src/GamePort/Game/*.cs"/>
<Compile Include="../../src/GamePort/Application/PlayerGadgetMaterial.cs"/>
<Compile Include="../../src/GamePort/Application/GrapplerVisuals.cs"/></ItemGroup>
</Project>
+180
View File
@@ -0,0 +1,180 @@
using System.Numerics;
using GamePort.Assets;
using GamePort.Game;
using GamePort.Application;
var tests=new(string,Action)[]{
("actual VR08 fire attaches after body and ordinary apply still runs",Attach),
("retained input attaches after ordinary publication",Retained),
("held reel, jump detach, loop and retained first scale",Reel),
("contact suffix uses strict60 boundary and no bounce impulse",Contact),
("actual VR08 collision delivers the attached contact callback",LiveContact),
("same body context replays stale wall, zero delta skips callback",BodyContext),
("source ground/air locals, gains, clipping and old-eye aim",Camera),
("camera transitions retain reattach look but cleanup restores defaults",CameraStates),
("control loss alone retains gadget, named Jimmy cleanup releases",Ownership),
("actual RETURN cleans selection before transition",Return),
("noclip/reset release and process scalar retention",Lifecycle),
("exact rope/swing pivot, fixed first scale and110 cursor",Visuals),
("actual aim rejection skips late primary actions",AimGate),
};
foreach(var(name,test)in tests){test();Console.WriteLine("PASS "+name);}Console.WriteLine($"{tests.Length} live Grappler groups passed.");
static void Attach()
{
using var f=new Fixture();f.Attach();
Check(f.G.Attached&&f.G.Attachments==1&&f.P.GadgetMode==7,"owned raw7");
Check(f.P.PhysicsSteps==1&&f.P.ControllerSteps==1,"both phases run once");
Check(f.P.Velocity.Y==100&&f.P.JumpState==0&&!f.G.SwingPose,"attachment impulse and next-input SWING");
int body=f.P.PhysicsSteps;f.Binding.Step(default);
Check(f.P.PhysicsSteps==body+1&&f.G.SwingPose&&f.P.Pose==PlayerPose.Swing,"ordinary body and swing pose continue");
Check(float.IsFinite(f.P.ActorRoot.Length()),"finite attached root");
}
static void Retained()
{
using var f=new Fixture();f.P.InputAfterPlayerUpdate=true;f.Attach();
Check(f.G.Attached&&f.P.PhysicsSteps==1&&f.P.ControllerSteps==1&&f.P.Velocity.Y==100,"late input keeps100 publication");
}
static void Reel()
{
using var f=new Fixture();int stops=0;var sounds=new List<int>();f.G.Sound+=(id,_)=>sounds.Add(id);f.G.LoopStopped+=()=>stops++;
f.Attach();var first=f.G.Memory.FirstLength;var scale=f.G.Memory.RopeScaleZ;var length=f.G.Memory.Length;
f.Binding.Step(new(false,false,false,false,false,Fire:true));
Check(f.G.Attached&&f.G.Memory.Length<length&&sounds.Contains(31)&&sounds.Contains(34),"attach and reel sounds/length");
f.Binding.Step(new(false,false,false,false,true));
Check(!f.G.Attached&&!f.G.SwingPose&&!f.G.LoopPlaying&&stops>0,"jump withoutfire detach");
Check(f.G.Memory.FirstLength==first&&f.G.Memory.RopeScaleZ==scale,"detach retains geometry scalar");
f.I.Inventory.SelectGadget(-1);f.I.Inventory.SelectGadget(7);
Check(f.G.Memory.FirstLength==first&&f.G.Memory.RopeScaleZ==scale,"reequip retains first scale");
f.G.StepInput(f.P.ActorRoot,new(0,f.AimYaw,0),Vector3.Zero,new(false,false,false,false,false,Fire:true),1f/60,d=>new(d,Vector3.Zero));
Check(f.G.Attached&&f.G.Memory.FirstLength==first,"reattach retains first length");
f.G.StepInput(f.P.ActorRoot,new(0,f.AimYaw,0),Vector3.Zero,new(false,false,false,false,true,Fire:true),1f/60,d=>new(d,Vector3.Zero));
Check(f.G.Attached,"simultaneous fire+jump does not detach");
}
static void Contact()
{
using var f=new Fixture();f.Attach();f.G.Memory.Swing=new(36,48,.7f);f.G.Contact();
Check(f.G.Attached&&f.G.Memory.Swing.X==0&&f.G.Memory.Swing.Z==0,"equal60 clears only");
f.G.Memory.Swing=new(60.001f,0,.7f);f.G.Contact();
Check(!f.G.Attached&&f.P.Velocity==Vector3.Zero&&f.G.Memory.Swing.Elapsed==.7f,"fast contact detaches zero velocity no impulse");
}
static void LiveContact()
{
using var f=new Fixture();f.Attach();
//Explicit root/scalar fixture: cross a large authored vertical wall, using
//the live constraint and47B4B0 path rather than calling Contact directly.
var index=Enumerable.Range(0,f.World.CollisionPolygons.Length).First(i=>
MathF.Abs(f.World.CollisionPolygons[i].Normal.Y)<.01f &&
Vector3.Cross(f.World.Vertices[f.World.Indices[3*i+1]].Position-f.World.Vertices[f.World.Indices[3*i]].Position,
f.World.Vertices[f.World.Indices[3*i+2]].Position-f.World.Vertices[f.World.Indices[3*i]].Position).Length()>200000);
var center=(f.World.Vertices[f.World.Indices[3*index]].Position+f.World.Vertices[f.World.Indices[3*index+1]].Position+
f.World.Vertices[f.World.Indices[3*index+2]].Position)/3;
var normal=f.World.CollisionPolygons[index].Normal;
f.P.ApplyAuthoredTransform(center+normal*80,f.P.Yaw);
f.G.Memory.Anchor=center-normal*80+Vector3.UnitY*116;
f.G.Memory.Length=0;f.G.Memory.Swing=new(100,0,1);f.Binding.Step(default);
Check(f.G.Contacts>0&&!f.G.Attached&&!f.G.LoopPlaying, $"live source wall callback detaches: contacts={f.G.Contacts}, attached={f.G.Attached}");
}
static void BodyContext()
{
var wall=new CameraRayPolygon(new(new(-1000,-1000,0),new(-1000,1000,0),new(1000,1000,0)),Vector3.UnitZ);
var physics=new OriginalBodyPhysics(new([wall]));
var result=physics.Step(new(new(0,75.9f,70),new(0,0,-1200),Vector3.Zero,Vector3.Zero,false,0),1f/60);
Check(result.Contact==wall,"body accepted wall");var saved=physics.LastStaticContext!;var nearest=saved.Nearest;
var root=result.Body.Position;var moved=physics.MoveAttached(root,root+Vector3.UnitZ*10,60);
Check(moved.CallbackPolygon==wall&&ReferenceEquals(saved,physics.LastStaticContext),"stale terminal wall retained");
Check(saved.Nearest==nearest,"departure adds no accepted hit");
Check(physics.MoveAttached(moved.Position,moved.Position,60).CallbackPolygon==null,"zero delta skips stale callback");
}
static void Camera()
{
var locals=GrapplerCameraLocals.Default.Equip().Attach();var eye=new Vector3(0,200,-350);
var ground=GrapplerCamera.Follow(locals,Vector3.Zero,Vector3.Zero,0,0,eye,.1f,null);
Near(ground.DesiredEye,new(0,380,-650),"ground adjusted locals");Near(ground.Look,new(0,169,80),"ground look");
Near(ground.Eye,new(0,221.6f,-374),"ground effective gains");
var air=GrapplerCamera.Follow(locals with{Gains=new(99,88,77)},Vector3.Zero,Vector3.Zero,0,1,eye,.1f,null);
Near(air.DesiredEye,new(0,400,-650),"air raw eye");Near(air.Eye,new(0,240,-386),"air fixed gains");
var clipped=GrapplerCamera.Follow(locals,Vector3.Zero,Vector3.Zero,0,0,eye,.1f,(a,b)=>new(a+(b-a)*.5f,0,0,0));
Near(clipped.DesiredEye,ground.Look+(ground.DesiredEye-ground.Look)*.375f,"clip .75 of hit from look");Check(clipped.RayGain==1.5f,"obstruction gain");
var(p,y)=OriginalHeading.Angles(ground.Look-eye);
Near(Vector3.Normalize(ground.Target-ground.Eye),RocketOrientation.Rotate(Vector3.UnitZ,new(p*.02197265625f,y*.02197265625f,0)),"aim from old eye");
var pitched=GrapplerCamera.Follow(locals,Vector3.Zero,new(30,40,15),2,1,eye,.1f,null);
Near(pitched.DesiredEye,RocketOrientation.Rotate(locals.Eye,new(0,RocketOrientation.AddAxis(40,2),15)),"air eye ignores pitch");
}
static void CameraStates()
{
var c=GrapplerCameraLocals.Default with{Gains=new(3,4,5)};Check(c.Equip().Gains==c.Gains,"equip retains gains");
c=c.Equip().Attach().Detach().Attach();Near(c.Look,new(0,130,100),"reattach retains detach look");
using var f=new Fixture();f.Attach();f.G.Release();Check(f.G.Camera==GrapplerCameraLocals.Default,"cleanup normal defaults");
}
static void Ownership()
{
using var f=new Fixture();f.Attach();var root=f.P.ActorRoot;
f.P.Step(default,false,false);Check(f.G.Attached&&f.G.Equipped&&f.P.ActorRoot!=root,"controlfalse still body, no generic release");
f.D.ReleasePlayerGadget();Check(!f.G.Attached&&!f.G.Equipped&&f.P.GadgetMode==-1,"namedJimmy selected cleanup");
f.I.Inventory.SelectGadget(7);f.D.Trigger("gr");Check(!f.G.Equipped,"actualVR08 intro MCA/CAM cleanup");
}
static void Return()
{
using var f=new Fixture();f.Attach();f.I.SetReturnContext("level1b.gam","STARTEXP");
var portal=GamLevel.Load("../Original/gam/VR08.gam").Entities.First(e=>e.Kind=="LOAD"&&e.Text("LevelName")=="RETURN");
LevelTransition? transition=null;f.I.Transition+=t=>{Check(!f.G.Equipped&&!f.G.Attached,"cleanup before event");transition=t;};
f.I.Update(portal.Position,60);Check(transition is{Returning:true,LevelFile:"level1b.gam"},"actual RETURN");
}
static void Lifecycle()
{
var memory=new GrapplerMemory();using(var f=new Fixture(memory)){f.Attach();f.P.SetNoclip(true);Check(!f.G.Equipped&&f.I.Inventory.SelectedGadget==-1,"noclip safety release");}
var first=memory.FirstLength;Check(first>0,"process scalar set");
using var next=new Fixture(memory);Check(next.G.Memory.FirstLength==first&&!next.G.Attached,"retained scalar fresh scene helper");
next.P.Reset();Check(memory.FirstLength==0&&next.P.GadgetMode==-1,"debug reset clears memory");
}
static void Visuals()
{
using var f=new Fixture();var visuals=new GrapplerVisuals(f.World,"artifacts/extracted");f.Equip();
f.G.StepInput(f.P.ActorRoot,new(0,f.AimYaw,0),Vector3.Zero,default,1f/60,d=>new(d,Vector3.Zero));
visuals.Update(visuals.Mesh,f.G,f.P.ActorRoot,Vector3.Zero,0,f.P.Appearance,new(0,0,-100),Vector3.Zero);
var cursor=visuals.Mesh.Draws[^1];Check(cursor.Visible&&cursor.Blend==MeshBlend.Alpha,"cursor alpha");
var vertices=visuals.Mesh.Vertices;NearF(Vector3.Distance(vertices[^4].Position,vertices[^3].Position),110,"cursor width");
NearF(Vector3.Distance(vertices[^3].Position,vertices[^2].Position),110,"cursor height");
f.G.StepInput(f.P.ActorRoot,new(0,f.AimYaw,0),Vector3.Zero,new(false,false,false,false,false,Fire:true),1f/60,d=>new(d,Vector3.Zero));
f.G.StepInput(f.P.ActorRoot,new(0,f.AimYaw,0),Vector3.Zero,default,1f/60,d=>new(d,Vector3.Zero));
visuals.Update(visuals.Mesh,f.G,f.P.ActorRoot,Vector3.Zero,.1,f.P.Appearance,new(0,0,-100),Vector3.Zero);
var rope=visuals.Mesh.Draws[^3];var swing=visuals.Mesh.Draws[^2];Check(rope.Visible&&swing.Visible,"rope and sourceSWING");
var index=(int)visuals.Mesh.Indices[(int)rope.FirstIndex];var before=vertices[index].Position;
f.G.Memory.Length*=.5f;visuals.Update(visuals.Mesh,f.G,f.P.ActorRoot,Vector3.Zero,.1,f.P.Appearance,new(0,0,-100),Vector3.Zero);
Near(vertices[index].Position,before,"render uses firstscale not currentlength");
f.G.Release();visuals.Update(visuals.Mesh,f.G,f.P.ActorRoot,Vector3.Zero,.1,f.P.Appearance,new(0,0,-100),Vector3.Zero);
Check(!rope.Visible&&!swing.Visible&&!cursor.Visible,"cleanup hides all helpers");
}
static void AimGate()
{
using var f=new Fixture();f.Equip();int late=0;f.P.InputActions+=_=>late++;
var ray=new GrapplerRay(f.World,"VR08");var hit=ray.Trace(f.P.ActorRoot,new(0,f.AimYaw,0))!.Value;
var root=hit.Hit.Position-Vector3.Normalize(ray.Endpoint(f.P.ActorRoot,new(0,f.AimYaw,0))-f.P.ActorRoot)*200;
f.P.ApplyAuthoredTransform(root,f.AimYaw);f.Binding.Step(new(false,false,false,false,false,Fire:true));
Check(!f.G.Attached&&late==0&&!f.G.CursorVisible,"close surface ends active input");
}
static void Check(bool v,string m){if(!v)throw new Exception(m);}
static void Near(Vector3 a,Vector3 b,string m)=>Check(Vector3.Distance(a,b)<.004f,$"{m}: {a} != {b}");
static void NearF(float a,float b,string m)=>Check(Math.Abs(a-b)<.004f,$"{m}: {a} != {b}");
sealed class Fixture:IDisposable
{
public Mesh World{get;}=Mesh.LoadSceneJson("artifacts/extracted/VR08/scene.json");
public SceneDirector D{get;}public SceneInteractions I{get;}public LabSimulation P{get;}public PlayerSceneBinding Binding{get;}
public GrapplerGadget G=>P.Grappler!;public float AimYaw{get;}
public Fixture(GrapplerMemory? memory=null)
{
var level=GamLevel.Load("../Original/gam/VR08.gam");var save=OriginalSave.Load("../Original/NewGame.tsk");var tasks=new TaskStates(save.Tasks);
D=new(level,tasks,(_,_)=>0);I=new(D,tasks,save);var start=level.FindStart()!;D.Begin(start,activateStartTrigger:false);
var ray=OriginalCameraRay.FromRouteScene(World,"VR08");
P=new(new(World),new MorphAnimation("artifacts/extracted/animations/jimstop/animation.json").Base,start.Position,start.Rotation.Y,
(a,b)=>ray.Trace(a,b),(a,b)=>ray.TraceGeometry(a,b),OriginalStaticCollision.FromRouteScene(World,"VR08")){LevelCode="VR08"};
P.EnableGrappler(World,memory??new());Binding=new(D,P,I.Inventory,level.Player!.Tag!);
var aim=new GrapplerRay(World,"VR08");AimYaw=Enumerable.Range(0,360).First(y=>aim.Aim(P.ActorRoot,new(0,y,0),false,false,0,1f/60).CursorVisible);
P.ApplyAuthoredTransform(P.ActorRoot,AimYaw);
}
public void Equip(){I.Inventory.SetState(0,7,1);I.Inventory.SelectGadget(7);}
public void Attach(){Equip();Binding.Step(new(false,false,false,false,false,Fire:true));}
public void Dispose(){G.Release();Binding.Dispose();}
}
@@ -0,0 +1,554 @@
{
"scope": "Copied original components, synthetic bodies/grid; Wine32 exit0; not whole-original gameplay.",
"source": "f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8",
"files": {
"tools/binary/grappler_body.py": "e57517dec4ef1e5404958a3a4c4243fa8bc7c2f8144dbd7161947a7ae651bcb9",
"artifacts/grappler-body-live/grappler_body_probe.c": "ee3a23390730099f9a0962b274d674d52bc127ed6e84296c9e8f97f51c6129b8",
"artifacts/grappler-body-live/probe/wine.log": "3e938a33ffc90614ec9edded6ffab9ff719d0602266e803ea9b7485014f81ec0"
},
"cases": [
{
"kind": "CASE",
"name": "body_wall_and_floor",
"observed": {
"root": "0,75.9000015,60",
"lastWall": "1",
"face": "70",
"edge": "60",
"hit": "0,75.9000015,0",
"callback370": "0",
"callback374": "1",
"unchanged": "0",
"support": "1"
}
},
{
"kind": "CASE",
"name": "support_preserves_sphere",
"observed": {
"root": "0,75.9000015,60",
"lastWall": "1",
"face": "70",
"edge": "60",
"hit": "0,75.9000015,0",
"callback370": "0",
"callback374": "0",
"unchanged": "1",
"support": "1"
}
},
{
"kind": "CASE",
"name": "ray_preserves_sphere",
"observed": {
"root": "0,75.9000015,60",
"lastWall": "1",
"face": "70",
"edge": "60",
"hit": "0,75.9000015,0",
"callback370": "0",
"callback374": "0",
"unchanged": "1",
"support": "1"
}
},
{
"kind": "CASE",
"name": "attached_depart_replays_wall",
"observed": {
"root": "0,75.9000015,70",
"lastWall": "1",
"face": "70",
"edge": "60",
"hit": "0,75.9000015,0",
"callback370": "0",
"callback374": "1",
"unchanged": "1",
"support": "1"
}
},
{
"kind": "CASE",
"name": "zero_delta_skips_replay",
"observed": {
"root": "0,75.9000015,70",
"lastWall": "1",
"face": "70",
"edge": "60",
"hit": "0,75.9000015,0",
"callback370": "0",
"callback374": "0",
"unchanged": "1",
"support": "1"
}
},
{
"kind": "CASE",
"name": "below_threshold_370",
"observed": {
"root": "0,75.9000015,70",
"lastWall": "1",
"face": "70",
"edge": "60",
"hit": "0,75.9000015,0",
"callback370": "1",
"callback374": "0",
"unchanged": "1",
"support": "1"
}
},
{
"kind": "CASE",
"name": "equal_threshold_370",
"observed": {
"root": "0,75.9000015,70",
"lastWall": "1",
"face": "70",
"edge": "60",
"hit": "0,75.9000015,0",
"callback370": "1",
"callback374": "0",
"unchanged": "1",
"support": "1"
}
},
{
"kind": "CASE",
"name": "above_threshold_374",
"observed": {
"root": "0,75.9000015,70",
"lastWall": "1",
"face": "70",
"edge": "60",
"hit": "0,75.9000015,0",
"callback370": "0",
"callback374": "1",
"unchanged": "1",
"support": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "0",
"grounded": "0",
"mature": "0",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "0",
"grounded": "0",
"mature": "0",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "0",
"grounded": "0",
"mature": "1",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "0",
"grounded": "0",
"mature": "1",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "0",
"grounded": "1",
"mature": "0",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "0",
"grounded": "1",
"mature": "0",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "0",
"grounded": "1",
"mature": "1",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "0",
"grounded": "1",
"mature": "1",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "2",
"grounded": "0",
"mature": "0",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "2",
"grounded": "0",
"mature": "0",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "2",
"grounded": "0",
"mature": "1",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "2",
"grounded": "0",
"mature": "1",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "2",
"grounded": "1",
"mature": "0",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "2",
"grounded": "1",
"mature": "0",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "2",
"grounded": "1",
"mature": "1",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "2",
"grounded": "1",
"mature": "1",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "3",
"grounded": "0",
"mature": "0",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "3",
"grounded": "0",
"mature": "0",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "3",
"grounded": "0",
"mature": "1",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "3",
"grounded": "0",
"mature": "1",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "3",
"grounded": "1",
"mature": "0",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "3",
"grounded": "1",
"mature": "0",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "3",
"grounded": "1",
"mature": "1",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "3",
"grounded": "1",
"mature": "1",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "4",
"grounded": "0",
"mature": "0",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "4",
"grounded": "0",
"mature": "0",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "4",
"grounded": "0",
"mature": "1",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "4",
"grounded": "0",
"mature": "1",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "4",
"grounded": "1",
"mature": "0",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "4",
"grounded": "1",
"mature": "0",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "4",
"grounded": "1",
"mature": "1",
"fast": "0",
"baseUnchanged": "1",
"detached": "0",
"latch": "0"
}
},
{
"kind": "MATERIAL",
"name": "MATERIAL",
"observed": {
"id": "4",
"grounded": "1",
"mature": "1",
"fast": "1",
"baseUnchanged": "1",
"detached": "1",
"latch": "1"
}
},
{
"kind": "CEILING",
"name": "CEILING",
"observed": {
"independentPositiveYOnly": "1"
}
}
]
}
@@ -27,5 +27,12 @@
<Compile Include="../../src/GamePort/Game/RecoveredMotion.cs"/>
<Compile Include="../../src/GamePort/Game/FixedStepClock.cs"/>
<Compile Include="../../src/GamePort/Game/OriginalBodySupport.cs"/>
<Compile Include="../../src/GamePort/Game/GrapplerGadget.cs" />
<Compile Include="../../src/GamePort/Game/GrapplerCamera.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/RocketOrientation.cs" />
<Compile Include="../../src/GamePort/Game/OriginalHeading.cs" />
</ItemGroup>
</Project>
@@ -31,5 +31,12 @@
<Compile Include="../../src/GamePort/Game/RecoveredMotion.cs"/>
<Compile Include="../../src/GamePort/Game/FixedStepClock.cs"/>
<Compile Include="../../src/GamePort/Application/PreviewCharacterPlacement.cs"/>
<Compile Include="../../src/GamePort/Game/GrapplerGadget.cs" />
<Compile Include="../../src/GamePort/Game/GrapplerCamera.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/RocketOrientation.cs" />
<Compile Include="../../src/GamePort/Game/OriginalHeading.cs" />
</ItemGroup>
</Project>
+39
View File
@@ -0,0 +1,39 @@
"""Source identity and the retained copied-original body handoff observations."""
from pathlib import Path
import json
import sys
import unittest
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'tools/binary'))
from grappler_body import collect, generate
class GrapplerBodyTests(unittest.TestCase):
def test_source_spans_and_independent_support_metadata(self):
report=collect(ROOT.parent/'Original')
self.assertEqual(len(report['handoff_ranges']),5)
self.assertEqual(report['support_sphere_references'],{'support':[],'nearest_support_query':[]})
self.assertEqual(report['sha256'],'f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8')
def test_retained_original_body_support_ray_and_attached_chain(self):
data=json.loads((ROOT/'tests/GamePort.GrapplerLiveTests/original-body-reference.json').read_text())
cases={c['name']:c['observed'] for c in data['cases'] if c['kind']=='CASE'}
self.assertEqual(len(cases),8)
for name in ('support_preserves_sphere','ray_preserves_sphere','attached_depart_replays_wall','zero_delta_skips_replay'):
self.assertEqual(cases[name]['unchanged'],'1')
self.assertEqual(cases[name]['lastWall'],'1')
self.assertEqual(cases['attached_depart_replays_wall']['callback374'],'1')
self.assertEqual(cases['zero_delta_skips_replay']['callback374'],'0')
for name in ('below_threshold_370','equal_threshold_370'):
self.assertEqual(cases[name]['callback370'],'1')
self.assertEqual(cases['above_threshold_374']['callback374'],'1')
def test_full_base_callback_is_noop_for_all_vr08_material_states(self):
cases=json.loads((ROOT/'tests/GamePort.GrapplerLiveTests/original-body-reference.json').read_text())['cases']
rows=[c['observed'] for c in cases if c['kind']=='MATERIAL']
self.assertEqual(len(rows),32)
self.assertEqual({int(c['id']) for c in rows},{0,2,3,4})
for c in rows:
self.assertEqual(c['baseUnchanged'],'1')
self.assertEqual(c['detached'],c['fast'])
self.assertEqual(c['latch'],c['fast'])
self.assertEqual([c['observed'] for c in cases if c['kind']=='CEILING'],[{'independentPositiveYOnly':'1'}])
def test_generator_rejects_original_output(self):
with self.assertRaises(ValueError):generate(ROOT.parent/'Original',ROOT.parent/'Original')
+92
View File
@@ -0,0 +1,92 @@
"""Guard original byte spans and interactions that a live adapter must preserve."""
from pathlib import Path
import sys
import unittest
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'tools/binary'))
from grappler_camera import CameraLocals, attach, cleanup, collect, desired, detach, equip, follow
class GrapplerCameraTests(unittest.TestCase):
def test_original_identity_spans_virtuals_and_constants(self):
report=collect(ROOT.parent/'Original')
self.assertEqual(len(report['spans']),11)
self.assertEqual(len(report['vtables']),7)
self.assertTrue(all(int(x['va'],16)-int(x['file_offset'],16)==0x400000
for x in report['spans']))
def test_equip_preserves_existing_gain_values(self):
camera=equip(CameraLocals(gains=(3.,4.,5.)))
self.assertEqual(camera.eye,(0.,50.,-350.))
self.assertEqual(camera.look,(0.,150.,80.))
self.assertEqual(camera.gains,(3.,4.,5.))
def test_reattach_after_detach_preserves_changed_look(self):
initial=attach(equip(CameraLocals()))
reattached=attach(detach(initial))
self.assertEqual(initial.look,(0.,150.,80.))
self.assertEqual(reattached.look,(0.,130.,100.))
self.assertEqual(reattached.eye,(0.,400.,-650.))
self.assertEqual(reattached.gains,(.8,1.,.8))
self.assertEqual(attach(CameraLocals(eye=(123.,50.,-350.))).eye[0],123.)
def test_inactive_detach_noop_but_cleanup_always_restores_default(self):
camera=equip(CameraLocals(gains=(3.,4.,5.)))
self.assertIs(detach(camera,False),camera)
self.assertEqual(cleanup(camera,False),CameraLocals())
def test_ground_normal_adjusts_locals_before_full_euler(self):
eye,look,gains=desired(equip(CameraLocals()))
self.assertEqual(eye,(0.,30.,-350.))
self.assertEqual(look,(0.,169.,80.))
self.assertEqual(gains,(1.6,1.2,1.6))
eye,look,gains=desired(attach(equip(CameraLocals())))
self.assertEqual(eye,(0.,380.,-650.))
self.assertEqual(gains,(.8,1.2,.8))
def test_air_uses_raw_locals_and_fixed_gains(self):
eye,look,gains=desired(attach(equip(CameraLocals())),movement_mode=1)
self.assertEqual(eye,(0.,400.,-650.))
self.assertEqual(look,(0.,150.,80.))
self.assertEqual(gains,(1.2,2.,1.2))
self.assertEqual(desired(CameraLocals(gains=(99.,88.,77.)),movement_mode=3)[2],gains)
def test_air_eye_flattens_pitch_but_look_uses_pitch(self):
camera=equip(CameraLocals())
base=desired(camera,movement_mode=1)
tilted=desired(camera,euler=(45.,0.,0.),movement_mode=1)
self.assertEqual(tilted[0],base[0])
self.assertNotEqual(tilted[1],base[1])
self.assertNotEqual(desired(camera,euler=(45.,0.,0.))[0],base[0])
def test_air_turn_rate_changes_eye_yaw_without_changing_look(self):
camera=equip(CameraLocals())
baseline=desired(camera,movement_mode=1)
changed=desired(camera,turn_rate=90.,movement_mode=1)
self.assertNotEqual(changed[0],baseline[0])
self.assertEqual(changed[1],baseline[1])
self.assertAlmostEqual(changed[0][0],350.,places=3)
def test_aim_uses_old_eye_even_after_interpolation(self):
result=follow(equip(CameraLocals()),(0.,100.,-100.),.1)
self.assertEqual(result['aim_vector'],(0.,69.,180.))
self.assertNotEqual(result['eye'],(0.,100.,-100.))
self.assertNotEqual(result['aim_vector'],tuple(a-b for a,b in zip(result['look'],result['eye'])))
def test_hit_is_weighted_toward_hit_and_scales_interpolation(self):
result=follow(equip(CameraLocals()),(0.,0.,0.),.5,hit=(20.,209.,-120.))
self.assertEqual(result['desired_eye'],(15.,199.,-70.))
self.assertEqual(result['ray_gain'],1.5)
self.assertAlmostEqual(result['eye'][0],18.,places=5)
self.assertAlmostEqual(result['eye'][1],179.1,places=4)
def test_follow_does_not_invent_final_clamp(self):
result=follow(equip(CameraLocals()),(0.,0.,0.),2.)
self.assertLess(result['eye'][2],result['desired_eye'][2])
def test_bubble_mode_is_not_claimed_by_grappler_projection(self):
with self.assertRaises(ValueError): desired(CameraLocals(),movement_mode=2)
if __name__=='__main__': unittest.main()
+102
View File
@@ -0,0 +1,102 @@
from pathlib import Path
import hashlib
import json
import sys
import tempfile
import unittest
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[1]
ORIGINAL = ROOT.parent/'Original'
sys.path.insert(0, str(ROOT/'tools/extractors'))
from grappler_resources import (CLIPS, CURSOR_RGBA_SHA256, JIMMY_RGBA_SHA256, SOURCES, export_grappler)
from ase import expand_mesh, read_ase
from entities import resolve_asset
from omt import FormatError
sys.path.insert(0,str(ROOT/"tools/binary"))
from pe_inspect import PE
from checkpoint_script_state import find_case,read_va
@unittest.skipUnless(ORIGINAL.exists(), 'Original assets are local integration fixtures')
class GrapplerResources(unittest.TestCase):
def test_source_final_cursor_swing_binding_roll_and_shape_scale_consumer(self):
spans=[('Neutron.exe',0x445580,96,'e2470f79238741d42a78acd678921e0810b93168fe9c53f9dc562d6596b4ae9e'),
('Neutron.exe',0x422bcc,19,'1c37f47d4c3f5235876a2330c28634645a704c28781fb7540e9f485a29d0df5f'),
('Neutron.exe',0x41f0fa,53,'0ec5e8e647578640c64290c69d6d193d2e14fbdbeb1eb424ee6b4d7305e8817b'),
('OMT2.dll',0x10005970,244,'5b3747756cf8a343b3b4007cbb9710591b9026db0661c4a60a127684eb37560a')]
for name,va,size,digest in spans:
pe=PE(find_case(ORIGINAL,name))
self.assertEqual(hashlib.sha256(read_va(pe,va,size)).hexdigest(),digest)
def test_exact_resources_and_source_sampling(self):
with tempfile.TemporaryDirectory() as directory:
output = Path(directory)/'grappler'
manifest = export_grappler(ORIGINAL, output)
self.assertEqual(manifest, json.loads((output/'grappler.json').read_text()))
self.assertEqual(manifest['sources'], SOURCES)
self.assertEqual(hashlib.sha256((output/'jimycarl.rgba').read_bytes()).hexdigest(), JIMMY_RGBA_SHA256)
self.assertEqual(hashlib.sha256((output/'canvas_8.rgba').read_bytes()).hexdigest(), CURSOR_RGBA_SHA256)
self.assertEqual((manifest['cursor']['width'], manifest['cursor']['height']), (64, 64))
for stem, _, vertices, faces, times in CLIPS:
animation = json.loads((output/stem/'animation.json').read_text())
self.assertEqual([f['time'] for f in animation['frames']], list(times))
self.assertEqual(animation['texture']['path'], '../jimycarl.rgba')
for frame in animation['frames']:
mesh = json.loads((output/stem/frame['path']).read_text())
self.assertEqual(len(mesh['vertices']), faces*3)
self.assertEqual(mesh['indices'], list(range(faces*3)))
def test_unscaled_rope_positions_and_swing_base_topology(self):
with tempfile.TemporaryDirectory() as directory:
output = Path(directory)/'grappler'
export_grappler(ORIGINAL, output)
base = read_ase(resolve_asset(ORIGINAL, 'ASE/jimstop.ASE'))['objects'][0]['samples'][0]
for stem, base_stem, _, _, _ in CLIPS:
source = read_ase(resolve_asset(ORIGINAL, f'ASE/{stem}.ASE'))
animation = json.loads((output/stem/'animation.json').read_text())
for sample, frame in zip(source['objects'][0]['samples'], animation['frames'], strict=True):
if base_stem:
sample = {**sample, 'faces': base['faces'], 'textureFaces': base['textureFaces'], 'uvs': base['uvs']}
expected = expand_mesh(sample)
actual = json.loads((output/stem/frame['path']).read_text())
self.assertEqual(actual['vertices'], [list(v) for v in expected['vertices']])
self.assertEqual(actual['uvs'], [list(v) for v in expected['uvs']])
rope = json.loads((output/'rope01/frame_0000.json').read_text())
self.assertEqual(max(v[2] for v in rope['vertices']), 600.9758)
self.assertEqual(min(v[2] for v in rope['vertices']), 0)
def test_source_defaults_keep_final_cursor_size_distinct_from_sprite_size(self):
with tempfile.TemporaryDirectory() as directory:
m = export_grappler(ORIGINAL, Path(directory)/'grappler')
self.assertEqual((m['bindings']['cursorInheritedSpriteSize'], m['bindings']['cursorWorldWidth'],
m['bindings']['cursorWorldHeight']), (150, 110, 110))
self.assertEqual(m['bindings']['cursorBlend'], [6, 7])
self.assertEqual(m['bindings']['cursorAlign'], [3, 3])
self.assertEqual((m['bindings']['ropeInitialRoll'], m['bindings']['ropeUpdateRoll']), (180, 0))
self.assertEqual(len(m['tutorial']['entities']), 16)
self.assertFalse(any(e['kind'] == '3GRA' for e in m['tutorial']['entities']))
def test_original_paths_ancestors_and_child_symlinks_rejected(self):
for output in (ORIGINAL, ORIGINAL/'generated', ORIGINAL.parent):
with self.subTest(output=output), self.assertRaises(ValueError):export_grappler(ORIGINAL, output)
with tempfile.TemporaryDirectory() as directory:
output = Path(directory)/'grappler';output.mkdir()
target = Path(directory)/'unchanged';target.write_bytes(b'unchanged')
(output/'jimycarl.rgba').symlink_to(target)
with self.assertRaises(ValueError):export_grappler(ORIGINAL, output)
self.assertEqual(target.read_bytes(), b'unchanged')
def test_bad_source_or_decoded_pixels_rejected_before_output(self):
with tempfile.TemporaryDirectory() as directory:
output = Path(directory)/'grappler'
with patch('grappler_resources.digest', return_value='0'*64), \
patch('grappler_resources.read_ase') as decoder, self.assertRaises(FormatError):
export_grappler(ORIGINAL, output)
decoder.assert_not_called();self.assertFalse(output.exists())
with patch('grappler_resources.read_png', return_value=dict(width=1,height=1,rgba=b'\0'*4)), self.assertRaises(FormatError):
export_grappler(ORIGINAL, output)
self.assertFalse(output.exists())
if __name__ == '__main__':unittest.main()