Implement system menu guard opcode
This commit is contained in:
66
engine/Age.Engine.Tests/SystemMenuGuardOpcodeTests.cs
Normal file
66
engine/Age.Engine.Tests/SystemMenuGuardOpcodeTests.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Age.Engine.Model;
|
||||
using Age.Engine.Sys4;
|
||||
using Age.Engine.Vm;
|
||||
|
||||
public class SystemMenuGuardOpcodeTests
|
||||
{
|
||||
private static readonly OpcodeTable Table = OpcodeTableJson.Load(Paths.OpcodesJson);
|
||||
private static Operand I(long value) => new(0, value);
|
||||
private static (int, Operand[]) Exit() => (0x2, Array.Empty<Operand>());
|
||||
|
||||
[Fact]
|
||||
public void SetterDefaultsEnabledAndReplacesTheCompleteNativeDword()
|
||||
{
|
||||
Script config = ScriptAssembler.Assemble(Table, "CONFIG.BIN",
|
||||
[
|
||||
(0x142, [I(0)]),
|
||||
(0x142, [I(-7)]),
|
||||
Exit(),
|
||||
], []);
|
||||
var vm = new VirtualMachine(config, Table, new RecordingHost());
|
||||
|
||||
Assert.Equal(1, vm.SystemMenuActionsEnabled);
|
||||
|
||||
vm.Run();
|
||||
|
||||
Assert.Equal(-7, vm.SystemMenuActionsEnabled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfigEntryAndExitPairRestoresNativeMenuActions()
|
||||
{
|
||||
Script config = ScriptAssembler.Assemble(Table, "CONFIG.BIN",
|
||||
[
|
||||
(0x142, [I(0)]),
|
||||
(0x142, [I(1)]),
|
||||
Exit(),
|
||||
], []);
|
||||
var vm = new VirtualMachine(config, Table, new RecordingHost());
|
||||
|
||||
vm.Run();
|
||||
|
||||
Assert.Equal(1, vm.SystemMenuActionsEnabled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RootSceneReloadRestoresTheNativeDefault()
|
||||
{
|
||||
Script system4 = ScriptAssembler.Assemble(Table, "SYSTEM4.BIN",
|
||||
[
|
||||
Exit(),
|
||||
], []);
|
||||
Script config = ScriptAssembler.Assemble(Table, "CONFIG.BIN",
|
||||
[
|
||||
(0x142, [I(0)]),
|
||||
(0x9, Array.Empty<Operand>()),
|
||||
], []);
|
||||
var provider = new MapProvider(new Dictionary<long, Script> { [0] = system4 });
|
||||
var host = new RecordingHost();
|
||||
var vm = new VirtualMachine(config, Table, host, provider: provider);
|
||||
|
||||
vm.Run();
|
||||
|
||||
Assert.Equal(1, vm.SystemMenuActionsEnabled);
|
||||
Assert.Equal(1, host.SceneContextResets);
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,9 @@ public sealed class VirtualMachine
|
||||
private AdvTextStyle _advTextStyle = AdvTextStyle.Default;
|
||||
private int _messageWindowAlphaSetting;
|
||||
private int _messageGlyphDelayMilliseconds;
|
||||
// EngineCtx +0xa0d10: AGERC queries this through IAGEService to gray its native
|
||||
// settings/save menu actions while CONFIG owns the scripted settings screen.
|
||||
private int _systemMenuActionsEnabled = 1;
|
||||
private readonly Dictionary<string, int> _valueSwitchTargets = new(StringComparer.Ordinal);
|
||||
// Native EngineCtx owns 11 lazily allocated integer FIFOs at +0x55130. ATSEEK/MVSEEK use
|
||||
// slot zero as their packed-coordinate flood-fill worklist; op 0x132 replaces a slot.
|
||||
@@ -111,6 +114,7 @@ public sealed class VirtualMachine
|
||||
public long Steps { get; private set; }
|
||||
public bool AutoMessageEnabled => _autoMessageEnabled;
|
||||
public bool MessageSkipEnabled => _messageSkipEnabled;
|
||||
public int SystemMenuActionsEnabled => _systemMenuActionsEnabled;
|
||||
public string PendingDiagnosticText => _diagnosticOutput.PendingText;
|
||||
/// <summary>
|
||||
/// Zero-based active-frame cutoff selected by opcode 0x1ad, or null when no surviving marker
|
||||
@@ -781,6 +785,7 @@ public sealed class VirtualMachine
|
||||
_advSkipServiceEnabled = false;
|
||||
_advReadSkipState = false;
|
||||
_advTextStyle = AdvTextStyle.Default;
|
||||
_systemMenuActionsEnabled = 1;
|
||||
TextHistory.SetRecordingEnabled(true);
|
||||
_host.SetMessageSkipActive(false);
|
||||
_host.SetPhysicalMessageSkipActive(false);
|
||||
@@ -2334,6 +2339,10 @@ public sealed class VirtualMachine
|
||||
_messageWindowAlphaSetting = (int)Read(a[0]);
|
||||
_host.SetMessageWindowAlphaSetting(_messageWindowAlphaSetting);
|
||||
return pc + 1;
|
||||
case "set-system-menu-enabled": // 0x142: native AGERC menu reentrancy guard
|
||||
case "u0041FB10": // pre-reference compatibility
|
||||
_systemMenuActionsEnabled = unchecked((int)Read(a[0]));
|
||||
return pc + 1;
|
||||
case "get-message-glyph-delay": // 0x7f
|
||||
case "u00414C60":
|
||||
Write(a[0], _messageGlyphDelayMilliseconds); return pc + 1;
|
||||
|
||||
Reference in New Issue
Block a user