Reconstruct lab story, interactions, patrol and jet pack practice flow
This commit is contained in:
1 parent
58424120bb
commit
c929f942e1
84 files changed
+7957
-305
No files matched your search
@@ -0,0 +1,18 @@
|
||||
<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/SceneInteractions.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/SceneInventory.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/SceneDirector.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/TaskActivation.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/TaskStates.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/LabSimulation.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/JetpackBurst.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/SceneCollision.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/RecoveredMotion.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/FixedStepClock.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/OriginalBodySupport.cs"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,201 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using GamePort.Assets;
|
||||
using GamePort.Game;
|
||||
|
||||
var root = Path.GetFullPath(args.Length == 1 ? args[0] : "../Original");
|
||||
var original = OriginalSave.Load(AssetPath.Resolve(root, "NewGame.tsk"));
|
||||
var lab = GamLevel.Load(AssetPath.Resolve(root, "gam/level1b.gam"));
|
||||
var counter = 1;
|
||||
var tasks = new TaskStates(original.Tasks);
|
||||
var director = new SceneDirector(lab, tasks, (_, _) => 5);
|
||||
var interactions = new SceneInteractions(director, tasks, original, lab.Code);
|
||||
director.Begin(lab.FindStart()!);
|
||||
interactions.Reset();
|
||||
director.Skip();
|
||||
Check(tasks.Get("SCENE") == 30 && director.Controlled, "Intro cannot invent lab completion");
|
||||
var explanation = lab.Entities.Single(e => e.Tag == "teleportexplanation");
|
||||
director.Touch("JIM1", explanation.Position);
|
||||
Check(tasks.Get("SCENE") == 35 && interactions.CurrentObjective == 1, "Original explanation enables objective1/task35");
|
||||
director.Skip();
|
||||
var shrinkray = director.FindActor("shrinkray")!;
|
||||
var checkpoint = Vector3.Zero;
|
||||
var help = -1;
|
||||
var selected = -1;
|
||||
var events = new List<string>();
|
||||
interactions.CheckpointCaptured += p => { checkpoint = p; events.Add("checkpoint"); };
|
||||
tasks.Assigned += (name, state) => { if (name == "SCENE" && state == 50) events.Add("task50"); };
|
||||
interactions.PracticeRequested += page => { help = page; events.Add("help"); };
|
||||
interactions.Inventory.GadgetSelected += gadget => { selected = gadget; events.Add("gadget"); };
|
||||
interactions.Collected += (_, points) => events.Add("score" + points);
|
||||
interactions.Update(shrinkray.Position);
|
||||
Check(tasks.Get("SCENE") == 50 && interactions.Score == 50, "Shrinkray grants50 and original task35->50");
|
||||
Check(interactions.Inventory.State(0, 3) == 1 && selected == 3 && help == 0, "Shrinkray inventory/help/gadget side effects");
|
||||
Check(checkpoint == shrinkray.Position && !shrinkray.Visible && !shrinkray.Active, "Capture current root before hiding acquired shrinkray");
|
||||
Check(events.SequenceEqual(new[] { "checkpoint", "task50", "help", "gadget", "score50" }), "Recovered special hook ordering");
|
||||
Check(interactions.Snapshot().ItemStates[301] == 1 && interactions.CurrentObjective == 2, "Acquired state and objective2 persist");
|
||||
interactions.Update(shrinkray.Position);
|
||||
Check(interactions.Score == 50 && events.Count == 5, "Repeated overlap cannot recollect");
|
||||
Console.WriteLine("PASS source intro/explanation/shrinkray state, inventory and event ordering");
|
||||
|
||||
var carl = director.FindActor("C3DCARL")!;
|
||||
Check(carl.Position == director.FindActor("CARLESC3")!.Position && carl.AIstate == 6, "Carl task callback positions state6 at authored marker");
|
||||
var talkStarted = 0;
|
||||
var taskAtSpeech = -1;
|
||||
var scoreAtSpeech = -1;
|
||||
director.Speech += (_, _) => { taskAtSpeech = tasks.Get("SCENE"); scoreAtSpeech = interactions.Score; };
|
||||
interactions.ConversationStarted += (_, tag) => { talkStarted++; Check(tag == "neutron1a", "Authored TalkTrigger0"); };
|
||||
director.SyncActor("JIM1", carl.Position, Vector3.Zero);
|
||||
interactions.Update(carl.Position);
|
||||
Check(taskAtSpeech == 60 && scoreAtSpeech == 150, "Carl callback runs before dialogue starts");
|
||||
Check(tasks.Get("SCENE") == 60 && carl.AIstate == 9 && talkStarted == 1, "Carl ends dispatcher in state9 with scene60");
|
||||
for (var i = 0; i < 10; i++) interactions.Update(carl.Position);
|
||||
Check(interactions.Score == 150 && talkStarted == 1, "Talk does not repeat on contact stay");
|
||||
Check(interactions.CurrentObjective == 3, "Carl transition selects objective3");
|
||||
director.Skip();
|
||||
LevelTransition? transition = null;
|
||||
interactions.Transition += request => transition = request;
|
||||
var exit = lab.Entities.Single(e => e.Tag == "LABTONEIGH");
|
||||
interactions.Update(exit.Position);
|
||||
Check(transition?.LevelFile == "level1.gam" && transition.StartPoint == "level1",
|
||||
$"Original lab exit task60 gate opens: request={transition}; controlled={director.Controlled}; blocked={director.Blocked}; tag={director.CurrentTag}");
|
||||
Console.WriteLine("PASS source Carl contact/callback/dialogue/task60 and original lab exit gate");
|
||||
|
||||
var snapshot = interactions.Snapshot();
|
||||
var decoded = OriginalSave.Parse(snapshot.Encode());
|
||||
Check(decoded.InventoryStates[3] == 1 && decoded.ItemStates[301] == 1 && decoded.Score == 150 && decoded.OtherCounter == 3,
|
||||
"Original TSK serializes acquired gadget, score and objective selector");
|
||||
Check(decoded.StoredVector == original.StoredVector, "Unknown saved vector is not overwritten by inferred checkpoint data");
|
||||
var restoredTasks = new TaskStates(decoded.Tasks);
|
||||
var restoredDirector = new SceneDirector(lab, restoredTasks, (_, _) => 5);
|
||||
var restored = new SceneInteractions(restoredDirector, restoredTasks, decoded, lab.Code);
|
||||
restoredDirector.Begin(lab.FindStart()!); restored.Reset(); restoredDirector.Skip();
|
||||
Check(!restoredDirector.FindActor("shrinkray")!.Active && restored.Inventory.State(0, 3) == 1, "Resume retains collected shrinkray/inventory");
|
||||
restored.Update(restoredDirector.FindActor("shrinkray")!.Position);
|
||||
Check(restored.Score == 150, "Resume cannot award shrinkray twice");
|
||||
Console.WriteLine("PASS original-format save/resume retains gadget and objective state");
|
||||
|
||||
// The source permits collection at other task values, but its special shrinkray
|
||||
// hook only grants the gadget when SCENE==35. Preserve that awkward boundary.
|
||||
foreach (var state in new[] { 30, 36, 50 })
|
||||
{
|
||||
var boundaryTasks = new TaskStates(original.Tasks.Select(t => t.Name == "SCENE" ? t with { State = state } : t));
|
||||
var boundaryDirector = new SceneDirector(lab, boundaryTasks, (_, _) => 1);
|
||||
var boundary = new SceneInteractions(boundaryDirector, boundaryTasks, original, lab.Code);
|
||||
boundary.Update(boundaryDirector.FindActor("shrinkray")!.Position);
|
||||
Check(boundaryTasks.Get("SCENE") == state && boundary.Inventory.State(0, 3) == 0 && boundary.Score == 50,
|
||||
"Shrinkray special effect exact task35 gate, ordinary score remains");
|
||||
}
|
||||
Console.WriteLine("PASS exact shrinkray task gate without invented progression");
|
||||
|
||||
var body = Entity("3JIM", "jim");
|
||||
var camera0 = Entity("3CAM", "first", ("CameraTarget", "jim"), ("SoundDatabase", "voice"), ("SoundIndex", 1));
|
||||
var camera1 = Entity("3CAM", "fallback", ("CameraTarget", "jim"), ("SoundDatabase", "voice"), ("SoundIndex", 2));
|
||||
foreach (var talkState in new[] { -1, -2, 50, 49 })
|
||||
{
|
||||
var friend = Entity("3CAR", "friend", ("AIState", 6), ("TargetName", "jim"), ("TaskName", "SCENE"),
|
||||
("TalkState0", talkState), ("TalkTrigger0", "missing"),
|
||||
("TalkState1", talkState), ("TalkTrigger1", "first"),
|
||||
("TalkState2", -2), ("TalkTrigger2", "fallback"));
|
||||
var testTasks = new TaskStates([new("SCENE", 50)]);
|
||||
var testDirector = new SceneDirector(new("TEST", [body, friend, camera0, camera1]), testTasks, (_, _) => 5);
|
||||
var test = new SceneInteractions(testDirector, testTasks, original, "TEST");
|
||||
test.Update(Vector3.Zero);
|
||||
Check(testDirector.CurrentTag == (talkState is -2 or 50 ? "first" : "fallback"), "First existing match/wildcard; -1 disabled, missing target skipped");
|
||||
Check(testTasks.Get("SCENE") == 60 && test.Score == 100, "Selected trigger alone invokes Carl callback");
|
||||
}
|
||||
var noneFriend = Entity("3CAR", "friend", ("AIState", 6), ("TargetName", "jim"), ("TaskName", "SCENE"),
|
||||
("TalkState0", 49), ("TalkTrigger0", "first"));
|
||||
var noTasks = new TaskStates([new("SCENE", 50)]);
|
||||
var noDirector = new SceneDirector(new("TEST", [body, noneFriend, camera0]), noTasks, (_, _) => 5);
|
||||
var noTalk = new SceneInteractions(noDirector, noTasks, original, "TEST");
|
||||
noTalk.Update(Vector3.Zero);
|
||||
Check(noTasks.Get("SCENE") == 50 && noTalk.Score == 0 && noDirector.FindActor("friend")!.AIstate == 0,
|
||||
"No matching talk target leaves state0 without award/task mutation");
|
||||
Console.WriteLine("PASS talk lookup order, missing/disabled/wildcard states and no-match behavior");
|
||||
|
||||
foreach (var distance in new[] { 160f, 159.5f })
|
||||
{
|
||||
var friend = Entity("3CAR", "friend", ("AIState", 6), ("TargetName", "jim"), ("TaskName", "SCENE"),
|
||||
("TalkState0", 50), ("TalkTrigger0", "first"));
|
||||
var edgeTasks = new TaskStates([new("SCENE", 50)]);
|
||||
var edgeDirector = new SceneDirector(new("TEST", [body, friend, camera0]), edgeTasks, (_, _) => 5);
|
||||
var edge = new SceneInteractions(edgeDirector, edgeTasks, original, "TEST");
|
||||
edge.Update(new(distance, 0, 0));
|
||||
Check(edge.Score == (distance < 160 ? 100 : 0), "Strict original sum-radius Carl contact boundary");
|
||||
}
|
||||
var waiting = new SceneDirector(lab, new TaskStates(original.Tasks), (_, _) => 5);
|
||||
waiting.Begin(lab.FindStart()!);
|
||||
var locked = new SceneInteractions(waiting, new TaskStates(original.Tasks), original, lab.Code);
|
||||
locked.Update(waiting.FindActor("shrinkray")!.Position);
|
||||
Check(locked.Score == 0 && locked.Snapshot().ItemStates[301] == 0, "Noncontrolled intro cannot collect pickups");
|
||||
Console.WriteLine("PASS strict recovered Carl radius boundary and active-player control gate");
|
||||
|
||||
var inventoryRaw = Enumerable.Range(0, 19).Select(i => i == 18 ? int.MinValue : i * 10).ToArray();
|
||||
var inventory = new SceneInventory(inventoryRaw);
|
||||
inventoryRaw[3] = 999;
|
||||
Check(inventory.State(0, 3) == 30 && inventory.State(1, 9) == int.MinValue, "Owned inventory copy preserves unknown signed wire values");
|
||||
var inventoryCopy = inventory.Snapshot(); inventoryCopy[3] = 888;
|
||||
Check(inventory.State(0, 3) == 30, "Snapshot owns its storage");
|
||||
Throws(() => inventory.State(2, 0)); Throws(() => inventory.State(0, 9));
|
||||
inventory.SetState(0, 3, 0); Throws(() => inventory.SelectGadget(3));
|
||||
inventory.SetState(0, 3, 1); inventory.SelectGadget(3); Check(inventory.SelectedGadget == 3, "Owned gadget selection");
|
||||
Console.WriteLine("PASS inventory bounds, ownership, unknown-state preservation and gadget availability");
|
||||
|
||||
// Independently recover the original SCENE setter's two dispatch tables rather
|
||||
// than testing the port's switch against another manually copied switch.
|
||||
var exe = File.ReadAllBytes(AssetPath.Resolve(root, "Neutron.exe"));
|
||||
foreach (var (address, expected) in new (int, string)[] {
|
||||
(0x435fcb, "e800060000"), //Contact invokes special hook before score.
|
||||
(0x4365fa, "83f823"), //Exact task35.
|
||||
(0x43663e, "6a016a036a00"), //Inventory group0,item3,state1.
|
||||
(0x436649, "6a00e84009fdff"), //Help page0.
|
||||
(0x43667c, "6a03ff9274010000"), //Jimmy gadget3.
|
||||
(0x413e2f, "680000c842"), //Carl radius100.
|
||||
(0x40a676, "83be0806000006"), //Carl inherited contact requires state6.
|
||||
(0x41b7cd, "ff9280010000"), //Derived award before selected trigger.
|
||||
(0x41b813, "6a64e8a6f50000"), //Base friend awards100.
|
||||
(0x41b7f0, "c786c806000009000000"), //Talk dispatcher ends in state9.
|
||||
(0x458880, "8b442404898194040000c20400"), //LOAD task hook only stores value.
|
||||
})
|
||||
Check(exe.AsSpan(address - 0x400000, expected.Length / 2).SequenceEqual(Convert.FromHexString(expected)),
|
||||
"Original interaction instruction evidence at" + address.ToString("X"));
|
||||
int U32(int address) => BinaryPrimitives.ReadInt32LittleEndian(exe.AsSpan(address - 0x400000, 4));
|
||||
int ExpectedObjective(int state)
|
||||
{
|
||||
int target;
|
||||
if (state is >= 35 and <= 280) target = U32(0x45fbf0 + 4 * exe[0x45fc48 + state - 35 - 0x400000]);
|
||||
else if (state == 290) target = 0x45fab6;
|
||||
else if (state is >= 300 and <= 550) target = U32(0x45fd40 + 4 * exe[0x45fd98 + state - 300 - 0x400000]);
|
||||
else return 0;
|
||||
var offset = target - 0x400000;
|
||||
return exe[offset] == 0x6a && exe[offset + 1] == 1 && exe[offset + 2] == 0x6a ? exe[offset + 3] : 0;
|
||||
}
|
||||
for (var state = -1; state <= 600; state++)
|
||||
Check(SceneInteractions.ObjectiveForScene(state) == ExpectedObjective(state), "Objective map agrees with original jump tables at state" + state);
|
||||
Console.WriteLine("PASS all SCENE objective milestones against original executable dispatch tables");
|
||||
|
||||
void Check(bool condition, string message) { if (!condition) throw new Exception(message); }
|
||||
void Throws(Action action)
|
||||
{
|
||||
try { action(); } catch (ArgumentOutOfRangeException) { return; }
|
||||
throw new Exception("Expected bounded inventory rejection");
|
||||
}
|
||||
GamEntity Entity(string kind, string tag, params (string Name, object Value)[] properties)
|
||||
{
|
||||
var values = new Dictionary<string, GamProperty> { ["ObjectTag"] = new("ObjectTag", 1, Encoding.Latin1.GetBytes(tag)) };
|
||||
foreach (var (name, value) in properties)
|
||||
{
|
||||
if (value is string text) values[name] = new(name, 1, Encoding.Latin1.GetBytes(text));
|
||||
else
|
||||
{
|
||||
var bytes = new byte[4];
|
||||
BinaryPrimitives.WriteInt32BigEndian(bytes, value is float number ? BitConverter.SingleToInt32Bits(number) : (int)value);
|
||||
values[name] = new(name, value is float ? 3u : 6u, bytes);
|
||||
}
|
||||
}
|
||||
// Distinct source offsets retain duplicate-tag contacts independently.
|
||||
return new(kind, counter++ * 100, values, []);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user