feat(runtime,net): Campaign OP slice OP1 — full character-option table, dirty model, real 0x01A1 blob builder
The retail Options panel (Campaign OP) needs a Runtime-owned option map
covering all 53 PlayerOption ids and the real batched SetCharacterOptions
(0x01A1) blob before any UI can be built on top of it. Today's surface only
modeled 6 ListenTo*Chat ids and the 0x01A1 builder was a malformed 16-byte
stub (deleted at Campaign CH slice CH3, docs/research/2026-08-09-chat-side-
channels-vs-ace.md).
- CharacterOptionTable.cs: the ONE typed table, PlayerOption id (0x00..0x34)
-> (Options1/Options2 word, mask, IsAutoSave, ClientDefault), transcribed
from acclient.h's verbatim CharacterOption/CharacterOptions2/PlayerOption
enums and byte-verified against IsAutoSaveOption @0x0059A600 (the 21-id
auto-save table) and GetDefaultOptionValue @0x005D2A30 (the Defaults-
button table). Reconstructing CharacterOptions1/2 defaults from the
ClientDefault column independently reproduces 0x50C4A54A / 0x00008700,
cross-confirming the id-mask mapping. CharacterOptionId (SocialActions.cs)
widened from 6 to all 53 ids to match.
- RuntimeCharacterOptionsState: SetOptionBit now resolves through the full
table (was a 6-case switch). New TrySetOption is the ONE shared local-
write-then-send/dirty seam — mirrors CPlayerModule::OnChanged exactly:
write the bit locally first, then either send 0x0005 immediately (auto-
save ids) or MarkDirty for the batched blob, no-op on an unchanged value
(retail's own early-return) or an unmodeled id. New dirty model (IsDirty/
FirstDirtiedAt/MarkDirty/TryFlush/TryFlushIfAutoSaveDue) uses an injected
TimeProvider so it's fully unit-testable without a live clock.
- Both IRuntimeCharacterCommands.SetSingleOption adapters (Direct + Current)
now route through TrySetOption instead of duplicating the write; this
fixes the headless local-write gap the OP1 research flagged (the direct
adapter previously sent the wire message without writing the bit first,
same class of bug CH4 fixed for the graphical host). Both also reject an
id outside the table instead of silently accepting it. LiveSessionRuntime
Factory's SendSingleCharacterOption closure now delegates to the same
seam instead of duplicating write-then-send inline.
- New IRuntimeCharacterCommands.SaveOptions(generation) — the explicit
blob-flush verb (retail's SaveToServer(force: 0)) — wired end-to-end in
both adapters, including a new SaveCharacterOptionsRuntimeCmd on the
graphical router.
- SocialActions.BuildSetCharacterOptions + WorldSession.SendSetCharacterOptions:
the real PlayerModule::Pack body per the wire research's field-by-field
layout — header always 0x460 OR'd with 0x001/0x008 when shortcuts/desired
comps are non-empty, favorite spells always 8 lists, never sets 0x100 or
0x200. Echoes last-parsed shortcuts/favorites/desired-comps/spellbook
filters (via new CharacterOptionsBlobSource) instead of zeroing them.
Conformance: a hand-computed golden byte vector (not generated by the
builder under test — the CH3 builder died of tests that pinned a wrong
shape and looked green) plus a round-trip through PlayerDescriptionParser.
Contract deviation: the 480 s auto-save timer and the flush-before-logout
trigger are implemented as fully-tested pure state-machine logic
(TryFlushIfAutoSaveDue) but are NOT wired into either host's live per-frame
loop or graceful-shutdown sequence in this slice — only the explicit
SaveOptions verb is production-wired. Wiring the timer touches App's
UpdateFrameOrchestrator graph and Headless's tick loop (outside this
slice's Runtime/wire-layer scope); wiring logout risks the already-fragile
graceful-shutdown sequence CLAUDE.md flags. Filed as TS-71 per the plan's
own escape valve ("target: not deferred" with a register row if deferred).
Also filed: AP-193 (the 0x34 HearPKDeathMessages id/mask is ACE-sourced,
unverifiable against the 2013 binary) and AP-194 (GetDefaultOptionValue's
table disagrees with the constructor default for ConfirmVolatileRareUse/
ShowHelm/ShowCloak — retail's own quirk, reproduced not fixed).
Tests: table completeness x53, auto-save/client-default split pinned
id-by-id against the byte-verified tables, unknown/reserved-id rejection
(0x35/0x36 landmines), local-write-then-send on both adapters + the router,
the dirty/flush state machine, SaveOptions, and the wire golden vector +
PlayerDescriptionParser round-trip. Full Release suite: 12,745 passed / 4
skipped / 0 failed (baseline 12,611/4/0 — slice adds 134 passing tests,
zero regressions).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
b585d80e7a
commit
86c0a7e0ee
19 changed files with 1464 additions and 62 deletions
|
|
@ -286,6 +286,167 @@ public sealed class RuntimeCharacterStateTests
|
|||
Assert.Equal(beforeRevision, options.Revision);
|
||||
}
|
||||
|
||||
// ── OP1 (Campaign OP, 2026-08-10): TrySetOption — the shared
|
||||
// local-write-then-send/dirty seam, + the dirty/flush state machine ────
|
||||
|
||||
[Fact]
|
||||
public void TrySetOption_AutoSaveId_WritesLocallyThenSendsImmediately_NeverDirties()
|
||||
{
|
||||
var options = new RuntimeCharacterOptionsState();
|
||||
options.Replace(options.Options1, 0u); // every Options2 Hear*Chat bit off
|
||||
var sent = new List<(uint OptionId, bool Value)>();
|
||||
|
||||
bool accepted = options.TrySetOption(
|
||||
(uint)CharacterOptionId.ListenToGeneralChat,
|
||||
true,
|
||||
sendAutoSave: () => sent.Add(
|
||||
((uint)CharacterOptionId.ListenToGeneralChat, true)));
|
||||
|
||||
Assert.True(accepted);
|
||||
Assert.Equal(
|
||||
(uint)PlayerDescriptionParser.CharacterOptions2.HearGeneralChat,
|
||||
options.Options2
|
||||
& (uint)PlayerDescriptionParser.CharacterOptions2.HearGeneralChat);
|
||||
Assert.Equal([((uint)CharacterOptionId.ListenToGeneralChat, true)], sent);
|
||||
Assert.False(options.IsDirty);
|
||||
Assert.Null(options.FirstDirtiedAt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TrySetOption_BatchedId_WritesLocallyAndMarksDirty_NeverSends()
|
||||
{
|
||||
var options = new RuntimeCharacterOptionsState();
|
||||
var sent = new List<(uint OptionId, bool Value)>();
|
||||
|
||||
// AutoTarget (0x0D) is default-ON per CharacterOptionTable — flip it
|
||||
// off to exercise a real transition.
|
||||
bool accepted = options.TrySetOption(
|
||||
(uint)CharacterOptionId.AutoTarget,
|
||||
false,
|
||||
sendAutoSave: () => sent.Add(((uint)CharacterOptionId.AutoTarget, false)));
|
||||
|
||||
Assert.True(accepted);
|
||||
// AutoTarget_CharacterOption = 0x2000 (acclient.h:3417).
|
||||
Assert.Equal(0u, options.Options1 & 0x00002000u);
|
||||
Assert.Empty(sent);
|
||||
Assert.True(options.IsDirty);
|
||||
Assert.NotNull(options.FirstDirtiedAt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TrySetOption_UnchangedValue_IsANoOp_MatchingRetailEarlyReturn()
|
||||
{
|
||||
var options = new RuntimeCharacterOptionsState();
|
||||
var sent = new List<(uint, bool)>();
|
||||
// AutoTarget defaults ON — re-asserting ON must be a no-op (retail:
|
||||
// an unchanged option produces no notice, no side effect, no send).
|
||||
bool accepted = options.TrySetOption(
|
||||
(uint)CharacterOptionId.AutoTarget,
|
||||
true,
|
||||
sendAutoSave: () => sent.Add(((uint)CharacterOptionId.AutoTarget, true)));
|
||||
|
||||
Assert.True(accepted);
|
||||
Assert.Empty(sent);
|
||||
Assert.False(options.IsDirty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TrySetOption_UnknownId_ReturnsFalse_NeverInvokesCallback()
|
||||
{
|
||||
var options = new RuntimeCharacterOptionsState();
|
||||
bool invoked = false;
|
||||
|
||||
bool accepted = options.TrySetOption(0x35u, true, () => invoked = true);
|
||||
|
||||
Assert.False(accepted);
|
||||
Assert.False(invoked);
|
||||
Assert.False(options.IsDirty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MarkDirty_OnlySecondCallDoesNotPushOutFirstDirtiedAt()
|
||||
{
|
||||
var clock = new ManualTimeProvider();
|
||||
var options = new RuntimeCharacterOptionsState(clock);
|
||||
|
||||
options.TrySetOption(
|
||||
(uint)CharacterOptionId.AutoTarget, false, () => { });
|
||||
DateTimeOffset? firstStamp = options.FirstDirtiedAt;
|
||||
Assert.NotNull(firstStamp);
|
||||
|
||||
clock.Advance(TimeSpan.FromSeconds(10));
|
||||
options.TrySetOption(
|
||||
(uint)CharacterOptionId.ShowTooltips, false, () => { });
|
||||
|
||||
Assert.Equal(firstStamp, options.FirstDirtiedAt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryFlush_NoOpWhenClean_FlushesAndClearsWhenDirty()
|
||||
{
|
||||
var options = new RuntimeCharacterOptionsState();
|
||||
int cleanFlushes = 0;
|
||||
Assert.False(options.TryFlush(() => cleanFlushes++));
|
||||
Assert.Equal(0, cleanFlushes);
|
||||
|
||||
options.TrySetOption(
|
||||
(uint)CharacterOptionId.AutoTarget, false, () => { });
|
||||
Assert.True(options.IsDirty);
|
||||
|
||||
int dirtyFlushes = 0;
|
||||
Assert.True(options.TryFlush(() => dirtyFlushes++));
|
||||
Assert.Equal(1, dirtyFlushes);
|
||||
Assert.False(options.IsDirty);
|
||||
Assert.Null(options.FirstDirtiedAt);
|
||||
|
||||
// A second flush on a now-clean module is a no-op — retail's
|
||||
// SaveToServer(force: 0) sends nothing for a clean module.
|
||||
Assert.False(options.TryFlush(() => dirtyFlushes++));
|
||||
Assert.Equal(1, dirtyFlushes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryFlushIfAutoSaveDue_DoesNotFireBeforeThreshold_FiresAtThreshold()
|
||||
{
|
||||
var clock = new ManualTimeProvider();
|
||||
var options = new RuntimeCharacterOptionsState(clock);
|
||||
options.TrySetOption(
|
||||
(uint)CharacterOptionId.AutoTarget, false, () => { });
|
||||
|
||||
int flushes = 0;
|
||||
clock.Advance(RuntimeCharacterOptionsState.AutoSaveDelay - TimeSpan.FromSeconds(1));
|
||||
Assert.False(options.TryFlushIfAutoSaveDue(() => flushes++));
|
||||
Assert.True(options.IsDirty);
|
||||
|
||||
clock.Advance(TimeSpan.FromSeconds(1));
|
||||
Assert.True(options.TryFlushIfAutoSaveDue(() => flushes++));
|
||||
Assert.Equal(1, flushes);
|
||||
Assert.False(options.IsDirty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetSession_ClearsDirtyState()
|
||||
{
|
||||
var options = new RuntimeCharacterOptionsState();
|
||||
options.TrySetOption(
|
||||
(uint)CharacterOptionId.AutoTarget, false, () => { });
|
||||
Assert.True(options.IsDirty);
|
||||
|
||||
options.ResetSession();
|
||||
|
||||
Assert.False(options.IsDirty);
|
||||
Assert.Null(options.FirstDirtiedAt);
|
||||
}
|
||||
|
||||
private sealed class ManualTimeProvider : TimeProvider
|
||||
{
|
||||
private DateTimeOffset _now = new(2026, 8, 10, 0, 0, 0, TimeSpan.Zero);
|
||||
|
||||
public override DateTimeOffset GetUtcNow() => _now;
|
||||
|
||||
public void Advance(TimeSpan elapsed) => _now += elapsed;
|
||||
}
|
||||
|
||||
// ── Campaign P Slice P1 (2026-07-30): burden/stamina/vitae-adjusted ───
|
||||
// ── run/jump skill (pseudocode doc §9) ─────────────────────────────
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue