Recover retained route state and complete PostLoad availability tails

This commit is contained in:
UnixNight committed 2026-10-26 03:58:52 -04:00
1 parent 1dddfefc68
commit 9ad5a8ef6b
36 files changed
+1559 -32

No files matched your search

+18
View File
@@ -117,6 +117,24 @@ public sealed class LabSimulation
CameraEye = DesiredEye().Eye;
}
public PlayerLevelState? CaptureLevelState(int selectedGadget) => Noclip ? null
: new(LevelCode, selectedGadget, movementMode, jumpState.HoldSeconds, jumpState.EffectRemaining);
/// <summary>Apply after destination construction. Init re-applies authored
/// body vectors and clears speed/turn; PostLoad resets jump, not these scalars.
/// Grounding and the next controller/fire tick may change them independently.</summary>
public bool ApplyRetainedLevelState(PlayerLevelState state)
{
ArgumentNullException.ThrowIfNull(state);
if (!state.SupportsDestination(LevelCode)) return false;
if (state.MovementMode is < 0 or > 1 || !float.IsFinite(state.HoldSeconds)
|| state.HoldSeconds < 0 || !float.IsFinite(state.EffectRemaining))
throw new ArgumentOutOfRangeException(nameof(state));
movementMode = state.MovementMode;
jumpState = new(0, state.HoldSeconds, state.EffectRemaining);
return true;
}
// EXE 0x47F940 truncates, then degree lookup masks to the 16384-entry table.
// Table generated with modern trig; x87 bit-identical table recovery is pending.
public static (float Sin, float Cos) Trig(float degrees)
+15
View File
@@ -0,0 +1,15 @@
namespace GamePort.Game;
/// <summary>
/// Retained scalars proven through route GAM read, Init and PostLoad callbacks.
/// This is in-memory ordinary-load state, never part of the original TSK format.
/// Other gadget cleanup branches/levels need their own lifecycle proof.
/// </summary>
public sealed record PlayerLevelState(string SourceLevel, int SelectedGadget,
int MovementMode, float HoldSeconds, float EffectRemaining)
{
public bool SupportsDestination(string level) => IsRoute(SourceLevel) && IsRoute(level)
&& SelectedGadget is -1 or 3;
private static bool IsRoute(string level) => level is "LV1B" or "VR04" or "LEV1";
}
+15 -3
View File
@@ -25,9 +25,10 @@ public sealed class SceneInventory
public void SetState(int group, int item, int state) => states[Offset(group, item)] = state;
/// <summary>
/// Jimmy PostLoad423DEF..423EC1: enable these eight owned gadgets, then
/// disable them in numeric VR01..VR08. State4 is unavailable ownership,
/// distinct from unowned0. Other wire values and item8 remain unchanged.
/// Jimmy PostLoad: enable eight owned gadgets, disable them in VR01..08,
/// then re-enable that tutorial's gadget in the later level-specific tail.
/// LV1B disables gadgets1/7. Other level-specific tails remain unported.
/// State4 is unavailable ownership, distinct from unowned0.
/// </summary>
public void ApplyLevelAvailability(string levelCode)
{
@@ -38,8 +39,19 @@ public sealed class SceneInventory
// Exactly the eight original FourCC values in the source numeric range.
if (levelCode.Length == 4 && levelCode.StartsWith("VR0", StringComparison.Ordinal)
&& levelCode[3] is >= '1' and <= '8')
{
foreach (var item in items)
if (states[item] == 1) states[item] = 4;
//4242AF..424400: each practice scene enables its matching gadget.
var practiceItem = levelCode[3] - '1';
if (states[practiceItem] == 4) states[practiceItem] = 1;
}
else if (levelCode == "LV1B")
{
//424102: lab restrictions follow the common enable pass.
foreach (var item in new[] { 1, 7 })
if (states[item] == 1) states[item] = 4;
}
}
public void SelectGadget(int item)
+33 -9
View File
@@ -17,13 +17,15 @@ internal static class Program
{
using var presentation = new RenderSession();
OriginalSave? carriedSave = null;
PlayerLevelState? carriedPlayer = null;
var returning = false;
var diagnostics = new DebugDiagnostics { Enabled = args.Contains("--debug-overlay") };
while (true)
{
var result = Run(args, carriedSave, returning, diagnostics, presentation, out var continuation);
var result = Run(args, carriedSave, carriedPlayer, returning, diagnostics, presentation, out var continuation);
if (result != 0 || continuation == null) return result;
args = continuation.Args; carriedSave = continuation.Save; returning = continuation.Returning;
carriedPlayer = continuation.Player;
}
}
catch (Exception error) { Console.Error.WriteLine(error); return 1; }
@@ -38,9 +40,9 @@ internal static class Program
return args[i + 1];
}
private sealed record SceneContinuation(string[] Args, OriginalSave Save, bool Returning);
private sealed record SceneContinuation(string[] Args, OriginalSave Save, bool Returning, PlayerLevelState? Player);
private static int Run(string[] args, OriginalSave? carriedSave, bool returning, DebugDiagnostics diagnostics,
private static int Run(string[] args, OriginalSave? carriedSave, PlayerLevelState? carriedPlayer, bool returning, DebugDiagnostics diagnostics,
RenderSession presentation, out SceneContinuation? continuation)
{
continuation = null;
@@ -160,17 +162,23 @@ internal static class Program
if (Option(args, "--effects-audio-smoke") is { } effectsManifest)
{
using var mixer = new SceneAudio(new PreparedEntityResources(effectsManifest));
// Start transport only after both streams exist, so slow stream
// creation cannot consume the entire baseline before it is sampled.
mixer.SetPaused(true);
mixer.Effect(59, "bars"); mixer.Effect(58);
var before = mixer.QueuedEffectBytes;
Thread.Sleep(200);
var consumed = mixer.QueuedEffectBytes < before;
mixer.SetPaused(false);
var consumptionClock = Stopwatch.StartNew();
while (mixer.QueuedEffectBytes >= before && consumptionClock.ElapsedMilliseconds < 3000) Thread.Sleep(20);
var after = mixer.QueuedEffectBytes;
var consumed = before > 0 && after < before;
mixer.Pump();
mixer.StopLoop("bars");
var stopped = mixer.LoopCount == 0 && mixer.EffectCount == 1;
mixer.Effect(230);
var mixed = mixer.EffectCount == 2;
mixer.StopEffects();
Console.WriteLine($"Original effects: consumed={consumed}, loop stopped={stopped}, independent one-shots={mixed}, cleared={mixer.QueuedEffectBytes == 0}.");
Console.WriteLine($"Original effects: consumed={consumed}, loop stopped={stopped}, independent one-shots={mixed}, cleared={mixer.QueuedEffectBytes == 0}; baseline={before}, after={after}.");
return consumed && stopped && mixed && mixer.QueuedEffectBytes == 0 ? 0 : 2;
}
if (Option(args, "--scene-audio-smoke") is { } sceneAudioManifest)
@@ -316,6 +324,16 @@ internal static class Program
simulation = new LabSimulation(new SceneCollision(world), standingPose, originalStart.Position, originalStart.Rotation.Y,
cameraRay == null ? null : (look, eye) => cameraRay.Trace(look, eye))
{ LevelCode = level.Code, InputAfterPlayerUpdate = carriedSave != null };
if (carriedPlayer != null)
{
var applied = simulation.ApplyRetainedLevelState(carriedPlayer);
if (applied)
Console.WriteLine($"Retained player scalars: mode={simulation.MovementMode}, hold={simulation.JumpHoldSeconds}, fire={simulation.JetpackRemaining}; jump={simulation.JumpState}, velocity={simulation.Velocity}, speed={simulation.Speed}.");
if (practiceReturnSmoke && (!applied || simulation.MovementMode != carriedPlayer.MovementMode
|| simulation.JumpHoldSeconds != carriedPlayer.HoldSeconds || simulation.JetpackRemaining != carriedPlayer.EffectRemaining
|| simulation.JumpState != 0 || simulation.Speed != 0 || simulation.Velocity != Vector3.Zero || simulation.PendingImpulse != Vector3.Zero))
throw new InvalidOperationException("Retained route scalar/body reset boundary changed");
}
}
if (walking && returning) simulation!.RestoreReturnRoot(returnRoot);
var placement = PreviewCharacterPlacement.Create(mesh, standingPose, originalStart.Position, originalStart.Rotation.Y);
@@ -475,8 +493,8 @@ internal static class Program
if (args.Contains("--skip-intro") || jetpackSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke) { sceneAudio?.StopSpeech(); director.Skip(); }
if (practiceReturnSmoke && level.Code == "VR04")
{
if (interactions!.Inventory.State(0, 3) != 4)
throw new InvalidOperationException("Tutorial PostLoad did not disable the owned gadget before VR04's bypass");
if (interactions!.Inventory.State(0, 3) != 1)
throw new InvalidOperationException("VR04 PostLoad tail did not re-enable its owned practice jetpack");
director.Skip();
interactions!.Update(level.Entities.First(e => e.Kind == "LOAD").Position);
if (transitionRequest is not { Returning: true }) throw new InvalidOperationException("VR04 exit did not preserve RETURN identity");
@@ -1237,8 +1255,14 @@ internal static class Program
nextArgs.AddRange(["--scene", nextScene, "--level", "gam/" + transitionRequest.LevelFile,
"--start", transitionRequest.StartPoint]);
if (toolsSmoke) nextArgs.AddRange(["--frames", "2"]);
// Deliberate test sentinels after the last departure tick: the
// destination assertion observes loader state, before grounding
// or controller/fire callbacks can legitimately change it.
if (practiceReturnSmoke && simulation != null)
simulation.ApplyRetainedLevelState(new(level!.Code, 3, 1, .625f, 6.125f));
continuation = new(nextArgs.ToArray(), (debugCheckpointToLoad ?? interactions!.Snapshot()) with {
StartPoint = transitionRequest.StartPoint, StoredVector = debugCheckpointToLoad?.StoredVector ?? returnRoot }, transitionRequest.Returning);
StartPoint = transitionRequest.StartPoint, StoredVector = debugCheckpointToLoad?.StoredVector ?? returnRoot }, transitionRequest.Returning,
debugCheckpointToLoad == null ? simulation?.CaptureLevelState(interactions!.Inventory.SelectedGadget) : null);
Console.WriteLine($"Loading original destination: {transitionRequest.LevelFile}, start={transitionRequest.StartPoint}; fade behavior remains unreconstructed.");
}
if (walkSmoke && !simulation!.SmokePassed) return 2;