diff --git a/src/aura/Api.cpp b/src/aura/Api.cpp index 04fd3208..7a1680a9 100644 --- a/src/aura/Api.cpp +++ b/src/aura/Api.cpp @@ -46,14 +46,10 @@ namespace Aura::Api { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - const uint8_t *ResolveUnit(const char *token) { if (token == nullptr) return nullptr; - auto fn = reinterpret_cast( - static_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN)); - return static_cast(fn(token)); + return static_cast(Game::ResolveUnitToken(token)); } // Resolves a token to its GUID for the out-of-range (no live CGUnit) path. diff --git a/src/aura/Data.cpp b/src/aura/Data.cpp index 1ca0d401..efefc319 100644 --- a/src/aura/Data.cpp +++ b/src/aura/Data.cpp @@ -77,13 +77,9 @@ const char *SpellIconPath(const uint8_t *spellRecord) { Offsets::OFF_SPELLICON_PATH); } -using ResolveUnitToken_t = void *(__fastcall *)(const char *); - // Returns the local player's CGUnit pointer, or nullptr pre-login. const uint8_t *LocalPlayer() { - auto fn = reinterpret_cast( - static_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN)); - return static_cast(fn("player")); + return static_cast(Game::ResolveUnitToken("player")); } // Looks up the player-buff-table entry for a given spellID. The table diff --git a/src/debug/Probe.cpp b/src/debug/Probe.cpp index c5bf0078..91d4529b 100644 --- a/src/debug/Probe.cpp +++ b/src/debug/Probe.cpp @@ -64,11 +64,8 @@ namespace Debug::Probe { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - const uint8_t *ResolvePlayer() { - auto fn = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - return static_cast(fn("player")); + return static_cast(Game::ResolveUnitToken("player")); } const uint8_t *ResolvePlayerDescriptor() { diff --git a/src/faction/Info.cpp b/src/faction/Info.cpp index 60138cf8..ed70b850 100644 --- a/src/faction/Info.cpp +++ b/src/faction/Info.cpp @@ -69,10 +69,7 @@ void PushFlag(void *L, bool value) { // `[player + 0xE68]`. Returns nullptr if "player" isn't resolvable // or the sub-struct is uninitialized (pre-login / glue). const uint8_t *PlayerInfo() { - using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - auto resolve = reinterpret_cast( - Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(resolve("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); if (player == nullptr) return nullptr; return *reinterpret_cast( diff --git a/src/item/Equipment.cpp b/src/item/Equipment.cpp index 4163c789..66188817 100644 --- a/src/item/Equipment.cpp +++ b/src/item/Equipment.cpp @@ -200,11 +200,8 @@ int __fastcall Script_C_Item_EquipItemByName(void *L) { if (!Item::Cursor::PickupBagItem(L, found.bagID, found.slotIndex)) return 0; - using ResolveUnitToken_t = void *(__fastcall *)(const char *token); using AutoEquipCursor_t = void (__thiscall *)(void *player, int flag); - auto resolve = reinterpret_cast( - Offsets::FUN_RESOLVE_UNIT_TOKEN); - if (auto *player = resolve("player")) { + if (auto *player = Game::ResolveUnitToken("player")) { auto equip = reinterpret_cast( Offsets::FUN_AUTO_EQUIP_CURSOR_ITEM); equip(player, 0); diff --git a/src/item/InventoryID.cpp b/src/item/InventoryID.cpp index 55647065..3ac3f05c 100644 --- a/src/item/InventoryID.cpp +++ b/src/item/InventoryID.cpp @@ -24,11 +24,9 @@ namespace { using GetItemBySlot_t = void *(__thiscall *)(void *invMgr, int slot); using GetVisibleItem_t = void *(__thiscall *)(void *unit, int slot); -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); void *ResolveUnit(const char *token) { - auto fn = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - return fn(token); + return Game::ResolveUnitToken(token); } // Walks the local player's private inventory manager — the same path diff --git a/src/item/Usable.cpp b/src/item/Usable.cpp index 3f0428dc..0da377ca 100644 --- a/src/item/Usable.cpp +++ b/src/item/Usable.cpp @@ -50,12 +50,10 @@ namespace Item::Usable { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); using SpellIsUsable_t = int(__fastcall *)(const uint8_t *spellRecord, int *outNoMana); const uint8_t *PlayerDescriptor() { - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(resolve("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); if (player == nullptr) return nullptr; return *reinterpret_cast( diff --git a/src/loot/Nearby.cpp b/src/loot/Nearby.cpp index a026b7ef..ae5af660 100644 --- a/src/loot/Nearby.cpp +++ b/src/loot/Nearby.cpp @@ -49,8 +49,6 @@ using ClntObjMgrEnumVisibleObjectsCallback_t = int(__fastcall *)(void *ctx, using ClntObjMgrEnumVisibleObjects_t = int(__fastcall *)(ClntObjMgrEnumVisibleObjectsCallback_t cb, void *ctx); -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // `__thiscall(self, outBuf) → const C3Vector *` at vtable slot 5 // (byte offset `0x14`). Both CGUnit_C and CGPlayer_C populate the // caller-provided 12-byte buffer with the unit's world position and @@ -182,9 +180,7 @@ int __fastcall Script_GetNearbyLootableUnits(void *L) { // Resolve the local player once — the canonical CGPlayer_C the // engine's own interact-range checks use, distinct from the // `VAR_LOCAL_PLAYER_PTR` global. Bail if unavailable. - auto ResolveUnitToken = reinterpret_cast( - Offsets::FUN_RESOLVE_UNIT_TOKEN); - const void *player = ResolveUnitToken("player"); + const void *player = Game::ResolveUnitToken("player"); if (player == nullptr) return 1; diff --git a/src/loot/Scan.cpp b/src/loot/Scan.cpp index 298277c9..98c2e978 100644 --- a/src/loot/Scan.cpp +++ b/src/loot/Scan.cpp @@ -105,7 +105,6 @@ using ClntObjMgrEnumVisibleObjectsCallback_t = int(__fastcall *)(void *ctx, uint64_t guid); using ClntObjMgrEnumVisibleObjects_t = int(__fastcall *)(ClntObjMgrEnumVisibleObjectsCallback_t cb, void *ctx); -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); using LootUnit_t = void(__thiscall *)(void *player, void *target, char useDistanceCheck); using CloseLootInner_t = void(__fastcall *)(int sendRelease, @@ -443,9 +442,7 @@ bool BeginWalk(bool lootMode, size_t maxCount) { return false; if (*reinterpret_cast(Offsets::VAR_LOCAL_PLAYER_PTR) == nullptr) return false; - auto Resolve = reinterpret_cast( - Offsets::FUN_RESOLVE_UNIT_TOKEN); - void *player = Resolve("player"); + void *player = Game::ResolveUnitToken("player"); if (player == nullptr) return false; diff --git a/src/loot/Unit.cpp b/src/loot/Unit.cpp index 5af452b1..53d41ce2 100644 --- a/src/loot/Unit.cpp +++ b/src/loot/Unit.cpp @@ -22,8 +22,6 @@ namespace Loot::Unit { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // `FUN_CMSG_LOOT_UNIT` is `__thiscall(player, target, useDistanceCheck)`. // MSVC `__thiscall` puts `player` in ECX and the rest on the stack — // matching the engine's own callsite at `FUN_0060FA20`. The trailing @@ -74,9 +72,7 @@ int __fastcall Script_LootUnit(void *L) { // `ResolveUnitToken("player")` gives the canonical CGPlayer_C the // engine uses for `__thiscall` calls — distinct from the global // at `VAR_LOCAL_PLAYER_PTR` (see the comment on that offset). - auto ResolveUnitToken = reinterpret_cast( - Offsets::FUN_RESOLVE_UNIT_TOKEN); - void *player = ResolveUnitToken("player"); + void *player = Game::ResolveUnitToken("player"); if (player == nullptr) return 0; diff --git a/src/loot/UnitItem.cpp b/src/loot/UnitItem.cpp index 24c55479..68c0b311 100644 --- a/src/loot/UnitItem.cpp +++ b/src/loot/UnitItem.cpp @@ -39,7 +39,6 @@ enum class State { WaitingOpen, }; -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); using LootUnit_t = void(__thiscall *)(void *player, void *target, char useDistanceCheck); // `FUN_005E1AD0` is `__stdcall(uint8_t)`, not `__fastcall` — the @@ -164,9 +163,7 @@ int __fastcall Script_LootUnitItem(void *L) { return 1; } - auto Resolve = reinterpret_cast( - Offsets::FUN_RESOLVE_UNIT_TOKEN); - void *player = Resolve("player"); + void *player = Game::ResolveUnitToken("player"); if (player == nullptr) { Game::Lua::PushBool(L, false); return 1; diff --git a/src/map/Overlays.cpp b/src/map/Overlays.cpp index 97ee7b77..6b033350 100644 --- a/src/map/Overlays.cpp +++ b/src/map/Overlays.cpp @@ -377,15 +377,12 @@ void PushTiles(void *L, const ResolvedOverlay *r, const char *basePath, } } -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // The local player's explored-areas bitfield (`[player+0xE68] + 0xE6C`), or // null before the player is resident. Bit `AreaBit` set == that AreaTable // area is explored. Same storage the engine's discovered-overlay rebuild // (FUN_004a67a0) reads. const uint8_t *ExplorationBits() { - auto fn = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(fn("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); if (player == nullptr) return nullptr; auto *sub = Game::Read(player, Offsets::OFF_CGPLAYER_INFO); diff --git a/src/player/InputEvents.cpp b/src/player/InputEvents.cpp index 12f22f24..047d983e 100644 --- a/src/player/InputEvents.cpp +++ b/src/player/InputEvents.cpp @@ -65,15 +65,12 @@ bool g_havePrevBodyYaw = false; float g_prevCameraYaw = 0.0f; bool g_havePrevCameraYaw = false; -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - const uint8_t *Controller() { return Game::Read(Offsets::VAR_UI_INPUT_CONTROLLER); } const uint8_t *Player() { - auto fn = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - return static_cast(fn("player")); + return static_cast(Game::ResolveUnitToken("player")); } const uint8_t *Camera() { diff --git a/src/quest/Log.cpp b/src/quest/Log.cpp index e428f9f3..ef779566 100644 --- a/src/quest/Log.cpp +++ b/src/quest/Log.cpp @@ -21,8 +21,6 @@ namespace Quest::Log { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // Walks the unit's `+0xE68` sub-struct quest list (20 slots, stride // 0xC) and returns true on first match. Mirrors the engine's loop in // `Script_IsUnitOnQuest` (`0x004DFE10`). @@ -225,9 +223,7 @@ static int __fastcall Script_IsUnitOnQuest(void *L) { return 1; } - auto resolve = reinterpret_cast( - static_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN)); - auto *unit = static_cast(resolve(token)); + auto *unit = static_cast(Game::ResolveUnitToken(token)); Game::Lua::PushBool(L, UnitHasQuest(unit, target)); return 1; } diff --git a/src/spell/AtCursor.cpp b/src/spell/AtCursor.cpp index 583c86d7..41517a99 100644 --- a/src/spell/AtCursor.cpp +++ b/src/spell/AtCursor.cpp @@ -58,10 +58,7 @@ bool InWorld() { // Player resolves only when in-world. Same gate other modules // (e.g. `Item::Location::ResolveBag`) use to avoid touching // engine state during loading screens or glue. - using ResolveUnitToken_t = void *(__fastcall *)(const char *); - auto fn = reinterpret_cast( - Offsets::FUN_RESOLVE_UNIT_TOKEN); - return fn("player") != nullptr; + return Game::ResolveUnitToken("player") != nullptr; } void CancelPlacement() { diff --git a/src/spell/Cast.cpp b/src/spell/Cast.cpp index 76187fa1..34da78ca 100644 --- a/src/spell/Cast.cpp +++ b/src/spell/Cast.cpp @@ -87,7 +87,6 @@ namespace Spell::Cast { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); using GetCastTime_t = uint32_t(__fastcall *)(int spellID, int unit, int flag); using GetDuration_t = int(__fastcall *)(const uint8_t *spellRecord, int unit, int skipMod); @@ -220,7 +219,7 @@ void PushMs(void *L, int ms) { } void *Resolve(const char *token) { - return reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN)(token); + return Game::ResolveUnitToken(token); } // Effective cast time (ms) for the local player, 0 if instant. Uses the diff --git a/src/spell/IsCurrent.cpp b/src/spell/IsCurrent.cpp index e72c8db9..df38abe2 100644 --- a/src/spell/IsCurrent.cpp +++ b/src/spell/IsCurrent.cpp @@ -34,15 +34,12 @@ namespace Spell::IsCurrent { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - int ReadGlobalSpellID(uintptr_t addr) { return *reinterpret_cast(addr); } int ReadPlayerChannelSpell() { - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(resolve("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); if (player == nullptr) return 0; auto *desc = *reinterpret_cast( diff --git a/src/spell/Level.cpp b/src/spell/Level.cpp index 2edb197f..34703df7 100644 --- a/src/spell/Level.cpp +++ b/src/spell/Level.cpp @@ -22,15 +22,12 @@ namespace Spell::Level { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // Reads the local player's descriptor — same pattern as // Unit::Combat::Script_InCombatLockdown. Returns nullptr at login // screen / character select / loading transition where the // CGPlayer doesn't exist yet. const uint8_t *PlayerDescriptor() { - auto fn = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(fn("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); if (player == nullptr) return nullptr; return Game::Read( diff --git a/src/spell/Mod.cpp b/src/spell/Mod.cpp index 5c04e7f6..e5cfb22e 100644 --- a/src/spell/Mod.cpp +++ b/src/spell/Mod.cpp @@ -21,15 +21,12 @@ namespace Spell::Mod { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // The local player's class SpellFamilyName, or 0 if it can't be resolved // (e.g. at the login screen). Gates the SpellMod family match — only // spells of the player's own class family receive the player's mods, so // a same-flag-bit spell of another family isn't falsely modified. uint32_t PlayerSpellFamily() { - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *unit = static_cast(resolve("player")); + auto *unit = static_cast(Game::ResolveUnitToken("player")); if (unit == nullptr) return 0; auto *desc = Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); diff --git a/src/spell/SkillLine.cpp b/src/spell/SkillLine.cpp index 13e04bea..759623c8 100644 --- a/src/spell/SkillLine.cpp +++ b/src/spell/SkillLine.cpp @@ -21,7 +21,6 @@ namespace Spell::SkillLine { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); using SkillLineToSlot_t = int(__thiscall *)(void *player, uint32_t skillLineID); // Reads UNIT_FIELD_BYTES_0 from the local player's descriptor. Same @@ -31,8 +30,7 @@ using SkillLineToSlot_t = int(__thiscall *)(void *player, uint32_t skillLineID); void ReadPlayerClassRace(uint8_t *outClassByte, uint8_t *outRaceByte) { *outClassByte = 0; *outRaceByte = 0; - auto fn = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(fn("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); if (player == nullptr) return; auto *desc = Game::Read( @@ -232,8 +230,7 @@ int __fastcall Script_GetSkillLineRank(void *L) { return 1; } - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(resolve("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); if (player == nullptr) { Game::Lua::PushNil(L); return 1; diff --git a/src/spell/Usable.cpp b/src/spell/Usable.cpp index 5e79dfbc..7d816da3 100644 --- a/src/spell/Usable.cpp +++ b/src/spell/Usable.cpp @@ -25,7 +25,6 @@ namespace Spell::Usable { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); using GetSpellCost_t = uint32_t(__fastcall *)(int spellID, int unit); // Spell.dbc record field offsets we read for usability. Fully documented @@ -52,8 +51,7 @@ bool PlayerKnowsSpell(int spellID) { } const uint8_t *PlayerDescriptor() { - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(resolve("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); if (player == nullptr) return nullptr; return Game::Read( diff --git a/src/unit/ClassBase.cpp b/src/unit/ClassBase.cpp index b27f4660..3398a373 100644 --- a/src/unit/ClassBase.cpp +++ b/src/unit/ClassBase.cpp @@ -19,8 +19,6 @@ namespace Unit::ClassBase { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // `UnitClassBase(unit) → (classFile, classID)` — returns the locale- // independent class token ("WARRIOR", "PALADIN", "HUNTER", "ROGUE", // "PRIEST", "SHAMAN", "MAGE", "WARLOCK", "DRUID") plus the numeric @@ -81,8 +79,7 @@ int __fastcall Script_UnitClassBase(void *L) { if (Unit::Identity::IsPlayerToken(token)) { classByte = Game::Read(Offsets::VAR_PLAYER_CLASS_BYTE); } else { - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *unit = static_cast(resolve(token)); + auto *unit = static_cast(Game::ResolveUnitToken(token)); if (unit != nullptr) { auto *desc = Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); diff --git a/src/unit/CreatureFamily.cpp b/src/unit/CreatureFamily.cpp index af05ae8f..91891b5a 100644 --- a/src/unit/CreatureFamily.cpp +++ b/src/unit/CreatureFamily.cpp @@ -44,8 +44,6 @@ namespace Unit::CreatureFamily { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - int __fastcall Script_UnitCreatureFamilyID(void *L) { if (!Game::Lua::IsString(L, 1)) { Game::Lua::Error(L, "Usage: UnitCreatureFamilyID(\"unit\")"); @@ -55,9 +53,7 @@ int __fastcall Script_UnitCreatureFamilyID(void *L) { if (token == nullptr) return 0; - auto resolve = reinterpret_cast( - Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *unit = static_cast(resolve(token)); + auto *unit = static_cast(Game::ResolveUnitToken(token)); if (unit == nullptr) return 0; diff --git a/src/unit/CreatureType.cpp b/src/unit/CreatureType.cpp index 7e5c73ee..8aa8906a 100644 --- a/src/unit/CreatureType.cpp +++ b/src/unit/CreatureType.cpp @@ -41,7 +41,6 @@ namespace Unit::CreatureType { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); using CreatureType_t = int(__fastcall *)(void *unit); int __fastcall Script_UnitCreatureTypeID(void *L) { @@ -53,9 +52,7 @@ int __fastcall Script_UnitCreatureTypeID(void *L) { if (token == nullptr) return 0; - auto resolve = reinterpret_cast( - Offsets::FUN_RESOLVE_UNIT_TOKEN); - void *unit = resolve(token); + void *unit = Game::ResolveUnitToken(token); if (unit == nullptr) return 0; diff --git a/src/unit/Flags.cpp b/src/unit/Flags.cpp index d035ad53..bf146746 100644 --- a/src/unit/Flags.cpp +++ b/src/unit/Flags.cpp @@ -44,8 +44,6 @@ bool IsPlayerObject(const uint8_t *unit) { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // Reads a PLAYER_FLAGS bit for a player. Path: // - Resolve unit; gate on the object actually being a player // (`OBJECT_TYPE_PLAYER`) so we never read the +0xE68 CGPlayer @@ -72,8 +70,7 @@ bool TestPlayerFlag(void *L, uint32_t flagMask) { if (token == nullptr) return false; - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *unit = static_cast(resolve(token)); + auto *unit = static_cast(Game::ResolveUnitToken(token)); // PLAYER_FLAGS lives in the CGPlayer sub-struct — gate on the object // actually being a player, not merely player-controlled (pets/totems // set that flag but have no sub-struct → garbage +0xE68 deref). @@ -123,8 +120,7 @@ int __fastcall Script_UnitIsFeignDeath(void *L) { return 1; } - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *unit = static_cast(resolve(token)); + auto *unit = static_cast(Game::ResolveUnitToken(token)); if (unit == nullptr) { Game::Lua::PushBoolean(L, 0); return 1; @@ -265,9 +261,8 @@ int __fastcall Script_UnitIsInMyGuild(void *L) { return 1; } - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); const uint32_t playerKey = ReadGuildKey( - static_cast(resolve("player"))); + static_cast(Game::ResolveUnitToken("player"))); if (playerKey == 0) { // Player isn't in a guild — nobody is. Game::Lua::PushNil(L); @@ -357,8 +352,7 @@ int __fastcall Script_UnitIsPossessed(void *L) { return 1; } - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *unit = static_cast(resolve(token)); + auto *unit = static_cast(Game::ResolveUnitToken(token)); if (unit == nullptr) { Game::Lua::PushBoolean(L, 0); return 1; diff --git a/src/unit/Health.cpp b/src/unit/Health.cpp index 519928de..7c528f01 100644 --- a/src/unit/Health.cpp +++ b/src/unit/Health.cpp @@ -32,8 +32,6 @@ namespace Unit::Health { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - const uint8_t *Descriptor(const uint8_t *unit) { if (unit == nullptr) return nullptr; @@ -44,8 +42,7 @@ const uint8_t *Descriptor(const uint8_t *unit) { const uint8_t *ResolveUnit(const char *token) { if (token == nullptr) return nullptr; - auto fn = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - return static_cast(fn(token)); + return static_cast(Game::ResolveUnitToken(token)); } // `UnitHealthMissing("unit")` — returns `max - current` health (never diff --git a/src/unit/Position.h b/src/unit/Position.h index c403ab60..b97eea7f 100644 --- a/src/unit/Position.h +++ b/src/unit/Position.h @@ -13,6 +13,7 @@ #pragma once +#include "Game.h" #include "Offsets.h" // Shared world-position read for any CGObject-derived unit. The @@ -32,9 +33,7 @@ namespace Unit::Position { inline void *ResolveToken(const char *token) { if (token == nullptr) return nullptr; - using ResolveUnitToken_t = void *(__fastcall *)(const char *); - auto fn = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - return fn(token); + return Game::ResolveUnitToken(token); } // Reads `obj`'s world position into `out[3]` (x, y, z). Calls diff --git a/src/unit/Power.cpp b/src/unit/Power.cpp index 2dc3276b..254540cf 100644 --- a/src/unit/Power.cpp +++ b/src/unit/Power.cpp @@ -60,8 +60,6 @@ const char *PowerTypeToken(int type) { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - const uint8_t *Descriptor(const uint8_t *unit) { if (unit == nullptr) return nullptr; @@ -72,8 +70,7 @@ const uint8_t *Descriptor(const uint8_t *unit) { const uint8_t *ResolveUnit(const char *token) { if (token == nullptr) return nullptr; - auto fn = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - return static_cast(fn(token)); + return static_cast(Game::ResolveUnitToken(token)); } // Per-power-type display divisor. Vanilla stores rage as 0..1000 diff --git a/src/unit/RaceBase.cpp b/src/unit/RaceBase.cpp index a88462f0..e4ed157d 100644 --- a/src/unit/RaceBase.cpp +++ b/src/unit/RaceBase.cpp @@ -19,8 +19,6 @@ namespace Unit::RaceBase { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // `UnitRaceBase(unit) → (raceFile, raceID)` — returns the locale- // independent race token (`"Human"`, `"Orc"`, `"Dwarf"`, `"NightElf"`, // `"Scourge"`, `"Tauren"`, `"Gnome"`, `"Troll"`) plus the numeric @@ -61,8 +59,7 @@ int __fastcall Script_UnitRaceBase(void *L) { if (Unit::Identity::IsPlayerToken(token)) { raceByte = Game::Read(Offsets::VAR_PLAYER_RACE_BYTE); } else { - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *unit = static_cast(resolve(token)); + auto *unit = static_cast(Game::ResolveUnitToken(token)); if (unit != nullptr) { auto *desc = Game::Read(unit, Offsets::OFF_UNIT_DESCRIPTOR); diff --git a/src/unit/ShapeshiftForm.cpp b/src/unit/ShapeshiftForm.cpp index d4cc9967..77ec4290 100644 --- a/src/unit/ShapeshiftForm.cpp +++ b/src/unit/ShapeshiftForm.cpp @@ -23,7 +23,6 @@ namespace Unit::ShapeshiftForm { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); using CancelAuraSend_t = void(__fastcall *)(int spellID); // Read the local player's current shapeshift form byte. Returns @@ -32,8 +31,7 @@ using CancelAuraSend_t = void(__fastcall *)(int spellID); // can tell "transient unresolved" from "left a form" and not fire // a bogus change event during early-login windows. int ReadCurrentForm() { - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(resolve("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); if (player == nullptr) return -1; auto *fields = *reinterpret_cast( @@ -101,8 +99,7 @@ int __fastcall Script_CancelShapeshiftForm(void *L) { if (form <= 0) return 0; - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(resolve("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); if (player == nullptr) return 0; diff --git a/src/unit/Sheath.cpp b/src/unit/Sheath.cpp index 0a477052..bdc3fd0b 100644 --- a/src/unit/Sheath.cpp +++ b/src/unit/Sheath.cpp @@ -18,8 +18,6 @@ namespace Unit::Sheath { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // `GetSheathState()` — returns which weapon type the local player currently // has drawn. Takes no arguments. The return is **1-based**, matching modern // WoW's contract: @@ -39,8 +37,7 @@ using ResolveUnitToken_t = void *(__fastcall *)(const char *token); // null for `"player"` out of world rather than raising, so this is safe from // any context. static int __fastcall Script_GetSheathState(void *L) { - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *player = static_cast(resolve("player")); + auto *player = static_cast(Game::ResolveUnitToken("player")); int state = 0; if (player != nullptr) diff --git a/src/unit/Speed.cpp b/src/unit/Speed.cpp index ef2a4117..5cc52564 100644 --- a/src/unit/Speed.cpp +++ b/src/unit/Speed.cpp @@ -20,12 +20,10 @@ namespace Unit::Speed { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); using GetEffectiveSpeed_t = float(__thiscall *)(void *movementInfo, int forceWalk); const uint8_t *MovementInfoForToken(const char *token) { - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *unit = static_cast(resolve(token)); + auto *unit = static_cast(Game::ResolveUnitToken(token)); if (unit == nullptr) return nullptr; return *reinterpret_cast( diff --git a/src/unit/SpellHaste.cpp b/src/unit/SpellHaste.cpp index 50cbacc3..3c6f0042 100644 --- a/src/unit/SpellHaste.cpp +++ b/src/unit/SpellHaste.cpp @@ -41,8 +41,6 @@ namespace Unit::SpellHaste { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - const uint8_t *Descriptor(const uint8_t *unit) { if (unit == nullptr) return nullptr; @@ -53,8 +51,7 @@ const uint8_t *Descriptor(const uint8_t *unit) { const uint8_t *ResolveUnit(const char *token) { if (token == nullptr) return nullptr; - auto fn = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - return static_cast(fn(token)); + return static_cast(Game::ResolveUnitToken(token)); } // `UnitSpellHaste("unit")` — spell haste percentage. `0` for an unhasted or diff --git a/src/unit/StandState.cpp b/src/unit/StandState.cpp index f3088268..40432b9f 100644 --- a/src/unit/StandState.cpp +++ b/src/unit/StandState.cpp @@ -20,8 +20,6 @@ namespace Unit::StandState { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - // `UnitStandState(unit)` — returns the unit's current standstate as // the integer encoded in the low byte of `UNIT_BYTES_1` // (descriptor + 0x210): @@ -55,8 +53,7 @@ int __fastcall Script_UnitStandState(void *L) { return 1; } - auto resolve = reinterpret_cast(Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *unit = static_cast(resolve(token)); + auto *unit = static_cast(Game::ResolveUnitToken(token)); if (unit == nullptr) { Game::Lua::PushNumber(L, 0); return 1; diff --git a/src/unit/SubName.cpp b/src/unit/SubName.cpp index 293ad983..68b1463f 100644 --- a/src/unit/SubName.cpp +++ b/src/unit/SubName.cpp @@ -43,8 +43,6 @@ namespace Unit::SubName { namespace { -using ResolveUnitToken_t = void *(__fastcall *)(const char *token); - int __fastcall Script_UnitSubName(void *L) { if (!Game::Lua::IsString(L, 1)) { Game::Lua::Error(L, "Usage: UnitSubName(\"unit\")"); @@ -54,9 +52,7 @@ int __fastcall Script_UnitSubName(void *L) { if (token == nullptr) return 0; - auto resolve = reinterpret_cast( - Offsets::FUN_RESOLVE_UNIT_TOKEN); - auto *unit = static_cast(resolve(token)); + auto *unit = static_cast(Game::ResolveUnitToken(token)); if (unit == nullptr) return 0;