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 { [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."); 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); }