mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
Modern arg-order shape (unit first, questID second; questID-keyed). Walks the unit's +0xE68 sub-struct quest list at +0x28 — same data source as the engine's IsUnitOnQuest(logIndex, unit). Single Lua call covers both "is the player on it" and "is a party/raid member on it" without making the caller find a matching log index first. Crash hazard fix: the +0xE68 sub-struct is uninitialized for NPCs (CGCreature_C). First attempt gated on `[unit + 0xE4] & 1` (the engine's own pre-check before +0xE68 derefs in SetUnitBuff etc.) but that wasn't sufficient — passing an NPC token still AV'd in the quest-list walk. The engine's Script_IsUnitOnQuest gets away with the weaker gate because its GUID-type-filtered ObjMgr lookup (FUN_00468460(0x10, ...)) rejects non-player GUIDs upstream; FUN_RESOLVE_UNIT_TOKEN doesn't have that filter. Switched to UNIT_FLAG_PLAYER_CONTROLLED, which is the gate Item::InventoryID and Unit::Flags already use for the same hazard. While doing that, extracted IsPlayerControlled to Unit::Flags:: (new Flags.h) as the canonical predicate. Removed the file-static copy in Item::InventoryID and collapsed two inline copies in Unit::Flags (TestPlayerFlag, ReadGuildKey) to call the shared helper.