102 lines
6.2 KiB
C#
102 lines
6.2 KiB
C#
using System.Numerics;
|
|
using System.Buffers.Binary;
|
|
using GamePort.Application;
|
|
using GamePort.Assets;
|
|
|
|
var original = Path.GetFullPath(args.Length == 1 ? args[0] : "../Original");
|
|
var executable = File.ReadAllBytes(Path.Combine(original, "Neutron.exe"));
|
|
|
|
// Guard the actual outside and tutorial layer stores, not just an expected helper value.
|
|
Bytes(0x450869, "8b3d3c9a5000c787c000000000c0da46");
|
|
Bytes(0x456bfe, "8b3d309a5000c787c000000000504347");
|
|
Bytes(0x456c44, "8b3d3c9a5000c787c000000000504347");
|
|
Require(BinaryPrimitives.ReadUInt32LittleEndian(executable.AsSpan(0x450875 - 0x400000, 4)) == BitConverter.SingleToUInt32Bits(28000),
|
|
"Outside geometry source far clip differs");
|
|
Require(SceneProjection.FarPlane("LEV1") == 28000 && SceneProjection.FarPlane("VR04") == 50000,
|
|
"Outside/tutorial must not inherit generic3200 clipping");
|
|
Console.WriteLine("PASS source outside/tutorial layer instructions and corrected far clips");
|
|
|
|
var ranges = new Dictionary<float, string[]>
|
|
{
|
|
[5000] = ["LV1A"], [10000] = ["LV1B", "LV1C", "LV4A", "LV4D", "LEV7"],
|
|
[120000] = ["LV1D", "LV1E"], [15000] = ["LV1F"], [28000] = ["LEV1"],
|
|
[3500] = ["LV2A"], [50000] = ["LV2B", "LEV2", "VR01", "VR02", "VR03", "VR04", "VR05", "VR06", "VR07", "VR08"],
|
|
[80000] = ["LV3A"], [40000] = ["LV3B", "LV3C", "LV3D", "LV3E", "LEV3"],
|
|
[7200] = ["LV4B"], [30000] = ["LV4C", "LEV4"], [16000] = ["LV5A", "LV5B"],
|
|
[12000] = ["LEV5"], [4000] = ["LV6A", "LEV6"]
|
|
};
|
|
var codes = Directory.EnumerateFiles(AssetPath.Resolve(original, "gam"))
|
|
.Where(path => path.EndsWith(".gam", StringComparison.OrdinalIgnoreCase)).Select(path => GamLevel.Load(path).Code).ToHashSet();
|
|
Require(codes.Count == 35 && ranges.Values.SelectMany(x => x).ToHashSet().SetEquals(codes), "Every supplied original level needs a clipping mapping");
|
|
foreach (var (far, levels) in ranges)
|
|
foreach (var level in levels)
|
|
{
|
|
Require(SceneProjection.FarPlane(level.ToLowerInvariant()) == far, "Case-insensitive source scene mapping differs");
|
|
var projection = SceneProjection.CreateGameplay(level, 4f / 3);
|
|
var nearClip = Vector4.Transform(new Vector4(0, 0, SceneProjection.NearPlane, 1), projection);
|
|
var farClip = Vector4.Transform(new Vector4(0, 0, far, 1), projection);
|
|
Require(MathF.Abs(nearClip.Z / nearClip.W) < .00001f && MathF.Abs(farClip.Z / farClip.W - 1) < .00001f,
|
|
"Recovered clipping must map to Vulkan0..1 depth");
|
|
}
|
|
Require(SceneProjection.FarPlane(null) == 3200 && SceneProjection.FarPlane("unknown") == 3200, "Unknown layers retain original engine default");
|
|
foreach (var aspect in new[] { 0, -1, float.NaN, float.PositiveInfinity })
|
|
{
|
|
try { SceneProjection.CreateGameplay("LEV1", aspect); throw new Exception("Invalid aspect accepted"); }
|
|
catch (ArgumentOutOfRangeException) { }
|
|
}
|
|
Console.WriteLine("PASS all35 level mappings, inherited fallback, depth endpoints and bounded aspect input");
|
|
|
|
var outside = Mesh.LoadSceneJson("artifacts/extracted/level1/scene.json");
|
|
var sourceLevel = GamLevel.Load(AssetPath.Resolve(original, "gam/level1.gam"));
|
|
var start = sourceLevel.FindStart("level1")!;
|
|
var view = Matrix4x4.CreateLookAtLeftHanded(start.CameraPosition, start.Position + new Vector3(0, 80, 0), Vector3.UnitY);
|
|
var oldMatrix = view * Matrix4x4.CreatePerspectiveFieldOfViewLeftHanded(SceneProjection.FieldOfView, 4f / 3, 20, 3200);
|
|
var newMatrix = view * SceneProjection.CreateGameplay(sourceLevel.Code, 4f / 3);
|
|
var recovered = outside.Vertices.Count(vertex =>
|
|
{
|
|
var point = new Vector4(vertex.Position, 1);
|
|
var current = Vector4.Transform(point, newMatrix);
|
|
var previous = Vector4.Transform(point, oldMatrix);
|
|
return current.W > 0 && MathF.Abs(current.X) <= current.W && MathF.Abs(current.Y) <= current.W
|
|
&& current.Z >= 0 && current.Z <= current.W && previous.Z > previous.W;
|
|
});
|
|
Require(recovered > 100, "Actual outside geometry must demonstrate the old arbitrary far-plane cut");
|
|
Console.WriteLine($"PASS actual LEV1 source view retains{recovered} vertices formerly beyond the incorrect3200 far plane");
|
|
Console.WriteLine("Projection recovery is statically verified; original-game visual comparison and per-layer/fog fidelity remain separate.");
|
|
|
|
//The modern inspector must preserve gameplay's screen directions instead of
|
|
//reflecting the original left-handed scene through a right-handed camera.
|
|
foreach(var aspect in new[]{4f/3,16f/9,21f/9})
|
|
foreach(var angle in new[]{0,MathF.PI/2,MathF.PI,MathF.PI*1.5f})
|
|
foreach(var elevation in new[]{-.7f,0,.7f})
|
|
{
|
|
var target=new Vector3(123,456,-789);
|
|
const float radius=600;
|
|
var orbit=OrbitCamera.Create(target,radius,angle,elevation,aspect);
|
|
var forward=Vector3.Normalize(target-orbit.Eye);
|
|
var right=Vector3.Normalize(Vector3.Cross(Vector3.UnitY,forward));
|
|
var up=Vector3.Cross(forward,right);
|
|
var projection=orbit.Projection;projection.M22*=-1;
|
|
Vector3 Screen(Vector3 point)
|
|
{
|
|
var clip=Vector4.Transform(new Vector4(point,1),orbit.View*projection);
|
|
Require(clip.W>0,"Orbit target lies in front of positive-Z view");
|
|
return new(clip.X/clip.W,clip.Y/clip.W,clip.Z/clip.W);
|
|
}
|
|
var center=Screen(target);var screenRight=Screen(target+right*40);var screenUp=Screen(target+up*40);
|
|
Require(MathF.Abs(center.X)<.00001f&&MathF.Abs(center.Y)<.00001f,"Orbit target stays centered");
|
|
Require(screenRight.X>center.X&&screenUp.Y<center.Y,"Orbit preserves gameplay right/up after Vulkan viewport flip");
|
|
var inView=Vector3.Transform(target,orbit.View);
|
|
Require(MathF.Abs(inView.Z-radius)<.001f,"Orbit view uses gameplay positive-Z forward");
|
|
var near=Screen(orbit.Eye+forward*.06f);var far=Screen(orbit.Eye+forward*12000);
|
|
Require(MathF.Abs(near.Z)<.003f&&MathF.Abs(far.Z-1)<.00001f,"Orbit near/far retain Vulkan0..1 depth");
|
|
}
|
|
Console.WriteLine("PASS orbit uses gameplay handedness/right/up/depth across36 camera poses and aspect ratios");
|
|
|
|
void Bytes(int address, string expected)
|
|
{
|
|
var bytes = Convert.FromHexString(expected);
|
|
Require(executable.AsSpan(address - 0x400000, bytes.Length).SequenceEqual(bytes), $"Source clip instruction differs at{address:X}");
|
|
}
|
|
static void Require(bool condition, string message) { if (!condition) throw new InvalidOperationException(message); }
|