mirror of
https://github.com/brues-code/nampower.git
synced 2026-10-23 21:00:49 +00:00
add getammo function
This commit is contained in:
@@ -1084,5 +1084,70 @@ namespace Nampower {
|
||||
return GetAllBagItems(luaState);
|
||||
}
|
||||
|
||||
uint32_t Script_GetAmmo(uintptr_t *luaState) {
|
||||
luaState = GetLuaStatePtr();
|
||||
|
||||
auto playerGuid = game::ClntObjMgrGetActivePlayerGuid();
|
||||
auto playerUnit = game::GetObjectPtr(playerGuid);
|
||||
|
||||
if (!playerUnit) {
|
||||
lua_pushnil(luaState);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get player fields pointer at byte offset 0xe68
|
||||
auto playerFields = *reinterpret_cast<uint8_t **>(reinterpret_cast<uint8_t *>(playerUnit) + 0xe68);
|
||||
if (!playerFields) {
|
||||
lua_pushnil(luaState);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get PLAYER_AMMO_ID at byte offset 0x102c from player fields
|
||||
auto ammoId = *reinterpret_cast<uint32_t *>(playerFields + 0x102c);
|
||||
if (ammoId == 0) {
|
||||
lua_pushnil(luaState);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Search player bags for the ammo item and sum stack counts
|
||||
auto const getBagItem = reinterpret_cast<CGBag_C_GetItemAtSlotT>(Offsets::CGBag_C_GetItemAtSlot);
|
||||
auto const getContainerGuid = reinterpret_cast<GetContainerGuidT>(Offsets::GetContainerGuid);
|
||||
auto inventory = game::GetPlayerInventoryPtr(playerUnit);
|
||||
|
||||
uint32_t totalCount = 0;
|
||||
|
||||
// Search backpack (absolute slots 23-38)
|
||||
for (uint32_t slot = 23; slot <= 38; slot++) {
|
||||
auto item = getBagItem(inventory, slot);
|
||||
if (item && game::GetItemId(item) == ammoId && item->itemFields) {
|
||||
totalCount += item->itemFields->stackCount;
|
||||
}
|
||||
}
|
||||
|
||||
// Search bags 1-4
|
||||
for (int32_t bagIndex = 1; bagIndex <= 4; bagIndex++) {
|
||||
uint64_t containerGuid = getContainerGuid(bagIndex - 1);
|
||||
if (containerGuid == 0) continue;
|
||||
|
||||
auto containerPtr = game::ClntObjMgrObjectPtr(game::TYPEMASK_CONTAINER, containerGuid);
|
||||
if (!containerPtr) continue;
|
||||
|
||||
auto bagPtr = GetBagPtrFromContainer(containerPtr);
|
||||
if (!bagPtr) continue;
|
||||
|
||||
auto bagSize = *bagPtr;
|
||||
for (uint32_t slot = 0; slot < bagSize; slot++) {
|
||||
auto item = getBagItem(bagPtr, slot);
|
||||
if (item && game::GetItemId(item) == ammoId && item->itemFields) {
|
||||
totalCount += item->itemFields->stackCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lua_pushnumber(luaState, static_cast<double>(ammoId));
|
||||
lua_pushnumber(luaState, static_cast<double>(totalCount));
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,4 +15,5 @@ namespace Nampower {
|
||||
uint32_t Script_GetEquippedItem(uintptr_t *luaState);
|
||||
uint32_t Script_GetBagItem(uintptr_t *luaState);
|
||||
uint32_t Script_GetBagItems(uintptr_t *luaState);
|
||||
uint32_t Script_GetAmmo(uintptr_t *luaState);
|
||||
}
|
||||
|
||||
@@ -1658,6 +1658,9 @@ namespace Nampower {
|
||||
|
||||
char getSpellIconTexture[] = "GetSpellIconTexture";
|
||||
RegisterLuaFunction(getSpellIconTexture, reinterpret_cast<uintptr_t *>(Script_GetSpellIconTexture));
|
||||
|
||||
char getAmmo[] = "GetAmmo";
|
||||
RegisterLuaFunction(getAmmo, reinterpret_cast<uintptr_t *>(Script_GetAmmo));
|
||||
}
|
||||
|
||||
void load() {
|
||||
|
||||
+1
-1
@@ -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 = 28;
|
||||
constexpr uint32_t MINOR_VERSION = 29;
|
||||
constexpr uint32_t PATCH_VERSION = 0;
|
||||
|
||||
constexpr int32_t LUA_REGISTRYINDEX = -10000;
|
||||
|
||||
Reference in New Issue
Block a user