fix bugs with GetBagItems and remove begin cast event

This commit is contained in:
avitasia
2026-01-02 16:41:39 -08:00
parent f7d8a0a002
commit 5573ce5f0c
10 changed files with 10085 additions and 10121 deletions
-18
View File
@@ -7,7 +7,6 @@ For custom Lua functions, see [SCRIPTS.md](SCRIPTS.md). For general usage inform
## Table of Contents
- [SPELL_QUEUE_EVENT](#spell_queue_event)
- [SPELL_CAST_EVENT](#spell_cast_event)
- [SPELL_BEGIN_CAST_EVENT](#spell_begin_cast_event)
- [SPELL_DAMAGE_EVENT_SELF and SPELL_DAMAGE_EVENT_OTHER](#spell_damage_event_self-and-spell_damage_event_other)
- [Buff/Debuff Events](#buffdebuff-events)
- [AURA_CAST_ON_SELF and AURA_CAST_ON_OTHER](#aura_cast_on_self-and-aura_cast_on_other)
@@ -91,23 +90,6 @@ Cursive:RegisterEvent("SPELL_CAST_EVENT", function(success, spellId, castType, t
end);
```
### SPELL_BEGIN_CAST_EVENT
Event you can register in game to get updates when the clien is about to attempt casting a spell. At this stage the spell is ready and has a valid target, but the spell cast might still be rejected based on line of sight or other factors.
The event is `SPELL_BEGIN_CAST_EVENT` and has 2 parameters:
1. int spellId
2. string targetGuid - guid string like "0xF5300000000000A5"
targetGuid will be “0x0000000000000000” if the spell requires no target
Example (uses ace RegisterEvent):
```
Cursive:RegisterEvent("SPELL_BEING_CAST_EVENT", function(spellId, targetGuid)
print(spellId)
print(targetGuid)
end);
```
### SPELL_DAMAGE_EVENT_SELF and SPELL_DAMAGE_EVENT_OTHER
New events you can register in game to get updates whenever spell damage occurs. SPELL_DAMAGE_EVENT_SELF will only trigger for damage you deal, while SPELL_DAMAGE_EVENT_OTHER will only trigger for damage dealt by others.
+4 -4
View File
@@ -192,7 +192,7 @@ Searches the player's inventory for an item by ID or name and returns its locati
- `0` = Inventory pack
- `1-4` = Regular bags
- `-1` = Bank item slots
- `5-9` = Bank bags
- `5-10` = Bank bags
- `-2` = Keyring
- 2nd param (number): Slot number within the bag (or equipment slot if 1st param is nil)
- For equipped items: 0-18 (equipment slots are 0-indexed)
@@ -200,7 +200,7 @@ Searches the player's inventory for an item by ID or name and returns its locati
- Bag 0: slots 1-16 (corresponding to absolute slots 23-38)
- Bag -1: slots 1-24 (corresponding to absolute bank slots 39-62)
- Bag -2: slots 1-16 (corresponding to absolute keyring slots 81-96)
- For regular bags (1-4) and bank bags (5-9): Returns 1-indexed slot within the bag
- For regular bags (1-4) and bank bags (5-10): Returns 1-indexed slot within the bag
- Returns `nil,nil` if the item is not found
**Examples:**
@@ -348,7 +348,7 @@ If no bagIndex is specified, the function returns a nested table reference conta
- 0 = Inventory pack (16 slots)
- 1-4 = Regular bags
- -1 = Bank item slots (24 slots, only if bank is open)
- 5-9 = Bank bags (only if bank is open)
- 5-10 = Bank bags (only if bank is open)
- -2 = Keyring
Item info table fields (same as GetEquippedItems for player):
@@ -399,7 +399,7 @@ Returns item info for a specific slot in a specific bag.
- 0 = Inventory pack
- 1-4 = Regular bags
- -1 = Bank item slots or buyback slots
- 5-9 = Bank bags (requires bank to be open)
- 5-10 = Bank bags (requires bank to be open)
- -2 = Keyring
- `slot` (number): **1-indexed** slot number within the bag
+10050 -10046
View File
File diff suppressed because it is too large Load Diff
-2
View File
@@ -1443,8 +1443,6 @@ namespace game {
AURA_CAST_ON_SELF = 560,
AURA_CAST_ON_OTHER = 561,
SPELL_BEGIN_CAST_EVENT = 562,
};
enum TypeMask {
+25 -24
View File
@@ -18,7 +18,7 @@ namespace Nampower {
static int trinketsTableRef = LUA_REFNIL;
static uint32_t lastTrinketCount = 0;
// Bag items table references (10 bags: 0-9, plus special indices for -1 bank, -2 keyring)
// Bag items table references (11 bags: 0-10, plus special indices for -1 bank, -2 keyring)
static std::array<int, MAX_BAGS> bagTableRefs{};
// Item entry table references: 2D matrix [bagIndex][slot] for direct mapping
@@ -110,8 +110,8 @@ namespace Nampower {
if (adjustedSlot < MAX_BAG_SLOTS) {
cachedData = &bagItemDataCache[KEYRING_CACHE_INDEX][adjustedSlot];
}
} else if (bagIndex >= 0 && bagIndex < 10 && adjustedSlot < MAX_BAG_SLOTS) {
// Regular bags (0-9)
} else if (bagIndex >= 0 && bagIndex <= 10 && adjustedSlot < MAX_BAG_SLOTS) {
// Regular bags (0-10)
cachedData = &bagItemDataCache[bagIndex][adjustedSlot];
}
@@ -179,8 +179,8 @@ namespace Nampower {
if (adjustedSlot < MAX_BAG_SLOTS) {
cachedData = &bagItemDataCache[KEYRING_CACHE_INDEX][adjustedSlot];
}
} else if (bagIndex >= 0 && bagIndex < 10) {
// Regular bag items (0-9)
} else if (bagIndex >= 0 && bagIndex <= 10) {
// Regular bag items (0-10)
if (adjustedSlot < MAX_BAG_SLOTS) {
cachedData = &bagItemDataCache[bagIndex][adjustedSlot];
}
@@ -211,7 +211,7 @@ namespace Nampower {
cacheIndexForTableRef = BANK_CACHE_INDEX;
} else if (bagIndex == -2) {
cacheIndexForTableRef = KEYRING_CACHE_INDEX;
} else if (bagIndex >= 0 && bagIndex < 10) {
} else if (bagIndex >= 0 && bagIndex <= 10) {
cacheIndexForTableRef = bagIndex;
}
@@ -487,7 +487,7 @@ namespace Nampower {
if (adjustedSlot < MAX_BAG_SLOTS) {
cachedData = &bagTrinketDataCache[KEYRING_CACHE_INDEX][adjustedSlot];
}
} else if (bagIndex >= 0 && bagIndex < 10) {
} else if (bagIndex >= 0 && bagIndex <= 10) {
if (adjustedSlot < MAX_BAG_SLOTS) {
cachedData = &bagTrinketDataCache[bagIndex][adjustedSlot];
}
@@ -534,7 +534,7 @@ namespace Nampower {
cacheIndexForTableRef = BANK_CACHE_INDEX;
} else if (bagIndex == KEYRING_BAG_INDEX) {
cacheIndexForTableRef = KEYRING_CACHE_INDEX;
} else if (bagIndex >= 0 && bagIndex < 10) {
} else if (bagIndex >= 0 && bagIndex <= 10) {
cacheIndexForTableRef = bagIndex;
}
@@ -843,14 +843,14 @@ namespace Nampower {
lua_error(luaState, "For bag -1, slot must be 1-24 (bank) or 31-42 (buyback) (Lua 1-indexed)");
return 0;
}
} else if (bagIndex >= 5 && bagIndex <= 9) {
} else if (bagIndex >= 5 && bagIndex <= 10) {
uint64_t bankGuid = *reinterpret_cast<uint64_t *>(Offsets::BankGuid);
if (bankGuid == 0) {
lua_error(luaState, "Bank is not open");
return 0;
}
uint64_t containerGuid = getContainerGuid(bagIndex-1);
uint64_t containerGuid = getContainerGuid(bagIndex-1); // bank bagIndex 5-10 maps to container 4-9
if (containerGuid == 0) {
lua_pushnil(luaState);
return 1;
@@ -882,7 +882,7 @@ namespace Nampower {
}
item = getBagItem(inventory, slot);
} else {
lua_error(luaState, "Invalid bag index. Valid values: 0, 1-4, -1, 5-9 (bank), -2 (keyring)");
lua_error(luaState, "Invalid bag index. Valid values: 0, 1-4, -1, 5-10 (bank), -2 (keyring)");
return 0;
}
@@ -899,11 +899,11 @@ namespace Nampower {
const auto player = game::GetObjectPtr(playerGuid);
const auto inventory = game::GetPlayerInventoryPtr(player);
GetTableRef(luaState, bagTableRefs[0]);
if (bagIndex == 0) {
for (uint32_t slot = 0; slot <= 16; slot++) {
uint32_t adjustedSlot = slot + 23; // Backbag goes from 23 to 39
GetTableRef(luaState, bagTableRefs[0]);
for (uint32_t slot = 0; slot <= 15; slot++) {
uint32_t adjustedSlot = slot + 23; // Backbag goes from 23 to 38
auto item = getBagItem(inventory, adjustedSlot);
if (item) {
PushBagCGItemToTable(luaState, 0, adjustedSlot, item);
@@ -917,13 +917,15 @@ namespace Nampower {
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;
GetTableRef(luaState, bagTableRefs[BANK_CACHE_INDEX]);
for (uint32_t slot = 0; slot <= 23; slot++) {
uint32_t adjustedSlot = slot + 39; // Bank backpack goes from 39 to 62
auto item = getBagItem(inventory, adjustedSlot);
if (item) {
PushBagCGItemToTable(luaState, -1, adjustedSlot, item);
@@ -975,12 +977,12 @@ namespace Nampower {
return 1;
}
if (bagIndex >= 5 && bagIndex <= 9) {
if (bagIndex >= 5 && bagIndex <= 10) {
uint64_t bankGuid = *reinterpret_cast<uint64_t *>(Offsets::BankGuid);
if (bankGuid <= 0) {
return 0;
}
uint64_t containerGuid = getContainerGuid(bagIndex - 1); // bagIndex 5-9 maps to container 4-8
uint64_t containerGuid = getContainerGuid(bagIndex - 1); // bagIndex 5-10 maps to container 4-9
if (containerGuid == 0) {
// Bag slot is empty, clear all cached items for this bag
GetTableRef(luaState, bagTableRefs[bagIndex]);
@@ -1017,7 +1019,7 @@ namespace Nampower {
return 1;
}
lua_error(luaState, "Invalid bag index. Valid values: 0, 1-4, -1, 5-9 (bank)");
lua_error(luaState, "Invalid bag index. Valid values: 0 (backpack), 1-4, -1 (bank backpack), 5-10 (bank)");
return 0;
}
@@ -1044,14 +1046,14 @@ namespace Nampower {
}
}
// Bank bags 5-9
// Bank bags 5-10
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++) {
for (int32_t bagIndex = 5; bagIndex <= 10; bagIndex++) {
const auto top = lua_gettop(luaState);
lua_pushnumber(luaState, static_cast<double>(bagIndex));
const auto bagResult = GetSingleBagItems(luaState, bagIndex);
@@ -1071,7 +1073,6 @@ namespace Nampower {
luaState = GetLuaStatePtr();
if (lua_gettop(luaState) == 1) {
if (!lua_isnumber(luaState, 1)) {
lua_error(luaState, "Bag index must be a number");
return 0;
+2 -2
View File
@@ -181,8 +181,8 @@ namespace Nampower {
}
}
for (int32_t bagIndex = 5; bagIndex <= 9; bagIndex++) {
uint64_t containerGuid = getContainerGuid(bagIndex - 1); // bagIndex 5-9 maps to container 4-8
for (int32_t bagIndex = 5; bagIndex <= 10; bagIndex++) {
uint64_t containerGuid = getContainerGuid(bagIndex - 1); // bagIndex 5-10 maps to container 4-9
if (containerGuid == 0) continue;
auto containerPtr = game::ClntObjMgrObjectPtr(game::TYPEMASK_CONTAINER, containerGuid);
+3 -3
View File
@@ -20,9 +20,9 @@ namespace Nampower {
constexpr int32_t KEYRING_BAG_INDEX = -2;
// Cache constants
constexpr uint32_t MAX_BAGS = 12; // 0-9 for regular bags, 10 for -1 (bank), 11 for -2 (keyring)
constexpr uint32_t BANK_CACHE_INDEX = 10;
constexpr uint32_t KEYRING_CACHE_INDEX = 11;
constexpr uint32_t MAX_BAGS = 13; // 0-10 for regular bags, 11 for -1 (bank), 12 for -2 (keyring)
constexpr uint32_t BANK_CACHE_INDEX = 11;
constexpr uint32_t KEYRING_CACHE_INDEX = 12;
constexpr uint32_t MAX_BAG_SLOTS = 64; // Increased to 64 for future-proofing
constexpr uint32_t MAX_EQUIPPED_SLOTS = 19;
-3
View File
@@ -1332,9 +1332,6 @@ namespace Nampower {
char SPELL_DAMAGE_EVENT_OTHER[] = "SPELL_DAMAGE_EVENT_OTHER";
addCustomEvent(game::SPELL_DAMAGE_EVENT_OTHER, SPELL_DAMAGE_EVENT_OTHER);
char SPELL_BEGIN_CAST_EVENT[] = "SPELL_BEGIN_CAST_EVENT";
addCustomEvent(game::SPELL_BEGIN_CAST_EVENT, SPELL_BEGIN_CAST_EVENT);
char DEBUFF_ADDED_SELF[] = "DEBUFF_ADDED_SELF";
addCustomEvent(game::DEBUFF_ADDED_SELF, DEBUFF_ADDED_SELF);
+1 -1
View File
@@ -36,7 +36,7 @@ namespace Nampower {
constexpr uint32_t MAJOR_VERSION = 2;
constexpr uint32_t MINOR_VERSION = 23;
constexpr uint32_t PATCH_VERSION = 2;
constexpr uint32_t PATCH_VERSION = 3;
constexpr int32_t LUA_REGISTRYINDEX = -10000;
constexpr int32_t LUA_GLOBALSINDEX = -10001;
-18
View File
@@ -107,21 +107,6 @@ namespace Nampower {
}
}
void
TriggerSpellBeginCastEvent(uint32_t spellId, std::uint64_t guid) {
char format[] = "%d%s";
char *guidStr = new char[21]; // 2 for 0x prefix, 18 for the number, and 1 for '\0'
std::snprintf(guidStr, 21, "0x%016llX", static_cast<unsigned long long>(guid));
((int (__cdecl *)(int, char *, uint32_t, char *)) Offsets::SignalEventParam)(
game::SPELL_BEGIN_CAST_EVENT, // SPELL_BEGIN_CAST_EVENT event we are adding
format,
spellId,
guidStr);
delete[] guidStr;
}
bool Spell_C_TargetSpellHook(hadesmem::PatchDetourBase *detour,
uint32_t *player,
uint32_t *spellId,
@@ -251,9 +236,6 @@ namespace Nampower {
}
gLastCastData.startTimeMs = currentTime;
TriggerSpellBeginCastEvent(cast->spellId, cast->unitTarget);
}
void CastQueuedNonGcdSpell() {