fix spell functions that looked up spell name -> spell id sometimes using incorrect spell ranks after changing specs

This commit is contained in:
avitasia
2026-03-21 21:50:38 -07:00
parent bbc029beaf
commit ddd6758348
4 changed files with 12392 additions and 12372 deletions
+1 -1
View File
@@ -775,7 +775,7 @@ Fast lookup for a single field on a unit. More efficient than GetUnitData when y
- For array fields (like "aura", "resistances"), returns a Lua table with numeric indices
- Object-reference GUID fields are returned as hex GUID strings (not numbers) to avoid Lua 64-bit precision issues. This includes fields such as `charm`, `summon`, `charmedBy`, `summonedBy`, `createdBy`, `target`, `persuaded`, and `channelObject`.
**Note:** `GetUnitField` falls back to cached `party_member_fields` data when the unit object is not loaded. The overlapping `UnitFields` names available through this fallback are `health`, `maxHealth`, `level`, and `aura` for party/raid members, plus `displayId`, `health`, `maxHealth`, and `aura` for party/raid pets.
**Note:** `GetUnitField` falls back to using `party_member_fields` data if available when the unit object is not loaded (invisible or out of range). The overlapping `UnitFields` names available through this fallback are `health`, `maxHealth`, `level`, and `aura` for party/raid members, plus `displayId`, `health`, `maxHealth`, and `aura` for party/raid pets.
Full field name lists are in [`UNIT_FIELDS.md`](UNIT_FIELDS.md).
+12371 -12347
View File
File diff suppressed because it is too large Load Diff
+19 -23
View File
@@ -39,6 +39,7 @@ namespace Nampower {
int32_t slot;
uint32_t type;
std::string cachedNameLower;
std::string cachedRankLower;
};
static std::unordered_map<std::string, CachedEntry> spellSlotCache;
@@ -50,49 +51,43 @@ namespace Nampower {
const std::string key = normalize(spellName);
auto const spellNameMatchesAtSlot = [&normalize](const char *requestedLower, uint32_t slot,
uint32_t type) -> bool {
if (!requestedLower) {
return false;
}
struct SlotSpellInfo {
std::string nameLower;
std::string rankLower;
};
auto const getSpellInfoAtSlot = [&normalize](uint32_t slot, uint32_t type) -> SlotSpellInfo {
uint32_t spellId = 0;
if (type == 0) {
spellId = *reinterpret_cast<uint32_t *>(static_cast<uint32_t>(Offsets::CGSpellBook_mKnownSpells) + slot * 4);
} else if (type == 1) {
spellId = *reinterpret_cast<uint32_t *>(static_cast<uint32_t>(Offsets::CGSpellBook_mKnownPetSpells) + slot * 4);
} else {
return false;
}
if (spellId == 0) {
return false;
return {};
}
auto const spell = game::GetSpellInfo(spellId);
if (!spell) {
return false;
return {};
}
auto const language = *reinterpret_cast<uint32_t *>(Offsets::Language);
auto const actualName = reinterpret_cast<const char *>(spell->Name[language]);
if (!actualName) {
return false;
}
auto const actualLower = normalize(actualName);
return _stricmp(actualLower.c_str(), requestedLower) == 0;
auto const actualRank = reinterpret_cast<const char *>(spell->Rank[language]);
return {normalize(actualName), normalize(actualRank ? actualRank : "")};
};
if (!key.empty()) {
auto cacheIt = spellSlotCache.find(key);
if (cacheIt != spellSlotCache.end()) {
auto const &entry = cacheIt->second;
if (entry.slot < 1024 && spellNameMatchesAtSlot(key.c_str(), entry.slot, entry.type)) {
if (spellType) {
*spellType = entry.type;
if (entry.slot < 1024) {
auto const info = getSpellInfoAtSlot(entry.slot, entry.type);
if (info.nameLower == entry.cachedNameLower && info.rankLower == entry.cachedRankLower) {
if (spellType) {
*spellType = entry.type;
}
return entry.slot;
}
return entry.slot;
}
}
}
@@ -101,7 +96,8 @@ namespace Nampower {
auto const slot = getSpellSlotAndType(spellName, spellType);
if (slot < 1024 && spellType && !key.empty()) {
spellSlotCache[key] = {slot, *spellType, key};
auto const info = getSpellInfoAtSlot(slot, *spellType);
spellSlotCache[key] = {slot, *spellType, info.nameLower, info.rankLower};
}
return slot;
+1 -1
View File
@@ -27,7 +27,7 @@ namespace Nampower {
constexpr uint32_t MAJOR_VERSION = 4;
constexpr uint32_t MINOR_VERSION = 1;
constexpr uint32_t PATCH_VERSION = 2;
constexpr uint32_t PATCH_VERSION = 3;
constexpr int32_t LUA_REGISTRYINDEX = -10000;
constexpr int32_t LUA_GLOBALSINDEX = -10001;