fix(chargen): Campaign CC CC6a review fix round — F1-F12

Addresses the CC6a dual-lens review (architectural PASS with reservations,
retail fidelity PASS with reservations, merge after F1/F2/F3).

F1 (BLOCKING) - AlternateSetup/setupId tested the wrong sentinel (0)
instead of retail's INVALID_DID (0xFFFFFFFF, CharGenState::GetSetupID
@0x005C5B22). A hair style storing that value would have been adopted as
a literal Setup id, nulling Get<Setup> and killing the whole preview.
Fixed both sites with a new InvalidDid constant; added two hand-built
tests plus an installed-DAT sweep of every hair style across all 26
heritage/gender combinations (869 selections, zero unresolved Setup ids).

F2 (BLOCKING) - TS-82's register row, ChargenClothingTable.cs's doc, and
the plan's ledger row all understated Undead's measured clothing-coverage
gap as "headgear/trousers/footwear" (3 slots) with a self-contradicting
"4 of 4 non-shirt slots" aside. Corrected everywhere to the true measured
ALL FOUR slots (headgear, trousers, shirt, footwear).

F3 (BLOCKING) - the palette-math "three independent sources" claim
overcounted: ACViewer's ClothingTableList.xaml.cs:97 computes a different
expression for a different problem, and its vendored PaletteSet.cs is
ACE's own file, not an independent implementation. Rewrote the evidence
paragraph in ChargenPalSetMath.cs to the two sources that actually hold
(decomp control flow + ACE's "Taken from acclient.c" port).

F4 (MEDIUM) - ChargenPreviewEntityBuilder.TryBuild did unlocked dat reads;
DatCollection is not thread-safe and every sibling dat-touching resolver
in this layer takes a shared datLock. Added a required datLock parameter;
every dat read now happens inside one lock, mirroring
RetailPaperdollPoseApplicator.Apply's shape.

F5 (LOW) - noted the pre-existing Streaming.LandblockBuildFactoryTests
timing flake in the ledger so a future session doesn't chase it.

F6 (LOW) - fixed ChargenPreviewCamera.cs's rotation doc, which cited a
nonexistent identifier in a dimensionally-wrong expression; corrected to
retail's actual DoRotation @0x0047CAC7 per-tick formula.

F7 (LOW-MEDIUM) - the TS-82 measurement was WriteLine-only; pinned with
real assertions (zero gaps for the 9 standard heritages, exactly the 4
measured Undead table ids on both genders). Kept the existing env-gated
skip pattern (confirmed house convention).

F8 (LOW) - the inner PalSet-miss loop recorded-and-continued past a miss;
retail's own loop returns immediately on a miss (~0x005A7B32), aborting
every remaining choice in that garment. Changed continue to break; added
a test proving a subsequent present PalSet is correctly not applied.

F9 (LOW) - fixed three dangling <see cref="...Compose"/> doc references
(the method is TryCompose).

F10 (LOW) - the packed (byte)(range/8) narrowing was unchecked; a real
NumColors of 2048 happened to wrap to the correct "whole palette" 0
sentinel by unchecked-cast accident. Replaced with explicit PackOffset/
PackNumColors helpers that document the 2048->0 equivalence deliberately
and throw on any other unrepresentable shape.

F11/F12 (LOW, CC6b scope) - noted in the plan's CC6b row: the second
m_alternateSetupID override source is unmodelled, and a shared
RetailHeldPose helper is worth extracting before a fourth consumer.

Test counts: Core.Tests 4772/1 skip (+5), Content.Tests 147/0 (+1),
App.Tests 5121/6 skips (unchanged; F5's named flake did not reproduce) -
zero failures, full solution Release build green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-15 17:51:14 +02:00
parent 55bfd9ca82
commit 1774d8b298
11 changed files with 561 additions and 120 deletions

View file

@ -93,9 +93,13 @@ public sealed class ChargenPreviewCamera : ICamera
/// (<c>gmCGAppearancePage::m_dRotationPerSec</c>, ctor pseudo-C
/// ~137523-137524 / ~226652-226653: raw double bits low32=0x00000000,
/// high32=0x40080000 → exactly 3.0 — the decompiler shows this cleanly,
/// no reconstruction needed). Consumed by CC6b's rotation controller as
/// <c>360f / RotationDegreesPerSecond</c> — NOT applied here; see this
/// class's own doc comment on why rotation is not a camera concern.
/// no reconstruction needed). Retail's own per-tick formula
/// (<c>gmCGAppearancePage::DoRotation @ 0x0047CA80</c>, pseudo-C
/// ~0x0047CAC7): <c>deltaDegrees = ((now - lastRotateTime) /
/// RotationSecondsPerRevolution) * 360</c> — CC6b's rotation controller
/// consumes this constant in exactly that shape, not as a
/// degrees-per-second rate. NOT applied here; see this class's own doc
/// comment on why rotation is not a camera concern.
/// </summary>
public const float RotationSecondsPerRevolution = 3.0f;

View file

@ -60,74 +60,85 @@ internal static class ChargenPreviewEntityBuilder
/// failure shape <see cref="DatLiveEntityProjectionMaterializer"/> treats
/// as "drop this spawn").
/// </summary>
/// <param name="datLock">
/// Shared exclusion object for every dat read this method performs.
/// <c>DatCollection</c> is NOT thread-safe (see
/// <c>claude-memory/feedback_phase_a1_hotfix_saga.md</c>) — every other
/// dat-touching renderer/resolver in this layer
/// (<c>RetailPaperdollPoseApplicator</c>, <c>PlayerModeController</c>,
/// <c>DatProjectileSetupResolver</c>, <c>EquippedChildRenderController</c>)
/// takes the SAME <c>object datLock</c> the composition root threads
/// through as <c>RuntimeOptions</c>/<c>d.DatLock</c>; callers MUST pass
/// that same shared instance, not a private lock, or this method's reads
/// race every other consumer's.
/// </param>
public static WorldEntity? TryBuild(
IDatReaderWriter dats,
IAnimationLoader animations,
ChargenAppearanceResult appearance,
uint heritageId,
Quaternion heading)
Quaternion heading,
object datLock)
{
ArgumentNullException.ThrowIfNull(dats);
ArgumentNullException.ThrowIfNull(animations);
ArgumentNullException.ThrowIfNull(appearance);
ArgumentNullException.ThrowIfNull(datLock);
Setup? setup = dats.Get<Setup>(appearance.SetupId);
if (setup is null)
return null;
List<MeshRef> meshRefs;
uint setupId = appearance.SetupId;
PaletteOverride? paletteOverride;
PartOverride[] partOverrides;
var flattened = new List<MeshRef>(SetupMesh.Flatten(setup));
foreach (ChargenAnimPartChange change in appearance.ObjDesc.AnimPartChanges)
// Every dat read this method performs — the Setup fetch, the held-
// pose animation resolution, the per-part GfxObj drawable checks,
// and the texture-change surface resolution — happens inside this
// one lock, mirroring RetailPaperdollPoseApplicator.Apply's "resolve
// everything under lock, then do pure processing" shape.
lock (datLock)
{
if (change.PartIndex < flattened.Count)
flattened[change.PartIndex] = new MeshRef(change.PartId, flattened[change.PartIndex].PartTransform);
}
Setup? setup = dats.Get<Setup>(setupId);
if (setup is null)
return null;
ApplyHeldPose(dats, animations, setup, heritageId, flattened);
var flattened = new List<MeshRef>(SetupMesh.Flatten(setup));
Dictionary<int, Dictionary<uint, uint>>? surfaceOverrides =
ResolveSurfaceOverrides(dats, flattened, appearance.ObjDesc.TextureChanges);
var meshRefs = new List<MeshRef>(flattened.Count);
for (int partIndex = 0; partIndex < flattened.Count; partIndex++)
{
MeshRef part = flattened[partIndex];
if (dats.Get<GfxObj>(part.GfxObjId) is null)
continue; // matches DatLiveEntityProjectionMaterializer's drawable filter.
IReadOnlyDictionary<uint, uint>? overrides = null;
if (surfaceOverrides is not null && surfaceOverrides.TryGetValue(partIndex, out var perPart))
overrides = perPart;
meshRefs.Add(new MeshRef(part.GfxObjId, part.PartTransform) { SurfaceOverrides = overrides });
}
if (meshRefs.Count == 0)
return null;
PaletteOverride? paletteOverride = null;
if (appearance.ObjDesc.SubPalettes.Count > 0)
{
var ranges = new PaletteOverride.SubPaletteRange[appearance.ObjDesc.SubPalettes.Count];
for (int i = 0; i < appearance.ObjDesc.SubPalettes.Count; i++)
foreach (ChargenAnimPartChange change in appearance.ObjDesc.AnimPartChanges)
{
ChargenSubPalette sub = appearance.ObjDesc.SubPalettes[i];
ranges[i] = new PaletteOverride.SubPaletteRange(sub.SubPaletteId, sub.Offset, sub.NumColors);
if (change.PartIndex < flattened.Count)
flattened[change.PartIndex] = new MeshRef(change.PartId, flattened[change.PartIndex].PartTransform);
}
paletteOverride = new PaletteOverride(appearance.BasePaletteId, ranges);
}
var partOverrides = new PartOverride[appearance.ObjDesc.AnimPartChanges.Count];
for (int i = 0; i < appearance.ObjDesc.AnimPartChanges.Count; i++)
{
ChargenAnimPartChange change = appearance.ObjDesc.AnimPartChanges[i];
partOverrides[i] = new PartOverride(change.PartIndex, change.PartId);
ApplyHeldPose(dats, animations, setup, heritageId, flattened);
Dictionary<int, Dictionary<uint, uint>>? surfaceOverrides =
ResolveSurfaceOverrides(dats, flattened, appearance.ObjDesc.TextureChanges);
meshRefs = new List<MeshRef>(flattened.Count);
for (int partIndex = 0; partIndex < flattened.Count; partIndex++)
{
MeshRef part = flattened[partIndex];
if (dats.Get<GfxObj>(part.GfxObjId) is null)
continue; // matches DatLiveEntityProjectionMaterializer's drawable filter.
IReadOnlyDictionary<uint, uint>? overrides = null;
if (surfaceOverrides is not null && surfaceOverrides.TryGetValue(partIndex, out var perPart))
overrides = perPart;
meshRefs.Add(new MeshRef(part.GfxObjId, part.PartTransform) { SurfaceOverrides = overrides });
}
if (meshRefs.Count == 0)
return null;
paletteOverride = BuildPaletteOverride(appearance);
partOverrides = BuildPartOverrides(appearance);
}
return new WorldEntity
{
Id = PreviewRenderId,
ServerGuid = PreviewServerGuid,
SourceGfxObjOrSetupId = appearance.SetupId,
SourceGfxObjOrSetupId = setupId,
Position = Vector3.Zero,
Rotation = heading,
MeshRefs = meshRefs,
@ -137,6 +148,35 @@ internal static class ChargenPreviewEntityBuilder
};
}
/// <summary>No dat access — pure projection of the already-composed
/// ObjDesc's subpalettes, safe to call outside <c>datLock</c>.</summary>
private static PaletteOverride? BuildPaletteOverride(ChargenAppearanceResult appearance)
{
if (appearance.ObjDesc.SubPalettes.Count == 0)
return null;
var ranges = new PaletteOverride.SubPaletteRange[appearance.ObjDesc.SubPalettes.Count];
for (int i = 0; i < appearance.ObjDesc.SubPalettes.Count; i++)
{
ChargenSubPalette sub = appearance.ObjDesc.SubPalettes[i];
ranges[i] = new PaletteOverride.SubPaletteRange(sub.SubPaletteId, sub.Offset, sub.NumColors);
}
return new PaletteOverride(appearance.BasePaletteId, ranges);
}
/// <summary>No dat access — pure projection, safe to call outside
/// <c>datLock</c>.</summary>
private static PartOverride[] BuildPartOverrides(ChargenAppearanceResult appearance)
{
var partOverrides = new PartOverride[appearance.ObjDesc.AnimPartChanges.Count];
for (int i = 0; i < appearance.ObjDesc.AnimPartChanges.Count; i++)
{
ChargenAnimPartChange change = appearance.ObjDesc.AnimPartChanges[i];
partOverrides[i] = new PartOverride(change.PartIndex, change.PartId);
}
return partOverrides;
}
/// <summary>
/// Overwrites every part's transform from the resolved rest pose's
/// FINAL frame — same "hold the settled last frame at zero frame rate"

View file

@ -1,7 +1,7 @@
namespace AcDream.Core.CharGen;
/// <summary>
/// The resolved render description <see cref="ChargenAppearanceFactory.Compose"/>
/// The resolved render description <see cref="ChargenAppearanceFactory.TryCompose"/>
/// produces: a body Setup id plus the composed ObjDesc a mesh builder applies
/// to it (<c>CPhysicsObj::DoObjDescChangesFromDefault @ 0x0050F9B0</c> is
/// retail's equivalent apply step). The three diagnostic lists let callers
@ -11,11 +11,15 @@ namespace AcDream.Core.CharGen;
/// <param name="SetupId">
/// The body Setup dat id (0x02......) to build the preview mesh from —
/// <c>gender.SetupId</c>, overridden by the selected hair style's
/// <c>AlternateSetup</c> when nonzero (Gear Knight / Undead / Tumerok body
/// variants), falling back to <see cref="ChargenAppearanceFactory.HumanSetupId"/>
/// when both are zero (retail: <c>CPhysicsObj::makeObject(setupId)</c>'s own
/// HUMAN_SETUP_ID fallback, <c>gmCG3DView</c> ctor pseudo-C ~0x004EE79D and
/// <c>gmCG3DView::Update</c> ~0x004EEA61).
/// <c>AlternateSetup</c> when it is neither 0 nor retail's <c>INVALID_DID</c>
/// (0xFFFFFFFF — Gear Knight / Undead / Tumerok body variants), falling back
/// to <see cref="ChargenAppearanceFactory.HumanSetupId"/> when the resolved
/// id is 0 OR <c>INVALID_DID</c> (retail: <c>CharGenState::GetSetupID @
/// 0x005C5B22</c> and <c>gmCG3DView::Update</c>'s own check at
/// ~0x004EEA51/0x004EEA5F both test against <c>INVALID_DID</c>, not zero —
/// <c>acclient.h:39909</c> types the field as <c>IDClass</c>, whose "unset"
/// value is 0xFFFFFFFF; <c>CPhysicsObj::makeObject(setupId)</c>'s own
/// HUMAN_SETUP_ID fallback, <c>gmCG3DView</c> ctor pseudo-C ~0x004EE79D).
/// </param>
/// <param name="BasePaletteId">
/// <c>gender.BasePaletteId</c> (retail <c>Sex_CG.BasePalette</c>) — the
@ -28,7 +32,7 @@ namespace AcDream.Core.CharGen;
/// </param>
/// <param name="ObjDesc">
/// The composed subpalette/texture/part-swap deltas, in retail's exact
/// application order (see <see cref="ChargenAppearanceFactory.Compose"/>).
/// application order (see <see cref="ChargenAppearanceFactory.TryCompose"/>).
/// </param>
public sealed record ChargenAppearanceResult(
uint SetupId,
@ -86,6 +90,18 @@ public static class ChargenAppearanceFactory
/// </summary>
public const uint HumanSetupId = 0x02000001u;
/// <summary>
/// Retail's <c>IDClass</c> "unset" sentinel (<c>INVALID_DID</c>,
/// 0xFFFFFFFF — <c>acclient.h:39909</c>). <c>CharGenState::GetSetupID @
/// 0x005C5B22</c> and <c>gmCG3DView::Update</c>'s own checks
/// (~0x004EEA51/0x004EEA5F) both test a Setup id against THIS value, not
/// zero — a hair style whose <c>AlternateSetup</c> field happens to
/// store this sentinel must be treated as "no override," exactly like
/// zero, or the factory would hand a bogus Setup id to
/// <c>Get&lt;Setup&gt;</c> and produce no preview at all.
/// </summary>
private const uint InvalidDid = 0xFFFFFFFFu;
/// <summary>
/// Skin subpalette overlay range, retail's hard-coded literal at
/// <c>gmCG3DView::Update</c> ~0x004EF066-0x004EF07E: real byte offset 0,
@ -151,10 +167,10 @@ public static class ChargenAppearanceFactory
&& selection.HairStyle < (uint)gender.HairStyles.Count)
{
hairStyle = gender.HairStyles[(int)selection.HairStyle];
if (hairStyle.AlternateSetup != 0)
if (hairStyle.AlternateSetup != 0 && hairStyle.AlternateSetup != InvalidDid)
setupId = hairStyle.AlternateSetup;
}
if (setupId == 0)
if (setupId == 0 || setupId == InvalidDid)
setupId = HumanSetupId;
// ── 2. ObjDesc accumulation, retail's exact append order ───────
@ -322,15 +338,22 @@ public static class ChargenAppearanceFactory
uint paletteTemplateId = clothingColors[(int)colorIndex];
if (!table.PaletteTemplatesById.TryGetValue(paletteTemplateId, out ChargenClothingPaletteTemplate? template))
return; // retail: hash miss on the palette-template lookup is a silent no-op.
return; // retail: hash miss on the OUTER palette-template lookup is a silent no-op.
foreach (ChargenClothingSubPaletteChoice choice in template.Choices)
{
ChargenPalSet? palSet = palSets.TryGetPalSet(choice.PalSetId);
if (palSet is null)
{
// Retail's own inner loop (ClothingTable::BuildObjDesc
// ~0x005A7B24-0x005A7BD3) returns 0 IMMEDIATELY when
// DBObj::Get fails for one subpalEffect entry's PalSet
// (~0x005A7B32) — aborting every REMAINING choice in this
// same garment's palette template, not merely skipping the
// failed one. `break`, not `continue`, matches that; the
// miss is still recorded so callers can see it happened.
missingPalSets.Add(choice.PalSetId);
continue;
break;
}
int index = ChargenPalSetMath.GetPaletteIndex(palSet.PaletteIds.Count, shade);
@ -342,9 +365,55 @@ public static class ChargenAppearanceFactory
{
subPalettes.Add(new ChargenSubPalette(
paletteId,
(byte)(range.Offset / 8),
(byte)(range.NumColors / 8)));
PackOffset(range.Offset),
PackNumColors(range.NumColors)));
}
}
}
/// <summary>
/// Converts a real (unpacked) clothing subpalette offset into
/// <see cref="ChargenSubPalette"/>'s packed *8 on-disk unit. Throws
/// rather than silently truncating on a shape we've never seen and
/// don't know how to represent losslessly (guards against the
/// unchecked-narrowing footgun a plain <c>(byte)(value / 8)</c> cast
/// would otherwise hide).
/// </summary>
private static byte PackOffset(uint realOffset)
{
if (realOffset % 8u != 0 || realOffset > 2040u)
{
throw new ArgumentOutOfRangeException(
nameof(realOffset),
realOffset,
"Clothing subpalette range offset does not fit the packed *8 byte "
+ "convention (expected a multiple of 8 in [0, 2040]).");
}
return (byte)(realOffset / 8u);
}
/// <summary>
/// Same packing as <see cref="PackOffset"/>, plus retail's own explicit
/// "whole palette" sentinel: a packed <c>NumColors</c> of 0 means "the
/// entire palette" (<see cref="AcDream.Core.World.PaletteOverride"/>'s
/// doc: "Length=0 is a sentinel meaning entire palette... defaulting to
/// 256*8"). A real count of exactly 2048 (256*8) IS that same value
/// spelled out in real units, so it packs to 0 BY DESIGN — not because
/// an unchecked <c>(byte)</c> cast happens to wrap 256 back to 0.
/// </summary>
private static byte PackNumColors(uint realNumColors)
{
if (realNumColors == 2048u)
return 0;
if (realNumColors % 8u != 0 || realNumColors > 2040u)
{
throw new ArgumentOutOfRangeException(
nameof(realNumColors),
realNumColors,
"Clothing subpalette range color count does not fit the packed *8 byte "
+ "convention (expected a multiple of 8 in [0, 2040], or exactly 2048 "
+ "for the whole-palette sentinel).");
}
return (byte)(realNumColors / 8u);
}
}

View file

@ -2,7 +2,7 @@ namespace AcDream.Core.CharGen;
/// <summary>
/// The fourteen style/color indices plus the six f64 shades
/// <see cref="ChargenAppearanceFactory.Compose"/> needs to build a preview
/// <see cref="ChargenAppearanceFactory.TryCompose"/> needs to build a preview
/// description — field-for-field the same shape as CC3's
/// <c>AcDream.Runtime.Session.RuntimeCharacterCreationAppearance</c> (and,
/// through it, <c>CharacterCreate.Appearance</c>'s wire fields), kept as a

View file

@ -85,31 +85,35 @@ public sealed record ChargenClothingBaseEffect(
/// Penumbraen, Undead skeleton/zombie, Anakshay) when
/// <see cref="BaseEffectsBySetupId"/> has no direct entry for the requested
/// body Setup. CC6a's composer looks up <see cref="BaseEffectsBySetupId"/>
/// directly and skips a slot's part/texture contribution on a miss
/// (matching retail's own "hash miss → BuildObjDesc returns failure, caller
/// does not check it, ObjDesc keeps whatever it already had" behavior)
/// rather than porting the substitution chain. The installed-DAT catalog
/// test (<c>ChargenAppearanceCatalogInstalledDatTests</c>) MEASURED this
/// directly across all 26 heritage/gender combinations rather than assuming
/// it: for the 9 standard heritages where retail's own UI actually shows
/// clothing controls (everything except Gear Knight and the two Olthoi
/// variants, which retail hides the clothes button for entirely —
/// <c>gmCGAppearancePage::Update @ 0x0047E8F0</c>'s
/// directly and skips a slot's part/texture contribution on a miss (this is
/// the OUTER lookup — <c>ClothingTable::_cloBaseHash</c> — whose retail
/// miss behavior is genuinely a no-op the caller never checks; the SEPARATE
/// inner per-choice PalSet lookup inside the same function's subpalette loop
/// has its own, stricter, abort-on-miss behavior — see
/// <c>ChargenAppearanceFactory.ComposeClothingSlot</c>'s own doc, ported
/// faithfully there) rather than porting the Setup-substitution chain. The
/// installed-DAT catalog test (<c>ChargenAppearanceCatalogInstalledDatTests</c>)
/// MEASURED this directly across all 26 heritage/gender combinations rather
/// than assuming it: for the 9 standard heritages where retail's own UI
/// actually shows clothing controls (everything except Gear Knight and the
/// two Olthoi variants, which retail hides the clothes button for entirely
/// — <c>gmCGAppearancePage::Update @ 0x0047E8F0</c>'s
/// <c>m_pClothesButton->SetVisible(0)</c> branches for
/// <c>mHeritageGroup == 6</c> and <c>== 0xc || == 0xd</c>), the default
/// gear choices resolve against their own body Setup with ZERO missing
/// coverage. <b>Undead IS a real gap</b> — retail DOES show clothing
/// controls for Undead, but its default headgear/trousers/footwear choices
/// have no <see cref="BaseEffectsBySetupId"/> entry for either gender's
/// live Setup id (measured: 4 of 4 non-shirt slots miss, on both genders),
/// because Undead's live body Setup IS one of the skeleton/zombie variants
/// the un-ported substitution chain exists to redirect. A live preview for
/// Undead will therefore render its default headgear/trousers/footwear
/// choice with NO part/texture override applied (the underlying body shows
/// through unclothed for those slots) until the substitution chain — or an
/// equivalent per-heritage default-clothing-setup mapping — lands. Filed as
/// a known CC6a limitation for CC6b/a follow-up rather than silently
/// "confirmed unreachable."
/// controls for Undead, and MEASURED coverage is missing for <b>ALL FOUR</b>
/// clothing slots (headgear, trousers, shirt, AND footwear — not just three
/// of the four), on both genders: neither gender's live body Setup has a
/// <see cref="BaseEffectsBySetupId"/> entry in any of its four default gear
/// choices' clothing tables, because Undead's live body Setup IS one of the
/// skeleton/zombie variants the un-ported substitution chain exists to
/// redirect. A live preview for Undead will therefore render its default
/// clothing selection with NO part/texture override applied on any of the
/// four slots (the underlying body shows through unclothed) until the
/// substitution chain — or an equivalent per-heritage default-clothing-setup
/// mapping — lands. Filed as a known CC6a limitation for CC6b/a follow-up
/// rather than silently "confirmed unreachable."
/// </para>
/// </summary>
public sealed record ChargenClothingTable(

View file

@ -5,17 +5,25 @@ namespace AcDream.Core.CharGen;
/// (<c>PalSet::GetPaletteID @ 0x005AC570</c>, invoked from
/// <c>gmCG3DView::Update @ 0x004EE9D0</c> for the skin/hair subpalette
/// build and from <c>ClothingTable::BuildObjDesc @ 0x005A7900</c> for every
/// clothing-slot dye choice). The decompiled body is FPU-elided (the x87
/// bounds-compare against 0.0/1.0 and the truncating <c>_ftol2()</c> cast
/// lose their operands to the decompiler), but ACE's
/// <c>ACE.DatLoader.FileTypes.PaletteSet.GetPaletteID</c> carries the
/// explicit comment "Taken from acclient.c (PalSet::GetPaletteID)" with the
/// exact formula below — corroborated by the decomp's own control-flow
/// shape (a two-sided FPU compare consistent with a <c>[0,1]</c> bounds
/// check, then one truncating cast) and independently by ACViewer's
/// <c>ClothingTableList.xaml.cs:97</c> UI slider, which reimplements the
/// identical <c>(count - 0.000001) * shade</c> expression for its own shade
/// preview. Three independent sources agree.
/// clothing-slot dye choice). The decompiled body is genuinely FPU-elided —
/// the <c>_ftol2()</c> truncating-cast operand is lost to the decompiler,
/// and can only be read as "some product of <paramref name="count"/>-ish and
/// <paramref name="shade"/>-ish operands" from the surrounding x87 stack
/// traffic — but the decomp's own control-flow SHAPE is still verifiable
/// independent of that lost operand: a two-sided FPU compare at
/// <c>0x005AC5A0</c> gating on <c>&gt;= 0.0</c>, consistent with a
/// <c>[0,1]</c> shade bounds check before the cast. What resolves the
/// elided operand is ACE's <c>ACE.DatLoader.FileTypes.PaletteSet.GetPaletteID</c>,
/// which carries the explicit comment "Taken from acclient.c
/// (PalSet::GetPaletteID)" against the exact formula below. That is TWO
/// sources (decomp control flow + ACE's cited port), not three: the
/// <c>PaletteSet.cs</c> file present in the vendored ACViewer checkout is
/// ACE's own file, not an independent reimplementation, and ACViewer's
/// <c>ClothingTableList.xaml.cs:97</c> UI slider computes a DIFFERENT
/// expression for a DIFFERENT problem (mapping a shade back to a slider tick
/// position against <c>Shades.Maximum</c>, i.e. <c>count-1</c>, not
/// <c>count</c>) — neither corroborates this formula and both are dropped
/// from the evidence chain here.
/// </summary>
public static class ChargenPalSetMath
{