Files
Pal3.Unity/Assets/Scripts/Pal3.Game/Script/ScriptVariableStore.cs
T
Jiaqi (0x7c13) Liu 7e5df726cc Implement PAL3A command handlers and isolate script execution
Correct PAL3A parameter signatures and add handlers for fortune selection,
skybox sequences, actor facing and attacks, team and progression state,
camera constraints, and battle preparation flags.

Give script instances separate locals, advance grouped waits concurrently,
and pause PAL3A parents only for their directly decoded child calls. Cancel
stale interactions and save replay on reset, preserve finite action semantics,
and restore camera orientation after releasing horizontal constraints.

Persist supported state in v2 saves and add protocol, runtime, and progression
regressions. Full combat gameplay remains outside this change.

Validation: PAL3 274/274 and PAL3A 291/291 EditMode tests; 18 PAL3 and 22 PAL3A
runtime checks. All 77,889 PAL3A instruction boundaries match EXE signatures.
2026-11-13 00:49:36 +08:00

53 lines
2.1 KiB
C#

// ------------------------------------------------------------------------
// Copyright (c) 2026, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ------------------------------------------------------------------------
namespace Pal3.Game.Script
{
using System;
using System.Collections;
using System.Collections.Generic;
using Core.Contract.Constants;
using Core.DataReader.Sce;
// Local variables belong to a script instance, not to its script ID or scene.
internal sealed class ScriptVariableStore : IUserVariableStore<ushort, int>
{
private readonly IUserVariableStore<ushort, int> _globals;
private readonly int[] _locals;
public ScriptVariableStore(IUserVariableStore<ushort, int> globals, SceUserVarInfo[] definitions)
{
_globals = globals;
_locals = new int[definitions?.Length ?? 0];
for (int i = 0; i < _locals.Length; i++)
{
byte[] data = definitions[i].InitData;
if (data == null || data.Length == 0) continue;
if (data.Length != sizeof(int))
throw new NotSupportedException($"Unsupported local variable initializer at index {i}");
_locals[i] = data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24;
}
}
public int Get(ushort variable) => (variable & ScriptConstants.GlobalVariableFlag) != 0
? _globals.Get(variable) : _locals[variable];
public void Set(ushort variable, int value)
{
if ((variable & ScriptConstants.GlobalVariableFlag) != 0) _globals.Set(variable, value);
else _locals[variable] = value;
}
public IEnumerator<KeyValuePair<ushort, int>> GetEnumerator()
{
foreach (var variable in _globals) yield return variable;
for (int i = 0; i < _locals.Length; i++)
yield return new KeyValuePair<ushort, int>((ushort)i, _locals[i]);
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}