From f6c280fa1f006388ff06504b0bbc50e3115e9f23 Mon Sep 17 00:00:00 2001 From: Mats391 Date: Tue, 30 Dec 2025 17:13:52 +0100 Subject: [PATCH] Evaluating -1 bank as well --- nampower/item_scripts.cpp | 119 +++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 46 deletions(-) diff --git a/nampower/item_scripts.cpp b/nampower/item_scripts.cpp index 7dda723..3b1368e 100644 --- a/nampower/item_scripts.cpp +++ b/nampower/item_scripts.cpp @@ -894,26 +894,50 @@ namespace Nampower { auto const getContainerGuid = reinterpret_cast(Offsets::GetContainerGuid); auto const getBagItem = reinterpret_cast(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(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(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(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(Offsets::BankGuid); if (bankGuid > 0) { + lua_pushnumber(luaState, static_cast(-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(bagIndex));