Files
nampower/nampower/helper.hpp
T

131 lines
3.9 KiB
C++

//
// Created by pmacc on 9/21/2024.
//
#pragma once
#include "game.hpp"
#include "main.hpp"
namespace Nampower {
// Lua function pointers
extern lua_errorT lua_error;
extern lua_gettopT lua_gettop;
extern lua_settopT lua_settop;
extern lua_typeT lua_type;
extern lua_isstringT lua_isstring;
extern lua_isnumberT lua_isnumber;
extern lua_toflagT lua_toflag;
extern lua_tostringT lua_tostring;
extern lua_tonumberT lua_tonumber;
extern lua_pushnumberT lua_pushnumber;
extern lua_pushstringT lua_pushstring;
extern lua_pushbooleanT lua_pushboolean;
extern lua_pushnilT lua_pushnil;
extern lua_newtableT lua_newtable;
extern lua_settableT lua_settable;
extern luaL_refT luaL_ref;
extern lua_touserdataT lua_touserdata;
extern lua_rawgetiT lua_rawgeti;
extern luaL_unrefT luaL_unref;
// Lua 5.0 constants
#ifndef LUA_REFNIL
#define LUA_REFNIL (-2)
#endif
#ifndef LUA_TTABLE
#define LUA_TTABLE 5
#endif
// Lua helper function - lua_istable implementation
inline bool lua_istable(uintptr_t *luaState, int idx) {
return lua_type(luaState, idx) == LUA_TTABLE;
}
int32_t GetSpellSlotAndTypeForName(const char *spellName, uint32_t *spellType);
uint32_t GetSpellIdFromSpellName(const char *spellName);
uint32_t ConvertSpellIdToSpellSlot(uint32_t spellId, uint32_t bookType);
bool SpellIsOnGcd(const game::SpellRec *spell);
bool SpellIsChanneling(const game::SpellRec *spell);
bool SpellIsTargeting(const game::SpellRec *spell);
bool SpellIsOnSwing(const game::SpellRec *spell);
bool SpellIsAttackTradeskillOrEnchant(const game::SpellRec *spell);
bool SpellIsMounting(const game::SpellRec *spell);
bool IsTargetingTerrainSpell();
uint32_t GetGcdOrCooldownForSpell(uint32_t spellId);
uint32_t GetRemainingGcdOrCooldownForSpell(uint32_t spellId);
uint32_t GetRemainingCooldownForSpell(uint32_t spellId);
bool IsSpellOnCooldown(uint32_t spellId);
extern const char kNilGuidStr[];
char *ConvertGuidToString(uint64_t guid);
void FreeGuidString(char *str);
void PushGuidString(uintptr_t *luaState, uint64_t guid);
bool IsReadableMemory(const void *ptr, size_t size);
bool SafeReadMemory(const void *address, void *out, size_t size);
template <typename T>
inline bool SafeRead(const void *address, T &out) {
return SafeReadMemory(address, &out, sizeof(T));
}
uint64_t GetUnitGuidFromLuaParam(uintptr_t *luaState, int paramIndex);
uint64_t GetUnitGuidFromString(const char *unitToken);
float GetNameplateDistance();
void SetNameplateDistance(float distance);
// Lua table helper functions
inline void PushTableValue(uintptr_t *luaState, char *key, uint32_t value) {
lua_pushstring(luaState, key);
lua_pushnumber(luaState, value);
lua_settable(luaState, -3);
}
inline void PushTableValue(uintptr_t *luaState, char *key, uint64_t value) {
lua_pushstring(luaState, key);
lua_pushnumber(luaState, static_cast<double>(value));
lua_settable(luaState, -3);
}
inline void PushTableValue(uintptr_t *luaState, char *key, double value) {
lua_pushstring(luaState, key);
lua_pushnumber(luaState, value);
lua_settable(luaState, -3);
}
inline void PushTableValue(uintptr_t *luaState, char *key, int32_t value) {
lua_pushstring(luaState, key);
lua_pushnumber(luaState, value);
lua_settable(luaState, -3);
}
inline void PushTableValue(uintptr_t *luaState, char *key, char *value) {
lua_pushstring(luaState, key);
lua_pushstring(luaState, value);
lua_settable(luaState, -3);
}
inline void PushTableValue(uintptr_t *luaState, char *key, const char *value) {
lua_pushstring(luaState, key);
lua_pushstring(luaState, const_cast<char *>(value));
lua_settable(luaState, -3);
}
}