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

+69
View File
@@ -0,0 +1,69 @@
using System.Numerics;
namespace GamePort.Game;
public readonly record struct GrapplerSurface(bool PolygonPresent,bool MaterialPresent,bool DefinitionPresent,int MaterialId)
{
public bool BlocksCursor=>PolygonPresent&&(!MaterialPresent||DefinitionPresent&&
(MaterialId is >=60 and <=69 or >=80 and <=89 or >=210 and <=219 or -1 or 170));
}
public readonly record struct GrapplerAim(bool CursorVisible,bool EndsActiveInput,Vector3 CursorPosition,float Length);
public readonly record struct GrapplerConstraint(Vector3 Offset,Vector3 DesiredRoot);
public readonly record struct GrapplerContact(GrapplerSwing Swing,bool Detach);
/// <summary>429D00 aim/constraint and42A69B post-base contact contracts.
/// Caller still owns registry phases, actual body callbacks, camera and helpers.</summary>
public static class GrapplerGeometry
{
public static GrapplerAim Aim(Vector3 root,Vector3 endpoint,Vector3? hit,GrapplerSurface surface,
bool fire,bool enter,float length,float seconds)
{
Finite(root);Finite(endpoint);
GrapplerMotion.Finite(length);GrapplerMotion.Time(seconds);
if(hit is not{} point)return new(false,false,default,length);
Finite(point);
double x=(double)point.X-root.X,y=(double)point.Y-root.Y,z=(double)point.Z-root.Z;
if(Math.Sqrt(x*x+y*y+z*z)<450)return new(false,true,default,length);
if(surface.BlocksCursor)
return new(false,true,default,fire||enter?GrapplerMotion.HeldReel(length,seconds):length);
var delta=endpoint-root;
double inverse=InverseMagnitude(delta);
var offset=new Vector3((float)((double)(float)(delta.X*inverse)*100),
(float)((double)(float)(delta.Y*inverse)*100),(float)(delta.Z*inverse*100));
return new(true,false,point-offset,length);
}
public static GrapplerConstraint Constrain(Vector3 root,Vector3 anchor,GrapplerSwing swing,float length,float seconds)
{
Finite(root);Finite(anchor);
Validate(swing);GrapplerMotion.Finite(length);GrapplerMotion.Time(seconds);
var pivot=root+Vector3.UnitY*116;
var delta=new Vector3((float)((float)(anchor.X-pivot.X)+(double)swing.X*seconds*30),
anchor.Y-pivot.Y,(float)(((double)anchor.Z-pivot.Z)+(double)swing.Z*seconds*30));
double inverse=InverseMagnitude(delta);
var offset=new Vector3((float)((double)(float)(delta.X*inverse)*length),
(float)((double)(float)(delta.Y*inverse)*length),(float)(delta.Z*inverse*length));
return new(offset,new(anchor.X-offset.X,(float)(anchor.Y-((double)offset.Y+116)),anchor.Z-offset.Z));
}
public static GrapplerContact Contact(GrapplerSwing swing)
{
Validate(swing);
double x=swing.X,z=swing.Z;
return new(new(0,0,swing.Elapsed),Math.Sqrt(x*x+z*z)>60);
}
private static double InverseMagnitude(Vector3 vector)
{
var magnitude=OriginalBodySupport.QuickMagnitude(vector);
if(magnitude<=0)throw new NotSupportedException("Source zero-vector normalization produces nonfinite geometry");
return 1d/magnitude;
}
private static void Finite(Vector3 vector)
{
if(!float.IsFinite(vector.X)||!float.IsFinite(vector.Y)||!float.IsFinite(vector.Z))
throw new ArgumentOutOfRangeException(nameof(vector));
}
private static void Validate(GrapplerSwing swing)
{GrapplerMotion.Finite(swing.X);GrapplerMotion.Finite(swing.Z);GrapplerMotion.Finite(swing.Elapsed);}
}
+3 -3
View File
@@ -52,13 +52,13 @@ public static class GrapplerMotion
public static bool JumpDetaches(bool jumpHeld,bool fireHeld,bool attached)=>jumpHeld&&!fireHeld&&attached;
private static void Time(float value)
internal static void Time(float value)
{
if(!float.IsFinite(value)||value<0||value>=1)throw new ArgumentOutOfRangeException(nameof(value));
}
private static void Finite(float value)
internal 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);}
internal static void Finite(Vector3 value){Finite(value.X);Finite(value.Y);Finite(value.Z);}
}
+30
View File
@@ -0,0 +1,30 @@
using System.Numerics;
using GamePort.Assets;
namespace GamePort.Game;
/// <summary>Bounded VR08 root/full-Euler ray and first-hit material snapshot.
/// Aiming's early return must gate later primary-fire attachment dispatch.</summary>
public sealed class GrapplerRay
{
private readonly OriginalCameraRay geometry;
public GrapplerRay(Mesh world,string level)
{
ArgumentNullException.ThrowIfNull(world);
if(level!="VR08")throw new NotSupportedException("Grappler ray admission currently covers VR08");
if(!world.HasCollisionMaterialIds||world.CollisionPolygons.Any(p=>p.MaterialId is not(0 or 2 or 3 or 4)))
throw new NotSupportedException("VR08 requires its verified material/definition profile");
geometry=OriginalCameraRay.FromRouteScene(world,level);
}
public Vector3 Endpoint(Vector3 root,Vector3 rotation)=>root+RocketOrientation.Rotate(new(0,2400,2400),rotation);
public CameraRaySelection? Trace(Vector3 root,Vector3 rotation)=>geometry.TraceSelectedGeometry(root,Endpoint(root,rotation));
public GrapplerAim Aim(Vector3 root,Vector3 rotation,bool fire,bool enter,float length,float seconds)
{
var endpoint=Endpoint(root,rotation);
var selection=geometry.TraceSelectedGeometry(root,endpoint);
var surface=selection is{} s?new GrapplerSurface(true,true,true,s.Polygon.MaterialId!.Value):default;
return GrapplerGeometry.Aim(root,endpoint,selection?.Hit.Position,surface,fire,enter,length,seconds);
}
}
+14 -3
View File
@@ -6,6 +6,7 @@ namespace GamePort.Game;
public readonly record struct CameraRayPolygon(SupportTriangle Triangle, Vector3 StoredNormal,
string? ShapeName = null, string? MaterialName = null, int? MaterialId = null);
public readonly record struct CameraRayResult(Vector3 Eye, float Gain, SupportHit? Hit);
public readonly record struct CameraRaySelection(SupportHit Hit, CameraRayPolygon Polygon);
/// <summary>
/// Source47C210 static camera predicate: first accepted wall-grid polygon, then
@@ -20,6 +21,7 @@ public sealed class OriginalCameraRay
public const float CellOrigin = 130; //49B1FC.
private readonly Dictionary<int, List<SupportTriangle>> walls = [];
private readonly Dictionary<int, List<SupportTriangle>> all = [];
private readonly Dictionary<(int Shape,int Polygon),CameraRayPolygon> sources = [];
public bool Enabled { get; set; } = true; // Modern camera-only debug override.
public int PolygonCount { get; }
public int WallPolygonCount { get; }
@@ -44,6 +46,7 @@ public sealed class OriginalCameraRay
RequireFinite(polygon.StoredNormal);
if (!identities.Add((triangle.ShapeId, triangle.PolygonId)))
throw new InvalidDataException("Camera query needs one source triangle per polygon; fan-triangulated polygons are unsupported");
sources.Add((triangle.ShapeId,triangle.PolygonId),polygon);
var wall = polygon.StoredNormal.Y < .7f; //4798B3; equality excluded.
var min = Vector3.Min(triangle.A, Vector3.Min(triangle.B, triangle.C));
var max = Vector3.Max(triangle.A, Vector3.Max(triangle.B, triangle.C));
@@ -59,15 +62,15 @@ public sealed class OriginalCameraRay
/// <summary>
/// Route/tutorial complete game slot134 is475CD0 (false), including VR02's
///4CDD30 table (rocketship.md), so only the proven
///4CDD30 and VR08's4D00D0 tables, so only the proven
/// NC/checkpoint gates apply. Reject other levels rather than inventing masks.
/// Prepared source metadata is required; raw render visibility is irrelevant.
/// </summary>
public static OriginalCameraRay FromRouteScene(Mesh mesh, string levelCode)
{
ArgumentNullException.ThrowIfNull(mesh);
if (levelCode is not ("LV1B" or "VR01" or "VR02" or "VR04" or "VR07" or "LEV1"))
throw new NotSupportedException("Static camera game-filter recovery covers the route and VR01");
if (levelCode is not ("LV1B" or "VR01" or "VR02" or "VR04" or "VR07" or "VR08" or "LEV1"))
throw new NotSupportedException("Static camera game-filter recovery covers only selected route/tutorial scenes");
if (mesh.Indices.Length % 3 != 0 || mesh.CollisionPolygons.Length != mesh.Indices.Length / 3)
throw new InvalidDataException("Original camera query requires source polygon metadata");
var polygons = new CameraRayPolygon[mesh.CollisionPolygons.Length];
@@ -100,6 +103,14 @@ public sealed class OriginalCameraRay
return TraceCore(start, end, twoSided, diagnostic: false);
}
/// <summary>Capture47C210's hit and selected polygon/material together.
/// This geometry query is independent of the modern camera debug toggle.</summary>
public CameraRaySelection? TraceSelectedGeometry(Vector3 start,Vector3 end,bool twoSided=false)
{
var hit=TraceGeometry(start,end,twoSided);
return hit is{} h?new(h,sources[(h.ShapeId,h.PolygonId)]):null;
}
private SupportHit? TraceCore(Vector3 start, Vector3 end, bool twoSided, bool diagnostic)
{
foreach (var grid in new[] { walls, all })