mirror of
https://github.com/brues-code/nampower.git
synced 2026-10-26 05:50:50 +00:00
clear spell slot caches on pet change
This commit is contained in:
+13157
-13144
File diff suppressed because it is too large
Load Diff
+16
-16
@@ -12,6 +12,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Nampower {
|
namespace Nampower {
|
||||||
|
std::unordered_map<std::string, SpellSlotCacheEntry> gSpellSlotCache;
|
||||||
|
std::unordered_map<uint64_t, uint32_t> gSpellIdToSlotCache;
|
||||||
|
|
||||||
// Lua function pointers
|
// Lua function pointers
|
||||||
lua_errorT lua_error = reinterpret_cast<lua_errorT>(Offsets::lua_error);
|
lua_errorT lua_error = reinterpret_cast<lua_errorT>(Offsets::lua_error);
|
||||||
lua_gettopT lua_gettop = reinterpret_cast<lua_gettopT>(Offsets::lua_gettop);
|
lua_gettopT lua_gettop = reinterpret_cast<lua_gettopT>(Offsets::lua_gettop);
|
||||||
@@ -35,14 +38,6 @@ namespace Nampower {
|
|||||||
|
|
||||||
|
|
||||||
int32_t GetSpellSlotAndTypeForName(const char *spellName, uint32_t *spellType) {
|
int32_t GetSpellSlotAndTypeForName(const char *spellName, uint32_t *spellType) {
|
||||||
struct CachedEntry {
|
|
||||||
int32_t slot;
|
|
||||||
uint32_t type;
|
|
||||||
std::string cachedNameLower;
|
|
||||||
std::string cachedRankLower;
|
|
||||||
};
|
|
||||||
static std::unordered_map<std::string, CachedEntry> spellSlotCache;
|
|
||||||
|
|
||||||
auto const normalize = [](const char *name) -> std::string {
|
auto const normalize = [](const char *name) -> std::string {
|
||||||
std::string out = name ? name : "";
|
std::string out = name ? name : "";
|
||||||
std::transform(out.begin(), out.end(), out.begin(), [](unsigned char c) { return char(std::tolower(c)); });
|
std::transform(out.begin(), out.end(), out.begin(), [](unsigned char c) { return char(std::tolower(c)); });
|
||||||
@@ -79,8 +74,8 @@ namespace Nampower {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!key.empty()) {
|
if (!key.empty()) {
|
||||||
auto cacheIt = spellSlotCache.find(key);
|
auto cacheIt = gSpellSlotCache.find(key);
|
||||||
if (cacheIt != spellSlotCache.end()) {
|
if (cacheIt != gSpellSlotCache.end()) {
|
||||||
auto const &entry = cacheIt->second;
|
auto const &entry = cacheIt->second;
|
||||||
if (entry.slot < 1024) {
|
if (entry.slot < 1024) {
|
||||||
auto const info = getSpellInfoAtSlot(entry.slot, entry.type);
|
auto const info = getSpellInfoAtSlot(entry.slot, entry.type);
|
||||||
@@ -99,7 +94,7 @@ namespace Nampower {
|
|||||||
|
|
||||||
if (slot < 1024 && spellType && !key.empty()) {
|
if (slot < 1024 && spellType && !key.empty()) {
|
||||||
auto const info = getSpellInfoAtSlot(slot, *spellType);
|
auto const info = getSpellInfoAtSlot(slot, *spellType);
|
||||||
spellSlotCache[key] = {slot, *spellType, info.nameLower, info.rankLower};
|
gSpellSlotCache[key] = {slot, *spellType, info.nameLower, info.rankLower};
|
||||||
}
|
}
|
||||||
|
|
||||||
return slot;
|
return slot;
|
||||||
@@ -124,7 +119,6 @@ namespace Nampower {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ConvertSpellIdToSpellSlot(uint32_t spellId, uint32_t bookType) {
|
uint32_t ConvertSpellIdToSpellSlot(uint32_t spellId, uint32_t bookType) {
|
||||||
static std::unordered_map<uint64_t, uint32_t> spellIdToSlotCache;
|
|
||||||
auto const cacheKey = (uint64_t(spellId) << 1) | (bookType & 0x1);
|
auto const cacheKey = (uint64_t(spellId) << 1) | (bookType & 0x1);
|
||||||
|
|
||||||
auto const slotHasSpellId = [bookType](uint32_t slot, uint32_t expectedId) -> bool {
|
auto const slotHasSpellId = [bookType](uint32_t slot, uint32_t expectedId) -> bool {
|
||||||
@@ -142,8 +136,8 @@ namespace Nampower {
|
|||||||
return slotSpellId == expectedId;
|
return slotSpellId == expectedId;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto cacheIt = spellIdToSlotCache.find(cacheKey);
|
auto cacheIt = gSpellIdToSlotCache.find(cacheKey);
|
||||||
if (cacheIt != spellIdToSlotCache.end()) {
|
if (cacheIt != gSpellIdToSlotCache.end()) {
|
||||||
if (slotHasSpellId(cacheIt->second, spellId)) {
|
if (slotHasSpellId(cacheIt->second, spellId)) {
|
||||||
return cacheIt->second;
|
return cacheIt->second;
|
||||||
}
|
}
|
||||||
@@ -155,7 +149,7 @@ namespace Nampower {
|
|||||||
uint32_t slotSpellId = *reinterpret_cast<uint32_t *>(uint32_t(Offsets::CGSpellBook_mKnownSpells) +
|
uint32_t slotSpellId = *reinterpret_cast<uint32_t *>(uint32_t(Offsets::CGSpellBook_mKnownSpells) +
|
||||||
spellSlot * 4);
|
spellSlot * 4);
|
||||||
if (slotSpellId == spellId) {
|
if (slotSpellId == spellId) {
|
||||||
spellIdToSlotCache[cacheKey] = spellSlot;
|
gSpellIdToSlotCache[cacheKey] = spellSlot;
|
||||||
return spellSlot;
|
return spellSlot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,7 +159,7 @@ namespace Nampower {
|
|||||||
uint32_t slotSpellId = *reinterpret_cast<uint32_t *>(uint32_t(Offsets::CGSpellBook_mKnownPetSpells) +
|
uint32_t slotSpellId = *reinterpret_cast<uint32_t *>(uint32_t(Offsets::CGSpellBook_mKnownPetSpells) +
|
||||||
spellSlot * 4);
|
spellSlot * 4);
|
||||||
if (slotSpellId == spellId) {
|
if (slotSpellId == spellId) {
|
||||||
spellIdToSlotCache[cacheKey] = spellSlot;
|
gSpellIdToSlotCache[cacheKey] = spellSlot;
|
||||||
return spellSlot;
|
return spellSlot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,6 +168,12 @@ namespace Nampower {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClearSpellSlotCaches() {
|
||||||
|
DEBUG_LOG("Clearing spell slot and spellId -> spell slot caches");
|
||||||
|
gSpellSlotCache.clear();
|
||||||
|
gSpellIdToSlotCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SpellIsOnGcd(const game::SpellRec *spell) {
|
bool SpellIsOnGcd(const game::SpellRec *spell) {
|
||||||
if (spell->Id == 51714) {
|
if (spell->Id == 51714) {
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ namespace Nampower {
|
|||||||
|
|
||||||
uint32_t ConvertSpellIdToSpellSlot(uint32_t spellId, uint32_t bookType);
|
uint32_t ConvertSpellIdToSpellSlot(uint32_t spellId, uint32_t bookType);
|
||||||
|
|
||||||
|
void ClearSpellSlotCaches();
|
||||||
|
|
||||||
bool SpellIsOnGcd(const game::SpellRec *spell);
|
bool SpellIsOnGcd(const game::SpellRec *spell);
|
||||||
|
|
||||||
bool SpellIsChanneling(const game::SpellRec *spell);
|
bool SpellIsChanneling(const game::SpellRec *spell);
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ namespace Nampower {
|
|||||||
|
|
||||||
constexpr uint32_t MAJOR_VERSION = 4;
|
constexpr uint32_t MAJOR_VERSION = 4;
|
||||||
constexpr uint32_t MINOR_VERSION = 2;
|
constexpr uint32_t MINOR_VERSION = 2;
|
||||||
constexpr uint32_t PATCH_VERSION = 1;
|
constexpr uint32_t PATCH_VERSION = 2;
|
||||||
|
|
||||||
constexpr int32_t LUA_REGISTRYINDEX = -10000;
|
constexpr int32_t LUA_REGISTRYINDEX = -10000;
|
||||||
constexpr int32_t LUA_GLOBALSINDEX = -10001;
|
constexpr int32_t LUA_GLOBALSINDEX = -10001;
|
||||||
|
|||||||
@@ -252,6 +252,7 @@ namespace Nampower {
|
|||||||
|
|
||||||
uint64_t newPetGuid = *reinterpret_cast<uint64_t *>(Offsets::ActivePetGuid);
|
uint64_t newPetGuid = *reinterpret_cast<uint64_t *>(Offsets::ActivePetGuid);
|
||||||
if (activePetGuid != newPetGuid) {
|
if (activePetGuid != newPetGuid) {
|
||||||
|
ClearSpellSlotCaches();
|
||||||
DEBUG_LOG("Active pet guid changed from " << activePetGuid << " to " << newPetGuid);
|
DEBUG_LOG("Active pet guid changed from " << activePetGuid << " to " << newPetGuid);
|
||||||
|
|
||||||
if (gUserSettings.preserveGreaterDemonAutocast && newPetGuid != 0) {
|
if (gUserSettings.preserveGreaterDemonAutocast && newPetGuid != 0) {
|
||||||
|
|||||||
@@ -166,3 +166,10 @@ struct EVENT_DATA_KEY {
|
|||||||
uint32_t repeat;
|
uint32_t repeat;
|
||||||
uint32_t time;
|
uint32_t time;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SpellSlotCacheEntry {
|
||||||
|
int32_t slot;
|
||||||
|
uint32_t type;
|
||||||
|
std::string cachedNameLower;
|
||||||
|
std::string cachedRankLower;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user