refactor: centralize engine field/global access via Game::Read/Ref/Ptr

Replace the raw `*reinterpret_cast<const T *>(base + Offsets::OFF_X)`
idiom (and its double-cast variant when base wasn't already a byte
pointer) with three typed accessors in Game.h:

  Game::Read<T>(base, offset)  field value read
  Game::Ref<T>(base, offset)   writable field lvalue
  Game::Ptr<T>(base, offset)   pointer to a field (arrays / out-params)
  Game::Read<T>(address) / Ref<T>(address)  fixed-VA globals

Pure mechanical refactor, zero behavior change: ~330 cast sites across
84 files collapse to 651 helper calls. Offsets stay in Offsets.h per the
single-source-of-truth rule — the helpers only remove the cast noise and
fold away the inner `reinterpret_cast<uint8_t*>(obj)` base casts.

Left as raw casts by design: FUN_* function-pointer casts, void*/char*
VA handles passed as arguments (caches, method registries), subobject-
anchor pointers fed to __thiscall helpers, `void *volatile` player-ptr
readiness gates (converting would strip volatile), and VA-as-array-base
captures that are subscripted later.
This commit is contained in:
Brues
2026-08-19 11:01:19 -05:00
parent bd14a93a11
commit c54556f6a1
84 changed files with 947 additions and 1032 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ using RegisterFrameMethods_t = void(__fastcall *)(const FrameMethodEntry *table,
} // namespace
void *State() {
return *reinterpret_cast<void **>(static_cast<uintptr_t>(Offsets::VAR_LUA_STATE));
return Game::Read<void *>(Offsets::VAR_LUA_STATE);
}
namespace {
+40
View File
@@ -17,6 +17,46 @@
namespace Game {
// --- Typed engine-memory access ---------------------------------------------
//
// The canonical way to read/write an engine object field or a fixed-VA global,
// replacing the `*reinterpret_cast<const T *>(base + Offsets::OFF_X)` idiom
// (and its double-cast variant when `base` isn't a byte pointer). Offsets stay
// in Offsets.h per the single-source-of-truth rule — these only centralize the
// cast noise, they add no checking.
//
// Game::Read<int>(obj, Offsets::OFF_FIELD) field read
// Game::Ref<uint32_t>(obj, Offsets::OFF_FIELD) writable field lvalue
// Game::Ptr<float>(obj, Offsets::OFF_FIELD) pointer TO a field (arrays,
// out-params for engine calls)
// Game::Read<float>(Offsets::VAR_GLOBAL) fixed-VA global read
// Game::Ref<int>(Offsets::VAR_GLOBAL) fixed-VA global lvalue
template <typename T>
inline const T *Ptr(const void *base, uintptr_t offset) {
return reinterpret_cast<const T *>(reinterpret_cast<const uint8_t *>(base) + offset);
}
template <typename T>
inline T *Ptr(void *base, uintptr_t offset) {
return reinterpret_cast<T *>(reinterpret_cast<uint8_t *>(base) + offset);
}
template <typename T>
inline T Read(const void *base, uintptr_t offset) {
return *Ptr<T>(base, offset);
}
template <typename T>
inline T &Ref(void *base, uintptr_t offset) {
return *Ptr<T>(base, offset);
}
template <typename T>
inline T Read(uintptr_t address) {
return *reinterpret_cast<const T *>(address);
}
template <typename T>
inline T &Ref(uintptr_t address) {
return *reinterpret_cast<T *>(address);
}
using FrameScript_Initialize_t = bool(__fastcall *)();
using LoadScriptFunctions_t = void(__fastcall *)();
+8 -8
View File
@@ -103,14 +103,14 @@ int CGItemCount(const uint8_t *item) {
auto *desc = Item::ObjectFields(item);
if (desc == nullptr)
return 0;
return *reinterpret_cast<const int *>(desc + Offsets::OFF_DESCRIPTOR_STACK_COUNT);
return Game::Read<int>(desc, Offsets::OFF_DESCRIPTOR_STACK_COUNT);
}
uint64_t CGItemGuid(const uint8_t *item) {
auto *inst = Item::InstanceBlock(item);
if (inst == nullptr)
return 0;
return *reinterpret_cast<const uint64_t *>(inst + Offsets::OFF_INSTANCE_BLOCK_GUID);
return Game::Read<uint64_t>(inst, Offsets::OFF_INSTANCE_BLOCK_GUID);
}
struct SlotInfo {
@@ -135,18 +135,18 @@ SlotInfo ReadSlot(void *L, int bag, int slot) {
// --- auction-house globals ----------------------------------------------
uint64_t AuctioneerGuid() {
const uint32_t lo = *reinterpret_cast<const uint32_t *>(
const uint32_t lo = Game::Read<uint32_t>(
Offsets::VAR_AUCTION_AUCTIONEER_GUID_LO);
const uint32_t hi = *reinterpret_cast<const uint32_t *>(
const uint32_t hi = Game::Read<uint32_t>(
Offsets::VAR_AUCTION_AUCTIONEER_GUID_HI);
return (static_cast<uint64_t>(hi) << 32) | lo;
}
bool AHOpen() { return AuctioneerGuid() != 0; }
void SetSellGuid(uint64_t guid) {
*reinterpret_cast<uint32_t *>(Offsets::VAR_AUCTION_SELL_GUID_LO) =
Game::Ref<uint32_t>(Offsets::VAR_AUCTION_SELL_GUID_LO) =
static_cast<uint32_t>(guid);
*reinterpret_cast<uint32_t *>(Offsets::VAR_AUCTION_SELL_GUID_HI) =
Game::Ref<uint32_t>(Offsets::VAR_AUCTION_SELL_GUID_HI) =
static_cast<uint32_t>(guid >> 32);
}
@@ -181,8 +181,8 @@ bool BagIsGeneral(int bag) {
const uint8_t *rec = Item::PeekRecord(static_cast<uint32_t>(id));
if (rec == nullptr)
return false;
return *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_ITEMSTATS_BAG_FAMILY) == 0;
return Game::Read<uint32_t>(
rec, Offsets::OFF_ITEMSTATS_BAG_FAMILY) == 0;
}
bool FindFreeGeneralSlot(void *L, int *outBag, int *outSlot) {
+2 -2
View File
@@ -352,8 +352,8 @@ int DispatchOverrideCommand(void *mgr, const char *cmd, int isDown) {
reinterpret_cast<volatile uint32_t *>(Offsets::VAR_FRAMESCRIPT_EXEC_CONTEXT);
volatile uint32_t *depth = reinterpret_cast<volatile uint32_t *>(
Offsets::VAR_FRAMESCRIPT_EXEC_CONTEXT_DEPTH);
volatile uint32_t *executing = reinterpret_cast<volatile uint32_t *>(
reinterpret_cast<char *>(mgr) + Offsets::OFF_BINDING_MANAGER_EXECUTING);
volatile uint32_t *executing =
Game::Ptr<volatile uint32_t>(mgr, Offsets::OFF_BINDING_MANAGER_EXECUTING);
const uint32_t savedContext = *context;
*depth = *depth + 1;
+19 -19
View File
@@ -80,12 +80,12 @@ bool BuildIconPath(uint32_t displayInfoID, char *out, size_t outSize) {
// readable-text id is non-zero (letters / server-authored notes).
bool ItemReadable(const uint8_t *item, const uint8_t *record) {
if (record != nullptr &&
*reinterpret_cast<const uint32_t *>(record + Offsets::OFF_ITEMSTATS_PAGE_TEXT) != 0)
Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_PAGE_TEXT) != 0)
return true;
const uint8_t *descriptor = Item::ObjectFields(item);
return descriptor != nullptr &&
*reinterpret_cast<const uint32_t *>(
descriptor + Offsets::OFF_DESCRIPTOR_READABLE_TEXT_ID) != 0;
Game::Read<uint32_t>(
descriptor, Offsets::OFF_DESCRIPTOR_READABLE_TEXT_ID) != 0;
}
int __fastcall Script_C_Container_GetContainerItemInfo(void *L) {
@@ -116,14 +116,14 @@ int __fastcall Script_C_Container_GetContainerItemInfo(void *L) {
int stackCount = 0;
bool isBound = false;
if (descriptor != nullptr) {
stackCount = *reinterpret_cast<const int *>(
descriptor + Offsets::OFF_DESCRIPTOR_STACK_COUNT);
isBound = (*reinterpret_cast<const uint32_t *>(
descriptor + Offsets::OFF_DESCRIPTOR_FLAGS) &
stackCount = Game::Read<int>(
descriptor, Offsets::OFF_DESCRIPTOR_STACK_COUNT);
isBound = (Game::Read<uint32_t>(
descriptor, Offsets::OFF_DESCRIPTOR_FLAGS) &
Offsets::ITEM_FLAG_SOULBOUND) != 0;
}
const bool isLocked = (*reinterpret_cast<const uint32_t *>(
item + Offsets::OFF_ITEM_CLIENT_LOCK) &
const bool isLocked = (Game::Read<uint32_t>(
item, Offsets::OFF_ITEM_CLIENT_LOCK) &
Offsets::ITEM_CLIENT_LOCK_BIT) != 0;
const bool isReadable = ItemReadable(item, record);
@@ -135,17 +135,17 @@ int __fastcall Script_C_Container_GetContainerItemInfo(void *L) {
bool hasLoot = false;
bool hasNoValue = false;
if (record != nullptr) {
const uint32_t displayInfoID = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
const uint32_t displayInfoID = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
haveIcon = BuildIconPath(displayInfoID, iconPath, sizeof(iconPath));
quality = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_QUALITY);
quality = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_QUALITY);
haveQuality = true;
const uint32_t flags = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_FLAGS);
const uint32_t flags = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_FLAGS);
hasLoot = (flags & Offsets::ITEM_FLAG_LOOTABLE) != 0;
hasNoValue = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_SELL_PRICE) == 0;
hasNoValue = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_SELL_PRICE) == 0;
}
const char *hyperlink = Item::Link::FromCGItem(item);
@@ -155,8 +155,8 @@ int __fastcall Script_C_Container_GetContainerItemInfo(void *L) {
if (Item::Link::NameFromCGItem(item, nameBuf, sizeof(nameBuf))) {
itemName = nameBuf;
} else if (record != nullptr) {
const char *baseName = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSTATS_NAME);
const char *baseName = Game::Read<const char *>(
record, Offsets::OFF_ITEMSTATS_NAME);
if (baseName != nullptr && baseName[0] != '\0')
itemName = baseName;
}
+22 -22
View File
@@ -95,14 +95,14 @@ int __fastcall Script_GetCreatureInfoByID(void *L) {
if (rec == nullptr)
return 0; // not cached -> nil
const char *name = *reinterpret_cast<const char *const *>(rec + Offsets::OFF_CREATURE_NAME);
const char *name = Game::Read<const char *>(rec, Offsets::OFF_CREATURE_NAME);
const char *subName =
*reinterpret_cast<const char *const *>(rec + Offsets::OFF_CREATURE_SUBNAME);
const uint32_t type = *reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_CREATURE_TYPE);
const uint32_t family = *reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_CREATURE_FAMILY);
const uint32_t rank = *reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_CREATURE_RANK);
Game::Read<const char *>(rec, Offsets::OFF_CREATURE_SUBNAME);
const uint32_t type = Game::Read<uint32_t>(rec, Offsets::OFF_CREATURE_TYPE);
const uint32_t family = Game::Read<uint32_t>(rec, Offsets::OFF_CREATURE_FAMILY);
const uint32_t rank = Game::Read<uint32_t>(rec, Offsets::OFF_CREATURE_RANK);
const uint32_t displayID =
*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_CREATURE_DISPLAYID);
Game::Read<uint32_t>(rec, Offsets::OFF_CREATURE_DISPLAYID);
Game::Lua::NewTable(L);
Game::Lua::SetFieldNumber(L, "creatureID", creatureID);
@@ -213,7 +213,7 @@ int __fastcall Script_GetCreatureFamilyIDs(void *L) {
Game::Lua::NewTable(L);
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_CREATUREFAMILY_COUNT);
Game::Read<int>(Offsets::VAR_CREATUREFAMILY_COUNT);
int n = 0;
for (int id = 1; id <= count; ++id) {
const char *name = DBC::LocalizedField(Offsets::VAR_CREATUREFAMILY_RECORDS,
@@ -250,8 +250,8 @@ int __fastcall Script_GetFactionInfo(void *L) {
static_cast<uint32_t>(raceID));
if (crRec == nullptr)
return 0; // unknown race
const int ftId = *reinterpret_cast<const int *>(
crRec + Offsets::OFF_CHRRACES_FACTION_TEMPLATE);
const int ftId = Game::Read<int>(
crRec, Offsets::OFF_CHRRACES_FACTION_TEMPLATE);
if (ftId <= 0)
return 0;
@@ -260,31 +260,31 @@ int __fastcall Script_GetFactionInfo(void *L) {
static_cast<uint32_t>(ftId));
if (ftRec == nullptr)
return 0;
const uint32_t mask = *reinterpret_cast<const uint32_t *>(
ftRec + Offsets::OFF_FACTIONTEMPLATE_GROUP_MASK);
const uint32_t mask = Game::Read<uint32_t>(
ftRec, Offsets::OFF_FACTIONTEMPLATE_GROUP_MASK);
// FactionGroup is stored contiguously (records-base + i*stride), not as a
// pointer array — iterate by hand rather than via DBC::Record.
auto *fgBase = *reinterpret_cast<const uint8_t *const *>(
auto *fgBase = Game::Read<const uint8_t *>(
Offsets::VAR_FACTIONGROUP_RECORDS);
const int fgCount =
*reinterpret_cast<const int *>(Offsets::VAR_FACTIONGROUP_COUNT);
const int locale = *reinterpret_cast<const int *>(Offsets::VAR_LOCALE_INDEX);
Game::Read<int>(Offsets::VAR_FACTIONGROUP_COUNT);
const int locale = Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
if (fgBase == nullptr)
return 0;
for (int i = 0; i < fgCount; ++i) {
const uint8_t *row = fgBase + i * Offsets::FACTIONGROUP_STRIDE;
const int bit = *reinterpret_cast<const int *>(
row + Offsets::OFF_FACTIONGROUP_BIT);
const int bit = Game::Read<int>(
row, Offsets::OFF_FACTIONGROUP_BIT);
if ((mask & (1u << (bit & 0x1F))) == 0)
continue;
const char *loc = *reinterpret_cast<const char *const *>(
row + Offsets::OFF_FACTIONGROUP_NAMES + locale * 4);
const char *loc = Game::Read<const char *>(
row, Offsets::OFF_FACTIONGROUP_NAMES + locale * 4);
if (loc == nullptr || *loc == '\0')
continue; // "Player" / "Monster" have empty localized names
const char *eng = *reinterpret_cast<const char *const *>(
row + Offsets::OFF_FACTIONGROUP_ENGLISH);
const char *eng = Game::Read<const char *>(
row, Offsets::OFF_FACTIONGROUP_ENGLISH);
Game::Lua::NewTable(L);
Game::Lua::SetFieldString(L, "name", loc);
@@ -324,7 +324,7 @@ int __fastcall Script_GetCreatureTypeIDs(void *L) {
Game::Lua::NewTable(L);
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_CREATURETYPE_COUNT);
Game::Read<int>(Offsets::VAR_CREATURETYPE_COUNT);
int n = 0;
for (int id = 1; id <= count; ++id) {
const char *name = DBC::LocalizedField(Offsets::VAR_CREATURETYPE_RECORDS,
@@ -376,7 +376,7 @@ uint32_t DisplayID(uint32_t creatureID) {
const uint8_t *rec = PeekCreature(creatureID);
if (rec == nullptr)
return 0;
return *reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_CREATURE_DISPLAYID);
return Game::Read<uint32_t>(rec, Offsets::OFF_CREATURE_DISPLAYID);
}
} // namespace Creature::Info
+4 -3
View File
@@ -13,6 +13,7 @@
#include "Storage.h"
#include "Game.h"
#include "Offsets.h"
#include <cstdint>
@@ -25,7 +26,7 @@ namespace EquipmentSet::Storage {
namespace {
const char *ReadAccountName() {
return *reinterpret_cast<const char *const *>(Offsets::VAR_ACCOUNT_NAME_PTR);
return Game::Read<const char *>(Offsets::VAR_ACCOUNT_NAME_PTR);
}
const char *ReadCharacterName() {
@@ -34,10 +35,10 @@ const char *ReadCharacterName() {
}
const char *ReadRealmName() {
auto *info = *reinterpret_cast<uint8_t **>(Offsets::VAR_REALM_INFO_PTR);
auto *info = Game::Read<uint8_t *>(Offsets::VAR_REALM_INFO_PTR);
if (info == nullptr)
return nullptr;
return *reinterpret_cast<const char *const *>(info + Offsets::OFF_REALM_INFO_NAME);
return Game::Read<const char *>(info, Offsets::OFF_REALM_INFO_NAME);
}
// Removes trailing CR/LF/whitespace. Names from the engine are ASCII
+2 -2
View File
@@ -210,8 +210,8 @@ int __fastcall Script_GameTooltipSetEquipmentSet(void *L) {
unnamedMissing++;
continue;
}
const char *name = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSTATS_NAME);
const char *name = Game::Read<const char *>(
record, Offsets::OFF_ITEMSTATS_NAME);
if (name == nullptr || name[0] == '\0') {
unnamedMissing++;
continue;
+29 -29
View File
@@ -112,13 +112,13 @@ void SMemFree(void *ptr) {
int TryClaim(const char *eventName) {
if (!g_writesEnabled)
return -1;
auto *base = *reinterpret_cast<uint8_t **>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = *reinterpret_cast<int *>(Offsets::VAR_EVENT_TABLE_COUNT);
auto *base = Game::Read<uint8_t *>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = Game::Read<int>(Offsets::VAR_EVENT_TABLE_COUNT);
if (base == nullptr || count <= 0)
return -1;
for (int i = 0; i < count; ++i) {
auto **namePtr = reinterpret_cast<const char **>(
base + i * Offsets::EVENT_ENTRY_STRIDE +
auto **namePtr = Game::Ptr<const char *>(
base + i * Offsets::EVENT_ENTRY_STRIDE,
Offsets::OFF_EVENT_ENTRY_NAME);
if (*namePtr == nullptr) {
char *copy = SStrDup(eventName);
@@ -169,15 +169,15 @@ void Grow() {
return;
g_growLatched = true; // one attempt per build, whether or not it grows
const int count = *reinterpret_cast<int *>(Offsets::VAR_EVENT_TABLE_COUNT);
auto *base = *reinterpret_cast<uint8_t **>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = Game::Read<int>(Offsets::VAR_EVENT_TABLE_COUNT);
auto *base = Game::Read<uint8_t *>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
if (base == nullptr || count <= 0 || g_reservedCount <= 0)
return;
int nulls = 0;
for (int i = 0; i < count; ++i)
if (*reinterpret_cast<const char *const *>(
base + i * Offsets::EVENT_ENTRY_STRIDE +
if (Game::Read<const char *>(
base + i * Offsets::EVENT_ENTRY_STRIDE,
Offsets::OFF_EVENT_ENTRY_NAME) == nullptr)
++nulls;
@@ -193,8 +193,8 @@ void Grow() {
// moving the buffer would corrupt their subscription). Abort if so and
// fall back to claim-NULL.
for (int i = 0; i < count; ++i) {
const uint32_t head = *reinterpret_cast<const uint32_t *>(
base + i * Offsets::EVENT_ENTRY_STRIDE + Offsets::OFF_EVENT_ENTRY_HEAD);
const uint32_t head = Game::Read<uint32_t>(
base + i * Offsets::EVENT_ENTRY_STRIDE, Offsets::OFF_EVENT_ENTRY_HEAD);
if (head != 0 && (head & 1) == 0) { // populated chain (not 0 / sentinel)
Debug::Log::Printf(
"[event] grow aborted — chain live at slot %d (not first-reg)", i);
@@ -231,9 +231,9 @@ void Grow() {
// Publish base BEFORE count so the globals never advertise more entries
// than the buffer holds. Then free the OLD buffer only — the name
// strings live on in newBuf and are freed by the reload teardown.
*reinterpret_cast<uint8_t **>(Offsets::VAR_EVENT_TABLE_BASE_PTR) = newBuf;
*reinterpret_cast<int *>(Offsets::VAR_EVENT_TABLE_CAP) = newCount;
*reinterpret_cast<int *>(Offsets::VAR_EVENT_TABLE_COUNT) = newCount;
Game::Ref<uint8_t *>(Offsets::VAR_EVENT_TABLE_BASE_PTR) = newBuf;
Game::Ref<int>(Offsets::VAR_EVENT_TABLE_CAP) = newCount;
Game::Ref<int>(Offsets::VAR_EVENT_TABLE_COUNT) = newCount;
SMemFree(base);
Debug::Log::Printf("[event] grew table %d -> %d (%d NULL, %d reserved%s)",
@@ -268,13 +268,13 @@ int Lookup(const char *name) {
int LookupByName(const char *name) {
if (name == nullptr)
return -1;
auto *base = *reinterpret_cast<uint8_t **>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = *reinterpret_cast<int *>(Offsets::VAR_EVENT_TABLE_COUNT);
auto *base = Game::Read<uint8_t *>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = Game::Read<int>(Offsets::VAR_EVENT_TABLE_COUNT);
if (base == nullptr || count <= 0)
return -1;
for (int i = 0; i < count; ++i) {
const char *entryName = *reinterpret_cast<const char *const *>(
base + i * Offsets::EVENT_ENTRY_STRIDE +
const char *entryName = Game::Read<const char *>(
base + i * Offsets::EVENT_ENTRY_STRIDE,
Offsets::OFF_EVENT_ENTRY_NAME);
if (entryName != nullptr && std::strcmp(entryName, name) == 0)
return i;
@@ -285,16 +285,16 @@ int LookupByName(const char *name) {
bool HasListeners(int slot) {
if (slot < 0)
return false;
auto *base = *reinterpret_cast<uint8_t **>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = *reinterpret_cast<int *>(Offsets::VAR_EVENT_TABLE_COUNT);
auto *base = Game::Read<uint8_t *>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = Game::Read<int>(Offsets::VAR_EVENT_TABLE_COUNT);
if (base == nullptr || slot >= count)
return false;
// The entry's chain head (`+0x0C`): a populated subscriber chain is a
// non-zero pointer with the low bit clear; `0` or an odd (tagged)
// value is the empty self-sentinel — same test the grow-safety scan
// uses. So this is true iff at least one frame registered for the event.
const uint32_t head = *reinterpret_cast<const uint32_t *>(
base + slot * Offsets::EVENT_ENTRY_STRIDE + Offsets::OFF_EVENT_ENTRY_HEAD);
const uint32_t head = Game::Read<uint32_t>(
base + slot * Offsets::EVENT_ENTRY_STRIDE, Offsets::OFF_EVENT_ENTRY_HEAD);
return head != 0 && (head & 1) == 0;
}
@@ -330,12 +330,12 @@ int __fastcall Script_DumpSlot(void *L) {
return 0;
}
const int slot = static_cast<int>(Game::Lua::ToNumber(L, 1));
auto *base = *reinterpret_cast<uint8_t **>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = *reinterpret_cast<int *>(Offsets::VAR_EVENT_TABLE_COUNT);
auto *base = Game::Read<uint8_t *>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = Game::Read<int>(Offsets::VAR_EVENT_TABLE_COUNT);
const char *name = nullptr;
if (base != nullptr && slot >= 0 && slot < count) {
name = *reinterpret_cast<const char *const *>(
base + slot * Offsets::EVENT_ENTRY_STRIDE +
name = Game::Read<const char *>(
base + slot * Offsets::EVENT_ENTRY_STRIDE,
Offsets::OFF_EVENT_ENTRY_NAME);
}
Debug::Log::Printf("[dumpslot] base=0x%08X count=%d slot=%d name='%s'",
@@ -345,16 +345,16 @@ int __fastcall Script_DumpSlot(void *L) {
}
int __fastcall Script_DumpAllEvents(void *) {
auto *base = *reinterpret_cast<uint8_t **>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = *reinterpret_cast<int *>(Offsets::VAR_EVENT_TABLE_COUNT);
auto *base = Game::Read<uint8_t *>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
const int count = Game::Read<int>(Offsets::VAR_EVENT_TABLE_COUNT);
Debug::Log::Printf("[dumpall] base=0x%08X count=%d",
static_cast<unsigned>(reinterpret_cast<uintptr_t>(base)),
count);
if (base == nullptr)
return 0;
for (int i = 0; i < count; ++i) {
const char *name = *reinterpret_cast<const char *const *>(
base + i * Offsets::EVENT_ENTRY_STRIDE +
const char *name = Game::Read<const char *>(
base + i * Offsets::EVENT_ENTRY_STRIDE,
Offsets::OFF_EVENT_ENTRY_NAME);
if (name != nullptr && *name != '\0')
Debug::Log::Printf("[%d] %s", i, name);
+6 -10
View File
@@ -50,22 +50,20 @@ int __fastcall Script_GetFramesRegisteredForEvent(void *L) {
if (slot < 0)
return 0;
auto *base = *reinterpret_cast<uint8_t **>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
auto *base = Game::Read<uint8_t *>(Offsets::VAR_EVENT_TABLE_BASE_PTR);
if (base == nullptr)
return 0;
const uint8_t *entry = base + slot * Offsets::EVENT_ENTRY_STRIDE;
const uintptr_t head = *reinterpret_cast<const uintptr_t *>(
entry + Offsets::OFF_EVENT_ENTRY_HEAD);
const uintptr_t head = Game::Read<uintptr_t>(entry, Offsets::OFF_EVENT_ENTRY_HEAD);
// First pass: count subscribers so we can reserve stack up front — an
// event with many registered frames would otherwise risk overflowing
// the default Lua stack slack as we push.
int count = 0;
for (uintptr_t node = head; (node & 1) == 0 && node != 0;
node = *reinterpret_cast<const uintptr_t *>(
node + Offsets::OFF_EVENT_NODE_NEXT)) {
if (*reinterpret_cast<void *const *>(node + Offsets::OFF_EVENT_NODE_FRAME))
node = Game::Read<uintptr_t>(node + Offsets::OFF_EVENT_NODE_NEXT)) {
if (Game::Read<void *>(node + Offsets::OFF_EVENT_NODE_FRAME))
++count;
}
if (count == 0)
@@ -74,10 +72,8 @@ int __fastcall Script_GetFramesRegisteredForEvent(void *L) {
int pushed = 0;
for (uintptr_t node = head; (node & 1) == 0 && node != 0;
node = *reinterpret_cast<const uintptr_t *>(
node + Offsets::OFF_EVENT_NODE_NEXT)) {
void *frame = *reinterpret_cast<void *const *>(
node + Offsets::OFF_EVENT_NODE_FRAME);
node = Game::Read<uintptr_t>(node + Offsets::OFF_EVENT_NODE_NEXT)) {
void *frame = Game::Read<void *>(node + Offsets::OFF_EVENT_NODE_FRAME);
if (frame != nullptr) {
UI::FrameObject::Push(L, frame);
++pushed;
+2 -2
View File
@@ -40,8 +40,8 @@ using StringHeightInternal_t = float(__fastcall *)(void *fs);
// push chain Script_GetStringWidth uses (the inverse of
// Tooltip::LinePool::PixelToInternal).
double InternalToPixel(float v) {
const float mul = *reinterpret_cast<const float *>(Offsets::VAR_UI_COORD_SCALE_MUL);
const float div = *reinterpret_cast<const float *>(Offsets::VAR_UI_COORD_SCALE_DIV);
const float mul = Game::Read<float>(Offsets::VAR_UI_COORD_SCALE_MUL);
const float div = Game::Read<float>(Offsets::VAR_UI_COORD_SCALE_DIV);
if (mul == 0.0f)
return 0.0;
return static_cast<double>(v) * div * Offsets::UI_COORD_SCALE_UNIT / mul;
+7 -9
View File
@@ -315,12 +315,11 @@ std::unordered_map<const void *, std::string> g_unitByFrame;
uint64_t g_lastSet = 0;
const void *CurrentMouseFocus() {
const void *ctx = *reinterpret_cast<const void *const *>(
const void *ctx = Game::Read<const void *>(
static_cast<uintptr_t>(Offsets::VAR_UI_CONTEXT_PTR));
if (ctx == nullptr)
return nullptr;
return *reinterpret_cast<const void *const *>(
reinterpret_cast<const uint8_t *>(ctx) + Offsets::OFF_UI_CONTEXT_MOUSE_FOCUS);
return Game::Read<const void *>(ctx, Offsets::OFF_UI_CONTEXT_MOUSE_FOCUS);
}
// The engine's real mouseover setter — `__stdcall(guidLo, guidHi, prevLo,
@@ -353,7 +352,7 @@ bool GuidHasLiveUnit(uint64_t guid) {
// works for an offline member). The engine's setter (FUN_00492890) gates this
// call on a live object, so offline members get nothing — we do it here.
void BuildRosterUnitTooltip(uint64_t guid) {
void *tooltip = *reinterpret_cast<void *const *>(
void *tooltip = Game::Read<void *>(
static_cast<uintptr_t>(Offsets::VAR_GAMETOOLTIP_OBJECT_PTR));
if (tooltip == nullptr)
return;
@@ -365,9 +364,8 @@ void BuildRosterUnitTooltip(uint64_t guid) {
// no owner and never re-appears (only a subsequent live-unit hover, which
// takes the engine's own anchor path, would). Use the self-contained
// invoker FUN_FRAME_INVOKE_SCRIPT, safe to call from the WorldTick.
const int anchorHandler = *reinterpret_cast<const int *>(
reinterpret_cast<uint8_t *>(tooltip) +
Offsets::OFF_TOOLTIP_SET_DEFAULT_ANCHOR_HANDLER);
const int anchorHandler = Game::Read<int>(
tooltip, Offsets::OFF_TOOLTIP_SET_DEFAULT_ANCHOR_HANDLER);
if (anchorHandler != 0)
reinterpret_cast<void(__fastcall *)(int, void *)>(
static_cast<uintptr_t>(Offsets::FUN_FRAME_INVOKE_SCRIPT))(anchorHandler,
@@ -598,10 +596,10 @@ bool DispatchVerb(void *L, int fi, const char *prefix, const char *suffix,
const bool swapped = unit != nullptr;
if (swapped) {
prevTarget =
(static_cast<uint64_t>(*reinterpret_cast<volatile uint32_t *>(
(static_cast<uint64_t>(Game::Read<volatile uint32_t>(
Offsets::VAR_CURRENT_SELECTION_GUID_HI))
<< 32) |
*reinterpret_cast<volatile uint32_t *>(
Game::Read<volatile uint32_t>(
Offsets::VAR_CURRENT_SELECTION_GUID_LO);
Game::Lua::CallGlobalString(L, "TargetUnit", unit);
}
+11 -17
View File
@@ -131,8 +131,7 @@ int __fastcall Script_IsMouseOver(void *L) {
Game::Lua::PushBool(L, false);
return 1;
}
const float effScale = *reinterpret_cast<const float *>(
reinterpret_cast<const uint8_t *>(obj) + Offsets::OFF_REGION_EFFECTIVE_SCALE);
const float effScale = Game::Read<float>(obj, Offsets::OFF_REGION_EFFECTIVE_SCALE);
double left, right, top, bottom;
if (effScale == 0.0f ||
@@ -193,13 +192,10 @@ int __fastcall Script_GetRect(void *L) {
// there, so it reports false, as it should.
int __fastcall Script_IsDragging(void *L) {
void *self = Game::Lua::ResolveObject(L, 1);
void *ctx = *reinterpret_cast<void *const *>(
static_cast<uintptr_t>(Offsets::VAR_UI_CONTEXT_PTR));
void *ctx = Game::Read<void *>(static_cast<uintptr_t>(Offsets::VAR_UI_CONTEXT_PTR));
void *dragTarget =
ctx != nullptr
? *reinterpret_cast<void *const *>(
reinterpret_cast<const uint8_t *>(ctx) +
Offsets::OFF_UI_CONTEXT_DRAG_TARGET)
? Game::Read<void *>(ctx, Offsets::OFF_UI_CONTEXT_DRAG_TARGET)
: nullptr;
Game::Lua::PushBool(L, self != nullptr && self == dragTarget);
return 1;
@@ -348,9 +344,9 @@ int __fastcall Script_HookScript(void *L) {
using SStrCmpI_t = int(__stdcall *)(const char *a, const char *b, int n);
bool FrameHasEvent(void *frame, const char *eventName) {
const uint32_t count = *reinterpret_cast<const uint32_t *>(
const uint32_t count = Game::Read<uint32_t>(
static_cast<uintptr_t>(Offsets::VAR_EVENT_TABLE_COUNT));
auto *base = *reinterpret_cast<const uint8_t *const *>(
auto *base = Game::Read<const uint8_t *>(
static_cast<uintptr_t>(Offsets::VAR_EVENT_TABLE_BASE_PTR));
if (count == 0 || base == nullptr)
return false;
@@ -360,21 +356,19 @@ bool FrameHasEvent(void *frame, const char *eventName) {
for (uint32_t i = 0; i < count; ++i) {
const uint8_t *entry = base + i * Offsets::EVENT_ENTRY_STRIDE;
const char *name = *reinterpret_cast<const char *const *>(
entry + Offsets::OFF_EVENT_ENTRY_NAME);
const char *name = Game::Read<const char *>(
entry, Offsets::OFF_EVENT_ENTRY_NAME);
if (name == nullptr)
continue;
if (sstrcmpi(name, eventName, 0x7FFFFFFF) != 0)
continue;
// Names are unique, so this is the one entry — walk its chain.
uintptr_t node = *reinterpret_cast<const uintptr_t *>(
entry + Offsets::OFF_EVENT_ENTRY_HEAD);
uintptr_t node = Game::Read<uintptr_t>(
entry, Offsets::OFF_EVENT_ENTRY_HEAD);
while ((node & 1) == 0 && node != 0) {
if (*reinterpret_cast<void *const *>(
node + Offsets::OFF_EVENT_NODE_FRAME) == frame)
if (Game::Read<void *>(node + Offsets::OFF_EVENT_NODE_FRAME) == frame)
return true;
node = *reinterpret_cast<const uintptr_t *>(
node + Offsets::OFF_EVENT_NODE_NEXT);
node = Game::Read<uintptr_t>(node + Offsets::OFF_EVENT_NODE_NEXT);
}
return false;
}
+6 -12
View File
@@ -54,8 +54,7 @@ int CallScript(uintptr_t fn, void *L) {
// The UI context is a pointer stored at VAR_UI_CONTEXT_PTR (null pre-world).
void *UIContext() {
return *reinterpret_cast<void *const *>(
static_cast<uintptr_t>(Offsets::VAR_UI_CONTEXT_PTR));
return Game::Read<void *>(static_cast<uintptr_t>(Offsets::VAR_UI_CONTEXT_PTR));
}
// Strata name -> draw rank, low (behind) to high (on top). Unknown -> 0.
@@ -110,8 +109,7 @@ Cursor ReadCursor(void *L) {
// With `self` at Lua idx 1, is the cursor within the frame's rect?
bool CursorOverSelf(void *L, void *obj, const Cursor &cur) {
const float effScale = *reinterpret_cast<const float *>(
reinterpret_cast<const uint8_t *>(obj) + Offsets::OFF_REGION_EFFECTIVE_SCALE);
const float effScale = Game::Read<float>(obj, Offsets::OFF_REGION_EFFECTIVE_SCALE);
if (effScale == 0.0f)
return false; // unpositioned region — no rect
double left, right, top, bottom;
@@ -141,19 +139,16 @@ int __fastcall Script_GetMouseFoci(void *L) {
// The engine's authoritative topmost focus — the frame GetMouseFocus
// returns. Forced to index 1 below.
void *focus = *reinterpret_cast<void *const *>(
reinterpret_cast<uint8_t *>(ctx) + Offsets::OFF_UI_CONTEXT_MOUSE_FOCUS);
void *focus = Game::Read<void *>(ctx, Offsets::OFF_UI_CONTEXT_MOUSE_FOCUS);
const Cursor cur = ReadCursor(L);
std::vector<Hit> hits;
void *node = *reinterpret_cast<void *const *>(
reinterpret_cast<uint8_t *>(ctx) + Offsets::OFF_UI_CONTEXT_FRAME_LIST_HEAD);
void *node = Game::Read<void *>(ctx, Offsets::OFF_UI_CONTEXT_FRAME_LIST_HEAD);
while (node != nullptr && (reinterpret_cast<uintptr_t>(node) & 1) == 0) {
// Read the next link before any Lua work (the walk is engine-list
// based, independent of the Lua stack, but this keeps it obvious).
void *next = *reinterpret_cast<void *const *>(
reinterpret_cast<uint8_t *>(node) + Offsets::OFF_FRAME_ENUM_NEXT);
void *next = Game::Read<void *>(node, Offsets::OFF_FRAME_ENUM_NEXT);
Game::Lua::SetTop(L, 0);
UI::FrameObject::Push(L, node); // (self)
@@ -164,8 +159,7 @@ int __fastcall Script_GetMouseFoci(void *L) {
Game::Lua::SetTop(L, 1);
CallScript(Offsets::FUN_SCRIPT_FRAME_GET_STRATA, L); // (self, strata)
const int rank = StrataRank(Game::Lua::ToString(L, 2));
const int level = *reinterpret_cast<const int *>(
reinterpret_cast<uint8_t *>(node) + Offsets::OFF_FRAME_LEVEL);
const int level = Game::Read<int>(node, Offsets::OFF_FRAME_LEVEL);
hits.push_back(Hit{node, rank, level});
}
+4 -7
View File
@@ -77,11 +77,10 @@ const auto RawGetI = reinterpret_cast<RawGetI_t>(Offsets::LUA_RAWGETI);
// Returns the frame's Lua object ref (frame+0x08), lazily creating it exactly
// as the engine runner does (`if (refcount == 0) ScriptRegister(frame, 0)`).
int EnsureLuaRef(void *frame) {
auto *f = reinterpret_cast<uint8_t *>(frame);
if (*reinterpret_cast<int *>(f + Offsets::OFF_COBJECT_LUA_REFCOUNT) == 0)
if (Game::Read<int>(frame, Offsets::OFF_COBJECT_LUA_REFCOUNT) == 0)
reinterpret_cast<ScriptRegister_t>(
Offsets::FUN_FRAMESCRIPT_OBJECT_SCRIPT_REGISTER)(frame, nullptr);
return *reinterpret_cast<int *>(f + Offsets::OFF_COBJECT_LUA_REF);
return Game::Read<int>(frame, Offsets::OFF_COBJECT_LUA_REF);
}
// Writes "arg" + k (k in 1..19) into buf; buf must hold at least 6 bytes.
@@ -193,9 +192,7 @@ bool RunModern(int handlerRef, void *frame, const char *fmt, const void *vaPtr)
// as the first positional to mirror retail's (self, event, arg1..argN).
const bool isOnEvent =
haveThis &&
*reinterpret_cast<const int *>(reinterpret_cast<uint8_t *>(frame) +
Offsets::OFF_FRAME_ONEVENT_SLOT) ==
handlerRef;
Game::Read<int>(frame, Offsets::OFF_FRAME_ONEVENT_SLOT) == handlerRef;
const int selfRef = haveThis ? EnsureLuaRef(frame) : 0;
Arg args[kMaxArgs];
@@ -230,7 +227,7 @@ bool RunModern(int handlerRef, void *frame, const char *fmt, const void *vaPtr)
// --- call handler(self, [event,] arg1..argN) ---------------------------
const int callBase = GetTop(L); // == base + saved-block size
const int errRef = *reinterpret_cast<const int *>(
const int errRef = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_FRAMESCRIPT_ERROR_HANDLER_REF));
int errIdx = 0;
if (errRef > 0) {
+4 -3
View File
@@ -18,6 +18,7 @@
#include "Notes.h"
#include "Game.h"
#include "Offsets.h"
#include <cstdint>
@@ -41,14 +42,14 @@ std::string g_path;
bool g_loaded = false;
const char *ReadAccountName() {
return *reinterpret_cast<const char *const *>(Offsets::VAR_ACCOUNT_NAME_PTR);
return Game::Read<const char *>(Offsets::VAR_ACCOUNT_NAME_PTR);
}
const char *ReadRealmName() {
auto *info = *reinterpret_cast<uint8_t **>(Offsets::VAR_REALM_INFO_PTR);
auto *info = Game::Read<uint8_t *>(Offsets::VAR_REALM_INFO_PTR);
if (info == nullptr)
return nullptr;
return *reinterpret_cast<const char *const *>(info + Offsets::OFF_REALM_INFO_NAME);
return Game::Read<const char *>(info, Offsets::OFF_REALM_INFO_NAME);
}
const char *ReadCharacterName() {
+8 -9
View File
@@ -34,8 +34,7 @@ namespace FriendList::WhoInfo {
namespace {
int WhoResultCount() {
return *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_WHO_RESULT_COUNT));
return Game::Read<int>(Offsets::VAR_WHO_RESULT_COUNT);
}
// `C_FriendList.GetNumWhoResults()` → `numWhos, totalCount`. The first is the
@@ -44,7 +43,7 @@ int WhoResultCount() {
// global's two returns.
int __fastcall Script_GetNumWhoResults(void *L) {
const int displayed = WhoResultCount();
const int total = *reinterpret_cast<const int *>(
const int total = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_WHO_RESULT_COUNT) + 4);
Game::Lua::PushNumber(L, static_cast<double>(displayed));
Game::Lua::PushNumber(L, static_cast<double>(total));
@@ -67,15 +66,15 @@ int __fastcall Script_GetWhoInfo(void *L) {
static_cast<uintptr_t>(Offsets::VAR_WHO_RESULTS) +
static_cast<size_t>(index - 1) * Offsets::WHO_RESULT_STRIDE);
const char *name = reinterpret_cast<const char *>(entry + Offsets::OFF_WHO_NAME);
const char *guild = reinterpret_cast<const char *>(entry + Offsets::OFF_WHO_GUILD);
const int level = *reinterpret_cast<const int *>(entry + Offsets::OFF_WHO_LEVEL);
const char *name = Game::Ptr<const char>(entry, Offsets::OFF_WHO_NAME);
const char *guild = Game::Ptr<const char>(entry, Offsets::OFF_WHO_GUILD);
const int level = Game::Read<int>(entry, Offsets::OFF_WHO_LEVEL);
const uint32_t raceID =
*reinterpret_cast<const uint32_t *>(entry + Offsets::OFF_WHO_RACE);
Game::Read<uint32_t>(entry, Offsets::OFF_WHO_RACE);
const uint32_t classID =
*reinterpret_cast<const uint32_t *>(entry + Offsets::OFF_WHO_CLASS);
Game::Read<uint32_t>(entry, Offsets::OFF_WHO_CLASS);
const uint32_t zoneID =
*reinterpret_cast<const uint32_t *>(entry + Offsets::OFF_WHO_ZONE);
Game::Read<uint32_t>(entry, Offsets::OFF_WHO_ZONE);
Game::Lua::NewTable(L);
Game::Lua::SetFieldString(L, "fullName", name); // inline; "" if empty
+3 -3
View File
@@ -72,10 +72,10 @@ int __fastcall Script_GetGameObjectInfoByID(void *L) {
if (rec == nullptr)
return 0; // not cached -> nil
const uint32_t type = *reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_GAMEOBJECT_TYPE);
const uint32_t type = Game::Read<uint32_t>(rec, Offsets::OFF_GAMEOBJECT_TYPE);
const uint32_t displayID =
*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_GAMEOBJECT_DISPLAYID);
const char *name = *reinterpret_cast<const char *const *>(rec + Offsets::OFF_GAMEOBJECT_NAME);
Game::Read<uint32_t>(rec, Offsets::OFF_GAMEOBJECT_DISPLAYID);
const char *name = Game::Read<const char *>(rec, Offsets::OFF_GAMEOBJECT_NAME);
Game::Lua::NewTable(L);
Game::Lua::SetFieldNumber(L, "gameObjectID", goID);
+8 -8
View File
@@ -63,10 +63,10 @@ static int __fastcall Script_GameTooltipGetGameObject(void *L) {
return 0;
const auto *base = static_cast<const uint8_t *>(tooltipObj);
const uint32_t guidLo = *reinterpret_cast<const uint32_t *>(
base + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO);
const uint32_t guidHi = *reinterpret_cast<const uint32_t *>(
base + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_HI);
const uint32_t guidLo =
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO);
const uint32_t guidHi =
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_HI);
if (guidLo == 0 && guidHi == 0)
return 0;
@@ -111,10 +111,10 @@ static int __fastcall Script_GameTooltipHasGameObject(void *L) {
return 1;
}
const auto *base = static_cast<const uint8_t *>(tooltipObj);
const uint32_t guidLo = *reinterpret_cast<const uint32_t *>(
base + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO);
const uint32_t guidHi = *reinterpret_cast<const uint32_t *>(
base + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_HI);
const uint32_t guidLo =
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO);
const uint32_t guidHi =
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_HI);
Game::Lua::PushBool(L, guidLo != 0 || guidHi != 0);
return 1;
}
+10 -9
View File
@@ -13,6 +13,7 @@
#include "group/MemberStats.h"
#include "Game.h"
#include "Offsets.h"
namespace Group::MemberStats {
@@ -23,7 +24,7 @@ namespace {
using Lookup_t = const uint8_t *(__fastcall *)(uint64_t *guid);
uint16_t U16(const uint8_t *p, int off) {
return *reinterpret_cast<const uint16_t *>(p + off);
return Game::Read<uint16_t>(p, off);
}
} // namespace
@@ -67,13 +68,13 @@ Stats Lookup(uint64_t guid) {
s.level = U16(e, Offsets::OFF_RAID_SLOT_LEVEL);
s.areaId = U16(e, Offsets::OFF_RAID_SLOT_AREA_ID);
const uint32_t flags =
*reinterpret_cast<const uint32_t *>(e + Offsets::OFF_RAID_SLOT_FLAGS);
Game::Read<uint32_t>(e, Offsets::OFF_RAID_SLOT_FLAGS);
s.online = (flags & Offsets::RAID_SLOT_FLAG_ONLINE) != 0;
s.dead = (flags & Offsets::RAID_SLOT_FLAG_DEAD) != 0;
s.subgroup = static_cast<int>(*reinterpret_cast<const uint32_t *>(
e + Offsets::OFF_RAID_SLOT_SUBGROUP)) + 1;
s.subgroup = static_cast<int>(Game::Read<uint32_t>(
e, Offsets::OFF_RAID_SLOT_SUBGROUP)) + 1;
s.rank = static_cast<int>(
*reinterpret_cast<const uint32_t *>(e + Offsets::OFF_RAID_SLOT_RANK));
Game::Read<uint32_t>(e, Offsets::OFF_RAID_SLOT_RANK));
return s;
}
@@ -93,8 +94,8 @@ const uint16_t *AuraArray(uint64_t guid) {
if ((e[Offsets::OFF_GROUP_MEMBER_STATUS_FLAGS] &
Offsets::GROUP_MEMBER_STATUS_ONLINE) == 0)
return nullptr;
return reinterpret_cast<const uint16_t *>(
e + Offsets::OFF_GROUP_MEMBER_STATS_AURAS);
return Game::Ptr<const uint16_t>(
e, Offsets::OFF_GROUP_MEMBER_STATS_AURAS);
}
// Raid slot — auras at +0x64, no online gate (mirrors the engine's raid
@@ -102,8 +103,8 @@ const uint16_t *AuraArray(uint64_t guid) {
auto slotFn = reinterpret_cast<Lookup_t>(
static_cast<uintptr_t>(Offsets::FUN_GROUP_MEMBER_SLOT_LOOKUP));
if (const uint8_t *e = slotFn(&guid)) {
return reinterpret_cast<const uint16_t *>(
e + Offsets::OFF_RAID_SLOT_AURAS);
return Game::Ptr<const uint16_t>(
e, Offsets::OFF_RAID_SLOT_AURAS);
}
return nullptr;
+6 -6
View File
@@ -138,8 +138,8 @@ ItemInfo ReadItemInfo(const uint8_t *cgItem) {
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
return {0, 0};
}
return {*reinterpret_cast<const uint32_t *>(record + Offsets::OFF_ITEMSTATS_ITEM_LEVEL),
*reinterpret_cast<const uint32_t *>(record + Offsets::OFF_ITEMSTATS_INVENTORY_TYPE)};
return {Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_ITEM_LEVEL),
Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_INVENTORY_TYPE)};
}
// Bank-walk helpers — bypass the bank-window gate on `GetItemBySlot`
@@ -184,8 +184,8 @@ void WalkGuidArrayRange(const uint8_t *invMgr, int firstSlot, int lastSlot,
std::vector<Candidate> &candidates) {
if (invMgr == nullptr)
return;
auto *guidArray = *reinterpret_cast<const uint64_t *const *>(
invMgr + Offsets::OFF_INVMGR_GUID_ARRAY);
auto *guidArray = Game::Read<const uint64_t *>(
invMgr, Offsets::OFF_INVMGR_GUID_ARRAY);
if (guidArray == nullptr)
return;
for (int slot = firstSlot; slot <= lastSlot; ++slot) {
@@ -203,8 +203,8 @@ void WalkBankBags(std::vector<Candidate> &candidates) {
auto *playerInvMgr = Unit::Identity::PlayerInventoryManager();
if (playerInvMgr == nullptr)
return;
auto *playerGuidArray = *reinterpret_cast<const uint64_t *const *>(
playerInvMgr + Offsets::OFF_INVMGR_GUID_ARRAY);
auto *playerGuidArray = Game::Read<const uint64_t *>(
playerInvMgr, Offsets::OFF_INVMGR_GUID_ARRAY);
if (playerGuidArray == nullptr)
return;
for (int slot = Offsets::INVMGR_BANK_BAG_FIRST_SLOT;
+3 -3
View File
@@ -39,7 +39,7 @@ constexpr int OFF_CONTAINER_GUID_LO = 0x08;
constexpr int OFF_CONTAINER_GUID_HI = 0x0C;
bool ItemLocked(const uint8_t *item) {
return (*reinterpret_cast<const uint32_t *>(item + Offsets::OFF_ITEM_CLIENT_LOCK) & 1) != 0;
return (Game::Read<uint32_t>(item, Offsets::OFF_ITEM_CLIENT_LOCK) & 1) != 0;
}
// Reads a CGItem's 64-bit instance GUID into lo/hi. False if the instance
@@ -48,8 +48,8 @@ bool ReadItemGuid(const uint8_t *item, uint32_t *lo, uint32_t *hi) {
auto *instance = Item::InstanceBlock(item);
if (instance == nullptr)
return false;
*lo = *reinterpret_cast<const uint32_t *>(instance + Offsets::OFF_INSTANCE_BLOCK_GUID);
*hi = *reinterpret_cast<const uint32_t *>(instance + Offsets::OFF_INSTANCE_BLOCK_GUID + 4);
*lo = Game::Read<uint32_t>(instance, Offsets::OFF_INSTANCE_BLOCK_GUID);
*hi = Game::Read<uint32_t>(instance, Offsets::OFF_INSTANCE_BLOCK_GUID + 4);
return true;
}
+5 -5
View File
@@ -115,8 +115,8 @@ static int ResolveLocationToItemID(void *L, int idx) {
auto *instance = Item::InstanceBlock(item);
if (instance == nullptr)
return 0;
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
instance + Offsets::OFF_INSTANCE_BLOCK_ITEM_ID));
return static_cast<int>(Game::Read<uint32_t>(
instance, Offsets::OFF_INSTANCE_BLOCK_ITEM_ID));
}
static int __fastcall Script_IsItemDataCachedByID(void *L) {
@@ -383,8 +383,8 @@ static void AddOwned(uint32_t itemID) {
static void CollectOwnedFrom(const uint8_t *invMgr, int first, int last) {
if (invMgr == nullptr)
return;
auto *guids = *reinterpret_cast<const uint64_t *const *>(
invMgr + Offsets::OFF_INVMGR_GUID_ARRAY);
auto *guids = Game::Read<const uint64_t *>(
invMgr, Offsets::OFF_INVMGR_GUID_ARRAY);
if (guids == nullptr)
return;
for (int slot = first; slot <= last; ++slot) {
@@ -409,7 +409,7 @@ static void RebuildOwned() {
if (bagInv == nullptr)
continue;
const int count = static_cast<int>(
*reinterpret_cast<const uint32_t *>(bagInv + Offsets::OFF_INVMGR_SLOT_COUNT));
Game::Read<uint32_t>(bagInv, Offsets::OFF_INVMGR_SLOT_COUNT));
if (count > 0)
CollectOwnedFrom(bagInv, 0, count - 1);
}
+5 -5
View File
@@ -83,8 +83,8 @@ int __fastcall Script_C_Item_GetEnchantInfo(void *L) {
// Localized display name (8-slot locale array at +0x34). Clamp the
// locale index to the array bounds — index 8 would read the locale
// mask column that follows. enUS (0) fallback for empty slots.
auto names = reinterpret_cast<const char *const *>(rec + Offsets::OFF_SPELLITEMENCHANT_NAME);
int locale = *reinterpret_cast<const int *>(Offsets::VAR_LOCALE_INDEX);
auto names = Game::Ptr<const char *const>(rec, Offsets::OFF_SPELLITEMENCHANT_NAME);
int locale = Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
if (locale < 0 || locale >= kNumNameLocales)
locale = 0;
const char *name = names[locale];
@@ -93,9 +93,9 @@ int __fastcall Script_C_Item_GetEnchantInfo(void *L) {
if (name == nullptr || name[0] == '\0')
return 0; // unnamed record -> nil
auto type = reinterpret_cast<const int32_t *>(rec + Offsets::OFF_SPELLITEMENCHANT_TYPE);
auto amount = reinterpret_cast<const int32_t *>(rec + Offsets::OFF_SPELLITEMENCHANT_AMOUNT);
auto arg = reinterpret_cast<const int32_t *>(rec + Offsets::OFF_SPELLITEMENCHANT_ARG);
auto type = Game::Ptr<const int32_t>(rec, Offsets::OFF_SPELLITEMENCHANT_TYPE);
auto amount = Game::Ptr<const int32_t>(rec, Offsets::OFF_SPELLITEMENCHANT_AMOUNT);
auto arg = Game::Ptr<const int32_t>(rec, Offsets::OFF_SPELLITEMENCHANT_ARG);
Game::Lua::NewTable(L);
Game::Lua::SetFieldNumber(L, "enchantID", enchantID);
+41 -41
View File
@@ -38,7 +38,7 @@ namespace Item::GetData {
namespace {
int CurrentLocaleIndex() {
return *reinterpret_cast<int *>(Offsets::VAR_LOCALE_INDEX);
return Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
}
// Mirrors the lookup in `Item::Info`. ItemClass.dbc record `+0x0C` is
@@ -53,10 +53,10 @@ const char *LookupClassName(uint32_t classID) {
// ItemSubClass.dbc walker — same fallback chain as Script_GetItemInfo
// (verbose name first, short name on miss).
const char *LookupSubClassName(uint32_t classID, uint32_t subClassID) {
const int count = *reinterpret_cast<int *>(Offsets::VAR_ITEMSUBCLASS_COUNT);
const int count = Game::Read<int>(Offsets::VAR_ITEMSUBCLASS_COUNT);
if (count <= 0)
return "";
auto *records = *reinterpret_cast<const uint8_t *const *>(Offsets::VAR_ITEMSUBCLASS_RECORDS);
auto *records = Game::Read<const uint8_t *>(Offsets::VAR_ITEMSUBCLASS_RECORDS);
if (records == nullptr)
return "";
const int locale = CurrentLocaleIndex();
@@ -66,12 +66,12 @@ const char *LookupSubClassName(uint32_t classID, uint32_t subClassID) {
continue;
if (*reinterpret_cast<const uint32_t *>(record + 0x04) != subClassID)
continue;
const char *verbose = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSUBCLASS_DISPLAY_NAME + locale * 4);
const char *verbose = Game::Read<const char *>(
record, Offsets::OFF_ITEMSUBCLASS_DISPLAY_NAME + locale * 4);
if (verbose != nullptr && verbose[0] != '\0')
return verbose;
const char *shortName = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSUBCLASS_NAME + locale * 4);
const char *shortName = Game::Read<const char *>(
record, Offsets::OFF_ITEMSUBCLASS_NAME + locale * 4);
return (shortName != nullptr && shortName[0] != '\0') ? shortName : "";
}
return "";
@@ -172,10 +172,10 @@ void SetF32Array(void *L, const uint8_t *record, const char *key,
void SetStatsMap(void *L, const uint8_t *record) {
Game::Lua::PushString(L, "stats");
Game::Lua::NewTable(L);
auto *types = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_STAT_TYPE);
auto *values = reinterpret_cast<const int32_t *>(
record + Offsets::OFF_ITEMSTATS_STAT_VALUE);
auto *types = Game::Ptr<const uint32_t>(
record, Offsets::OFF_ITEMSTATS_STAT_TYPE);
auto *values = Game::Ptr<const int32_t>(
record, Offsets::OFF_ITEMSTATS_STAT_VALUE);
for (int i = 0; i < Offsets::ITEMSTATS_STAT_SLOT_COUNT; ++i) {
if (types[i] == 0 && values[i] == 0)
continue;
@@ -193,18 +193,18 @@ void SetStatsMap(void *L, const uint8_t *record) {
void SetSpellsArray(void *L, const uint8_t *record) {
Game::Lua::PushString(L, "spells");
Game::Lua::NewTable(L);
auto *ids = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_SPELL_ID);
auto *triggers = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_SPELL_TRIGGER);
auto *charges = reinterpret_cast<const int32_t *>(
record + Offsets::OFF_ITEMSTATS_SPELL_CHARGES);
auto *cooldowns = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_SPELL_COOLDOWN);
auto *categories = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_SPELL_CATEGORY);
auto *catCooldowns = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_SPELL_CATEGORY_CD);
auto *ids = Game::Ptr<const uint32_t>(
record, Offsets::OFF_ITEMSTATS_SPELL_ID);
auto *triggers = Game::Ptr<const uint32_t>(
record, Offsets::OFF_ITEMSTATS_SPELL_TRIGGER);
auto *charges = Game::Ptr<const int32_t>(
record, Offsets::OFF_ITEMSTATS_SPELL_CHARGES);
auto *cooldowns = Game::Ptr<const uint32_t>(
record, Offsets::OFF_ITEMSTATS_SPELL_COOLDOWN);
auto *categories = Game::Ptr<const uint32_t>(
record, Offsets::OFF_ITEMSTATS_SPELL_CATEGORY);
auto *catCooldowns = Game::Ptr<const uint32_t>(
record, Offsets::OFF_ITEMSTATS_SPELL_CATEGORY_CD);
int written = 0;
for (int i = 0; i < Offsets::ITEMSTATS_SPELL_SLOT_COUNT; ++i) {
if (ids[i] == 0)
@@ -234,38 +234,38 @@ void PushItemDataTable(void *L, uint32_t itemID, const uint8_t *record) {
Game::Lua::SetFieldNumber(L, "itemID", static_cast<double>(itemID));
// Identity strings
const char *name = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSTATS_NAME);
const char *name = Game::Read<const char *>(
record, Offsets::OFF_ITEMSTATS_NAME);
Game::Lua::SetFieldString(L, "name", name);
const char *description = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSTATS_DESCRIPTION);
const char *description = Game::Read<const char *>(
record, Offsets::OFF_ITEMSTATS_DESCRIPTION);
if (description != nullptr && description[0] != '\0')
Game::Lua::SetFieldString(L, "description", description);
// Display
const uint32_t displayInfoID = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
const uint32_t displayInfoID = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
Game::Lua::SetFieldNumber(L, "displayInfoID", static_cast<double>(displayInfoID));
char iconPath[260];
if (BuildIconPath(displayInfoID, iconPath, sizeof(iconPath)))
Game::Lua::SetFieldString(L, "icon", iconPath);
// Quality / classification
const uint32_t quality = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_QUALITY);
const uint32_t quality = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_QUALITY);
Game::Lua::SetFieldNumber(L, "quality", static_cast<double>(quality));
const uint32_t classID = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_CLASS);
const uint32_t subClassID = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_SUBCLASS);
const uint32_t classID = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_CLASS);
const uint32_t subClassID = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_SUBCLASS);
Game::Lua::SetFieldNumber(L, "classID", static_cast<double>(classID));
Game::Lua::SetFieldNumber(L, "subclassID", static_cast<double>(subClassID));
Game::Lua::SetFieldString(L, "className", LookupClassName(classID));
Game::Lua::SetFieldString(L, "subclassName", LookupSubClassName(classID, subClassID));
const uint32_t invType = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_INVENTORY_TYPE);
const uint32_t invType = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_INVENTORY_TYPE);
Game::Lua::SetFieldNumber(L, "inventoryType", static_cast<double>(invType));
Game::Lua::SetFieldString(L, "equipLoc", LookupInvType(invType));
@@ -273,8 +273,8 @@ void PushItemDataTable(void *L, uint32_t itemID, const uint8_t *record) {
SetU32(L, record, "bindType", Offsets::OFF_ITEMSTATS_BONDING);
// Flags: raw + decoded bits.
const uint32_t flags = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_FLAGS);
const uint32_t flags = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_FLAGS);
Game::Lua::SetFieldNumber(L, "flags", static_cast<double>(flags));
Game::Lua::SetFieldBool(L, "isConjured",
(flags & Offsets::ITEM_FLAG_CONJURED) != 0);
@@ -289,8 +289,8 @@ void PushItemDataTable(void *L, uint32_t itemID, const uint8_t *record) {
SetI32(L, record, "maxStackSize", Offsets::OFF_ITEMSTATS_STACKABLE);
SetI32(L, record, "maxCount", Offsets::OFF_ITEMSTATS_MAX_COUNT);
SetU32(L, record, "containerSlots", Offsets::OFF_ITEMSTATS_CONTAINER_SLOTS);
const uint32_t rawBagFamily = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_BAG_FAMILY);
const uint32_t rawBagFamily = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_BAG_FAMILY);
Game::Lua::SetFieldNumber(L, "bagFamily",
static_cast<double>(BagFamilyIdToBitmask(rawBagFamily)));
+17 -17
View File
@@ -30,7 +30,7 @@ namespace Item::Info {
static const char *PushedOrEmpty(const char *s) { return (s != nullptr && s[0] != 0) ? s : ""; }
static int CurrentLocaleIndex() { return *reinterpret_cast<int *>(Offsets::VAR_LOCALE_INDEX); }
static int CurrentLocaleIndex() { return Game::Read<int>(Offsets::VAR_LOCALE_INDEX); }
static const char *LookupItemClassName(uint32_t classID) {
return PushedOrEmpty(DBC::LocalizedField(
@@ -39,10 +39,10 @@ static const char *LookupItemClassName(uint32_t classID) {
}
static const char *LookupItemSubClassName(uint32_t classID, uint32_t subClassID) {
const int count = *reinterpret_cast<int *>(Offsets::VAR_ITEMSUBCLASS_COUNT);
const int count = Game::Read<int>(Offsets::VAR_ITEMSUBCLASS_COUNT);
if (count <= 0)
return "";
auto *records = *reinterpret_cast<const uint8_t *const *>(Offsets::VAR_ITEMSUBCLASS_RECORDS);
auto *records = Game::Read<const uint8_t *>(Offsets::VAR_ITEMSUBCLASS_RECORDS);
if (records == nullptr)
return "";
const int locale = CurrentLocaleIndex();
@@ -54,12 +54,12 @@ static const char *LookupItemSubClassName(uint32_t classID, uint32_t subClassID)
continue;
// Mirror Script_GetItemInfo's fallback chain at 0x48E311..0x48E32C:
// try the verbose name first, fall back to the short name.
const char *verbose = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSUBCLASS_DISPLAY_NAME + locale * 4);
const char *verbose = Game::Read<const char *>(
record, Offsets::OFF_ITEMSUBCLASS_DISPLAY_NAME + locale * 4);
if (verbose != nullptr && verbose[0] != 0)
return verbose;
const char *shortName = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSUBCLASS_NAME + locale * 4);
const char *shortName = Game::Read<const char *>(
record, Offsets::OFF_ITEMSUBCLASS_NAME + locale * 4);
return PushedOrEmpty(shortName);
}
return "";
@@ -112,13 +112,13 @@ static int __fastcall Script_GetItemInfoInstant(void *L) {
}
const uint32_t classID =
*reinterpret_cast<const uint32_t *>(record + Offsets::OFF_ITEMSTATS_CLASS);
Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_CLASS);
const uint32_t subClassID =
*reinterpret_cast<const uint32_t *>(record + Offsets::OFF_ITEMSTATS_SUBCLASS);
Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_SUBCLASS);
const uint32_t displayInfoID =
*reinterpret_cast<const uint32_t *>(record + Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
const uint32_t invType =
*reinterpret_cast<const uint32_t *>(record + Offsets::OFF_ITEMSTATS_INVENTORY_TYPE);
Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_INVENTORY_TYPE);
char iconPath[260];
if (!BuildIconPath(displayInfoID, iconPath, sizeof(iconPath)))
@@ -143,8 +143,8 @@ static int PushIconForItemID(void *L, int itemID) {
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
if (record == nullptr)
return 0;
const uint32_t displayInfoID = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
const uint32_t displayInfoID = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_DISPLAY_INFO_ID);
char iconPath[260];
if (!BuildIconPath(displayInfoID, iconPath, sizeof(iconPath)))
return 0;
@@ -274,10 +274,10 @@ static int __fastcall Script_C_Item_GetItemInfo(void *L) {
const uint32_t sellPrice = u32(Offsets::OFF_ITEMSTATS_SELL_PRICE);
const uint32_t bindType = u32(Offsets::OFF_ITEMSTATS_BONDING);
const uint32_t setID = u32(Offsets::OFF_ITEMSTATS_ITEM_SET);
const char *name = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSTATS_NAME);
const char *description = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSTATS_DESCRIPTION);
const char *name = Game::Read<const char *>(
record, Offsets::OFF_ITEMSTATS_NAME);
const char *description = Game::Read<const char *>(
record, Offsets::OFF_ITEMSTATS_DESCRIPTION);
// Apply the link's random suffix ("... of the Owl") to both the name and
// the reconstructed link when the input carried one (arg.suffix); with no
+4 -4
View File
@@ -58,8 +58,8 @@ bool ReadItemGuid(const uint8_t *item, uint32_t *lo, uint32_t *hi) {
auto *inst = Item::InstanceBlock(item);
if (inst == nullptr)
return false;
*lo = *reinterpret_cast<const uint32_t *>(inst + Offsets::OFF_INSTANCE_BLOCK_GUID);
*hi = *reinterpret_cast<const uint32_t *>(inst + Offsets::OFF_INSTANCE_BLOCK_GUID + 4);
*lo = Game::Read<uint32_t>(inst, Offsets::OFF_INSTANCE_BLOCK_GUID);
*hi = Game::Read<uint32_t>(inst, Offsets::OFF_INSTANCE_BLOCK_GUID + 4);
return true;
}
@@ -84,8 +84,8 @@ int __fastcall Script_C_Item_IsLocked(void *L) {
Game::Lua::PushBool(L, false);
return 1;
}
const uint32_t flags = *reinterpret_cast<const uint32_t *>(
item + Offsets::OFF_ITEM_CLIENT_LOCK);
const uint32_t flags = Game::Read<uint32_t>(
item, Offsets::OFF_ITEM_CLIENT_LOCK);
Game::Lua::PushBool(L, (flags & Offsets::ITEM_CLIENT_LOCK_BIT) != 0);
return 1;
}
+27 -27
View File
@@ -155,14 +155,14 @@ void AddSpellStatAuras(Accum *acc, int spellID, long sign) {
static_cast<uint32_t>(spellID));
if (sp == nullptr)
return;
auto aura = reinterpret_cast<const int32_t *>(
sp + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME);
auto misc = reinterpret_cast<const int32_t *>(
sp + Offsets::OFF_SPELL_RECORD_EFFECT_MISC_VALUE);
auto base = reinterpret_cast<const int32_t *>(
sp + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS);
auto dice = reinterpret_cast<const int32_t *>(
sp + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE);
auto aura = Game::Ptr<const int32_t>(
sp, Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME);
auto misc = Game::Ptr<const int32_t>(
sp, Offsets::OFF_SPELL_RECORD_EFFECT_MISC_VALUE);
auto base = Game::Ptr<const int32_t>(
sp, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS);
auto dice = Game::Ptr<const int32_t>(
sp, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE);
// Vanilla "+N Attack Power" spells carry a melee (99) AND a ranged
// (124) aura with the same value; the generic melee key subsumes the
@@ -248,10 +248,10 @@ void AddSpellStatAuras(Accum *acc, int spellID, long sign) {
// mp5 / defense on base items (vanilla stores them as equip spells, not
// stat slots).
void AddEquipSpellStats(Accum *acc, const uint8_t *record, long sign) {
auto ids = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_SPELL_ID);
auto triggers = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_SPELL_TRIGGER);
auto ids = Game::Ptr<const uint32_t>(
record, Offsets::OFF_ITEMSTATS_SPELL_ID);
auto triggers = Game::Ptr<const uint32_t>(
record, Offsets::OFF_ITEMSTATS_SPELL_TRIGGER);
for (int i = 0; i < Offsets::ITEMSTATS_SPELL_SLOT_COUNT; ++i)
if (ids[i] != 0 && triggers[i] == 1) // ON_EQUIP
AddSpellStatAuras(acc, static_cast<int>(ids[i]), sign);
@@ -288,14 +288,14 @@ long Value(const Accum *acc, const char *key) {
double ComputeDPS(const uint8_t *record) {
if (record == nullptr)
return 0.0;
const uint32_t delayMs = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_DELAY);
const uint32_t delayMs = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_DELAY);
if (delayMs == 0)
return 0.0;
auto *dmgMin = reinterpret_cast<const float *>(
record + Offsets::OFF_ITEMSTATS_DAMAGE_MIN);
auto *dmgMax = reinterpret_cast<const float *>(
record + Offsets::OFF_ITEMSTATS_DAMAGE_MAX);
auto *dmgMin = Game::Ptr<const float>(
record, Offsets::OFF_ITEMSTATS_DAMAGE_MIN);
auto *dmgMax = Game::Ptr<const float>(
record, Offsets::OFF_ITEMSTATS_DAMAGE_MAX);
double avgTotal = 0.0;
for (int i = 0; i < Offsets::ITEMSTATS_DAMAGE_SLOT_COUNT; ++i)
avgTotal += (static_cast<double>(dmgMin[i]) +
@@ -312,9 +312,9 @@ void ApplyEnchant(Accum *acc, uint32_t enchantID, long sign) {
Offsets::VAR_SPELLITEMENCHANT_COUNT, enchantID);
if (en == nullptr)
return;
auto type = reinterpret_cast<const int32_t *>(en + Offsets::OFF_SPELLITEMENCHANT_TYPE);
auto amount = reinterpret_cast<const int32_t *>(en + Offsets::OFF_SPELLITEMENCHANT_AMOUNT);
auto arg = reinterpret_cast<const int32_t *>(en + Offsets::OFF_SPELLITEMENCHANT_ARG);
auto type = Game::Ptr<const int32_t>(en, Offsets::OFF_SPELLITEMENCHANT_TYPE);
auto amount = Game::Ptr<const int32_t>(en, Offsets::OFF_SPELLITEMENCHANT_AMOUNT);
auto arg = Game::Ptr<const int32_t>(en, Offsets::OFF_SPELLITEMENCHANT_ARG);
for (int i = 0; i < 3; ++i) { // SpellItemEnchantment has 3 effect slots
switch (type[i]) {
case 3: // equip spell — stat/resist value lives in the spell
@@ -341,8 +341,8 @@ void ApplyRandomSuffix(Accum *acc, int suffixID, long sign) {
static_cast<uint32_t>(suffixID));
if (rp == nullptr)
return;
auto enchants = reinterpret_cast<const uint32_t *>(
rp + Offsets::OFF_ITEMRANDOMPROP_ENCHANT);
auto enchants = Game::Ptr<const uint32_t>(
rp, Offsets::OFF_ITEMRANDOMPROP_ENCHANT);
for (int s = 0; s < Offsets::ITEMRANDOMPROP_ENCHANT_SLOT_COUNT; ++s)
ApplyEnchant(acc, enchants[s], sign);
}
@@ -350,10 +350,10 @@ void ApplyRandomSuffix(Accum *acc, int suffixID, long sign) {
void AccumulateRecord(Accum *acc, const uint8_t *record, long sign) {
if (record == nullptr)
return;
auto *types = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_STAT_TYPE);
auto *values = reinterpret_cast<const int32_t *>(
record + Offsets::OFF_ITEMSTATS_STAT_VALUE);
auto *types = Game::Ptr<const uint32_t>(
record, Offsets::OFF_ITEMSTATS_STAT_TYPE);
auto *values = Game::Ptr<const int32_t>(
record, Offsets::OFF_ITEMSTATS_STAT_VALUE);
for (int i = 0; i < Offsets::ITEMSTATS_STAT_SLOT_COUNT; ++i)
AddByKey(acc, StatKeyForItemModType(types[i]),
sign * static_cast<long>(values[i]));
+4 -4
View File
@@ -44,8 +44,8 @@ bool ReadGuid(const void *cgObject, uint32_t *lo, uint32_t *hi) {
auto *inst = Item::InstanceBlock(base);
if (inst == nullptr)
return false;
*lo = *reinterpret_cast<const uint32_t *>(inst + Offsets::OFF_INSTANCE_BLOCK_GUID);
*hi = *reinterpret_cast<const uint32_t *>(inst + Offsets::OFF_INSTANCE_BLOCK_GUID + 4);
*lo = Game::Read<uint32_t>(inst, Offsets::OFF_INSTANCE_BLOCK_GUID);
*hi = Game::Read<uint32_t>(inst, Offsets::OFF_INSTANCE_BLOCK_GUID + 4);
return true;
}
@@ -259,8 +259,8 @@ bool MoveCount(void *L, int srcBag, int srcSlot, int dstBag, int dstSlot, int co
// have to special-case "move everything".
auto *srcDescriptor = Item::ObjectFields(srcItem);
const int srcStack = srcDescriptor == nullptr ? 0 :
static_cast<int>(*reinterpret_cast<const uint32_t *>(
srcDescriptor + Offsets::OFF_DESCRIPTOR_STACK_COUNT));
static_cast<int>(Game::Read<uint32_t>(
srcDescriptor, Offsets::OFF_DESCRIPTOR_STACK_COUNT));
if (count > srcStack)
return false; // server would reject anyway; fail fast and locally
if (count == srcStack)
+6 -6
View File
@@ -241,16 +241,16 @@ static int __fastcall Script_GameTooltipGetItem(void *L) {
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
return 0;
}
const char *name = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_ITEMSTATS_NAME);
const char *name = Game::Read<const char *>(
record, Offsets::OFF_ITEMSTATS_NAME);
if (name == nullptr || *name == '\0')
return 0;
const uint32_t quality = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_QUALITY);
const uint32_t quality = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_QUALITY);
int suffix = 0;
if (*reinterpret_cast<const int *>(base + Offsets::OFF_TOOLTIP_COMPARE_FLAG) != 0)
suffix = *reinterpret_cast<const int *>(base + Offsets::OFF_TOOLTIP_COMPARE_SUFFIX);
if (Game::Read<int>(base, Offsets::OFF_TOOLTIP_COMPARE_FLAG) != 0)
suffix = Game::Read<int>(base, Offsets::OFF_TOOLTIP_COMPARE_SUFFIX);
char link[256];
std::snprintf(link, sizeof(link),
+6 -5
View File
@@ -13,6 +13,7 @@
#include "item/TooltipItem.h"
#include "Game.h"
#include "Offsets.h"
#include "item/ID.h"
#include "item/Location.h"
@@ -27,10 +28,10 @@ int CurrentID(const void *tooltipObj, uint64_t *outGuid) {
auto *c = static_cast<const uint8_t *>(tooltipObj);
const uint64_t itemGuid =
*reinterpret_cast<const uint64_t *>(c + Offsets::OFF_TOOLTIP_ITEM_GUID_LO);
Game::Read<uint64_t>(c, Offsets::OFF_TOOLTIP_ITEM_GUID_LO);
// Link item: the itemID field is authoritative (and reliably cleared).
const int linkItemID = *reinterpret_cast<const int *>(c + Offsets::OFF_TOOLTIP_ITEM_ID);
const int linkItemID = Game::Read<int>(c, Offsets::OFF_TOOLTIP_ITEM_ID);
if (linkItemID > 0) {
if (outGuid != nullptr)
*outGuid = itemGuid;
@@ -44,11 +45,11 @@ int CurrentID(const void *tooltipObj, uint64_t *outGuid) {
// it to the itemID (this also yields the dressed link for callers).
if (itemGuid == 0)
return 0;
if (*reinterpret_cast<const uint64_t *>(c + Offsets::OFF_TOOLTIP_UNIT_GUID_LO) != 0)
if (Game::Read<uint64_t>(c, Offsets::OFF_TOOLTIP_UNIT_GUID_LO) != 0)
return 0;
if (*reinterpret_cast<const uint64_t *>(c + Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO) != 0)
if (Game::Read<uint64_t>(c, Offsets::OFF_TOOLTIP_GAMEOBJECT_GUID_LO) != 0)
return 0;
if (*reinterpret_cast<const int *>(c + Offsets::OFF_TOOLTIP_SPELL_ID) > 0)
if (Game::Read<int>(c, Offsets::OFF_TOOLTIP_SPELL_ID) > 0)
return 0;
const uint8_t *cg = Item::Location::ResolveByGUID(itemGuid);
+4 -4
View File
@@ -31,7 +31,7 @@ static int __fastcall Script_GetInboxItemID(void *L) {
if (mailID < 0)
return 0;
const int count = static_cast<int>(*reinterpret_cast<const uint32_t *>(
const int count = static_cast<int>(Game::Read<uint32_t>(
Offsets::VAR_INBOX_COUNT));
if (mailID >= count)
return 0;
@@ -39,15 +39,15 @@ static int __fastcall Script_GetInboxItemID(void *L) {
// `VAR_INBOX_ENTRIES` is a pointer slot, not the array — the
// engine reads it via `MOV ECX, [imm32]; MOV EDI, [ECX + idx*4]`
// (two derefs total before the entry pointer is in hand).
auto **entries = *reinterpret_cast<const uint8_t ***>(Offsets::VAR_INBOX_ENTRIES);
auto **entries = Game::Read<const uint8_t **>(Offsets::VAR_INBOX_ENTRIES);
if (entries == nullptr)
return 0;
auto *entry = entries[mailID];
if (entry == nullptr)
return 0;
const int itemID = static_cast<int>(*reinterpret_cast<const uint32_t *>(
entry + Offsets::OFF_INBOX_ENTRY_ITEM_ID));
const int itemID = static_cast<int>(Game::Read<uint32_t>(
entry, Offsets::OFF_INBOX_ENTRY_ITEM_ID));
if (itemID == 0)
return 0;
+3 -3
View File
@@ -38,13 +38,13 @@ static int __fastcall Script_GetLootSlotItemID(void *L) {
}
int slot = static_cast<int>(Game::Lua::ToNumber(L, 1));
const uint32_t guidLo = *reinterpret_cast<const uint32_t *>(Offsets::VAR_LOOT_GUID_LO);
const uint32_t guidHi = *reinterpret_cast<const uint32_t *>(Offsets::VAR_LOOT_GUID_HI);
const uint32_t guidLo = Game::Read<uint32_t>(Offsets::VAR_LOOT_GUID_LO);
const uint32_t guidHi = Game::Read<uint32_t>(Offsets::VAR_LOOT_GUID_HI);
if ((guidLo | guidHi) == 0)
return 0;
slot -= 1;
if (*reinterpret_cast<const uint32_t *>(Offsets::VAR_LOOT_LOOTABLE) != 0) {
if (Game::Read<uint32_t>(Offsets::VAR_LOOT_LOOTABLE) != 0) {
if (slot <= 0)
return 0;
slot -= 1;
+5 -5
View File
@@ -30,20 +30,20 @@ static int __fastcall Script_GetMerchantItemID(void *L) {
if (index < 0)
return 0;
const uint32_t guidLo = *reinterpret_cast<const uint32_t *>(Offsets::VAR_MERCHANT_NPC_GUID_LO);
const uint32_t guidHi = *reinterpret_cast<const uint32_t *>(Offsets::VAR_MERCHANT_NPC_GUID_HI);
const uint32_t guidLo = Game::Read<uint32_t>(Offsets::VAR_MERCHANT_NPC_GUID_LO);
const uint32_t guidHi = Game::Read<uint32_t>(Offsets::VAR_MERCHANT_NPC_GUID_HI);
if ((guidLo | guidHi) == 0)
return 0;
const int count = static_cast<int>(*reinterpret_cast<const uint32_t *>(
const int count = static_cast<int>(Game::Read<uint32_t>(
Offsets::VAR_MERCHANT_COUNT));
if (index >= count)
return 0;
auto *entry = reinterpret_cast<const uint8_t *>(
Offsets::VAR_MERCHANT_ITEMS + index * Offsets::MERCHANT_STRIDE);
const int itemID = static_cast<int>(*reinterpret_cast<const uint32_t *>(
entry + Offsets::OFF_MERCHANT_ITEM_ID));
const int itemID = static_cast<int>(Game::Read<uint32_t>(
entry, Offsets::OFF_MERCHANT_ITEM_ID));
if (itemID == 0)
return 0;
+3 -3
View File
@@ -92,13 +92,13 @@ const uint8_t *LookupPlayerRecord(uint64_t guid) {
const char *NameFromRecord(const uint8_t *rec) {
return rec != nullptr
? reinterpret_cast<const char *>(rec + Offsets::OFF_PLAYER_INFO_NAME)
? Game::Ptr<const char>(rec, Offsets::OFF_PLAYER_INFO_NAME)
: nullptr;
}
uint32_t ClassIdFromRecord(const uint8_t *rec) {
return rec != nullptr
? *reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_PLAYER_INFO_CLASS)
? Game::Read<uint32_t>(rec, Offsets::OFF_PLAYER_INFO_CLASS)
: 0;
}
@@ -312,7 +312,7 @@ int RecordAllPassed(const void *msg) {
// the same field offsets as the message. This is the only place the random
// fields are populated, so the result recorders leave them alone.
void RecordStart() {
const uint8_t *node = *reinterpret_cast<const uint8_t *const *>(
const uint8_t *node = Game::Read<const uint8_t *>(
static_cast<uintptr_t>(Offsets::VAR_LOOTROLL_STORE_HEAD));
if (node == nullptr)
return;
+5 -8
View File
@@ -76,10 +76,9 @@ constexpr int VTBL_GET_POSITION_OFFSET = 0x14;
// bit of *race* — yields false positives for any Human / Dwarf /
// Undead / Gnome player and false negatives for dead mobs.
bool IsLootable(const void *unit) {
auto *fields = *reinterpret_cast<const uint8_t *const *>(
static_cast<const uint8_t *>(unit) + Offsets::OFF_UNIT_DESCRIPTOR);
const uint32_t flags = *reinterpret_cast<const uint32_t *>(
fields + Offsets::OFF_UNIT_FIELD_DYNAMIC_FLAGS);
auto *fields = Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
const uint32_t flags =
Game::Read<uint32_t>(fields, Offsets::OFF_UNIT_FIELD_DYNAMIC_FLAGS);
return (flags & Offsets::UNIT_DYNFLAG_LOOTABLE) != 0;
}
@@ -87,10 +86,8 @@ bool IsLootable(const void *unit) {
// engine uses this as the contribution from both sides (player + target)
// in its interact-range computation.
float BoundingRadius(const void *unit) {
auto *fields = *reinterpret_cast<const uint8_t *const *>(
static_cast<const uint8_t *>(unit) + Offsets::OFF_UNIT_DESCRIPTOR);
return *reinterpret_cast<const float *>(
fields + Offsets::OFF_UNIT_FIELD_BOUNDING_RADIUS);
auto *fields = Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
return Game::Read<float>(fields, Offsets::OFF_UNIT_FIELD_BOUNDING_RADIUS);
}
// Invokes the unit's virtual `GetPosition` (vtable slot at offset
+7 -12
View File
@@ -143,18 +143,15 @@ constexpr float MIN_INTERACT_RANGE = 5.0f;
// === Range / lootability helpers (identical to Loot::Nearby) ===
bool IsLootableUnit(const void *unit) {
auto *fields = *reinterpret_cast<const uint8_t *const *>(
static_cast<const uint8_t *>(unit) + Offsets::OFF_UNIT_DESCRIPTOR);
const uint32_t flags = *reinterpret_cast<const uint32_t *>(
fields + Offsets::OFF_UNIT_FIELD_DYNAMIC_FLAGS);
auto *fields = Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
const uint32_t flags =
Game::Read<uint32_t>(fields, Offsets::OFF_UNIT_FIELD_DYNAMIC_FLAGS);
return (flags & Offsets::UNIT_DYNFLAG_LOOTABLE) != 0;
}
float BoundingRadius(const void *unit) {
auto *fields = *reinterpret_cast<const uint8_t *const *>(
static_cast<const uint8_t *>(unit) + Offsets::OFF_UNIT_DESCRIPTOR);
return *reinterpret_cast<const float *>(
fields + Offsets::OFF_UNIT_FIELD_BOUNDING_RADIUS);
auto *fields = Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
return Game::Read<float>(fields, Offsets::OFF_UNIT_FIELD_BOUNDING_RADIUS);
}
const C3Vector *GetPosition(const void *unit, C3Vector *outBuf) {
@@ -190,8 +187,7 @@ bool InInteractRange(const void *player, const void *target) {
// `FUN_LOOT_CONTROLLER` run, so the slot table is fully filled in
// and the link builder works against it.
void ScrapeCurrentLoot(LootEntry *out) {
const uint32_t coinRaw = *reinterpret_cast<const uint32_t *>(
Offsets::VAR_LOOT_LOOTABLE);
const uint32_t coinRaw = Game::Read<uint32_t>(Offsets::VAR_LOOT_LOOTABLE);
out->coin = (coinRaw == 0xFFFFFFFFu) ? 0u : coinRaw;
const bool hasCoin = coinRaw != 0;
@@ -239,8 +235,7 @@ void ScrapeCurrentLoot(LootEntry *out) {
void LootCurrentWindow() {
// Coin present when `VAR_LOOT_LOOTABLE` holds a real amount (0 = none;
// 0xFFFFFFFF = already-looted sentinel, never seen on a fresh open).
const uint32_t coinRaw = *reinterpret_cast<const uint32_t *>(
Offsets::VAR_LOOT_LOOTABLE);
const uint32_t coinRaw = Game::Read<uint32_t>(Offsets::VAR_LOOT_LOOTABLE);
if (coinRaw != 0 && coinRaw != 0xFFFFFFFFu) {
auto LootMoney = reinterpret_cast<LootMoney_t>(Offsets::FUN_CMSG_LOOT_MONEY);
LootMoney(s_scan.player);
+2 -2
View File
@@ -57,8 +57,8 @@ uint32_t s_desiredItemID = 0;
int s_ticksSinceTransition = 0;
uint64_t ReadLootTargetGuid() {
const uint32_t lo = *reinterpret_cast<const uint32_t *>(Offsets::VAR_LOOT_GUID_LO);
const uint32_t hi = *reinterpret_cast<const uint32_t *>(Offsets::VAR_LOOT_GUID_HI);
const uint32_t lo = Game::Read<uint32_t>(Offsets::VAR_LOOT_GUID_LO);
const uint32_t hi = Game::Read<uint32_t>(Offsets::VAR_LOOT_GUID_HI);
return static_cast<uint64_t>(hi) << 32 | lo;
}
+4 -4
View File
@@ -61,14 +61,14 @@ using Time::Clock::NowMs;
using Time::Clock::Reached;
const char *SpellName(const uint8_t *rec) {
const int locale = *reinterpret_cast<int *>(Offsets::VAR_LOCALE_INDEX);
const int locale = Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
const char *n =
*reinterpret_cast<const char *const *>(rec + Offsets::OFF_SPELL_NAMES + locale * 4);
Game::Read<const char *>(rec, Offsets::OFF_SPELL_NAMES + locale * 4);
return (n != nullptr) ? n : "";
}
const char *SpellIconPath(const uint8_t *rec) {
const int iconID = *reinterpret_cast<const int *>(rec + Offsets::OFF_SPELL_RECORD_ICON_ID);
const int iconID = Game::Read<int>(rec, Offsets::OFF_SPELL_RECORD_ICON_ID);
const uint8_t *iconRec = DBC::Record(Offsets::VAR_SPELL_ICON_RECORDS,
Offsets::VAR_SPELL_ICON_COUNT,
static_cast<uint32_t>(iconID));
@@ -79,7 +79,7 @@ const char *SpellIconPath(const uint8_t *rec) {
}
int SpellSchoolIndex(const uint8_t *rec) {
return *reinterpret_cast<const int *>(rec + Offsets::OFF_SPELL_SCHOOL);
return Game::Read<int>(rec, Offsets::OFF_SPELL_SCHOOL);
}
// The control-loss classifier lives in `Spell::CrowdControl::Classify` so the
+22 -30
View File
@@ -13,21 +13,20 @@
#include "map/Area.h"
#include "Game.h"
#include "Offsets.h"
#include "dbc/Lookup.h"
namespace Map::Area {
int RowForAreaID(uint32_t areaID) {
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_AREA_COUNT);
const int count = Game::Read<int>(Offsets::VAR_WORLDMAP_AREA_COUNT);
for (int id = 1; id <= count; ++id) {
const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS,
Offsets::VAR_WORLDMAP_AREA_COUNT,
static_cast<uint32_t>(id));
if (rec != nullptr &&
*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_WMA_AREA_ID) ==
areaID)
Game::Read<uint32_t>(rec, Offsets::OFF_WMA_AREA_ID) == areaID)
return id;
}
return -1;
@@ -35,17 +34,15 @@ int RowForAreaID(uint32_t areaID) {
int CurrentViewRow() {
const int continent =
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_CONTINENT_INDEX);
Game::Read<int>(Offsets::VAR_WORLDMAP_CONTINENT_INDEX);
if (continent < 0)
return *reinterpret_cast<const int *>(
Offsets::VAR_WORLDMAP_DEFAULT_AREA_ROW);
const uint8_t *blob = *reinterpret_cast<const uint8_t *const *>(
Offsets::VAR_WORLDMAP_CONTINENT_DATA);
return Game::Read<int>(Offsets::VAR_WORLDMAP_DEFAULT_AREA_ROW);
const uint8_t *blob =
Game::Read<const uint8_t *>(Offsets::VAR_WORLDMAP_CONTINENT_DATA);
if (blob == nullptr)
return -1;
const uint8_t *entry = blob + continent * Offsets::WORLDMAP_CONTINENT_STRIDE;
const int zone =
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_ZONE_INDEX);
const int zone = Game::Read<int>(Offsets::VAR_WORLDMAP_ZONE_INDEX);
if (zone < 0)
return *reinterpret_cast<const int *>(entry + 0x04);
const int *zoneRows = *reinterpret_cast<const int *const *>(entry + 0x10);
@@ -80,20 +77,19 @@ double OverlayMargin(int wmaRow, double mapXpct, double mapYpct) {
const double cx = mapXpct / 100.0 * kZoneCanvasW;
const double cy = mapYpct / 100.0 * kZoneCanvasH;
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_OVERLAY_COUNT);
Game::Read<int>(Offsets::VAR_WORLDMAP_OVERLAY_COUNT);
double best = -1.0;
for (int id = 1; id <= count; ++id) {
const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_OVERLAY_RECORDS,
Offsets::VAR_WORLDMAP_OVERLAY_COUNT,
static_cast<uint32_t>(id));
if (rec == nullptr ||
*reinterpret_cast<const int *>(rec + Offsets::OFF_WMO_WORLDMAP_AREA) !=
wmaRow)
Game::Read<int>(rec, Offsets::OFF_WMO_WORLDMAP_AREA) != wmaRow)
continue;
const int hl = *reinterpret_cast<const int *>(rec + Offsets::OFF_WMO_HITRECT_LEFT);
const int hr = *reinterpret_cast<const int *>(rec + Offsets::OFF_WMO_HITRECT_RIGHT);
const int ht = *reinterpret_cast<const int *>(rec + Offsets::OFF_WMO_HITRECT_TOP);
const int hb = *reinterpret_cast<const int *>(rec + Offsets::OFF_WMO_HITRECT_BOTTOM);
const int hl = Game::Read<int>(rec, Offsets::OFF_WMO_HITRECT_LEFT);
const int hr = Game::Read<int>(rec, Offsets::OFF_WMO_HITRECT_RIGHT);
const int ht = Game::Read<int>(rec, Offsets::OFF_WMO_HITRECT_TOP);
const int hb = Game::Read<int>(rec, Offsets::OFF_WMO_HITRECT_BOTTOM);
const double sw = hr - hl, sh = hb - ht;
if (sw <= 0.0 || sh <= 0.0)
continue; // no / degenerate hit rect
@@ -111,8 +107,7 @@ double OverlayMargin(int wmaRow, double mapXpct, double mapYpct) {
bool ZonePercent(int mapID, float x, float y, int *outAreaID, double *outMapX,
double *outMapY) {
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_AREA_COUNT);
const int count = Game::Read<int>(Offsets::VAR_WORLDMAP_AREA_COUNT);
// Two candidate tracks over the zones whose rect contains the point:
// land* — the point is on the zone's drawn landmass (an overlay hit rect
// encloses it): authoritative, wins whenever any zone qualifies.
@@ -132,10 +127,9 @@ bool ZonePercent(int mapID, float x, float y, int *outAreaID, double *outMapX,
static_cast<uint32_t>(id));
if (rec == nullptr)
continue;
if (*reinterpret_cast<const int *>(rec + Offsets::OFF_WMA_MAP_ID) != mapID)
if (Game::Read<int>(rec, Offsets::OFF_WMA_MAP_ID) != mapID)
continue;
const int areaID =
*reinterpret_cast<const int *>(rec + Offsets::OFF_WMA_AREA_ID);
const int areaID = Game::Read<int>(rec, Offsets::OFF_WMA_AREA_ID);
if (areaID == 0)
continue; // continent-spanning row, not a zone
@@ -191,15 +185,14 @@ bool ZonePercent(int mapID, float x, float y, int *outAreaID, double *outMapX,
}
bool PercentInZone(int areaID, float x, float y, double *outMapX, double *outMapY) {
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_AREA_COUNT);
const int count = Game::Read<int>(Offsets::VAR_WORLDMAP_AREA_COUNT);
for (int id = 1; id <= count; ++id) {
const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS,
Offsets::VAR_WORLDMAP_AREA_COUNT,
static_cast<uint32_t>(id));
if (rec == nullptr)
continue;
if (*reinterpret_cast<const int *>(rec + Offsets::OFF_WMA_AREA_ID) != areaID)
if (Game::Read<int>(rec, Offsets::OFF_WMA_AREA_ID) != areaID)
continue;
const double left = FloatField(rec, Offsets::OFF_WMA_LOC_LEFT);
const double right = FloatField(rec, Offsets::OFF_WMA_LOC_RIGHT);
@@ -219,17 +212,16 @@ bool PercentInZone(int areaID, float x, float y, double *outMapX, double *outMap
}
bool ContinentPercent(int mapID, float x, float y, double *outPx, double *outPy) {
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_AREA_COUNT);
const int count = Game::Read<int>(Offsets::VAR_WORLDMAP_AREA_COUNT);
for (int id = 1; id <= count; ++id) {
const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS,
Offsets::VAR_WORLDMAP_AREA_COUNT,
static_cast<uint32_t>(id));
if (rec == nullptr)
continue;
if (*reinterpret_cast<const int *>(rec + Offsets::OFF_WMA_MAP_ID) != mapID)
if (Game::Read<int>(rec, Offsets::OFF_WMA_MAP_ID) != mapID)
continue;
if (*reinterpret_cast<const int *>(rec + Offsets::OFF_WMA_AREA_ID) != 0)
if (Game::Read<int>(rec, Offsets::OFF_WMA_AREA_ID) != 0)
continue; // want the continent-spanning row
const double left = FloatField(rec, Offsets::OFF_WMA_LOC_LEFT);
+3 -4
View File
@@ -80,7 +80,7 @@ bool PushTriggerInfo(void *L, int id) {
if (rec == nullptr)
return false;
const int mapID = *reinterpret_cast<const int *>(rec + Offsets::OFF_AT_MAP_ID);
const int mapID = Game::Read<int>(rec, Offsets::OFF_AT_MAP_ID);
const float x = FloatField(rec, Offsets::OFF_AT_X);
const float y = FloatField(rec, Offsets::OFF_AT_Y);
const float z = FloatField(rec, Offsets::OFF_AT_Z);
@@ -134,8 +134,7 @@ int __fastcall Script_GetAreaTriggers(void *L) {
Game::Lua::SetTop(L, 0);
Game::Lua::NewTable(L);
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_AREATRIGGER_COUNT);
const int count = Game::Read<int>(Offsets::VAR_AREATRIGGER_COUNT);
int outIdx = 0;
for (int id = 1; id <= count; ++id) {
const uint8_t *rec = DBC::Record(Offsets::VAR_AREATRIGGER_RECORDS,
@@ -144,7 +143,7 @@ int __fastcall Script_GetAreaTriggers(void *L) {
if (rec == nullptr)
continue;
if (filter &&
*reinterpret_cast<const int *>(rec + Offsets::OFF_AT_MAP_ID) != wantMap)
Game::Read<int>(rec, Offsets::OFF_AT_MAP_ID) != wantMap)
continue;
outIdx += 1;
+4 -6
View File
@@ -67,8 +67,7 @@ int __fastcall Script_GetAreas(void *L) {
Game::Lua::SetTop(L, 0);
Game::Lua::NewTable(L);
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_AREATABLE_COUNT);
const int count = Game::Read<int>(Offsets::VAR_AREATABLE_COUNT);
for (int id = 1; id <= count; ++id) {
const char *name =
DBC::AreaName(static_cast<uint32_t>(id), /*resolveToParent=*/false);
@@ -98,18 +97,17 @@ int __fastcall Script_GetMapAreaIDs(void *L) {
Game::Lua::SetTop(L, 0);
Game::Lua::NewTable(L);
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_AREA_COUNT);
const int count = Game::Read<int>(Offsets::VAR_WORLDMAP_AREA_COUNT);
for (int id = 1; id <= count; ++id) {
const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_AREA_RECORDS,
Offsets::VAR_WORLDMAP_AREA_COUNT,
static_cast<uint32_t>(id));
if (rec == nullptr)
continue;
const int areaID = *reinterpret_cast<const int *>(rec + Offsets::OFF_WMA_AREA_ID);
const int areaID = Game::Read<int>(rec, Offsets::OFF_WMA_AREA_ID);
if (areaID == 0)
continue; // continent-spanning row, no zone id
const char *dir = *reinterpret_cast<const char *const *>(rec + Offsets::OFF_WMA_NAME);
const char *dir = Game::Read<const char *>(rec, Offsets::OFF_WMA_NAME);
if (dir == nullptr || dir[0] == '\0')
continue;
Game::Lua::SetFieldNumber(L, dir, static_cast<double>(areaID));
+12 -15
View File
@@ -274,7 +274,7 @@ void ResolveTiles(ResolvedOverlay *out, const char *basePath, int dbcW,
const ResolvedOverlay *CachedResolve(int overlayId, const char *basePath,
int dbcW, int dbcH) {
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_OVERLAY_COUNT);
Game::Read<int>(Offsets::VAR_WORLDMAP_OVERLAY_COUNT);
if (g_cache == nullptr || g_cacheSize < count + 1) {
auto **fresh = new ResolvedOverlay *[count + 1]();
for (int i = 0; i < g_cacheSize; ++i)
@@ -388,8 +388,7 @@ const uint8_t *ExplorationBits() {
auto *player = static_cast<const uint8_t *>(fn("player"));
if (player == nullptr)
return nullptr;
auto *sub = *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_CGPLAYER_INFO);
auto *sub = Game::Read<const uint8_t *>(player, Offsets::OFF_CGPLAYER_INFO);
if (sub == nullptr)
return nullptr;
return sub + Offsets::OFF_PLAYER_EXPLORED_BITS;
@@ -404,8 +403,8 @@ bool IsOverlayExplored(const uint8_t *overlayRec, const uint8_t *bits) {
if (bits == nullptr)
return false;
for (int k = 0; k < 4; ++k) {
const int areaID = *reinterpret_cast<const int *>(
overlayRec + Offsets::OFF_WMO_AREA_ID + k * 4);
const int areaID =
Game::Read<int>(overlayRec, Offsets::OFF_WMO_AREA_ID + k * 4);
if (areaID <= 0)
continue;
const uint8_t *areaRec =
@@ -413,10 +412,10 @@ bool IsOverlayExplored(const uint8_t *overlayRec, const uint8_t *bits) {
Offsets::VAR_AREATABLE_COUNT, static_cast<uint32_t>(areaID));
if (areaRec == nullptr)
continue;
if (*reinterpret_cast<const int *>(areaRec + Offsets::OFF_AREATABLE_EXPLORE_GATE) < 0)
if (Game::Read<int>(areaRec, Offsets::OFF_AREATABLE_EXPLORE_GATE) < 0)
return true; // area needs no exploration → always counts
const int areaBit = *reinterpret_cast<const int *>(
areaRec + Offsets::OFF_AREATABLE_AREA_BIT);
const int areaBit =
Game::Read<int>(areaRec, Offsets::OFF_AREATABLE_AREA_BIT);
if (areaBit < 0)
continue;
const int byteIdx = areaBit >> 3;
@@ -455,8 +454,7 @@ void PushZoneOverlays(void *L, int wmaRow, Filter filter) {
static_cast<uint32_t>(wmaRow));
const char *mapDir =
(wmaRec != nullptr)
? *reinterpret_cast<const char *const *>(wmaRec +
Offsets::OFF_WMA_NAME)
? Game::Read<const char *>(wmaRec, Offsets::OFF_WMA_NAME)
: nullptr;
// Exploration bitfield only needed for the filtered variants.
@@ -464,15 +462,14 @@ void PushZoneOverlays(void *L, int wmaRow, Filter filter) {
(filter == Filter::All) ? nullptr : ExplorationBits();
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_WORLDMAP_OVERLAY_COUNT);
Game::Read<int>(Offsets::VAR_WORLDMAP_OVERLAY_COUNT);
int outIdx = 0;
for (int id = 1; id <= count; ++id) {
const uint8_t *rec = DBC::Record(Offsets::VAR_WORLDMAP_OVERLAY_RECORDS,
Offsets::VAR_WORLDMAP_OVERLAY_COUNT,
static_cast<uint32_t>(id));
if (rec == nullptr ||
*reinterpret_cast<const int *>(rec + Offsets::OFF_WMO_WORLDMAP_AREA) !=
wmaRow)
Game::Read<int>(rec, Offsets::OFF_WMO_WORLDMAP_AREA) != wmaRow)
continue;
if (filter != Filter::All) {
@@ -483,8 +480,8 @@ void PushZoneOverlays(void *L, int wmaRow, Filter filter) {
continue;
}
const char *texName = *reinterpret_cast<const char *const *>(
rec + Offsets::OFF_WMO_TEXTURE_NAME);
const char *texName =
Game::Read<const char *>(rec, Offsets::OFF_WMO_TEXTURE_NAME);
const bool hasTexture = (texName != nullptr && texName[0] != '\0');
const auto fieldInt = [rec](uintptr_t off) {
+4 -4
View File
@@ -60,10 +60,10 @@ int __fastcall Script_GetMapWorldSize(void *L) {
if (rec == nullptr)
return 0;
const float left = *reinterpret_cast<const float *>(rec + Offsets::OFF_WMA_LOC_LEFT);
const float right = *reinterpret_cast<const float *>(rec + Offsets::OFF_WMA_LOC_RIGHT);
const float top = *reinterpret_cast<const float *>(rec + Offsets::OFF_WMA_LOC_TOP);
const float bottom = *reinterpret_cast<const float *>(rec + Offsets::OFF_WMA_LOC_BOTTOM);
const float left = Game::Read<float>(rec, Offsets::OFF_WMA_LOC_LEFT);
const float right = Game::Read<float>(rec, Offsets::OFF_WMA_LOC_RIGHT);
const float top = Game::Read<float>(rec, Offsets::OFF_WMA_LOC_TOP);
const float bottom = Game::Read<float>(rec, Offsets::OFF_WMA_LOC_BOTTOM);
Game::Lua::PushNumber(L, static_cast<double>(left) - right); // width (world Y span)
Game::Lua::PushNumber(L, static_cast<double>(top) - bottom); // height (world X span)
+21 -23
View File
@@ -69,11 +69,9 @@ Fn Vmethod(void *obj, int byteOffset) {
// Model method call; mirror that assignment (FUN_0076d950's prologue) so a
// type-check is valid even if no stock Model method has run yet.
int ModelTypeId() {
auto &typeId = *reinterpret_cast<int *>(
static_cast<uintptr_t>(Offsets::VAR_MODEL_LUA_TYPE_ID));
auto &typeId = Game::Ref<int>(Offsets::VAR_MODEL_LUA_TYPE_ID);
if (typeId == 0) {
auto &counter = *reinterpret_cast<int *>(
static_cast<uintptr_t>(Offsets::VAR_FRAMESCRIPT_TYPE_ID_COUNTER));
auto &counter = Game::Ref<int>(Offsets::VAR_FRAMESCRIPT_TYPE_ID_COUNTER);
counter += 1;
typeId = counter;
}
@@ -107,8 +105,8 @@ void ApplySkins(void *model, const char *modelPath, const uint8_t *displayRec) {
Offsets::FUN_MODEL_SET_REPLACEABLE_TEXTURE);
constexpr int kMonsterSlot[3] = {11, 12, 13};
for (int i = 0; i < 3; ++i) {
const char *variation = *reinterpret_cast<const char *const *>(
displayRec + Offsets::OFF_CREATUREDISPLAYINFO_TEXTURE_VARIATION + i * 4);
const char *variation = Game::Read<const char *>(
displayRec, Offsets::OFF_CREATUREDISPLAYINFO_TEXTURE_VARIATION + i * 4);
if (variation == nullptr || variation[0] == '\0')
continue;
const std::string skin = dir + variation;
@@ -229,14 +227,14 @@ DressJob *ClaimJob(void *frame) {
// engine's own early-out: an Extra record with no bake name gets no
// customization at all (FUN_005fb200 returns before creating the builder).
void ScheduleDress(void *frame, const uint8_t *extraRec) {
const char *bake = *reinterpret_cast<const char *const *>(
extraRec + Offsets::OFF_CREATUREDISPLAYINFOEXTRA_BAKE_NAME);
const char *bake = Game::Read<const char *>(
extraRec, Offsets::OFF_CREATUREDISPLAYINFOEXTRA_BAKE_NAME);
if (bake == nullptr || bake[0] == '\0')
return;
DressJob *job = ClaimJob(frame);
job->frame = frame;
job->instance = *reinterpret_cast<void **>(reinterpret_cast<uint8_t *>(frame) +
Offsets::OFF_SIMPLEMODELFFX_MODEL_INSTANCE);
job->instance = Game::Read<void *>(frame,
Offsets::OFF_SIMPLEMODELFFX_MODEL_INSTANCE);
job->extraRec = extraRec;
}
@@ -244,8 +242,8 @@ void ScheduleDress(void *frame, const uint8_t *extraRec) {
// equipment (the engine's order: SetInfo, then the 10 Extra equipment slots),
// then pump until done. Field-for-field mirror of FUN_005fb200's NPC branch.
void StepJob(DressJob &job) {
void *instance = *reinterpret_cast<void **>(reinterpret_cast<uint8_t *>(job.frame) +
Offsets::OFF_SIMPLEMODELFFX_MODEL_INSTANCE);
void *instance = Game::Read<void *>(job.frame,
Offsets::OFF_SIMPLEMODELFFX_MODEL_INSTANCE);
if (job.instance == nullptr)
job.instance = instance;
if (instance == nullptr || instance != job.instance || ++job.ticks > kMaxDressTicks) {
@@ -266,7 +264,7 @@ void StepJob(DressJob &job) {
const uint8_t *extra = job.extraRec;
auto field = [extra](int off) {
return *reinterpret_cast<const uint32_t *>(extra + off);
return Game::Read<uint32_t>(extra, off);
};
CharCompInfo info = {};
info.race = field(Offsets::OFF_CREATUREDISPLAYINFOEXTRA_RACE);
@@ -278,8 +276,8 @@ void StepJob(DressJob &job) {
info.hairStyle = field(Offsets::OFF_CREATUREDISPLAYINFOEXTRA_HAIR_STYLE);
info.model = instance;
info.useBake = 1;
const char *bake = *reinterpret_cast<const char *const *>(
extra + Offsets::OFF_CREATUREDISPLAYINFOEXTRA_BAKE_NAME);
const char *bake = Game::Read<const char *>(
extra, Offsets::OFF_CREATUREDISPLAYINFOEXTRA_BAKE_NAME);
std::snprintf(info.bakePath, sizeof(info.bakePath), "%s%s",
"Textures\\BakedNpcTextures\\", bake);
std::memcpy(info.geosetDefaults, kGeosetGroupDefaults, sizeof(kGeosetGroupDefaults));
@@ -308,10 +306,10 @@ void StepJob(DressJob &job) {
reinterpret_cast<SetRenderCb_t>(Offsets::FUN_MODEL_INSTANCE_SET_RENDER_CB);
const void *lightFogCb =
reinterpret_cast<const void *>(Offsets::FUN_SIMPLEMODELFFX_LIGHT_FOG_CB);
for (auto *child = *reinterpret_cast<uint8_t **>(
reinterpret_cast<uint8_t *>(instance) + Offsets::OFF_MODEL_INSTANCE_CHILD_HEAD);
child != nullptr; child = *reinterpret_cast<uint8_t **>(
child + Offsets::OFF_MODEL_INSTANCE_CHILD_NEXT))
for (auto *child = Game::Read<uint8_t *>(
instance, Offsets::OFF_MODEL_INSTANCE_CHILD_HEAD);
child != nullptr; child = Game::Read<uint8_t *>(
child, Offsets::OFF_MODEL_INSTANCE_CHILD_NEXT))
setRenderCb(child, lightFogCb, job.frame);
job.configured = true;
@@ -340,8 +338,8 @@ void LoadDisplay(void *model, int displayID) {
static_cast<uint32_t>(displayID));
if (displayRec == nullptr)
return;
const uint32_t modelID = *reinterpret_cast<const uint32_t *>(
displayRec + Offsets::OFF_CREATUREDISPLAYINFO_MODEL_ID);
const uint32_t modelID = Game::Read<uint32_t>(
displayRec, Offsets::OFF_CREATUREDISPLAYINFO_MODEL_ID);
const char *modelPath = DBC::StringField(Offsets::VAR_CREATUREMODELDATA_RECORDS,
Offsets::VAR_CREATUREMODELDATA_COUNT,
@@ -360,8 +358,8 @@ void LoadDisplay(void *model, int displayID) {
// Character-based display (Character\Race\Sex base): dress it through the
// engine compositor, else body and hair render white with every geoset on.
const uint32_t extID = *reinterpret_cast<const uint32_t *>(
displayRec + Offsets::OFF_CREATUREDISPLAYINFO_EXTENDED_ID);
const uint32_t extID = Game::Read<uint32_t>(
displayRec, Offsets::OFF_CREATUREDISPLAYINFO_EXTENDED_ID);
if (extID != 0) {
const uint8_t *extraRec = DBC::Record(Offsets::VAR_CREATUREDISPLAYINFOEXTRA_RECORDS,
Offsets::VAR_CREATUREDISPLAYINFOEXTRA_COUNT, extID);
+35 -39
View File
@@ -86,10 +86,10 @@ bool RestrictedOut(uint32_t mask, uint32_t index1Based) {
// item's class *has* a proficiency concept (mask != 0) and the item's
// subclass bit is unset.
bool ProficiencyMet(const uint8_t *record) {
const uint32_t itemClass = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_CLASS);
const uint32_t subClass = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_SUBCLASS);
const uint32_t itemClass = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_CLASS);
const uint32_t subClass = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_SUBCLASS);
if (itemClass > 16) // table is 17 entries (m_class 0..16)
return true;
auto *table = reinterpret_cast<const uint32_t *>(
@@ -105,27 +105,26 @@ bool ProficiencyMet(const uint8_t *record) {
// item's SkillLine.dbc row to the player's skill slot; the player must
// have the line at an effective rank (current + temp bonus) >= required.
bool RequiredSkillMet(const uint8_t *player, const uint8_t *record) {
const uint32_t reqSkill = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_REQUIRED_SKILL);
const uint32_t reqSkill = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_REQUIRED_SKILL);
if (reqSkill == 0)
return true; // no skill requirement
const uint32_t reqRank = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_REQUIRED_SKILL_RANK);
const uint32_t reqRank = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_REQUIRED_SKILL_RANK);
auto toSlot = reinterpret_cast<SkillLineToSlot_t>(Offsets::FUN_SKILL_LINE_TO_SLOT);
const int slot = toSlot(const_cast<uint8_t *>(player), reqSkill);
if (slot < 0)
return false; // player doesn't have the skill line at all
auto *sub = *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_CGPLAYER_INFO);
auto *sub = Game::Read<const uint8_t *>(player, Offsets::OFF_CGPLAYER_INFO);
if (sub == nullptr)
return false;
const uint8_t *rec = sub + Offsets::OFF_SKILL_INFO_TABLE +
slot * Offsets::SKILL_INFO_STRIDE;
uint32_t rank = *reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_CUR);
uint32_t rank = Game::Read<uint16_t>(rec, Offsets::OFF_SKILL_INFO_CUR);
if (rank != 0) // add the temp bonus only when there's a base value
rank += *reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_BONUS);
rank += Game::Read<uint16_t>(rec, Offsets::OFF_SKILL_INFO_BONUS);
return rank >= reqRank;
}
@@ -138,11 +137,11 @@ bool RequiredSkillMet(const uint8_t *player, const uint8_t *record) {
bool PlayerKnowsSpell(int spellID) {
if (spellID <= 0)
return false;
auto *bitmap = *reinterpret_cast<const uint32_t *const *>(
auto *bitmap = Game::Read<const uint32_t *>(
static_cast<uintptr_t>(Offsets::VAR_PLAYER_SPELL_BITMAP));
if (bitmap == nullptr)
return false;
const int spellCount = *reinterpret_cast<const int *>(
const int spellCount = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_SPELL_RECORD_COUNT));
if (spellID > spellCount)
return false;
@@ -163,8 +162,8 @@ bool PlayerKnowsSpell(int spellID) {
// specialization/proficiency in practice, so the chain walk is
// belt-and-suspenders, but it makes the check exact.
bool RequiredSpellMet(const uint8_t *player, const uint8_t *record) {
const int reqSpell = *reinterpret_cast<const int32_t *>(
record + Offsets::OFF_ITEMSTATS_REQUIRED_SPELL);
const int reqSpell = Game::Read<int32_t>(
record, Offsets::OFF_ITEMSTATS_REQUIRED_SPELL);
if (reqSpell <= 0)
return true; // no requirement
if (::Spell::Lookup::RecordForID(reqSpell) == nullptr)
@@ -180,8 +179,8 @@ bool RequiredSpellMet(const uint8_t *player, const uint8_t *record) {
// RequiredHonorRank — the player's PvP honor rank must be >= the item's.
// `sub` is the CGPlayer +0xE68 sub-struct (may be null pre-world).
bool RequiredHonorRankMet(const uint8_t *sub, const uint8_t *record) {
const uint32_t req = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_REQUIRED_HONOR_RANK);
const uint32_t req = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_REQUIRED_HONOR_RANK);
if (req == 0)
return true;
if (sub == nullptr)
@@ -193,14 +192,14 @@ bool RequiredHonorRankMet(const uint8_t *sub, const uint8_t *record) {
// RequiredCityRank — a PvP-medal bitmask gate: the item's rank R passes
// when the player has earned bit (R-1) in the medal mask.
bool RequiredCityRankMet(const uint8_t *sub, const uint8_t *record) {
const uint32_t req = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_REQUIRED_CITY_RANK);
const uint32_t req = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_REQUIRED_CITY_RANK);
if (req == 0)
return true;
if (sub == nullptr)
return false;
const uint32_t medals = *reinterpret_cast<const uint32_t *>(
sub + Offsets::OFF_CGPLAYER_PVP_MEDALS);
const uint32_t medals = Game::Read<uint32_t>(
sub, Offsets::OFF_CGPLAYER_PVP_MEDALS);
return (medals & (1u << ((req - 1) & 31))) != 0;
}
@@ -209,17 +208,17 @@ bool RequiredCityRankMet(const uint8_t *sub, const uint8_t *record) {
// indexes the engine's reaction-min threshold table; the player's total
// rep with the faction must be >= that threshold.
bool RequiredReputationMet(const uint8_t *record) {
const int faction = *reinterpret_cast<const int32_t *>(
record + Offsets::OFF_ITEMSTATS_REQUIRED_FACTION);
const int faction = Game::Read<int32_t>(
record, Offsets::OFF_ITEMSTATS_REQUIRED_FACTION);
if (faction == 0)
return true;
const uint32_t band = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_REQUIRED_FACTION_RANK);
const uint32_t band = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_REQUIRED_FACTION_RANK);
if (band > 7) // reaction-min table is 8 bands (0..7); guard OOB
return true;
auto getStanding = reinterpret_cast<RepStanding_t>(Offsets::FUN_REPUTATION_GET_STANDING);
const int current = getStanding(faction);
const int threshold = *reinterpret_cast<const int *>(
const int threshold = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_REACTION_MIN_TABLE) + band * 4);
return current >= threshold;
}
@@ -233,29 +232,27 @@ bool ComputeCanUse(int itemID) {
auto *player = Unit::Identity::PlayerObject();
if (player == nullptr)
return false; // pre-login / no player
auto *desc = *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_UNIT_DESCRIPTOR);
auto *desc = Game::Read<const uint8_t *>(player, Offsets::OFF_UNIT_DESCRIPTOR);
if (desc == nullptr)
return false;
if (!ProficiencyMet(record))
return false;
const int playerLevel = *reinterpret_cast<const int *>(
desc + Offsets::OFF_UNIT_FIELD_LEVEL);
const uint32_t reqLevel = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_REQUIRED_LEVEL);
const int playerLevel = Game::Read<int>(desc, Offsets::OFF_UNIT_FIELD_LEVEL);
const uint32_t reqLevel = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_REQUIRED_LEVEL);
if (static_cast<int>(reqLevel) > playerLevel)
return false;
const uint32_t allowClass = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_ALLOWABLE_CLASS);
const uint32_t allowClass = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_ALLOWABLE_CLASS);
const uint32_t playerClass = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE);
if (RestrictedOut(allowClass, playerClass))
return false;
const uint32_t allowRace = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_ITEMSTATS_ALLOWABLE_RACE);
const uint32_t allowRace = Game::Read<uint32_t>(
record, Offsets::OFF_ITEMSTATS_ALLOWABLE_RACE);
const uint32_t playerRace = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_RACE_BYTE);
if (RestrictedOut(allowRace, playerRace))
return false;
@@ -267,8 +264,7 @@ bool ComputeCanUse(int itemID) {
return false;
// PvP rank + reputation gates read the CGPlayer +0xE68 sub-struct.
auto *sub = *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_CGPLAYER_INFO);
auto *sub = Game::Read<const uint8_t *>(player, Offsets::OFF_CGPLAYER_INFO);
if (!RequiredHonorRankMet(sub, record))
return false;
if (!RequiredCityRankMet(sub, record))
+9 -10
View File
@@ -31,6 +31,7 @@
// the free-look bit is held AND the camera yaw changes; STOPPED
// fires on LMB release.
#include "Game.h"
#include "Offsets.h"
#include "event/Custom.h"
#include "tick/WorldTick.h"
@@ -67,7 +68,7 @@ bool g_havePrevCameraYaw = false;
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
const uint8_t *Controller() {
return *reinterpret_cast<const uint8_t *const *>(Offsets::VAR_UI_INPUT_CONTROLLER);
return Game::Read<const uint8_t *>(Offsets::VAR_UI_INPUT_CONTROLLER);
}
const uint8_t *Player() {
@@ -76,12 +77,12 @@ const uint8_t *Player() {
}
const uint8_t *Camera() {
const uint8_t *gameState = *reinterpret_cast<const uint8_t *const *>(
const uint8_t *gameState = Game::Read<const uint8_t *>(
Offsets::VAR_GAME_STATE_PTR);
if (gameState == nullptr)
return nullptr;
return *reinterpret_cast<const uint8_t *const *>(
gameState + Offsets::OFF_GAME_STATE_CAMERA_PTR);
return Game::Read<const uint8_t *>(
gameState, Offsets::OFF_GAME_STATE_CAMERA_PTR);
}
void FireTransition(bool now, bool &prev, const char *startedName,
@@ -109,8 +110,7 @@ void OnWorldTick() {
return;
}
const uint32_t flags = *reinterpret_cast<const uint32_t *>(
ctrl + Offsets::OFF_UI_INPUT_FLAGS);
const uint32_t flags = Game::Read<uint32_t>(ctrl, Offsets::OFF_UI_INPUT_FLAGS);
const bool freeLookHeld = (flags & Offsets::INPUT_FLAG_FREE_LOOK) != 0;
const bool mouselookHeld = (flags & Offsets::INPUT_FLAG_MOUSELOOK) != 0;
@@ -133,8 +133,7 @@ void OnWorldTick() {
// Once STARTED has fired during a hold, the latch stays on
// until the bit clears — so a drag-stop-drag motion within
// the same RMB hold doesn't flap STARTED/STOPPED.
const float bodyYaw = *reinterpret_cast<const float *>(
player + Offsets::OFF_PLAYER_BODY_YAW);
const float bodyYaw = Game::Read<float>(player, Offsets::OFF_PLAYER_BODY_YAW);
bool turning;
if (!mouselookHeld) {
turning = false;
@@ -159,8 +158,8 @@ void OnWorldTick() {
} else if (camera == nullptr) {
looking = false; // can't read camera yaw — bail
} else {
const float cameraYaw = *reinterpret_cast<const float *>(
camera + Offsets::OFF_CAMERA_RELATIVE_YAW);
const float cameraYaw = Game::Read<float>(
camera, Offsets::OFF_CAMERA_RELATIVE_YAW);
if (g_wasLooking) {
looking = true;
} else if (g_havePrevCameraYaw &&
+1 -1
View File
@@ -52,7 +52,7 @@ const char *LookupQuestType(uint32_t row) {
if (!record)
return nullptr;
const int localeIdx =
*reinterpret_cast<const int *>(Offsets::VAR_LOCALE_INDEX);
Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
if (localeIdx < 0 || localeIdx > 8)
return nullptr;
auto *names = reinterpret_cast<const char *const *>(record + 4);
+27 -27
View File
@@ -83,8 +83,8 @@ const uint8_t *PlayerFields() {
const uint8_t *player = Unit::Identity::PlayerObject();
if (player == nullptr)
return nullptr;
return *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_CGPLAYER_INFO);
return Game::Read<const uint8_t *>(
player, Offsets::OFF_CGPLAYER_INFO);
}
// Net spell damage for a 0-based school (0=physical .. 6=arcane). POS is the
@@ -94,10 +94,10 @@ long SpellDamageForSchool(int school0) {
const uint8_t *pf = PlayerFields();
if (pf == nullptr)
return 0;
const int32_t pos = *reinterpret_cast<const int32_t *>(
pf + Offsets::OFF_PLAYER_FIELD_MOD_DAMAGE_DONE_POS + school0 * 4);
const int32_t neg = *reinterpret_cast<const int32_t *>(
pf + Offsets::OFF_PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + school0 * 4);
const int32_t pos = Game::Read<int32_t>(
pf, Offsets::OFF_PLAYER_FIELD_MOD_DAMAGE_DONE_POS + school0 * 4);
const int32_t neg = Game::Read<int32_t>(
pf, Offsets::OFF_PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + school0 * 4);
return static_cast<long>(pos) - static_cast<long>(neg);
}
@@ -128,12 +128,12 @@ long ItemFlatHealing(const uint8_t *cgItem) {
// Random suffix ("… of Restoration") + applied permanent (slot 0) and
// temporary (slot 1) enchants (Healing Power, Mana Oil, …).
Item::StatAccum::ApplyRandomSuffix(
acc, *reinterpret_cast<const int32_t *>(
desc + Offsets::OFF_DESCRIPTOR_RANDOM_PROPERTY), +1);
acc, Game::Read<int32_t>(
desc, Offsets::OFF_DESCRIPTOR_RANDOM_PROPERTY), +1);
for (int slot = 0; slot <= 1; ++slot)
Item::StatAccum::ApplyEnchant(
acc, *reinterpret_cast<const uint32_t *>(
desc + Offsets::OFF_DESCRIPTOR_ENCHANTMENT_ID +
acc, Game::Read<uint32_t>(
desc, Offsets::OFF_DESCRIPTOR_ENCHANTMENT_ID +
slot * Offsets::DESCRIPTOR_ENCHANTMENT_SLOT_STRIDE), +1);
}
return Item::StatAccum::Value(acc, "ITEM_MOD_SPELL_HEALING_DONE_SHORT");
@@ -165,15 +165,15 @@ void AddSpellHealingAuras(long &total, int spellID, int32_t spirit,
if (sp == nullptr)
return;
if (requirePassive &&
!(*reinterpret_cast<const uint32_t *>(sp + Offsets::OFF_SPELL_RECORD_ATTRIBUTES) &
!(Game::Read<uint32_t>(sp, Offsets::OFF_SPELL_RECORD_ATTRIBUTES) &
Offsets::SPELL_ATTR_PASSIVE))
return;
auto aura = reinterpret_cast<const int32_t *>(
sp + Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME);
auto base = reinterpret_cast<const int32_t *>(
sp + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS);
auto dice = reinterpret_cast<const int32_t *>(
sp + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE);
auto aura = Game::Ptr<const int32_t>(
sp, Offsets::OFF_SPELL_RECORD_EFFECT_APPLY_AURA_NAME);
auto base = Game::Ptr<const int32_t>(
sp, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS);
auto dice = Game::Ptr<const int32_t>(
sp, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE);
for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) {
const long amount = static_cast<long>(base[i]) + static_cast<long>(dice[i]);
if (aura[i] == kAuraModHealingDone)
@@ -194,21 +194,21 @@ long ComputeHealing() {
// Player Spirit / Armor for the aura-175 / aura-199 conversions.
const uint8_t *desc = Unit::Identity::PlayerDescriptor();
const int32_t spirit = desc ? *reinterpret_cast<const int32_t *>(
desc + Offsets::OFF_UNIT_FIELD_STAT_SPIRIT) : 0;
const int32_t armor = desc ? *reinterpret_cast<const int32_t *>(
desc + Offsets::OFF_UNIT_FIELD_RESISTANCE_ARMOR) : 0;
const int32_t spirit = desc ? Game::Read<int32_t>(
desc, Offsets::OFF_UNIT_FIELD_STAT_SPIRIT) : 0;
const int32_t armor = desc ? Game::Read<int32_t>(
desc, Offsets::OFF_UNIT_FIELD_RESISTANCE_ARMOR) : 0;
// Active buffs — flat healing + Spirit/Armor conversions, one pass.
auto *table = reinterpret_cast<const uint8_t *>(
static_cast<uintptr_t>(Offsets::VAR_PLAYER_BUFF_TABLE));
for (int i = 0; i < Offsets::PLAYER_BUFF_TABLE_COUNT; ++i) {
const uint8_t *entry = table + i * Offsets::PLAYER_BUFF_ENTRY_STRIDE;
if (*reinterpret_cast<const int32_t *>(
entry + Offsets::OFF_PLAYER_BUFF_SLOT_CODE) < 0)
if (Game::Read<int32_t>(
entry, Offsets::OFF_PLAYER_BUFF_SLOT_CODE) < 0)
continue;
AddSpellHealingAuras(total, *reinterpret_cast<const int32_t *>(
entry + Offsets::OFF_PLAYER_BUFF_SPELL_ID),
AddSpellHealingAuras(total, Game::Read<int32_t>(
entry, Offsets::OFF_PLAYER_BUFF_SPELL_ID),
spirit, armor, /*requirePassive=*/false);
}
@@ -216,9 +216,9 @@ long ComputeHealing() {
// and any passive flat healing, via the known-spell bitmap (bounded by
// spellCount). The passive gate assumes ranks supersede (only the learned
// rank is known), so no per-rank dedup is needed.
auto *bitmap = *reinterpret_cast<const uint32_t *const *>(
auto *bitmap = Game::Read<const uint32_t *>(
static_cast<uintptr_t>(Offsets::VAR_PLAYER_SPELL_BITMAP));
const int spellCount = *reinterpret_cast<const int *>(
const int spellCount = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_SPELL_RECORD_COUNT));
if (bitmap != nullptr && spellCount > 0) {
for (int id = 1; id <= spellCount; ++id)
+22 -23
View File
@@ -170,8 +170,8 @@ bool MovementInterruptible(int spellID) {
const uint8_t *rec = Spell::Lookup::RecordForID(spellID);
if (rec == nullptr)
return true;
return (*reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_SPELL_RECORD_INTERRUPT_FLAGS) &
return (Game::Read<uint32_t>(
rec, Offsets::OFF_SPELL_RECORD_INTERRUPT_FLAGS) &
Offsets::SPELL_INTERRUPT_FLAG_MOVEMENT) != 0;
}
@@ -190,11 +190,11 @@ bool PlayerMoving() {
const uint8_t *player = Unit::Identity::PlayerObject();
if (player == nullptr)
return false;
const uint8_t *move = *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_UNIT_MOVEMENT_INFO_PTR);
const uint8_t *move = Game::Read<const uint8_t *>(
player, Offsets::OFF_UNIT_MOVEMENT_INFO_PTR);
if (move == nullptr)
return false;
return (*reinterpret_cast<const uint32_t *>(move + Offsets::OFF_MOVEMENT_FLAGS) &
return (Game::Read<uint32_t>(move, Offsets::OFF_MOVEMENT_FLAGS) &
Offsets::MOVEFLAG_MASK_CAST_DROP) != 0;
}
@@ -244,9 +244,9 @@ int CastTimeMs(int spellID) {
const uint8_t *rec = Spell::Lookup::RecordForID(spellID);
if (rec != nullptr) {
const uint32_t attr =
*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_SPELL_RECORD_ATTRIBUTES);
Game::Read<uint32_t>(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES);
const uint32_t attrEx2 =
*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX2);
Game::Read<uint32_t>(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX2);
if ((attr & SPELL_ATTR_RANGED) && !(attrEx2 & Offsets::SPELL_ATTR_EX2_AUTOREPEAT_FLAG))
ms += 500;
}
@@ -267,12 +267,12 @@ int ChannelDurationMs(int spellID) {
}
const char *SpellName(const uint8_t *rec) {
const int locale = *reinterpret_cast<int *>(Offsets::VAR_LOCALE_INDEX);
return *reinterpret_cast<const char *const *>(rec + Offsets::OFF_SPELL_NAMES + locale * 4);
const int locale = Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
return Game::Read<const char *>(rec, Offsets::OFF_SPELL_NAMES + locale * 4);
}
bool IsTradeskill(const uint8_t *rec) {
return (*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_SPELL_RECORD_ATTRIBUTES) &
return (Game::Read<uint32_t>(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES) &
SPELL_ATTR_TRADESPELL) != 0;
}
@@ -280,13 +280,13 @@ bool IsTradeskill(const uint8_t *rec) {
// already stores the full "Interface\Icons\..." path (unlike item icons,
// which are bare filenames) — so it's used verbatim, no prefix.
const char *SpellIconPath(const uint8_t *rec) {
const int iconID = *reinterpret_cast<const int *>(rec + Offsets::OFF_SPELL_RECORD_ICON_ID);
const int iconID = Game::Read<int>(rec, Offsets::OFF_SPELL_RECORD_ICON_ID);
const uint8_t *iconRec = DBC::Record(Offsets::VAR_SPELL_ICON_RECORDS,
Offsets::VAR_SPELL_ICON_COUNT,
static_cast<uint32_t>(iconID));
if (iconRec == nullptr)
return "";
const char *path = *reinterpret_cast<const char *const *>(iconRec + Offsets::OFF_SPELLICON_PATH);
const char *path = Game::Read<const char *>(iconRec, Offsets::OFF_SPELLICON_PATH);
return (path != nullptr) ? path : "";
}
@@ -400,7 +400,7 @@ const Game::HookAutoRegister _castStartHook{
// times to `UnitChannelInfo` (validated against the live +0x228 field).
bool IsChannelSpell(const uint8_t *rec) {
return (*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX) &
return (Game::Read<uint32_t>(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX) &
Offsets::SPELL_ATTR_EX_CHANNELED) != 0;
}
@@ -702,8 +702,7 @@ ClearCastingSpell_t g_origClearCastingSpell = nullptr;
void __fastcall ClearCastingSpell_h(void *unit, void *edx, int spellID,
char notify, char cleanup) {
if (unit != nullptr && spellID != 0) {
const int current = *reinterpret_cast<const int *>(
static_cast<const uint8_t *>(unit) + Offsets::OFF_UNIT_CAST_SPELL);
const int current = Game::Read<int>(unit, Offsets::OFF_UNIT_CAST_SPELL);
if (current != 0 && current == spellID)
HandleCastAborted(Unit::Identity::GuidForObject(unit), spellID);
}
@@ -753,7 +752,7 @@ void OnWorldTick() {
// so they're exempt — they expire on their computed endMs (self-expiry in
// PushCastInfo).
if (g_cast.spellID != 0 && !g_castFromServer &&
*reinterpret_cast<const int *>(Offsets::VAR_CURRENT_CAST_SPELL) == 0)
Game::Read<int>(Offsets::VAR_CURRENT_CAST_SPELL) == 0)
g_cast.spellID = 0;
// End a move-dropped cast (issue #23): the engine cleared its cast-state on
@@ -783,9 +782,9 @@ void OnWorldTick() {
// SENT castGUID); on cancel it simply stays cleared. Gated on
// !g_castFromServer so it can never touch that server re-stamp.
if (g_cast.spellID != 0 && !g_castFromServer &&
*reinterpret_cast<const int *>(Offsets::VAR_SPELL_TARGETING_FLAGS) != 0 &&
Game::Read<int>(Offsets::VAR_SPELL_TARGETING_FLAGS) != 0 &&
g_cast.spellID ==
*reinterpret_cast<const int *>(Offsets::VAR_PENDING_CAST_SPELL))
Game::Read<int>(Offsets::VAR_PENDING_CAST_SPELL))
g_cast.spellID = 0;
// Detect a player CHANNEL that ended before its computed endMs — the
@@ -806,8 +805,8 @@ void OnWorldTick() {
if (g_channel.spellID != 0) {
const uint8_t *desc = Unit::Identity::PlayerDescriptor();
if (desc != nullptr) {
const int chan = *reinterpret_cast<const int *>(
desc + Offsets::OFF_UNIT_FIELD_CHANNEL_SPELL);
const int chan = Game::Read<int>(
desc, Offsets::OFF_UNIT_FIELD_CHANNEL_SPELL);
if (chan == g_channel.spellID)
g_channelConfirmed = true;
else if (chan == 0 && g_channelConfirmed)
@@ -894,14 +893,14 @@ static int __fastcall Script_UnitChannelInfo(void *L) {
if (u == Resolve("player"))
return PushChannelInfo(L, g_channel.spellID, g_channel.startMs, g_channel.endMs, true);
auto *desc = *reinterpret_cast<const uint8_t *const *>(
static_cast<const uint8_t *>(u) + Offsets::OFF_UNIT_DESCRIPTOR);
auto *desc = Game::Read<const uint8_t *>(
u, Offsets::OFF_UNIT_DESCRIPTOR);
if (desc == nullptr)
return 0;
// The live +0x228 field is authoritative for "is this unit channeling
// right now"; the SMSG_SPELL_START cache adds real start/end times when
// we observed the channel begin (and still matches the current spell).
const int spellID = *reinterpret_cast<const int *>(desc + Offsets::OFF_UNIT_FIELD_CHANNEL_SPELL);
const int spellID = Game::Read<int>(desc, Offsets::OFF_UNIT_FIELD_CHANNEL_SPELL);
if (spellID == 0)
return 0;
const RemoteCast *rc = FindRemoteCast(Unit::Identity::GuidForObject(u));
+2 -2
View File
@@ -44,9 +44,9 @@ static const char *LocaleNameForID(int spellID) {
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
if (record == nullptr)
return nullptr;
const int locale = *reinterpret_cast<const int *>(
const int locale = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_LOCALE_INDEX));
return *reinterpret_cast<const char *const *>(record + Offsets::OFF_SPELL_NAMES + locale * 4);
return Game::Read<const char *>(record, Offsets::OFF_SPELL_NAMES + locale * 4);
}
// Hook on the single name → spellbook-slot resolver
+5 -5
View File
@@ -67,8 +67,8 @@ constexpr uint32_t kAutoShotSpellId = 75;
constexpr uint16_t kTargetFlagUnit = 0x0002;
const char *LocalizedField(const uint8_t *rec, int fieldOffset) {
const int locale = *reinterpret_cast<int *>(Offsets::VAR_LOCALE_INDEX);
return *reinterpret_cast<const char *const *>(rec + fieldOffset + locale * 4);
const int locale = Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
return Game::Read<const char *>(rec, fieldOffset + locale * 4);
}
// Cast UID for a REAL (Type-3) cast — player and remote alike. Per the retail
@@ -269,7 +269,7 @@ constexpr int kChanSuccDeferMs = 500;
bool IsChanneledSpell(int spellID) {
const uint8_t *rec = Spell::Lookup::RecordForID(spellID);
return rec != nullptr &&
(*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX) &
(Game::Read<uint32_t>(rec, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX) &
Offsets::SPELL_ATTR_EX_CHANNELED) != 0;
}
@@ -552,14 +552,14 @@ void OnPlayerSucceeded(int spellID) {
void PollReticle() {
const bool active =
*reinterpret_cast<const int *>(Offsets::VAR_SPELL_TARGETING_FLAGS) != 0;
Game::Read<int>(Offsets::VAR_SPELL_TARGETING_FLAGS) != 0;
if (active) {
if (s_reticleSpell == 0) {
// Reticle just came up — report the pending spell. Read the spellID
// now (it's set by Spell_C_CastSpell before targeting begins); if
// it's transiently 0 this frame, retry next tick.
const int spellID =
*reinterpret_cast<const int *>(Offsets::VAR_PENDING_CAST_SPELL);
Game::Read<int>(Offsets::VAR_PENDING_CAST_SPELL);
if (spellID != 0) {
s_reticleSpell = spellID;
s_reticlePlaced = false;
+3 -3
View File
@@ -66,7 +66,7 @@ const CastSpellByName_t Script_CastSpellByName_Engine =
reinterpret_cast<CastSpellByName_t>(Offsets::FUN_SCRIPT_CAST_SPELL_BY_NAME);
int ReadActiveSpellID() {
return *reinterpret_cast<const int *>(
return Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_ACTIVE_AUTO_REPEAT_SPELL));
}
@@ -74,9 +74,9 @@ const char *LocaleName(int spellID) {
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
if (record == nullptr)
return nullptr;
const int locale = *reinterpret_cast<const int *>(
const int locale = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_LOCALE_INDEX));
return *reinterpret_cast<const char *const *>(record + Offsets::OFF_SPELL_NAMES + locale * 4);
return Game::Read<const char *>(record, Offsets::OFF_SPELL_NAMES + locale * 4);
}
// Case-insensitive name match for the auto-repeat-name gate. Walks
+24 -24
View File
@@ -129,26 +129,26 @@ static bool ReadSpellInfo(int spellID, SpellInfoData &out) {
const int locale = ReadGlobal<int>(Offsets::VAR_LOCALE_INDEX);
out.spellID = spellID;
out.name = *reinterpret_cast<const char *const *>(record + Offsets::OFF_SPELL_NAMES + locale * 4);
out.rank = *reinterpret_cast<const char *const *>(record + Offsets::OFF_SPELL_RECORD_RANK + locale * 4);
out.name = Game::Read<const char *>(record, Offsets::OFF_SPELL_NAMES + locale * 4);
out.rank = Game::Read<const char *>(record, Offsets::OFF_SPELL_RECORD_RANK + locale * 4);
out.iconPath = nullptr;
const int iconID = *reinterpret_cast<const int *>(record + Offsets::OFF_SPELL_RECORD_ICON_ID);
const int iconID = Game::Read<int>(record, Offsets::OFF_SPELL_RECORD_ICON_ID);
if (auto *iconRec = LookupSubRecord(Offsets::VAR_SPELL_ICON_RECORDS,
Offsets::VAR_SPELL_ICON_COUNT, iconID)) {
out.iconPath = *reinterpret_cast<const char *const *>(iconRec + Offsets::OFF_SPELLICON_PATH);
out.iconPath = Game::Read<const char *>(iconRec, Offsets::OFF_SPELLICON_PATH);
}
out.cost = *reinterpret_cast<const int *>(record + Offsets::OFF_SPELL_RECORD_MANA_COST);
out.cost = Game::Read<int>(record, Offsets::OFF_SPELL_RECORD_MANA_COST);
const uint32_t attrEx2 = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX2);
const uint32_t attrEx2 = Game::Read<uint32_t>(
record, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX2);
out.isFunnel = (attrEx2 & SPELL_ATTR_EX2_HEALTH_FUNNEL) != 0;
out.powerType = *reinterpret_cast<const int *>(record + Offsets::OFF_SPELL_RECORD_POWER_TYPE);
out.powerType = Game::Read<int>(record, Offsets::OFF_SPELL_RECORD_POWER_TYPE);
out.castTimeMs = 0;
const int castIndex = *reinterpret_cast<const int *>(record + Offsets::OFF_SPELL_RECORD_CASTING_TIME_INDEX);
const int castIndex = Game::Read<int>(record, Offsets::OFF_SPELL_RECORD_CASTING_TIME_INDEX);
if (auto *castRec = LookupSubRecord(Offsets::VAR_SPELL_CAST_TIMES_RECORDS,
Offsets::VAR_SPELL_CAST_TIMES_COUNT, castIndex)) {
out.castTimeMs = *reinterpret_cast<const int *>(castRec + 4);
@@ -156,7 +156,7 @@ static bool ReadSpellInfo(int spellID, SpellInfoData &out) {
out.minRange = 0.0f;
out.maxRange = 0.0f;
const int rangeIndex = *reinterpret_cast<const int *>(record + Offsets::OFF_SPELL_RECORD_RANGE_INDEX);
const int rangeIndex = Game::Read<int>(record, Offsets::OFF_SPELL_RECORD_RANGE_INDEX);
if (auto *rangeRec = LookupSubRecord(Offsets::VAR_SPELL_RANGE_RECORDS,
Offsets::VAR_SPELL_RANGE_COUNT, rangeIndex)) {
out.minRange = *reinterpret_cast<const float *>(rangeRec + 4);
@@ -276,7 +276,7 @@ static int __fastcall Script_C_GetSpellName(void *L) {
return 0; // nil for unknown spellID
const int locale = ReadGlobal<int>(Offsets::VAR_LOCALE_INDEX);
const char *name = *reinterpret_cast<const char *const *>(record + Offsets::OFF_SPELL_NAMES + locale * 4);
const char *name = Game::Read<const char *>(record, Offsets::OFF_SPELL_NAMES + locale * 4);
if (name == nullptr || *name == '\0')
return 0; // empty / no name in current locale → nil
Game::Lua::PushString(L, name);
@@ -289,12 +289,12 @@ static int __fastcall Script_C_GetSpellTexture(void *L) {
if (record == nullptr)
return 0;
const int iconID = *reinterpret_cast<const int *>(record + Offsets::OFF_SPELL_RECORD_ICON_ID);
const int iconID = Game::Read<int>(record, Offsets::OFF_SPELL_RECORD_ICON_ID);
auto *iconRec = LookupSubRecord(Offsets::VAR_SPELL_ICON_RECORDS,
Offsets::VAR_SPELL_ICON_COUNT, iconID);
if (iconRec == nullptr)
return 0;
const char *path = *reinterpret_cast<const char *const *>(iconRec + Offsets::OFF_SPELLICON_PATH);
const char *path = Game::Read<const char *>(iconRec, Offsets::OFF_SPELLICON_PATH);
if (path == nullptr || *path == '\0')
return 0;
Game::Lua::PushString(L, path);
@@ -315,7 +315,7 @@ static bool BuildSpellLink(int spellID, char *out, size_t outLen) {
if (record == nullptr)
return false;
const int locale = ReadGlobal<int>(Offsets::VAR_LOCALE_INDEX);
const char *name = *reinterpret_cast<const char *const *>(record + Offsets::OFF_SPELL_NAMES + locale * 4);
const char *name = Game::Read<const char *>(record, Offsets::OFF_SPELL_NAMES + locale * 4);
if (name == nullptr || *name == '\0')
return false;
const int n = std::snprintf(out, outLen, "|cff71d5ff|Hspell:%d:0|h[%s]|h|r",
@@ -392,8 +392,8 @@ static int PushIsPassive(void *L, int spellID) {
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
if (record == nullptr)
return 0;
const uint32_t attr = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES);
const uint32_t attr = Game::Read<uint32_t>(
record, Offsets::OFF_SPELL_RECORD_ATTRIBUTES);
Game::Lua::PushBool(L, (attr & Offsets::SPELL_ATTR_PASSIVE) != 0);
return 1;
}
@@ -438,11 +438,11 @@ static int __fastcall Script_C_IsSpellPassive(void *L) {
static bool PlayerKnowsSpell(int spellID) {
if (spellID < 1)
return false;
const int spellCount = *reinterpret_cast<const int *>(
const int spellCount = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_SPELL_RECORD_COUNT));
if (spellID > spellCount)
return false;
auto *bitmap = *reinterpret_cast<const uint32_t *const *>(
auto *bitmap = Game::Read<const uint32_t *>(
static_cast<uintptr_t>(Offsets::VAR_PLAYER_SPELL_BITMAP));
if (bitmap == nullptr)
return false;
@@ -522,10 +522,10 @@ template <typename Pred>
static bool AnyEffectTarget(const uint8_t *record, Pred pred) {
if (record == nullptr)
return false;
auto *targetsA = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_A);
auto *targetsB = reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_B);
auto *targetsA = Game::Ptr<const uint32_t>(
record, Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_A);
auto *targetsB = Game::Ptr<const uint32_t>(
record, Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_B);
for (int i = 0; i < 3; ++i) {
if (pred(targetsA[i]) || pred(targetsB[i]))
return true;
@@ -661,8 +661,8 @@ static int __fastcall Script_C_SpellBook_GetSpellBookItemInfo(void *L) {
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
const uint32_t attr =
record ? *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES)
record ? Game::Read<uint32_t>(
record, Offsets::OFF_SPELL_RECORD_ATTRIBUTES)
: 0u;
Game::Lua::NewTable(L);
+34 -34
View File
@@ -33,8 +33,8 @@ const uint8_t *PlayerDescriptor() {
auto *player = static_cast<const uint8_t *>(fn("player"));
if (player == nullptr)
return nullptr;
return *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_UNIT_DESCRIPTOR);
return Game::Read<const uint8_t *>(
player, Offsets::OFF_UNIT_DESCRIPTOR);
}
// Builds (or returns the cached) set of every spellID that appears
@@ -51,9 +51,9 @@ std::unordered_set<int> &TalentSpellSet() {
static std::unordered_set<int> set;
if (!set.empty())
return set;
const uint8_t *const *records = *reinterpret_cast<const uint8_t *const *const *>(
const uint8_t *const *records = Game::Read<const uint8_t *const *>(
static_cast<uintptr_t>(Offsets::VAR_TALENT_DBC_RECORDS));
const int count = *reinterpret_cast<const int *>(
const int count = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_TALENT_DBC_COUNT));
if (records == nullptr || count <= 0)
return set;
@@ -63,8 +63,8 @@ std::unordered_set<int> &TalentSpellSet() {
const uint8_t *rec = records[i];
if (rec == nullptr)
continue;
auto *ranks = reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_TALENT_SPELL_RANK);
auto *ranks = Game::Ptr<const uint32_t>(
rec, Offsets::OFF_TALENT_SPELL_RANK);
for (int j = 0; j < 9; ++j) {
const uint32_t spellID = ranks[j];
if (spellID != 0)
@@ -80,8 +80,8 @@ int SpellBaseLevel(int spellID) {
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
if (record == nullptr)
return 0;
return *reinterpret_cast<const int32_t *>(
record + Offsets::OFF_SPELL_RECORD_BASE_LEVEL);
return Game::Read<int32_t>(
record, Offsets::OFF_SPELL_RECORD_BASE_LEVEL);
}
// Spell.dbc attribute filter for the learnable-spell walk. Only the
@@ -110,8 +110,8 @@ bool SpellHiddenFromSpellbook(int spellID) {
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
if (record == nullptr)
return false;
const uint32_t attributes = *reinterpret_cast<const uint32_t *>(
record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES);
const uint32_t attributes = Game::Read<uint32_t>(
record, Offsets::OFF_SPELL_RECORD_ATTRIBUTES);
return (attributes & SPELL_ATTR_HIDDEN_CLIENTSIDE) != 0;
}
@@ -134,7 +134,7 @@ constexpr uint32_t SPELL_EFFECT_APPLY_AURA = 6;
constexpr uint32_t SPELL_EFFECT_APPLY_AREA_AURA_PARTY = 35;
int LocaleIndex() {
return *reinterpret_cast<const int *>(
return Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_LOCALE_INDEX));
}
@@ -169,8 +169,8 @@ bool IsPositiveRankTarget(uint32_t t) {
// single-rank buffs (Power Infusion / Innervate / Blessing of Kings, all
// empty Rank and un-gated) vs ranked ones (Divine Spirit / Fortitude).
bool HasRankString(const uint8_t *record) {
const char *rank = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_SPELL_RECORD_RANK + LocaleIndex() * 4);
const char *rank = Game::Read<const char *>(
record, Offsets::OFF_SPELL_RECORD_RANK + LocaleIndex() * 4);
return rank != nullptr && *rank != '\0';
}
@@ -178,19 +178,19 @@ bool HasRankString(const uint8_t *record) {
// the spell isn't subject to the ranked-positive-aura target-level rule.
int RequiredTargetLevel(const uint8_t *record) {
const int spellLevel =
*reinterpret_cast<const int *>(record + Offsets::OFF_SPELL_RECORD_SPELL_LEVEL);
Game::Read<int>(record, Offsets::OFF_SPELL_RECORD_SPELL_LEVEL);
if (spellLevel <= 10) // targetLevel + 10 >= spellLevel holds for any level
return 0;
const uint32_t attr =
*reinterpret_cast<const uint32_t *>(record + Offsets::OFF_SPELL_RECORD_ATTRIBUTES);
Game::Read<uint32_t>(record, Offsets::OFF_SPELL_RECORD_ATTRIBUTES);
if (attr & Offsets::SPELL_ATTR_PASSIVE)
return 0;
if (!HasRankString(record)) // single-rank spell → not gated
return 0;
auto *effect = reinterpret_cast<const uint32_t *>(record + Offsets::OFF_SPELL_RECORD_EFFECT);
auto *effect = Game::Ptr<const uint32_t>(record, Offsets::OFF_SPELL_RECORD_EFFECT);
auto *targetA =
reinterpret_cast<const uint32_t *>(record + Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_A);
Game::Ptr<const uint32_t>(record, Offsets::OFF_SPELL_RECORD_EFFECT_IMPLICIT_TARGET_A);
bool positiveAura = false;
for (int i = 0; i < 3; ++i) {
if ((effect[i] == SPELL_EFFECT_APPLY_AURA &&
@@ -221,13 +221,13 @@ int __fastcall Script_GetSpellLevelInfo(void *L) {
return 0;
Game::Lua::PushNumber(
L, static_cast<double>(
*reinterpret_cast<const int *>(record + Offsets::OFF_SPELL_RECORD_SPELL_LEVEL)));
Game::Read<int>(record, Offsets::OFF_SPELL_RECORD_SPELL_LEVEL)));
Game::Lua::PushNumber(
L, static_cast<double>(
*reinterpret_cast<const int *>(record + Offsets::OFF_SPELL_RECORD_BASE_LEVEL)));
Game::Read<int>(record, Offsets::OFF_SPELL_RECORD_BASE_LEVEL)));
Game::Lua::PushNumber(
L, static_cast<double>(
*reinterpret_cast<const int *>(record + Offsets::OFF_SPELL_RECORD_MAX_LEVEL)));
Game::Read<int>(record, Offsets::OFF_SPELL_RECORD_MAX_LEVEL)));
return 3;
}
@@ -308,8 +308,8 @@ int __fastcall Script_GetCurrentLevelSpells(void *L) {
const uint8_t classByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE);
const uint8_t raceByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_RACE_BYTE);
const int32_t playerLevel = *reinterpret_cast<const int32_t *>(
desc + Offsets::OFF_UNIT_FIELD_LEVEL);
const int32_t playerLevel = Game::Read<int32_t>(
desc, Offsets::OFF_UNIT_FIELD_LEVEL);
if (classByte == 0 || raceByte == 0 || playerLevel <= 0)
return 1;
@@ -337,9 +337,9 @@ int __fastcall Script_GetCurrentLevelSpells(void *L) {
(1u << 0) | (1u << 1) | (1u << 2) | (1u << 3) | (1u << 4) |
(1u << 6) | (1u << 7) | (1u << 8) | (1u << 10);
const uint8_t *const *records = *reinterpret_cast<const uint8_t *const *const *>(
const uint8_t *const *records = Game::Read<const uint8_t *const *>(
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_RECORDS));
const int count = *reinterpret_cast<const int *>(
const int count = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_COUNT));
if (records == nullptr || count <= 0)
return 1;
@@ -357,14 +357,14 @@ int __fastcall Script_GetCurrentLevelSpells(void *L) {
if (rec == nullptr)
continue;
const uint32_t recClassMask = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_SLA_CLASS_MASK);
const uint32_t recRaceMask = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_SLA_RACE_MASK);
const uint32_t recExcludeClass = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_SLA_EXCLUDE_CLASS);
const uint32_t recExcludeRace = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_SLA_EXCLUDE_RACE);
const uint32_t recClassMask = Game::Read<uint32_t>(
rec, Offsets::OFF_SLA_CLASS_MASK);
const uint32_t recRaceMask = Game::Read<uint32_t>(
rec, Offsets::OFF_SLA_RACE_MASK);
const uint32_t recExcludeClass = Game::Read<uint32_t>(
rec, Offsets::OFF_SLA_EXCLUDE_CLASS);
const uint32_t recExcludeRace = Game::Read<uint32_t>(
rec, Offsets::OFF_SLA_EXCLUDE_RACE);
// Skip if explicitly excluded.
if ((recExcludeClass & playerClassBit) != 0)
@@ -406,8 +406,8 @@ int __fastcall Script_GetCurrentLevelSpells(void *L) {
if (!isClassSpell && !isRacial)
continue;
const int spellID = *reinterpret_cast<const int *>(
rec + Offsets::OFF_SLA_SPELL_ID);
const int spellID = Game::Read<int>(
rec, Offsets::OFF_SLA_SPELL_ID);
if (spellID <= 0)
continue;
if (SpellBaseLevel(spellID) != queryLevel)
+2 -2
View File
@@ -53,7 +53,7 @@ static const char *MechanicName(uint32_t mechanicID) {
Offsets::VAR_SPELLMECHANIC_COUNT, mechanicID);
if (rec == nullptr)
return nullptr;
auto names = reinterpret_cast<const char *const *>(rec + Offsets::OFF_SPELLMECHANIC_NAME);
auto names = Game::Ptr<const char *const>(rec, Offsets::OFF_SPELLMECHANIC_NAME);
const char *s = names[0]; // enUS
return (s != nullptr && s[0] != '\0') ? s : nullptr;
}
@@ -65,7 +65,7 @@ static int __fastcall Script_GetSpellMechanicByID(void *L) {
return 0; // nil for invalid / out-of-range spell IDs
const uint32_t mechanicID =
*reinterpret_cast<const uint32_t *>(record + Offsets::OFF_SPELL_RECORD_MECHANIC);
Game::Read<uint32_t>(record, Offsets::OFF_SPELL_RECORD_MECHANIC);
Game::Lua::PushNumber(L, static_cast<double>(mechanicID));
+8 -8
View File
@@ -32,7 +32,7 @@ uint32_t PlayerSpellFamily() {
auto *unit = static_cast<const uint8_t *>(resolve("player"));
if (unit == nullptr)
return 0;
auto *desc = *reinterpret_cast<const uint8_t *const *>(unit + Offsets::OFF_UNIT_DESCRIPTOR);
auto *desc = Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
if (desc == nullptr)
return 0;
const uint8_t classByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE);
@@ -40,7 +40,7 @@ uint32_t PlayerSpellFamily() {
Offsets::VAR_CHRCLASSES_COUNT, classByte);
if (cls == nullptr)
return 0;
return *reinterpret_cast<const uint32_t *>(cls + Offsets::OFF_CHRCLASSES_SPELL_FAMILY);
return Game::Read<uint32_t>(cls, Offsets::OFF_CHRCLASSES_SPELL_FAMILY);
}
} // namespace
@@ -49,18 +49,18 @@ float Apply(const uint8_t *spellRecord, int op, float base) {
if (spellRecord == nullptr)
return base;
const uint32_t familyName = *reinterpret_cast<const uint32_t *>(
spellRecord + Offsets::OFF_SPELL_RECORD_FAMILY_NAME);
const uint32_t attrEx3 = *reinterpret_cast<const uint32_t *>(
spellRecord + Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX3);
const uint32_t familyName = Game::Read<uint32_t>(
spellRecord, Offsets::OFF_SPELL_RECORD_FAMILY_NAME);
const uint32_t attrEx3 = Game::Read<uint32_t>(
spellRecord, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX3);
if (familyName == 0 ||
(attrEx3 & Offsets::SPELL_ATTR_EX3_IGNORE_CASTER_MODIFIERS) != 0)
return base;
if (familyName != PlayerSpellFamily())
return base;
const uint64_t familyFlags = *reinterpret_cast<const uint64_t *>(
spellRecord + Offsets::OFF_SPELL_RECORD_FAMILY_FLAGS);
const uint64_t familyFlags = Game::Read<uint64_t>(
spellRecord, Offsets::OFF_SPELL_RECORD_FAMILY_FLAGS);
if (familyFlags == 0)
return base;
+2 -2
View File
@@ -64,8 +64,8 @@ int __fastcall Script_GetSpellPowerCost(void *L) {
if (cost == 0xFFFFFFFF)
return 0; // engine error (no player context, etc.)
const int powerType = *reinterpret_cast<const int *>(rec + Offsets::OFF_SPELL_RECORD_POWER_TYPE);
const int costPercent = *reinterpret_cast<const int *>(rec + Offsets::OFF_SPELL_RECORD_MANA_COST_PERCENT);
const int powerType = Game::Read<int>(rec, Offsets::OFF_SPELL_RECORD_POWER_TYPE);
const int costPercent = Game::Read<int>(rec, Offsets::OFF_SPELL_RECORD_MANA_COST_PERCENT);
if (cost == 0 && costPercent == 0)
return 0; // nil — no resource cost
+3 -3
View File
@@ -61,14 +61,14 @@ namespace Spell::Radius {
static float MaxBaseRadius(const uint8_t *record) {
float best = -1.0f;
for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) {
const int radiusIndex = *reinterpret_cast<const int *>(
record + Offsets::OFF_SPELL_RECORD_EFFECT_RADIUS_INDEX + i * 4);
const int radiusIndex = Game::Read<int>(
record, Offsets::OFF_SPELL_RECORD_EFFECT_RADIUS_INDEX + i * 4);
const uint8_t *rad = DBC::Record(Offsets::VAR_SPELL_RADIUS_RECORDS,
Offsets::VAR_SPELL_RADIUS_COUNT,
static_cast<uint32_t>(radiusIndex));
if (rad == nullptr)
continue;
const float r = *reinterpret_cast<const float *>(rad + Offsets::OFF_SPELL_RADIUS_VALUE);
const float r = Game::Read<float>(rad, Offsets::OFF_SPELL_RADIUS_VALUE);
if (r > best)
best = r;
}
+2 -1
View File
@@ -13,6 +13,7 @@
#include "Range.h"
#include "Game.h"
#include "Offsets.h"
#include "dbc/Lookup.h"
#include "unit/Position.h"
@@ -41,7 +42,7 @@ bool SpellIDHasRange(int spellID) {
if (rec == nullptr)
return false;
const uint32_t rangeIdx =
*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_SPELL_RECORD_RANGE_INDEX);
Game::Read<uint32_t>(rec, Offsets::OFF_SPELL_RECORD_RANGE_INDEX);
if (rangeIdx == 0)
return false;
const uint8_t *rangeRec = DBC::Record(Offsets::VAR_SPELL_RANGE_RECORDS,
+21 -21
View File
@@ -35,8 +35,8 @@ void ReadPlayerClassRace(uint8_t *outClassByte, uint8_t *outRaceByte) {
auto *player = static_cast<const uint8_t *>(fn("player"));
if (player == nullptr)
return;
auto *desc = *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_UNIT_DESCRIPTOR);
auto *desc = Game::Read<const uint8_t *>(
player, Offsets::OFF_UNIT_DESCRIPTOR);
if (desc == nullptr)
return;
*outClassByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE);
@@ -56,9 +56,9 @@ uint32_t FindSkillIDForSpell(int spellID) {
if (spellID <= 0)
return 0;
auto *const *records = *reinterpret_cast<const uint8_t *const *const *>(
auto *const *records = Game::Read<const uint8_t *const *>(
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_RECORDS));
const int count = *reinterpret_cast<const int *>(
const int count = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_COUNT));
if (records == nullptr || count <= 0)
return 0;
@@ -75,13 +75,13 @@ uint32_t FindSkillIDForSpell(int spellID) {
const uint8_t *rec = records[i];
if (rec == nullptr)
continue;
const int rowSpell = *reinterpret_cast<const int *>(
rec + Offsets::OFF_SLA_SPELL_ID);
const int rowSpell = Game::Read<int>(
rec, Offsets::OFF_SLA_SPELL_ID);
if (rowSpell != spellID)
continue;
const uint32_t skill = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_SLA_SKILL_ID);
const uint32_t skill = Game::Read<uint32_t>(
rec, Offsets::OFF_SLA_SKILL_ID);
if (skill == 0)
continue;
if (fallback == 0)
@@ -92,14 +92,14 @@ uint32_t FindSkillIDForSpell(int spellID) {
if (playerClassBit == 0)
return skill;
const uint32_t classMask = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_SLA_CLASS_MASK);
const uint32_t raceMask = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_SLA_RACE_MASK);
const uint32_t excludeClass = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_SLA_EXCLUDE_CLASS);
const uint32_t excludeRace = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_SLA_EXCLUDE_RACE);
const uint32_t classMask = Game::Read<uint32_t>(
rec, Offsets::OFF_SLA_CLASS_MASK);
const uint32_t raceMask = Game::Read<uint32_t>(
rec, Offsets::OFF_SLA_RACE_MASK);
const uint32_t excludeClass = Game::Read<uint32_t>(
rec, Offsets::OFF_SLA_EXCLUDE_CLASS);
const uint32_t excludeRace = Game::Read<uint32_t>(
rec, Offsets::OFF_SLA_EXCLUDE_RACE);
if ((excludeClass & playerClassBit) != 0)
continue;
if ((excludeRace & playerRaceBit) != 0)
@@ -246,8 +246,8 @@ int __fastcall Script_GetSkillLineRank(void *L) {
return 1;
}
auto *sub = *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_CGPLAYER_INFO);
auto *sub = Game::Read<const uint8_t *>(
player, Offsets::OFF_CGPLAYER_INFO);
if (sub == nullptr) {
Game::Lua::PushNil(L);
return 1;
@@ -256,11 +256,11 @@ int __fastcall Script_GetSkillLineRank(void *L) {
const uint8_t *rec = sub + Offsets::OFF_SKILL_INFO_TABLE +
slot * Offsets::SKILL_INFO_STRIDE;
const uint32_t cur =
*reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_CUR);
Game::Read<uint16_t>(rec, Offsets::OFF_SKILL_INFO_CUR);
const uint32_t max =
*reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_MAX);
Game::Read<uint16_t>(rec, Offsets::OFF_SKILL_INFO_MAX);
const uint32_t modifier =
*reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_BONUS);
Game::Read<uint16_t>(rec, Offsets::OFF_SKILL_INFO_BONUS);
Game::Lua::PushNumber(L, static_cast<double>(cur));
Game::Lua::PushNumber(L, static_cast<double>(max));
+18 -18
View File
@@ -75,30 +75,30 @@ void AppendByID(void *L, int spellID) {
return;
auto *tt = static_cast<uint8_t *>(tooltipObj);
const int before = *reinterpret_cast<const int *>(
tt + Offsets::OFF_GAMETOOLTIP_NUM_LINES);
const int before = Game::Read<int>(
tt, Offsets::OFF_GAMETOOLTIP_NUM_LINES);
auto BuildSpellTooltip =
reinterpret_cast<BuildSpellTooltip_t>(Offsets::FUN_GAMETOOLTIP_BUILD_SPELL_TOOLTIP);
BuildSpellTooltip(tooltipObj, spellID, 0, 0, 0, 0, 0, /*param_7 (append)=*/1);
const int after = *reinterpret_cast<const int *>(
tt + Offsets::OFF_GAMETOOLTIP_NUM_LINES);
const int after = Game::Read<int>(
tt, Offsets::OFF_GAMETOOLTIP_NUM_LINES);
if (after <= before)
return; // nothing appended (bad spellID / missing Spell.dbc record)
const uint8_t *record = Spell::Lookup::RecordForID(spellID);
if (record == nullptr)
return;
const int locale = *reinterpret_cast<const int *>(Offsets::VAR_LOCALE_INDEX);
const char *name = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_SPELL_NAMES + locale * 4);
const int locale = Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
const char *name = Game::Read<const char *>(
record, Offsets::OFF_SPELL_NAMES + locale * 4);
if (name == nullptr || name[0] == '\0')
return;
// Left-text FontString array: descriptor at +0x324, data ptr at +0x8.
auto **textLeft = *reinterpret_cast<void ***>(
tt + Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 8);
auto **textLeft = Game::Read<void **>(
tt, Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 8);
if (textLeft == nullptr)
return;
void *fs = textLeft[before];
@@ -141,8 +141,8 @@ static int __fastcall Script_GameTooltipGetSpell(void *L) {
if (tooltipObj == nullptr)
return 0;
const int spellID = *reinterpret_cast<const int *>(
static_cast<const uint8_t *>(tooltipObj) + Offsets::OFF_TOOLTIP_SPELL_ID);
const int spellID = Game::Read<int>(
tooltipObj, Offsets::OFF_TOOLTIP_SPELL_ID);
if (spellID <= 0)
return 0;
@@ -150,11 +150,11 @@ static int __fastcall Script_GameTooltipGetSpell(void *L) {
if (record == nullptr)
return 0;
const int locale = *reinterpret_cast<const int *>(Offsets::VAR_LOCALE_INDEX);
const char *name = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_SPELL_NAMES + locale * 4);
const char *rank = *reinterpret_cast<const char *const *>(
record + Offsets::OFF_SPELL_RECORD_RANK + locale * 4);
const int locale = Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
const char *name = Game::Read<const char *>(
record, Offsets::OFF_SPELL_NAMES + locale * 4);
const char *rank = Game::Read<const char *>(
record, Offsets::OFF_SPELL_RECORD_RANK + locale * 4);
if (name == nullptr)
return 0;
@@ -181,8 +181,8 @@ static int __fastcall Script_GameTooltipHasSpell(void *L) {
Game::Lua::PushBool(L, 0);
return 1;
}
const int spellID = *reinterpret_cast<const int *>(
static_cast<const uint8_t *>(tooltipObj) + Offsets::OFF_TOOLTIP_SPELL_ID);
const int spellID = Game::Read<int>(
tooltipObj, Offsets::OFF_TOOLTIP_SPELL_ID);
Game::Lua::PushBool(L, spellID > 0);
return 1;
}
+17 -17
View File
@@ -40,11 +40,11 @@ using GetSpellCost_t = uint32_t(__fastcall *)(int spellID, int unit);
bool PlayerKnowsSpell(int spellID) {
if (spellID <= 0)
return false;
auto *bitmap = *reinterpret_cast<const uint32_t *const *>(
auto *bitmap = Game::Read<const uint32_t *>(
static_cast<uintptr_t>(Offsets::VAR_PLAYER_SPELL_BITMAP));
if (bitmap == nullptr)
return false;
const int spellCount = *reinterpret_cast<const int *>(
const int spellCount = Game::Read<int>(
static_cast<uintptr_t>(Offsets::VAR_SPELL_RECORD_COUNT));
if (spellID > spellCount)
return false;
@@ -56,8 +56,8 @@ const uint8_t *PlayerDescriptor() {
auto *player = static_cast<const uint8_t *>(resolve("player"));
if (player == nullptr)
return nullptr;
return *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_UNIT_DESCRIPTOR);
return Game::Read<const uint8_t *>(
player, Offsets::OFF_UNIT_DESCRIPTOR);
}
// Calls the engine's cooldown helper at `FUN_SPELL_QUERY_COOLDOWN`
@@ -101,8 +101,8 @@ int CountItemInBags(void *L, int targetItemID) {
auto *itemDesc = Item::ObjectFields(item);
if (itemDesc == nullptr)
continue;
total += static_cast<int>(*reinterpret_cast<const uint32_t *>(
itemDesc + Offsets::OFF_DESCRIPTOR_STACK_COUNT));
total += static_cast<int>(Game::Read<uint32_t>(
itemDesc, Offsets::OFF_DESCRIPTOR_STACK_COUNT));
}
}
return total;
@@ -113,10 +113,10 @@ int CountItemInBags(void *L, int targetItemID) {
// Spells with zero reagents trivially pass.
bool HasReagents(void *L, const uint8_t *record) {
for (int i = 0; i < Offsets::SPELL_MAX_REAGENTS; i++) {
const int reagentItemID = static_cast<int>(*reinterpret_cast<const int32_t *>(
record + Offsets::OFF_SPELL_REAGENT_ID + i * 4));
const int reagentCount = static_cast<int>(*reinterpret_cast<const int32_t *>(
record + Offsets::OFF_SPELL_REAGENT_COUNT + i * 4));
const int reagentItemID = static_cast<int>(Game::Read<int32_t>(
record, Offsets::OFF_SPELL_REAGENT_ID + i * 4));
const int reagentCount = static_cast<int>(Game::Read<int32_t>(
record, Offsets::OFF_SPELL_REAGENT_COUNT + i * 4));
if (reagentItemID <= 0 || reagentCount <= 0)
continue;
if (CountItemInBags(L, reagentItemID) < reagentCount)
@@ -162,8 +162,8 @@ Usability ComputeUsability(void *L, int spellID) {
if (desc == nullptr)
return r;
const int health = *reinterpret_cast<const int *>(
desc + Offsets::OFF_UNIT_FIELD_HEALTH);
const int health = Game::Read<int>(
desc, Offsets::OFF_UNIT_FIELD_HEALTH);
if (health <= 0)
return r;
@@ -176,16 +176,16 @@ Usability ComputeUsability(void *L, int spellID) {
// not just the base ManaCost. Falls back to base if the engine can't
// resolve a cost (shouldn't happen here: the player descriptor
// resolved above, so it has a player context).
const int powerType = static_cast<int>(*reinterpret_cast<const int8_t *>(
record + Offsets::OFF_SPELL_RECORD_POWER_TYPE));
const int powerType = static_cast<int>(Game::Read<int8_t>(
record, Offsets::OFF_SPELL_RECORD_POWER_TYPE));
if (powerType >= 0 && powerType <= 4) {
auto getCost = reinterpret_cast<GetSpellCost_t>(Offsets::FUN_GET_SPELL_COST);
uint32_t cost = getCost(spellID, 0 /* local player */);
if (cost == 0xFFFFFFFF)
cost = *reinterpret_cast<const uint32_t *>(record + Offsets::OFF_SPELL_RECORD_MANA_COST);
cost = Game::Read<uint32_t>(record, Offsets::OFF_SPELL_RECORD_MANA_COST);
if (cost > 0) {
const int currentPower = *reinterpret_cast<const int *>(
desc + Offsets::OFF_UNIT_FIELD_POWER1 + powerType * 4);
const int currentPower = Game::Read<int>(
desc, Offsets::OFF_UNIT_FIELD_POWER1 + powerType * 4);
if (currentPower < static_cast<int>(cost)) {
r.noMana = true;
return r;
+31 -33
View File
@@ -77,8 +77,8 @@ static int __fastcall Script_GetTalentSpellID(void *L) {
ResolveTalentRecordForClass(classID, tabIndex, talentIndex);
if (rec == nullptr)
return 0;
const uint32_t spellID = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_TALENT_SPELL_RANK + (rank - 1) * sizeof(uint32_t));
const uint32_t spellID = Game::Read<uint32_t>(
rec, Offsets::OFF_TALENT_SPELL_RANK + (rank - 1) * sizeof(uint32_t));
if (spellID == 0)
return 0; // rank slot not populated (rank > maxRank for this talent)
Game::Lua::PushNumber(L, static_cast<double>(spellID));
@@ -89,21 +89,20 @@ static int __fastcall Script_GetTalentSpellID(void *L) {
// engine's `Script_GetTalentInfo` on out-of-range input. The engine
// bails to its error path (lua_error) on bad tab, bad talent index,
// or NULL player; we want all of those to return nil instead.
const int tabCount = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_TALENT_TAB_COUNT));
const int tabCount = Game::Read<int>(Offsets::VAR_TALENT_TAB_COUNT);
if (tabIndex > tabCount)
return 0;
auto *tabs = *reinterpret_cast<const uint8_t *const *const *>(
static_cast<uintptr_t>(Offsets::VAR_TALENT_TAB_INFO_ARRAY));
auto *tabs = Game::Read<const uint8_t *const *>(
Offsets::VAR_TALENT_TAB_INFO_ARRAY);
if (tabs == nullptr)
return 0;
const uint8_t *tabInfo = tabs[tabIndex - 1];
if (tabInfo == nullptr)
return 0;
const int numTalents = *reinterpret_cast<const int *>(
tabInfo + Offsets::OFF_TABINFO_NUM_TALENTS);
const int numTalents = Game::Read<int>(
tabInfo, Offsets::OFF_TABINFO_NUM_TALENTS);
if (talentIndex > numTalents)
return 0;
@@ -131,14 +130,14 @@ static int __fastcall Script_GetTalentSpellID(void *L) {
rank = 1; // unallocated talent → fall back to rank-1 spellID
}
auto *talents = *reinterpret_cast<const uint8_t *const *>(
tabInfo + Offsets::OFF_TABINFO_TALENT_ARRAY);
auto *talents = Game::Read<const uint8_t *>(
tabInfo, Offsets::OFF_TABINFO_TALENT_ARRAY);
if (talents == nullptr)
return 0;
const uint8_t *entry = talents +
(talentIndex - 1) * Offsets::TALENT_ENTRY_STRIDE;
const uint32_t spellID = *reinterpret_cast<const uint32_t *>(
entry + Offsets::OFF_TALENT_SPELL_RANK + (rank - 1) * sizeof(uint32_t));
const uint32_t spellID = Game::Read<uint32_t>(
entry, Offsets::OFF_TALENT_SPELL_RANK + (rank - 1) * sizeof(uint32_t));
if (spellID == 0)
return 0; // rank slot not populated (rank > maxRank for this talent)
@@ -158,22 +157,22 @@ static int __fastcall Script_GetTalentSpellID(void *L) {
// never race-restricted — so we apply only the class half of `FUN_004f2e50`.
static uint32_t NthClassTalentTabID(int classID, int tabIndex) {
const uint32_t classBit = 1u << ((classID - 1) & 0x1F);
auto *base = *reinterpret_cast<const uint8_t *const *>(
static_cast<uintptr_t>(Offsets::VAR_TALENTTAB_DBC_FLAT_RECORDS));
const int count = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_TALENTTAB_DBC_FLAT_COUNT));
auto *base = Game::Read<const uint8_t *>(
Offsets::VAR_TALENTTAB_DBC_FLAT_RECORDS);
const int count = Game::Read<int>(
Offsets::VAR_TALENTTAB_DBC_FLAT_COUNT);
if (base == nullptr)
return 0;
int match = 0;
for (int i = 0; i < count; ++i) {
const uint8_t *rec = base + i * Offsets::TALENTTAB_ENTRY_STRIDE;
const uint32_t classMask = *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_TALENTTAB_CLASS_MASK);
const uint32_t classMask = Game::Read<uint32_t>(
rec, Offsets::OFF_TALENTTAB_CLASS_MASK);
if (classMask != 0 && (classMask & classBit) == 0)
continue;
if (++match == tabIndex)
return *reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_TALENTTAB_ID);
return Game::Read<uint32_t>(
rec, Offsets::OFF_TALENTTAB_ID);
}
return 0;
}
@@ -182,16 +181,16 @@ static uint32_t NthClassTalentTabID(int classID, int tabIndex) {
// `tabID`, in DBC row order — the same order the builder assigns within a tab.
// Returns null if there aren't that many.
static const uint8_t *NthTabTalentRecord(uint32_t tabID, int talentIndex) {
auto *base = *reinterpret_cast<const uint8_t *const *>(
static_cast<uintptr_t>(Offsets::VAR_TALENT_DBC_FLAT_RECORDS));
const int count = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_TALENT_DBC_FLAT_COUNT));
auto *base = Game::Read<const uint8_t *>(
Offsets::VAR_TALENT_DBC_FLAT_RECORDS);
const int count = Game::Read<int>(
Offsets::VAR_TALENT_DBC_FLAT_COUNT);
if (base == nullptr)
return nullptr;
int match = 0;
for (int i = 0; i < count; ++i) {
const uint8_t *rec = base + i * Offsets::TALENT_ENTRY_STRIDE;
if (*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_TALENT_DBC_TAB_ID) != tabID)
if (Game::Read<uint32_t>(rec, Offsets::OFF_TALENT_DBC_TAB_ID) != tabID)
continue;
if (++match == talentIndex)
return rec;
@@ -259,26 +258,25 @@ static int __fastcall Script_GetTalentIDByIndex(void *L) {
return 1;
}
const int tabCount = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_TALENT_TAB_COUNT));
const int tabCount = Game::Read<int>(Offsets::VAR_TALENT_TAB_COUNT);
if (tabIndex > tabCount)
return 0;
auto *tabs = *reinterpret_cast<const uint8_t *const *const *>(
static_cast<uintptr_t>(Offsets::VAR_TALENT_TAB_INFO_ARRAY));
auto *tabs = Game::Read<const uint8_t *const *>(
Offsets::VAR_TALENT_TAB_INFO_ARRAY);
if (tabs == nullptr)
return 0;
const uint8_t *tabInfo = tabs[tabIndex - 1];
if (tabInfo == nullptr)
return 0;
const int numTalents = *reinterpret_cast<const int *>(
tabInfo + Offsets::OFF_TABINFO_NUM_TALENTS);
const int numTalents = Game::Read<int>(
tabInfo, Offsets::OFF_TABINFO_NUM_TALENTS);
if (talentIndex > numTalents)
return 0;
auto *talents = *reinterpret_cast<const uint8_t *const *>(
tabInfo + Offsets::OFF_TABINFO_TALENT_ARRAY);
auto *talents = Game::Read<const uint8_t *>(
tabInfo, Offsets::OFF_TABINFO_TALENT_ARRAY);
if (talents == nullptr)
return 0;
+8 -9
View File
@@ -27,10 +27,9 @@ namespace Talent::Tooltip {
// classes' talents aren't findable here. Same access pattern as
// `Talent::Info::Script_GetTalentIDByIndex` (#42), inverted.
static bool FindTalentByID(uint32_t talentID, int *outTab, int *outIdx) {
const int tabCount = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_TALENT_TAB_COUNT));
auto *tabs = *reinterpret_cast<const uint8_t *const *const *>(
static_cast<uintptr_t>(Offsets::VAR_TALENT_TAB_INFO_ARRAY));
const int tabCount = Game::Read<int>(Offsets::VAR_TALENT_TAB_COUNT);
auto *tabs = Game::Read<const uint8_t *const *>(
Offsets::VAR_TALENT_TAB_INFO_ARRAY);
if (tabs == nullptr)
return false;
@@ -38,10 +37,10 @@ static bool FindTalentByID(uint32_t talentID, int *outTab, int *outIdx) {
const uint8_t *tabInfo = tabs[t - 1];
if (tabInfo == nullptr)
continue;
const int numTalents = *reinterpret_cast<const int *>(
tabInfo + Offsets::OFF_TABINFO_NUM_TALENTS);
auto *talents = *reinterpret_cast<const uint8_t *const *>(
tabInfo + Offsets::OFF_TABINFO_TALENT_ARRAY);
const int numTalents = Game::Read<int>(
tabInfo, Offsets::OFF_TABINFO_NUM_TALENTS);
auto *talents = Game::Read<const uint8_t *>(
tabInfo, Offsets::OFF_TABINFO_TALENT_ARRAY);
if (talents == nullptr)
continue;
@@ -70,7 +69,7 @@ static uint32_t LookupTalentRank1Spell(uint32_t talentID) {
talentID);
if (rec == nullptr)
return 0;
return *reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_TALENT_SPELL_RANK);
return Game::Read<uint32_t>(rec, Offsets::OFF_TALENT_SPELL_RANK);
}
// `GameTooltip:SetTalentByID(talentID)` — modern method that renders a
+14 -14
View File
@@ -117,7 +117,7 @@ int ResolveZoneByName(const char *zone) {
if (zone == nullptr || *zone == '\0')
return 0;
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_AREATABLE_COUNT);
Game::Read<int>(Offsets::VAR_AREATABLE_COUNT);
int prefixHit = 0;
for (int id = 1; id <= count; ++id) {
const char *nm =
@@ -154,7 +154,7 @@ void PushPosition(void *L, const char *key, double px, double py) {
// is ample). Returns false when the path table isn't loaded.
constexpr int kMaxTaxiNodeID = 2048;
bool BuildTaxiGraph(bool *endpoint, bool *dest, int size) {
const int count = *reinterpret_cast<const int *>(Offsets::VAR_TAXIPATH_COUNT);
const int count = Game::Read<int>(Offsets::VAR_TAXIPATH_COUNT);
if (count <= 0)
return false;
for (int i = 1; i <= count; ++i) {
@@ -193,7 +193,7 @@ int __fastcall Script_GetTaxiNodesForMap(void *L) {
BuildTaxiGraph(endpoint, dest, kMaxTaxiNodeID);
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_TAXINODES_COUNT);
Game::Read<int>(Offsets::VAR_TAXINODES_COUNT);
int outIdx = 0;
for (int id = 1; id <= count; ++id) {
const uint8_t *rec = DBC::Record(Offsets::VAR_TAXINODES_RECORDS,
@@ -316,7 +316,7 @@ int __fastcall Script_GetAllTaxiNodes(void *L) {
Game::Lua::NewTable(L);
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_TAXI_NODE_COUNT);
Game::Read<int>(Offsets::VAR_TAXI_NODE_COUNT);
if (count <= 0)
return 1; // no taxi map open
@@ -326,8 +326,8 @@ int __fastcall Script_GetAllTaxiNodes(void *L) {
for (int slot = 0; slot < count; ++slot) {
const uint8_t *slotRec = arrayBase + slot * Offsets::TAXI_NODE_STRIDE;
const uint8_t *dbcRec = *reinterpret_cast<const uint8_t *const *>(
slotRec + Offsets::OFF_TAXI_SLOT_RECORD);
const uint8_t *dbcRec = Game::Read<const uint8_t *>(
slotRec, Offsets::OFF_TAXI_SLOT_RECORD);
const float x = FloatField(slotRec, Offsets::OFF_TAXI_SLOT_X);
const float y = FloatField(slotRec, Offsets::OFF_TAXI_SLOT_Y);
@@ -378,7 +378,7 @@ int __fastcall Script_GetTaxiRoute(void *L) {
return 0;
const int slot1 = static_cast<int>(Game::Lua::ToNumber(L, 1));
const int count =
*reinterpret_cast<const int *>(Offsets::VAR_TAXI_NODE_COUNT);
Game::Read<int>(Offsets::VAR_TAXI_NODE_COUNT);
if (count <= 0 || slot1 < 1 || slot1 > count)
return 0;
@@ -387,10 +387,10 @@ int __fastcall Script_GetTaxiRoute(void *L) {
const uint8_t *slotRec =
arrayBase + (slot1 - 1) * Offsets::TAXI_NODE_STRIDE;
const uint8_t *curRec = *reinterpret_cast<const uint8_t *const *>(
const uint8_t *curRec = Game::Read<const uint8_t *>(
Offsets::VAR_TAXI_CURRENT_REC);
const uint8_t *dstRec = *reinterpret_cast<const uint8_t *const *>(
slotRec + Offsets::OFF_TAXI_SLOT_RECORD);
const uint8_t *dstRec = Game::Read<const uint8_t *>(
slotRec, Offsets::OFF_TAXI_SLOT_RECORD);
if (curRec == nullptr || dstRec == nullptr)
return 0;
const int currentID = IntField(curRec, 0);
@@ -405,10 +405,10 @@ int __fastcall Script_GetTaxiRoute(void *L) {
ids[n++] = currentID;
ids[n++] = destID;
} else if (*(slotRec + Offsets::OFF_TAXI_SLOT_MULTIHOP) != 0) {
const int *route = *reinterpret_cast<const int *const *>(
slotRec + Offsets::OFF_TAXI_SLOT_ROUTE);
const int rc = *reinterpret_cast<const int *>(
slotRec + Offsets::OFF_TAXI_SLOT_ROUTE_COUNT);
const int *route = Game::Read<const int *>(
slotRec, Offsets::OFF_TAXI_SLOT_ROUTE);
const int rc = Game::Read<int>(
slotRec, Offsets::OFF_TAXI_SLOT_ROUTE_COUNT);
if (route == nullptr || rc < 2)
return 0;
const int cap = rc < 64 ? rc : 64;
+2 -2
View File
@@ -49,7 +49,7 @@ int __fastcall Script_GetTaxiPaths(void *L) {
Game::Lua::SetTop(L, 0);
Game::Lua::NewTable(L);
const int count = *reinterpret_cast<const int *>(Offsets::VAR_TAXIPATH_COUNT);
const int count = Game::Read<int>(Offsets::VAR_TAXIPATH_COUNT);
int outIdx = 0;
for (int id = 1; id <= count; ++id) {
const uint8_t *rec = DBC::Record(Offsets::VAR_TAXIPATH_RECORDS,
@@ -86,7 +86,7 @@ int __fastcall Script_GetTaxiPathWaypoints(void *L) {
int mapID;
};
std::vector<Waypoint> pts;
const int count = *reinterpret_cast<const int *>(Offsets::VAR_TAXIPATHNODE_COUNT);
const int count = Game::Read<int>(Offsets::VAR_TAXIPATHNODE_COUNT);
for (int id = 1; id <= count; ++id) {
const uint8_t *rec = DBC::Record(Offsets::VAR_TAXIPATHNODE_RECORDS,
Offsets::VAR_TAXIPATHNODE_COUNT,
+44 -76
View File
@@ -247,12 +247,10 @@ void *OwningFontStringOf(void *node) {
auto ow = g_nodeOwner.find(node);
if (ow == g_nodeOwner.end() || !LooksReadable(ow->second))
return nullptr;
auto *of = reinterpret_cast<uint8_t *>(ow->second);
void *block = *reinterpret_cast<void **>(of + Offsets::OFF_FONTSTRING_TEXT_BLOCK);
void *block = Game::Read<void *>(ow->second, Offsets::OFF_FONTSTRING_TEXT_BLOCK);
if (!LooksReadable(block))
return nullptr;
void *cur = *reinterpret_cast<void **>(reinterpret_cast<uint8_t *>(block) +
Offsets::OFF_TEXTBLOCK_NODE);
void *cur = Game::Read<void *>(block, Offsets::OFF_TEXTBLOCK_NODE);
return (cur == node) ? ow->second : nullptr;
}
@@ -318,12 +316,10 @@ void __fastcall RebuildString_h(void *fs) {
g_rebuildOriginal(fs);
if (!LooksReadable(fs))
return;
void *block = *reinterpret_cast<void **>(reinterpret_cast<uint8_t *>(fs) +
Offsets::OFF_FONTSTRING_TEXT_BLOCK);
void *block = Game::Read<void *>(fs, Offsets::OFF_FONTSTRING_TEXT_BLOCK);
if (!LooksReadable(block))
return;
void *node = *reinterpret_cast<void **>(reinterpret_cast<uint8_t *>(block) +
Offsets::OFF_TEXTBLOCK_NODE);
void *node = Game::Read<void *>(block, Offsets::OFF_TEXTBLOCK_NODE);
if (LooksReadable(node))
g_nodeOwner[node] = fs;
}
@@ -343,12 +339,11 @@ static const Game::HookAutoRegister _rebuildHook{Offsets::FUN_FONTSTRING_REBUILD
// ±10% (a mid-layout stale-rect read must not poison it).
float DeriveK(const uint8_t *n, const uint8_t *f, float originX) {
if (LooksReadable(f)) {
const float left = *reinterpret_cast<const float *>(f + Offsets::OFF_REGION_RECT + 4);
const float right = *reinterpret_cast<const float *>(f + Offsets::OFF_REGION_RECT + 12);
const float insetX = *reinterpret_cast<const float *>(f + Offsets::OFF_FONTSTRING_INSET_X);
const float left = Game::Read<float>(f, Offsets::OFF_REGION_RECT + 4);
const float right = Game::Read<float>(f, Offsets::OFF_REGION_RECT + 12);
const float insetX = Game::Read<float>(f, Offsets::OFF_FONTSTRING_INSET_X);
if (left < right && std::fabs(insetX) < 1e-6f) {
const int justify =
*reinterpret_cast<const int *>(n + Offsets::OFF_TEXT_NODE_JUSTIFY);
const int justify = Game::Read<int>(n, Offsets::OFF_TEXT_NODE_JUSTIFY);
const float ref =
(justify == 1) ? (left + right) * 0.5f : ((justify == 2) ? right : left);
if (std::fabs(ref) > 0.02f && originX > 1.0f) {
@@ -383,13 +378,12 @@ bool PtrInBuffer(const uint8_t *t, const uint8_t *buf) {
// FUN_00772ae0 → … → FUN_005c6940 loops the tokenizer), so the measure tokenizer's
// `text` points directly into it.
const uint8_t *FocusedEditboxInput() {
const void *fe = *reinterpret_cast<const void *const *>(Offsets::VAR_FOCUSED_EDITBOX);
const void *fe = Game::Read<const void *>(Offsets::VAR_FOCUSED_EDITBOX);
if (!LooksReadable(fe))
return nullptr;
auto *f = reinterpret_cast<const uint8_t *>(fe);
const uint8_t sel = f[Offsets::OFF_EDITBOX_BUFFER_SELECT];
const uint8_t *inBuf = *reinterpret_cast<const uint8_t *const *>(
f + ((sel & 8u) ? Offsets::OFF_EDITBOX_BUFFER_MASKED : Offsets::OFF_EDITBOX_BUFFER));
const uint8_t sel = Game::Read<uint8_t>(fe, Offsets::OFF_EDITBOX_BUFFER_SELECT);
const uint8_t *inBuf = Game::Read<const uint8_t *>(
fe, (sel & 8u) ? Offsets::OFF_EDITBOX_BUFFER_MASKED : Offsets::OFF_EDITBOX_BUFFER);
return LooksReadable(inBuf) ? inBuf : nullptr;
}
@@ -474,9 +468,7 @@ bool InlineInterceptActive(const uint8_t *text, bool editable) {
// global misses (multi-line editors build once, un-focused). This mirrors 4.3.4's
// per-render texture-disable flag, adapted to 1.12's layout.
inline bool NodeEditable(const void *node) {
return (*reinterpret_cast<const uint32_t *>(reinterpret_cast<const uint8_t *>(node) +
Offsets::OFF_TEXT_NODE_FLAGS) &
0x40u) != 0;
return (Game::Read<uint32_t>(node, Offsets::OFF_TEXT_NODE_FLAGS) & 0x40u) != 0;
}
// Geometry constants, calibrated in-game during bring-up (via a since-removed
@@ -745,14 +737,11 @@ float __fastcall StringWidth_h(void *fs) {
const float base = g_stringWidthOriginal(fs);
if (!LooksReadable(fs))
return base;
const auto *f = reinterpret_cast<const uint8_t *>(fs);
// fs+0x120 bit 0x1000 → gxu editbox bit 0x40: an editbox measures the raw
// markup it renders, so its width must stay unadjusted (caret alignment).
const bool editable =
(*reinterpret_cast<const uint32_t *>(f + Offsets::OFF_FONTSTRING_MEASURE_FLAGS) &
0x1000u) != 0;
const uint8_t *text =
*reinterpret_cast<const uint8_t *const *>(f + Offsets::OFF_FONTSTRING_TEXT);
(Game::Read<uint32_t>(fs, Offsets::OFF_FONTSTRING_MEASURE_FLAGS) & 0x1000u) != 0;
const uint8_t *text = Game::Read<const uint8_t *>(fs, Offsets::OFF_FONTSTRING_TEXT);
if (!LooksReadable(text) || !InlineInterceptActive(text, editable))
return base;
int len = 0;
@@ -760,8 +749,8 @@ float __fastcall StringWidth_h(void *fs) {
++len;
if (!HasInlineTexture(text, len))
return base;
const float mul = *reinterpret_cast<const float *>(Offsets::VAR_UI_COORD_SCALE_MUL);
const float div = *reinterpret_cast<const float *>(Offsets::VAR_UI_COORD_SCALE_DIV);
const float mul = Game::Read<float>(Offsets::VAR_UI_COORD_SCALE_MUL);
const float div = Game::Read<float>(Offsets::VAR_UI_COORD_SCALE_DIV);
if (!(mul > 0.0f) || !(div > 0.0f))
return base;
const float anchorToPx = div * Offsets::UI_COORD_SCALE_UNIT / mul; // ≈1468 (the push K)
@@ -810,12 +799,9 @@ float __fastcall StringHeight_h(void *fs) {
const float base = g_stringHeightOriginal(fs);
if (!LooksReadable(fs))
return base;
const auto *f = reinterpret_cast<const uint8_t *>(fs);
const bool editable =
(*reinterpret_cast<const uint32_t *>(f + Offsets::OFF_FONTSTRING_MEASURE_FLAGS) &
0x1000u) != 0;
const uint8_t *text =
*reinterpret_cast<const uint8_t *const *>(f + Offsets::OFF_FONTSTRING_TEXT);
(Game::Read<uint32_t>(fs, Offsets::OFF_FONTSTRING_MEASURE_FLAGS) & 0x1000u) != 0;
const uint8_t *text = Game::Read<const uint8_t *>(fs, Offsets::OFF_FONTSTRING_TEXT);
if (!LooksReadable(text) || !InlineInterceptActive(text, editable))
return base;
int len = 0;
@@ -823,8 +809,8 @@ float __fastcall StringHeight_h(void *fs) {
++len;
if (!HasInlineTexture(text, len))
return base;
const float mul = *reinterpret_cast<const float *>(Offsets::VAR_UI_COORD_SCALE_MUL);
const float div = *reinterpret_cast<const float *>(Offsets::VAR_UI_COORD_SCALE_DIV);
const float mul = Game::Read<float>(Offsets::VAR_UI_COORD_SCALE_MUL);
const float div = Game::Read<float>(Offsets::VAR_UI_COORD_SCALE_DIV);
if (!(mul > 0.0f) || !(div > 0.0f))
return base;
const float anchorToPx = div * Offsets::UI_COORD_SCALE_UNIT / mul;
@@ -878,10 +864,8 @@ void __fastcall LinkRectAdd_h(void *node, void *edx, float yA, float xLeft, floa
if (HasInlineTexture(escStart, len)) {
// The line's font pixel height, the emitter's own recipe (ecx =
// (nodeFlags>>7)&1, stack = node fontSize).
const uint32_t nodeFlags = *reinterpret_cast<const uint32_t *>(
reinterpret_cast<const uint8_t *>(node) + Offsets::OFF_TEXT_NODE_FLAGS);
const float fontSize = *reinterpret_cast<const float *>(
reinterpret_cast<const uint8_t *>(node) + Offsets::OFF_TEXT_NODE_FONT_SIZE);
const uint32_t nodeFlags = Game::Read<uint32_t>(node, Offsets::OFF_TEXT_NODE_FLAGS);
const float fontSize = Game::Read<float>(node, Offsets::OFF_TEXT_NODE_FONT_SIZE);
const float fontH = reinterpret_cast<float(__fastcall *)(int, float)>(
Offsets::FUN_TEXT_FONT_HEIGHT)(static_cast<int>((nodeFlags >> 7) & 1u), fontSize);
const float overflow = MaxIconOverflowPx(escStart, len, fontH);
@@ -1168,8 +1152,7 @@ void __fastcall Emitter_h(void *node, void *edx, uint8_t *text, int len, uint32_
const bool firstLine =
(node == g_buildNode)
? (g_buildEmitSeq++ == 0)
: (text == *reinterpret_cast<uint8_t **>(reinterpret_cast<uint8_t *>(node) +
Offsets::OFF_TEXT_NODE_TEXT));
: (text == Game::Read<uint8_t *>(node, Offsets::OFF_TEXT_NODE_TEXT));
if (firstLine)
g_nodeIcons.erase(node);
@@ -1195,8 +1178,7 @@ void __fastcall Emitter_h(void *node, void *edx, uint8_t *text, int len, uint32_
// the batch-clear ONCE per build (a len-0 original call with bit 3 still set,
// only on the first wrapped line), then clearing bit 3 so our per-segment calls
// APPEND. Restore the flags before returning.
uint32_t *const flagsPtr = reinterpret_cast<uint32_t *>(reinterpret_cast<uint8_t *>(node) +
Offsets::OFF_TEXT_NODE_FLAGS);
uint32_t *const flagsPtr = Game::Ptr<uint32_t>(node, Offsets::OFF_TEXT_NODE_FLAGS);
const uint32_t savedFlags = *flagsPtr;
const bool batchClearMode = (savedFlags & 8u) != 0;
if (batchClearMode) {
@@ -1225,17 +1207,14 @@ void __fastcall Emitter_h(void *node, void *edx, uint8_t *text, int len, uint32_
// near the text top). Mirrors the emitter's own call: ecx = (nodeFlags>>7)&1,
// stack = the node's font size [node+0x1c].
const int fontFlag = static_cast<int>((savedFlags >> 7) & 1u);
const float fontSize =
*reinterpret_cast<float *>(reinterpret_cast<uint8_t *>(node) +
Offsets::OFF_TEXT_NODE_FONT_SIZE);
const float fontSize = Game::Read<float>(node, Offsets::OFF_TEXT_NODE_FONT_SIZE);
const float fontH = reinterpret_cast<float(__fastcall *)(int, float)>(
Offsets::FUN_TEXT_FONT_HEIGHT)(fontFlag, fontSize);
// Font face + native→pen advance scale, mirroring the emitter's own
// `local_10 = fontH / (float)nativeHeight`. Used by drawRun's terminal-
// advance correction (glyph-record advances are native-font units).
void *const fontFace = *reinterpret_cast<void **>(reinterpret_cast<uint8_t *>(node) +
Offsets::OFF_TEXT_NODE_FONT_FACE);
void *const fontFace = Game::Read<void *>(node, Offsets::OFF_TEXT_NODE_FONT_FACE);
using FontNativeHeight_t = int(__fastcall *)(void *font);
const int fontNativeH =
(fontFace != nullptr)
@@ -1260,8 +1239,7 @@ void __fastcall Emitter_h(void *node, void *edx, uint8_t *text, int len, uint32_
// (right) so the whole text+icons block is justified as a unit. Left-justify
// (chat, justify 0) needs no shift. node+0x54: 1 = centre, 2 = right (verified
// in the draw builder FUN_005cdc20's justify branch).
const int justify = *reinterpret_cast<const int *>(
reinterpret_cast<const uint8_t *>(node) + Offsets::OFF_TEXT_NODE_JUSTIFY);
const int justify = Game::Read<int>(node, Offsets::OFF_TEXT_NODE_JUSTIFY);
if (justify == 1 || justify == 2) {
// Shared helper so the pre-shift matches the real advances exactly
// (including the positive-offsetX term an earlier inline copy omitted).
@@ -1447,9 +1425,8 @@ Paint_t g_paintOriginal = nullptr;
void FlushLayout(void *layout) {
if (!LooksReadable(layout))
return;
auto *L = reinterpret_cast<uint8_t *>(layout);
const int linkOff = *reinterpret_cast<int *>(L + Offsets::OFF_TEXT_LAYOUT_NODE_LINK);
void *node = *reinterpret_cast<void **>(L + Offsets::OFF_TEXT_LAYOUT_NODE_HEAD);
const int linkOff = Game::Read<int>(layout, Offsets::OFF_TEXT_LAYOUT_NODE_LINK);
void *node = Game::Read<void *>(layout, Offsets::OFF_TEXT_LAYOUT_NODE_HEAD);
for (int guard = 0; node != nullptr && (reinterpret_cast<uintptr_t>(node) & 1) == 0 &&
guard < 4096;
@@ -1457,7 +1434,7 @@ void FlushLayout(void *layout) {
if (!LooksReadable(node))
break;
auto *n = reinterpret_cast<uint8_t *>(node);
void *const next = *reinterpret_cast<void **>(n + linkOff + 4);
void *const next = Game::Read<void *>(n, linkOff + 4);
// Resolve the owning fontstring up front: a node with NO icons must
// still clear its fontstring's regions — the fs may have just been
@@ -1470,12 +1447,9 @@ void FlushLayout(void *layout) {
{
auto ow = g_nodeOwner.find(node);
if (ow != g_nodeOwner.end() && LooksReadable(ow->second)) {
auto *of = reinterpret_cast<uint8_t *>(ow->second);
void *block =
*reinterpret_cast<void **>(of + Offsets::OFF_FONTSTRING_TEXT_BLOCK);
void *block = Game::Read<void *>(ow->second, Offsets::OFF_FONTSTRING_TEXT_BLOCK);
if (LooksReadable(block) &&
*reinterpret_cast<void **>(reinterpret_cast<uint8_t *>(block) +
Offsets::OFF_TEXTBLOCK_NODE) == node) {
Game::Read<void *>(block, Offsets::OFF_TEXTBLOCK_NODE) == node) {
fs = ow->second;
} else if (block == nullptr) {
// Stuck-blockless fs: RebuildString released the block (a
@@ -1484,8 +1458,7 @@ void FlushLayout(void *layout) {
// fs's rebuild-dirty bit so the engine rebuilds next update
// and the icon pipeline resumes. Byte write only — safe
// from the paint tail (consumed by the fs's own update).
uint8_t *flags = of + Offsets::OFF_FONTSTRING_DIRTY_FLAGS;
*flags |= 1u;
Game::Ref<uint8_t>(ow->second, Offsets::OFF_FONTSTRING_DIRTY_FLAGS) |= 1u;
}
}
}
@@ -1503,8 +1476,7 @@ void FlushLayout(void *layout) {
// check erases good records on every clean paint: the all-icons-gone
// regression.)
if (it != g_nodeIcons.end() && !it->second.empty() && fs != nullptr) {
const char *ftext = *reinterpret_cast<const char *const *>(
reinterpret_cast<uint8_t *>(fs) + Offsets::OFF_FONTSTRING_TEXT);
const char *ftext = Game::Read<const char *>(fs, Offsets::OFF_FONTSTRING_TEXT);
bool fsHasMarkup = false;
if (LooksReadable(ftext)) {
for (int k = 1; k < 2048 && ftext[k] != '\0'; ++k)
@@ -1550,26 +1522,23 @@ void FlushLayout(void *layout) {
// node alpha too). One-frame lag (flush runs post-paint), same as
// the icon fade mirror. Chat (bit-3 clear) is excluded: the engine
// re-bakes those on colour change itself.
if ((*reinterpret_cast<const uint32_t *>(n + Offsets::OFF_TEXT_NODE_FLAGS) &
8u) != 0) {
const uint8_t liveA = n[Offsets::OFF_TEXT_NODE_COLOR + 3];
if ((Game::Read<uint32_t>(n, Offsets::OFF_TEXT_NODE_FLAGS) & 8u) != 0) {
const uint8_t liveA = Game::Read<uint8_t>(n, Offsets::OFF_TEXT_NODE_COLOR + 3);
for (int page = 0; page < Offsets::TEXT_NODE_PAGE_COUNT; ++page) {
auto *buf = *reinterpret_cast<uint8_t *const *>(
n + Offsets::OFF_TEXT_NODE_PAGE_BUFFERS + page * 4);
auto *buf =
Game::Read<uint8_t *>(n, Offsets::OFF_TEXT_NODE_PAGE_BUFFERS + page * 4);
if (buf == nullptr)
continue;
const int count = *reinterpret_cast<const int *>(
buf + Offsets::OFF_TEXT_PAGE_COLOR_COUNT);
auto *colors =
*reinterpret_cast<uint8_t *const *>(buf + Offsets::OFF_TEXT_PAGE_COLORS);
const int count = Game::Read<int>(buf, Offsets::OFF_TEXT_PAGE_COLOR_COUNT);
auto *colors = Game::Read<uint8_t *>(buf, Offsets::OFF_TEXT_PAGE_COLORS);
if (colors == nullptr || count <= 0 || colors[3] == liveA)
continue;
for (int i = 0; i < count; ++i)
colors[i * 4 + 3] = liveA;
}
}
const float ox = *reinterpret_cast<float *>(n + Offsets::OFF_TEXT_NODE_ORIGIN_X);
const float oy = *reinterpret_cast<float *>(n + Offsets::OFF_TEXT_NODE_ORIGIN_Y);
const float ox = Game::Read<float>(n, Offsets::OFF_TEXT_NODE_ORIGIN_X);
const float oy = Game::Read<float>(n, Offsets::OFF_TEXT_NODE_ORIGIN_Y);
// The fs rect, read HERE in the same flush as the icon coords — a
// coherent snapshot. Placements are stored FS-RELATIVE: an
// apply-time rect read raced the chat relayout (SetText invalidates
@@ -1581,8 +1550,7 @@ void FlushLayout(void *layout) {
float fsLeft = 0.0f, fsBottom = 0.0f;
bool fsRectValid = false;
if (fs != nullptr) {
const float *rc = reinterpret_cast<const float *>(
reinterpret_cast<uint8_t *>(fs) + Offsets::OFF_REGION_RECT);
const float *rc = Game::Ptr<const float>(fs, Offsets::OFF_REGION_RECT);
fsBottom = (rc[0] < rc[2]) ? rc[0] : rc[2];
fsLeft = (rc[1] < rc[3]) ? rc[1] : rc[3];
fsRectValid = rc[1] != rc[3]; // unresolved rect reads 0-width
+6 -8
View File
@@ -22,6 +22,7 @@
#include "text/InlineTexturePool.h"
#include "Game.h"
#include "Offsets.h"
#include "text/PtrProbe.h"
#include "tick/FrameTick.h"
@@ -173,11 +174,9 @@ void Hide(void *tex) {
// derivation); mirroring the byte onto the line's icon regions makes inline
// icons fade with their text. Count 0 = never colored = opaque default.
uint8_t FsColorAlpha(const void *fs) {
auto *f = reinterpret_cast<const uint8_t *>(fs);
if (*reinterpret_cast<const uint32_t *>(f + Offsets::OFF_FONTSTRING_COLOR_COUNT) < 1u)
if (Game::Read<uint32_t>(fs, Offsets::OFF_FONTSTRING_COLOR_COUNT) < 1u)
return 0xFFu;
const uint8_t *colors =
*reinterpret_cast<const uint8_t *const *>(f + Offsets::OFF_FONTSTRING_COLOR_ARRAY);
const uint8_t *colors = Game::Read<const uint8_t *>(fs, Offsets::OFF_FONTSTRING_COLOR_ARRAY);
if (!LooksReadable(colors))
return 0xFFu;
return colors[3]; // slot 0's BGRA dword, alpha byte
@@ -216,7 +215,7 @@ void ApplyPlacement(IconRegion &r, void *fs, const Placement &p, uint8_t fsAlpha
// then froze them — the scroll-landing "randomly hidden icon" bug.
if (r.path != p.path) {
const uint32_t blend = *reinterpret_cast<uint32_t *>(Offsets::VAR_TEXTURE_BLEND_DEFAULT);
const uint32_t blend = Game::Read<uint32_t>(Offsets::VAR_TEXTURE_BLEND_DEFAULT);
reinterpret_cast<SetTexture_t>(Offsets::FUN_SIMPLETEXTURE_SET_TEXTURE)(r.tex, p.path.c_str(),
0, blend, 0);
r.path = p.path;
@@ -236,10 +235,9 @@ void ApplyPlacement(IconRegion &r, void *fs, const Placement &p, uint8_t fsAlpha
// the probe: a 50px SetPoint offset stored as 0.0319 internal resolved to a
// rect at 0.0290 = 0.0319 × s (s = 0.91). So divide the desired resolved
// delta by the region's own scale before storing.
float sReg = *reinterpret_cast<float *>(reinterpret_cast<uint8_t *>(r.tex) +
Offsets::OFF_LAYOUT_SCALE);
float sReg = Game::Read<float>(r.tex, Offsets::OFF_LAYOUT_SCALE);
if (!(sReg > 0.01f && sReg < 100.0f))
sReg = *reinterpret_cast<float *>(f + Offsets::OFF_LAYOUT_SCALE);
sReg = Game::Read<float>(f, Offsets::OFF_LAYOUT_SCALE);
const float inv = (sReg > 0.01f && sReg < 100.0f) ? 1.0f / sReg : 1.0f;
// Single deterministic placement; the resolver's true offset scale is
+12 -21
View File
@@ -94,8 +94,8 @@ using Crop_t = void(__fastcall *)(void *region, void *edx, float *rect);
// region's LOCAL pixels must be folded through its effective scale (+0x7C)
// before this factor applies; WriteCorners does that.
float PixelToInternal(float px) {
const float mul = *reinterpret_cast<const float *>(Offsets::VAR_UI_COORD_SCALE_MUL);
const float div = *reinterpret_cast<const float *>(Offsets::VAR_UI_COORD_SCALE_DIV);
const float mul = Game::Read<float>(Offsets::VAR_UI_COORD_SCALE_MUL);
const float div = Game::Read<float>(Offsets::VAR_UI_COORD_SCALE_DIV);
if (div == 0.0f)
return 0.0f;
return px * mul / (div * Offsets::UI_COORD_SCALE_UNIT);
@@ -139,14 +139,12 @@ void WriteCorners(void *region, float left, float right, float top, float bottom
const float cy = bottom + xf.cyN * (top - bottom);
const float c = std::cos(xf.angle);
const float s = std::sin(xf.angle);
float scale = *reinterpret_cast<const float *>(
reinterpret_cast<const char *>(region) + Offsets::OFF_REGION_EFFECTIVE_SCALE);
float scale = Game::Read<float>(region, Offsets::OFF_REGION_EFFECTIVE_SCALE);
if (!(scale > 0.0f))
scale = 1.0f;
const float xs[4] = {left, left, right, right};
const float ys[4] = {bottom, top, bottom, top};
float *base = reinterpret_cast<float *>(
reinterpret_cast<char *>(region) + Offsets::OFF_SIMPLETEXTURE_CORNERS);
float *base = Game::Ptr<float>(region, Offsets::OFF_SIMPLETEXTURE_CORNERS);
// Compute each corner's TARGET rect-space position first.
float tx[4], ty[4];
for (int i = 0; i < 4; ++i) {
@@ -204,8 +202,7 @@ bool ApplyFromRect(void *region, const Xf &xf) {
// BOTH states, so this immediate apply and the corner-store co-hook below
// (which re-derives edges from whatever rect the engine stored) can never
// disagree about the base rect.
if (*reinterpret_cast<const int *>(reinterpret_cast<char *>(region) +
Offsets::OFF_REGION_TEXCOORD_MODIFIES_RECT) != 0)
if (Game::Read<int>(region, Offsets::OFF_REGION_TEXCOORD_MODIFIES_RECT) != 0)
reinterpret_cast<Crop_t>(Offsets::FUN_REGION_TEXCOORD_CROP)(region, nullptr, rect);
// rect = {top, left, bottom, right}
WriteCorners(region, rect[1], rect[3], rect[0], rect[2], xf);
@@ -238,8 +235,7 @@ void __fastcall StoreCorners_h(void *region, void *edx, float *rect) {
auto it = g_xf.find(region);
if (it == g_xf.end() || !it->second.active())
return;
const float *base = reinterpret_cast<const float *>(
reinterpret_cast<char *>(region) + Offsets::OFF_SIMPLETEXTURE_CORNERS);
const float *base = Game::Ptr<const float>(region, Offsets::OFF_SIMPLETEXTURE_CORNERS);
const float left = base[0]; // corner0 BL.x
const float bottom = base[1]; // corner0 BL.y
const float top = base[4]; // corner1 TL.y
@@ -297,13 +293,11 @@ template <class Fn>
int ForEachVert(uint8_t *n, Fn fn) {
int visited = 0;
for (int page = 0; page < Offsets::TEXT_NODE_PAGE_COUNT; ++page) {
auto *buf = *reinterpret_cast<uint8_t *const *>(
n + Offsets::OFF_TEXT_NODE_PAGE_BUFFERS + page * 4);
auto *buf = Game::Read<uint8_t *>(n, Offsets::OFF_TEXT_NODE_PAGE_BUFFERS + page * 4);
if (buf == nullptr)
continue;
const int count =
*reinterpret_cast<const int *>(buf + Offsets::OFF_TEXT_PAGE_VERT_COUNT);
auto *verts = *reinterpret_cast<float *const *>(buf + Offsets::OFF_TEXT_PAGE_VERTS);
const int count = Game::Read<int>(buf, Offsets::OFF_TEXT_PAGE_VERT_COUNT);
auto *verts = Game::Read<float *>(buf, Offsets::OFF_TEXT_PAGE_VERTS);
if (verts == nullptr || count <= 0)
continue;
for (int i = 0; i < count; ++i) {
@@ -382,12 +376,10 @@ bool RestoreBaseline(uint8_t *n, const std::vector<float> &base) {
// The CSimpleFontString's current live text node (fs+0xF8 → block, block+8), or
// null when the text isn't laid out yet.
void *FontStringNode(void *fs) {
void *block = *reinterpret_cast<void **>(reinterpret_cast<uint8_t *>(fs) +
Offsets::OFF_FONTSTRING_TEXT_BLOCK);
void *block = Game::Read<void *>(fs, Offsets::OFF_FONTSTRING_TEXT_BLOCK);
if (block == nullptr)
return nullptr;
return *reinterpret_cast<void **>(reinterpret_cast<uint8_t *>(block) +
Offsets::OFF_TEXTBLOCK_NODE);
return Game::Read<void *>(block, Offsets::OFF_TEXTBLOCK_NODE);
}
// Applies the fontstring's stored rotation to `node`'s verts, starting from an
@@ -516,8 +508,7 @@ int __fastcall Script_GetCorners(void *L) {
Game::Lua::Error(L, "Usage: texture:GetCorners()");
return 0;
}
const float *base = reinterpret_cast<const float *>(
reinterpret_cast<char *>(tex) + Offsets::OFF_SIMPLETEXTURE_CORNERS);
const float *base = Game::Ptr<const float>(tex, Offsets::OFF_SIMPLETEXTURE_CORNERS);
for (int i = 0; i < 4; ++i) {
Game::Lua::PushNumber(L, base[i * 3 + 0]);
Game::Lua::PushNumber(L, base[i * 3 + 1]);
+5 -5
View File
@@ -49,14 +49,14 @@ int64_t ComputeCurrentEpoch() {
auto *base = reinterpret_cast<const uint8_t *>(
static_cast<uintptr_t>(Offsets::VAR_GAMETIME_STRUCT));
const int year = *reinterpret_cast<const int *>(base + Offsets::OFF_GAMETIME_YEAR);
const int year = Game::Read<int>(base, Offsets::OFF_GAMETIME_YEAR);
if (year <= 0)
return 0; // pre-login / not yet sync'd
const int month = *reinterpret_cast<const int *>(base + Offsets::OFF_GAMETIME_MONTH);
const int day = *reinterpret_cast<const int *>(base + Offsets::OFF_GAMETIME_DAY);
const int hour = *reinterpret_cast<const int *>(base + Offsets::OFF_GAMETIME_HOUR);
const int minute = *reinterpret_cast<const int *>(base + Offsets::OFF_GAMETIME_MINUTE);
const int month = Game::Read<int>(base, Offsets::OFF_GAMETIME_MONTH);
const int day = Game::Read<int>(base, Offsets::OFF_GAMETIME_DAY);
const int hour = Game::Read<int>(base, Offsets::OFF_GAMETIME_HOUR);
const int minute = Game::Read<int>(base, Offsets::OFF_GAMETIME_MINUTE);
const DWORD now = GetTickCount();
if (year != g_lastYear || month != g_lastMonth || day != g_lastDay ||
+17 -22
View File
@@ -374,8 +374,7 @@ void RenderDeltas(void *self, void *L, const Accum *acc, double dpsDelta) {
const char *FSText(const void *fs) {
if (fs == nullptr)
return nullptr;
return *reinterpret_cast<const char *const *>(
static_cast<const uint8_t *>(fs) + Offsets::OFF_FONTSTRING_TEXT);
return Game::Read<const char *>(fs, Offsets::OFF_FONTSTRING_TEXT);
}
// Whether a line's FontString is actually shown. The tooltip clear hides
@@ -384,8 +383,7 @@ const char *FSText(const void *fs) {
bool FSVisible(const void *fs) {
if (fs == nullptr)
return false;
return *reinterpret_cast<const int *>(
static_cast<const uint8_t *>(fs) + Offsets::OFF_FONTSTRING_VISIBLE) != 0;
return Game::Read<int>(fs, Offsets::OFF_FONTSTRING_VISIBLE) != 0;
}
// Reads a FontString's current color into `*out` (4-byte {b,g,r,a}).
@@ -394,8 +392,7 @@ bool FSVisible(const void *fs) {
bool FSColor(const void *fs, uint32_t *out) {
if (fs == nullptr)
return false;
auto *slot = *reinterpret_cast<const uint32_t *const *>(
static_cast<const uint8_t *>(fs) + Offsets::OFF_FONTSTRING_COLOR_PTR);
auto *slot = Game::Read<const uint32_t *>(fs, Offsets::OFF_FONTSTRING_COLOR_PTR);
if (slot == nullptr)
return false;
*out = *slot;
@@ -421,8 +418,7 @@ using ShowHideFS_t = void(__fastcall *)(void *fs);
void FSSetShown(void *fs, bool shown) {
if (fs == nullptr)
return;
*reinterpret_cast<int *>(static_cast<uint8_t *>(fs) +
Offsets::OFF_FONTSTRING_SHOWN_FLAG) = shown ? 1 : 0;
Game::Ref<int>(fs, Offsets::OFF_FONTSTRING_SHOWN_FLAG) = shown ? 1 : 0;
reinterpret_cast<ShowHideFS_t>(
shown ? Offsets::FUN_FONTSTRING_SHOW : Offsets::FUN_FONTSTRING_HIDE)(fs);
}
@@ -452,19 +448,19 @@ void CopyLineCell(void *dst, const void *src) {
void PrependCurrentlyEquipped(void *self, void *L) {
auto *t = static_cast<uint8_t *>(self);
int *numLines = reinterpret_cast<int *>(t + Offsets::OFF_GAMETOOLTIP_NUM_LINES);
int *numLines = Game::Ptr<int>(t, Offsets::OFF_GAMETOOLTIP_NUM_LINES);
const int allocated =
*reinterpret_cast<const int *>(t + Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC);
Game::Read<int>(t, Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC);
const int n = *numLines;
if (n <= 0 || n + 1 > allocated)
return; // nothing built, or pool full (LinePool keeps 60, so rare)
auto **leftArr = *reinterpret_cast<void ***>(
t + Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 8);
auto **rightArr = *reinterpret_cast<void ***>(
t + Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC + 8);
auto *wrapArr = *reinterpret_cast<int **>(
t + Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC + 8);
auto **leftArr = Game::Read<void **>(
t, Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 8);
auto **rightArr = Game::Read<void **>(
t, Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC + 8);
auto *wrapArr = Game::Read<int *>(
t, Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC + 8);
if (leftArr == nullptr || rightArr == nullptr || wrapArr == nullptr)
return;
@@ -495,16 +491,15 @@ int EquippedSuffix(const uint8_t *item) {
auto *desc = Item::ObjectFields(item);
if (desc == nullptr)
return 0;
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
desc + Offsets::OFF_DESCRIPTOR_RANDOM_PROPERTY));
return static_cast<int>(
Game::Read<uint32_t>(desc, Offsets::OFF_DESCRIPTOR_RANDOM_PROPERTY));
}
uint64_t EquippedGUID(const uint8_t *item) {
auto *instance = Item::InstanceBlock(item);
if (instance == nullptr)
return 0;
return *reinterpret_cast<const uint64_t *>(
instance + Offsets::OFF_INSTANCE_BLOCK_GUID);
return Game::Read<uint64_t>(instance, Offsets::OFF_INSTANCE_BLOCK_GUID);
}
int __fastcall Script_SetHyperlinkCompareItem(void *L) {
@@ -545,8 +540,8 @@ int __fastcall Script_SetHyperlinkCompareItem(void *L) {
if (hoveredRec == nullptr)
return bail(0); // no link and no comparisonTooltip item, or not cached yet
const int invType = static_cast<int>(*reinterpret_cast<const uint32_t *>(
hoveredRec + Offsets::OFF_ITEMSTATS_INVENTORY_TYPE));
const int invType = static_cast<int>(
Game::Read<uint32_t>(hoveredRec, Offsets::OFF_ITEMSTATS_INVENTORY_TYPE));
int slots[2] = {0, 0};
const int nSlots = SlotsForInvType(invType, slots);
if (nSlots == 0)
+11 -12
View File
@@ -76,8 +76,8 @@ uint8_t *DescData(uint8_t *tooltip, int descOffset) {
// otherwise a -2px gap lands ~1000px off. Returns 0 if the scale globals
// aren't populated yet (degrades to a 0-offset anchor, not a wild one).
float PixelToInternal(float pixels) {
const float mul = *reinterpret_cast<const float *>(Offsets::VAR_UI_COORD_SCALE_MUL);
const float divBase = *reinterpret_cast<const float *>(Offsets::VAR_UI_COORD_SCALE_DIV);
const float mul = Game::Read<float>(Offsets::VAR_UI_COORD_SCALE_MUL);
const float divBase = Game::Read<float>(Offsets::VAR_UI_COORD_SCALE_DIV);
const float denom = divBase * static_cast<float>(Offsets::UI_COORD_SCALE_UNIT);
if (denom == 0.0f)
return 0.0f;
@@ -89,8 +89,7 @@ float PixelToInternal(float pixels) {
void *FontObjectOf(void *fontString) {
if (fontString == nullptr)
return nullptr;
return *reinterpret_cast<void **>(reinterpret_cast<uint8_t *>(fontString) +
Offsets::OFF_FONTSTRING_FONT_OBJECT);
return Game::Read<void *>(fontString, Offsets::OFF_FONTSTRING_FONT_OBJECT);
}
// Builds one CSimpleFontString: alloc → ctor(parent) → name → font (copied
@@ -138,30 +137,30 @@ void AppendLine(uint8_t *tooltip, void *left, void *right) {
auto reallocPtr = reinterpret_cast<ReallocArray_t>(Offsets::FUN_TOOLTIP_REALLOC_PTR_ARRAY);
auto reallocInt = reinterpret_cast<ReallocArray_t>(Offsets::FUN_TOOLTIP_REALLOC_INT_ARRAY);
const uint32_t index = *reinterpret_cast<uint32_t *>(
tooltip + Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC);
const uint32_t index =
Game::Read<uint32_t>(tooltip, Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC);
const uint32_t newCount = index + 1;
reallocPtr(tooltip + Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC, newCount);
*reinterpret_cast<uint32_t *>(tooltip + Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 4) = newCount;
Game::Ref<uint32_t>(tooltip, Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC + 4) = newCount;
reallocPtr(tooltip + Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC, newCount);
*reinterpret_cast<uint32_t *>(tooltip + Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC + 4) = newCount;
Game::Ref<uint32_t>(tooltip, Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC + 4) = newCount;
reallocInt(tooltip + Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC, newCount);
*reinterpret_cast<uint32_t *>(tooltip + Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC + 4) = newCount;
Game::Ref<uint32_t>(tooltip, Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC + 4) = newCount;
reinterpret_cast<void **>(DescData(tooltip, Offsets::OFF_GAMETOOLTIP_TEXTLEFT_DESC))[index] = left;
reinterpret_cast<void **>(DescData(tooltip, Offsets::OFF_GAMETOOLTIP_TEXTRIGHT_DESC))[index] = right;
reinterpret_cast<uint32_t *>(DescData(tooltip, Offsets::OFF_GAMETOOLTIP_WRAPFLAG_DESC))[index] = 0;
*reinterpret_cast<uint32_t *>(tooltip + Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC) = newCount;
Game::Ref<uint32_t>(tooltip, Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC) = newCount;
}
// Grows `tooltip`'s line pool up to kMaxLines, creating + appending the
// missing `TextLeftN`/`TextRightN` pairs. No-op if the pool is empty
// (scan didn't populate) or already at/above the target.
void GrowPool(uint8_t *tooltip) {
uint32_t count = *reinterpret_cast<uint32_t *>(
tooltip + Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC);
uint32_t count =
Game::Read<uint32_t>(tooltip, Offsets::OFF_GAMETOOLTIP_NUM_LINES_ALLOC);
if (count == 0 || count >= kMaxLines)
return;
+3 -4
View File
@@ -53,15 +53,14 @@ static int __fastcall Script_GameTooltipGetOwner(void *L) {
if (tooltip == nullptr)
return 0;
auto *layoutFrame = *reinterpret_cast<uint8_t *const *>(
static_cast<uint8_t *>(tooltip) + Offsets::OFF_TOOLTIP_OWNER);
auto *layoutFrame = Game::Read<uint8_t *>(tooltip, Offsets::OFF_TOOLTIP_OWNER);
if (layoutFrame == nullptr) {
Game::Lua::PushNil(L);
return 1;
}
auto *ownerFrame = layoutFrame - Offsets::OFF_FRAME_LAYOUT_SUBOBJECT;
const int refKey = *reinterpret_cast<const int *>(
ownerFrame + Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
const int refKey =
Game::Read<int>(ownerFrame, Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
auto rawgeti = reinterpret_cast<LuaRawGetI_t>(
Offsets::FUN_FRAMESCRIPT_PUSH_OBJECT);
rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey);
+23 -25
View File
@@ -92,7 +92,7 @@ using Time::Clock::NowMs;
// The totem tool item a spell requires (`Totem[0]`), or 0.
uint32_t TotemToolItem(const uint8_t *rec) {
const int32_t t = *reinterpret_cast<const int32_t *>(rec + Offsets::OFF_SPELL_RECORD_TOTEM);
const int32_t t = Game::Read<int32_t>(rec, Offsets::OFF_SPELL_RECORD_TOTEM);
return t > 0 ? static_cast<uint32_t>(t) : 0;
}
@@ -122,7 +122,7 @@ void ScanTools() {
const uint8_t *rec = Spell::Lookup::RecordForID(spellID);
if (rec == nullptr)
continue;
const auto *eff = reinterpret_cast<const int32_t *>(rec + Offsets::OFF_SPELL_RECORD_EFFECT);
const auto *eff = Game::Ptr<const int32_t>(rec, Offsets::OFF_SPELL_RECORD_EFFECT);
for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) {
const int e = eff[i];
if (e < kEffectSummonTotemSlot1 || e > kEffectSummonTotemSlot4)
@@ -190,12 +190,12 @@ int __fastcall ScanCallback(ScanCtx *ctx, void * /*unusedEdx*/, uint64_t guid) {
void *obj = Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, nullptr, 0);
if (obj == nullptr)
return 1;
auto *desc = *reinterpret_cast<const uint8_t *const *>(
static_cast<const uint8_t *>(obj) + Offsets::OFF_UNIT_DESCRIPTOR);
auto *desc = Game::Read<const uint8_t *>(
obj, Offsets::OFF_UNIT_DESCRIPTOR);
if (desc == nullptr)
return 1;
const uint64_t createdBy = *reinterpret_cast<const uint64_t *>(
desc + Offsets::OFF_UNIT_FIELD_CREATEDBY);
const uint64_t createdBy = Game::Read<uint64_t>(
desc, Offsets::OFF_UNIT_FIELD_CREATEDBY);
if (createdBy == ctx->playerGuid)
ctx->present[match] = true;
return 1; // keep scanning — other slots may match other creatures
@@ -218,12 +218,12 @@ int __fastcall FindGuidCallback(FindGuidCtx *ctx, void * /*unusedEdx*/,
void *obj = Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, nullptr, 0);
if (obj == nullptr)
return 1;
auto *desc = *reinterpret_cast<const uint8_t *const *>(
static_cast<const uint8_t *>(obj) + Offsets::OFF_UNIT_DESCRIPTOR);
auto *desc = Game::Read<const uint8_t *>(
obj, Offsets::OFF_UNIT_DESCRIPTOR);
if (desc == nullptr)
return 1;
if (*reinterpret_cast<const uint64_t *>(
desc + Offsets::OFF_UNIT_FIELD_CREATEDBY) == ctx->playerGuid) {
if (Game::Read<uint64_t>(
desc, Offsets::OFF_UNIT_FIELD_CREATEDBY) == ctx->playerGuid) {
ctx->found = guid;
return 0; // stop
}
@@ -233,7 +233,7 @@ int __fastcall FindGuidCallback(FindGuidCtx *ctx, void * /*unusedEdx*/,
uint64_t FindTotemGuid(uint32_t entry) {
if (entry == 0)
return 0;
if (*reinterpret_cast<void *volatile *>(Offsets::VAR_LOCAL_PLAYER_PTR) ==
if (Game::Read<void *volatile>(Offsets::VAR_LOCAL_PLAYER_PTR) ==
nullptr)
return 0;
const uint64_t player = Unit::Identity::PlayerGuid();
@@ -294,7 +294,7 @@ void OnTick() {
// object-manager enumerator derefs the manager unconditionally, so it's
// gated on the local player existing.
if (anyActive && now - g_lastScanMs >= kScanIntervalMs &&
*reinterpret_cast<void *volatile *>(Offsets::VAR_LOCAL_PLAYER_PTR) !=
Game::Read<void *volatile>(Offsets::VAR_LOCAL_PLAYER_PTR) !=
nullptr) {
const uint64_t player = Unit::Identity::PlayerGuid();
if (player != 0) {
@@ -331,12 +331,11 @@ const Tick::WorldTick::AutoSubscribe _tick{&OnTick};
const char *IconPath(int iconID) {
if (iconID <= 0)
return nullptr;
const int count = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_SPELL_ICON_COUNT));
const int count = Game::Read<int>(Offsets::VAR_SPELL_ICON_COUNT);
if (iconID > count)
return nullptr;
auto *const *records = *reinterpret_cast<const uint8_t *const *const *>(
static_cast<uintptr_t>(Offsets::VAR_SPELL_ICON_RECORDS));
auto *const *records = Game::Read<const uint8_t *const *>(
Offsets::VAR_SPELL_ICON_RECORDS);
if (records == nullptr || records[iconID] == nullptr)
return nullptr;
return *reinterpret_cast<const char *const *>(records[iconID] + 4);
@@ -390,13 +389,12 @@ int __fastcall Script_GetTotemInfo(void *L) {
const char *icon = nullptr;
if (rec != nullptr) {
const int locale =
*reinterpret_cast<const int *>(static_cast<uintptr_t>(
Offsets::VAR_LOCALE_INDEX));
const char *n = *reinterpret_cast<const char *const *>(
rec + Offsets::OFF_SPELL_NAMES + locale * 4);
Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
const char *n = Game::Read<const char *>(
rec, Offsets::OFF_SPELL_NAMES + locale * 4);
if (n != nullptr)
name = n;
icon = IconPath(*reinterpret_cast<const int *>(rec + Offsets::OFF_SPELL_RECORD_ICON_ID));
icon = IconPath(Game::Read<int>(rec, Offsets::OFF_SPELL_RECORD_ICON_ID));
}
Game::Lua::PushBool(L, haveTotem);
@@ -540,9 +538,9 @@ int __fastcall Script_GameTooltipSetTotem(void *L) {
if (rec == nullptr)
return 0;
const int locale =
*reinterpret_cast<const int *>(static_cast<uintptr_t>(Offsets::VAR_LOCALE_INDEX));
Game::Read<int>(Offsets::VAR_LOCALE_INDEX);
const char *name =
*reinterpret_cast<const char *const *>(rec + Offsets::OFF_SPELL_NAMES + locale * 4);
Game::Read<const char *>(rec, Offsets::OFF_SPELL_NAMES + locale * 4);
if (name == nullptr || name[0] == '\0')
return 0;
@@ -605,8 +603,8 @@ void OnPlayerSpellGo(uint32_t spellID) {
if (rec == nullptr)
return;
const auto *effects = reinterpret_cast<const int32_t *>(rec + Offsets::OFF_SPELL_RECORD_EFFECT);
const auto *misc = reinterpret_cast<const int32_t *>(rec + Offsets::OFF_SPELL_RECORD_EFFECT_MISC_VALUE);
const auto *effects = Game::Ptr<const int32_t>(rec, Offsets::OFF_SPELL_RECORD_EFFECT);
const auto *misc = Game::Ptr<const int32_t>(rec, Offsets::OFF_SPELL_RECORD_EFFECT_MISC_VALUE);
for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) {
const int eff = effects[i];
if (eff < kEffectSummonTotemSlot1 || eff > kEffectSummonTotemSlot4)
+42 -44
View File
@@ -87,8 +87,8 @@ bool IsCraftRecipe(int spellID) {
const uint8_t *rec = Spell::Lookup::RecordForID(spellID);
if (rec == nullptr)
return false;
const int32_t *eff = reinterpret_cast<const int32_t *>(
rec + Offsets::OFF_SPELL_RECORD_EFFECT);
const int32_t *eff = Game::Ptr<const int32_t>(
rec, Offsets::OFF_SPELL_RECORD_EFFECT);
for (int i = 0; i < Offsets::SPELL_RECORD_EFFECT_COUNT; ++i) {
const int e = eff[i];
if (e == Offsets::SPELL_EFFECT_CREATE_ITEM ||
@@ -108,10 +108,10 @@ bool IsCraftRecipe(int spellID) {
// use, so the bit-index space is identical.
int BuildRecipeList(uint32_t skillLineID, int *outSpell, int *outGrey,
int *outGreen, int maxOut) {
auto *const *records = *reinterpret_cast<const uint8_t *const *const *>(
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_RECORDS));
const int count = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_COUNT));
auto *const *records = Game::Read<const uint8_t *const *>(
Offsets::VAR_SKILL_LINE_ABILITY_RECORDS);
const int count = Game::Read<int>(
Offsets::VAR_SKILL_LINE_ABILITY_COUNT);
if (records == nullptr || count <= 0)
return 0;
@@ -120,19 +120,19 @@ int BuildRecipeList(uint32_t skillLineID, int *outSpell, int *outGrey,
const uint8_t *rec = records[i];
if (rec == nullptr)
continue;
if (static_cast<uint32_t>(*reinterpret_cast<const int *>(
rec + Offsets::OFF_SLA_SKILL_ID)) != skillLineID)
if (static_cast<uint32_t>(Game::Read<int>(
rec, Offsets::OFF_SLA_SKILL_ID)) != skillLineID)
continue;
const int spellID =
*reinterpret_cast<const int *>(rec + Offsets::OFF_SLA_SPELL_ID);
Game::Read<int>(rec, Offsets::OFF_SLA_SPELL_ID);
if (!IsCraftRecipe(spellID))
continue;
if (outGrey != nullptr)
outGrey[n] = *reinterpret_cast<const int *>(
rec + Offsets::OFF_SLA_TRIVIAL_SKILL_HIGH);
outGrey[n] = Game::Read<int>(
rec, Offsets::OFF_SLA_TRIVIAL_SKILL_HIGH);
if (outGreen != nullptr)
outGreen[n] = *reinterpret_cast<const int *>(
rec + Offsets::OFF_SLA_TRIVIAL_SKILL_LOW);
outGreen[n] = Game::Read<int>(
rec, Offsets::OFF_SLA_TRIVIAL_SKILL_LOW);
outSpell[n++] = spellID;
}
return n;
@@ -143,8 +143,8 @@ int BuildRecipeList(uint32_t skillLineID, int *outSpell, int *outGrey,
bool IsKnownSpell(int spellID) {
if (spellID <= 0)
return false;
auto *bitmap = *reinterpret_cast<const uint32_t *const *>(
static_cast<uintptr_t>(Offsets::VAR_PLAYER_SPELL_BITMAP));
auto *bitmap = Game::Read<const uint32_t *>(
Offsets::VAR_PLAYER_SPELL_BITMAP);
if (bitmap == nullptr)
return false;
return (bitmap[static_cast<uint32_t>(spellID) >> 5] &
@@ -158,19 +158,19 @@ bool IsKnownSpell(int spellID) {
uint32_t SkillForSpell(int spellID) {
if (spellID <= 0)
return 0;
auto *const *records = *reinterpret_cast<const uint8_t *const *const *>(
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_RECORDS));
const int count = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_SKILL_LINE_ABILITY_COUNT));
auto *const *records = Game::Read<const uint8_t *const *>(
Offsets::VAR_SKILL_LINE_ABILITY_RECORDS);
const int count = Game::Read<int>(
Offsets::VAR_SKILL_LINE_ABILITY_COUNT);
if (records == nullptr || count <= 0)
return 0;
for (int i = 1; i <= count; ++i) {
const uint8_t *rec = records[i];
if (rec != nullptr &&
*reinterpret_cast<const int *>(rec + Offsets::OFF_SLA_SPELL_ID) ==
Game::Read<int>(rec, Offsets::OFF_SLA_SPELL_ID) ==
spellID)
return static_cast<uint32_t>(
*reinterpret_cast<const int *>(rec + Offsets::OFF_SLA_SKILL_ID));
Game::Read<int>(rec, Offsets::OFF_SLA_SKILL_ID));
}
return 0;
}
@@ -178,8 +178,7 @@ uint32_t SkillForSpell(int spellID) {
// Skill line of the open Craft window (Enchanting, pet training) — derived
// from its first real recipe entry, mirroring the engine. 0 if none open.
uint32_t CraftSkillLine() {
const int count = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_CRAFT_COUNT));
const int count = Game::Read<int>(Offsets::VAR_CRAFT_COUNT);
if (count <= 0)
return 0;
const int cap = (count < kMaxRecipes) ? count : kMaxRecipes;
@@ -238,16 +237,16 @@ void ReadPlayerSkillRank(int skillLine, int *outCur, int *outMax) {
Offsets::FUN_SKILL_LINE_TO_SLOT)(player, skillLine);
if (slot < 0)
return;
const uint8_t *base = *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_CGPLAYER_INFO);
const uint8_t *base = Game::Read<const uint8_t *>(
player, Offsets::OFF_CGPLAYER_INFO);
if (base == nullptr)
return;
const uint8_t *rec =
base + Offsets::OFF_SKILL_INFO_TABLE + slot * Offsets::SKILL_INFO_STRIDE;
uint32_t cur = *reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_CUR);
uint32_t mx = *reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_MAX);
uint32_t cur = Game::Read<uint16_t>(rec, Offsets::OFF_SKILL_INFO_CUR);
uint32_t mx = Game::Read<uint16_t>(rec, Offsets::OFF_SKILL_INFO_MAX);
const uint32_t bonus =
*reinterpret_cast<const uint16_t *>(rec + Offsets::OFF_SKILL_INFO_BONUS);
Game::Read<uint16_t>(rec, Offsets::OFF_SKILL_INFO_BONUS);
if (cur != 0)
cur += bonus;
if (mx != 0)
@@ -274,14 +273,13 @@ int BuildLink(void *L, bool useCraft) {
int skillLine;
if (useCraft) {
// Craft-window open-state flag; zeroed by the engine on close.
if (*reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_CRAFT_WINDOW_STATE)) == 0)
if (Game::Read<int>(Offsets::VAR_CRAFT_WINDOW_STATE) == 0)
return 0;
skillLine = static_cast<int>(CraftSkillLine());
} else {
// TradeSkill skill-line global; zeroed by the engine on close.
skillLine = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_CURRENT_TRADESKILL_LINE));
skillLine = Game::Read<int>(
Offsets::VAR_CURRENT_TRADESKILL_LINE);
}
if (skillLine <= 0)
return 0;
@@ -373,16 +371,16 @@ int __fastcall Script_GetTradeSkillListRecipes(void *L) {
int createdItem = 0;
int numMade = 0;
if (srec != nullptr) {
createdItem = *reinterpret_cast<const int *>(
srec + Offsets::OFF_SPELL_RECORD_CREATED_ITEM);
createdItem = Game::Read<int>(
srec, Offsets::OFF_SPELL_RECORD_CREATED_ITEM);
// Yield: the CREATE_ITEM effect's magnitude (base points + dice),
// mirroring the engine's item-creation math. 0 for enchants.
const int32_t *eff = reinterpret_cast<const int32_t *>(
srec + Offsets::OFF_SPELL_RECORD_EFFECT);
const int32_t *basePts = reinterpret_cast<const int32_t *>(
srec + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS);
const int32_t *baseDice = reinterpret_cast<const int32_t *>(
srec + Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE);
const int32_t *eff = Game::Ptr<const int32_t>(
srec, Offsets::OFF_SPELL_RECORD_EFFECT);
const int32_t *basePts = Game::Ptr<const int32_t>(
srec, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_POINTS);
const int32_t *baseDice = Game::Ptr<const int32_t>(
srec, Offsets::OFF_SPELL_RECORD_EFFECT_BASE_DICE);
for (int e = 0; e < Offsets::SPELL_RECORD_EFFECT_COUNT; ++e) {
if (eff[e] == Offsets::SPELL_EFFECT_CREATE_ITEM) {
numMade = basePts[e] + baseDice[e];
@@ -408,10 +406,10 @@ int __fastcall Script_GetTradeSkillListRecipes(void *L) {
Game::Lua::PushString(L, "reagents");
Game::Lua::NewTable(L);
if (srec != nullptr) {
const int32_t *rids = reinterpret_cast<const int32_t *>(
srec + Offsets::OFF_SPELL_REAGENT_ID);
const int32_t *rcounts = reinterpret_cast<const int32_t *>(
srec + Offsets::OFF_SPELL_REAGENT_COUNT);
const int32_t *rids = Game::Ptr<const int32_t>(
srec, Offsets::OFF_SPELL_REAGENT_ID);
const int32_t *rcounts = Game::Ptr<const int32_t>(
srec, Offsets::OFF_SPELL_REAGENT_COUNT);
int outIdx = 0;
for (int r = 0; r < Offsets::SPELL_MAX_REAGENTS; ++r) {
if (rids[r] == 0)
+4 -7
View File
@@ -60,12 +60,10 @@ void Push(void *L, void *frame) {
static_cast<uintptr_t>(Offsets::FUN_FRAMESCRIPT_OBJECT_SCRIPT_REGISTER));
auto *cobj = static_cast<uint8_t *>(frame);
int refKey = *reinterpret_cast<const int *>(
cobj + Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
int refKey = Game::Read<int>(cobj, Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
if (refKey <= 0) {
scriptRegister(frame, nullptr, nullptr);
refKey = *reinterpret_cast<const int *>(
cobj + Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
refKey = Game::Read<int>(cobj, Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
}
rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey);
@@ -76,10 +74,9 @@ void Push(void *L, void *frame) {
// Slot got freed somewhere — re-register to rebuild a fresh wrapper
// and slot. Zero the refcount so `ScriptRegister` re-enters its build
// branch.
*reinterpret_cast<int *>(cobj + Offsets::OFF_COBJECT_LUA_REFCOUNT) = 0;
Game::Ref<int>(cobj, Offsets::OFF_COBJECT_LUA_REFCOUNT) = 0;
scriptRegister(frame, nullptr, nullptr);
refKey = *reinterpret_cast<const int *>(
cobj + Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
refKey = Game::Read<int>(cobj, Offsets::OFF_COBJECT_LUA_REGISTRY_REF);
rawgeti(L, Game::Lua::REGISTRY_INDEX, refKey);
}
+5 -5
View File
@@ -79,13 +79,13 @@ int __fastcall Script_UnitClassBase(void *L) {
// tokens go through the unit descriptor.
uint8_t classByte = 0;
if (Unit::Identity::IsPlayerToken(token)) {
classByte = *reinterpret_cast<const uint8_t *>(Offsets::VAR_PLAYER_CLASS_BYTE);
classByte = Game::Read<uint8_t>(Offsets::VAR_PLAYER_CLASS_BYTE);
} else {
auto resolve = reinterpret_cast<ResolveUnitToken_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN);
auto *unit = static_cast<const uint8_t *>(resolve(token));
if (unit != nullptr) {
auto *desc = *reinterpret_cast<const uint8_t *const *>(
unit + Offsets::OFF_UNIT_DESCRIPTOR);
auto *desc =
Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
if (desc != nullptr)
classByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_CLASS_BYTE);
}
@@ -98,8 +98,8 @@ int __fastcall Script_UnitClassBase(void *L) {
const uint8_t *rec = Unit::Identity::PlayerInfoRecord(
Unit::Identity::GuidForToken(token));
if (rec != nullptr)
classByte = static_cast<uint8_t>(*reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_PLAYER_INFO_CLASS));
classByte = static_cast<uint8_t>(
Game::Read<uint32_t>(rec, Offsets::OFF_PLAYER_INFO_CLASS));
}
}
if (classByte == 0) {
+24 -29
View File
@@ -26,19 +26,19 @@ namespace Unit::Flags {
bool IsPlayerControlled(const uint8_t *unit) {
if (unit == nullptr)
return false;
auto *fields = *reinterpret_cast<const uint8_t *const *>(
unit + Offsets::OFF_UNIT_DESCRIPTOR);
auto *fields =
Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
if (fields == nullptr)
return false;
const uint32_t unitFlags = *reinterpret_cast<const uint32_t *>(
fields + Offsets::OFF_UNIT_FIELD_FLAGS);
const uint32_t unitFlags =
Game::Read<uint32_t>(fields, Offsets::OFF_UNIT_FIELD_FLAGS);
return (unitFlags & Offsets::UNIT_FLAG_PLAYER_CONTROLLED) != 0;
}
bool IsPlayerObject(const uint8_t *unit) {
if (unit == nullptr)
return false;
return *reinterpret_cast<const int *>(unit + Offsets::OFF_CGOBJECT_TYPE_ID) ==
return Game::Read<int>(unit, Offsets::OFF_CGOBJECT_TYPE_ID) ==
Offsets::OBJECT_TYPE_PLAYER;
}
@@ -80,12 +80,12 @@ bool TestPlayerFlag(void *L, uint32_t flagMask) {
if (!IsPlayerObject(unit))
return false;
auto *playerInfo = *reinterpret_cast<const uint8_t *const *>(
unit + Offsets::OFF_CGPLAYER_INFO);
auto *playerInfo =
Game::Read<const uint8_t *>(unit, Offsets::OFF_CGPLAYER_INFO);
if (playerInfo == nullptr)
return false;
const uint32_t flags = *reinterpret_cast<const uint32_t *>(
playerInfo + Offsets::OFF_PLAYER_INFO_FLAGS);
const uint32_t flags =
Game::Read<uint32_t>(playerInfo, Offsets::OFF_PLAYER_INFO_FLAGS);
return (flags & flagMask) != 0;
}
@@ -129,14 +129,14 @@ int __fastcall Script_UnitIsFeignDeath(void *L) {
Game::Lua::PushBoolean(L, 0);
return 1;
}
auto *fields = *reinterpret_cast<const uint8_t *const *>(
unit + Offsets::OFF_UNIT_DESCRIPTOR);
auto *fields =
Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
if (fields == nullptr) {
Game::Lua::PushBoolean(L, 0);
return 1;
}
const uint32_t unitFlags = *reinterpret_cast<const uint32_t *>(
fields + Offsets::OFF_UNIT_FIELD_FLAGS);
const uint32_t unitFlags =
Game::Read<uint32_t>(fields, Offsets::OFF_UNIT_FIELD_FLAGS);
Game::Lua::PushBoolean(L,
(unitFlags & Offsets::UNIT_FLAG_FEIGN_DEATH) != 0);
return 1;
@@ -154,12 +154,10 @@ uint32_t ReadGuildKey(const uint8_t *unit) {
// and crash (issue: UnitIsInMyGuild on a nameplate pet/totem).
if (!IsPlayerObject(unit))
return 0;
auto *info = *reinterpret_cast<const uint8_t *const *>(
unit + Offsets::OFF_CGPLAYER_INFO);
auto *info = Game::Read<const uint8_t *>(unit, Offsets::OFF_CGPLAYER_INFO);
if (info == nullptr)
return 0;
return *reinterpret_cast<const uint32_t *>(
info + Offsets::OFF_PLAYER_INFO_GUILD_KEY);
return Game::Read<uint32_t>(info, Offsets::OFF_PLAYER_INFO_GUILD_KEY);
}
using TokenToGUID_t = uint64_t(__fastcall *)(const char *token);
@@ -212,8 +210,7 @@ const char *NameFromGuid(uint64_t guid, char (&nameBuf)[64]) {
return nullptr;
std::snprintf(nameBuf, sizeof(nameBuf), "%s",
reinterpret_cast<const char *>(
entry + Offsets::OFF_PLAYER_INFO_NAME));
Game::Ptr<const char>(entry, Offsets::OFF_PLAYER_INFO_NAME));
return nameBuf;
}
@@ -323,10 +320,8 @@ int __fastcall Script_UnitIsInMyGuild(void *L) {
nameToFind = input;
}
auto **roster = *reinterpret_cast<uint8_t ***>(
Offsets::VAR_GUILD_ROSTER_PTR);
const int total = *reinterpret_cast<const int *>(
Offsets::VAR_GUILD_ROSTER_TOTAL_COUNT);
auto **roster = Game::Read<uint8_t **>(Offsets::VAR_GUILD_ROSTER_PTR);
const int total = Game::Read<int>(Offsets::VAR_GUILD_ROSTER_TOTAL_COUNT);
if (roster == nullptr || total <= 0) {
Game::Lua::PushNil(L);
return 1;
@@ -335,8 +330,8 @@ int __fastcall Script_UnitIsInMyGuild(void *L) {
const uint8_t *entry = roster[i];
if (entry == nullptr)
continue;
const char *name = reinterpret_cast<const char *>(
entry + Offsets::OFF_GUILD_MEMBER_NAME);
const char *name =
Game::Ptr<const char>(entry, Offsets::OFF_GUILD_MEMBER_NAME);
if (std::strcmp(name, nameToFind) == 0) {
Game::Lua::PushNumber(L, 1.0);
return 1;
@@ -368,14 +363,14 @@ int __fastcall Script_UnitIsPossessed(void *L) {
Game::Lua::PushBoolean(L, 0);
return 1;
}
auto *fields = *reinterpret_cast<const uint8_t *const *>(
unit + Offsets::OFF_UNIT_DESCRIPTOR);
auto *fields =
Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
if (fields == nullptr) {
Game::Lua::PushBoolean(L, 0);
return 1;
}
const uint32_t unitFlags = *reinterpret_cast<const uint32_t *>(
fields + Offsets::OFF_UNIT_FIELD_FLAGS);
const uint32_t unitFlags =
Game::Read<uint32_t>(fields, Offsets::OFF_UNIT_FIELD_FLAGS);
Game::Lua::PushBoolean(L,
(unitFlags & Offsets::UNIT_FLAG_POSSESSED) != 0);
return 1;
+11 -16
View File
@@ -47,12 +47,11 @@ static void __cdecl EnterWorld_h() {
g_origEnterWorld();
// Only on a genuine commit — the rename / char-locked bail paths return
// before the worker sets the state code to "entering world".
if (*reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_GLUE_LOGIN_INPROGRESS)) !=
if (Game::Read<int>(Offsets::VAR_GLUE_LOGIN_INPROGRESS) !=
Offsets::GLUE_STATE_ENTERING_WORLD)
return;
const uintptr_t charStruct = *reinterpret_cast<const uintptr_t *>(
static_cast<uintptr_t>(Offsets::VAR_GLUE_SELECTED_CHAR));
const uintptr_t charStruct =
Game::Read<uintptr_t>(Offsets::VAR_GLUE_SELECTED_CHAR);
if (charStruct != 0)
g_charSelectGuid = *reinterpret_cast<const uint64_t *>(
charStruct + Offsets::OFF_GLUE_CHAR_GUID);
@@ -86,11 +85,10 @@ static const Game::HookAutoRegister _enterWorldHook{
// this only makes the GUID *value* available early, for keying SavedVariables,
// comparisons, our aura/cast caster checks, etc.)
uint64_t PlayerGuid() {
auto *player = *reinterpret_cast<uint8_t *const *>(
static_cast<uintptr_t>(Offsets::VAR_LOCAL_PLAYER_PTR));
auto *player = Game::Read<uint8_t *>(Offsets::VAR_LOCAL_PLAYER_PTR);
if (player != nullptr) {
const uint64_t guid = *reinterpret_cast<const uint64_t *>(
player + Offsets::OFF_LOCAL_PLAYER_GUID);
const uint64_t guid =
Game::Read<uint64_t>(player, Offsets::OFF_LOCAL_PLAYER_GUID);
if (guid != 0)
return guid; // live engine value — authoritative
}
@@ -123,16 +121,15 @@ const uint8_t *PlayerDescriptor() {
const uint8_t *player = PlayerObject();
if (player == nullptr)
return nullptr;
return *reinterpret_cast<const uint8_t *const *>(
player + Offsets::OFF_UNIT_DESCRIPTOR);
return Game::Read<const uint8_t *>(player, Offsets::OFF_UNIT_DESCRIPTOR);
}
uint64_t GuidForObject(const void *unitObject) {
if (unitObject == nullptr)
return 0;
const auto *unit = static_cast<const uint8_t *>(unitObject);
const uint8_t *block = *reinterpret_cast<const uint8_t *const *>(
unit + Offsets::OFF_UNIT_GUID_PTR);
const uint8_t *block =
Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_GUID_PTR);
if (block == nullptr)
return 0;
return *reinterpret_cast<const uint64_t *>(block);
@@ -179,8 +176,7 @@ const char *NameForGuid(uint64_t guid) {
const uint8_t *rec = PlayerInfoRecord(guid);
if (rec == nullptr)
return nullptr;
const char *name =
reinterpret_cast<const char *>(rec + Offsets::OFF_PLAYER_INFO_NAME);
const char *name = Game::Ptr<const char>(rec, Offsets::OFF_PLAYER_INFO_NAME);
return (name != nullptr && *name != '\0') ? name : nullptr;
}
@@ -287,8 +283,7 @@ const char *TokenFromGUID(uint64_t target, char *buf, size_t bufSize) {
if (partyGuids[i] != 0)
++partyCount;
}
int raidCount = *reinterpret_cast<const int *>(
static_cast<uintptr_t>(Offsets::VAR_RAID_MEMBER_COUNT));
int raidCount = Game::Read<int>(Offsets::VAR_RAID_MEMBER_COUNT);
if (raidCount > Offsets::RAID_MAX_SLOTS)
raidCount = Offsets::RAID_MAX_SLOTS;
+3 -4
View File
@@ -52,8 +52,7 @@ constexpr float kMaxTraceYards = 150.0f; // guard: raw call can crash beyond
constexpr float kSamePointYards = 0.05f;
int ObjectType(void *obj) {
return *reinterpret_cast<int *>(reinterpret_cast<uint8_t *>(obj) +
Offsets::OFF_CGOBJECT_TYPE_ID);
return Game::Read<int>(obj, Offsets::OFF_CGOBJECT_TYPE_ID);
}
bool IsUnitOrPlayer(void *obj) {
@@ -65,8 +64,8 @@ bool IsUnitOrPlayer(void *obj) {
// CMovement sub-struct. 0 if the movement pointer is absent (degrades to a
// foot-level trace rather than crashing).
float EyeHeight(void *unit) {
const uint32_t cmov = *reinterpret_cast<uint32_t *>(
reinterpret_cast<uint8_t *>(unit) + Offsets::OFF_UNIT_MOVEMENT_INFO_PTR);
const uint32_t cmov =
Game::Read<uint32_t>(unit, Offsets::OFF_UNIT_MOVEMENT_INFO_PTR);
if (cmov == 0)
return 0.0f;
return *reinterpret_cast<float *>(cmov +
+5 -5
View File
@@ -59,13 +59,13 @@ int __fastcall Script_UnitRaceBase(void *L) {
// tokens go through the unit descriptor.
uint8_t raceByte = 0;
if (Unit::Identity::IsPlayerToken(token)) {
raceByte = *reinterpret_cast<const uint8_t *>(Offsets::VAR_PLAYER_RACE_BYTE);
raceByte = Game::Read<uint8_t>(Offsets::VAR_PLAYER_RACE_BYTE);
} else {
auto resolve = reinterpret_cast<ResolveUnitToken_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN);
auto *unit = static_cast<const uint8_t *>(resolve(token));
if (unit != nullptr) {
auto *desc = *reinterpret_cast<const uint8_t *const *>(
unit + Offsets::OFF_UNIT_DESCRIPTOR);
auto *desc =
Game::Read<const uint8_t *>(unit, Offsets::OFF_UNIT_DESCRIPTOR);
if (desc != nullptr)
raceByte = *(desc + Offsets::OFF_UNIT_DESCRIPTOR_RACE_BYTE);
}
@@ -78,8 +78,8 @@ int __fastcall Script_UnitRaceBase(void *L) {
const uint8_t *rec = Unit::Identity::PlayerInfoRecord(
Unit::Identity::GuidForToken(token));
if (rec != nullptr)
raceByte = static_cast<uint8_t>(*reinterpret_cast<const uint32_t *>(
rec + Offsets::OFF_PLAYER_INFO_RACE));
raceByte = static_cast<uint8_t>(
Game::Read<uint32_t>(rec, Offsets::OFF_PLAYER_INFO_RACE));
}
}
if (raceByte == 0) {
+8 -8
View File
@@ -113,10 +113,10 @@ static int __fastcall Script_GameTooltipGetUnitGUID(void *L) {
return 0;
const auto *base = static_cast<const uint8_t *>(tooltipObj);
const uint32_t guidLo = *reinterpret_cast<const uint32_t *>(
base + Offsets::OFF_TOOLTIP_UNIT_GUID_LO);
const uint32_t guidHi = *reinterpret_cast<const uint32_t *>(
base + Offsets::OFF_TOOLTIP_UNIT_GUID_HI);
const uint32_t guidLo =
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_UNIT_GUID_LO);
const uint32_t guidHi =
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_UNIT_GUID_HI);
if (guidLo == 0 && guidHi == 0)
return 0;
@@ -147,10 +147,10 @@ static int __fastcall Script_GameTooltipHasUnit(void *L) {
return 1;
}
const auto *base = static_cast<const uint8_t *>(tooltipObj);
const uint32_t guidLo = *reinterpret_cast<const uint32_t *>(
base + Offsets::OFF_TOOLTIP_UNIT_GUID_LO);
const uint32_t guidHi = *reinterpret_cast<const uint32_t *>(
base + Offsets::OFF_TOOLTIP_UNIT_GUID_HI);
const uint32_t guidLo =
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_UNIT_GUID_LO);
const uint32_t guidHi =
Game::Read<uint32_t>(base, Offsets::OFF_TOOLTIP_UNIT_GUID_HI);
Game::Lua::PushBool(L, guidLo != 0 || guidHi != 0);
return 1;
}
+15 -22
View File
@@ -60,19 +60,16 @@ const char *Attr(const uint8_t *node, const char *name) {
}
const uint8_t *FirstChild(const uint8_t *node) {
return *reinterpret_cast<const uint8_t *const *>(
node + Offsets::OFF_XML_NODE_CHILD);
return Game::Read<const uint8_t *>(node, Offsets::OFF_XML_NODE_CHILD);
}
const uint8_t *NextSibling(const uint8_t *node) {
return *reinterpret_cast<const uint8_t *const *>(
node + Offsets::OFF_XML_NODE_SIBLING);
return Game::Read<const uint8_t *>(node, Offsets::OFF_XML_NODE_SIBLING);
}
// Case-insensitive tag match, using the engine's own comparator (the same one
// FUN_006f1eb0 uses to recognize "AbsDimension" etc.).
bool TagEquals(const uint8_t *node, const char *tag) {
const char *t = *reinterpret_cast<const char *const *>(
node + Offsets::OFF_XML_NODE_TAG);
const char *t = Game::Read<const char *>(node, Offsets::OFF_XML_NODE_TAG);
if (t == nullptr)
return false;
return reinterpret_cast<SStrCmpI_t>(Offsets::FUN_SSTR_CMP_I)(
@@ -119,35 +116,32 @@ void ReadSize(const uint8_t *node, double *outW, double *outH) {
int __fastcall Script_GetTemplates(void *L) {
Game::Lua::NewTable(L); // the result array
const uint32_t mask =
*reinterpret_cast<const uint32_t *>(Offsets::VAR_XML_TEMPLATE_MASK);
const uint32_t mask = Game::Read<uint32_t>(Offsets::VAR_XML_TEMPLATE_MASK);
if (mask == 0xFFFFFFFFu)
return 1; // no template has ever registered — empty array
const uint8_t *base = *reinterpret_cast<const uint8_t *const *>(
Offsets::VAR_XML_TEMPLATE_TABLE);
const uint8_t *base = Game::Read<const uint8_t *>(Offsets::VAR_XML_TEMPLATE_TABLE);
if (base == nullptr)
return 1;
int outIdx = 0;
for (uint32_t b = 0; b <= mask; ++b) {
const uint8_t *bucket = base + b * Offsets::XML_TEMPLATE_BUCKET_STRIDE;
const int linkOff = *reinterpret_cast<const int *>(
bucket + Offsets::OFF_XML_TEMPLATE_BUCKET_LINKOFF);
const uint8_t *node = *reinterpret_cast<const uint8_t *const *>(
bucket + Offsets::OFF_XML_TEMPLATE_BUCKET_HEAD);
const int linkOff = Game::Read<int>(
bucket, Offsets::OFF_XML_TEMPLATE_BUCKET_LINKOFF);
const uint8_t *node = Game::Read<const uint8_t *>(
bucket, Offsets::OFF_XML_TEMPLATE_BUCKET_HEAD);
// Walk the intrusive chain; the tail sentinel has its low bit set
// (mirrors the engine's own traversal in FUN_006ee6f0).
while (node != nullptr && (reinterpret_cast<uintptr_t>(node) & 1) == 0) {
const char *name = *reinterpret_cast<const char *const *>(
node + Offsets::OFF_XML_TEMPLATE_NODE_NAME);
const uint8_t *def = *reinterpret_cast<const uint8_t *const *>(
node + Offsets::OFF_XML_TEMPLATE_NODE_DEF);
const char *name = Game::Read<const char *>(
node, Offsets::OFF_XML_TEMPLATE_NODE_NAME);
const uint8_t *def = Game::Read<const uint8_t *>(
node, Offsets::OFF_XML_TEMPLATE_NODE_DEF);
const char *type =
(def != nullptr)
? *reinterpret_cast<const char *const *>(
def + Offsets::OFF_XML_NODE_TAG)
? Game::Read<const char *>(def, Offsets::OFF_XML_NODE_TAG)
: nullptr;
++outIdx;
@@ -177,8 +171,7 @@ int __fastcall Script_GetTemplateInfo(void *L) {
Game::Lua::NewTable(L); // XMLTemplateInfo
const char *type = *reinterpret_cast<const char *const *>(
node + Offsets::OFF_XML_NODE_TAG);
const char *type = Game::Read<const char *>(node, Offsets::OFF_XML_NODE_TAG);
Game::Lua::SetFieldString(L, "type", type != nullptr ? type : "");
double w = 0.0, h = 0.0;