Evaluating -1 bank as well

This commit is contained in:
Mats391
2025-12-30 17:13:52 +01:00
parent 7ef1ab1030
commit f6c280fa1f
+73 -46
View File
@@ -894,26 +894,50 @@ namespace Nampower {
auto const getContainerGuid = reinterpret_cast<GetContainerGuidT>(Offsets::GetContainerGuid);
auto const getBagItem = reinterpret_cast<CGBag_C_GetItemAtSlotT>(Offsets::CGBag_C_GetItemAtSlot);
if (bagIndex == 0) {
if (bagIndex == 0 || bagIndex == -1) {
const auto playerGuid = game::ClntObjMgrGetActivePlayerGuid();
const auto player = game::GetObjectPtr(playerGuid);
const auto inventory = game::GetPlayerInventoryPtr(player);
GetTableRef(luaState, bagTableRefs[0]);
for (uint32_t slot = 23; slot <= 38; slot++) {
auto item = getBagItem(inventory, slot);
uint32_t adjustedSlot = slot - 0x17;
if (item) {
PushBagCGItemToTable(luaState, 0, slot, item);
} else {
// Check if item was removed from this slot
ClearBagSlot(luaState, 0, adjustedSlot);
if (bagIndex == 0) {
for (uint32_t slot = 0; slot <= 16; slot++) {
uint32_t adjustedSlot = slot + 23; // Backbag goes from 23 to 39
auto item = getBagItem(inventory, adjustedSlot);
if (item) {
PushBagCGItemToTable(luaState, 0, adjustedSlot, item);
} else {
// Check if item was removed from this slot
ClearBagSlot(luaState, 0, slot);
}
}
return 1;
}
if (bagIndex == -1) {
uint64_t bankGuid = *reinterpret_cast<uint64_t *>(Offsets::BankGuid);
if (bankGuid <= 0) {
return 0;
}
for (uint32_t slot = 0; slot <= 24; slot++) {
uint32_t adjustedSlot = slot + 39;
auto item = getBagItem(inventory, adjustedSlot);
if (item) {
PushBagCGItemToTable(luaState, -1, adjustedSlot, item);
}
else {
// Check if item was removed from this slot
ClearBagSlot(luaState, -1, slot);
}
}
return 1;
}
return 1;
}
if (bagIndex >= 1 && bagIndex <= 4) {
uint64_t containerGuid = getContainerGuid(bagIndex - 1); // bagIndex 1-4 maps to container 0-3
if (containerGuid == 0) {
@@ -953,45 +977,45 @@ namespace Nampower {
if (bagIndex >= 5 && bagIndex <= 9) {
uint64_t bankGuid = *reinterpret_cast<uint64_t *>(Offsets::BankGuid);
if (bankGuid > 0) {
uint64_t containerGuid = getContainerGuid(bagIndex - 1); // bagIndex 5-9 maps to container 4-8
if (containerGuid == 0) {
// Bag slot is empty, clear all cached items for this bag
GetTableRef(luaState, bagTableRefs[bagIndex]);
for (uint32_t slot = 0; slot < MAX_BAG_SLOTS; slot++) {
ClearBagSlot(luaState, bagIndex, slot);
}
lua_settable(luaState, -3);
return 1;
}
auto containerPtr = game::ClntObjMgrObjectPtr(game::TYPEMASK_CONTAINER, containerGuid);
if (!containerPtr) {
return 0;
}
auto bagPtr = GetBagPtrFromContainer(containerPtr);
if (!bagPtr) {
return 0;
}
if (bankGuid <= 0) {
return 0;
}
uint64_t containerGuid = getContainerGuid(bagIndex - 1); // bagIndex 5-9 maps to container 4-8
if (containerGuid == 0) {
// Bag slot is empty, clear all cached items for this bag
GetTableRef(luaState, bagTableRefs[bagIndex]);
auto bagSize = *bagPtr;
// Check all possible slots up to bag size
for (uint32_t slot = 0; slot < bagSize && slot < MAX_BAG_SLOTS; slot++) {
auto item = getBagItem(bagPtr, slot);
if (item) {
PushBagCGItemToTable(luaState, bagIndex, slot, item);
} else {
ClearBagSlot(luaState, bagIndex, slot);
}
for (uint32_t slot = 0; slot < MAX_BAG_SLOTS; slot++) {
ClearBagSlot(luaState, bagIndex, slot);
}
lua_settable(luaState, -3);
return 1;
}
}
auto containerPtr = game::ClntObjMgrObjectPtr(game::TYPEMASK_CONTAINER, containerGuid);
if (!containerPtr) {
return 0;
}
auto bagPtr = GetBagPtrFromContainer(containerPtr);
if (!bagPtr) {
return 0;
}
GetTableRef(luaState, bagTableRefs[bagIndex]);
auto bagSize = *bagPtr;
// Check all possible slots up to bag size
for (uint32_t slot = 0; slot < bagSize && slot < MAX_BAG_SLOTS; slot++) {
auto item = getBagItem(bagPtr, slot);
if (item) {
PushBagCGItemToTable(luaState, bagIndex, slot, item);
} else {
ClearBagSlot(luaState, bagIndex, slot);
}
}
return 1;
}
// TODO Error for not finding the bag
return 0;
@@ -1004,7 +1028,6 @@ namespace Nampower {
// Backpack (bag 0)
lua_pushnumber(luaState, static_cast<double>(0));
GetSingleBagItems(luaState, 0);
lua_settable(luaState, -3);
// Bags 1-4
@@ -1024,6 +1047,10 @@ namespace Nampower {
// Bank bags 5-9
uint64_t bankGuid = *reinterpret_cast<uint64_t*>(Offsets::BankGuid);
if (bankGuid > 0) {
lua_pushnumber(luaState, static_cast<double>(-1));
GetSingleBagItems(luaState, -1);
lua_settable(luaState, -3);
for (int32_t bagIndex = 5; bagIndex <= 9; bagIndex++) {
const auto top = lua_gettop(luaState);
lua_pushnumber(luaState, static_cast<double>(bagIndex));