92 lines
5.0 KiB
C#
92 lines
5.0 KiB
C#
using GamePort.Assets;
|
|
using GamePort.Game;
|
|
using System.Numerics;
|
|
|
|
var root = args.Length == 1 ? Path.GetFullPath(args[0])
|
|
: Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../../../../Original"));
|
|
var files = Directory.GetFiles(Path.Combine(root, "gam"), "*.gam");
|
|
Require(files.Length == 35, $"Expected all 35 original level files at {root}");
|
|
var entities = 0;
|
|
foreach (var file in files)
|
|
{
|
|
var level = GamLevel.Load(file);
|
|
entities += level.Entities.Count;
|
|
Require(level.Player is not null, $"Missing player in {file}");
|
|
Require(level.FindStart() is not null, $"Missing matching player startpoint in {file}");
|
|
}
|
|
Require(entities == 3299, "Original entity total differs");
|
|
var initial = GamLevel.Load(Path.Combine(root, "gam/level1b.gam"));
|
|
Require(initial.Code == "LV1B" && initial.Entities.Count == 129, "Wrong initial scene");
|
|
Require(initial.Player!.Position.X == 5071.93310546875f, "Original player X changed");
|
|
Require(initial.FindStart()!.CameraPosition.Y == 235.64761352539062f, "Original camera Y changed");
|
|
Require(initial.FindStart()!.Text("StartTrigger") == "LABEXP", "Initial trigger differs");
|
|
Require(initial.FindStart()!.Text("MusicDatabase") == "musicsecretlab.omt", "Initial music differs");
|
|
|
|
var sample = File.ReadAllBytes(Path.Combine(root, "gam/VR01.gam"));
|
|
foreach (var length in new[] { 0, 3, 7, 8, 30, sample.Length - 1 })
|
|
Reject(sample[..length]);
|
|
Reject([.. sample, 0]);
|
|
var corruptCount = (byte[])sample.Clone();
|
|
Array.Fill(corruptCount, (byte)0xff, 4, 4);
|
|
Reject(corruptCount);
|
|
var corruptString = (byte[])sample.Clone();
|
|
corruptString[0x22] = 100; // first property's Pascal payload length
|
|
Reject(corruptString);
|
|
Console.WriteLine($"PASS: C# decoded {files.Length} original GAM files, {entities} entities; original startup and corruption checks passed.");
|
|
|
|
var velocity = Vector3.Zero;
|
|
var impulse = new Vector3(0, RecoveredMotion.JumpImpulse, 0);
|
|
var displacement = RecoveredMotion.Integrate(ref velocity, ref impulse, Vector3.Zero, RecoveredMotion.Gravity, 0.125f);
|
|
Require(velocity.Y == 450 && displacement.Y == 56.25f && impulse == Vector3.Zero,
|
|
"Recovered jump/gravity order or impulse consumption differs");
|
|
displacement = RecoveredMotion.Integrate(ref velocity, ref impulse, Vector3.Zero, RecoveredMotion.Gravity, 0.125f);
|
|
Require(velocity.Y == 350 && displacement.Y == 43.75f, "Impulse was incorrectly repeated");
|
|
var speed = 0f;
|
|
for (var i = 0; i < 30; i++) speed = RecoveredMotion.AddSpeed(speed);
|
|
Require(speed == 600, "Original speed cap differs");
|
|
for (var i = 0; i < 30; i++) speed = RecoveredMotion.ReleaseSpeed(speed);
|
|
Require(speed == 0 && RecoveredMotion.ReleaseSpeed(-10) == 0, "Speed decay crossed zero");
|
|
var rng = new OriginalRandom(uint.MaxValue);
|
|
Require(rng.Next() == 65511 && rng.State == 4293335538u, "LCG uint32 overflow differs");
|
|
Console.WriteLine("PASS: recovered impulse/gravity integration, speed limits and wrapping RNG regression checks.");
|
|
|
|
var project = Path.GetFullPath(Path.Combine(root, "../GamePort"));
|
|
var scene = Mesh.LoadSceneJson(Path.Combine(project, "artifacts/extracted/level1b/scene.json"));
|
|
Require(scene.HasExplicitDraws && scene.Draws.Length > 0, "Missing original material draw ranges");
|
|
Require(scene.Draws.Sum(d => (long)d.IndexCount) < scene.Indices.Length,
|
|
"Null-material collision proxy geometry was incorrectly rendered");
|
|
var baseMesh = AseMesh.Load(AssetPath.Resolve(root, "ase/JIMSTOP.ASE"));
|
|
Require(baseMesh.Indices.Length == 2442, "Original Jimmy topology differs");
|
|
Require(baseMesh.Vertices.Any(v => v.Uv != Vector2.Zero), "Original base UVs missing");
|
|
var animation = new MorphAnimation(Path.Combine(project, "artifacts/extracted/animations/jimrun/animation.json"));
|
|
var a = new MeshVertex[animation.Base.Vertices.Length];
|
|
var b = new MeshVertex[a.Length];
|
|
var half = new MeshVertex[a.Length];
|
|
animation.Sample(0, a, Matrix4x4.Identity);
|
|
animation.Sample(animation.SampleInterval, b, Matrix4x4.Identity);
|
|
animation.Sample(animation.SampleInterval / 2, half, Matrix4x4.Identity);
|
|
Require(a.Where((v, i) => v.Position != b[i].Position).Any(), "Original animation samples do not change positions");
|
|
for (var i = 0; i < a.Length; i++)
|
|
{
|
|
Require(Vector3.Distance(half[i].Position, (a[i].Position + b[i].Position) / 2) < 0.0001f,
|
|
"Original morph interpolation differs");
|
|
Require(a[i].Uv == b[i].Uv && a[i].Uv == half[i].Uv, "Morph changed retained base UV");
|
|
}
|
|
var combined = animation.AppendTo(scene);
|
|
Require(combined.Indices.Length == scene.Indices.Length + 2442 && combined.Textures.Count == 34,
|
|
"Original scene/character resource merge differs");
|
|
Require(combined.Indices.All(i => i < combined.Vertices.Length), "Combined scene contains invalid index");
|
|
Console.WriteLine("PASS: null-material visibility, case-insensitive ASE, original morph interpolation/base UV, and scene/character merge.");
|
|
|
|
static void Require(bool condition, string message)
|
|
{
|
|
if (!condition) throw new Exception(message);
|
|
}
|
|
|
|
static void Reject(byte[] data)
|
|
{
|
|
try { GamLevel.Parse(data); }
|
|
catch (InvalidDataException) { return; }
|
|
throw new Exception("Malformed GAM was accepted");
|
|
}
|