Skip to content

Commit 993c82c

Browse files
committed
refactor: route unit-token resolution through Game::ResolveUnitToken
Sweep the ~35 modules that each hand-rolled a `ResolveUnitToken_t` typedef plus `reinterpret_cast<…>(Offsets::FUN_RESOLVE_UNIT_TOKEN)` onto the shared `Game::ResolveUnitToken` helper. Behavior-identical — it is the same engine function — and net -87 lines. The typedef now lives in exactly one place (Game.cpp). unit/Position.h is a header, so it gains an `#include "Game.h"`; every other touched file already pulled Game.h in. No offsets, logic, or unrelated typedefs were changed.
1 parent 94e77ef commit 993c82c

35 files changed

Lines changed: 41 additions & 148 deletions

src/aura/Api.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,10 @@ namespace Aura::Api {
4646

4747
namespace {
4848

49-
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
50-
5149
const uint8_t *ResolveUnit(const char *token) {
5250
if (token == nullptr)
5351
return nullptr;
54-
auto fn = reinterpret_cast<ResolveUnitToken_t>(
55-
static_cast<uintptr_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN));
56-
return static_cast<const uint8_t *>(fn(token));
52+
return static_cast<const uint8_t *>(Game::ResolveUnitToken(token));
5753
}
5854

5955
// Resolves a token to its GUID for the out-of-range (no live CGUnit) path.

src/aura/Data.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,9 @@ const char *SpellIconPath(const uint8_t *spellRecord) {
7777
Offsets::OFF_SPELLICON_PATH);
7878
}
7979

80-
using ResolveUnitToken_t = void *(__fastcall *)(const char *);
81-
8280
// Returns the local player's CGUnit pointer, or nullptr pre-login.
8381
const uint8_t *LocalPlayer() {
84-
auto fn = reinterpret_cast<ResolveUnitToken_t>(
85-
static_cast<uintptr_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN));
86-
return static_cast<const uint8_t *>(fn("player"));
82+
return static_cast<const uint8_t *>(Game::ResolveUnitToken("player"));
8783
}
8884

8985
// Looks up the player-buff-table entry for a given spellID. The table

src/debug/Probe.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,8 @@ namespace Debug::Probe {
6464

6565
namespace {
6666

67-
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
68-
6967
const uint8_t *ResolvePlayer() {
70-
auto fn = reinterpret_cast<ResolveUnitToken_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN);
71-
return static_cast<const uint8_t *>(fn("player"));
68+
return static_cast<const uint8_t *>(Game::ResolveUnitToken("player"));
7269
}
7370

7471
const uint8_t *ResolvePlayerDescriptor() {

src/faction/Info.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ void PushFlag(void *L, bool value) {
6969
// `[player + 0xE68]`. Returns nullptr if "player" isn't resolvable
7070
// or the sub-struct is uninitialized (pre-login / glue).
7171
const uint8_t *PlayerInfo() {
72-
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
73-
auto resolve = reinterpret_cast<ResolveUnitToken_t>(
74-
Offsets::FUN_RESOLVE_UNIT_TOKEN);
75-
auto *player = static_cast<const uint8_t *>(resolve("player"));
72+
auto *player = static_cast<const uint8_t *>(Game::ResolveUnitToken("player"));
7673
if (player == nullptr)
7774
return nullptr;
7875
return *reinterpret_cast<const uint8_t *const *>(

src/item/Equipment.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,8 @@ int __fastcall Script_C_Item_EquipItemByName(void *L) {
200200
if (!Item::Cursor::PickupBagItem(L, found.bagID, found.slotIndex))
201201
return 0;
202202

203-
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
204203
using AutoEquipCursor_t = void (__thiscall *)(void *player, int flag);
205-
auto resolve = reinterpret_cast<ResolveUnitToken_t>(
206-
Offsets::FUN_RESOLVE_UNIT_TOKEN);
207-
if (auto *player = resolve("player")) {
204+
if (auto *player = Game::ResolveUnitToken("player")) {
208205
auto equip = reinterpret_cast<AutoEquipCursor_t>(
209206
Offsets::FUN_AUTO_EQUIP_CURSOR_ITEM);
210207
equip(player, 0);

src/item/InventoryID.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ namespace {
2424

2525
using GetItemBySlot_t = void *(__thiscall *)(void *invMgr, int slot);
2626
using GetVisibleItem_t = void *(__thiscall *)(void *unit, int slot);
27-
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
2827

2928
void *ResolveUnit(const char *token) {
30-
auto fn = reinterpret_cast<ResolveUnitToken_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN);
31-
return fn(token);
29+
return Game::ResolveUnitToken(token);
3230
}
3331

3432
// Walks the local player's private inventory manager — the same path

src/item/Usable.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ namespace Item::Usable {
5050

5151
namespace {
5252

53-
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
5453
using SpellIsUsable_t = int(__fastcall *)(const uint8_t *spellRecord, int *outNoMana);
5554

5655
const uint8_t *PlayerDescriptor() {
57-
auto resolve = reinterpret_cast<ResolveUnitToken_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN);
58-
auto *player = static_cast<const uint8_t *>(resolve("player"));
56+
auto *player = static_cast<const uint8_t *>(Game::ResolveUnitToken("player"));
5957
if (player == nullptr)
6058
return nullptr;
6159
return *reinterpret_cast<const uint8_t *const *>(

src/loot/Nearby.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ using ClntObjMgrEnumVisibleObjectsCallback_t = int(__fastcall *)(void *ctx,
4949
using ClntObjMgrEnumVisibleObjects_t =
5050
int(__fastcall *)(ClntObjMgrEnumVisibleObjectsCallback_t cb, void *ctx);
5151

52-
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
53-
5452
// `__thiscall(self, outBuf) → const C3Vector *` at vtable slot 5
5553
// (byte offset `0x14`). Both CGUnit_C and CGPlayer_C populate the
5654
// caller-provided 12-byte buffer with the unit's world position and
@@ -182,9 +180,7 @@ int __fastcall Script_GetNearbyLootableUnits(void *L) {
182180
// Resolve the local player once — the canonical CGPlayer_C the
183181
// engine's own interact-range checks use, distinct from the
184182
// `VAR_LOCAL_PLAYER_PTR` global. Bail if unavailable.
185-
auto ResolveUnitToken = reinterpret_cast<ResolveUnitToken_t>(
186-
Offsets::FUN_RESOLVE_UNIT_TOKEN);
187-
const void *player = ResolveUnitToken("player");
183+
const void *player = Game::ResolveUnitToken("player");
188184
if (player == nullptr)
189185
return 1;
190186

src/loot/Scan.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ using ClntObjMgrEnumVisibleObjectsCallback_t = int(__fastcall *)(void *ctx,
105105
uint64_t guid);
106106
using ClntObjMgrEnumVisibleObjects_t =
107107
int(__fastcall *)(ClntObjMgrEnumVisibleObjectsCallback_t cb, void *ctx);
108-
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
109108
using LootUnit_t = void(__thiscall *)(void *player, void *target,
110109
char useDistanceCheck);
111110
using CloseLootInner_t = void(__fastcall *)(int sendRelease,
@@ -443,9 +442,7 @@ bool BeginWalk(bool lootMode, size_t maxCount) {
443442
return false;
444443
if (*reinterpret_cast<void *volatile *>(Offsets::VAR_LOCAL_PLAYER_PTR) == nullptr)
445444
return false;
446-
auto Resolve = reinterpret_cast<ResolveUnitToken_t>(
447-
Offsets::FUN_RESOLVE_UNIT_TOKEN);
448-
void *player = Resolve("player");
445+
void *player = Game::ResolveUnitToken("player");
449446
if (player == nullptr)
450447
return false;
451448

src/loot/Unit.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ namespace Loot::Unit {
2222

2323
namespace {
2424

25-
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
26-
2725
// `FUN_CMSG_LOOT_UNIT` is `__thiscall(player, target, useDistanceCheck)`.
2826
// MSVC `__thiscall` puts `player` in ECX and the rest on the stack —
2927
// matching the engine's own callsite at `FUN_0060FA20`. The trailing
@@ -74,9 +72,7 @@ int __fastcall Script_LootUnit(void *L) {
7472
// `ResolveUnitToken("player")` gives the canonical CGPlayer_C the
7573
// engine uses for `__thiscall` calls — distinct from the global
7674
// at `VAR_LOCAL_PLAYER_PTR` (see the comment on that offset).
77-
auto ResolveUnitToken = reinterpret_cast<ResolveUnitToken_t>(
78-
Offsets::FUN_RESOLVE_UNIT_TOKEN);
79-
void *player = ResolveUnitToken("player");
75+
void *player = Game::ResolveUnitToken("player");
8076
if (player == nullptr)
8177
return 0;
8278

0 commit comments

Comments
 (0)