remove accidental debug log

add auraSlot to buff/debuff events
add buff/debuff duration events
add GetPlayerAuraDuration
This commit is contained in:
avitasia
2026-02-09 12:24:32 -08:00
parent 453e656e3e
commit 983ea93c71
12 changed files with 12611 additions and 12309 deletions
+40 -3
View File
@@ -8,6 +8,8 @@
#include "game.hpp"
namespace Nampower {
uint32_t gAuraExpirationTime[MAX_AURA_SLOTS] = {};
// Helper function to trigger buff/debuff events
void TriggerAuraEvent(uintptr_t *unit, uint32_t slot, uint32_t spellId, bool wasAdded) {
// Determine if the unit is the active player (self) or another unit (other)
@@ -71,7 +73,7 @@ namespace Nampower {
}
}
static char format[] = "%s%d%d%d%d";
static char format[] = "%s%d%d%d%d%d";
char *guidStr = new char[21]; // 2 for 0x prefix, 18 for the number, and 1 for '\0'
if (isSelf) {
std::snprintf(guidStr, 21, "0x%016llX", static_cast<unsigned long long>(playerGuid));
@@ -80,14 +82,15 @@ namespace Nampower {
}
// Trigger the event with spellId as parameter
((int (__cdecl *)(int, char *, char *, uint32_t, uint32_t, uint32_t, uint32_t)) Offsets::SignalEventParam)(
((int (__cdecl *)(int, char *, char *, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)) Offsets::SignalEventParam)(
eventToTrigger,
format,
guidStr,
luaUnitSlot,
spellId,
luaStacks,
auraLevels[slot]);
auraLevels[slot],
slot);
delete[] guidStr;
}
@@ -127,6 +130,40 @@ namespace Nampower {
TriggerAuraEvent(unit, slot, spellId, true);
}
void CGBuffBar_UpdateDurationHook(hadesmem::PatchDetourBase *detour, uint8_t auraSlot, int durationMs) {
auto const updateDuration = detour->GetTrampolineT<CGBuffBar_UpdateDurationT>();
// Store expiration time indexed by aura slot
if (auraSlot < MAX_AURA_SLOTS) {
auto now = static_cast<uint32_t>(GetWowTimeMs() & 0xFFFFFFFF);
uint32_t expirationTime = durationMs > 0 ? now + durationMs : 0;
gAuraExpirationTime[auraSlot] = expirationTime;
// Get player unit to read spellId from aura fields
auto playerGuid = game::ClntObjMgrGetActivePlayerGuid();
auto *playerUnit = game::GetObjectPtr(playerGuid);
if (playerUnit) {
auto *unitFields = *reinterpret_cast<game::UnitFields **>(playerUnit + 68);
uint32_t spellId = unitFields->aura[auraSlot];
bool isBuff = auraSlot < 32;
game::Events eventToTrigger = isBuff ? game::BUFF_UPDATE_DURATION_SELF : game::DEBUFF_UPDATE_DURATION_SELF;
static char format[] = "%d%d%d%d";
((int (__cdecl *)(int, char *, uint32_t, uint32_t, int, uint32_t)) Offsets::SignalEventParam)(
eventToTrigger,
format,
auraSlot,
spellId,
durationMs,
expirationTime);
}
}
// Call the original function
updateDuration(auraSlot, durationMs);
}
void UnitCombatLogUnitDeadHook(hadesmem::PatchDetourBase *detour, uint64_t guid) {
auto const unitCombatLogUnitDead = detour->GetTrampolineT<UnitCombatLogUnitDeadT>();
+6
View File
@@ -8,13 +8,19 @@
#include "main.hpp"
namespace Nampower {
constexpr int MAX_AURA_SLOTS = 48;
extern uint32_t gAuraExpirationTime[MAX_AURA_SLOTS];
using CGUnit_C_OnAuraRemovedT = void (__fastcall *)(uintptr_t *unit, void *dummy_edx,uint32_t slot, uint32_t spellId);
using CGUnit_C_OnAuraAddedT = void (__fastcall *)(uintptr_t *unit, void *dummy_edx,uint32_t slot, uint32_t spellId);
using CGUnit_C_OnAuraAddedStackT = void (__fastcall *)(uintptr_t *unit, int slot);
using UnitCombatLogUnitDeadT = void (__fastcall *)(uint64_t guid);
using CGBuffBar_UpdateDurationT = void (__fastcall *)(uint8_t auraSlot, int durationMs);
void CGUnit_C_OnAuraRemovedHook(hadesmem::PatchDetourBase *detour, uintptr_t *unit, void *dummy_edx, uint32_t slot, uint32_t spellId);
void CGUnit_C_OnAuraAddedHook(hadesmem::PatchDetourBase *detour, uintptr_t *unit, void *dummy_edx, uint32_t slot, uint32_t spellId);
void CGUnit_C_OnAuraAddedStackHook(hadesmem::PatchDetourBase *detour, uintptr_t *unit, int slot);
void UnitCombatLogUnitDeadHook(hadesmem::PatchDetourBase *detour, uint64_t guid);
void CGBuffBar_UpdateDurationHook(hadesmem::PatchDetourBase *detour, uint8_t auraSlot, int durationMs);
}
+3
View File
@@ -1556,6 +1556,9 @@ namespace game {
SPELL_ENERGIZE_BY_SELF = 577,
SPELL_ENERGIZE_BY_OTHER = 578,
SPELL_ENERGIZE_ON_SELF = 579,
BUFF_UPDATE_DURATION_SELF = 580,
DEBUFF_UPDATE_DURATION_SELF = 581,
};
enum TypeMask {
+12
View File
@@ -145,6 +145,7 @@ namespace Nampower {
std::unique_ptr<hadesmem::PatchDetour<CGUnit_C_OnAuraAddedT> > gCGUnit_C_OnAuraAddedDetour;
std::unique_ptr<hadesmem::PatchDetour<CGUnit_C_OnAuraAddedStackT> > gCGUnit_C_OnAuraAddedStackDetour;
std::unique_ptr<hadesmem::PatchDetour<UnitCombatLogUnitDeadT> > gUnitCombatLogUnitDeadDetour;
std::unique_ptr<hadesmem::PatchDetour<CGBuffBar_UpdateDurationT> > gCGBuffBar_UpdateDurationDetour;
std::unique_ptr<hadesmem::PatchDetour<InvalidFunctionPtrCheckT> > gInvalidFunctionPtrCheckDetour;
@@ -1385,6 +1386,8 @@ namespace Nampower {
&CGUnit_C_OnAuraAddedStackHook);
gUnitCombatLogUnitDeadDetour = createHook<UnitCombatLogUnitDeadT>(process, Offsets::UnitCombatLogUnitDead,
&UnitCombatLogUnitDeadHook);
gCGBuffBar_UpdateDurationDetour = createHook<CGBuffBar_UpdateDurationT>(process, Offsets::CGBuffBar_UpdateDuration,
&CGBuffBar_UpdateDurationHook);
gAttackRoundInfo_ReadPacketDetour = createHook<AttackRoundInfo_ReadPacketT>(process, Offsets::AttackRoundInfo_ReadPacket,
&AttackRoundInfo_ReadPacketHook);
gCSimpleFrame_GetNameDetour = createHook<LuaScriptT>(process, Offsets::CSimpleFrame_GetName,
@@ -1517,6 +1520,12 @@ namespace Nampower {
char SPELL_ENERGIZE_ON_SELF[] = "SPELL_ENERGIZE_ON_SELF";
addCustomEvent(game::SPELL_ENERGIZE_ON_SELF, SPELL_ENERGIZE_ON_SELF);
char BUFF_UPDATE_DURATION_SELF[] = "BUFF_UPDATE_DURATION_SELF";
addCustomEvent(game::BUFF_UPDATE_DURATION_SELF, BUFF_UPDATE_DURATION_SELF);
char DEBUFF_UPDATE_DURATION_SELF[] = "DEBUFF_UPDATE_DURATION_SELF";
addCustomEvent(game::DEBUFF_UPDATE_DURATION_SELF, DEBUFF_UPDATE_DURATION_SELF);
}
void FrameScript_CreateEventsHook(hadesmem::PatchDetourBase *detour, int param_1, uint32_t maxEventId) {
@@ -1661,6 +1670,9 @@ namespace Nampower {
char getAmmo[] = "GetAmmo";
RegisterLuaFunction(getAmmo, reinterpret_cast<uintptr_t *>(Script_GetAmmo));
char getPlayerAuraDuration[] = "GetPlayerAuraDuration";
RegisterLuaFunction(getPlayerAuraDuration, reinterpret_cast<uintptr_t *>(Script_GetPlayerAuraDuration));
}
void load() {
+1 -1
View File
@@ -25,7 +25,7 @@ namespace Nampower {
constexpr uint32_t DISENCHANT_QUALITY_PURPLE = 0x04; // Epic
constexpr uint32_t MAJOR_VERSION = 2;
constexpr uint32_t MINOR_VERSION = 29;
constexpr uint32_t MINOR_VERSION = 30;
constexpr uint32_t PATCH_VERSION = 0;
constexpr int32_t LUA_REGISTRYINDEX = -10000;
+36 -2
View File
@@ -9,6 +9,7 @@
#include "unit_fields.hpp"
#include "helper.hpp"
#include "lua_refs.hpp"
#include "auras.hpp"
#include <cstring>
namespace Nampower {
@@ -841,6 +842,41 @@ namespace Nampower {
return 1;
}
uint32_t Script_GetPlayerAuraDuration(uintptr_t *luaState) {
luaState = GetLuaStatePtr();
if (!lua_isnumber(luaState, 1)) {
lua_error(luaState, "Usage: GetPlayerAuraDuration(auraSlot)");
return 0;
}
auto auraSlot = static_cast<uint32_t>(lua_tonumber(luaState, 1));
if (auraSlot >= MAX_AURA_SLOTS) {
lua_pushnil(luaState);
return 1;
}
// Get spellId from player unit fields
auto playerGuid = game::ClntObjMgrGetActivePlayerGuid();
auto *playerUnit = game::GetObjectPtr(playerGuid);
if (!playerUnit) {
lua_pushnil(luaState);
return 1;
}
auto *unitFields = *reinterpret_cast<game::UnitFields **>(playerUnit + 68);
uint32_t spellId = unitFields->aura[auraSlot];
uint32_t expirationTime = gAuraExpirationTime[auraSlot];
auto now = static_cast<uint32_t>(GetWowTimeMs() & 0xFFFFFFFF);
int remainingDurationMs = expirationTime > now ? static_cast<int>(expirationTime - now) : 0;
lua_pushnumber(luaState, spellId);
lua_pushnumber(luaState, remainingDurationMs);
lua_pushnumber(luaState, expirationTime);
return 3;
}
uint32_t CSimpleFrame_GetNameHook(hadesmem::PatchDetourBase *detour, uintptr_t *luaState) {
luaState = GetLuaStatePtr();
@@ -885,8 +921,6 @@ namespace Nampower {
uint32_t guidHigh = frameObj[0x13b];
uint64_t guid = (static_cast<uint64_t>(guidHigh) << 32) | guidLow;
DEBUG_LOG(guid);
char guidStr[21] = {0};
std::snprintf(guidStr, sizeof(guidStr), "0x%016llX", static_cast<unsigned long long>(guid));
lua_pushstring(luaState, guidStr);
+2
View File
@@ -40,5 +40,7 @@ namespace Nampower {
bool RunQueuedScript(int priority);
uint32_t Script_GetPlayerAuraDuration(uintptr_t *luaState);
uint32_t CSimpleFrame_GetNameHook(hadesmem::PatchDetourBase *detour, uintptr_t *luaState);
}
+1
View File
@@ -191,6 +191,7 @@ enum class Offsets : std::uint32_t {
CastEventStringPtr = 0X00BE1A08, // unused event 540 0x21C
CGBuffBar__m_buffs = 0X00BC6040,
CGBuffBar_UpdateDuration = 0x004E4390,
GetBuffByIndex = 0X004E4430,
CGUnit_C_ClearCastingSpell = 0x0060d040,