acdream/tools/SpellDump/Program.cs
Erik 46ce6f238c feat: regen buffs, wand aura, spellbook assess, indicator press flash
Four reports from one gate round. Three were mine; the fourth I first
mis-explained, and the correction is the useful part.

**The vital regeneration rates were never cast.** Regeneration (health),
Rejuvenation (stamina) and Mana Renewal (mana) all landed in the catch-all
Other bucket, which is off by default. Retail words each of the three
differently and two of the six phrasings do not begin with "Increases the
caster's" at all:

    Increase caster's natural healing rate by 10%.                 <- and note "Increase"
    Increases your Health Regeneration Rate by 50%.                (Empyrean)
    Increases the rate at which the caster regains Stamina by 10%.
    Increases the caster's natural mana rate by 10%.

They are matched per vital, on by default, and ranked at the very tail of the
Life group so they finish the pass. The mana line had to be checked BEFORE the
generic "Increases the caster's X by N" match, which would otherwise read it as
a buff to a stat named "natural mana rate".

**Aura of Hermetic Link was the sixth aura line and the only one missed.**
"a magic casting implement's" is reached by none of the other alternatives, so
the wand's mana-conversion buff was silently in Other too.

**Right-clicking a spell in the spellbook did nothing.** I claimed this had
never worked; the user said it used to, and they were right -- I had checked
one file's history and concluded from it. The regression is 3e31b0ac, which
gave UiCatalogSlot its own RightClick case returning true unconditionally. On
any list that had not wired the examine seam -- the spellbook among them -- the
event was reported handled and UiRoot stopped bubbling. Two fixes: the row now
reports an unwired right-click UNHANDLED so bubbling continues, and the
spellbook wires the seam to the same appraisal window the spell bar uses.

Retail does this generically in the list rather than per window
(UIElement_ItemList::ListenToElementMessage @ 0x004E4F1F -> ExamineSpell
@ 0x00564A70), which is exactly why a per-controller seam could be forgotten
for one window and not another.

**No green flash when pressing an indicator.** Every indicator button authors
a full-size 0x100000F2 child whose DirectState is a draw-nothing File=0 image
and whose only other state, Normal_pressed, carries the green selector sprite
0x06004CE8 -- and the buttons author Normal_pressed with PassToChildren. But
UiButton.ConsumesDatChildren drops dat children at import, so the cascade had
nothing left to reach. The child is re-attached through the same repair the map
hotspot's rollover highlight already uses.

**tools/LayoutDump** is new, and is why the last two are diagnoses rather than
guesses: it prints an authored LayoutDesc tree -- geometry, edge modes, state
sets, PassToChildren, per-state media -- straight from the installed DATs.
"Does this button even have a pressed state?" was being answered by reading our
own importer and inferring; now it is read from the data.

Solution builds clean; 14,464 tests pass on the standard hermetic lane filter,
0 failures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 20:38:28 +02:00

104 lines
4.5 KiB
C#

// Dump self-targeted beneficial spells from portal.dat's SpellTable so buff
// selection can be built on what the data actually says rather than on
// remembered spell names.
using AcDream.Content;
using AcDream.Core.Spells;
using DatReaderWriter;
using DatReaderWriter.Options;
using SysEnv = System.Environment;
string datDir = SysEnv.GetEnvironmentVariable("ACDREAM_DAT_DIR")
?? Path.Combine(SysEnv.GetFolderPath(SysEnv.SpecialFolder.UserProfile),
"Documents", "Asheron's Call");
using var dats = new DatCollection(datDir, DatAccessType.Read);
using var adapter = new DatCollectionAdapter(dats);
MagicCatalog catalog = MagicCatalog.Load(adapter);
SpellTable table = catalog.SpellTable;
Console.WriteLine($"spells loaded: {table.Count}");
if (args.Length > 0 && args[0] == "--cursors")
{
// Resolve the retail global-cursor enum table (6) to DAT surface ids, the
// same walk RetailCursorResolver does: portal master map -> table 6 -> id.
uint masterDid = (uint)dats.Portal.Header.MasterMapId;
if (!dats.Portal.TryGet<DatReaderWriter.DBObjs.EnumIDMap>(masterDid, out var master) || master is null)
throw new InvalidOperationException("no master enum map");
if (!master.ClientEnumToID.TryGetValue(6u, out uint cursorMapDid))
throw new InvalidOperationException("no cursor enum table 6");
if (!dats.Portal.TryGet<DatReaderWriter.DBObjs.EnumIDMap>(cursorMapDid, out var cursorMap) || cursorMap is null)
throw new InvalidOperationException("cursor map missing");
foreach (var kv in cursorMap.ClientEnumToID.OrderBy(k => k.Key))
Console.WriteLine($"cursorEnum 0x{kv.Key:X2} -> surface 0x{kv.Value:X8}");
return;
}
if (args.Length > 0 && args[0] == "--flags")
{
string want = args.Length > 1 ? args[1].ToLowerInvariant() : "bane";
foreach (uint id in table.SpellIds.OrderBy(i => i))
{
if (!table.TryGet(id, out var m)) continue;
if (!m.Name.ToLowerInvariant().Contains(want)) continue;
if (m.Generation != 1 && !m.Name.Contains(" I", StringComparison.Ordinal)) continue;
Console.WriteLine(
$"0x{m.SpellId:X4} fam{m.Family,-5} gen{m.Generation,-3} " +
$"flags=0x{m.Flags:X4} mask=0x{m.TargetMask:X4} " +
$"self={m.IsSelfTargeted,-5} unt={m.IsUntargeted,-5} ben={m.IsBeneficial,-5} " +
$"school={m.School,-20} {m.Name,-28} | {m.Description}");
}
return;
}
if (args.Length > 0 && args[0] == "--desc")
{
foreach (uint id in table.SpellIds.OrderBy(i => i))
{
if (!table.TryGet(id, out var m)) continue;
if (!m.IsSelfTargeted || !m.IsBeneficial || m.IsDebuff) continue;
// One representative per line by default; a name filter lifts that so
// the higher tiers' wording can be checked (they do not always match).
string descFilter = args.Length > 1 ? args[1].ToLowerInvariant() : "";
if (descFilter.Length == 0 && m.Generation != 1) continue;
if (descFilter.Length != 0 && !m.Name.ToLowerInvariant().Contains(descFilter)) continue;
Console.WriteLine($"fam {m.Family,-5} 0x{m.SpellId:X4} {m.Name,-40} | {m.Description}");
}
return;
}
if (args.Length > 0 && args[0] == "--skills")
{
var skillTable = dats.Get<DatReaderWriter.DBObjs.SkillTable>(0x0E000004u)
?? throw new InvalidOperationException("SkillTable 0x0E000004 missing");
Console.WriteLine($"skills: {skillTable.Skills.Count}");
foreach (var kv in skillTable.Skills.OrderBy(k => (uint)k.Key))
Console.WriteLine($" {(uint)kv.Key,-4} {kv.Value.Name}");
return;
}
if (args.Length > 0 && args[0] == "--enum")
{
string outPath = args.Length > 1
? args[1]
: Path.Combine("src", "AcDream.Plugins.MossTank", "SpellId.g.cs");
SpellDump.EmitEnum.Run(table, outPath, "AcDream.Plugins.MossTank", "SpellId");
return;
}
string filter = args.Length > 0 ? args[0].ToLowerInvariant() : "";
var rows = table.SpellIds
.Select(id => table.TryGet(id, out var m) ? m : null)
.Where(s => s is not null)!
.Select(s => s!)
.Where(s => s.IsSelfTargeted && s.IsBeneficial && !s.IsDebuff)
.Where(s => filter.Length == 0 || s.Name.ToLowerInvariant().Contains(filter))
.OrderBy(s => s.Family).ThenBy(s => s.Generation)
.ToList();
Console.WriteLine($"self-targeted beneficial: {rows.Count}\n");
Console.WriteLine($"{"family",-8} {"gen",-4} {"id",-8} {"school",-12} {"mana",-5} {"dur",-8} name");
foreach (var s in rows)
{
Console.WriteLine(
$"{s.Family,-8} {s.Generation,-4} 0x{s.SpellId:X4} {s.School,-12} {s.ManaCost,-5} {s.Duration,-8:F0} {s.Name}");
}