mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
fix(macro): keep the unlearn sweep from deleting #showtooltip macros
The spell-removal handler FUN_005E9FE0 calls FUN_004E5E20(spellID) right after the unlearn writer. That sweep walks all 0x78 action slots, resolves each through FUN_ACTION_SLOT_TO_SPELL -- which is macro-aware, so a macro slot answers with the primary-spell cache this module writes -- and clears every slot whose spell matches. The clear notifies with sendToServer = 1, so CMSG_SET_ACTION_BUTTON goes out and the server persists it: the macro is gone for good, not until the next reload. That rule is sound for a cache the engine filled from a /cast line and wrong for one filled from a display directive, which names an icon rather than what the button does. `#showtooltip [known:18223] 18223` over a /cast the player can still perform would lose the whole macro on a respec, and a conditional directive makes it arbitrary besides -- the cached value is whichever clause happened to match on the last evaluation. Co-hook the sweep and park every managed macro's cache at 0 for its duration, restoring afterwards with a plain field write (nothing we own changed, so no repaint is owed; the slots the engine really did clear were announced by its own notify). A BusyScope wraps it because the sweep's ACTIONBAR_SLOT_CHANGED handlers reach Lookup, whose catch-up would otherwise re-apply the parked values mid-sweep for slots the loop has yet to reach. Macros with no directive are untouched. Consequence: a plain #showtooltip macro whose /cast line names the unlearned spell now also survives, where stock 1.12 removed it.
This commit is contained in:
@@ -4741,6 +4741,22 @@ enum Offsets {
|
||||
// packet (verified by disassembly: the packet build is the `edx != 0`
|
||||
// branch, the event fire the `[esp+4] == 0` branch).
|
||||
FUN_ACTION_SLOT_CHANGED_NOTIFY = 0x004E58E0,
|
||||
// Single-slot clear — `__fastcall(uint slot0)`: writes
|
||||
// `VAR_ACTION_TABLE[slot0] = 0` then FUN_ACTION_SLOT_CHANGED_NOTIFY(slot0,
|
||||
// /*sendToServer=*/1, 0), so the removal goes out as CMSG_SET_ACTION_BUTTON
|
||||
// and the server persists it.
|
||||
FUN_ACTION_SLOT_CLEAR = 0x004E5DB0,
|
||||
// The unlearn sweep — `__fastcall(uint spellID)`. Walks all
|
||||
// ACTION_TABLE_MAX_SLOTS slots, resolves each through
|
||||
// FUN_ACTION_SLOT_TO_SPELL, and FUN_ACTION_SLOT_CLEARs every slot whose
|
||||
// spell equals `spellID`. Sole caller is the spell-removal handler
|
||||
// FUN_005E9FE0, immediately after FUN_UNLEARN_SPELL (verified by
|
||||
// disassembly + xrefs). Because the resolver is macro-aware — a macro slot
|
||||
// answers with its primary-spell cache — a macro whose cache holds the
|
||||
// unlearned spell is permanently removed from the action bar, which is why
|
||||
// `Macro::ShowTooltip` co-hooks this to keep its DISPLAY resolution out of
|
||||
// the comparison.
|
||||
FUN_ACTION_BAR_PRUNE_SPELL = 0x004E5E20,
|
||||
// Count of `itemID` the player carries, as `UseAction` caches per
|
||||
// item-by-ID slot into VAR_ACTION_ITEM_COUNTS — `uint __fastcall(uint
|
||||
// itemID)`. Charged items (ItemStats `SPELL_CHARGES[0]` set) sum charges
|
||||
|
||||
@@ -52,6 +52,11 @@
|
||||
// `Util/SecureStateDriver.lua` already uses for the same evaluator);
|
||||
// static ones every second (a newly learned rank / newly looted item —
|
||||
// the engine never re-parses a resolved macro on its own).
|
||||
// - Unlearn. The engine's own sweep clears any action slot whose spell was
|
||||
// just unlearned, and it resolves macro slots through the cache above — so
|
||||
// a display resolution could get a working macro permanently deleted off
|
||||
// the bar (the clear is sent to the server). `PruneSpell_h` parks every
|
||||
// managed macro's cache across the sweep; see it for the full trail.
|
||||
// - One deliberate divergence from 3.3.5 (user decision), in the PARSER
|
||||
// rather than here: a group whose only piece is `@unit` passes only while
|
||||
// that unit exists (Util/MacroOptions.lua `GroupPasses`). 3.3.5 passes it
|
||||
@@ -784,6 +789,70 @@ void MaintainExternal(void *L) {
|
||||
}
|
||||
}
|
||||
|
||||
// Keep our resolution out of the engine's unlearn sweep.
|
||||
//
|
||||
// `FUN_ACTION_BAR_PRUNE_SPELL` runs straight after the unlearn writer and
|
||||
// walks every action slot, resolving each through the MACRO-AWARE
|
||||
// `FUN_ACTION_SLOT_TO_SPELL` — for a macro slot, the primary-spell cache this
|
||||
// module writes — and clears every slot whose spell is the one just unlearned.
|
||||
// The clear is `FUN_ACTION_SLOT_CLEAR`, which notifies with `sendToServer = 1`,
|
||||
// so a CMSG_SET_ACTION_BUTTON goes out and the removal is persisted: the macro
|
||||
// is gone for good, not until the next reload.
|
||||
//
|
||||
// That rule is sound for a cache the engine filled from a `/cast` line. It is
|
||||
// wrong for one we filled from a DISPLAY directive, which names an icon rather
|
||||
// than what the button does — `#showtooltip [known:18223] 18223` over a
|
||||
// `/cast` the player can still perform would lose the whole macro on a respec.
|
||||
// A conditional directive makes it arbitrary besides: the cached value is
|
||||
// whichever clause happened to match on the last evaluation.
|
||||
//
|
||||
// So for the length of the sweep every macro we describe shows a cache of `0`,
|
||||
// which no real spellID matches, and gets its value back afterwards. A macro
|
||||
// with no directive is never touched and keeps stock behaviour. The restore is
|
||||
// a plain field write with no repaint — it puts back exactly what was there a
|
||||
// moment earlier, and the slots the engine really did clear were announced by
|
||||
// the engine's own notify.
|
||||
//
|
||||
// The directive itself catches up on its own: the spellbook just changed, so
|
||||
// the next evaluation re-runs `[known:…]` against it and repaints if the
|
||||
// answer moved.
|
||||
using PruneSpell_t = void(__fastcall *)(uint32_t spellID);
|
||||
PruneSpell_t g_origPruneSpell = nullptr;
|
||||
|
||||
void __fastcall PruneSpell_h(uint32_t spellID) {
|
||||
// The sweep's ACTIONBAR_SLOT_CHANGED handlers run our action overrides,
|
||||
// which reach `Lookup` — and its catch-up would re-apply the very values
|
||||
// we just parked, mid-sweep, for every slot the loop has yet to reach.
|
||||
BusyScope busy;
|
||||
|
||||
uint8_t *entries[kMaxMacros];
|
||||
uint32_t saved[kMaxMacros];
|
||||
int savedCount = 0;
|
||||
for (Entry &e : g_entries) {
|
||||
if (e.macroID == 0)
|
||||
continue;
|
||||
// Exactly the macros this module drives — the same test `CatchUp` uses
|
||||
// to decide what it may evaluate, plus published ones.
|
||||
const bool managed =
|
||||
e.external || (e.kind != Kind::None && e.optionCount > 0 && !e.foreign);
|
||||
if (!managed)
|
||||
continue;
|
||||
uint8_t *entry = EntryForID(e.macroID);
|
||||
if (entry == nullptr)
|
||||
continue;
|
||||
auto &cache = Game::Ref<uint32_t>(entry, Offsets::OFF_MACRO_PRIMARY_SPELL);
|
||||
entries[savedCount] = entry;
|
||||
saved[savedCount] = cache; // whatever is there, ours or the engine's
|
||||
++savedCount;
|
||||
cache = 0;
|
||||
}
|
||||
|
||||
g_origPruneSpell(spellID);
|
||||
|
||||
for (int i = 0; i < savedCount; ++i)
|
||||
Game::Ref<uint32_t>(entries[i], Offsets::OFF_MACRO_PRIMARY_SPELL) = saved[i];
|
||||
}
|
||||
|
||||
// Read `CleveRoids.<field>` as a boolean. The table is already at the top of
|
||||
// the stack; leaves the stack as it found it apart from what the caller pops.
|
||||
bool ReadCleveRoidsFlag(void *L, const char *field) {
|
||||
@@ -1034,6 +1103,9 @@ bool LookupEntries(uint32_t macroID, Info *out) {
|
||||
const Tick::WorldTick::AutoSubscribe _tick{&Tick};
|
||||
const Game::ReloadAutoRegister _reload{&PrepareForReload};
|
||||
const Spell::MacroPrimarySpell::PostParseAutoRegister _parsed{&OnMacroParsed};
|
||||
const Game::HookAutoRegister _hookPruneSpell{
|
||||
Offsets::FUN_ACTION_BAR_PRUNE_SPELL, reinterpret_cast<void *>(&PruneSpell_h),
|
||||
reinterpret_cast<void **>(&g_origPruneSpell)};
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user