The wire carries an id, a stage and two timers. Every word the player reads lives in portal.dat's ContractTable, which nothing in the tree had ever opened — the only reference counted its entries in a CLI diagnostic. Chorizite does decode it (322 contracts installed), which was a real question given it declares TabooTable without decoding it. FillProgressString @0x00498DE0 is the one real algorithm in this panel, and it is now ported whole. Its x87 compares are the usual fcom/sahf pattern, so the (status & 0x41) tests decode as "<= 0" rather than "< 0" — the difference between a cooldown that expires and one that never does. Three readings recorded as tests because each looks like a mistake: TimeWhenDone is on the wire and is never read; an EMPTY QuestflagRepeatTime is the entire difference between "Done" and "Available"; and DescriptionProgress is a printf format taking stage-4, not a literal — rendering it verbatim shows the player "%d/20 Tuskers". DeltaTimeToString @0x00565E10 emits every part with a trailing space and then overwrites the last one. That truncation is invisible in the decompiler output (the instruction reads as pointer noise), so it was settled by decoding the bytes: mov byte ptr [esp+eax+0x1b], cl with cl == 0 and eax == strlen writes the terminator over buffer[len-1]. Guessing either way was a coin flip that decides whether every repeat timer reads "Done (1h 30s to Repeat)". The single-%d substitution is a MEASUREMENT, not a convenience: 89 of the 322 installed contracts author a progress format and every one uses exactly one specifier. An installed-DAT test asserts that, so a future dat that ships two fails there rather than silently rendering a raw specifier. LayoutDump gained --contracts, which is how all of the above was measured. Campaign QT slices 2 and 4 of 6. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
183 lines
7.1 KiB
C#
183 lines
7.1 KiB
C#
using System;
|
|
using AcDream.Core.Quests;
|
|
|
|
namespace AcDream.Core.Tests.Quests;
|
|
|
|
/// <summary>
|
|
/// Campaign QT slice QT4: <c>gmContractsUI::FillProgressString @0x00498DE0</c>
|
|
/// and the <c>ClientUISystem::DeltaTimeToString @0x00565E10</c> it calls.
|
|
/// </summary>
|
|
public sealed class ContractProgressTextTests
|
|
{
|
|
private static readonly DateTime Arrival = new(2026, 8, 21, 12, 0, 0, DateTimeKind.Utc);
|
|
|
|
private static ContractEntry Entry(
|
|
string descriptionProgress = "", string questflagRepeatTime = "")
|
|
=> ContractEntry.Unknown with
|
|
{
|
|
DescriptionProgress = descriptionProgress,
|
|
QuestflagRepeatTime = questflagRepeatTime,
|
|
};
|
|
|
|
// ── DeltaTimeToString ───────────────────────────────────────────────
|
|
|
|
[Theory]
|
|
[InlineData(0, "0s")]
|
|
[InlineData(45, "45s")]
|
|
[InlineData(60, "1m 0s")]
|
|
[InlineData(3600, "1h 0s")] // minutes are OMITTED when zero
|
|
[InlineData(3661, "1h 1m 1s")]
|
|
[InlineData(86400, "1d 0s")]
|
|
[InlineData(2592000, "1mo 0s")] // a "month" is a flat 30 days
|
|
[InlineData(2592000 + 86400 + 3600 + 61, "1mo 1d 1h 1m 1s")]
|
|
public void DeltaTimeFormatsLargestUnitFirstAndAlwaysShowsSeconds(
|
|
double seconds, string expected)
|
|
=> Assert.Equal(expected, ContractProgressText.DeltaTimeToString(seconds));
|
|
|
|
[Fact]
|
|
public void DeltaTimeHasNoTrailingSpace()
|
|
{
|
|
// Retail emits every part WITH a trailing space and then writes the
|
|
// terminator over the last one (0x00565F0E). Missing that truncation
|
|
// gives "Done (30s to Repeat)" with a double space — and the
|
|
// instruction is invisible in the decompiler output, so this is the
|
|
// assertion that pins the byte-level reading.
|
|
string text = ContractProgressText.DeltaTimeToString(30);
|
|
|
|
Assert.Equal("30s", text);
|
|
Assert.DoesNotContain(" ", ContractProgressText.Build(
|
|
3u, 30d, Arrival, Entry(questflagRepeatTime: "flag"), Arrival));
|
|
}
|
|
|
|
[Fact]
|
|
public void DeltaTimeTruncatesTowardZeroLikeRetailsFtol()
|
|
{
|
|
Assert.Equal("59s", ContractProgressText.DeltaTimeToString(59.99));
|
|
}
|
|
|
|
// ── the stage arms ──────────────────────────────────────────────────
|
|
|
|
[Fact]
|
|
public void StageOneIsAvailable()
|
|
=> Assert.Equal("Available", ContractProgressText.Build(
|
|
1u, 0d, Arrival, Entry(), Arrival));
|
|
|
|
[Fact]
|
|
public void StageTwoIsInProgress()
|
|
=> Assert.Equal("In Progress", ContractProgressText.Build(
|
|
2u, 0d, Arrival, Entry(), Arrival));
|
|
|
|
[Fact]
|
|
public void StageThreeWithNoRepeatFlagIsDoneForGood()
|
|
{
|
|
// An empty QuestflagRepeatTime is the whole difference between a
|
|
// one-shot quest and a repeatable one on cooldown.
|
|
Assert.Equal("Done", ContractProgressText.Build(
|
|
3u, 0d, Arrival, Entry(questflagRepeatTime: ""), Arrival));
|
|
}
|
|
|
|
[Fact]
|
|
public void StageThreeWithARepeatFlagAndNoTimerIsAvailableAgain()
|
|
{
|
|
Assert.Equal("Available", ContractProgressText.Build(
|
|
3u, 0d, Arrival, Entry(questflagRepeatTime: "SomeQuestRepeat"), Arrival));
|
|
}
|
|
|
|
[Fact]
|
|
public void StageThreeWithATimerStillRunningCountsDownToTheRepeat()
|
|
{
|
|
string text = ContractProgressText.Build(
|
|
3u,
|
|
timeWhenRepeats: 3661d,
|
|
Arrival,
|
|
Entry(questflagRepeatTime: "SomeQuestRepeat"),
|
|
now: Arrival);
|
|
|
|
Assert.Equal("Done (1h 1m 1s to Repeat)", text);
|
|
}
|
|
|
|
[Fact]
|
|
public void TheCountdownIsAnchoredAtArrivalNotRecomputedFromTheServerValue()
|
|
{
|
|
// The server sends the remaining seconds ONCE and never sends the
|
|
// instant it measured them from. Anchoring at arrival is what makes
|
|
// the timer tick; without it the same number would be shown forever.
|
|
string atArrival = ContractProgressText.Build(
|
|
3u, 600d, Arrival, Entry(questflagRepeatTime: "f"), Arrival);
|
|
string tenMinutesLater = ContractProgressText.Build(
|
|
3u, 600d, Arrival, Entry(questflagRepeatTime: "f"),
|
|
Arrival.AddMinutes(5));
|
|
|
|
Assert.Equal("Done (10m 0s to Repeat)", atArrival);
|
|
Assert.Equal("Done (5m 0s to Repeat)", tenMinutesLater);
|
|
}
|
|
|
|
[Fact]
|
|
public void ATimerThatHasRunOutSinceArrivalReadsAsAvailable()
|
|
{
|
|
Assert.Equal("Available", ContractProgressText.Build(
|
|
3u, 600d, Arrival, Entry(questflagRepeatTime: "f"),
|
|
now: Arrival.AddHours(1)));
|
|
}
|
|
|
|
[Fact]
|
|
public void TimeWhenDoneNeverReachesThisText()
|
|
{
|
|
// It IS on the wire and it does NOT drive the progress column. Passing
|
|
// it here instead of TimeWhenRepeats is the plausible misreading; the
|
|
// signature refuses it, and this test says why.
|
|
string text = ContractProgressText.Build(
|
|
3u, timeWhenRepeats: 0d, Arrival, Entry(questflagRepeatTime: ""), Arrival);
|
|
|
|
Assert.Equal("Done", text);
|
|
}
|
|
|
|
// ── the progress counter ────────────────────────────────────────────
|
|
|
|
[Theory]
|
|
[InlineData(4u, "0/20 Tuskers")]
|
|
[InlineData(9u, "5/20 Tuskers")]
|
|
[InlineData(24u, "20/20 Tuskers")]
|
|
public void StageFourAndAboveSubstitutesTheCountIntoTheAuthoredFormat(
|
|
uint stage, string expected)
|
|
{
|
|
// The count is stage - 4, and DescriptionProgress is a printf format,
|
|
// not a literal — rendering it verbatim shows the player "%d/20".
|
|
Assert.Equal(expected, ContractProgressText.Build(
|
|
stage, 0d, Arrival, Entry(descriptionProgress: "%d/20 Tuskers"), Arrival));
|
|
}
|
|
|
|
[Fact]
|
|
public void AProgressStageWithNoAuthoredFormatFallsBackToInProgress()
|
|
{
|
|
Assert.Equal("In Progress", ContractProgressText.Build(
|
|
7u, 0d, Arrival, Entry(descriptionProgress: ""), Arrival));
|
|
}
|
|
|
|
[Fact]
|
|
public void AFormatWithoutASpecifierIsShownVerbatim()
|
|
{
|
|
Assert.Equal("Gathering herbs", ContractProgressText.Build(
|
|
6u, 0d, Arrival, Entry(descriptionProgress: "Gathering herbs"), Arrival));
|
|
}
|
|
|
|
[Fact]
|
|
public void OnlyTheFirstSpecifierIsSubstitutedBecauseRetailPassesOneArgument()
|
|
{
|
|
// A second %d would read past the argument in retail too. No installed
|
|
// contract has one (measured: 89 formats, all exactly one %d), so this
|
|
// pins the behaviour rather than describing shipped content.
|
|
Assert.Equal("3 of %d", ContractProgressText.Build(
|
|
7u, 0d, Arrival, Entry(descriptionProgress: "%d of %d"), Arrival));
|
|
}
|
|
|
|
[Fact]
|
|
public void AnUnknownStageProducesNothingRatherThanGuessing()
|
|
{
|
|
// Retail returns without writing, leaving the caller's string as it
|
|
// found it. Inventing a label here would put text on screen that the
|
|
// real client never shows.
|
|
Assert.Equal(string.Empty, ContractProgressText.Build(
|
|
0u, 0d, Arrival, Entry(), Arrival));
|
|
}
|
|
}
|