mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-14 23:20:44 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46cae9d465 | ||
|
|
93360ce482 | ||
|
|
b879730dfb | ||
|
|
9cbf185b3c | ||
|
|
68f6a687cc | ||
|
|
2d5ecdc493 | ||
|
|
783ffd05bf | ||
|
|
f559eb4d07 | ||
|
|
2de7176b94 | ||
|
|
13008ab8aa | ||
|
|
0df8885045 | ||
|
|
8fa344a084 | ||
|
|
2612118ff6 | ||
|
|
76e40fec96 | ||
|
|
b72c52d9f7 | ||
|
|
1447317cd3 | ||
|
|
f293653837 | ||
|
|
ba1e12fca9 | ||
|
|
867478f410 | ||
|
|
caeb598b78 | ||
|
|
37ca209210 | ||
|
|
94c5eaafd2 | ||
|
|
3f09b3f883 | ||
|
|
9f640de74b | ||
|
|
67b968c36c | ||
|
|
f833aad769 | ||
|
|
b38673f51f | ||
|
|
f2161265be | ||
|
|
eefcbb17f2 | ||
|
|
599a65d80c | ||
|
|
228c5daa0f | ||
|
|
cc6953a530 |
@@ -109,5 +109,7 @@ jobs:
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: ${{ steps.ver.outputs.tag }}
|
||||
files: build/Release/ClassicAPI.dll
|
||||
files: |
|
||||
build/Release/ClassicAPI.dll
|
||||
build/Release/ClassicAPI.map
|
||||
generate_release_notes: true
|
||||
|
||||
@@ -7,46 +7,16 @@
|
||||
-- the only duration packet (SMSG_UPDATE_AURA_DURATION) is self-scoped to the
|
||||
-- aura-bearer, so an observing caster hears nothing (and on a mob the packet
|
||||
-- isn't even built). We can't hear the change, but we DO see the *triggering*
|
||||
-- cast, so C_UnitAuras.RegisterAuraDurationModifier mirrors the server's edit
|
||||
-- off that trigger.
|
||||
-- cast, so a registered rule mirrors the server's edit off that trigger.
|
||||
--
|
||||
-- A trigger is matched by exact spellID (stable across ranks -- these are the
|
||||
-- IDs the server binds its spell script to); the affected aura by
|
||||
-- SpellFamilyName + a family-flag overlap (rank-proof, exactly how the server
|
||||
-- scripts locate it). Flags below are from the client's Spell.dbc. When the
|
||||
-- trigger is a whole class of spells rather than a named ability,
|
||||
-- RegisterAuraDurationModifierByTrigger matches it by SpellFamilyName + school
|
||||
-- index instead (see Shadow Weaving below).
|
||||
--
|
||||
-- NOT included on purpose: Carnage's Rip/Rake refresh fires behind a
|
||||
-- server-side probability roll on Ferocious Bite. The client can't know the
|
||||
-- roll's outcome, so inferring it would show wrong timers. If you accept that,
|
||||
-- register it yourself, e.g. (DRUID = 7):
|
||||
-- C_UnitAuras.RegisterAuraDurationModifier(<ferociousBiteID>, 7, tonumber("800000",16), 108, "refresh") -- Rip
|
||||
-- C_UnitAuras.RegisterAuraDurationModifier(<ferociousBiteID>, 7, tonumber("1000",16), 494, "refresh") -- Rake
|
||||
-- Conflagrate's *full*-consume variant (other servers) removes Immolate
|
||||
-- outright; that clears the aura slot and ClassicAPI evicts it via the normal
|
||||
-- removal path, so the reduce rule below is harmless there and correct on
|
||||
-- Turtle (where Immolate keeps ticking with 3s shaved off).
|
||||
-- A trigger keyed to a whole class of spells (rather than a named ability) is
|
||||
-- registered from Lua with RegisterAuraDurationModifierByTrigger, matched by
|
||||
-- SpellFamilyName + school index (see Shadow Weaving below). Exact-spellID
|
||||
-- triggers are registered from C++ (Aura::Source::AddDurationMod): Turtle's
|
||||
-- Conflagrate -> Immolate and Molten Blast -> Flame Shock live in the DLL
|
||||
-- (src/turtle/DurationMods.cpp), as does Carnage, whose per-combo-point roll no
|
||||
-- rule can express (src/turtle/Carnage.cpp).
|
||||
|
||||
if TURTLE_WOW_VERSION then
|
||||
local WARLOCK, SHAMAN = 5, 11
|
||||
-- Lua 5.0 has no 0x hex literals; tonumber(hex, 16) keeps the flags readable.
|
||||
local IMMOLATE_FLAG = tonumber("4", 16) -- CF_WARLOCK_IMMOLATE (bit 2)
|
||||
local FLAMESHOCK_FLAG = tonumber("10000000", 16) -- CF_SHAMAN_FLAME_SHOCK (bit 28)
|
||||
|
||||
-- Conflagrate (all ranks) -> shave 3s off the caster's Immolate.
|
||||
local CONFLAGRATE = { 17962, 18930, 18931, 18932 }
|
||||
for i = 1, table.getn(CONFLAGRATE) do
|
||||
C_UnitAuras.RegisterAuraDurationModifier(CONFLAGRATE[i], WARLOCK, IMMOLATE_FLAG, 0, "reduce", 3)
|
||||
end
|
||||
|
||||
-- Molten Blast (all ranks) -> refresh the caster's Flame Shock to full.
|
||||
local MOLTEN_BLAST = { 36916, 36917, 36918, 36919, 36920, 36921 }
|
||||
for i = 1, table.getn(MOLTEN_BLAST) do
|
||||
C_UnitAuras.RegisterAuraDurationModifier(MOLTEN_BLAST[i], SHAMAN, FLAMESHOCK_FLAG, 0, "refresh")
|
||||
end
|
||||
end
|
||||
-- Shadow Weaving (priest): any shadow-school priest cast refreshes the caster's
|
||||
-- Shadow Vulnerability (15258, 15s, stacks to 5). The 1->5 stack changes fire
|
||||
-- OnAuraStacksChanged (already handled); the 5->5 refresh is the silent blind
|
||||
|
||||
@@ -7,19 +7,46 @@
|
||||
-- the cursor -- the same UnitPopup menu Blizzard's PlayerFrame / TargetFrame /
|
||||
-- PartyMemberFrame show on right-click. Lets a unit frame express its
|
||||
-- right-click menu purely as an attribute (e.g. type2 = "menu") instead of a
|
||||
-- hand-rolled OnClick handler.
|
||||
-- hand-rolled OnClick handler. pfUI's unit frames use exactly this path
|
||||
-- (api/unitframes.lua -> ClassicAPI_ToggleUnitMenu).
|
||||
--
|
||||
-- The unit -> menu-type resolution mirrors Blizzard's own generic resolver
|
||||
-- (TargetFrameDropDown_Initialize in FrameXML): self -> SELF, pet -> PET, a
|
||||
-- grouped player -> PARTY (whisper / inspect / trade / follow / promote / ...),
|
||||
-- any other player -> PLAYER (adds INVITE), anything else (NPC) ->
|
||||
-- RAID_TARGET_ICON. Vanilla's stock UI never wires a unit to the "RAID" menu
|
||||
-- (there are no clickable raid unit frames in 1.12), and PARTY carries the
|
||||
-- options players actually want on a grouped member, so grouped players (party
|
||||
-- or raid) use PARTY -- matching how pfUI drives its raid menu.
|
||||
-- RAID_TARGET_ICON (the raid-marker list). Vanilla's stock UI never wires a
|
||||
-- unit to the "RAID" menu (there are no clickable raid unit frames in 1.12),
|
||||
-- and PARTY carries the options players actually want on a grouped member, so
|
||||
-- grouped players (party or raid) use PARTY -- matching how pfUI drives its
|
||||
-- raid menu.
|
||||
--
|
||||
-- Focus / Clear Focus: we add one contextual entry -- "Set Focus" when the
|
||||
-- unit is not the current focus, "Clear Focus" when it is -- for every real,
|
||||
-- non-self unit, NPCs included. This is done entirely inside our own dropdown:
|
||||
-- no hooksecurefunc, and no mutation of Blizzard's shared UnitPopupMenus tables
|
||||
-- (so default frames and other addons are unaffected). Because
|
||||
-- UnitPopup_ShowMenu hardwires every button's click to UnitPopup_OnClick (which
|
||||
-- does not know our keys), we add the Focus button ourselves with our own func.
|
||||
-- To keep Cancel last, we show the standard menu MINUS its trailing Cancel,
|
||||
-- then append Focus and Cancel.
|
||||
--
|
||||
-- This also fixes NPCs opening no menu at all: an NPC resolves to the
|
||||
-- RAID_TARGET_ICON menu, whose entries UnitPopup_HideButtons hides entirely
|
||||
-- unless you are in a group and can place markers -- so solo the menu was
|
||||
-- empty and never opened. Appending Focus + Cancel ourselves guarantees the
|
||||
-- menu always opens (markers still show when they are allowed).
|
||||
--
|
||||
-- Backed by the DLL's FocusUnit / ClearFocus globals and the `focus` unit
|
||||
-- token (src/unit/Focus.cpp). Labels come from the localized SET_FOCUS /
|
||||
-- CLEAR_FOCUS globals (locales/*.lua).
|
||||
|
||||
local dropdown;
|
||||
|
||||
-- Scratch menu key we own, rebuilt each open as a copy of the resolved base
|
||||
-- menu with its trailing CANCEL removed. Kept out of Blizzard's tables so the
|
||||
-- stock menus are never mutated.
|
||||
local SCRATCH_MENU = "CLASSICAPI_UNITMENU";
|
||||
|
||||
local function EnsureDropdown()
|
||||
if not dropdown then
|
||||
dropdown = CreateFrame("Frame", "ClassicAPIUnitMenuDropDown", UIParent, "UIDropDownMenuTemplate");
|
||||
@@ -42,18 +69,57 @@ local function ResolveMenu(unit)
|
||||
return "RAID_TARGET_ICON";
|
||||
end
|
||||
|
||||
-- Append the contextual Focus / Clear Focus button for `unit`, with our own
|
||||
-- click func. Skipped for the player themselves (focusing yourself is a no-op).
|
||||
local function AddFocusButton(unit)
|
||||
if UnitIsUnit(unit, "player") then
|
||||
return;
|
||||
end
|
||||
local info = {};
|
||||
info.notCheckable = 1;
|
||||
if UnitExists("focus") and UnitIsUnit(unit, "focus") then
|
||||
info.text = CLEAR_FOCUS;
|
||||
info.func = function() ClearFocus(); end;
|
||||
else
|
||||
info.text = SET_FOCUS;
|
||||
info.func = function() FocusUnit(unit); end;
|
||||
end
|
||||
UIDropDownMenu_AddButton(info);
|
||||
end
|
||||
|
||||
local function AddCancelButton()
|
||||
local info = {};
|
||||
info.text = CANCEL;
|
||||
info.notCheckable = 1;
|
||||
info.func = function() end;
|
||||
UIDropDownMenu_AddButton(info);
|
||||
end
|
||||
|
||||
function ClassicAPI_ToggleUnitMenu(unit)
|
||||
if not unit or not UnitExists(unit) then
|
||||
return;
|
||||
end
|
||||
local which = ResolveMenu(unit);
|
||||
local name;
|
||||
if which == "RAID_TARGET_ICON" then
|
||||
name = RAID_TARGET_ICON;
|
||||
end
|
||||
local dd = EnsureDropdown();
|
||||
dd.initialize = function()
|
||||
UnitPopup_ShowMenu(dd, which, unit, name);
|
||||
dd.initialize = function(level)
|
||||
level = level or UIDROPDOWNMENU_MENU_LEVEL or 1;
|
||||
|
||||
if level > 1 then
|
||||
UnitPopup_ShowMenu(dd, which, unit);
|
||||
return;
|
||||
end
|
||||
|
||||
local base = UnitPopupMenus[which];
|
||||
local scratch = {};
|
||||
for _, value in ipairs(base) do
|
||||
if value ~= "CANCEL" then
|
||||
table.insert(scratch, value);
|
||||
end
|
||||
end
|
||||
UnitPopupMenus[SCRATCH_MENU] = scratch;
|
||||
UnitPopup_ShowMenu(dd, SCRATCH_MENU, unit);
|
||||
AddFocusButton(unit);
|
||||
AddCancelButton();
|
||||
end
|
||||
ToggleDropDownMenu(1, nil, dd, "cursor");
|
||||
end
|
||||
|
||||
@@ -25,6 +25,8 @@ EQUIPSET_EQUIP = "Anlegen";
|
||||
ERR_EQUIPMENT_MANAGER_BAGS_FULL = "Ausrüstungstausch fehlgeschlagen. Inventar ist voll.";
|
||||
ERR_EQUIPMENT_MANAGER_COMBAT_SWAP_S = "Einige Gegenstände des Sets '%s' können nicht gewechselt werden, da Ihr Euch im Kampf befindet.";
|
||||
ERR_EQUIPMENT_MANAGER_MISSING_ITEM_S = "Mindestens ein Teil des Sets '%s' fehlt und kann nicht ausgerüstet werden.";
|
||||
CLEAR_FOCUS = "Fokus löschen";
|
||||
SET_FOCUS = "Fokus setzen";
|
||||
FOCUSTARGET = "Ziel als Fokus festlegen";
|
||||
GEARSETS_POPUP_TEXT = "Setnamen eingeben (Max. 16 Zeichen):";
|
||||
ITEMS_VARIABLE_QUANTITY = "%d |4IGegenstand:Gegenstände;";
|
||||
@@ -73,6 +75,8 @@ MINUTES_SECONDS = "%.2d:%.2d";
|
||||
PAPERDOLL_EQUIPMENTMANAGER = "Ausrüstungsmanager";
|
||||
PAPERDOLL_NEWEQUIPMENTSET = "Neues Set";
|
||||
PERCENTAGE_STRING = "%d%%";
|
||||
SET_FRIENDNOTE_LABEL = "Notizen für %s eintragen:";
|
||||
SET_NOTE = "Notiz eintragen";
|
||||
SILVER_AMOUNT_SYMBOL = "S";
|
||||
SLASH_CLEARFOCUS1 = "/fokusaufheben";
|
||||
SLASH_CLEARFOCUS2 = "/clearfocus";
|
||||
|
||||
@@ -25,6 +25,8 @@ EQUIPSET_EQUIP = "Equip";
|
||||
ERR_EQUIPMENT_MANAGER_BAGS_FULL = "Equipment swap failed. Inventory is full.";
|
||||
ERR_EQUIPMENT_MANAGER_COMBAT_SWAP_S = "Some items from set %s cannot be swapped because you are in combat.";
|
||||
ERR_EQUIPMENT_MANAGER_MISSING_ITEM_S = "One or more items from set %s were missing and could not be equipped.";
|
||||
CLEAR_FOCUS = "Clear Focus";
|
||||
SET_FOCUS = "Set Focus";
|
||||
FOCUSTARGET = "Focus Target";
|
||||
GEARSETS_POPUP_TEXT = "Enter Set Name (Max 16 Characters):";
|
||||
GENERIC_FRACTION_STRING = "%d/%d";
|
||||
@@ -70,6 +72,8 @@ MINUTES_SECONDS = "%.2d:%.2d";
|
||||
PAPERDOLL_EQUIPMENTMANAGER = "Equipment Manager";
|
||||
PAPERDOLL_NEWEQUIPMENTSET = "New Set";
|
||||
PERCENTAGE_STRING = "%d%%";
|
||||
SET_FRIENDNOTE_LABEL = "Set Notes for %s:";
|
||||
SET_NOTE = "Set Note";
|
||||
SILVER_AMOUNT_SYMBOL = "s";
|
||||
SLASH_CLEARFOCUS1 = "/clearfocus";
|
||||
SLASH_CLEARFOCUS2 = "/clearfocus";
|
||||
|
||||
@@ -25,6 +25,8 @@ EQUIPSET_EQUIP = "Equipar";
|
||||
ERR_EQUIPMENT_MANAGER_BAGS_FULL = "No se ha podido cambiar el equipamiento. Inventario lleno.";
|
||||
ERR_EQUIPMENT_MANAGER_COMBAT_SWAP_S = "Algunos objetos del equipo %s no se cambiarán porque estás en combate.";
|
||||
ERR_EQUIPMENT_MANAGER_MISSING_ITEM_S = "Falta uno o más objetos del equipo %s y no se ha podido equipar.";
|
||||
CLEAR_FOCUS = "Quitar foco";
|
||||
SET_FOCUS = "Establecer foco";
|
||||
FOCUSTARGET = "Establecer objetivo";
|
||||
GEARSETS_POPUP_TEXT = "Nombra este equipamiento (Máx. 16 carac.):";
|
||||
ITEMS_VARIABLE_QUANTITY = "%d |4objeto:objetos;";
|
||||
@@ -73,6 +75,8 @@ MINUTES_SECONDS = "%.2d:%.2d";
|
||||
PAPERDOLL_EQUIPMENTMANAGER = "Gestor de equipamiento";
|
||||
PAPERDOLL_NEWEQUIPMENTSET = "Nuevo conjunto";
|
||||
PERCENTAGE_STRING = "%d%%";
|
||||
SET_FRIENDNOTE_LABEL = "Establecer nota para %s:";
|
||||
SET_NOTE = "Establecer nota";
|
||||
SILVER_AMOUNT_SYMBOL = "p";
|
||||
SLASH_CLEARFOCUS1 = "/quitarenfoque";
|
||||
SLASH_CLEARFOCUS2 = "/clearfocus";
|
||||
|
||||
@@ -25,6 +25,8 @@ EQUIPSET_EQUIP = "Equiper";
|
||||
ERR_EQUIPMENT_MANAGER_BAGS_FULL = "Échec de l'échange d'équipement. L'inventaire est plein.";
|
||||
ERR_EQUIPMENT_MANAGER_COMBAT_SWAP_S = "Certains objets de l'ensemble %s ne peuvent pas être échangés car vous êtes en combat.";
|
||||
ERR_EQUIPMENT_MANAGER_MISSING_ITEM_S = "Une ou plusieurs pièces de l'ensemble %s manquaient et n'ont pu être équipées.";
|
||||
CLEAR_FOCUS = "Effacer la focalisation";
|
||||
SET_FOCUS = "Définir la focalisation";
|
||||
FOCUSTARGET = "Définir la cible de focalisation";
|
||||
ITEMS_VARIABLE_QUANTITY = "%d |4objet:objets;";
|
||||
ITEMS_EQUIPPED = "%d |4objet:objets; équipés";
|
||||
@@ -73,6 +75,8 @@ MINUTES_SECONDS = "%.2d:%.2d";
|
||||
PAPERDOLL_EQUIPMENTMANAGER = "Gestionnaire d'équipement";
|
||||
PAPERDOLL_NEWEQUIPMENTSET = "Nouvel ensemble";
|
||||
PERCENTAGE_STRING = "%d%%";
|
||||
SET_FRIENDNOTE_LABEL = "Écrire une note pour %s :";
|
||||
SET_NOTE = "Écrire une note";
|
||||
SILVER_AMOUNT_SYMBOL = "a";
|
||||
SLASH_CLEARFOCUS1 = "/clearfocus";
|
||||
SLASH_CLEARFOCUS2 = "/annulerfocal";
|
||||
|
||||
@@ -25,6 +25,8 @@ EQUIPSET_EQUIP = "Надеть";
|
||||
ERR_EQUIPMENT_MANAGER_BAGS_FULL = "Не удалось заменить комплект обмундирования. Инвентарь переполнен.";
|
||||
ERR_EQUIPMENT_MANAGER_COMBAT_SWAP_S = "Некоторые предметы из набора \"%s\" не будут экипированы, поскольку вы участвуете в бою.";
|
||||
ERR_EQUIPMENT_MANAGER_MISSING_ITEM_S = "Недостает одного или более предметов из набора \"%s\".";
|
||||
CLEAR_FOCUS = "Отменить запоминание цели";
|
||||
SET_FOCUS = "Запомнить цель";
|
||||
FOCUSTARGET = "Запомнить цель";
|
||||
ITEMS_VARIABLE_QUANTITY = "%d |4предмет:предмета:предметов;";
|
||||
ITEMS_EQUIPPED = "%d |4предмет экипирован:предмета экипировано:предметов экипировано;";
|
||||
@@ -73,6 +75,8 @@ MINUTES_SECONDS = "%.2d:%.2d";
|
||||
PAPERDOLL_EQUIPMENTMANAGER = "Комплекты экипировки";
|
||||
PAPERDOLL_NEWEQUIPMENTSET = "Новый комплект";
|
||||
PERCENTAGE_STRING = "%d%%";
|
||||
SET_FRIENDNOTE_LABEL = "Заметка о |3-5(%s):";
|
||||
SET_NOTE = "Добавить заметку";
|
||||
SILVER_AMOUNT_SYMBOL = "с";
|
||||
SLASH_CLEARFOCUS1 = "/clearfocus";
|
||||
SLASH_CLEARFOCUS2 = "/сбросфокуса";
|
||||
|
||||
@@ -25,6 +25,8 @@ EQUIPSET_EQUIP = "装备";
|
||||
ERR_EQUIPMENT_MANAGER_BAGS_FULL = "装备更换失败。背包已满。";
|
||||
ERR_EQUIPMENT_MANAGER_COMBAT_SWAP_S = "装备方案%s中的某些物品不能在战斗中切换。";
|
||||
ERR_EQUIPMENT_MANAGER_MISSING_ITEM_S = "未找到套装方案%s中的一件或多件物品,无法装备。";
|
||||
CLEAR_FOCUS = "清除焦点";
|
||||
SET_FOCUS = "设置焦点";
|
||||
FOCUSTARGET = "设定焦点目标";
|
||||
ITEMS_VARIABLE_QUANTITY = "%d件物品";
|
||||
ITEMS_EQUIPPED = "已装备%d件物品";
|
||||
@@ -73,6 +75,8 @@ MINUTES_SECONDS = "%.2d:%.2d";
|
||||
PAPERDOLL_EQUIPMENTMANAGER = "装备管理";
|
||||
PAPERDOLL_NEWEQUIPMENTSET = "新的方案";
|
||||
PERCENTAGE_STRING = "%d%%";
|
||||
SET_FRIENDNOTE_LABEL = "为%s设置备注:";
|
||||
SET_NOTE = "设置备注";
|
||||
SILVER_AMOUNT_SYMBOL = "银";
|
||||
SLASH_CLEARFOCUS1 = "/clearfocus";
|
||||
SLASH_CLEARFOCUS2 = "/clearfocus";
|
||||
|
||||
@@ -25,6 +25,8 @@ EQUIPSET_EQUIP = "裝備";
|
||||
ERR_EQUIPMENT_MANAGER_BAGS_FULL = "裝備切換失敗。物品欄已滿。";
|
||||
ERR_EQUIPMENT_MANAGER_COMBAT_SWAP_S = "%s設定中的某些物品必須等到你脫離戰鬥後才能更換。";
|
||||
ERR_EQUIPMENT_MANAGER_MISSING_ITEM_S = "%s設定中的一個或多個物品未尋獲,因此無法裝備。";
|
||||
CLEAR_FOCUS = "清除專注目標";
|
||||
SET_FOCUS = "設定專注目標";
|
||||
FOCUSTARGET = "設定鎖定目標";
|
||||
ITEMS_VARIABLE_QUANTITY = "%d件物品";
|
||||
ITEMS_EQUIPPED = "裝備%d件物品";
|
||||
@@ -73,6 +75,8 @@ MINUTES_SECONDS = "%.2d:%.2d";
|
||||
PAPERDOLL_EQUIPMENTMANAGER = "裝備管理員";
|
||||
PAPERDOLL_NEWEQUIPMENTSET = "新設定";
|
||||
PERCENTAGE_STRING = "%d%%";
|
||||
SET_FRIENDNOTE_LABEL = "設定%s的註記:";
|
||||
SET_NOTE = "設定註記";
|
||||
SILVER_AMOUNT_SYMBOL = "銀";
|
||||
SLASH_CLEARFOCUS1 = "/clearfocus";
|
||||
SLASH_CLEARFOCUS2 = "/清除專注目標";
|
||||
|
||||
+6
-1
@@ -144,5 +144,10 @@ set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "ClassicAPI")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS
|
||||
"/OPT:REF /OPT:ICF /MERGE:.rdata=.text /MERGE:.pdata=.text /SECTION:.text,EWR /NODEFAULTLIB:MSVCRT"
|
||||
# /MAP emits build/Release/ClassicAPI.map — a linker-only output (no effect
|
||||
# on code layout) that maps `0001:offset` addresses from WoW's ERROR #132
|
||||
# crash dumps back to functions. Published as a build/release artifact so
|
||||
# any crash from a shipped DLL can be triaged exactly. (/OPT:ICF folds
|
||||
# identical functions, so a few map symbols share an address — harmless.)
|
||||
"/OPT:REF /OPT:ICF /MERGE:.rdata=.text /MERGE:.pdata=.text /SECTION:.text,EWR /NODEFAULTLIB:MSVCRT /MAP"
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
|
||||
| [Faction](docs/API.md#faction) | `C_Reputation.GetFactionDataByIndex`, `C_Reputation.GetFactionStandings`, `C_Reputation.GetLastStandingChange`, `C_Reputation.GetWatchedFactionData`, `C_Reputation.SetWatchedFactionByID`, `GetFactionIDByIndex`, `GetFactionInfoByID`, `GetFactionParentID` |
|
||||
| [Focus](docs/API.md#focus) | `ClearFocus`, `FocusUnit` |
|
||||
| [Frame](docs/API.md#frame) | `region:SetPoint("point")` (one-arg form), `region:SetSize`, `region:GetSize`, `region:IsMouseOver`, `region:GetRect`, `region:IsDragging`, `GetMouseFoci`, `frame:SetShown`, `frame:SetResizeBounds`, `frame:HookScript`, `frame:IsEventRegistered`, `frame:GetEffectiveAlpha`, `frame:SetAttribute`, `frame:SetAttributeNoHandler`, `frame:ClearAttribute`, `frame:GetAttribute`, `OnAttributeChanged` (script), `SetModernScriptArgs`, `GetModernScriptArgs` |
|
||||
| [FriendList](docs/API.md#friendlist) | `C_FriendList.IsWhoQueryPending`, `C_FriendList.SendWhoQueryByName` |
|
||||
| [FriendList](docs/API.md#friendlist) | `C_FriendList.GetFriendInfo`, `C_FriendList.GetFriendInfoByIndex`, `C_FriendList.GetNumFriends`, `C_FriendList.GetNumOnlineFriends`, `C_FriendList.GetNumWhoResults`, `C_FriendList.GetWhoInfo`, `C_FriendList.IsFriend`, `C_FriendList.IsIgnored`, `C_FriendList.IsIgnoredByGuid`, `C_FriendList.IsWhoQueryPending`, `C_FriendList.SendWhoQueryByName`, `C_FriendList.SetFriendNotes`, `C_FriendList.SetFriendNotesByIndex` |
|
||||
| [GameObject](docs/API.md#gameobject) | `C_GameObjectInfo.GetGameObjectInfoByID`, `C_GameObjectInfo.RequestLoadGameObjectByID`, `ClosestGameObjectPosition` |
|
||||
| [Glue](docs/API.md#glue) | `C_Glue.IsOnGlueScreen` |
|
||||
| [Gossip](docs/API.md#gossip) | `C_GossipInfo.CloseGossip`, `C_GossipInfo.GetActiveQuests`, `C_GossipInfo.GetAvailableQuests`, `C_GossipInfo.GetNumActiveQuests`, `C_GossipInfo.GetNumAvailableQuests`, `C_GossipInfo.GetNumOptions`, `C_GossipInfo.GetOptions`, `C_GossipInfo.GetText`, `C_GossipInfo.SelectActiveQuest`, `C_GossipInfo.SelectAvailableQuest`, `C_GossipInfo.SelectOption`, `C_GossipInfo.SelectOptionByIndex` |
|
||||
@@ -59,7 +59,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
|
||||
| [NewItems](docs/API.md#newitems) | `C_NewItems.ClearAll`, `C_NewItems.IsNewItem`, `C_NewItems.RemoveNewItem` |
|
||||
| [PlayerInfo](docs/API.md#playerinfo) | `C_PlayerInfo.CanUseItem`, `C_PlayerInfo.GetClass`, `C_PlayerInfo.GetName`, `C_PlayerInfo.GetRace`, `C_PlayerInfo.GetSex`, `C_PlayerInfo.GUIDIsCreature`, `C_PlayerInfo.GUIDIsGameObject`, `C_PlayerInfo.GUIDIsPet`, `C_PlayerInfo.GUIDIsPlayer`, `C_PlayerInfo.IsConnected` |
|
||||
| [Quest](docs/API.md#quest) | `C_QuestLog.GetNumQuestObjectives`, `C_QuestLog.GetQuestDetails`, `C_QuestLog.GetHeaderIndexForQuest`, `C_QuestLog.GetLogIndexForQuestID`, `C_QuestLog.GetQuestIDForLogIndex`, `C_QuestLog.GetTitleForQuestID`, `C_QuestLog.IsOnQuest`, `C_QuestLog.IsQuestDataCachedByID`, `C_QuestLog.IsUnitOnQuest`, `C_QuestLog.RequestLoadQuestByID`, `GetQuestLogLeaderBoardID` |
|
||||
| [Spell](docs/API.md#spell) | `C_Spell.CancelSpellByID`, `C_Spell.CastAtCursor`, `C_Spell.CastAtUnit`, `C_Spell.CastingInfo`, `C_Spell.ChannelInfo`, `C_Spell.DoesSpellExist`, `C_Spell.GetSchoolString`, `C_Spell.GetSpellCooldown`, `C_Spell.GetSpellDescription`, `C_Spell.GetSpellEffectMechanics`, `C_Spell.GetSpellInfo`, `C_Spell.GetSpellLevelInfo`, `C_Spell.GetSpellLink`, `C_Spell.GetSpellMechanicByID`, `C_Spell.GetSpellName`, `C_Spell.GetSpellPowerCost`, `C_Spell.GetSpellRadius`, `C_Spell.GetSpellReagents`, `C_Spell.GetSpellRequiredTargetLevel`, `C_Spell.GetSpellSubtext`, `C_Spell.GetSpellTexture`, `C_Spell.IsAutoAttackSpell`, `C_Spell.IsCurrentSpell`, `C_Spell.IsRangedAutoAttackSpell`, `C_Spell.IsSelfBuff`, `C_Spell.IsSpellHarmful`, `C_Spell.IsSpellHelpful`, `C_Spell.IsSpellInRange`, `C_Spell.IsSpellPassive`, `C_Spell.IsSpellUsable`, `C_Spell.SpellHasRange`, `C_Spell.UnitCastingInfo`, `C_Spell.UnitChannelInfo`, `CanDualWield`, `CancelSpellByName`, `CastSpellNoToggle`, `GetCraftSpellID`, `GetSpellBonusDamage`, `GetSpellBonusHealing`, `GetSpellInfo`, `GetSpellLink`, `GetSpellRadius`, `GetSpellRequiredTargetLevel`, `GetSpellSchool`, `IsHarmfulSpell`, `IsHelpfulSpell`, `IsPassiveSpell`, `IsPlayerSpell`, `IsSpellKnown`, `IsUsableSpell`, `SpellHasRange` |
|
||||
| [Spell](docs/API.md#spell) | `C_Spell.CancelSpellByID`, `C_Spell.CastAtCursor`, `C_Spell.CastAtUnit`, `C_Spell.CastingInfo`, `C_Spell.ChannelInfo`, `C_Spell.DoesSpellExist`, `C_Spell.GetSchoolString`, `C_Spell.GetSpellCooldown`, `C_Spell.GetSpellDescription`, `C_Spell.GetSpellDispelType`, `C_Spell.GetSpellEffectMechanics`, `C_Spell.GetSpellInfo`, `C_Spell.GetSpellLevelInfo`, `C_Spell.GetSpellLink`, `C_Spell.GetSpellMechanicByID`, `C_Spell.GetSpellName`, `C_Spell.GetSpellPowerCost`, `C_Spell.GetSpellRadius`, `C_Spell.GetSpellReagents`, `C_Spell.GetSpellRequiredTargetLevel`, `C_Spell.GetSpellSubtext`, `C_Spell.GetSpellTexture`, `C_Spell.IsAutoAttackSpell`, `C_Spell.IsCurrentSpell`, `C_Spell.IsNextMeleeSpell`, `C_Spell.IsRangedAutoAttackSpell`, `C_Spell.IsSelfBuff`, `C_Spell.IsSpellHarmful`, `C_Spell.IsSpellHelpful`, `C_Spell.IsSpellInRange`, `C_Spell.IsSpellPassive`, `C_Spell.IsSpellUsable`, `C_Spell.ResetsMeleeSwing`, `C_Spell.SpellHasRange`, `C_Spell.UnitCastingInfo`, `C_Spell.UnitChannelInfo`, `CanDualWield`, `CancelSpellByName`, `CastSpellNoToggle`, `GetCraftSpellID`, `GetSpellBonusDamage`, `GetSpellBonusHealing`, `GetSpellInfo`, `GetSpellLink`, `GetSpellRadius`, `GetSpellRequiredTargetLevel`, `GetSpellSchool`, `IsHarmfulSpell`, `IsHelpfulSpell`, `IsPassiveSpell`, `IsPlayerSpell`, `IsSpellKnown`, `IsUsableSpell`, `SpellHasRange` |
|
||||
| [SpellBook](docs/API.md#spellbook) | `C_SpellBook.GetCurrentLevelSpells`, `C_SpellBook.GetSkillLineName`, `C_SpellBook.GetSkillLineRank`, `C_SpellBook.GetSpellLevelLearned`, `C_SpellBook.GetSpellSkillLine`, `C_SpellBook.IsAutoAttackSpellBookItem`, `C_SpellBook.IsRangedAutoAttackSpellBookItem`, `FindSpellBookSlotByID` |
|
||||
| [State](docs/API.md#state) | `CancelShapeshiftForm`, `Dismount`, `GetMirrorTimerInfo`, `GetMirrorTimerProgress`, `GetShapeshiftFormID`, `IsAssistingRitual`, `IsFalling`, `IsIndoors`, `IsInGroup`, `IsInRaid`, `IsLoggedIn`, `IsMounted`, `IsOutdoors`, `IsStealthed`, `IsSwimming` |
|
||||
| [System](docs/API.md#system) | `CopyToClipboard`, `GetPhysicalScreenSize` |
|
||||
@@ -71,7 +71,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**.
|
||||
| [TradeSkillUI](docs/API.md#tradeskillui) | `C_TradeSkillUI.GetTradeSkillListLink`, `C_TradeSkillUI.GetCraftListLink`, `C_TradeSkillUI.GetTradeSkillListRecipes` |
|
||||
| [UIColor](docs/API.md#uicolor) | `C_UIColor.GetColors` |
|
||||
| [Unit](docs/API.md#unit) | `ClosestUnitPosition`, `GetUnitSpeed`, `UnitClassBase`, `UnitCreatureFamilyID`, `UnitCreatureTypeID`, `UnitDistanceSquared`, `UnitGUID`, `UnitHealthMissing`, `UnitInLineOfSight`, `UnitInRange`, `UnitIsAFK`, `UnitIsDND`, `UnitIsFeignDeath`, `UnitIsInMyGuild`, `UnitIsMinion`, `UnitIsOtherPlayersPet`, `UnitIsPet`, `UnitIsPossessed`, `UnitOwnerGUID`, `UnitPosition`, `UnitPower`, `UnitPowerMax`, `UnitPowerMissing`, `UnitPowerType`, `UnitRaceBase`, `UnitSpellHaste`, `UnitStandState`, `UnitSubName`, `UnitTokenFromGUID` |
|
||||
| [UnitAuras](docs/API.md#unitauras) | `C_UnitAuras.GetAuraDataByIndex`, `C_UnitAuras.GetAuraDataBySpellName`, `C_UnitAuras.GetAuraDispelTypeColor`, `C_UnitAuras.GetBuffDataByIndex`, `C_UnitAuras.GetDebuffDataByIndex`, `C_UnitAuras.GetPlayerAuraBySpellID`, `C_UnitAuras.GetUnitAuraBySpellID`, `C_UnitAuras.GetUnitAuras`, `C_UnitAuras.RegisterAuraDurationModifier`, `C_UnitAuras.RegisterAuraDurationModifierByTrigger`, `C_UnitAuras.RegisterComboDuration` |
|
||||
| [UnitAuras](docs/API.md#unitauras) | `C_UnitAuras.GetAuraDataByIndex`, `C_UnitAuras.GetAuraDataBySpellName`, `C_UnitAuras.GetAuraDispelTypeColor`, `C_UnitAuras.GetBuffDataByIndex`, `C_UnitAuras.GetDebuffDataByIndex`, `C_UnitAuras.GetPlayerAuraBySpellID`, `C_UnitAuras.GetUnitAuraBySpellID`, `C_UnitAuras.GetUnitAuras`, `C_UnitAuras.RegisterAuraDurationModifierByTrigger`, `C_UnitAuras.RegisterComboDuration` |
|
||||
| [VoiceChat](docs/API.md#voicechat) | `C_VoiceChat.GetTtsVoices`, `C_VoiceChat.GetRemoteTtsVoices`, `C_VoiceChat.SpeakText`, `C_VoiceChat.StopSpeakingText`, `C_TTSSettings.GetSpeechRate`, `C_TTSSettings.GetSpeechVolume`, `C_TTSSettings.GetSpeechVoiceID`, `C_TTSSettings.GetVoiceOptionName`, `C_TTSSettings.SetSpeechRate`, `C_TTSSettings.SetSpeechVolume`, `C_TTSSettings.SetVoiceOption`, `C_TTSSettings.SetVoiceOptionByName`, `C_TTSSettings.SetDefaultSettings`, `C_TTSSettings.RefreshVoices` |
|
||||
| [XMLUtil](docs/API.md#xmlutil) | `C_XMLUtil.DoesTemplateExist`, `C_XMLUtil.GetTemplateInfo`, `C_XMLUtil.GetTemplates` |
|
||||
|
||||
|
||||
+446
-163
@@ -131,6 +131,7 @@ build instructions.
|
||||
- [`UNIT_FACTION` event (fire-coverage fix)](#unit_faction-event-fire-coverage-fix)
|
||||
- [`UPDATE_MOUSEOVER_UNIT` event (loss-fire fix)](#update_mouseover_unit-event-loss-fire-fix)
|
||||
- [`UPDATE_SHAPESHIFT_FORM` event](#update_shapeshift_form-event)
|
||||
- [`UNIT_SPELLCAST_*` events](#unit_spellcast_-events)
|
||||
|
||||
- [Expansion](#expansion)
|
||||
- [`GetClassicExpansionLevel()`](#getclassicexpansionlevel)
|
||||
@@ -171,6 +172,17 @@ build instructions.
|
||||
- [FriendList](#friendlist)
|
||||
- [`C_FriendList.SendWhoQueryByName(name)`](#c_friendlistsendwhoquerybynamename)
|
||||
- [`C_FriendList.IsWhoQueryPending()`](#c_friendlistiswhoquerypending)
|
||||
- [`C_FriendList.GetNumWhoResults()`](#c_friendlistgetnumwhoresults)
|
||||
- [`C_FriendList.GetWhoInfo(index)`](#c_friendlistgetwhoinfoindex)
|
||||
- [`C_FriendList.IsFriend(guid)`](#c_friendlistisfriendguid)
|
||||
- [`C_FriendList.IsIgnored(token)`](#c_friendlistisignoredtoken)
|
||||
- [`C_FriendList.IsIgnoredByGuid(guid)`](#c_friendlistisignoredbyguidguid)
|
||||
- [`C_FriendList.GetNumFriends()`](#c_friendlistgetnumfriends)
|
||||
- [`C_FriendList.GetNumOnlineFriends()`](#c_friendlistgetnumonlinefriends)
|
||||
- [`C_FriendList.GetFriendInfo(name)`](#c_friendlistgetfriendinfoname)
|
||||
- [`C_FriendList.GetFriendInfoByIndex(index)`](#c_friendlistgetfriendinfobyindexindex)
|
||||
- [`C_FriendList.SetFriendNotes(name, notes)`](#c_friendlistsetfriendnotesname-notes)
|
||||
- [`C_FriendList.SetFriendNotesByIndex(index, notes)`](#c_friendlistsetfriendnotesbyindexindex-notes)
|
||||
|
||||
- [GameObject](#gameobject)
|
||||
- [`C_GameObjectInfo.GetGameObjectInfoByID(gameObjectID)`](#c_gameobjectinfogetgameobjectinfobyidgameobjectid)
|
||||
@@ -418,6 +430,7 @@ build instructions.
|
||||
- [`C_Spell.GetSpellDescription(spellID)`](#c_spellgetspelldescriptionspellid)
|
||||
- [`C_Spell.GetSpellMechanicByID(spellID)`](#c_spellgetspellmechanicbyidspellid)
|
||||
- [`C_Spell.GetSpellEffectMechanics(spellID)`](#c_spellgetspelleffectmechanicsspellid)
|
||||
- [`C_Spell.GetSpellDispelType(spellID)`](#c_spellgetspelldispeltypespellid)
|
||||
- [`C_Spell.GetSpellRadius(spellID)` / `GetSpellRadius(slot, bookType)`](#c_spellgetspellradiusspellid--getspellradiusslot-booktype)
|
||||
- [`C_Spell.GetSpellPowerCost(spellIdentifier)`](#c_spellgetspellpowercostspellidentifier)
|
||||
- [`C_Spell.GetSpellReagents(spellID)`](#c_spellgetspellreagentsspellid)
|
||||
@@ -438,6 +451,8 @@ build instructions.
|
||||
- [`C_Spell.IsSpellInRange(spellIdentifier, targetUnit)`](#c_spellisspellinrangespellidentifier-targetunit)
|
||||
- [`C_Spell.IsAutoAttackSpell(spellID)`](#c_spellisautoattackspellspellid)
|
||||
- [`C_Spell.IsRangedAutoAttackSpell(spellID)`](#c_spellisrangedautoattackspellspellid)
|
||||
- [`C_Spell.IsNextMeleeSpell(spellID)`](#c_spellisnextmeleespellspellid)
|
||||
- [`C_Spell.ResetsMeleeSwing(spellID)`](#c_spellresetsmeleeswingspellid)
|
||||
- [`IsHarmfulSpell(spell)` / `IsHelpfulSpell(spell)`](#isharmfulspellspell--ishelpfulspellspell)
|
||||
- [`C_Spell.IsSpellHarmful(spellID)` / `C_Spell.IsSpellHelpful(spellID)`](#c_spellisspellharmfulspellid--c_spellisspellhelpfulspellid)
|
||||
- [`GetSpellSchool(spellID)`](#getspellschoolspellid)
|
||||
@@ -447,7 +462,6 @@ build instructions.
|
||||
- [`C_Spell.CancelSpellByID(spellID)` / `CancelSpellByName(name)`](#c_spellcancelspellbyidspellid--cancelspellbynamename)
|
||||
- [`C_Spell.UnitCastingInfo(unit)` / `C_Spell.CastingInfo()`](#c_spellunitcastinginfounit--c_spellcastinginfo)
|
||||
- [`C_Spell.UnitChannelInfo(unit)` / `C_Spell.ChannelInfo()`](#c_spellunitchannelinfounit--c_spellchannelinfo)
|
||||
- [`UNIT_SPELLCAST_*` events (player)](#unit_spellcast_-events-player)
|
||||
- [`C_Spell.GetSpellLevelInfo(spellID)`](#c_spellgetspelllevelinfospellid)
|
||||
- [`GetSpellRequiredTargetLevel(spellID)`](#getspellrequiredtargetlevelspellid)
|
||||
|
||||
@@ -564,7 +578,7 @@ build instructions.
|
||||
- [`C_UnitAuras.GetPlayerAuraBySpellID(spellID)`](#c_unitaurasgetplayeraurabyspellidspellid)
|
||||
- [`C_UnitAuras.GetAuraDataBySpellName(unit, spellName [, filter])`](#c_unitaurasgetauradatabyspellnameunit-spellname--filter)
|
||||
- [`C_UnitAuras.RegisterComboDuration(spellID, baseSeconds, maxSeconds)`](#c_unitaurasregistercombodurationspellid-baseseconds-maxseconds)
|
||||
- [`C_UnitAuras.RegisterAuraDurationModifier(triggerSpellID, affectedFamily, affectedFamilyFlags, affectedIcon, op [, valueSeconds])`](#c_unitaurasregisterauradurationmodifiertriggerspellid-affectedfamily-affectedfamilyflags-affectedicon-op--valueseconds)
|
||||
- [`C_UnitAuras.RegisterAuraDurationModifierByTrigger(triggerFamily, triggerSchool, affectedFamily, affectedFamilyFlags, affectedIcon, op [, valueSeconds])`](#c_unitaurasregisterauradurationmodifierbytriggertriggerfamily-triggerschool-affectedfamily-affectedfamilyflags-affectedicon-op--valueseconds)
|
||||
- [`C_UnitAuras.GetUnitAuras(unit [, filter])`](#c_unitaurasgetunitaurasunit--filter)
|
||||
- [`C_UnitAuras.GetAuraDispelTypeColor(dispelName)`](#c_unitaurasgetauradispeltypecolordispelname)
|
||||
|
||||
@@ -3230,6 +3244,131 @@ The cached "last form" sentinel uses `-1` for "player descriptor not
|
||||
yet resolvable" so transient resolution failures during early login
|
||||
don't get misread as leaving a form.
|
||||
|
||||
### `UNIT_SPELLCAST_*` events
|
||||
|
||||
Backport of the TBC+ cast/channel events to 1.12, for the **local player and
|
||||
other units**. Ported cast-bar / rotation addons (anything written against
|
||||
the modern signature) register these instead of vanilla's arg-less
|
||||
`SPELLCAST_*` events and read `unit, castGUID, spellID` directly. Thirteen
|
||||
events are provided; six also fire for non-player units:
|
||||
|
||||
| Event | Fires when | Units | Args |
|
||||
|-------|-----------|-------|------|
|
||||
| `UNIT_SPELLCAST_SENT` | `CMSG_CAST_SPELL` leaves the client (earliest point) | player | `unit, target, castGUID, spellID, spellName, rank` |
|
||||
| `UNIT_SPELLCAST_START` | a cast-time spell begins | all | `unit, castGUID, spellID, spellName, rank` |
|
||||
| `UNIT_SPELLCAST_STOP` | a cast-time spell ends (any reason) | all | same |
|
||||
| `UNIT_SPELLCAST_DELAYED` | pushback extends the cast | player | same |
|
||||
| `UNIT_SPELLCAST_SUCCEEDED` | the spell goes off (`SMSG_SPELL_GO`) — incl. instants | all | same |
|
||||
| `UNIT_SPELLCAST_INTERRUPTED` | a started **cast** is interrupted (kick, movement, LoS) — never for channels | all | same |
|
||||
| `UNIT_SPELLCAST_FAILED` | a cast is rejected before it starts (range, mana, cooldown) with an error shown | player | same |
|
||||
| `UNIT_SPELLCAST_FAILED_QUIET` | a cast fails with **no** error shown (spammy retry, reticle cancel, …) | player | same |
|
||||
| `UNIT_SPELLCAST_CHANNEL_START` | a channel begins | all | same |
|
||||
| `UNIT_SPELLCAST_CHANNEL_UPDATE` | pushback shortens a channel | player | same |
|
||||
| `UNIT_SPELLCAST_CHANNEL_STOP` | a channel ends | all | same |
|
||||
| `UNIT_SPELLCAST_RETICLE_TARGET` | a ground-target reticle appears (AoE placement — Blizzard, Flare, …) | player | `unit, "", spellID, spellName, rank` |
|
||||
| `UNIT_SPELLCAST_RETICLE_CLEAR` | the reticle is placed or cancelled | player | `unit, "", spellID, spellName, rank` |
|
||||
|
||||
`unit` (arg1) is the token of the casting unit — `"player"` for your own
|
||||
casts, or a unit token (`"target"`, `"focus"`, `"party3"`, `"nameplate2"`,
|
||||
`"pet"`, `"mouseover"`, …) for another unit. `spellName` / `rank` are
|
||||
ClassicAPI tail extensions (modern stops at `spellID`); addons reading only
|
||||
the first three positional args are unaffected.
|
||||
|
||||
**Per-token fan-out.** A caster GUID can map to several tokens at once (your
|
||||
`target` is also `party2` and `nameplate1`). Like retail, the event fires
|
||||
**once per token** currently pointing at the caster, so a `target`-frame
|
||||
cast bar, a `party2` frame, and a nameplate cast bar each get their own
|
||||
event with the same castGUID. Tokens are resolved fresh at fire time (they
|
||||
shift frame-to-frame). If you run **SuperWoW**, its raw-GUID token (`"0x…"`)
|
||||
is deliberately filtered out — only standard tokens are fanned out.
|
||||
|
||||
**Non-player limits.** Only the six events above fire for other units, and
|
||||
they're **best-effort** — driven purely by the packets an observer receives:
|
||||
- `SENT` never fires (only your own outgoing casts are visible).
|
||||
- `DELAYED` / `CHANNEL_UPDATE` never fire (pushback is sent only to the
|
||||
caster, so another unit's bar can't stretch/shrink from damage).
|
||||
- `FAILED` never fires (a pre-cast requirement failure is client-local).
|
||||
- A remote cast/channel only has timing from the moment its
|
||||
`SMSG_SPELL_START` was observed; casters who were already casting when
|
||||
they came into range have no start time.
|
||||
|
||||
**Channels never fire `INTERRUPTED`.** Retail emits only `CHANNEL_STOP` when a
|
||||
channel ends, whether it completed or was cut short (verified against retail),
|
||||
so ClassicAPI matches that for both the player and other units. `INTERRUPTED`
|
||||
is a cast-only event.
|
||||
|
||||
**Reticle events** fire for ground-targeted (AoE) spells only, always for the
|
||||
player: `RETICLE_TARGET` when the placement reticle comes up, `RETICLE_CLEAR`
|
||||
when it's placed or cancelled. There's no cast yet, so the castGUID slot
|
||||
(arg2) is empty — retail pushes `nil` there, but the engine's event
|
||||
dispatcher can't emit a `nil` mid-argument-list, so ClassicAPI pushes `""`
|
||||
instead. `unit` (arg1) and `spellID` (arg3) are exact; arg2 is the only
|
||||
difference and is inconsequential for a reticle.
|
||||
|
||||
**castGUID.** A synthesized string in the modern shape
|
||||
`Cast-<type>-<serverID>-<instanceID>-<zoneUID>-<spellID>-<castUID>`. Vanilla
|
||||
can't know server / instance / zone, so those three fields are `0`; the
|
||||
load-bearing parts are the `spellID` (field 6, which addons `strsplit("-")`
|
||||
out) and a unique-per-cast `castUID` (field 7). **Every event of one cast
|
||||
carries the same castGUID**, so `SENT` → `START`/`CHANNEL_START` →
|
||||
`SUCCEEDED` → `STOP`/`CHANNEL_STOP` all pair up — including across the caster
|
||||
and observers (they converge on the same value), and a chained same-spell
|
||||
recast gets its own castUID. The `type` and `castUID` follow the
|
||||
[spell-cast-GUID spec](https://warcraft.wiki.gg/wiki/GUID#Cast):
|
||||
- **Type 3** (real casts — the common case): `castUID` is time-based — the
|
||||
low 23 bits are the cast's UNIX-epoch second, the higher bits a per-second
|
||||
counter.
|
||||
- **Type 2** (`UNIT_SPELLCAST_FAILED` — a local-only cast that never reached
|
||||
the server): `castUID` is a plain locally-incrementing integer.
|
||||
|
||||
**Ordering** matches modern:
|
||||
|
||||
- Cast-time spell: `SENT → START → SUCCEEDED → STOP`.
|
||||
- Channel: `SENT → CHANNEL_START → SUCCEEDED → CHANNEL_STOP` (CHANNEL_START
|
||||
before SUCCEEDED, as on retail).
|
||||
- Instant: `SENT → SUCCEEDED`.
|
||||
|
||||
**INTERRUPTED vs FAILED vs FAILED_QUIET** follow modern's split: a spell that
|
||||
never started (out of range, not enough mana, on cooldown, LoS to a target)
|
||||
fires `FAILED`, except for a fixed whitelist of "quiet" `SpellCastResult`
|
||||
codes that fire `FAILED_QUIET` instead — `SPELL_IN_PROGRESS` (casting while
|
||||
already casting / a spell-queue rejection), `DONT_REPORT` (fake fails, a
|
||||
cancelled ground reticle), and `CHARMED`. That whitelist mirrors the 3.3.5
|
||||
client's own unit-spellcast dispatch, mapped to vanilla's `SpellCastResult`
|
||||
enum. A spell that was *already casting* and gets stopped (an enemy kick,
|
||||
moving to cancel, breaking LoS mid-cast) fires `INTERRUPTED`. Holding
|
||||
the cast key while running fires `INTERRUPTED` repeatedly (once per retry),
|
||||
each reusing the interrupted cast's castGUID — matching retail.
|
||||
|
||||
**Channel pushback (player).** Taking damage while channeling shortens the
|
||||
channel in vanilla; `CHANNEL_UPDATE` fires on each hit and
|
||||
[`C_Spell.UnitChannelInfo`](#c_spellunitchannelinfounit--c_spellchannelinfo)'s
|
||||
`endTimeMs` re-anchors to the server's new remaining time, so cast bars
|
||||
shrink correctly. (The event carries no time — like retail it's a "re-read
|
||||
now" trigger; timing is read back from `UnitChannelInfo`.)
|
||||
|
||||
Every fire is gated on whether any frame is registered for that event, so
|
||||
the whole system costs one pointer-compare per state transition when no
|
||||
addon uses it (no arg synthesis, no DBC lookups, no per-token fan-out).
|
||||
|
||||
```lua
|
||||
local f = CreateFrame("Frame")
|
||||
for _, e in ipairs({
|
||||
"UNIT_SPELLCAST_START", "UNIT_SPELLCAST_STOP",
|
||||
"UNIT_SPELLCAST_SUCCEEDED", "UNIT_SPELLCAST_CHANNEL_START",
|
||||
}) do f:RegisterEvent(e) end
|
||||
f:SetScript("OnEvent", function()
|
||||
-- vanilla passes event/arg1/... as globals, not function params
|
||||
if arg1 == "target" then print(event, arg3) end -- arg3 = spellID
|
||||
end)
|
||||
```
|
||||
|
||||
> **Additive to the vanilla `SPELLCAST_*` events.** The engine's own arg-less
|
||||
> `SPELLCAST_START` / `SPELLCAST_CHANNEL_UPDATE` / … still fire as before;
|
||||
> these `UNIT_`-prefixed events are the modern layer on top. The empowered-cast
|
||||
> events (`UNIT_SPELLCAST_EMPOWER_*`, a Dragonflight addition) are not
|
||||
> implemented — vanilla has no empowered casts.
|
||||
|
||||
## Expansion
|
||||
|
||||
Helpers shipped by modern Classic Era / Cata Classic for addons that
|
||||
@@ -4058,6 +4197,226 @@ contribute to the same pending window. This is acceptable for the
|
||||
addons that need per-call tracking should manage their own ticket
|
||||
state on top.
|
||||
|
||||
### `C_FriendList.GetNumWhoResults()`
|
||||
|
||||
Returns two numbers: how many /who results you can read, and a
|
||||
server-reported count.
|
||||
|
||||
```lua
|
||||
local shown, serverCount = C_FriendList.GetNumWhoResults()
|
||||
```
|
||||
|
||||
`shown` is the number of entries you can index with
|
||||
[`GetWhoInfo`](#c_friendlistgetwhoinfoindex). The server caps the list
|
||||
(50, or 49 on some cores), so `shown` is at most that. Run a `/who` (or
|
||||
[`SendWhoQueryByName`](#c_friendlistsendwhoquerybynamename)) first to
|
||||
populate the list.
|
||||
|
||||
`serverCount` is the second header value the server sends, and its
|
||||
meaning depends on the server core:
|
||||
|
||||
- Mangos and cmangos derived cores send the number of characters that
|
||||
matched your query.
|
||||
- Turtle WoW (tortoise-wow) sends the whole realm's online population
|
||||
when more than 49 players are online, ignoring your filter. Below
|
||||
that count it sends the match count.
|
||||
|
||||
Do not rely on one meaning across servers. On Turtle it is a live
|
||||
population counter for any query. On other cores it is a match total.
|
||||
|
||||
### `C_FriendList.GetWhoInfo(index)`
|
||||
|
||||
Returns a table for the /who result at `index` (1-based), or `nil` when
|
||||
the index is out of range.
|
||||
|
||||
```lua
|
||||
local info = C_FriendList.GetWhoInfo(1)
|
||||
-- {
|
||||
-- fullName = "Nadamage", fullGuildName = "",
|
||||
-- level = 26, raceStr = "Troll",
|
||||
-- classStr = "Mage", filename = "MAGE",
|
||||
-- area = "Hillsbrad Foothills",
|
||||
-- }
|
||||
```
|
||||
|
||||
Table fields:
|
||||
|
||||
- `fullName` — the character name.
|
||||
- `fullGuildName` — the guild name, or `""` when the player has no
|
||||
guild.
|
||||
- `level` — the character level.
|
||||
- `raceStr` — localized race name, or `nil` when unknown.
|
||||
- `classStr` — localized class name, or `nil` when unknown.
|
||||
- `filename` — locale-independent class token (`"WARRIOR"`, `"MAGE"`,
|
||||
…), or `nil` when unknown. This is the key for `RAID_CLASS_COLORS`.
|
||||
Vanilla's own `GetWhoInfo` does not provide it, which is the main
|
||||
reason to use this table form.
|
||||
- `area` — the zone name.
|
||||
|
||||
There is no `gender` field — vanilla's /who result stores no sex.
|
||||
|
||||
Vanilla also keeps the global `GetWhoInfo(index)`, which returns
|
||||
positional values and no class token. This namespaced form returns a
|
||||
table and adds `filename`.
|
||||
|
||||
### `C_FriendList.IsFriend(guid)`
|
||||
|
||||
Returns `true` if the player with the given GUID is on your friends
|
||||
list, `false` if not.
|
||||
|
||||
```lua
|
||||
C_FriendList.IsFriend(UnitGUID("target")) -- true if the target is a friend
|
||||
C_FriendList.IsFriend("0x00000000000ABCDE")
|
||||
```
|
||||
|
||||
`guid` is a GUID string — the `"0x…"` form that `UnitGUID` returns.
|
||||
You can also pass a plain character name, because vanilla's friends
|
||||
list is keyed by name (`AddFriend(name)`).
|
||||
|
||||
The check reads the engine's friends list directly. It matches the
|
||||
input GUID against each friend's stored GUID. The server sends that
|
||||
GUID for both online and offline friends. As a fallback it also
|
||||
compares character names, so the answer holds for any friend the
|
||||
client saw this session.
|
||||
|
||||
### `C_FriendList.IsIgnored(token)`
|
||||
|
||||
Returns `true` if the player is on your ignore list, `false` if not.
|
||||
|
||||
```lua
|
||||
C_FriendList.IsIgnored("Bob")
|
||||
C_FriendList.IsIgnored("0x00000000000ABCDE")
|
||||
```
|
||||
|
||||
`token` is a character name or a GUID string. The ignore list stores
|
||||
GUIDs, not names. A GUID always matches. A name matches only a player
|
||||
the client has seen this session — the same players `GetIgnoreName` can
|
||||
name — because the name comes from the client's name cache.
|
||||
|
||||
### `C_FriendList.IsIgnoredByGuid(guid)`
|
||||
|
||||
Returns `true` if the player with the given GUID is on your ignore
|
||||
list, `false` if not.
|
||||
|
||||
```lua
|
||||
C_FriendList.IsIgnoredByGuid(UnitGUID("target"))
|
||||
C_FriendList.IsIgnoredByGuid("0x00000000000ABCDE")
|
||||
```
|
||||
|
||||
`guid` is a GUID string — the `"0x…"` form that `UnitGUID` returns.
|
||||
This is the exact key the ignore list uses, so it works for every
|
||||
ignored player.
|
||||
|
||||
### `C_FriendList.GetNumFriends()`
|
||||
|
||||
Returns the number of players on your friends list. The vanilla global
|
||||
`GetNumFriends()` returns the same count — this is the modern
|
||||
namespaced form.
|
||||
|
||||
```lua
|
||||
C_FriendList.GetNumFriends() -- e.g. 12
|
||||
```
|
||||
|
||||
### `C_FriendList.GetNumOnlineFriends()`
|
||||
|
||||
Returns how many friends on your list are online. This is a subset of
|
||||
[`GetNumFriends`](#c_friendlistgetnumfriends), which counts online and
|
||||
offline friends together.
|
||||
|
||||
```lua
|
||||
C_FriendList.GetNumOnlineFriends() -- e.g. 3
|
||||
```
|
||||
|
||||
Vanilla stores no online count, so the value is the number of friends
|
||||
whose `connected` flag is set — the same flag
|
||||
[`GetFriendInfo`](#c_friendlistgetfriendinfoname) reports.
|
||||
|
||||
### `C_FriendList.GetFriendInfo(name)`
|
||||
|
||||
Returns a `FriendInfo` table for the friend with the given name, or
|
||||
`nil` if that name is not on your list. The name match is
|
||||
case-insensitive.
|
||||
|
||||
```lua
|
||||
local info = C_FriendList.GetFriendInfo("Sarahnity")
|
||||
-- {
|
||||
-- name = "Sarahnity", connected = true, level = 60,
|
||||
-- className = "Druid", classFilename = "DRUID", area = "Stratholme",
|
||||
-- guid = "0x000000003B9CB7BF",
|
||||
-- afk = false, dnd = false,
|
||||
-- mobile = false, referAFriend = false, rafLinkType = 0,
|
||||
-- }
|
||||
```
|
||||
|
||||
Table fields:
|
||||
|
||||
- `name` — the friend's character name.
|
||||
- `connected` — `true` when the friend is online.
|
||||
- `level` — the friend's level, or `0` when unknown.
|
||||
- `className` — localized class name, or `nil` when unknown.
|
||||
- `classFilename` — locale-independent class token (`"WARRIOR"`,
|
||||
`"MAGE"`, …), or `nil` when unknown. Present whenever `className`
|
||||
is. This is the key for `RAID_CLASS_COLORS` and other class tables,
|
||||
so you can color a friend's name without matching the localized
|
||||
class name.
|
||||
- `area` — localized zone name, resolved to the parent zone, or `nil`
|
||||
when unknown.
|
||||
- `guid` — the friend's GUID string.
|
||||
- `notes` — your note for this friend, or `nil` if none. Set it with
|
||||
[`SetFriendNotes`](#c_friendlistsetfriendnotesname-notes).
|
||||
- `afk` / `dnd` — the friend's status flags.
|
||||
- `mobile` / `referAFriend` / `rafLinkType` — always `false` / `false`
|
||||
/ `0`. Vanilla 1.12 has no mobile app, Recruit-A-Friend, or RAF link
|
||||
data.
|
||||
|
||||
Notes are a ClassicAPI addition — vanilla has no note field. ClassicAPI
|
||||
persists them per character in
|
||||
`WTF\Account\<acct>\<realm>\<char>\ClassicAPI_FriendNotes.txt`, local to
|
||||
this client (not stored on the server, not shared with other machines).
|
||||
|
||||
### `C_FriendList.GetFriendInfoByIndex(index)`
|
||||
|
||||
The same `FriendInfo` table, addressed by a 1-based list index instead
|
||||
of a name. Returns `nil` for an index below 1 or above
|
||||
[`GetNumFriends`](#c_friendlistgetnumfriends).
|
||||
|
||||
```lua
|
||||
for i = 1, C_FriendList.GetNumFriends() do
|
||||
local info = C_FriendList.GetFriendInfoByIndex(i)
|
||||
print(info.name, info.connected, info.className, info.area)
|
||||
end
|
||||
```
|
||||
|
||||
See [`C_FriendList.GetFriendInfo`](#c_friendlistgetfriendinfoname) for
|
||||
the field list.
|
||||
|
||||
### `C_FriendList.SetFriendNotes(name, notes)`
|
||||
|
||||
Sets your note for the friend with the given name. Pass an empty string
|
||||
or `nil` to clear it. There is no return value, and the name must
|
||||
already be on your friends list.
|
||||
|
||||
```lua
|
||||
C_FriendList.SetFriendNotes("Sarahnity", "raid healer")
|
||||
C_FriendList.SetFriendNotes("Sarahnity", "") -- clears the note
|
||||
```
|
||||
|
||||
The note is stored client-side and read back through the `notes` field
|
||||
of [`GetFriendInfo`](#c_friendlistgetfriendinfoname). Setting a note
|
||||
fires `FRIENDLIST_UPDATE` so the friends UI and note-aware addons
|
||||
refresh. See the persistence note under `GetFriendInfo`.
|
||||
|
||||
### `C_FriendList.SetFriendNotesByIndex(index, notes)`
|
||||
|
||||
The same as
|
||||
[`SetFriendNotes`](#c_friendlistsetfriendnotesname-notes), addressed by
|
||||
a 1-based list index instead of a name. An out-of-range index does
|
||||
nothing.
|
||||
|
||||
```lua
|
||||
C_FriendList.SetFriendNotesByIndex(1, "tank")
|
||||
```
|
||||
|
||||
## GameObject
|
||||
|
||||
The gameobject analog of [`C_CreatureInfo`](#creature) — reads the
|
||||
@@ -9134,10 +9493,16 @@ sex, class) was reverse-engineered from the
|
||||
### `UnitNameFromGUID(guid)`
|
||||
|
||||
Returns `name, realm` for the player identified by `guid`, or `nil`
|
||||
if no player with that GUID has been encountered yet. Same lookup
|
||||
chain as [`GetPlayerInfoByGUID`](#getplayerinfobyguidguid) (engine
|
||||
NameCache, persistent on-disk fallback when enabled) — just narrower
|
||||
return shape for callers that only need the name.
|
||||
if no player with that GUID has been encountered yet.
|
||||
|
||||
It tries three sources in order:
|
||||
|
||||
1. The object manager — any currently-synced unit (a player you can
|
||||
see, your target, a party or raid member, an NPC in range).
|
||||
2. Your friends list — it keeps name and GUID for online and offline
|
||||
friends, so a friend resolves even when not synced and never seen
|
||||
in chat. Always on.
|
||||
3. The persistent on-disk name cache, when you have enabled it.
|
||||
|
||||
```lua
|
||||
local name, realm = UnitNameFromGUID(UnitGUID("target"))
|
||||
@@ -10210,6 +10575,21 @@ Reads `Spell.dbc` directly (`EffectMechanic[3]` at `+0x13C`), so it covers
|
||||
every spell the client knows — not just the player's spellbook — with no
|
||||
caching or network round-trip.
|
||||
|
||||
### `C_Spell.GetSpellDispelType(spellID)`
|
||||
|
||||
Returns the spell's dispel type from `Spell.dbc`: `1` = Magic,
|
||||
`2` = Curse, `3` = Disease, `4` = Poison. Returns `0` for a spell
|
||||
that nothing can dispel, and for an unknown spell.
|
||||
|
||||
```lua
|
||||
C_Spell.GetSpellDispelType(118) -- Polymorph → 1 (Magic)
|
||||
C_Spell.GetSpellDispelType(980) -- Curse of Agony → 2 (Curse)
|
||||
C_Spell.GetSpellDispelType(133) -- Fireball → 0 (none)
|
||||
```
|
||||
|
||||
Use the number to show what removes an effect, or to filter auras by
|
||||
dispel type. The values match the `DISPEL_*` set the server uses.
|
||||
|
||||
### `C_Spell.GetSpellRadius(spellID)` / `GetSpellRadius(slot, bookType)`
|
||||
|
||||
Returns `(baseRadius, modifiedRadius)` — the spell's AOE radius in yards,
|
||||
@@ -10694,15 +11074,50 @@ C_Spell.IsRangedAutoAttackSpell(5019) -- true (Shoot wand)
|
||||
C_Spell.IsRangedAutoAttackSpell(6603) -- false (melee)
|
||||
```
|
||||
|
||||
Tests `Spell.dbc.Attributes & 0x02` (the `SPELL_ATTR_AUTO_REPEAT`
|
||||
flag) — verified empirically against in-game spell data. Auto Shot
|
||||
(`0x00050012`) and Shoot wand (`0x00000012`) share bit 1; Heroic
|
||||
Strike (`0x00050014`) and other ranged abilities don't. Naturally
|
||||
covers any future auto-repeating spell a private server might add.
|
||||
Tests the auto-repeat flag in `Spell.dbc.AttributesEx2` (bit `0x20`).
|
||||
Only Auto Shot and Shoot carry it. The on-cast ranged abilities —
|
||||
Aimed Shot and Multi-Shot — set the general `RANGED` bit but not the
|
||||
auto-repeat flag, so they return `false`. The flag also covers any
|
||||
future auto-repeating spell a private server adds. Verified against
|
||||
`Spell.dbc`.
|
||||
|
||||
See [`C_SpellBook.IsRangedAutoAttackSpellBookItem`](#c_spellbookisrangedautoattackspellbookitemslot-booktype)
|
||||
for the spellbook-slot variant.
|
||||
|
||||
### `C_Spell.IsNextMeleeSpell(spellID)`
|
||||
|
||||
Returns `true` if the spell is an "on next swing" melee ability.
|
||||
These abilities queue and land on your next weapon swing instead of
|
||||
an instant cast (Heroic Strike, Cleave, Maul, Raptor Strike).
|
||||
|
||||
```lua
|
||||
C_Spell.IsNextMeleeSpell(78) -- Heroic Strike → true
|
||||
C_Spell.IsNextMeleeSpell(6807) -- Maul → true
|
||||
C_Spell.IsNextMeleeSpell(116) -- Frostbolt → false
|
||||
```
|
||||
|
||||
Tests the two on-next-swing bits in `Spell.dbc.Attributes`
|
||||
(`0x04` and `0x400`).
|
||||
|
||||
### `C_Spell.ResetsMeleeSwing(spellID)`
|
||||
|
||||
Returns `true` if casting the spell resets your melee swing timer.
|
||||
Cast-time spells reset it when you cast them (Fireball, Frostbolt,
|
||||
Polymorph, wand Shoot). Instant abilities like Sinister Strike do not,
|
||||
so a rogue can weave them between swings.
|
||||
|
||||
```lua
|
||||
C_Spell.ResetsMeleeSwing(133) -- Fireball → true
|
||||
C_Spell.ResetsMeleeSwing(1752) -- Sinister Strike → false
|
||||
C_Spell.ResetsMeleeSwing(1464) -- Slam → false (flagged "no reset")
|
||||
```
|
||||
|
||||
Mirrors the server's `IsMeleeAttackResetSpell`: `true` when the
|
||||
spell's `InterruptFlags` has the auto-attack bit (`0x08`) and its
|
||||
`AttributesEx2` does not have the "no reset auto actions" bit
|
||||
(`0x20000`). Both fields come from `Spell.dbc`. Slam carries that
|
||||
second bit, so it keeps its swing.
|
||||
|
||||
### `C_Item.GetWeaponEnchantInfo()`
|
||||
|
||||
Returns the modern 12-tuple matching WotLK+'s extended
|
||||
@@ -11196,131 +11611,6 @@ otherwise it falls back to `name`/`displayName`/`textureID`/`spellID` with
|
||||
**`nil` times**. The player path is unchanged (full timing). Same
|
||||
placeholder fields as `C_Spell.UnitCastingInfo`.
|
||||
|
||||
### `UNIT_SPELLCAST_*` events
|
||||
|
||||
Backport of the TBC+ cast/channel events to 1.12, for the **local player and
|
||||
other units**. Ported cast-bar / rotation addons (anything written against
|
||||
the modern signature) register these instead of vanilla's arg-less
|
||||
`SPELLCAST_*` events and read `unit, castGUID, spellID` directly. Thirteen
|
||||
events are provided; six also fire for non-player units:
|
||||
|
||||
| Event | Fires when | Units | Args |
|
||||
|-------|-----------|-------|------|
|
||||
| `UNIT_SPELLCAST_SENT` | `CMSG_CAST_SPELL` leaves the client (earliest point) | player | `unit, target, castGUID, spellID, spellName, rank` |
|
||||
| `UNIT_SPELLCAST_START` | a cast-time spell begins | all | `unit, castGUID, spellID, spellName, rank` |
|
||||
| `UNIT_SPELLCAST_STOP` | a cast-time spell ends (any reason) | all | same |
|
||||
| `UNIT_SPELLCAST_DELAYED` | pushback extends the cast | player | same |
|
||||
| `UNIT_SPELLCAST_SUCCEEDED` | the spell goes off (`SMSG_SPELL_GO`) — incl. instants | all | same |
|
||||
| `UNIT_SPELLCAST_INTERRUPTED` | a started **cast** is interrupted (kick, movement, LoS) — never for channels | all | same |
|
||||
| `UNIT_SPELLCAST_FAILED` | a cast is rejected before it starts (range, mana, cooldown) with an error shown | player | same |
|
||||
| `UNIT_SPELLCAST_FAILED_QUIET` | a cast fails with **no** error shown (spammy retry, reticle cancel, …) | player | same |
|
||||
| `UNIT_SPELLCAST_CHANNEL_START` | a channel begins | all | same |
|
||||
| `UNIT_SPELLCAST_CHANNEL_UPDATE` | pushback shortens a channel | player | same |
|
||||
| `UNIT_SPELLCAST_CHANNEL_STOP` | a channel ends | all | same |
|
||||
| `UNIT_SPELLCAST_RETICLE_TARGET` | a ground-target reticle appears (AoE placement — Blizzard, Flare, …) | player | `unit, "", spellID, spellName, rank` |
|
||||
| `UNIT_SPELLCAST_RETICLE_CLEAR` | the reticle is placed or cancelled | player | `unit, "", spellID, spellName, rank` |
|
||||
|
||||
`unit` (arg1) is the token of the casting unit — `"player"` for your own
|
||||
casts, or a unit token (`"target"`, `"focus"`, `"party3"`, `"nameplate2"`,
|
||||
`"pet"`, `"mouseover"`, …) for another unit. `spellName` / `rank` are
|
||||
ClassicAPI tail extensions (modern stops at `spellID`); addons reading only
|
||||
the first three positional args are unaffected.
|
||||
|
||||
**Per-token fan-out.** A caster GUID can map to several tokens at once (your
|
||||
`target` is also `party2` and `nameplate1`). Like retail, the event fires
|
||||
**once per token** currently pointing at the caster, so a `target`-frame
|
||||
cast bar, a `party2` frame, and a nameplate cast bar each get their own
|
||||
event with the same castGUID. Tokens are resolved fresh at fire time (they
|
||||
shift frame-to-frame). If you run **SuperWoW**, its raw-GUID token (`"0x…"`)
|
||||
is deliberately filtered out — only standard tokens are fanned out.
|
||||
|
||||
**Non-player limits.** Only the six events above fire for other units, and
|
||||
they're **best-effort** — driven purely by the packets an observer receives:
|
||||
- `SENT` never fires (only your own outgoing casts are visible).
|
||||
- `DELAYED` / `CHANNEL_UPDATE` never fire (pushback is sent only to the
|
||||
caster, so another unit's bar can't stretch/shrink from damage).
|
||||
- `FAILED` never fires (a pre-cast requirement failure is client-local).
|
||||
- A remote cast/channel only has timing from the moment its
|
||||
`SMSG_SPELL_START` was observed; casters who were already casting when
|
||||
they came into range have no start time.
|
||||
|
||||
**Channels never fire `INTERRUPTED`.** Retail emits only `CHANNEL_STOP` when a
|
||||
channel ends, whether it completed or was cut short (verified against retail),
|
||||
so ClassicAPI matches that for both the player and other units. `INTERRUPTED`
|
||||
is a cast-only event.
|
||||
|
||||
**Reticle events** fire for ground-targeted (AoE) spells only, always for the
|
||||
player: `RETICLE_TARGET` when the placement reticle comes up, `RETICLE_CLEAR`
|
||||
when it's placed or cancelled. There's no cast yet, so the castGUID slot
|
||||
(arg2) is empty — retail pushes `nil` there, but the engine's event
|
||||
dispatcher can't emit a `nil` mid-argument-list, so ClassicAPI pushes `""`
|
||||
instead. `unit` (arg1) and `spellID` (arg3) are exact; arg2 is the only
|
||||
difference and is inconsequential for a reticle.
|
||||
|
||||
**castGUID.** A synthesized string in the modern shape
|
||||
`Cast-<type>-<serverID>-<instanceID>-<zoneUID>-<spellID>-<castUID>`. Vanilla
|
||||
can't know server / instance / zone, so those three fields are `0`; the
|
||||
load-bearing parts are the `spellID` (field 6, which addons `strsplit("-")`
|
||||
out) and a unique-per-cast `castUID` (field 7). **Every event of one cast
|
||||
carries the same castGUID**, so `SENT` → `START`/`CHANNEL_START` →
|
||||
`SUCCEEDED` → `STOP`/`CHANNEL_STOP` all pair up — including across the caster
|
||||
and observers (they converge on the same value), and a chained same-spell
|
||||
recast gets its own castUID. The `type` and `castUID` follow the
|
||||
[spell-cast-GUID spec](https://warcraft.wiki.gg/wiki/GUID#Cast):
|
||||
- **Type 3** (real casts — the common case): `castUID` is time-based — the
|
||||
low 23 bits are the cast's UNIX-epoch second, the higher bits a per-second
|
||||
counter.
|
||||
- **Type 2** (`UNIT_SPELLCAST_FAILED` — a local-only cast that never reached
|
||||
the server): `castUID` is a plain locally-incrementing integer.
|
||||
|
||||
**Ordering** matches modern:
|
||||
|
||||
- Cast-time spell: `SENT → START → SUCCEEDED → STOP`.
|
||||
- Channel: `SENT → CHANNEL_START → SUCCEEDED → CHANNEL_STOP` (CHANNEL_START
|
||||
before SUCCEEDED, as on retail).
|
||||
- Instant: `SENT → SUCCEEDED`.
|
||||
|
||||
**INTERRUPTED vs FAILED vs FAILED_QUIET** follow modern's split: a spell that
|
||||
never started (out of range, not enough mana, on cooldown, LoS to a target)
|
||||
fires `FAILED`, except for a fixed whitelist of "quiet" `SpellCastResult`
|
||||
codes that fire `FAILED_QUIET` instead — `SPELL_IN_PROGRESS` (casting while
|
||||
already casting / a spell-queue rejection), `DONT_REPORT` (fake fails, a
|
||||
cancelled ground reticle), and `CHARMED`. That whitelist mirrors the 3.3.5
|
||||
client's own unit-spellcast dispatch, mapped to vanilla's `SpellCastResult`
|
||||
enum. A spell that was *already casting* and gets stopped (an enemy kick,
|
||||
moving to cancel, breaking LoS mid-cast) fires `INTERRUPTED`. Holding
|
||||
the cast key while running fires `INTERRUPTED` repeatedly (once per retry),
|
||||
each reusing the interrupted cast's castGUID — matching retail.
|
||||
|
||||
**Channel pushback (player).** Taking damage while channeling shortens the
|
||||
channel in vanilla; `CHANNEL_UPDATE` fires on each hit and
|
||||
[`C_Spell.UnitChannelInfo`](#c_spellunitchannelinfounit--c_spellchannelinfo)'s
|
||||
`endTimeMs` re-anchors to the server's new remaining time, so cast bars
|
||||
shrink correctly. (The event carries no time — like retail it's a "re-read
|
||||
now" trigger; timing is read back from `UnitChannelInfo`.)
|
||||
|
||||
Every fire is gated on whether any frame is registered for that event, so
|
||||
the whole system costs one pointer-compare per state transition when no
|
||||
addon uses it (no arg synthesis, no DBC lookups, no per-token fan-out).
|
||||
|
||||
```lua
|
||||
local f = CreateFrame("Frame")
|
||||
for _, e in ipairs({
|
||||
"UNIT_SPELLCAST_START", "UNIT_SPELLCAST_STOP",
|
||||
"UNIT_SPELLCAST_SUCCEEDED", "UNIT_SPELLCAST_CHANNEL_START",
|
||||
}) do f:RegisterEvent(e) end
|
||||
f:SetScript("OnEvent", function()
|
||||
-- vanilla passes event/arg1/... as globals, not function params
|
||||
if arg1 == "target" then print(event, arg3) end -- arg3 = spellID
|
||||
end)
|
||||
```
|
||||
|
||||
> **Additive to the vanilla `SPELLCAST_*` events.** The engine's own arg-less
|
||||
> `SPELLCAST_START` / `SPELLCAST_CHANNEL_UPDATE` / … still fire as before;
|
||||
> these `UNIT_`-prefixed events are the modern layer on top. The empowered-cast
|
||||
> events (`UNIT_SPELLCAST_EMPOWER_*`, a Dragonflight addition) are not
|
||||
> implemented — vanilla has no empowered casts.
|
||||
|
||||
### `C_Spell.GetSpellLevelInfo(spellID)`
|
||||
|
||||
Returns the raw `Spell.dbc` level fields for a spell:
|
||||
@@ -13819,7 +14109,7 @@ is the escape hatch for *other* custom servers with the same class of
|
||||
gap — call it from your own config or addon; a registered override
|
||||
beats both the DBC and the built-in values.
|
||||
|
||||
### `C_UnitAuras.RegisterAuraDurationModifier(triggerSpellID, affectedFamily, affectedFamilyFlags, affectedIcon, op [, valueSeconds])`
|
||||
### `C_UnitAuras.RegisterAuraDurationModifierByTrigger(triggerFamily, triggerSchool, affectedFamily, affectedFamilyFlags, affectedIcon, op [, valueSeconds])`
|
||||
|
||||
ClassicAPI extension for **server-side DoT-duration changes on another
|
||||
unit that the client is never told about**. Returns `true` on success.
|
||||
@@ -13838,8 +14128,9 @@ trigger lands:
|
||||
|
||||
| Arg | Meaning |
|
||||
|-----|---------|
|
||||
| `triggerSpellID` | The spell whose cast triggers the change (match one rank per call — use the exact IDs the server binds). |
|
||||
| `affectedFamily` | `SpellFamilyName` of the affected aura (e.g. `5` warlock, `11` shaman, `7` druid). |
|
||||
| `triggerFamily` | `SpellFamilyName` of the triggering cast (e.g. `6` priest). |
|
||||
| `triggerSchool` | School index the trigger must be (`0` physical … `2` fire, `5` shadow, `6` arcane), or `< 0` for any. Matching by family + school covers a whole class of spells at once — every rank, plus server-added ones — rather than a named ability. |
|
||||
| `affectedFamily` | `SpellFamilyName` of the affected aura (e.g. `5` warlock, `11` shaman, `6` priest). |
|
||||
| `affectedFamilyFlags` | A `SpellFamilyFlags` bitmask; the affected aura matches if it overlaps. Family + flag is rank-proof (covers every rank at once). |
|
||||
| `affectedIcon` | `SpellIconID` the affected aura must have, or `0` to match any. |
|
||||
| `op` | `"refresh"` (reset to full duration), `"reduce"` (subtract `valueSeconds`, removing the aura if it would go non-positive), `"set"` (to `valueSeconds`), `"remove"`. |
|
||||
@@ -13849,34 +14140,26 @@ The rule only fires for the aura **cast by the same unit** as the trigger
|
||||
(these mechanics act on the caster's own DoT), and misses are excluded for
|
||||
free (a missed trigger isn't in the packet's hit list).
|
||||
|
||||
**`C_UnitAuras.RegisterAuraDurationModifierByTrigger(triggerFamily, triggerSchool, affectedFamily, affectedFamilyFlags, affectedIcon, op [, valueSeconds])`**
|
||||
is the same, but matches the *trigger* by `SpellFamilyName` + school index
|
||||
(`0` physical … `2` fire, `5` shadow, `6` arcane; `< 0` = any) instead of an
|
||||
exact spellID — one rule covers a whole class of spells (every rank, plus
|
||||
server-added ones). Use it when the trigger is a category rather than a named
|
||||
ability.
|
||||
Rules keyed to an **exact trigger spellID** (rather than a family + school
|
||||
category) are registered inside the DLL instead. `!!!ClassicAPI`'s built-in
|
||||
Turtle mods — Conflagrate shaving 3s off the caster's Immolate, Molten Blast
|
||||
refreshing the caster's Flame Shock — live in `src/turtle/DurationMods.cpp`,
|
||||
and Carnage's roll-gated Rip/Rake refresh in `src/turtle/Carnage.cpp`.
|
||||
|
||||
`!!!ClassicAPI` ships a default Turtle ruleset
|
||||
([Util/AuraDurationModifiers.lua](../AddOns/!!!ClassicAPI/Util/AuraDurationModifiers.lua)):
|
||||
Conflagrate shaves 3s off the caster's Immolate, Molten Blast refreshes the
|
||||
caster's Flame Shock, and — for a 5/5 Shadow Weaving priest (talent `15334`,
|
||||
where the proc is 100%) — any shadow-school priest cast refreshes the target's
|
||||
Shadow Vulnerability (`15258`). Deliberately excluded: probabilistic effects
|
||||
(Carnage's roll-gated Rip/Rake refresh, and Shadow Weaving below 5/5) — the
|
||||
client can't see the server's roll, so inferring them would show wrong timers.
|
||||
Two accepted best-effort caveats on the Shadow Weaving rule: DoT *ticks*
|
||||
(SW:P / Devouring Plague) also refresh it server-side but emit no cast packet,
|
||||
so a pure DoT-only phase under-counts slightly; and a full-consume Conflagrate
|
||||
variant on other servers *removes* Immolate, which ClassicAPI already evicts
|
||||
via the normal removal path (so the reduce rule is harmless there).
|
||||
The one rule registered from Lua
|
||||
([Util/AuraDurationModifiers.lua](../AddOns/!!!ClassicAPI/Util/AuraDurationModifiers.lua))
|
||||
is Shadow Weaving: for a 5/5 priest (talent `15334`, where the proc is 100%),
|
||||
any shadow-school priest cast refreshes the target's Shadow Vulnerability
|
||||
(`15258`). Below 5/5 it's roll-gated and deliberately not inferred — the client
|
||||
can't see the server's roll, so inferring it would show wrong timers. One
|
||||
accepted best-effort caveat: DoT *ticks* (SW:P / Devouring Plague) also refresh
|
||||
it server-side but emit no cast packet, so a pure DoT-only phase under-counts
|
||||
slightly.
|
||||
|
||||
```lua
|
||||
-- Flags are hex; Lua 5.0 has no 0x literals, so use tonumber(hex, 16).
|
||||
-- Conflagrate (Rank 4) shaves 3s off the caster's Immolate (warlock, flag 0x4):
|
||||
C_UnitAuras.RegisterAuraDurationModifier(18932, 5, tonumber("4", 16), 0, "reduce", 3)
|
||||
-- Molten Blast refreshes the caster's Flame Shock (shaman, flag 0x10000000):
|
||||
C_UnitAuras.RegisterAuraDurationModifier(36916, 11, tonumber("10000000", 16), 0, "refresh")
|
||||
-- Any priest (6) shadow-school (5) cast refreshes Shadow Vulnerability (15258):
|
||||
-- Any priest (6) shadow-school (5) cast refreshes Shadow Vulnerability
|
||||
-- (affected priest 6, flag 0x4000000, icon 9):
|
||||
C_UnitAuras.RegisterAuraDurationModifierByTrigger(6, 5, 6, tonumber("4000000", 16), 9, "refresh")
|
||||
```
|
||||
|
||||
|
||||
+62
-23
@@ -198,7 +198,7 @@ enum Offsets {
|
||||
// Returns an int the caller (Script_GameTooltip_SetUnit) tests, so the
|
||||
// co-hook must forward the original's return value.
|
||||
// - GameObject (0x0052aa20, __thiscall(self, guid*), RET 4) — the GO
|
||||
// hover populator; resolves the GO (OBJ_TYPE_GAMEOBJECT) and writes the
|
||||
// hover populator; resolves the GO (TYPEMASK_GAMEOBJECT) and writes the
|
||||
// GO field at +0x370.
|
||||
FUN_GAMETOOLTIP_BUILD_UNIT = 0x00529FE0,
|
||||
FUN_GAMETOOLTIP_BUILD_GAMEOBJECT = 0x0052AA20,
|
||||
@@ -1069,6 +1069,10 @@ enum Offsets {
|
||||
// derive `dispelName` from `Spell.dbc[+0x10]` (see
|
||||
// `OFF_SPELL_DISPEL_TYPE` below), not from the flags nibble.
|
||||
OFF_UNIT_FIELD_AURA = 0xA4, // u32 spell ID per slot, 48 slots total
|
||||
// UNIT_AURA event id for FUN_UNIT_EVENT_BROADCAST. The per-token unit
|
||||
// events use field-index == event-id; the aura field is index 0x29
|
||||
// (OFF_UNIT_FIELD_AURA 0xA4 >> 2), per Unit::TokenObserver's watched set.
|
||||
UNIT_EVENT_UNIT_AURA = 0x29,
|
||||
OFF_UNIT_FIELD_AURAFLAGS = 0x164, // 4 bits per aura, 2 per byte, covers all 48
|
||||
OFF_UNIT_FIELD_AURALEVELS = 0x17C, // u8 caster level per aura, 48 bytes
|
||||
OFF_UNIT_FIELD_AURAAPPLICATIONS = 0x1AC, // u8 (stacks-1) per aura, display value = byte+1
|
||||
@@ -1895,7 +1899,7 @@ enum Offsets {
|
||||
// gated on the bank-open globals). Returns the CGContainer GUID of the bag
|
||||
// equipped in that slot, or 0 if none. This is the internal PackBagSlot
|
||||
// uses to resolve bags 1..4: get the bag GUID here, resolve the container
|
||||
// via FUN_OBJECT_RESOLVE_BY_GUID(OBJ_TYPE_CONTAINER, guid), then call the
|
||||
// via FUN_OBJECT_RESOLVE_BY_GUID(TYPEMASK_CONTAINER, guid), then call the
|
||||
// container's vtable[+OFF_CONTAINER_GET_INVENTORY] to get the inventory
|
||||
// object GetItemBySlot indexes. Lets us enumerate bag contents in pure C++
|
||||
// without PackBagSlot's Lua-stack coupling. (Reads GUID arrays at
|
||||
@@ -1951,16 +1955,14 @@ enum Offsets {
|
||||
//
|
||||
// Type values: 2 = item (returns CGItem*), 4 = container/bag
|
||||
// (returns CGContainer*). Engine passes `"ItemMgr"` as debugName
|
||||
// and `0x172` as priority for both call sites we've decoded.
|
||||
// and `0x172` as priority for both call sites we've decoded. Some engine
|
||||
// sites type it as `(u32 typeMask, void *unused, u64 guid, int)` —
|
||||
// ABI-equivalent (the u64 occupies the same two stack dwords as
|
||||
// guidLo/guidHi). All our callers go through `Object::ByGuid`
|
||||
// (object/Resolve.h), which wraps this single address.
|
||||
FUN_OBJECT_RESOLVE_BY_GUID = 0x00468460,
|
||||
// The type arg is a bitmask of object-type bits, not an enum
|
||||
// index — `1<<1` for items, `1<<2` for containers, `1<<3` for
|
||||
// units, matching what `FUN_00529FE0` passes for SetUnit (`ECX=8`).
|
||||
OBJ_TYPE_ITEM = 2,
|
||||
OBJ_TYPE_CONTAINER = 4,
|
||||
OBJ_TYPE_UNIT = 8,
|
||||
OBJ_TYPE_PLAYER = 0x10, // what the engine's bag observer FUN_004F8DB0 passes
|
||||
OBJ_TYPE_GAMEOBJECT = 0x20, // 1<<5; passed by FUN_0052AA20 (hover-tooltip populator).
|
||||
// The type arg is a bitmask of object-type bits (see the TYPEMASK_*
|
||||
// block below), not an enum index.
|
||||
|
||||
// `CGObject::GetName` — returns the display-name `const char *` for
|
||||
// a resolved CGObject (CGUnit / CGPlayer / CGCreature). Internally
|
||||
@@ -2672,6 +2674,10 @@ enum Offsets {
|
||||
VAR_AREATABLE_RECORDS = 0x00C0E048,
|
||||
VAR_AREATABLE_COUNT = 0x00C0E04C,
|
||||
OFF_AREATABLE_NAMES = 0x2C,
|
||||
// Parent AreaTable id @ +0x08 — a sub-area's enclosing zone (e.g. Goldshire
|
||||
// → Elwynn Forest). GetFriendInfo resolves it to name the zone, not the
|
||||
// sub-area. 0 for a top-level zone.
|
||||
OFF_AREATABLE_PARENT_ID = 0x08,
|
||||
// AreaBit @ +0x0C: index into the player's explored-areas bitfield
|
||||
// (OFF_PLAYER_EXPLORED_BITS). Gate @ +0x28: when < 0 the area needs no
|
||||
// exploration (always counts explored); when >= 0 the AreaBit check
|
||||
@@ -2842,15 +2848,11 @@ enum Offsets {
|
||||
// each callback invocation, guidLo/guidHi pushed as 8 stack bytes.
|
||||
FUN_CLNT_OBJ_MGR_ENUM_VISIBLE_OBJECTS = 0x00468380,
|
||||
|
||||
// GUID → CGObject resolver. __fastcall with this signature:
|
||||
// CGObject *(__fastcall *)(uint32_t typeMask, void *unused,
|
||||
// uint64_t guid, int unused2);
|
||||
// typeMask filters to specific object types; returns NULL if the
|
||||
// GUID isn't loaded or its type doesn't match the mask.
|
||||
FUN_CLNT_OBJ_MGR_OBJECT_PTR = 0x00468460,
|
||||
|
||||
// Type-mask flags accepted by FUN_CLNT_OBJ_MGR_OBJECT_PTR. Single-bit
|
||||
// flags can be OR'd together.
|
||||
// Type-mask flags accepted by FUN_OBJECT_RESOLVE_BY_GUID (and the SetUnit
|
||||
// path FUN_00529FE0, which passes ECX=8 for UNIT). A bitmask of
|
||||
// object-type bits, not an enum index — single-bit flags OR together.
|
||||
// PLAYER (0x10) is what the bag observer FUN_004F8DB0 passes; GAMEOBJECT
|
||||
// (0x20) what the hover-tooltip populator FUN_0052AA20 passes.
|
||||
TYPEMASK_OBJECT = 0x01,
|
||||
TYPEMASK_ITEM = 0x02,
|
||||
TYPEMASK_CONTAINER = 0x04,
|
||||
@@ -3095,11 +3097,16 @@ enum Offsets {
|
||||
VAR_FACTION_COLLAPSED_BITMASK = 0x0084A0A4,
|
||||
MAX_FACTION_HEADERS = 32,
|
||||
|
||||
// Who-query (the /who system).
|
||||
// The social singleton (0x00C28168) — one object shared by the friend
|
||||
// list, ignore list, and /who system. Layout: friend entries inline from
|
||||
// offset 0 (stride 0x20, up to 50; each is {connected@+0x00, name char*
|
||||
// @+0x04, GUID u64 @+0x08, level@+0x10, area@+0x14, class@+0x18}), the
|
||||
// 25-entry ignore-GUID table at +0x650, and the who-query state. Read by
|
||||
// GetNumFriends/GetFriendInfo, GetNumIgnores, and Script_SendWho.
|
||||
//
|
||||
// `Script_SendWho` (0x005AD3B0) is a 32-byte wrapper:
|
||||
// - validate arg1 is a string via lua_isstring
|
||||
// - load WhoSystem singleton from `[VAR_WHO_SYSTEM]`
|
||||
// - load the singleton from `[VAR_SOCIAL_SYSTEM]`
|
||||
// - if non-NULL, lua_tostring(L, 1) for the query string
|
||||
// - tail-call `FUN_WHO_SYSTEM_SEND_QUERY` with
|
||||
// `__thiscall(this = WhoSystem, queryStr)`
|
||||
@@ -3120,9 +3127,13 @@ enum Offsets {
|
||||
// Server-side cooldown for CMSG_WHO is ~5 seconds — a faster
|
||||
// client gets silent-dropped, so any client-side gating just
|
||||
// matches that.
|
||||
VAR_WHO_SYSTEM = 0x00C28168,
|
||||
VAR_SOCIAL_SYSTEM = 0x00C28168,
|
||||
VAR_WHO_TO_UI_FLAG = 0x00C2A12C,
|
||||
FUN_WHO_SYSTEM_SEND_QUERY = 0x005AEBB0,
|
||||
// Friend count: `__fastcall(socialSingleton) -> uint` — walks the inline
|
||||
// entries and returns the number of populated friend slots. Backs
|
||||
// GetNumFriends and C_FriendList.IsFriend.
|
||||
FUN_FRIEND_LIST_COUNT = 0x005AE490,
|
||||
|
||||
// SMSG_WHO opcode handler — opcode 0x63 (99) per the registration
|
||||
// in `FUN_005adc50`: `FUN_005ab650(99, FUN_005adf60, 0)`. Reads
|
||||
@@ -3136,6 +3147,25 @@ enum Offsets {
|
||||
// user actually wanted both.
|
||||
FUN_SMSG_WHO_RESPONSE = 0x005ADF60,
|
||||
|
||||
// /who result list — the buffer `Script_GetWhoInfo` (0x005AD6E0) and
|
||||
// `Script_GetNumWhoResults` (0x005AD690) read. An array of fixed-size
|
||||
// entries at `VAR_WHO_RESULTS`, stride `WHO_RESULT_STRIDE`; the field
|
||||
// offsets below are all relative to an entry. `name`/`guildName` are
|
||||
// inline C strings; `race`/`class` index ChrRaces/ChrClasses.dbc and
|
||||
// `zone` indexes AreaTable.dbc (own name, not parent-resolved).
|
||||
// `VAR_WHO_RESULT_COUNT` is the displayed count (the first of the two
|
||||
// values GetNumWhoResults returns; the second, total matches, is at +4).
|
||||
// Verified by decompiling both accessors.
|
||||
VAR_WHO_RESULTS = 0x00C281B8,
|
||||
VAR_WHO_RESULT_COUNT = 0x00C2A120,
|
||||
WHO_RESULT_STRIDE = 0xA0,
|
||||
OFF_WHO_NAME = 0x00, // char[] inline
|
||||
OFF_WHO_GUILD = 0x30, // char[] inline
|
||||
OFF_WHO_LEVEL = 0x90, // i32
|
||||
OFF_WHO_RACE = 0x94, // i32 → ChrRaces.dbc
|
||||
OFF_WHO_CLASS = 0x98, // i32 → ChrClasses.dbc
|
||||
OFF_WHO_ZONE = 0x9C, // i32 → AreaTable.dbc
|
||||
|
||||
// Per-faction current standing — `__fastcall(ecx = factionID) → int`.
|
||||
// Returns `base + delta` where the two values are stored at
|
||||
// `+0x08` / `+0x0C` of the player's rep slot (slot stride 0x10,
|
||||
@@ -4480,6 +4510,14 @@ enum Offsets {
|
||||
// No `%b` for boolean — pass `%d` with 0/1; the engine has no native
|
||||
// bool concept here. No bounds check on eventID; pass valid indices.
|
||||
FUN_FIRE_EVENT = 0x00703F50,
|
||||
// Per-token unit-event broadcast. Fires unit event `eventCode` for every
|
||||
// unit token currently mapping to `*guid` (target / party / raid /
|
||||
// nameplateN / mouseover / focus), via the engine's own GUID->token reverse
|
||||
// map -- the same path the descriptor-field observers drive on a real field
|
||||
// change. `void __fastcall(uint64_t *guid, uint32_t eventCode)`; verified
|
||||
// against nampower's SendUnitSignal (0x00515e50). `eventCode` is the unit
|
||||
// field index, which doubles as the event id (see UNIT_EVENT_UNIT_AURA).
|
||||
FUN_UNIT_EVENT_BROADCAST = 0x00515E50,
|
||||
// Event name strings live in `.data` (mostly clustered around
|
||||
// 0x00851000..0x00855000); event-name string pointers also reach into
|
||||
// `.rdata` (starts at 0x007FF000) for some entries. Bound the dereference
|
||||
@@ -5728,6 +5766,7 @@ enum Offsets {
|
||||
// ENCHANT_ITEM / _TEMPORARY (enchants), and LEARN_SPELL (Turtle's custom
|
||||
// recipes, e.g. "Steel Plate Boots" = effect 36).
|
||||
OFF_SPELL_RECORD_EFFECT = 0xF4, // int32[3]
|
||||
SPELL_EFFECT_SCHOOL_DAMAGE = 2, // direct damage (verified vs server SpellDefines.h)
|
||||
SPELL_EFFECT_CREATE_ITEM = 24,
|
||||
SPELL_EFFECT_LEARN_SPELL = 36,
|
||||
SPELL_EFFECT_ENCHANT_ITEM = 53,
|
||||
|
||||
@@ -55,8 +55,10 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "event/Custom.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
#include "item/Swap.h"
|
||||
#include "tick/WorldTick.h"
|
||||
|
||||
@@ -97,27 +99,15 @@ Job g_job{};
|
||||
|
||||
// --- small CGItem / cache readers ---------------------------------------
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
int CGItemCount(const uint8_t *item) {
|
||||
auto *desc = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *desc = Item::ObjectFields(item);
|
||||
if (desc == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const int *>(desc + Offsets::OFF_DESCRIPTOR_STACK_COUNT);
|
||||
}
|
||||
|
||||
uint64_t CGItemGuid(const uint8_t *item) {
|
||||
auto *inst = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *inst = Item::InstanceBlock(item);
|
||||
if (inst == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint64_t *>(inst + Offsets::OFF_INSTANCE_BLOCK_GUID);
|
||||
@@ -188,7 +178,7 @@ bool BagIsGeneral(int bag) {
|
||||
const int id = Item::ID::FromCGItem(bagItem);
|
||||
if (id == 0)
|
||||
return false;
|
||||
const uint8_t *rec = PeekItemRecord(static_cast<uint32_t>(id));
|
||||
const uint8_t *rec = Item::PeekRecord(static_cast<uint32_t>(id));
|
||||
if (rec == nullptr)
|
||||
return false;
|
||||
return *reinterpret_cast<const uint32_t *>(
|
||||
|
||||
+36
-12
@@ -57,28 +57,52 @@ uint8_t CurrentComboPoints() {
|
||||
return *(info + Offsets::OFF_CGPLAYER_COMBO_POINTS);
|
||||
}
|
||||
|
||||
// One cast in flight at a time is the practical case (a second finisher
|
||||
// can't be cast until the server consumes the first one's combo points),
|
||||
// so a single slot with a spellID match and a short TTL suffices.
|
||||
// Keyed by spellID, because a finisher's own SMSG_SPELL_GO is not reliably
|
||||
// the next one to arrive after its cast. A talent that procs an aura on the
|
||||
// finisher (Turtle's rogue Taste for Blood casts spell 52529 on the player)
|
||||
// lands its SPELL_GO first, and every player-cast aura spell reaches
|
||||
// TryComboScaledMs. A single slot -- or a lookup that cleared the slot on a
|
||||
// spellID mismatch -- therefore lost the snapshot to the proc, and the
|
||||
// finisher fell back to its 0-CP base duration. Only the matching entry is
|
||||
// ever consumed; a miss leaves every other capture intact.
|
||||
struct Capture {
|
||||
uint32_t spellId;
|
||||
uint8_t comboPoints;
|
||||
uint32_t capturedMs;
|
||||
};
|
||||
Capture g_capture{0, 0, 0};
|
||||
constexpr int kCaptureCount = 8;
|
||||
Capture g_captures[kCaptureCount];
|
||||
int g_captureCursor = 0;
|
||||
|
||||
// Worst-case send -> SMSG_SPELL_GO roundtrip. Past this the snapshot is
|
||||
// stale (the cast failed / was rejected) and must not scale a later cast.
|
||||
constexpr uint32_t kCaptureTtlMs = 2000;
|
||||
|
||||
void RememberCapture(uint32_t spellId, uint8_t comboPoints, uint32_t nowMs) {
|
||||
for (auto &c : g_captures) {
|
||||
if (c.spellId == spellId) { // re-cast before the first resolved
|
||||
c.comboPoints = comboPoints;
|
||||
c.capturedMs = nowMs;
|
||||
return;
|
||||
}
|
||||
}
|
||||
g_captures[g_captureCursor] = {spellId, comboPoints, nowMs};
|
||||
g_captureCursor = (g_captureCursor + 1) % kCaptureCount;
|
||||
}
|
||||
|
||||
int ConsumeCapturedCP(uint32_t spellId) {
|
||||
const Capture c = g_capture;
|
||||
g_capture = {0, 0, 0};
|
||||
if (c.spellId != spellId || c.comboPoints == 0)
|
||||
return 0;
|
||||
if (NowMs() - c.capturedMs >= kCaptureTtlMs)
|
||||
return 0;
|
||||
return c.comboPoints;
|
||||
for (auto &c : g_captures) {
|
||||
if (c.spellId != spellId)
|
||||
continue;
|
||||
const Capture got = c;
|
||||
c = {0, 0, 0};
|
||||
if (got.comboPoints == 0)
|
||||
return 0;
|
||||
if (NowMs() - got.capturedMs >= kCaptureTtlMs)
|
||||
return 0;
|
||||
return got.comboPoints;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Co-hook on the NetClient send — the one funnel every outgoing CMSG
|
||||
@@ -94,7 +118,7 @@ void OnSend(uint32_t opcode, Net::CDataStore *packet) {
|
||||
return;
|
||||
const uint32_t spellId = Net::Read<uint32_t>(packet);
|
||||
if (spellId != 0)
|
||||
g_capture = {spellId, CurrentComboPoints(), NowMs()};
|
||||
RememberCapture(spellId, CurrentComboPoints(), NowMs());
|
||||
}
|
||||
|
||||
const Net::SendObserver::AutoSubscribe _sendSub{&OnSend};
|
||||
|
||||
+109
-65
@@ -21,6 +21,7 @@
|
||||
#include "Offsets.h"
|
||||
#include "net/PacketDispatch.h"
|
||||
#include "net/PacketReader.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "player/StatSignal.h"
|
||||
#include "spell/CastEvents.h"
|
||||
#include "spell/Lookup.h"
|
||||
@@ -171,16 +172,10 @@ constexpr uint32_t kEvictGraceMs = 2000;
|
||||
bool DescriptorListsAura(uint64_t guid, uint32_t spellId) {
|
||||
if (guid == 0 || spellId == 0)
|
||||
return false;
|
||||
using ResolveByGuid_t = void *(__fastcall *)(int typeMask, const char *dbg,
|
||||
uint32_t guidLo,
|
||||
uint32_t guidHi, int priority);
|
||||
constexpr int kUnitOrPlayerMask =
|
||||
(1 << Offsets::OBJECT_TYPE_UNIT) | (1 << Offsets::OBJECT_TYPE_PLAYER);
|
||||
auto resolve = reinterpret_cast<ResolveByGuid_t>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID));
|
||||
const auto *unit = static_cast<const uint8_t *>(
|
||||
resolve(kUnitOrPlayerMask, nullptr, static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), 0));
|
||||
Object::ByGuid(kUnitOrPlayerMask, guid, nullptr, 0));
|
||||
if (unit == nullptr)
|
||||
return false;
|
||||
const auto *desc = *reinterpret_cast<const uint8_t *const *>(
|
||||
@@ -330,15 +325,18 @@ void Evict(uint64_t targetGuid, uint32_t spellId) {
|
||||
// notifies the aura's target-if-a-player (self-scoped), never the observing
|
||||
// caster; on a mob the packet isn't even built. We can't hear the *change*,
|
||||
// but we DO see the TRIGGERING cast's SMSG_SPELL_GO, so we mirror the
|
||||
// server's edit on the cached entry. Rules come from Lua
|
||||
// (`C_UnitAuras.RegisterAuraDurationModifier`), so the server-specific set
|
||||
// lives in the addon, not the DLL. Turtle examples:
|
||||
// server's edit on the cached entry. Rules are registered two ways: the
|
||||
// family/school-matched form from Lua (`RegisterAuraDurationModifierByTrigger`,
|
||||
// e.g. Shadow Weaving), and the exact-spellID form from C++ (`AddDurationMod`),
|
||||
// which src/turtle uses for the server's built-in mods. Turtle examples
|
||||
// (registered in src/turtle/DurationMods.cpp):
|
||||
// Conflagrate -> Immolate: reduce 3s (Immolate keeps ticking, -3s)
|
||||
// Molten Blast -> Flame Shock: refresh (RefreshHolder → reset to max)
|
||||
// A trigger is matched by exact spellID (from the server's script binding,
|
||||
// stable across ranks); the affected aura by SpellFamilyName + a family-flag
|
||||
// overlap (+ optional icon) — rank-proof, exactly how the server's scripts
|
||||
// find it. Conflagrate's *full*-consume path removes Immolate, which clears
|
||||
// A trigger is matched either by exact spellID (from the server's script
|
||||
// binding, stable across ranks) or by SpellFamilyName + school; the affected
|
||||
// aura by SpellFamilyName + a family-flag overlap (+ optional icon) — rank-proof,
|
||||
// exactly how the server's scripts find it. Conflagrate's *full*-consume path
|
||||
// removes Immolate, which clears
|
||||
// the descriptor slot → OnAuraRemoved already handles it; the reduce rule
|
||||
// covers the keep-ticking case. Probabilistic refreshes (Carnage's roll) are
|
||||
// deliberately NOT shipped as defaults — the client can't know the server's
|
||||
@@ -360,23 +358,24 @@ constexpr int kMaxMods = 128;
|
||||
DurationMod g_mods[kMaxMods];
|
||||
int g_modCount = 0;
|
||||
|
||||
bool AffectedMatches(const uint8_t *rec, const DurationMod &m) {
|
||||
if (rec == nullptr)
|
||||
// The affected-aura selector alone, shared with the Lua-facing by-family
|
||||
// refresh so the two cannot disagree about what they match.
|
||||
bool AffectedMatchesRaw(const uint8_t *rec, uint32_t family, uint64_t mask,
|
||||
uint32_t icon) {
|
||||
if (!Spell::Lookup::IsFitToFamily(rec, family, mask))
|
||||
return false;
|
||||
if (*reinterpret_cast<const uint32_t *>(
|
||||
rec + Offsets::OFF_SPELL_RECORD_FAMILY_NAME) != m.affectedFamily)
|
||||
return false;
|
||||
const uint64_t flags = *reinterpret_cast<const uint64_t *>(
|
||||
rec + Offsets::OFF_SPELL_RECORD_FAMILY_FLAGS);
|
||||
if ((flags & m.affectedMask) == 0)
|
||||
return false;
|
||||
if (m.affectedIcon != 0 &&
|
||||
if (icon != 0 &&
|
||||
*reinterpret_cast<const uint32_t *>(
|
||||
rec + Offsets::OFF_SPELL_RECORD_ICON_ID) != m.affectedIcon)
|
||||
rec + Offsets::OFF_SPELL_RECORD_ICON_ID) != icon)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AffectedMatches(const uint8_t *rec, const DurationMod &m) {
|
||||
return AffectedMatchesRaw(rec, m.affectedFamily, m.affectedMask,
|
||||
m.affectedIcon);
|
||||
}
|
||||
|
||||
// A rule's trigger matches either by exact spellID, or (triggerSpellId == 0)
|
||||
// by the cast spell's SpellFamilyName + school index — one rule then covers
|
||||
// every rank / server-added spell of a class's school (e.g. any priest
|
||||
@@ -397,26 +396,62 @@ bool TriggerMatches(const DurationMod &m, uint32_t triggerSpellId,
|
||||
return true;
|
||||
}
|
||||
|
||||
// A cache duration edit has no engine packet behind it, so nothing re-fires
|
||||
// UNIT_AURA and event-driven consumers (aura-bar addons that read the duration
|
||||
// once and count down locally) never see the change. Re-broadcast UNIT_AURA for
|
||||
// the affected unit so they re-read. Deferred to the world tick, not fired
|
||||
// inline: the callers run inside the SMSG_SPELL_GO subscriber, and firing a
|
||||
// unit event there would run addon Lua mid-packet (the re-entrancy class this
|
||||
// codebase keeps getting bitten by). The tick flush is the context the engine's
|
||||
// own UNIT_AURA fires are safe in. Repeats within a frame are coalesced.
|
||||
constexpr int kPendingSignalMax = 32;
|
||||
uint64_t g_pendingSignals[kPendingSignalMax];
|
||||
int g_pendingSignalCount = 0;
|
||||
|
||||
void SignalAuraChanged(uint64_t guid) {
|
||||
if (guid == 0)
|
||||
return;
|
||||
for (int i = 0; i < g_pendingSignalCount; ++i)
|
||||
if (g_pendingSignals[i] == guid)
|
||||
return;
|
||||
if (g_pendingSignalCount < kPendingSignalMax)
|
||||
g_pendingSignals[g_pendingSignalCount++] = guid;
|
||||
}
|
||||
|
||||
void FlushAuraSignals() {
|
||||
using Broadcast_t = void(__fastcall *)(uint64_t *guid, uint32_t eventCode);
|
||||
auto broadcast = reinterpret_cast<Broadcast_t>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_UNIT_EVENT_BROADCAST));
|
||||
for (int i = 0; i < g_pendingSignalCount; ++i)
|
||||
broadcast(&g_pendingSignals[i], Offsets::UNIT_EVENT_UNIT_AURA);
|
||||
g_pendingSignalCount = 0;
|
||||
}
|
||||
|
||||
void ApplyMod(Entry &e, const DurationMod &m, uint32_t now) {
|
||||
switch (m.op) {
|
||||
case MOD_REFRESH:
|
||||
if (e.durationMs > 0)
|
||||
if (e.durationMs > 0) {
|
||||
e.expirationMs = now + e.durationMs; // RefreshHolder → reset to max
|
||||
SignalAuraChanged(e.targetGuid);
|
||||
}
|
||||
break;
|
||||
case MOD_SET:
|
||||
e.durationMs = static_cast<uint32_t>(m.valueMs);
|
||||
e.expirationMs = now + static_cast<uint32_t>(m.valueMs);
|
||||
SignalAuraChanged(e.targetGuid);
|
||||
break;
|
||||
case MOD_REDUCE:
|
||||
if (e.expirationMs != 0) {
|
||||
if (e.expirationMs > now + static_cast<uint32_t>(m.valueMs))
|
||||
if (e.expirationMs > now + static_cast<uint32_t>(m.valueMs)) {
|
||||
e.expirationMs -= static_cast<uint32_t>(m.valueMs);
|
||||
else
|
||||
SignalAuraChanged(e.targetGuid);
|
||||
} else {
|
||||
e.used = false; // shaved to/past now → server removes it
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MOD_REMOVE:
|
||||
e.used = false;
|
||||
e.used = false; // removal — OnAuraRemoved / descriptor path fires UNIT_AURA
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -499,40 +534,6 @@ int OpFromString(const char *s) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// `C_UnitAuras.RegisterAuraDurationModifier(triggerSpellID, affectedFamily,
|
||||
// affectedFamilyFlags, affectedIcon, op [, valueSeconds])` -> bool.
|
||||
// op: "refresh" | "reduce" | "set" | "remove". valueSeconds used by
|
||||
// reduce/set. affectedIcon 0 = match any icon. Re-registering an identical
|
||||
// (trigger, family, flags, icon) tuple replaces its op/value.
|
||||
int __fastcall Script_RegisterAuraDurationModifier(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1) || !Game::Lua::IsNumber(L, 2) ||
|
||||
!Game::Lua::IsNumber(L, 3) || !Game::Lua::IsNumber(L, 4) ||
|
||||
!Game::Lua::IsString(L, 5)) {
|
||||
Game::Lua::Error(
|
||||
L, "Usage: C_UnitAuras.RegisterAuraDurationModifier(triggerSpellID, "
|
||||
"affectedFamily, affectedFamilyFlags, affectedIcon, op[, "
|
||||
"valueSeconds])");
|
||||
return 0;
|
||||
}
|
||||
const auto trigger = static_cast<uint32_t>(Game::Lua::ToNumber(L, 1));
|
||||
const auto family = static_cast<uint32_t>(Game::Lua::ToNumber(L, 2));
|
||||
const auto mask = static_cast<uint64_t>(Game::Lua::ToNumber(L, 3));
|
||||
const auto icon = static_cast<uint32_t>(Game::Lua::ToNumber(L, 4));
|
||||
const int op = OpFromString(Game::Lua::ToString(L, 5));
|
||||
const int32_t valueMs =
|
||||
Game::Lua::IsNumber(L, 6)
|
||||
? static_cast<int32_t>(Game::Lua::ToNumber(L, 6) * 1000.0)
|
||||
: 0;
|
||||
if (op < 0) {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
}
|
||||
Game::Lua::PushBool(L, RegisterDurationMod(trigger, /*triggerFamily*/ 0,
|
||||
/*triggerSchool*/ -1, family, mask,
|
||||
icon, op, valueMs));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// `C_UnitAuras.RegisterAuraDurationModifierByTrigger(triggerFamily,
|
||||
// triggerSchool, affectedFamily, affectedFamilyFlags, affectedIcon, op
|
||||
// [, valueSeconds])` -> bool. Like the above, but the trigger is matched
|
||||
@@ -570,8 +571,6 @@ int __fastcall Script_RegisterAuraDurationModifierByTrigger(void *L) {
|
||||
}
|
||||
|
||||
void RegisterDurationModLua() {
|
||||
Game::Lua::RegisterTableFunction("C_UnitAuras", "RegisterAuraDurationModifier",
|
||||
&Script_RegisterAuraDurationModifier);
|
||||
Game::Lua::RegisterTableFunction("C_UnitAuras",
|
||||
"RegisterAuraDurationModifierByTrigger",
|
||||
&Script_RegisterAuraDurationModifierByTrigger);
|
||||
@@ -638,6 +637,9 @@ void OnWorldTick() {
|
||||
if (s.used && now - s.touchMs > kGroupSnapshotTtlMs)
|
||||
s.used = false;
|
||||
}
|
||||
// Re-fire UNIT_AURA for units whose cached duration a mod/refresh changed
|
||||
// this frame (see SignalAuraChanged).
|
||||
FlushAuraSignals();
|
||||
}
|
||||
|
||||
const Tick::WorldTick::AutoSubscribe _tickSub{&OnWorldTick};
|
||||
@@ -867,6 +869,48 @@ bool Get(uint64_t unitGuid, uint32_t spellId, uint64_t *outCaster,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AddDurationMod(uint32_t triggerSpellId, uint32_t affectedFamily,
|
||||
uint64_t affectedMask, uint32_t affectedIcon, int op,
|
||||
int32_t valueMs) {
|
||||
// Exact-spellID trigger (triggerFamily 0, triggerSchool -1).
|
||||
return RegisterDurationMod(triggerSpellId, /*triggerFamily*/ 0,
|
||||
/*triggerSchool*/ -1, affectedFamily, affectedMask,
|
||||
affectedIcon, op, valueMs);
|
||||
}
|
||||
|
||||
uint32_t RefreshDurationByFamily(uint64_t unitGuid, uint32_t family,
|
||||
uint64_t mask, uint32_t icon,
|
||||
uint64_t casterGuid) {
|
||||
if (unitGuid == 0 || mask == 0 || casterGuid == 0)
|
||||
return 0;
|
||||
const uint32_t now = NowMs();
|
||||
for (auto &e : g_cache) {
|
||||
if (!e.used || e.targetGuid != unitGuid)
|
||||
continue;
|
||||
// Caller's own aura only, scoped as ApplyDurationModifiers scopes a
|
||||
// rule; a caster-less entry is claimed rather than skipped, same as
|
||||
// there.
|
||||
if (e.casterGuid != 0 && e.casterGuid != casterGuid)
|
||||
continue;
|
||||
if (!AffectedMatchesRaw(
|
||||
Spell::Lookup::RecordForID(static_cast<int>(e.spellId)), family,
|
||||
mask, icon))
|
||||
continue;
|
||||
if (e.durationMs == 0)
|
||||
continue; // never invent a duration
|
||||
if (e.casterGuid == 0)
|
||||
e.casterGuid = casterGuid;
|
||||
// The applied duration, not a recomputed one (the server's
|
||||
// RefreshHolder): a Rip cast at 3 combo points returns to its own
|
||||
// duration, not a five-point one.
|
||||
e.expirationMs = now + e.durationMs;
|
||||
e.stampMs = now;
|
||||
SignalAuraChanged(e.targetGuid);
|
||||
return e.spellId;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EvictAbsent(uint64_t unitGuid, const uint32_t *presentSpellIds, int count) {
|
||||
if (unitGuid == 0 || presentSpellIds == nullptr || count <= 0)
|
||||
return;
|
||||
|
||||
@@ -42,6 +42,34 @@ namespace Aura::Source {
|
||||
bool Get(uint64_t unitGuid, uint32_t spellId, uint64_t *outCaster,
|
||||
uint32_t *outExpirationMs, uint32_t *outDurationMs);
|
||||
|
||||
// Refreshes `casterGuid`'s aura on `unitGuid` matching the same selector the
|
||||
// duration rules use — SpellFamilyName + family-flag overlap + optional icon
|
||||
// (0 = any) — to a full duration from now. Returns the spellID refreshed, or 0
|
||||
// if nothing matched. For a mechanic whose duration edit reaches the client
|
||||
// too late to be attributed to a cast packet, so no rule can express it.
|
||||
uint32_t RefreshDurationByFamily(uint64_t unitGuid, uint32_t family,
|
||||
uint64_t mask, uint32_t icon,
|
||||
uint64_t casterGuid);
|
||||
|
||||
// Op codes for AddDurationMod (mirror the Lua op strings).
|
||||
enum DurationModOp {
|
||||
DURATION_MOD_REFRESH = 0,
|
||||
DURATION_MOD_REDUCE = 1,
|
||||
DURATION_MOD_SET = 2,
|
||||
DURATION_MOD_REMOVE = 3,
|
||||
};
|
||||
|
||||
// Register a server duration-modifier rule from C++. The trigger is matched by
|
||||
// exact `triggerSpellId`; the affected aura by SpellFamilyName + a family-flag
|
||||
// overlap (+ optional `affectedIcon`, 0 = any). `valueMs` is the reduce/set
|
||||
// amount in milliseconds (ignored by refresh/remove). Used by src/turtle
|
||||
// modules for the server's built-in mods (the family/school-matched variant is
|
||||
// still Lua-registerable via C_UnitAuras.RegisterAuraDurationModifierByTrigger).
|
||||
// Returns false on bad input or a full table.
|
||||
bool AddDurationMod(uint32_t triggerSpellId, uint32_t affectedFamily,
|
||||
uint64_t affectedMask, uint32_t affectedIcon, int op,
|
||||
int32_t valueMs);
|
||||
|
||||
// One cached aura, as returned by `Enumerate`.
|
||||
struct CachedAura {
|
||||
uint32_t spellId;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
// Tiny ASCII string helpers. Header-only — no locale, no allocation, safe from
|
||||
// any context (hook callbacks, DBC walks). Use these instead of hand-rolling
|
||||
// yet another case-insensitive compare.
|
||||
|
||||
namespace Ascii {
|
||||
|
||||
// Fold a single ASCII char to lower case (non-letters unchanged).
|
||||
inline char ToLower(char c) {
|
||||
return (c >= 'A' && c <= 'Z') ? static_cast<char>(c - 'A' + 'a') : c;
|
||||
}
|
||||
|
||||
// Case-insensitive full-string equality over ASCII. Two null pointers compare
|
||||
// equal; a null vs non-null does not.
|
||||
inline bool EqualCI(const char *a, const char *b) {
|
||||
if (a == nullptr || b == nullptr)
|
||||
return a == b;
|
||||
for (; *a && *b; ++a, ++b)
|
||||
if (ToLower(*a) != ToLower(*b))
|
||||
return false;
|
||||
return *a == *b;
|
||||
}
|
||||
|
||||
} // namespace Ascii
|
||||
+8
-30
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Names.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -22,21 +23,11 @@ namespace Classes::Info {
|
||||
|
||||
namespace {
|
||||
|
||||
const uint8_t *const *Records() {
|
||||
return *reinterpret_cast<const uint8_t *const *const *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CHRCLASSES_RECORDS));
|
||||
}
|
||||
|
||||
int Count() {
|
||||
return *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CHRCLASSES_COUNT));
|
||||
}
|
||||
|
||||
int LocaleIndex() {
|
||||
return *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_LOCALE_INDEX));
|
||||
}
|
||||
|
||||
// `FillLocalizedClassList(table [, isFemale]) → table` — fills the
|
||||
// passed-in table with `[classToken] = localizedName` pairs for every
|
||||
// class in `ChrClasses.dbc`, then returns the same table for chaining.
|
||||
@@ -58,15 +49,7 @@ int __fastcall Script_FillLocalizedClassList(void *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto *records = Records();
|
||||
if (records == nullptr) {
|
||||
// DBC not loaded yet — return the table unchanged. Matches
|
||||
// modern behavior of "fill what's available, don't crash".
|
||||
Game::Lua::SetTop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
const int count = Count();
|
||||
const int locale = LocaleIndex();
|
||||
|
||||
// Drop the optional `isFemale` arg (and any further junk) so the
|
||||
// table sits alone at idx 1. Each loop iteration pushes key+value
|
||||
@@ -74,19 +57,14 @@ int __fastcall Script_FillLocalizedClassList(void *L) {
|
||||
// [table] before the next iteration.
|
||||
Game::Lua::SetTop(L, 1);
|
||||
for (int i = 1; i <= count; i++) {
|
||||
const uint8_t *record = records[i];
|
||||
if (record == nullptr)
|
||||
// DBC::* are null-safe (empty result if ChrClasses.dbc isn't loaded)
|
||||
// and skip empty strings, so a sparse/absent class id just falls
|
||||
// through — same "fill what's available, don't crash" behavior.
|
||||
const char *token = DBC::ClassToken(static_cast<uint32_t>(i));
|
||||
if (token == nullptr)
|
||||
continue;
|
||||
|
||||
const char *token = *reinterpret_cast<const char *const *>(
|
||||
record + Offsets::OFF_CHRCLASSES_FILENAME);
|
||||
if (token == nullptr || *token == '\0')
|
||||
continue;
|
||||
|
||||
const char *const *names = reinterpret_cast<const char *const *>(
|
||||
record + Offsets::OFF_CHRCLASSES_NAMES);
|
||||
const char *name = names[locale];
|
||||
if (name == nullptr || *name == '\0')
|
||||
const char *name = DBC::ClassName(static_cast<uint32_t>(i));
|
||||
if (name == nullptr)
|
||||
continue;
|
||||
|
||||
Game::Lua::PushString(L, token);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "item/BagFamily.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -23,21 +24,6 @@ namespace Container::FreeSlots {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
// Same `Peek the item cache without firing a query` shape as
|
||||
// `Item::Info::FetchItemRecord`. We don't share that helper because it's
|
||||
// file-static there; copying the four-line lookup is simpler than
|
||||
// promoting it to a header for one extra caller.
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
// Resolves the bag's metadata: total slot count + BagFamily bitfield.
|
||||
//
|
||||
// - bagID 0 (backpack) → (16, 0). Vanilla 1.12 backpack is fixed at 16
|
||||
@@ -68,7 +54,7 @@ BagInfo ResolveBagInfo(int bagID) {
|
||||
if (itemID == 0)
|
||||
return {0, 0};
|
||||
|
||||
auto *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
auto *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr)
|
||||
return {0, 0};
|
||||
|
||||
|
||||
@@ -50,9 +50,11 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Link.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
#include "item/StatAccum.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -80,8 +82,7 @@ bool ItemReadable(const uint8_t *item, const uint8_t *record) {
|
||||
if (record != nullptr &&
|
||||
*reinterpret_cast<const uint32_t *>(record + Offsets::OFF_ITEMSTATS_PAGE_TEXT) != 0)
|
||||
return true;
|
||||
const uint8_t *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
const uint8_t *descriptor = Item::ObjectFields(item);
|
||||
return descriptor != nullptr &&
|
||||
*reinterpret_cast<const uint32_t *>(
|
||||
descriptor + Offsets::OFF_DESCRIPTOR_READABLE_TEXT_ID) != 0;
|
||||
@@ -107,12 +108,11 @@ int __fastcall Script_C_Container_GetContainerItemInfo(void *L) {
|
||||
// them off the half-built table avoids any stack interleaving. ---
|
||||
const int itemID = Item::ID::FromCGItem(item);
|
||||
const uint8_t *record = (itemID > 0)
|
||||
? Item::StatAccum::FetchRecord(static_cast<uint32_t>(itemID))
|
||||
? Item::PeekRecord(static_cast<uint32_t>(itemID))
|
||||
: nullptr;
|
||||
|
||||
// Live per-instance descriptor fields.
|
||||
const uint8_t *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
const uint8_t *descriptor = Item::ObjectFields(item);
|
||||
int stackCount = 0;
|
||||
bool isBound = false;
|
||||
if (descriptor != nullptr) {
|
||||
|
||||
+5
-18
@@ -54,6 +54,7 @@
|
||||
#include "Offsets.h"
|
||||
#include "cache/QueryLoad.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "dbc/Names.h"
|
||||
#include "event/Custom.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -143,17 +144,10 @@ int __fastcall Script_GetRaceInfo(void *L) {
|
||||
return 0; // nil
|
||||
const int raceID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
const char *file =
|
||||
(raceID > 0) ? DBC::StringField(Offsets::VAR_CHRRACES_RECORDS,
|
||||
Offsets::VAR_CHRRACES_COUNT,
|
||||
static_cast<uint32_t>(raceID),
|
||||
Offsets::OFF_CHRRACES_FILENAME)
|
||||
: nullptr;
|
||||
(raceID > 0) ? DBC::RaceToken(static_cast<uint32_t>(raceID)) : nullptr;
|
||||
if (file == nullptr)
|
||||
return 0; // unknown id -> nil
|
||||
const char *name = DBC::LocalizedField(Offsets::VAR_CHRRACES_RECORDS,
|
||||
Offsets::VAR_CHRRACES_COUNT,
|
||||
static_cast<uint32_t>(raceID),
|
||||
Offsets::OFF_CHRRACES_NAMES);
|
||||
const char *name = DBC::RaceName(static_cast<uint32_t>(raceID));
|
||||
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetFieldString(L, "raceName", name); // NULL coerced to ""
|
||||
@@ -169,17 +163,10 @@ int __fastcall Script_GetClassInfo(void *L) {
|
||||
return 0; // nil
|
||||
const int classID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
const char *file =
|
||||
(classID > 0) ? DBC::StringField(Offsets::VAR_CHRCLASSES_RECORDS,
|
||||
Offsets::VAR_CHRCLASSES_COUNT,
|
||||
static_cast<uint32_t>(classID),
|
||||
Offsets::OFF_CHRCLASSES_FILENAME)
|
||||
: nullptr;
|
||||
(classID > 0) ? DBC::ClassToken(static_cast<uint32_t>(classID)) : nullptr;
|
||||
if (file == nullptr)
|
||||
return 0; // unknown id -> nil
|
||||
const char *name = DBC::LocalizedField(Offsets::VAR_CHRCLASSES_RECORDS,
|
||||
Offsets::VAR_CHRCLASSES_COUNT,
|
||||
static_cast<uint32_t>(classID),
|
||||
Offsets::OFF_CHRCLASSES_NAMES);
|
||||
const char *name = DBC::ClassName(static_cast<uint32_t>(classID));
|
||||
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetFieldString(L, "className", name); // NULL coerced to ""
|
||||
|
||||
+2
-12
@@ -53,6 +53,7 @@
|
||||
#include "item/Link.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/QualityColor.h"
|
||||
#include "item/Record.h"
|
||||
#include "spell/Lookup.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -140,17 +141,6 @@ int PushBagItemCursor(void *L) {
|
||||
return PushItem(L, cgItem);
|
||||
}
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
// Builds a basic `"|cffRRGGBB|Hitem:N:0:0:0|h[Name]|h|r"` link from
|
||||
// the cached ItemStats record for `itemID`. No enchant / random-
|
||||
// suffix decoration — the cursor only stores the bare itemID for
|
||||
@@ -158,7 +148,7 @@ const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
// instance state from. Returns true and writes into `out` (size
|
||||
// `outSize`) on success; returns false if the item isn't cached.
|
||||
bool BuildBasicItemLink(uint32_t itemID, char *out, size_t outSize) {
|
||||
const uint8_t *record = PeekItemRecord(itemID);
|
||||
const uint8_t *record = Item::PeekRecord(itemID);
|
||||
if (record == nullptr) return false;
|
||||
const char *name = *reinterpret_cast<const char *const *>(
|
||||
record + Offsets::OFF_ITEMSTATS_NAME);
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "Names.h"
|
||||
|
||||
#include "Lookup.h"
|
||||
#include "Offsets.h"
|
||||
#include "baselib/Ascii.h"
|
||||
|
||||
namespace DBC {
|
||||
|
||||
namespace {
|
||||
|
||||
// Reverse lookup shared by ClassIdForToken / RaceIdForToken: the id whose
|
||||
// single-string field at `offset` matches `token` (case-insensitive), or 0.
|
||||
uint32_t IdForStringField(uintptr_t recordsVar, uintptr_t countVar, int offset,
|
||||
const char *token) {
|
||||
if (token == nullptr || *token == '\0')
|
||||
return 0;
|
||||
const int count = *reinterpret_cast<const int *>(countVar);
|
||||
const uint8_t *const *records =
|
||||
*reinterpret_cast<const uint8_t *const *const *>(recordsVar);
|
||||
if (records == nullptr)
|
||||
return 0;
|
||||
for (int i = 1; i <= count; ++i) {
|
||||
const uint8_t *rec = records[i];
|
||||
if (rec == nullptr)
|
||||
continue;
|
||||
const char *field =
|
||||
*reinterpret_cast<const char *const *>(rec + offset);
|
||||
if (field != nullptr && Ascii::EqualCI(field, token))
|
||||
return static_cast<uint32_t>(i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const char *ClassName(uint32_t classID) {
|
||||
if (classID == 0)
|
||||
return nullptr;
|
||||
return LocalizedField(Offsets::VAR_CHRCLASSES_RECORDS,
|
||||
Offsets::VAR_CHRCLASSES_COUNT, classID,
|
||||
Offsets::OFF_CHRCLASSES_NAMES);
|
||||
}
|
||||
|
||||
const char *ClassToken(uint32_t classID) {
|
||||
if (classID == 0)
|
||||
return nullptr;
|
||||
return StringField(Offsets::VAR_CHRCLASSES_RECORDS,
|
||||
Offsets::VAR_CHRCLASSES_COUNT, classID,
|
||||
Offsets::OFF_CHRCLASSES_FILENAME);
|
||||
}
|
||||
|
||||
const char *RaceName(uint32_t raceID) {
|
||||
if (raceID == 0)
|
||||
return nullptr;
|
||||
return LocalizedField(Offsets::VAR_CHRRACES_RECORDS,
|
||||
Offsets::VAR_CHRRACES_COUNT, raceID,
|
||||
Offsets::OFF_CHRRACES_NAMES);
|
||||
}
|
||||
|
||||
const char *RaceToken(uint32_t raceID) {
|
||||
if (raceID == 0)
|
||||
return nullptr;
|
||||
return StringField(Offsets::VAR_CHRRACES_RECORDS,
|
||||
Offsets::VAR_CHRRACES_COUNT, raceID,
|
||||
Offsets::OFF_CHRRACES_FILENAME);
|
||||
}
|
||||
|
||||
uint32_t ClassIdForToken(const char *token) {
|
||||
return IdForStringField(Offsets::VAR_CHRCLASSES_RECORDS,
|
||||
Offsets::VAR_CHRCLASSES_COUNT,
|
||||
Offsets::OFF_CHRCLASSES_FILENAME, token);
|
||||
}
|
||||
|
||||
uint32_t RaceIdForToken(const char *token) {
|
||||
return IdForStringField(Offsets::VAR_CHRRACES_RECORDS,
|
||||
Offsets::VAR_CHRRACES_COUNT,
|
||||
Offsets::OFF_CHRRACES_FILENAME, token);
|
||||
}
|
||||
|
||||
const char *AreaName(uint32_t areaID, bool resolveToParent) {
|
||||
if (areaID == 0)
|
||||
return nullptr;
|
||||
// Only the parent-resolving path needs the record; the direct read goes
|
||||
// straight through LocalizedField (which bounds-checks the id itself), so
|
||||
// the common !resolveToParent case is a single lookup.
|
||||
uint32_t use = areaID;
|
||||
if (resolveToParent) {
|
||||
const uint8_t *rec = Record(Offsets::VAR_AREATABLE_RECORDS,
|
||||
Offsets::VAR_AREATABLE_COUNT, areaID);
|
||||
if (rec != nullptr) {
|
||||
const uint32_t parent = *reinterpret_cast<const uint32_t *>(
|
||||
rec + Offsets::OFF_AREATABLE_PARENT_ID);
|
||||
if (parent != 0 &&
|
||||
Record(Offsets::VAR_AREATABLE_RECORDS,
|
||||
Offsets::VAR_AREATABLE_COUNT, parent) != nullptr)
|
||||
use = parent;
|
||||
}
|
||||
}
|
||||
return LocalizedField(Offsets::VAR_AREATABLE_RECORDS,
|
||||
Offsets::VAR_AREATABLE_COUNT, use,
|
||||
Offsets::OFF_AREATABLE_NAMES);
|
||||
}
|
||||
|
||||
} // namespace DBC
|
||||
@@ -0,0 +1,54 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// `DBC::*` display-name resolvers for the character/zone DBCs. Thin wrappers
|
||||
// over `DBC::Record` / `LocalizedField` / `StringField` (see `Lookup.h`) that
|
||||
// bake in the specific table + field for a game concept, so callers don't
|
||||
// repeat the `(recordsVar, countVar, id, offset)` tuple. Shared by the
|
||||
// friends-list and /who surfaces (and any future class/race/zone display).
|
||||
// All return `nullptr` when the id is 0 / out of range / the field is empty.
|
||||
|
||||
namespace DBC {
|
||||
|
||||
// Localized class name for a `ChrClasses.dbc` id (e.g. "Mage").
|
||||
const char *ClassName(uint32_t classID);
|
||||
|
||||
// Locale-independent class token for a `ChrClasses.dbc` id (e.g. "MAGE") —
|
||||
// the key addons use for RAID_CLASS_COLORS and other class tables.
|
||||
const char *ClassToken(uint32_t classID);
|
||||
|
||||
// Localized race name for a `ChrRaces.dbc` id (e.g. "Night Elf").
|
||||
const char *RaceName(uint32_t raceID);
|
||||
|
||||
// Locale-independent race token for a `ChrRaces.dbc` id — the client-filename
|
||||
// column (e.g. "NightElf", "Scourge"), the race analog of ClassToken and what
|
||||
// `UnitRace`'s second return / GetPlayerInfoByGUID's englishRace use.
|
||||
const char *RaceToken(uint32_t raceID);
|
||||
|
||||
// Reverse of ClassToken / RaceToken: the `ChrClasses.dbc` / `ChrRaces.dbc` id
|
||||
// whose client-filename token matches `token` (case-insensitive), or 0 if none
|
||||
// matches. Walks the table (cheap — a handful of records).
|
||||
uint32_t ClassIdForToken(const char *token);
|
||||
uint32_t RaceIdForToken(const char *token);
|
||||
|
||||
// Localized zone name for an `AreaTable.dbc` id. When `resolveToParent` is
|
||||
// true, a sub-area reports its parent zone (so "Goldshire" → "Elwynn
|
||||
// Forest"); when false, the area's own name is returned (what the engine's
|
||||
// GetWhoInfo does — /who zones are already zone-level).
|
||||
const char *AreaName(uint32_t areaID, bool resolveToParent);
|
||||
|
||||
} // namespace DBC
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "Offsets.h"
|
||||
#include "Set.h"
|
||||
#include "event/Custom.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Swap.h"
|
||||
|
||||
@@ -72,8 +73,7 @@ const char *ArgString(void *L, int idx) {
|
||||
int ResolveItemID(const uint8_t *cgItem) {
|
||||
if (cgItem == nullptr)
|
||||
return 0;
|
||||
auto *instance = *reinterpret_cast<const uint8_t *const *>(
|
||||
cgItem + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *instance = Item::InstanceBlock(cgItem);
|
||||
if (instance == nullptr)
|
||||
return 0;
|
||||
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "Offsets.h"
|
||||
#include "item/Location.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -58,13 +59,7 @@ int InvMgrSlotCount(const uint8_t *invMgr) {
|
||||
uint8_t *ResolveByGUID(int type, uint64_t guid) {
|
||||
if (guid == 0)
|
||||
return nullptr;
|
||||
using ResolveByGUID_t = void *(__fastcall *)(int, const char *, uint32_t,
|
||||
uint32_t, int);
|
||||
auto fn = reinterpret_cast<ResolveByGUID_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
return static_cast<uint8_t *>(fn(type, "ItemMgr",
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32),
|
||||
0x172));
|
||||
return static_cast<uint8_t *>(Object::ByGuid(type, guid, "ItemMgr", 0x172));
|
||||
}
|
||||
|
||||
// Walks one bag's contents for a matching GUID. Returns the 1-based
|
||||
@@ -73,7 +68,7 @@ uint8_t *ResolveByGUID(int type, uint64_t guid) {
|
||||
// bank bags (linear 63..68) — the only differences are the source of
|
||||
// the bag's GUID and how the result encodes back into a location.
|
||||
int WalkBagContents(uint64_t bagGuid, uint64_t targetGuid) {
|
||||
auto *bag = ResolveByGUID(Offsets::OBJ_TYPE_CONTAINER, bagGuid);
|
||||
auto *bag = ResolveByGUID(Offsets::TYPEMASK_CONTAINER, bagGuid);
|
||||
if (bag == nullptr)
|
||||
return 0;
|
||||
auto *bagInvMgr =
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include "equipmentset/Data.h"
|
||||
#include "equipmentset/Locations.h"
|
||||
#include "equipmentset/Set.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -108,17 +109,6 @@ struct Tally {
|
||||
uint32_t missingItemIDs[SLOT_COUNT];
|
||||
};
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
// Walks a set's slots, classifying each non-empty entry into the
|
||||
// equipped / in-inventory / ignored / missing buckets via
|
||||
// `Locations::FindGUID`. For missing slots, also records the saved
|
||||
@@ -215,7 +205,7 @@ int __fastcall Script_GameTooltipSetEquipmentSet(void *L) {
|
||||
unnamedMissing++;
|
||||
continue;
|
||||
}
|
||||
auto *record = PeekItemRecord(id);
|
||||
auto *record = Item::PeekRecord(id);
|
||||
if (record == nullptr) {
|
||||
unnamedMissing++;
|
||||
continue;
|
||||
|
||||
+17
-29
@@ -96,7 +96,9 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "baselib/Ascii.h"
|
||||
#include "cursor/Info.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "spell/AtCursor.h"
|
||||
#include "spell/AtUnit.h"
|
||||
#include "tick/WorldTick.h"
|
||||
@@ -147,15 +149,6 @@ void Compose3Lower(char *dst, size_t n, const char *a, const char *b, const char
|
||||
dst[i] = '\0';
|
||||
}
|
||||
|
||||
// ASCII case-insensitive full-string equality.
|
||||
bool EqI(const char *a, const char *b) {
|
||||
for (; *a && *b; ++a, ++b)
|
||||
if (std::tolower(static_cast<unsigned char>(*a)) !=
|
||||
std::tolower(static_cast<unsigned char>(*b)))
|
||||
return false;
|
||||
return *a == *b;
|
||||
}
|
||||
|
||||
// True if `lname` (already lowercase) is a click "type" action attribute: an
|
||||
// optional modifier prefix (alt-/ctrl-/shift-, any order/combo) followed by
|
||||
// "type" and an optional button digit — i.e. anything the click resolver
|
||||
@@ -419,12 +412,7 @@ bool GuidHasLiveUnit(uint64_t guid) {
|
||||
return false;
|
||||
constexpr int kUnitOrPlayerMask =
|
||||
(1 << Offsets::OBJECT_TYPE_UNIT) | (1 << Offsets::OBJECT_TYPE_PLAYER);
|
||||
auto resolve = reinterpret_cast<void *(__fastcall *)(int, const char *, uint32_t,
|
||||
uint32_t, int)>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID));
|
||||
return resolve(kUnitOrPlayerMask, "ClassicAPI",
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), 0) != nullptr;
|
||||
return Object::ByGuid(kUnitOrPlayerMask, guid, "ClassicAPI", 0) != nullptr;
|
||||
}
|
||||
|
||||
// Build the mouseover tooltip for a unit with no live object, straight from the
|
||||
@@ -510,10 +498,10 @@ void BuildModifierPrefix(void *L, char *buf, size_t n) {
|
||||
|
||||
// Button name -> attribute suffix (retail's convention: the button number).
|
||||
const char *ButtonSuffix(const char *btn) {
|
||||
if (EqI(btn, "RightButton")) return "2";
|
||||
if (EqI(btn, "MiddleButton")) return "3";
|
||||
if (EqI(btn, "Button4")) return "4";
|
||||
if (EqI(btn, "Button5")) return "5";
|
||||
if (Ascii::EqualCI(btn, "RightButton")) return "2";
|
||||
if (Ascii::EqualCI(btn, "MiddleButton")) return "3";
|
||||
if (Ascii::EqualCI(btn, "Button4")) return "4";
|
||||
if (Ascii::EqualCI(btn, "Button5")) return "5";
|
||||
return "1"; // LeftButton / unknown
|
||||
}
|
||||
|
||||
@@ -601,10 +589,10 @@ bool CallGlobalNum2(void *L, const char *name, double a, double b) {
|
||||
// Returns true if it owned the click (so the chained handler is skipped).
|
||||
bool DispatchVerb(void *L, int fi, const char *prefix, const char *suffix,
|
||||
const char *verb, const char *unit) {
|
||||
if (EqI(verb, "target")) {
|
||||
if (Ascii::EqualCI(verb, "target")) {
|
||||
if (!unit) return false;
|
||||
// `unit="none"` clears the target (retail's SecureActionButton behavior).
|
||||
if (EqI(unit, "none")) {
|
||||
if (Ascii::EqualCI(unit, "none")) {
|
||||
Game::Lua::CallGlobal(L, "ClearTarget");
|
||||
return true;
|
||||
}
|
||||
@@ -621,17 +609,17 @@ bool DispatchVerb(void *L, int fi, const char *prefix, const char *suffix,
|
||||
Game::Lua::CallGlobalString(L, "TargetUnit", unit);
|
||||
return true;
|
||||
}
|
||||
if (EqI(verb, "assist")) {
|
||||
if (Ascii::EqualCI(verb, "assist")) {
|
||||
if (!unit) return false;
|
||||
Game::Lua::CallGlobalString(L, "AssistUnit", unit);
|
||||
return true;
|
||||
}
|
||||
if (EqI(verb, "focus")) {
|
||||
if (Ascii::EqualCI(verb, "focus")) {
|
||||
if (!unit) return false;
|
||||
Unit::Focus::Set(Unit::Identity::GuidForToken(unit));
|
||||
return true;
|
||||
}
|
||||
if (EqI(verb, "spell")) {
|
||||
if (Ascii::EqualCI(verb, "spell")) {
|
||||
if (!unit) return false;
|
||||
char spell[128];
|
||||
if (!ReadModAttr(L, fi, prefix, "spell", suffix, spell, sizeof spell))
|
||||
@@ -639,7 +627,7 @@ bool DispatchVerb(void *L, int fi, const char *prefix, const char *suffix,
|
||||
Spell::AtUnit::CastByName(spell, unit);
|
||||
return true;
|
||||
}
|
||||
if (EqI(verb, "item")) {
|
||||
if (Ascii::EqualCI(verb, "item")) {
|
||||
char item[128];
|
||||
int bag, slot;
|
||||
if (ReadModAttr(L, fi, prefix, "item", suffix, item, sizeof item)) {
|
||||
@@ -657,7 +645,7 @@ bool DispatchVerb(void *L, int fi, const char *prefix, const char *suffix,
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (EqI(verb, "macro")) {
|
||||
if (Ascii::EqualCI(verb, "macro")) {
|
||||
char macro[512];
|
||||
if (!ReadModAttr(L, fi, prefix, "macrotext", suffix, macro, sizeof macro) &&
|
||||
!ReadModAttr(L, fi, prefix, "macro", suffix, macro, sizeof macro))
|
||||
@@ -669,11 +657,11 @@ bool DispatchVerb(void *L, int fi, const char *prefix, const char *suffix,
|
||||
RunMacroTextC(L, macro);
|
||||
return true;
|
||||
}
|
||||
if (EqI(verb, "stop") || EqI(verb, "stopcasting")) {
|
||||
if (Ascii::EqualCI(verb, "stop") || Ascii::EqualCI(verb, "stopcasting")) {
|
||||
Game::Lua::CallGlobal(L, "SpellStopCasting");
|
||||
return true;
|
||||
}
|
||||
if (EqI(verb, "menu") || EqI(verb, "togglemenu")) {
|
||||
if (Ascii::EqualCI(verb, "menu") || Ascii::EqualCI(verb, "togglemenu")) {
|
||||
if (!unit) return false;
|
||||
// The unit dropdown is pure FrameXML work (UnitPopup + ToggleDropDown),
|
||||
// so it lives in the !!!ClassicAPI addon; we just pop it at the cursor.
|
||||
@@ -793,7 +781,7 @@ int __fastcall FrameResolver_h(void *frame, void *edx, const char *name) {
|
||||
const int slot = g_frameResolverOriginal(frame, edx, name);
|
||||
if (slot != 0) // a real base-frame / subtype script — leave it
|
||||
return slot;
|
||||
if (EqI(name, "onattributechanged"))
|
||||
if (Ascii::EqualCI(name, "onattributechanged"))
|
||||
return reinterpret_cast<int>(AttrSlotFor(frame, /*create*/ true));
|
||||
return 0;
|
||||
}
|
||||
|
||||
+136
-103
@@ -29,8 +29,9 @@
|
||||
// purely additive; Lua silently drops the extra positional args a zero-param
|
||||
// handler doesn't declare), but push `self` + `arg1..argN` as real arguments
|
||||
// and `pcall` with `nargs = 1 + N`. The reimplementation mirrors the engine's
|
||||
// exact global save/set/restore and its message-handler errfunc; only the
|
||||
// final push+pcall differs.
|
||||
// message-handler errfunc, but saves the clobbered globals on the Lua stack
|
||||
// (not registry refs like the engine) so an out-of-memory longjmp mid-push
|
||||
// unwinds them for free — no leaked refs, no per-call ref churn. See RunModern.
|
||||
//
|
||||
// Convention: `(self, arg1..argN)` for every script, plus `event` inserted as
|
||||
// the first positional for OnEvent — `(self, event, arg1..argN)` — matching
|
||||
@@ -67,17 +68,11 @@ constexpr int kMaxArgs = 19;
|
||||
// push a value stored under an integer ref (handler / frame object / message
|
||||
// handler / luaL_ref'd saved globals).
|
||||
using RawGetI_t = void(__fastcall *)(void *L, int idx, int ref);
|
||||
// luaL_ref(L, t) → int — pop the top, store it under a fresh int key in table
|
||||
// `t`, return the key. luaL_unref frees it.
|
||||
using LuaLRef_t = int(__fastcall *)(void *L, int t);
|
||||
using LuaLUnref_t = void(__fastcall *)(void *L, int t, int ref);
|
||||
// FUN_FRAMESCRIPT_OBJECT_SCRIPT_REGISTER — __thiscall(frame, nameOrNull);
|
||||
// lazily materializes the frame's Lua-registry ref at frame+OFF_COBJECT_LUA_REF.
|
||||
using ScriptRegister_t = void(__thiscall *)(void *frame, void *nameOrNull);
|
||||
|
||||
const auto RawGetI = reinterpret_cast<RawGetI_t>(Offsets::LUA_RAWGETI);
|
||||
const auto LuaLRef = reinterpret_cast<LuaLRef_t>(Offsets::LUA_REF_REF);
|
||||
const auto LuaLUnref = reinterpret_cast<LuaLUnref_t>(Offsets::LUA_REF_UNREF);
|
||||
|
||||
// Returns the frame's Lua object ref (frame+0x08), lazily creating it exactly
|
||||
// as the engine runner does (`if (refcount == 0) ScriptRegister(frame, 0)`).
|
||||
@@ -104,40 +99,93 @@ void ArgName(char *buf, int k) {
|
||||
}
|
||||
}
|
||||
|
||||
// Sets _G[name] = <value currently on the stack top>, capturing the previous
|
||||
// _G[name] into *outOldRef (a luaL_ref for later restore). Stack-neutral:
|
||||
// consumes the value, leaves the stack as it was minus that value.
|
||||
void SetGlobalSaving(void *L, const char *name, int *outOldRef) {
|
||||
using namespace Game::Lua;
|
||||
PushString(L, name); // [.., newVal, name]
|
||||
GetTable(L, GLOBALS_INDEX); // [.., newVal, oldVal]
|
||||
*outOldRef = LuaLRef(L, REGISTRY_INDEX); // [.., newVal]
|
||||
PushString(L, name); // [.., newVal, name]
|
||||
Insert(L, -2); // [.., name, newVal]
|
||||
SetTable(L, GLOBALS_INDEX); // [..]
|
||||
// One parsed positional argument from the runner's printf-style format.
|
||||
// Numbers ('d'/'u'/'f') land in `num`; strings ('s') keep the char* the engine
|
||||
// handed us (stable for the duration of the call).
|
||||
struct Arg {
|
||||
char name[6]; // "arg1".."arg19"
|
||||
char kind; // 'd' | 'u' | 'f' | 's'
|
||||
double num;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
// Decodes `fmt`/`vaPtr` (the runner's %d/%u/%f/%s specs over a packed vararg
|
||||
// buffer) into `out`, returning the count (capped at kMaxArgs). Unknown specs
|
||||
// are skipped and consume no vararg — mirroring the engine runner's switch.
|
||||
// Pure C, touches no Lua state, so it can never throw.
|
||||
int ParseArgs(const char *fmt, const void *vaPtr, Arg *out) {
|
||||
if (fmt == nullptr)
|
||||
return 0;
|
||||
const char *cur = static_cast<const char *>(vaPtr);
|
||||
int n = 0;
|
||||
for (const char *p = fmt; *p != '\0' && n < kMaxArgs; ++p) {
|
||||
if (*p != '%')
|
||||
continue;
|
||||
++p;
|
||||
if (*p == '\0')
|
||||
break;
|
||||
Arg &a = out[n];
|
||||
switch (*p) {
|
||||
case 'd':
|
||||
a.num = static_cast<double>(*reinterpret_cast<const int *>(cur));
|
||||
cur += 4;
|
||||
break;
|
||||
case 'u':
|
||||
a.num = static_cast<double>(
|
||||
*reinterpret_cast<const unsigned int *>(cur));
|
||||
cur += 4;
|
||||
break;
|
||||
case 'f':
|
||||
a.num = *reinterpret_cast<const double *>(cur);
|
||||
cur += 8;
|
||||
break;
|
||||
case 's':
|
||||
a.str = *reinterpret_cast<const char *const *>(cur);
|
||||
cur += 4;
|
||||
break;
|
||||
default:
|
||||
continue; // unknown spec — consume nothing
|
||||
}
|
||||
a.kind = *p;
|
||||
ArgName(a.name, n + 1);
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// Restores _G[name] to the value at oldRef, then frees the ref.
|
||||
void RestoreGlobal(void *L, const char *name, int oldRef) {
|
||||
using namespace Game::Lua;
|
||||
RawGetI(L, REGISTRY_INDEX, oldRef); // [.., oldVal]
|
||||
PushString(L, name); // [.., oldVal, name]
|
||||
Insert(L, -2); // [.., name, oldVal]
|
||||
SetTable(L, GLOBALS_INDEX); // [..]
|
||||
LuaLUnref(L, REGISTRY_INDEX, oldRef);
|
||||
// Pushes a parsed argument's value onto the Lua stack.
|
||||
void PushArg(void *L, const Arg &a) {
|
||||
if (a.kind == 's')
|
||||
Game::Lua::PushString(L, a.str);
|
||||
else
|
||||
Game::Lua::PushNumber(L, a.num);
|
||||
}
|
||||
|
||||
// Reimplements the runner tail: set globals (with save/restore), then invoke
|
||||
// the handler with modern positional args `(self, arg1..argN)` under the
|
||||
// engine's own message-handler errfunc. `fmt`/`vaPtr` are null for the no-arg
|
||||
// runner (N == 0).
|
||||
void RunModern(int handlerRef, void *frame, const char *fmt, const void *vaPtr) {
|
||||
// Reimplements the runner tail: set the `this`/`arg1..argN` globals, invoke the
|
||||
// handler with modern positional args `(self, [event,] arg1..argN)` under the
|
||||
// engine's own message-handler errfunc, then restore the globals. `fmt`/`vaPtr`
|
||||
// are null for the no-arg runner (N == 0).
|
||||
//
|
||||
// Unlike the engine (and our first cut), the old global values are saved on the
|
||||
// Lua STACK, not in the registry via luaL_ref. A registry save leaks its ref if
|
||||
// any push before the protected call longjmps — and out-of-memory, the one
|
||||
// failure that actually fires here, does exactly that. Stack slots need no
|
||||
// cleanup: an unwinding error resets `L->top` past them for free, so nothing
|
||||
// leaks and there's no per-call ref churn on the OnUpdate hot path. The cost is
|
||||
// a deeper stack (up to ~2*N slots live at once), so we CheckStack up front.
|
||||
//
|
||||
// Returns false WITHOUT side effects when it declines (no Lua state, or the
|
||||
// stack can't grow); the caller then runs the original. Every false path is
|
||||
// before the first push, so falling back never double-runs the handler.
|
||||
bool RunModern(int handlerRef, void *frame, const char *fmt, const void *vaPtr) {
|
||||
using namespace Game::Lua;
|
||||
void *L = State();
|
||||
if (L == nullptr)
|
||||
return;
|
||||
return false;
|
||||
// Headroom for the saved-old block plus the transient set/call pushes.
|
||||
if (CheckStack(L, 2 * kMaxArgs + 16) == 0)
|
||||
return false;
|
||||
|
||||
// --- _G.this = frame -----------------------------------------------------
|
||||
const bool haveThis = frame != nullptr;
|
||||
// OnEvent dispatch? The event dispatchers invoke the frame's OnEvent slot
|
||||
// (frame+0x0C); matching the handler ref against that slot identifies it
|
||||
@@ -148,65 +196,46 @@ void RunModern(int handlerRef, void *frame, const char *fmt, const void *vaPtr)
|
||||
*reinterpret_cast<const int *>(reinterpret_cast<uint8_t *>(frame) +
|
||||
Offsets::OFF_FRAME_ONEVENT_SLOT) ==
|
||||
handlerRef;
|
||||
int selfRef = 0;
|
||||
int oldThisRef = 0;
|
||||
if (haveThis) {
|
||||
selfRef = EnsureLuaRef(frame);
|
||||
RawGetI(L, REGISTRY_INDEX, selfRef); // push frame object
|
||||
SetGlobalSaving(L, "this", &oldThisRef);
|
||||
}
|
||||
const int selfRef = haveThis ? EnsureLuaRef(frame) : 0;
|
||||
|
||||
// --- _G.arg1..argN from the format --------------------------------------
|
||||
int oldArgRefs[kMaxArgs];
|
||||
char argNames[kMaxArgs][6];
|
||||
int n = 0;
|
||||
if (fmt != nullptr) {
|
||||
const char *cur = static_cast<const char *>(vaPtr);
|
||||
for (const char *p = fmt; *p != '\0' && n < kMaxArgs; ++p) {
|
||||
if (*p != '%')
|
||||
continue;
|
||||
++p;
|
||||
if (*p == '\0')
|
||||
break;
|
||||
bool consumed = true;
|
||||
switch (*p) {
|
||||
case 'd':
|
||||
PushNumber(L, static_cast<double>(*reinterpret_cast<const int *>(cur)));
|
||||
cur += 4;
|
||||
break;
|
||||
case 'u':
|
||||
PushNumber(L, static_cast<double>(
|
||||
*reinterpret_cast<const unsigned int *>(cur)));
|
||||
cur += 4;
|
||||
break;
|
||||
case 'f':
|
||||
PushNumber(L, *reinterpret_cast<const double *>(cur));
|
||||
cur += 8;
|
||||
break;
|
||||
case 's':
|
||||
PushString(L, *reinterpret_cast<const char *const *>(cur));
|
||||
cur += 4;
|
||||
break;
|
||||
default:
|
||||
consumed = false; // unknown spec — skip, consume nothing
|
||||
break;
|
||||
}
|
||||
if (!consumed)
|
||||
continue;
|
||||
ArgName(argNames[n], n + 1);
|
||||
SetGlobalSaving(L, argNames[n], &oldArgRefs[n]);
|
||||
++n;
|
||||
}
|
||||
}
|
||||
Arg args[kMaxArgs];
|
||||
const int n = ParseArgs(fmt, vaPtr, args);
|
||||
|
||||
// --- call handler(self, arg1..argN) -------------------------------------
|
||||
// --- save the globals we're about to clobber, onto the stack ------------
|
||||
// Absolute indices, live until the closing SetTop(base):
|
||||
// base+1 = old _G.this (if haveThis)
|
||||
// savedArgBase+1 .. +n = old _G.arg1..argN
|
||||
const int base = GetTop(L);
|
||||
if (haveThis) {
|
||||
PushString(L, "this");
|
||||
GetTable(L, GLOBALS_INDEX); // [.. oldThis]
|
||||
}
|
||||
const int savedArgBase = base + (haveThis ? 1 : 0);
|
||||
for (int k = 0; k < n; ++k) {
|
||||
PushString(L, args[k].name);
|
||||
GetTable(L, GLOBALS_INDEX); // [.. oldArgk]
|
||||
}
|
||||
|
||||
// --- set the new globals (each op is stack-neutral) ---------------------
|
||||
if (haveThis) {
|
||||
PushString(L, "this");
|
||||
RawGetI(L, REGISTRY_INDEX, selfRef); // frame object
|
||||
SetTable(L, GLOBALS_INDEX);
|
||||
}
|
||||
for (int k = 0; k < n; ++k) {
|
||||
PushString(L, args[k].name);
|
||||
PushArg(L, args[k]);
|
||||
SetTable(L, GLOBALS_INDEX);
|
||||
}
|
||||
|
||||
// --- call handler(self, [event,] arg1..argN) ---------------------------
|
||||
const int callBase = GetTop(L); // == base + saved-block size
|
||||
const int errRef = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_FRAMESCRIPT_ERROR_HANDLER_REF));
|
||||
int errIdx = 0;
|
||||
if (errRef > 0) {
|
||||
RawGetI(L, REGISTRY_INDEX, errRef); // message handler
|
||||
errIdx = base + 1; // absolute index of the errfunc
|
||||
errIdx = callBase + 1; // absolute index of the errfunc
|
||||
}
|
||||
RawGetI(L, REGISTRY_INDEX, handlerRef); // handler
|
||||
if (haveThis)
|
||||
@@ -217,18 +246,24 @@ void RunModern(int handlerRef, void *frame, const char *fmt, const void *vaPtr)
|
||||
PushString(L, "event");
|
||||
GetTable(L, GLOBALS_INDEX);
|
||||
}
|
||||
for (int k = 0; k < n; ++k) { // positional args, re-read from the globals
|
||||
PushString(L, argNames[k]);
|
||||
GetTable(L, GLOBALS_INDEX);
|
||||
}
|
||||
for (int k = 0; k < n; ++k)
|
||||
PushArg(L, args[k]);
|
||||
PCall(L, 1 + (isOnEvent ? 1 : 0) + n, 0, errIdx);
|
||||
SetTop(L, base); // drop the message handler + any leftover error object
|
||||
SetTop(L, callBase); // drop the message handler + any leftover error object
|
||||
|
||||
// --- restore globals (reverse order) ------------------------------------
|
||||
for (int k = n - 1; k >= 0; --k)
|
||||
RestoreGlobal(L, argNames[k], oldArgRefs[k]);
|
||||
if (haveThis)
|
||||
RestoreGlobal(L, "this", oldThisRef);
|
||||
// --- restore globals from the saved block, then drop it -----------------
|
||||
for (int k = 0; k < n; ++k) {
|
||||
PushString(L, args[k].name);
|
||||
PushValue(L, savedArgBase + 1 + k);
|
||||
SetTable(L, GLOBALS_INDEX);
|
||||
}
|
||||
if (haveThis) {
|
||||
PushString(L, "this");
|
||||
PushValue(L, base + 1);
|
||||
SetTable(L, GLOBALS_INDEX);
|
||||
}
|
||||
SetTop(L, base);
|
||||
return true;
|
||||
}
|
||||
|
||||
// --- FUN_FRAME_RUN_SCRIPT_ARGS co-hook (scripts with values) ----------------
|
||||
@@ -238,11 +273,10 @@ RunArgs_t g_origRunArgs = nullptr;
|
||||
|
||||
void __cdecl RunArgs_h(int handlerRef, void *frame, const char *fmt,
|
||||
const void *vaPtr) {
|
||||
if (!g_enabled || handlerRef == 0 || fmt == nullptr) {
|
||||
g_origRunArgs(handlerRef, frame, fmt, vaPtr);
|
||||
if (g_enabled && handlerRef != 0 && fmt != nullptr &&
|
||||
RunModern(handlerRef, frame, fmt, vaPtr))
|
||||
return;
|
||||
}
|
||||
RunModern(handlerRef, frame, fmt, vaPtr);
|
||||
g_origRunArgs(handlerRef, frame, fmt, vaPtr);
|
||||
}
|
||||
|
||||
// --- FUN_FRAME_INVOKE_SCRIPT co-hook (no-arg scripts) -----------------------
|
||||
@@ -252,11 +286,10 @@ using Invoke_t = void(__fastcall *)(int handlerRef, void *frame);
|
||||
Invoke_t g_origInvoke = nullptr;
|
||||
|
||||
void __fastcall Invoke_h(int handlerRef, void *frame) {
|
||||
if (!g_enabled || handlerRef == 0 || frame == nullptr) {
|
||||
g_origInvoke(handlerRef, frame);
|
||||
if (g_enabled && handlerRef != 0 && frame != nullptr &&
|
||||
RunModern(handlerRef, frame, /*fmt*/ nullptr, /*vaPtr*/ nullptr))
|
||||
return;
|
||||
}
|
||||
RunModern(handlerRef, frame, /*fmt*/ nullptr, /*vaPtr*/ nullptr);
|
||||
g_origInvoke(handlerRef, frame);
|
||||
}
|
||||
|
||||
const Game::HookAutoRegister _runArgsHook{
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Offsets.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Shared access to the client's friend list. The friend entries live inline
|
||||
// in the social singleton (`VAR_SOCIAL_SYSTEM`, shared with the ignore list
|
||||
// and /who): up to 50 entries from offset 0, stride 0x20. The field offsets
|
||||
// are verified from GetNumFriends (FUN_005AD000), GetFriendInfo
|
||||
// (FUN_005AD060), and the count walker FUN_005AE490.
|
||||
//
|
||||
// The ignore list lives in the same singleton: a flat array of u64 GUIDs at
|
||||
// `+0x650`, stride 8, up to 25 entries, terminated by the first zero GUID.
|
||||
// Vanilla ignores are GUID-keyed, not name-keyed — GetIgnoreName (0x005AD460)
|
||||
// reads the GUID via FUN_005AE570 (`social + 0x650 + index*8`) and resolves it
|
||||
// to a name through the NameCache, and GetNumIgnores (0x005AD400 → the count
|
||||
// walker FUN_005AE550) stops at the first zero GUID and caps at 25.
|
||||
|
||||
namespace FriendList {
|
||||
|
||||
constexpr int FRIEND_ENTRY_STRIDE = 0x20;
|
||||
constexpr int MAX_FRIENDS = 50;
|
||||
|
||||
constexpr int OFF_FRIEND_CONNECTED = 0x00; // u8 — 0 = offline
|
||||
constexpr int OFF_FRIEND_STATUS = 0x01; // u8 — bit 0x02 AFK, 0x04 DND
|
||||
constexpr int OFF_FRIEND_NAME = 0x04; // char*
|
||||
constexpr int OFF_FRIEND_GUID = 0x08; // u64
|
||||
constexpr int OFF_FRIEND_LEVEL = 0x10; // i32
|
||||
constexpr int OFF_FRIEND_CLASS_INDEX = 0x14; // i32 → ChrClasses.dbc
|
||||
constexpr int OFF_FRIEND_AREA_INDEX = 0x18; // i32 → AreaTable.dbc
|
||||
|
||||
constexpr uint8_t FRIEND_STATUS_AFK = 0x02;
|
||||
constexpr uint8_t FRIEND_STATUS_DND = 0x04;
|
||||
|
||||
constexpr int OFF_IGNORE_LIST = 0x650; // u64 GUID array in the social singleton
|
||||
constexpr int IGNORE_ENTRY_STRIDE = 0x8; // one packed u64 GUID per entry
|
||||
constexpr int MAX_IGNORES = 25; // 0x19 — GetNumIgnores' cap
|
||||
|
||||
// The social singleton, or null before login.
|
||||
inline const uint8_t *Social() {
|
||||
return *reinterpret_cast<const uint8_t *const *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_SOCIAL_SYSTEM));
|
||||
}
|
||||
|
||||
// Number of populated friend slots (what GetNumFriends returns).
|
||||
inline int Count() {
|
||||
const uint8_t *social = Social();
|
||||
if (social == nullptr)
|
||||
return 0;
|
||||
using CountFn = uint32_t(__fastcall *)(const void *social);
|
||||
auto fn = reinterpret_cast<CountFn>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_FRIEND_LIST_COUNT));
|
||||
return static_cast<int>(fn(social));
|
||||
}
|
||||
|
||||
// Friend entry at 0-based `index`, or null if there is no list or the index
|
||||
// is out of the fixed slot range. Does not bounds-check against the live
|
||||
// count — callers that iterate should use `Count()`.
|
||||
inline const uint8_t *EntryByIndex(int index) {
|
||||
const uint8_t *social = Social();
|
||||
if (social == nullptr || index < 0 || index >= MAX_FRIENDS)
|
||||
return nullptr;
|
||||
return social + index * FRIEND_ENTRY_STRIDE;
|
||||
}
|
||||
|
||||
// The inline name of the friend with GUID `guid`, or null if that GUID is
|
||||
// not on the friends list. The list keeps name + GUID for online AND offline
|
||||
// friends (SMSG_FRIEND_LIST), so this resolves a GUID to a name even when the
|
||||
// unit is not synced in the object manager and not in the name cache.
|
||||
inline const char *NameForGuid(uint64_t guid) {
|
||||
if (guid == 0)
|
||||
return nullptr;
|
||||
const int count = Count();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const uint8_t *entry = EntryByIndex(i);
|
||||
if (entry == nullptr)
|
||||
break;
|
||||
if (*reinterpret_cast<const uint64_t *>(entry + OFF_FRIEND_GUID) == guid) {
|
||||
const char *name =
|
||||
*reinterpret_cast<const char *const *>(entry + OFF_FRIEND_NAME);
|
||||
return (name != nullptr && *name != '\0') ? name : nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The ignore-list GUID at 0-based `index`, or 0 if there is no list or the
|
||||
// index is past the fixed cap. Mirrors FUN_005AE570.
|
||||
inline uint64_t IgnoreGuidByIndex(int index) {
|
||||
const uint8_t *social = Social();
|
||||
if (social == nullptr || index < 0 || index >= MAX_IGNORES)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint64_t *>(
|
||||
social + OFF_IGNORE_LIST + index * IGNORE_ENTRY_STRIDE);
|
||||
}
|
||||
|
||||
// True if `guid` is on the ignore list. Walks the GUID array, stopping at the
|
||||
// first zero entry (the list is contiguous — same terminate-on-zero contract
|
||||
// GetNumIgnores relies on).
|
||||
inline bool IsGuidIgnored(uint64_t guid) {
|
||||
if (guid == 0)
|
||||
return false;
|
||||
for (int i = 0; i < MAX_IGNORES; ++i) {
|
||||
const uint64_t entry = IgnoreGuidByIndex(i);
|
||||
if (entry == 0)
|
||||
break;
|
||||
if (entry == guid)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace FriendList
|
||||
@@ -0,0 +1,166 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// `C_FriendList.GetFriendInfo(name)` / `GetFriendInfoByIndex(index)` — the
|
||||
// modern FriendInfo table, plus `C_FriendList.GetNumFriends()`.
|
||||
//
|
||||
// Reads the friend entries directly (see `FriendList.h`). The class and zone
|
||||
// names come from the same DBC lookups the engine's own GetFriendInfo uses:
|
||||
// ChrClasses.dbc by the entry's class index, and AreaTable.dbc by the area
|
||||
// index — resolved to the parent zone so a sub-area reports its zone. Both
|
||||
// are locale-applied through `DBC::LocalizedField`.
|
||||
//
|
||||
// vanilla 1.12 stores no friend notes, so `notes` is omitted (nil). `mobile`
|
||||
// and `referAFriend` are always false, and `rafLinkType` is 0 — vanilla has
|
||||
// none of those systems; the fields exist so modern consumers do not nil-out.
|
||||
|
||||
#include "FriendList.h"
|
||||
#include "Notes.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "dbc/Names.h"
|
||||
#include "guid/Guid.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace FriendList::Info {
|
||||
|
||||
namespace {
|
||||
|
||||
// Push the modern FriendInfo table for `entry` on top of the Lua stack.
|
||||
void PushFriendInfo(void *L, const uint8_t *entry) {
|
||||
const bool connected = *(entry + OFF_FRIEND_CONNECTED) != 0;
|
||||
const char *name =
|
||||
*reinterpret_cast<const char *const *>(entry + OFF_FRIEND_NAME);
|
||||
const int level = *reinterpret_cast<const int *>(entry + OFF_FRIEND_LEVEL);
|
||||
const uint64_t guid =
|
||||
*reinterpret_cast<const uint64_t *>(entry + OFF_FRIEND_GUID);
|
||||
const uint8_t status = *(entry + OFF_FRIEND_STATUS);
|
||||
const uint32_t classIndex =
|
||||
*reinterpret_cast<const uint32_t *>(entry + OFF_FRIEND_CLASS_INDEX);
|
||||
const uint32_t areaIndex =
|
||||
*reinterpret_cast<const uint32_t *>(entry + OFF_FRIEND_AREA_INDEX);
|
||||
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetFieldString(L, "name", name);
|
||||
Game::Lua::SetFieldBool(L, "connected", connected);
|
||||
Game::Lua::SetFieldNumber(L, "level", static_cast<double>(level));
|
||||
// Optional strings: leave the field nil (unset) when unresolved rather
|
||||
// than "" — SetFieldString coerces null to "", which is truthy in Lua and
|
||||
// would fool an `if info.notes then` presence check. Matches retail, where
|
||||
// these are nil when absent.
|
||||
if (const char *className = DBC::ClassName(classIndex))
|
||||
Game::Lua::SetFieldString(L, "className", className);
|
||||
// classFilename: the locale-independent class token ("MAGE", "WARRIOR"),
|
||||
// the key for RAID_CLASS_COLORS and other class tables. nil when unknown,
|
||||
// so `className` and `classFilename` appear together.
|
||||
if (const char *classToken = DBC::ClassToken(classIndex))
|
||||
Game::Lua::SetFieldString(L, "classFilename", classToken);
|
||||
// Resolve a sub-area to its parent zone for friends (e.g. "Goldshire" ->
|
||||
// "Elwynn Forest"), matching what the friends UI shows.
|
||||
if (const char *area = DBC::AreaName(areaIndex, /*resolveToParent=*/true))
|
||||
Game::Lua::SetFieldString(L, "area", area);
|
||||
if (guid != 0) {
|
||||
char buf[Guid::STRING_SIZE];
|
||||
Game::Lua::SetFieldString(L, "guid",
|
||||
Guid::FormatAsString(guid, buf, sizeof buf));
|
||||
}
|
||||
if (const char *note = Notes::Get(guid)) // client-side note (see Notes.h)
|
||||
Game::Lua::SetFieldString(L, "notes", note);
|
||||
Game::Lua::SetFieldBool(L, "afk", (status & FRIEND_STATUS_AFK) != 0);
|
||||
Game::Lua::SetFieldBool(L, "dnd", (status & FRIEND_STATUS_DND) != 0);
|
||||
Game::Lua::SetFieldBool(L, "mobile", false);
|
||||
Game::Lua::SetFieldBool(L, "referAFriend", false);
|
||||
Game::Lua::SetFieldNumber(L, "rafLinkType", 0);
|
||||
}
|
||||
|
||||
int __fastcall Script_GetNumFriends(void *L) {
|
||||
Game::Lua::PushNumber(L, static_cast<double>(FriendList::Count()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// `C_FriendList.GetNumOnlineFriends()` — how many friends are online. Vanilla
|
||||
// stores no online count, so we count entries whose `connected` byte is set
|
||||
// (the same flag GetFriendInfo reports as `connected`).
|
||||
int __fastcall Script_GetNumOnlineFriends(void *L) {
|
||||
int online = 0;
|
||||
const int count = FriendList::Count();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const uint8_t *entry = FriendList::EntryByIndex(i);
|
||||
if (entry == nullptr)
|
||||
break;
|
||||
if (*(entry + OFF_FRIEND_CONNECTED) != 0)
|
||||
++online;
|
||||
}
|
||||
Game::Lua::PushNumber(L, static_cast<double>(online));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int __fastcall Script_GetFriendInfoByIndex(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1)) {
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
}
|
||||
const int index = static_cast<int>(Game::Lua::ToNumber(L, 1)); // 1-based
|
||||
if (index < 1 || index > FriendList::Count()) {
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
}
|
||||
const uint8_t *entry = FriendList::EntryByIndex(index - 1);
|
||||
if (entry == nullptr) {
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
}
|
||||
PushFriendInfo(L, entry);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int __fastcall Script_GetFriendInfo(void *L) {
|
||||
const char *name = Game::Lua::IsString(L, 1) ? Game::Lua::ToString(L, 1) : nullptr;
|
||||
if (name == nullptr || *name == '\0') {
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
}
|
||||
const int count = FriendList::Count();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const uint8_t *entry = FriendList::EntryByIndex(i);
|
||||
if (entry == nullptr)
|
||||
break;
|
||||
const char *fname =
|
||||
*reinterpret_cast<const char *const *>(entry + OFF_FRIEND_NAME);
|
||||
if (fname != nullptr && _stricmp(fname, name) == 0) {
|
||||
PushFriendInfo(L, entry);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "GetNumFriends",
|
||||
&Script_GetNumFriends);
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "GetNumOnlineFriends",
|
||||
&Script_GetNumOnlineFriends);
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "GetFriendInfoByIndex",
|
||||
&Script_GetFriendInfoByIndex);
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "GetFriendInfo",
|
||||
&Script_GetFriendInfo);
|
||||
}
|
||||
|
||||
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace FriendList::Info
|
||||
@@ -0,0 +1,82 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// `C_FriendList.IsFriend(guid)` — is the given player on the friends list?
|
||||
//
|
||||
// Matches the input GUID against each friend entry's GUID (+0x08) — the same
|
||||
// GUID `SMSG_FRIEND_LIST` populates for online AND offline friends — and also
|
||||
// falls back to a name compare (resolving the GUID through the NameCache) so
|
||||
// the answer holds even if a build stores the GUID differently. As a
|
||||
// ClassicAPI convenience the arg may also be a bare character name, since
|
||||
// vanilla's friends list is fundamentally name-keyed (AddFriend(name)). See
|
||||
// `FriendList.h` for the entry layout.
|
||||
|
||||
#include "FriendList.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "guid/Guid.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace FriendList::IsFriend {
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsFriendByGuidOrName(uint64_t guid, const char *name) {
|
||||
const int count = FriendList::Count();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const uint8_t *entry = FriendList::EntryByIndex(i);
|
||||
if (entry == nullptr)
|
||||
break;
|
||||
if (guid != 0 &&
|
||||
*reinterpret_cast<const uint64_t *>(entry + FriendList::OFF_FRIEND_GUID) == guid)
|
||||
return true;
|
||||
if (name != nullptr) {
|
||||
const char *fname = *reinterpret_cast<const char *const *>(
|
||||
entry + FriendList::OFF_FRIEND_NAME);
|
||||
if (fname != nullptr && _stricmp(fname, name) == 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int __fastcall Script_IsFriend(void *L) {
|
||||
const char *arg = Game::Lua::IsString(L, 1) ? Game::Lua::ToString(L, 1) : nullptr;
|
||||
if (arg == nullptr || *arg == '\0') {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint64_t guid = 0;
|
||||
const char *name = nullptr;
|
||||
if (Guid::Parse(arg, &guid) && guid != 0)
|
||||
name = Unit::Identity::NameForGuid(guid); // GUID input → name for the fallback compare
|
||||
else
|
||||
name = arg; // not a GUID → treat the string as a character name
|
||||
|
||||
Game::Lua::PushBool(L, IsFriendByGuidOrName(guid, name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "IsFriend", &Script_IsFriend);
|
||||
}
|
||||
|
||||
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace FriendList::IsFriend
|
||||
@@ -0,0 +1,98 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// `C_FriendList.IsIgnored(token)` / `C_FriendList.IsIgnoredByGuid(guid)` — is
|
||||
// the given player on the ignore list?
|
||||
//
|
||||
// The ignore list is a flat array of u64 GUIDs in the social singleton (see
|
||||
// `FriendList.h`) — vanilla ignores are GUID-keyed, not name-keyed. So
|
||||
// `IsIgnoredByGuid` is a direct GUID walk, and `IsIgnored` accepts either a
|
||||
// GUID string or a character name: for a name it resolves each ignored GUID to
|
||||
// its cached name through the NameCache and compares (the same GUID→name path
|
||||
// GetIgnoreName uses), so it matches any ignored player the client has synced.
|
||||
// An ignored player never seen this session has no cached name and so cannot
|
||||
// match by name — identical to GetIgnoreName returning "Unknown" for them.
|
||||
|
||||
#include "FriendList.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "guid/Guid.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace FriendList::IsIgnored {
|
||||
|
||||
namespace {
|
||||
|
||||
// True if any ignored GUID matches `guid`, or (when `name` is given) resolves
|
||||
// to `name`. Single walk of the GUID array.
|
||||
bool IgnoredByGuidOrName(uint64_t guid, const char *name) {
|
||||
for (int i = 0; i < FriendList::MAX_IGNORES; ++i) {
|
||||
const uint64_t entry = FriendList::IgnoreGuidByIndex(i);
|
||||
if (entry == 0)
|
||||
break; // contiguous list — first zero is the end
|
||||
if (guid != 0 && entry == guid)
|
||||
return true;
|
||||
if (name != nullptr) {
|
||||
const char *ename = Unit::Identity::NameForGuid(entry);
|
||||
if (ename != nullptr && _stricmp(ename, name) == 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// `IsIgnored(token)` — token is a character name or a GUID string.
|
||||
int __fastcall Script_IsIgnored(void *L) {
|
||||
const char *arg = Game::Lua::IsString(L, 1) ? Game::Lua::ToString(L, 1) : nullptr;
|
||||
if (arg == nullptr || *arg == '\0') {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint64_t guid = 0;
|
||||
const char *name = nullptr;
|
||||
if (Guid::Parse(arg, &guid) && guid != 0)
|
||||
name = Unit::Identity::NameForGuid(guid); // GUID input → name for the fallback compare
|
||||
else
|
||||
name = arg; // not a GUID → treat the string as a character name
|
||||
|
||||
Game::Lua::PushBool(L, IgnoredByGuidOrName(guid, name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// `IsIgnoredByGuid(guid)` — GUID string only.
|
||||
int __fastcall Script_IsIgnoredByGuid(void *L) {
|
||||
const char *arg = Game::Lua::IsString(L, 1) ? Game::Lua::ToString(L, 1) : nullptr;
|
||||
uint64_t guid = 0;
|
||||
if (arg == nullptr || !Guid::Parse(arg, &guid) || guid == 0) {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
}
|
||||
Game::Lua::PushBool(L, FriendList::IsGuidIgnored(guid));
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "IsIgnored", &Script_IsIgnored);
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "IsIgnoredByGuid",
|
||||
&Script_IsIgnoredByGuid);
|
||||
}
|
||||
|
||||
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace FriendList::IsIgnored
|
||||
@@ -0,0 +1,206 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// See `Notes.h`. Mirrors the equipment manager's storage approach
|
||||
// (equipmentset/Storage.cpp): a small text file under WTF, atomic
|
||||
// tmp+rename write, path re-resolved on every access so a
|
||||
// logout→character-select→login (no DLL reload) picks up the new realm.
|
||||
|
||||
#include "Notes.h"
|
||||
|
||||
#include "Offsets.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace FriendList::Notes {
|
||||
|
||||
namespace {
|
||||
|
||||
struct Entry {
|
||||
std::string name; // last-seen name, for a readable file (not the key)
|
||||
std::string note;
|
||||
};
|
||||
|
||||
std::unordered_map<uint64_t, Entry> g_notes;
|
||||
std::string g_path;
|
||||
bool g_loaded = false;
|
||||
|
||||
const char *ReadAccountName() {
|
||||
return *reinterpret_cast<const char *const *>(Offsets::VAR_ACCOUNT_NAME_PTR);
|
||||
}
|
||||
|
||||
const char *ReadRealmName() {
|
||||
auto *info = *reinterpret_cast<uint8_t **>(Offsets::VAR_REALM_INFO_PTR);
|
||||
if (info == nullptr)
|
||||
return nullptr;
|
||||
return *reinterpret_cast<const char *const *>(info + Offsets::OFF_REALM_INFO_NAME);
|
||||
}
|
||||
|
||||
const char *ReadCharacterName() {
|
||||
auto *p = reinterpret_cast<const char *>(Offsets::VAR_CHARACTER_NAME);
|
||||
return (p[0] == '\0') ? nullptr : p;
|
||||
}
|
||||
|
||||
// WTF\Account\<acct>\<realm>\<char>\ClassicAPI_FriendNotes.txt, or empty until
|
||||
// the account + realm + character session globals are populated. Per-character
|
||||
// because the friends list is per-character in vanilla.
|
||||
std::string ResolveFilePath() {
|
||||
const char *account = ReadAccountName();
|
||||
if (account == nullptr || account[0] == '\0')
|
||||
return {};
|
||||
const char *realm = ReadRealmName();
|
||||
if (realm == nullptr || realm[0] == '\0')
|
||||
return {};
|
||||
const char *character = ReadCharacterName();
|
||||
if (character == nullptr)
|
||||
return {};
|
||||
std::string out = "WTF\\Account\\";
|
||||
out += account;
|
||||
out += '\\';
|
||||
out += realm;
|
||||
out += '\\';
|
||||
out += character;
|
||||
out += "\\ClassicAPI_FriendNotes.txt";
|
||||
return out;
|
||||
}
|
||||
|
||||
// Notes are a single line each; the file is tab-delimited, so a note must
|
||||
// carry no tab or newline. Replace any with a space and trim trailing space.
|
||||
void Sanitize(std::string *s) {
|
||||
for (char &c : *s)
|
||||
if (c == '\r' || c == '\n' || c == '\t')
|
||||
c = ' ';
|
||||
while (!s->empty() && s->back() == ' ')
|
||||
s->pop_back();
|
||||
}
|
||||
|
||||
void Load() {
|
||||
g_notes.clear();
|
||||
std::ifstream file(g_path);
|
||||
if (!file.is_open())
|
||||
return; // first run for this character — empty store is fine
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
while (!line.empty() && (line.back() == '\r' || line.back() == '\n'))
|
||||
line.pop_back();
|
||||
if (line.empty() || line[0] == '#')
|
||||
continue;
|
||||
// Format: `0xGUID<tab>name<tab>note`.
|
||||
const auto t1 = line.find('\t');
|
||||
if (t1 == std::string::npos)
|
||||
continue;
|
||||
const auto t2 = line.find('\t', t1 + 1);
|
||||
const uint64_t guid = std::strtoull(line.c_str(), nullptr, 0);
|
||||
if (guid == 0 || t2 == std::string::npos)
|
||||
continue;
|
||||
std::string name = line.substr(t1 + 1, t2 - (t1 + 1));
|
||||
std::string note = line.substr(t2 + 1);
|
||||
if (note.empty())
|
||||
continue;
|
||||
if (static_cast<int>(note.size()) > MAX_NOTE_LEN)
|
||||
note.resize(MAX_NOTE_LEN);
|
||||
g_notes[guid] = Entry{std::move(name), std::move(note)};
|
||||
}
|
||||
}
|
||||
|
||||
void Save() {
|
||||
if (g_path.empty())
|
||||
return;
|
||||
const std::string tmp = g_path + ".tmp";
|
||||
{
|
||||
std::ofstream out(tmp, std::ios::binary | std::ios::trunc);
|
||||
if (!out.is_open())
|
||||
return;
|
||||
out << "# ClassicAPI Friend Notes v1\n";
|
||||
out << "# <0xGUID>\\t<name>\\t<note> (per-character, GUID-keyed)\n";
|
||||
for (const auto &kv : g_notes) {
|
||||
char buf[24];
|
||||
std::snprintf(buf, sizeof(buf), "0x%016llX",
|
||||
static_cast<unsigned long long>(kv.first));
|
||||
out << buf << '\t' << kv.second.name << '\t' << kv.second.note << '\n';
|
||||
}
|
||||
}
|
||||
std::remove(g_path.c_str());
|
||||
std::rename(tmp.c_str(), g_path.c_str());
|
||||
}
|
||||
|
||||
// Re-resolve the path each call; reload when it changes. The DLL survives a
|
||||
// character/realm switch, so a permanent latch would keep the old character's
|
||||
// file — matching EquipmentSet::Data::EnsureLoaded.
|
||||
void EnsureLoaded() {
|
||||
std::string path = ResolveFilePath();
|
||||
if (path.empty()) {
|
||||
// Session globals not ready (login / char-select / loading screen).
|
||||
// Drop any cached state so a stale path from the PREVIOUS character
|
||||
// can never be read from or written to — that is the "didn't wipe
|
||||
// between characters" trap. Nothing queries notes out of world, so
|
||||
// there is nothing to lose; the next in-world call reloads cleanly.
|
||||
g_notes.clear();
|
||||
g_path.clear();
|
||||
g_loaded = false;
|
||||
return;
|
||||
}
|
||||
if (g_loaded && path == g_path)
|
||||
return;
|
||||
// Path changed (different character/account) — Load() clears the map
|
||||
// before reading, so the new character never inherits the old one's notes.
|
||||
g_path = std::move(path);
|
||||
Load();
|
||||
g_loaded = true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const char *Get(uint64_t guid) {
|
||||
if (guid == 0)
|
||||
return nullptr;
|
||||
EnsureLoaded();
|
||||
auto it = g_notes.find(guid);
|
||||
if (it == g_notes.end() || it->second.note.empty())
|
||||
return nullptr;
|
||||
return it->second.note.c_str();
|
||||
}
|
||||
|
||||
bool Set(uint64_t guid, const char *name, const char *note) {
|
||||
if (guid == 0)
|
||||
return false;
|
||||
EnsureLoaded();
|
||||
if (g_path.empty())
|
||||
return false; // no realm/account yet — nowhere to persist
|
||||
|
||||
std::string text = (note != nullptr) ? note : "";
|
||||
Sanitize(&text);
|
||||
if (static_cast<int>(text.size()) > MAX_NOTE_LEN)
|
||||
text.resize(MAX_NOTE_LEN);
|
||||
|
||||
if (text.empty()) {
|
||||
if (g_notes.erase(guid) == 0)
|
||||
return false; // nothing to clear
|
||||
} else {
|
||||
Entry e;
|
||||
e.name = (name != nullptr) ? name : "";
|
||||
Sanitize(&e.name);
|
||||
e.note = std::move(text);
|
||||
g_notes[guid] = std::move(e);
|
||||
}
|
||||
Save();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace FriendList::Notes
|
||||
@@ -0,0 +1,40 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Client-side friend notes. Vanilla 1.12 has no server-side note field
|
||||
// (TBC added it), so we persist notes ourselves — the same pattern the
|
||||
// equipment manager uses for its sets. Backing file:
|
||||
// WTF\Account\<acct>\<realm>\<char>\ClassicAPI_FriendNotes.txt
|
||||
// Per-character, because the friends list itself is per-character in
|
||||
// vanilla (each character keeps its own friends). GUID-keyed within that
|
||||
// file — a friend's GUID is stable and unique on the realm.
|
||||
|
||||
namespace FriendList::Notes {
|
||||
|
||||
// Longest stored note. Longer input is truncated on Set.
|
||||
constexpr int MAX_NOTE_LEN = 128;
|
||||
|
||||
// The note for a friend GUID, or nullptr if none. Loads the per-realm store
|
||||
// on first use. The pointer is valid until the next Set or realm switch.
|
||||
const char *Get(uint64_t guid);
|
||||
|
||||
// Set the note for a friend GUID, or clear it when `note` is null/empty.
|
||||
// `name` is stored alongside so the file stays human-readable. Persists to
|
||||
// disk immediately. Returns true if the store changed.
|
||||
bool Set(uint64_t guid, const char *name, const char *note);
|
||||
|
||||
} // namespace FriendList::Notes
|
||||
@@ -0,0 +1,89 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// `C_FriendList.SetFriendNotes(name, notes)` / `SetFriendNotesByIndex(index,
|
||||
// notes)` — write a client-side note for a friend (see `Notes.h`). Passing an
|
||||
// empty / nil note clears it. Matches retail: the target must already be on
|
||||
// the friends list, and there is no return value. Fires FRIENDLIST_UPDATE on
|
||||
// change so the friends UI and note-aware addons refresh.
|
||||
|
||||
#include "FriendList.h"
|
||||
#include "Notes.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "event/Custom.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace FriendList::SetNotes {
|
||||
|
||||
namespace {
|
||||
|
||||
// The friend entry whose name matches (case-insensitive), or null.
|
||||
const uint8_t *FindByName(const char *name) {
|
||||
if (name == nullptr || *name == '\0')
|
||||
return nullptr;
|
||||
const int count = FriendList::Count();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const uint8_t *entry = FriendList::EntryByIndex(i);
|
||||
if (entry == nullptr)
|
||||
break;
|
||||
const char *fname = *reinterpret_cast<const char *const *>(
|
||||
entry + FriendList::OFF_FRIEND_NAME);
|
||||
if (fname != nullptr && _stricmp(fname, name) == 0)
|
||||
return entry;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ApplyNote(const uint8_t *entry, const char *note) {
|
||||
if (entry == nullptr)
|
||||
return;
|
||||
const uint64_t guid = *reinterpret_cast<const uint64_t *>(
|
||||
entry + FriendList::OFF_FRIEND_GUID);
|
||||
const char *name = *reinterpret_cast<const char *const *>(
|
||||
entry + FriendList::OFF_FRIEND_NAME);
|
||||
if (Notes::Set(guid, name, note))
|
||||
Event::Custom::Fire(Event::Custom::LookupByName("FRIENDLIST_UPDATE"), "");
|
||||
}
|
||||
|
||||
int __fastcall Script_SetFriendNotes(void *L) {
|
||||
const char *name = Game::Lua::IsString(L, 1) ? Game::Lua::ToString(L, 1) : nullptr;
|
||||
const char *note = Game::Lua::IsString(L, 2) ? Game::Lua::ToString(L, 2) : nullptr;
|
||||
ApplyNote(FindByName(name), note);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __fastcall Script_SetFriendNotesByIndex(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1))
|
||||
return 0;
|
||||
const int index = static_cast<int>(Game::Lua::ToNumber(L, 1)); // 1-based
|
||||
const char *note = Game::Lua::IsString(L, 2) ? Game::Lua::ToString(L, 2) : nullptr;
|
||||
if (index >= 1 && index <= FriendList::Count())
|
||||
ApplyNote(FriendList::EntryByIndex(index - 1), note);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "SetFriendNotes",
|
||||
&Script_SetFriendNotes);
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "SetFriendNotesByIndex",
|
||||
&Script_SetFriendNotesByIndex);
|
||||
}
|
||||
|
||||
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace FriendList::SetNotes
|
||||
@@ -121,7 +121,7 @@ using SendQuery_t = void(__thiscall *)(void *self, const char *queryStr);
|
||||
|
||||
bool SendQueryInternal(const char *fullQuery) {
|
||||
auto *system = *reinterpret_cast<void *const *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_WHO_SYSTEM));
|
||||
static_cast<uintptr_t>(Offsets::VAR_SOCIAL_SYSTEM));
|
||||
if (system == nullptr)
|
||||
return false;
|
||||
auto fn = reinterpret_cast<SendQuery_t>(Offsets::FUN_WHO_SYSTEM_SEND_QUERY);
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// `C_FriendList.GetWhoInfo(index)` — the modern table form of vanilla's
|
||||
// `GetWhoInfo(index)`. The vanilla global returns positional values and, most
|
||||
// notably, no class *token* — only the localized class name. This returns a
|
||||
// table that includes `filename` (the "MAGE"/"WARRIOR" token), so a /who list
|
||||
// can be class-colored via RAID_CLASS_COLORS without reverse-mapping the
|
||||
// localized name.
|
||||
//
|
||||
// Reads the same /who result buffer the engine's Script_GetWhoInfo
|
||||
// (0x005AD6E0) reads (see the WHO_RESULT_* offsets in Offsets.h): an array of
|
||||
// stride-0xA0 entries with inline name/guild strings and race/class/zone DBC
|
||||
// indices. `C_FriendList.GetNumWhoResults()` is the companion count.
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Names.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace FriendList::WhoInfo {
|
||||
|
||||
namespace {
|
||||
|
||||
int WhoResultCount() {
|
||||
return *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_WHO_RESULT_COUNT));
|
||||
}
|
||||
|
||||
// `C_FriendList.GetNumWhoResults()` → `numWhos, totalCount`. The first is the
|
||||
// number of entries you can index with GetWhoInfo; the second is the server's
|
||||
// total-match count (it can exceed the displayed list). Mirrors the vanilla
|
||||
// global's two returns.
|
||||
int __fastcall Script_GetNumWhoResults(void *L) {
|
||||
const int displayed = WhoResultCount();
|
||||
const int total = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_WHO_RESULT_COUNT) + 4);
|
||||
Game::Lua::PushNumber(L, static_cast<double>(displayed));
|
||||
Game::Lua::PushNumber(L, static_cast<double>(total));
|
||||
return 2;
|
||||
}
|
||||
|
||||
// `C_FriendList.GetWhoInfo(index)` → WhoInfo table, or nil for a bad index.
|
||||
int __fastcall Script_GetWhoInfo(void *L) {
|
||||
if (!Game::Lua::IsNumber(L, 1)) {
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
}
|
||||
const int index = static_cast<int>(Game::Lua::ToNumber(L, 1)); // 1-based
|
||||
if (index < 1 || index > WhoResultCount()) {
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const uint8_t *entry = reinterpret_cast<const uint8_t *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_WHO_RESULTS) +
|
||||
static_cast<size_t>(index - 1) * Offsets::WHO_RESULT_STRIDE);
|
||||
|
||||
const char *name = reinterpret_cast<const char *>(entry + Offsets::OFF_WHO_NAME);
|
||||
const char *guild = reinterpret_cast<const char *>(entry + Offsets::OFF_WHO_GUILD);
|
||||
const int level = *reinterpret_cast<const int *>(entry + Offsets::OFF_WHO_LEVEL);
|
||||
const uint32_t raceID =
|
||||
*reinterpret_cast<const uint32_t *>(entry + Offsets::OFF_WHO_RACE);
|
||||
const uint32_t classID =
|
||||
*reinterpret_cast<const uint32_t *>(entry + Offsets::OFF_WHO_CLASS);
|
||||
const uint32_t zoneID =
|
||||
*reinterpret_cast<const uint32_t *>(entry + Offsets::OFF_WHO_ZONE);
|
||||
|
||||
Game::Lua::NewTable(L);
|
||||
Game::Lua::SetFieldString(L, "fullName", name); // inline; "" if empty
|
||||
Game::Lua::SetFieldString(L, "fullGuildName", guild); // "" when guildless
|
||||
Game::Lua::SetFieldNumber(L, "level", static_cast<double>(level));
|
||||
// Optional strings stay nil (unset) when the DBC id doesn't resolve, so an
|
||||
// `if info.filename then` check works — SetFieldString would coerce null
|
||||
// to "" (truthy).
|
||||
if (const char *raceStr = DBC::RaceName(raceID))
|
||||
Game::Lua::SetFieldString(L, "raceStr", raceStr);
|
||||
if (const char *classStr = DBC::ClassName(classID))
|
||||
Game::Lua::SetFieldString(L, "classStr", classStr);
|
||||
if (const char *filename = DBC::ClassToken(classID))
|
||||
Game::Lua::SetFieldString(L, "filename", filename);
|
||||
// /who zones are already zone-level, so use the area's own name (no parent
|
||||
// walk) — matches the engine's own GetWhoInfo.
|
||||
if (const char *area = DBC::AreaName(zoneID, /*resolveToParent=*/false))
|
||||
Game::Lua::SetFieldString(L, "area", area);
|
||||
// No `gender`: vanilla's /who result carries no sex field (the entry ends
|
||||
// at the zone index), so modern's gender return has no source here.
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RegisterLuaFunctions() {
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "GetWhoInfo",
|
||||
&Script_GetWhoInfo);
|
||||
Game::Lua::RegisterTableFunction("C_FriendList", "GetNumWhoResults",
|
||||
&Script_GetNumWhoResults);
|
||||
}
|
||||
|
||||
const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace FriendList::WhoInfo
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "guid/Guid.h"
|
||||
#include "object/Resolve.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -28,9 +29,6 @@ namespace GameObject::Tooltip {
|
||||
// on every subsequent `SetX` call — same gating pattern Has/GetUnitGUID,
|
||||
// Has/GetItem, and Has/GetSpell use.
|
||||
|
||||
using ObjectResolveByGUID_t = void *(__fastcall *)(int type, const char *debugName,
|
||||
uint32_t guidLo, uint32_t guidHi,
|
||||
int priority);
|
||||
using GameObjectGetName_t = const char *(__fastcall *)(void *gameObject);
|
||||
|
||||
// `GameTooltip:GetGameObject()` → (name, id, guid) for whichever gameobject
|
||||
@@ -72,10 +70,9 @@ static int __fastcall Script_GameTooltipGetGameObject(void *L) {
|
||||
if (guidLo == 0 && guidHi == 0)
|
||||
return 0;
|
||||
|
||||
auto resolve = reinterpret_cast<ObjectResolveByGUID_t>(
|
||||
Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
void *obj = resolve(Offsets::OBJ_TYPE_GAMEOBJECT, "GameTooltip:GetGameObject",
|
||||
guidLo, guidHi, 0x172);
|
||||
void *obj = Object::ByGuid(Offsets::TYPEMASK_GAMEOBJECT,
|
||||
(static_cast<uint64_t>(guidHi) << 32) | guidLo,
|
||||
"GameTooltip:GetGameObject", 0x172);
|
||||
if (obj == nullptr)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@
|
||||
#include "item/Data.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -65,10 +67,6 @@ namespace Item::AverageLevel {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
// 1-based slot range used by both walks.
|
||||
constexpr int kFirstSlot = 1;
|
||||
constexpr int kLastSlot = 19;
|
||||
@@ -119,13 +117,6 @@ constexpr uint32_t kSlotMaskByInvType[29] = {
|
||||
constexpr int kInvTypeMax = static_cast<int>(sizeof(kSlotMaskByInvType) /
|
||||
sizeof(kSlotMaskByInvType[0])) - 1;
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
// Returns (itemLevel, inventoryType) for the CGItem, or (0, 0) if
|
||||
// the itemID is unresolvable or the cache record hasn't loaded.
|
||||
struct ItemInfo {
|
||||
@@ -139,7 +130,7 @@ ItemInfo ReadItemInfo(const uint8_t *cgItem) {
|
||||
const int itemID = Item::ID::FromCGItem(cgItem);
|
||||
if (itemID <= 0)
|
||||
return {0, 0};
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
// Equipped or bagged item with no cache record yet — queue a
|
||||
// warmup so the next call gets populated data. Cheap on cache
|
||||
@@ -154,22 +145,11 @@ ItemInfo ReadItemInfo(const uint8_t *cgItem) {
|
||||
// Bank-walk helpers — bypass the bank-window gate on `GetItemBySlot`
|
||||
// by reading the player's invMgr GUID array directly. Same shape as
|
||||
// `C_Item.GetItemCount`'s bank path.
|
||||
using ResolveObjectByGuid_t = void *(__fastcall *)(int type,
|
||||
const char *debugName,
|
||||
uint32_t guidLo,
|
||||
uint32_t guidHi,
|
||||
int priority);
|
||||
|
||||
const uint8_t *ResolveByGuid(int type, uint64_t guid) {
|
||||
if (guid == 0)
|
||||
return nullptr;
|
||||
auto fn = reinterpret_cast<ResolveObjectByGuid_t>(
|
||||
Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
return static_cast<const uint8_t *>(
|
||||
fn(type, "AverageLevel",
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32),
|
||||
0x172));
|
||||
Object::ByGuid(type, guid, "AverageLevel", 0x172));
|
||||
}
|
||||
|
||||
// Collects a single CGItem into `candidates` if it could equip in
|
||||
@@ -209,7 +189,7 @@ void WalkGuidArrayRange(const uint8_t *invMgr, int firstSlot, int lastSlot,
|
||||
if (guidArray == nullptr)
|
||||
return;
|
||||
for (int slot = firstSlot; slot <= lastSlot; ++slot) {
|
||||
const uint8_t *item = ResolveByGuid(Offsets::OBJ_TYPE_ITEM, guidArray[slot]);
|
||||
const uint8_t *item = ResolveByGuid(Offsets::TYPEMASK_ITEM, guidArray[slot]);
|
||||
if (item == nullptr)
|
||||
continue;
|
||||
CollectBagOrBankItem(item, candidates);
|
||||
@@ -229,7 +209,7 @@ void WalkBankBags(std::vector<Candidate> &candidates) {
|
||||
return;
|
||||
for (int slot = Offsets::INVMGR_BANK_BAG_FIRST_SLOT;
|
||||
slot <= Offsets::INVMGR_BANK_BAG_LAST_SLOT; ++slot) {
|
||||
const uint8_t *bag = ResolveByGuid(Offsets::OBJ_TYPE_CONTAINER,
|
||||
const uint8_t *bag = ResolveByGuid(Offsets::TYPEMASK_CONTAINER,
|
||||
playerGuidArray[slot]);
|
||||
if (bag == nullptr)
|
||||
continue;
|
||||
|
||||
+2
-2
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -20,8 +21,7 @@
|
||||
namespace Item::Bound {
|
||||
|
||||
static bool ItemIsSoulbound(const uint8_t *item) {
|
||||
auto *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *descriptor = Item::ObjectFields(item);
|
||||
if (descriptor == nullptr)
|
||||
return false;
|
||||
const uint32_t flags = *reinterpret_cast<const uint32_t *>(
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "CGItem.h"
|
||||
|
||||
#include "Offsets.h"
|
||||
|
||||
namespace Item {
|
||||
|
||||
const uint8_t *InstanceBlock(const uint8_t *cgItem) {
|
||||
if (cgItem == nullptr)
|
||||
return nullptr;
|
||||
return *reinterpret_cast<const uint8_t *const *>(
|
||||
cgItem + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
}
|
||||
|
||||
const uint8_t *ObjectFields(const uint8_t *cgItem) {
|
||||
if (cgItem == nullptr)
|
||||
return nullptr;
|
||||
return *reinterpret_cast<const uint8_t *const *>(
|
||||
cgItem + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
}
|
||||
|
||||
} // namespace Item
|
||||
@@ -0,0 +1,38 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Accessors for a `CGItem`'s two descriptor-like pointers (see the "Item
|
||||
// lookups" notes in CLAUDE.md). Every item module used to spell out the same
|
||||
// `*reinterpret_cast<const uint8_t *const *>(cgItem + OFF_...)` deref; these
|
||||
// name it once.
|
||||
|
||||
namespace Item {
|
||||
|
||||
// The item's **instance block** (`CGItem + 0x08` dereferenced): a `uint64`
|
||||
// item GUID at `+0x00` and the `uint32` itemID at `+0x0C`. This is the block
|
||||
// the canonical inventory→cache path reads the itemID from. Returns nullptr
|
||||
// for a null `cgItem`; the stored pointer itself may still be null (callers
|
||||
// null-check the result before reading fields).
|
||||
const uint8_t *InstanceBlock(const uint8_t *cgItem);
|
||||
|
||||
// The item's **m_objectFields descriptor** (`CGItem + 0x114` dereferenced):
|
||||
// the UpdateField block holding stack count (`+0x20`), flags (`+0x3C`),
|
||||
// spell charges (`+0x28`), durability (`+0xA0`), enchantments, etc. Distinct
|
||||
// from the instance block. Returns nullptr for a null `cgItem`.
|
||||
const uint8_t *ObjectFields(const uint8_t *cgItem);
|
||||
|
||||
} // namespace Item
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "../Game.h"
|
||||
#include "../Offsets.h"
|
||||
#include "CGItem.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
@@ -23,8 +24,7 @@ namespace Item::Charges {
|
||||
int PushChargesForItem(void *L, const uint8_t *item) {
|
||||
if (item == nullptr)
|
||||
return 0;
|
||||
auto *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *descriptor = Item::ObjectFields(item);
|
||||
if (descriptor == nullptr)
|
||||
return 0;
|
||||
const int32_t stack = static_cast<int32_t>(*reinterpret_cast<const uint32_t *>(
|
||||
|
||||
+2
-12
@@ -34,6 +34,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/Arg.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -41,17 +42,6 @@ namespace Item::Consumable {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
constexpr uint32_t kItemClassConsumable = 0;
|
||||
constexpr uint32_t kInvTypeAmmo = 24; // INVTYPE_AMMO
|
||||
constexpr uint32_t kInvTypeThrown = 25; // INVTYPE_THROWN
|
||||
@@ -62,7 +52,7 @@ int __fastcall Script_C_Item_IsConsumableItem(void *L) {
|
||||
Game::Lua::PushBoolean(L, 0);
|
||||
return 1;
|
||||
}
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Game::Lua::PushBoolean(L, 0);
|
||||
return 1;
|
||||
|
||||
+7
-18
@@ -16,8 +16,10 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/Arg.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -32,8 +34,7 @@ namespace {
|
||||
int GetStackCount(const uint8_t *cgItem) {
|
||||
if (cgItem == nullptr)
|
||||
return 0;
|
||||
auto *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
cgItem + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *descriptor = Item::ObjectFields(cgItem);
|
||||
if (descriptor == nullptr)
|
||||
return 0;
|
||||
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
|
||||
@@ -51,8 +52,7 @@ int GetStackCount(const uint8_t *cgItem) {
|
||||
int GetUsesPerItem(const uint8_t *cgItem) {
|
||||
if (cgItem == nullptr)
|
||||
return 1;
|
||||
auto *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
cgItem + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *descriptor = Item::ObjectFields(cgItem);
|
||||
if (descriptor == nullptr)
|
||||
return 1;
|
||||
const int32_t raw = *reinterpret_cast<const int32_t *>(
|
||||
@@ -97,22 +97,11 @@ int CountInBag(void *L, int bagID, int targetItemID, bool includeUses) {
|
||||
// object resolver `FUN_OBJECT_RESOLVE_BY_GUID` (the same function
|
||||
// `GetItemBySlot` would call internally if the gate let us through).
|
||||
|
||||
using ResolveObjectByGuid_t = void *(__fastcall *)(int type,
|
||||
const char *debugName,
|
||||
uint32_t guidLo,
|
||||
uint32_t guidHi,
|
||||
int priority);
|
||||
|
||||
const uint8_t *ResolveByGuid(int type, uint64_t guid) {
|
||||
if (guid == 0)
|
||||
return nullptr;
|
||||
auto fn = reinterpret_cast<ResolveObjectByGuid_t>(
|
||||
Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
return static_cast<const uint8_t *>(
|
||||
fn(type, "ItemMgr",
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32),
|
||||
0x172));
|
||||
Object::ByGuid(type, guid, "ItemMgr", 0x172));
|
||||
}
|
||||
|
||||
// Walks linear slots `[firstSlot, lastSlot]` of `invMgr`'s GUID array
|
||||
@@ -130,7 +119,7 @@ int CountInGuidArray(const uint8_t *invMgr, int firstSlot, int lastSlot,
|
||||
return 0;
|
||||
int total = 0;
|
||||
for (int slot = firstSlot; slot <= lastSlot; slot++) {
|
||||
const uint8_t *item = ResolveByGuid(Offsets::OBJ_TYPE_ITEM, guidArray[slot]);
|
||||
const uint8_t *item = ResolveByGuid(Offsets::TYPEMASK_ITEM, guidArray[slot]);
|
||||
if (item == nullptr)
|
||||
continue;
|
||||
if (Item::ID::FromCGItem(item) != targetItemID)
|
||||
@@ -159,7 +148,7 @@ int CountInBankBags(int targetItemID, bool includeUses) {
|
||||
int total = 0;
|
||||
for (int slot = Offsets::INVMGR_BANK_BAG_FIRST_SLOT;
|
||||
slot <= Offsets::INVMGR_BANK_BAG_LAST_SLOT; slot++) {
|
||||
const uint8_t *bag = ResolveByGuid(Offsets::OBJ_TYPE_CONTAINER,
|
||||
const uint8_t *bag = ResolveByGuid(Offsets::TYPEMASK_CONTAINER,
|
||||
playerGuidArray[slot]);
|
||||
if (bag == nullptr)
|
||||
continue;
|
||||
|
||||
+2
-2
@@ -16,6 +16,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "cursor/Info.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -44,8 +45,7 @@ bool ItemLocked(const uint8_t *item) {
|
||||
// Reads a CGItem's 64-bit instance GUID into lo/hi. False if the instance
|
||||
// block pointer is absent.
|
||||
bool ReadItemGuid(const uint8_t *item, uint32_t *lo, uint32_t *hi) {
|
||||
auto *instance = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *instance = Item::InstanceBlock(item);
|
||||
if (instance == nullptr)
|
||||
return false;
|
||||
*lo = *reinterpret_cast<const uint32_t *>(instance + Offsets::OFF_INSTANCE_BLOCK_GUID);
|
||||
|
||||
+2
-2
@@ -15,6 +15,7 @@
|
||||
#include "Offsets.h"
|
||||
#include "event/Custom.h"
|
||||
#include "item/Arg.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Data.h"
|
||||
#include "item/Location.h"
|
||||
#include "tick/WorldTick.h"
|
||||
@@ -119,8 +120,7 @@ static int ResolveLocationToItemID(void *L, int idx) {
|
||||
const uint8_t *item = Item::Location::Resolve(L, idx);
|
||||
if (item == nullptr)
|
||||
return 0;
|
||||
auto *instance = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *instance = Item::InstanceBlock(item);
|
||||
if (instance == nullptr)
|
||||
return 0;
|
||||
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -34,8 +35,7 @@ namespace Item::Durability {
|
||||
int PushDurabilityForItem(void *L, const uint8_t *item) {
|
||||
if (item == nullptr)
|
||||
return 0;
|
||||
auto *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *descriptor = Item::ObjectFields(item);
|
||||
if (descriptor == nullptr)
|
||||
return 0;
|
||||
const uint32_t cur = *reinterpret_cast<const uint32_t *>(
|
||||
|
||||
+3
-16
@@ -17,6 +17,7 @@
|
||||
#include "item/Cursor.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
#include "item/Swap.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -25,20 +26,6 @@ namespace Item::Equipment {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
// Same item-cache peek pattern as `Item::Bag::PeekItemRecord` — we
|
||||
// don't share because each caller is one-line-different and the
|
||||
// helper isn't worth a header.
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
// `OffhandHasWeapon()` — true iff the player has a one-handed
|
||||
// weapon (or off-hand-only weapon) equipped in the off-hand slot.
|
||||
// Returns false for empty off-hand, shields, and held items
|
||||
@@ -64,7 +51,7 @@ int __fastcall Script_OffhandHasWeapon(void *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
auto *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Game::Lua::PushBoolean(L, 0);
|
||||
return 1;
|
||||
@@ -102,7 +89,7 @@ int __fastcall Script_C_Item_IsEquippableItem(void *L) {
|
||||
Game::Lua::PushBoolean(L, 0);
|
||||
return 1;
|
||||
}
|
||||
auto *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
auto *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Game::Lua::PushBoolean(L, 0);
|
||||
return 1;
|
||||
|
||||
+2
-2
@@ -14,6 +14,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "guid/Guid.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -27,8 +28,7 @@ namespace {
|
||||
uint64_t ReadItemGuid(const uint8_t *cgItem) {
|
||||
if (cgItem == nullptr)
|
||||
return 0;
|
||||
auto *instance = *reinterpret_cast<const uint8_t *const *>(
|
||||
cgItem + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *instance = Item::InstanceBlock(cgItem);
|
||||
if (instance == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint64_t *>(
|
||||
|
||||
+2
-12
@@ -27,6 +27,7 @@
|
||||
#include "item/Arg.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
#include "item/Spell.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -36,17 +37,6 @@ namespace Item::GetData {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, bool requestIfMissing);
|
||||
|
||||
const uint8_t *FetchItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, false);
|
||||
}
|
||||
|
||||
int CurrentLocaleIndex() {
|
||||
return *reinterpret_cast<int *>(Offsets::VAR_LOCALE_INDEX);
|
||||
}
|
||||
@@ -377,7 +367,7 @@ int PushDataForItemID(void *L, int itemID) {
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
}
|
||||
const uint8_t *record = FetchItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
|
||||
+2
-2
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
|
||||
@@ -23,8 +24,7 @@ namespace Item::ID {
|
||||
int FromCGItem(const uint8_t *item) {
|
||||
if (item == nullptr)
|
||||
return 0;
|
||||
auto *instance = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *instance = Item::InstanceBlock(item);
|
||||
if (instance == nullptr)
|
||||
return 0;
|
||||
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
|
||||
|
||||
+5
-15
@@ -20,6 +20,7 @@
|
||||
#include "item/ID.h"
|
||||
#include "item/Link.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
@@ -27,21 +28,10 @@
|
||||
|
||||
namespace Item::Info {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, bool requestIfMissing);
|
||||
|
||||
static const char *PushedOrEmpty(const char *s) { return (s != nullptr && s[0] != 0) ? s : ""; }
|
||||
|
||||
static int CurrentLocaleIndex() { return *reinterpret_cast<int *>(Offsets::VAR_LOCALE_INDEX); }
|
||||
|
||||
static const uint8_t *FetchItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, false);
|
||||
}
|
||||
|
||||
static const char *LookupItemClassName(uint32_t classID) {
|
||||
return PushedOrEmpty(DBC::LocalizedField(
|
||||
Offsets::VAR_ITEMCLASS_RECORDS, Offsets::VAR_ITEMCLASS_COUNT,
|
||||
@@ -114,7 +104,7 @@ static int __fastcall Script_GetItemInfoInstant(void *L) {
|
||||
|
||||
Game::Lua::PushNumber(L, static_cast<double>(itemID));
|
||||
|
||||
const uint8_t *record = FetchItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
for (int i = 0; i < 6; ++i)
|
||||
Game::Lua::PushNil(L);
|
||||
@@ -150,7 +140,7 @@ static int __fastcall Script_GetItemInfoInstant(void *L) {
|
||||
static int PushIconForItemID(void *L, int itemID) {
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = FetchItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr)
|
||||
return 0;
|
||||
const uint32_t displayInfoID = *reinterpret_cast<const uint32_t *>(
|
||||
@@ -229,7 +219,7 @@ static int __fastcall Script_C_Item_GetItemFamily(void *L) {
|
||||
const int itemID = Item::Arg::ResolveItemID(L, 1);
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = FetchItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
@@ -264,7 +254,7 @@ static int __fastcall Script_C_Item_GetItemInfo(void *L) {
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
|
||||
const uint8_t *record = FetchItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0; // nil this call; GET_ITEM_INFO_RECEIVED fires when ready
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "unit/Flags.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -41,8 +42,7 @@ int ItemIDForLocalPlayer(void *playerPtr, int slot1Based) {
|
||||
auto *item = static_cast<uint8_t *>(getBySlot(invMgr, slot1Based - 1));
|
||||
if (item == nullptr)
|
||||
return 0;
|
||||
auto *instance = *reinterpret_cast<uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *instance = Item::InstanceBlock(item);
|
||||
if (instance == nullptr)
|
||||
return 0;
|
||||
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include "item/ID.h"
|
||||
#include "item/Link.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
@@ -54,10 +55,6 @@ namespace Item::InventoryItemsForSlot {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
// invType → slot bitmask. Bit N (0-based) means "this item type fits
|
||||
// 1-based slot N+1". Values 0..28 cover every InventoryType
|
||||
// vanilla's Item.dbc emits. Indices outside this range read as 0
|
||||
@@ -146,18 +143,11 @@ bool PlayerCanEquip(const uint8_t *record) {
|
||||
return PlayerHasProficiency(classCode, subclass);
|
||||
}
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
const uint8_t *ItemRecordForCGItem(const uint8_t *cgItem) {
|
||||
const int itemID = Item::ID::FromCGItem(cgItem);
|
||||
if (itemID <= 0)
|
||||
return nullptr;
|
||||
return PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
return Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
}
|
||||
|
||||
uint32_t ReadInventoryType(const uint8_t *record) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "item/Data.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -24,21 +25,10 @@ namespace Item::InventoryType {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
int PushInventoryTypeForItemID(void *L, int itemID) {
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
|
||||
+2
-12
@@ -17,6 +17,7 @@
|
||||
#include "item/Data.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -24,21 +25,10 @@ namespace Item::Level {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
int PushItemLevelForItemID(void *L, int itemID) {
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
|
||||
+2
-15
@@ -17,6 +17,7 @@
|
||||
#include "Offsets.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/QualityColor.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
@@ -34,20 +35,6 @@ using BuildInstanceName_t = void(__thiscall *)(const void *cgItem, char *out,
|
||||
using BuildNameFromID_t = void(__fastcall *)(char *out, unsigned outSize,
|
||||
uint32_t itemID, int suffixID);
|
||||
|
||||
// Cached ItemStats record lookup. Same `_GetRecord` pattern the rest of
|
||||
// the codebase uses; passes a noop NULL callback so no SMSG fires for
|
||||
// uncached items — caller treats "not cached" as a clean failure.
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int dedupFlag);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const char *FromCGItem(const uint8_t *cgItem) {
|
||||
@@ -80,7 +67,7 @@ bool NameFromIDSuffix(uint32_t itemID, int suffixID, char *out, size_t outSize)
|
||||
bool BasicFromIDSuffix(uint32_t itemID, int suffixID, char *out, size_t outSize) {
|
||||
if (out == nullptr || outSize == 0)
|
||||
return false;
|
||||
const uint8_t *record = PeekItemRecord(itemID);
|
||||
const uint8_t *record = Item::PeekRecord(itemID);
|
||||
if (record == nullptr)
|
||||
return false;
|
||||
char name[128];
|
||||
|
||||
+8
-25
@@ -16,10 +16,13 @@
|
||||
#include "../Game.h"
|
||||
#include "../Offsets.h"
|
||||
#include "../guid/Guid.h"
|
||||
#include "../object/Resolve.h"
|
||||
#include "../unit/Identity.h"
|
||||
#include "Arg.h"
|
||||
#include "CGItem.h"
|
||||
#include "ID.h"
|
||||
#include "Link.h"
|
||||
#include "Record.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@@ -30,9 +33,6 @@ namespace {
|
||||
using GetItemBySlot_t = void *(__thiscall *)(void *thisInvMgr, int slot);
|
||||
using PackBagSlot_t = int(__fastcall *)(void *L, void **outInvMgr, int *outLinearSlot,
|
||||
int *outUnused);
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
// Reads `loc.fieldName` and returns it as an int. Returns false via the
|
||||
// boolean result if the field is missing or non-numeric. Always leaves the
|
||||
@@ -56,16 +56,8 @@ const uint8_t *ResolveBagSlot(void *L, int bagID, int slotIndex) {
|
||||
|
||||
// --- GUID-walk helpers ---------------------------------------------------
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
uint64_t ReadCGItemGUID(const uint8_t *item) {
|
||||
auto *instance = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *instance = Item::InstanceBlock(item);
|
||||
if (instance == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint64_t *>(
|
||||
@@ -105,12 +97,8 @@ void *EquippedBagInventory(int bagID) {
|
||||
const uint64_t bagGuid = getBagGuid(static_cast<uint32_t>(bagID - 1));
|
||||
if (bagGuid == 0)
|
||||
return nullptr; // no bag equipped in that slot
|
||||
using ResolveByGUID_t = void *(__fastcall *)(int, const char *, uint32_t,
|
||||
uint32_t, int);
|
||||
auto resolve = reinterpret_cast<ResolveByGUID_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
auto *container = static_cast<const uint8_t *>(
|
||||
resolve(Offsets::OBJ_TYPE_CONTAINER, "ItemMgr", static_cast<uint32_t>(bagGuid),
|
||||
static_cast<uint32_t>(bagGuid >> 32), 0x172));
|
||||
Object::ByGuid(Offsets::TYPEMASK_CONTAINER, bagGuid, "ItemMgr", 0x172));
|
||||
return ContainerInventory(container);
|
||||
}
|
||||
|
||||
@@ -128,7 +116,7 @@ int GetBagSlotCount(int bagID) {
|
||||
const int bagItemID = Item::ID::FromCGItem(bagItem);
|
||||
if (bagItemID == 0)
|
||||
return 0;
|
||||
auto *record = PeekItemRecord(static_cast<uint32_t>(bagItemID));
|
||||
auto *record = Item::PeekRecord(static_cast<uint32_t>(bagItemID));
|
||||
if (record == nullptr)
|
||||
return 0;
|
||||
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
|
||||
@@ -170,13 +158,8 @@ bool ParseGUIDString(const char *s, uint64_t *out) {
|
||||
const uint8_t *ResolveByGUID(uint64_t guid) {
|
||||
if (guid == 0)
|
||||
return nullptr;
|
||||
using ResolveByGUID_t = void *(__fastcall *)(int, const char *, uint32_t,
|
||||
uint32_t, int);
|
||||
auto fn = reinterpret_cast<ResolveByGUID_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
return static_cast<const uint8_t *>(fn(Offsets::OBJ_TYPE_ITEM, "ItemMgr",
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32),
|
||||
0x172));
|
||||
return static_cast<const uint8_t *>(
|
||||
Object::ByGuid(Offsets::TYPEMASK_ITEM, guid, "ItemMgr", 0x172));
|
||||
}
|
||||
|
||||
bool FindByItemID(void *L, int itemID, ByGUIDResult *out) {
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ const uint8_t *ResolveEquipmentSlot(int slot1Based);
|
||||
int GetBagSlotCount(int bagID);
|
||||
|
||||
// Given a `CGContainer*` (an equipped bag or bank bag, resolved by GUID via
|
||||
// `FUN_OBJECT_RESOLVE_BY_GUID` with `OBJ_TYPE_CONTAINER`), returns its own
|
||||
// `FUN_OBJECT_RESOLVE_BY_GUID` with `TYPEMASK_CONTAINER`), returns its own
|
||||
// inventory-manager object via the container's vtable method at
|
||||
// `+OFF_CONTAINER_GET_INVENTORY`. The returned object has the same layout as
|
||||
// the player inventory manager: slot count at `+0x00`, flat GUID array at
|
||||
|
||||
+2
-2
@@ -32,6 +32,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "guid/Guid.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -54,8 +55,7 @@ using UnlockAll_t = void(__cdecl *)();
|
||||
bool ReadItemGuid(const uint8_t *item, uint32_t *lo, uint32_t *hi) {
|
||||
if (item == nullptr)
|
||||
return false;
|
||||
auto *inst = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *inst = Item::InstanceBlock(item);
|
||||
if (inst == nullptr)
|
||||
return false;
|
||||
*lo = *reinterpret_cast<const uint32_t *>(inst + Offsets::OFF_INSTANCE_BLOCK_GUID);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "item/Data.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -24,21 +25,10 @@ namespace Item::MaxStackSize {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
int PushMaxStackSizeForItemID(void *L, int itemID) {
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
|
||||
+2
-12
@@ -18,6 +18,7 @@
|
||||
#include "item/ID.h"
|
||||
#include "item/Link.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -25,17 +26,6 @@ namespace Item::Name {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
// Reads `m_name[0]` directly off a cached record. Items only ever
|
||||
// populate the first name slot — the array shape (`char *m_name[4]`
|
||||
// per VanillaHelpers's `ItemStats_C`) is a client-internal layout, not
|
||||
@@ -44,7 +34,7 @@ const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
int PushNameForItemID(void *L, int itemID) {
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
|
||||
@@ -75,7 +75,9 @@
|
||||
#include "Offsets.h"
|
||||
#include "bag/UpdateDelayed.h"
|
||||
#include "event/Custom.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "tick/WorldTick.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
@@ -196,8 +198,7 @@ bool RemoveFrom(uint64_t *arr, int *count, uint64_t guid) {
|
||||
uint64_t ItemGUID(const uint8_t *item) {
|
||||
if (item == nullptr)
|
||||
return 0;
|
||||
auto *instance = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *instance = Item::InstanceBlock(item);
|
||||
if (instance == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint64_t *>(
|
||||
@@ -265,16 +266,11 @@ void AppendGuidArray(const uint8_t *invMgr, int first, int last, uint64_t *out,
|
||||
AddUnique(out, count, arr[slot]);
|
||||
}
|
||||
|
||||
using ResolveByGuid_t = void *(__fastcall *)(int type, const char *debugName,
|
||||
uint32_t guidLo, uint32_t guidHi,
|
||||
int priority);
|
||||
const uint8_t *ResolveByGuid(int type, uint64_t guid) {
|
||||
if (guid == 0)
|
||||
return nullptr;
|
||||
auto fn = reinterpret_cast<ResolveByGuid_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
return static_cast<const uint8_t *>(
|
||||
fn(type, "ItemMgr", static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), 0x172));
|
||||
Object::ByGuid(type, guid, "ItemMgr", 0x172));
|
||||
}
|
||||
|
||||
// Appends every item the player owns that ISN'T in bags 0..4 — worn
|
||||
@@ -308,7 +304,7 @@ void AppendNonBagOwned(uint64_t *out, int *count) {
|
||||
return;
|
||||
for (int slot = Offsets::INVMGR_BANK_BAG_FIRST_SLOT;
|
||||
slot <= Offsets::INVMGR_BANK_BAG_LAST_SLOT; ++slot) {
|
||||
const uint8_t *bag = ResolveByGuid(Offsets::OBJ_TYPE_CONTAINER, playerArr[slot]);
|
||||
const uint8_t *bag = ResolveByGuid(Offsets::TYPEMASK_CONTAINER, playerArr[slot]);
|
||||
if (bag == nullptr)
|
||||
continue;
|
||||
auto *bagInvMgr =
|
||||
|
||||
+4
-18
@@ -27,10 +27,12 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Data.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Openable.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -38,29 +40,13 @@ namespace Item::Openable {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
|
||||
// Reads `ITEM_FIELD_FLAGS` from the instance descriptor at +0x114.
|
||||
// Defaults to 0 if `cgItem` is null or the descriptor pointer hasn't
|
||||
// been populated yet.
|
||||
uint32_t InstanceFlags(const uint8_t *cgItem) {
|
||||
if (cgItem == nullptr)
|
||||
return 0;
|
||||
auto *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
cgItem + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *descriptor = Item::ObjectFields(cgItem);
|
||||
if (descriptor == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint32_t *>(
|
||||
@@ -73,7 +59,7 @@ int PushIsItemOpenable(void *L, const uint8_t *cgItem) {
|
||||
const int itemID = Item::ID::FromCGItem(cgItem);
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
|
||||
+2
-12
@@ -17,6 +17,7 @@
|
||||
#include "item/Data.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -24,21 +25,10 @@ namespace Item::Quality {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
int PushQualityForItemID(void *L, int itemID) {
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "Record.h"
|
||||
|
||||
#include "Offsets.h"
|
||||
|
||||
namespace Item {
|
||||
|
||||
const uint8_t *PeekRecord(uint32_t itemID) {
|
||||
using GetRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid,
|
||||
void *callback, void *userData,
|
||||
int dedup);
|
||||
auto fn = reinterpret_cast<GetRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
// Null callback = passive peek (no network query). dedup is irrelevant
|
||||
// with a null callback (nothing is appended to the pending list).
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, false);
|
||||
}
|
||||
|
||||
} // namespace Item
|
||||
@@ -0,0 +1,34 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Passive read of the client-side item cache (the ItemSparse `ItemStats_C`
|
||||
// records). Every read-only item accessor used to re-declare the same
|
||||
// `DBCache_ItemStats_C_GetRecord` typedef and call it with a null callback;
|
||||
// this names that one passive peek.
|
||||
|
||||
namespace Item {
|
||||
|
||||
// The cached `ItemStats_C` record for `itemID`, or nullptr if it isn't cached.
|
||||
// PASSIVE — a null callback means "look up only": it never warms the cache or
|
||||
// fires SMSG_ITEM_QUERY_SINGLE, so it is safe to call many times per frame
|
||||
// from tooltips / bag scans. (Eagerly triggering a query from a passive getter
|
||||
// is the cache-race trap documented in CLAUDE.md — the request/response path
|
||||
// lives in item/Data.cpp, not here.) Fields are read via the `OFF_ITEMSTATS_*`
|
||||
// offsets.
|
||||
const uint8_t *PeekRecord(uint32_t itemID);
|
||||
|
||||
} // namespace Item
|
||||
+2
-12
@@ -17,6 +17,7 @@
|
||||
#include "item/Data.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -24,21 +25,10 @@ namespace Item::SellPrice {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
int PushSellPriceForItemID(void *L, int itemID) {
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
|
||||
+2
-12
@@ -27,6 +27,7 @@
|
||||
#include "item/Data.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -34,21 +35,10 @@ namespace Item::Set {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
int PushSetIDForItemID(void *L, int itemID) {
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
|
||||
+3
-13
@@ -29,6 +29,7 @@
|
||||
#include "Offsets.h"
|
||||
#include "item/Arg.h"
|
||||
#include "item/Data.h"
|
||||
#include "item/Record.h"
|
||||
#include "spell/Lookup.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -37,17 +38,6 @@ namespace Item::Spell {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, bool requestIfMissing);
|
||||
|
||||
const uint8_t *FetchItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, false);
|
||||
}
|
||||
|
||||
const char *SpellNameForID(int spellID) {
|
||||
const uint8_t *record = ::Spell::Lookup::RecordForID(spellID);
|
||||
if (record == nullptr)
|
||||
@@ -69,7 +59,7 @@ int __fastcall Script_GetItemSpell(void *L) {
|
||||
const int itemID = Item::Arg::ResolveItemID(L, 1);
|
||||
if (itemID <= 0)
|
||||
return 0;
|
||||
const uint8_t *record = FetchItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
@@ -113,7 +103,7 @@ int FindOnUseSpellIDInRecord(const uint8_t *record) {
|
||||
int OnUseSpellIDForItemID(uint32_t itemID) {
|
||||
if (itemID == 0)
|
||||
return 0;
|
||||
const uint8_t *record = FetchItemRecord(itemID);
|
||||
const uint8_t *record = Item::PeekRecord(itemID);
|
||||
if (record == nullptr)
|
||||
return 0;
|
||||
return FindOnUseSpellIDInRecord(record);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -36,8 +37,7 @@ static int __fastcall Script_GetStackCount(void *L) {
|
||||
Game::Lua::PushNumber(L, 0.0);
|
||||
return 1;
|
||||
}
|
||||
auto *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *descriptor = Item::ObjectFields(item);
|
||||
if (descriptor == nullptr) {
|
||||
Game::Lua::PushNumber(L, 0.0);
|
||||
return 1;
|
||||
|
||||
+1
-11
@@ -47,6 +47,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
@@ -55,10 +56,6 @@ namespace Item::StatAccum {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, bool requestIfMissing);
|
||||
|
||||
// Base-record m_statType uses the ItemModType enum: 0=mana, 1=health,
|
||||
// 3=agility, 4=strength, 5=intellect, 6=spirit, 7=stamina (2 is
|
||||
// deprecated). Returns nullptr for types with no vanilla key.
|
||||
@@ -288,13 +285,6 @@ long Value(const Accum *acc, const char *key) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint8_t *FetchRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, false);
|
||||
}
|
||||
|
||||
double ComputeDPS(const uint8_t *record) {
|
||||
if (record == nullptr)
|
||||
return 0.0;
|
||||
|
||||
@@ -54,11 +54,6 @@ void AddByKey(Accum *acc, const char *key, long delta);
|
||||
// Read the accumulated value for `key` (0 for an unknown key). Linear scan.
|
||||
long Value(const Accum *acc, const char *key);
|
||||
|
||||
// Passive cache peek for an item's `ItemStats_C` record. Does NOT warm
|
||||
// the cache (returns nullptr for an uncached item) — see the item-cache
|
||||
// race note in CLAUDE.md.
|
||||
const uint8_t *FetchRecord(uint32_t itemID);
|
||||
|
||||
// Fold an item record's base stats + on-equip-spell stats into `acc`,
|
||||
// scaled by `sign` (+1 to add, -1 to subtract for a delta). No-op for a
|
||||
// null record.
|
||||
|
||||
+4
-3
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "item/Arg.h"
|
||||
#include "item/Record.h"
|
||||
#include "item/StatAccum.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -70,7 +71,7 @@ int __fastcall Script_GetItemStats(void *L) {
|
||||
return 0;
|
||||
}
|
||||
const int suffixID = StatAccum::ParseRandomSuffixFromLink(L, 1);
|
||||
const uint8_t *record = StatAccum::FetchRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
@@ -99,8 +100,8 @@ int __fastcall Script_GetItemStatDelta(void *L) {
|
||||
}
|
||||
const int suffix1 = StatAccum::ParseRandomSuffixFromLink(L, 1);
|
||||
const int suffix2 = StatAccum::ParseRandomSuffixFromLink(L, 2);
|
||||
const uint8_t *r1 = StatAccum::FetchRecord(static_cast<uint32_t>(id1));
|
||||
const uint8_t *r2 = StatAccum::FetchRecord(static_cast<uint32_t>(id2));
|
||||
const uint8_t *r1 = Item::PeekRecord(static_cast<uint32_t>(id1));
|
||||
const uint8_t *r2 = Item::PeekRecord(static_cast<uint32_t>(id2));
|
||||
if (r1 == nullptr || r2 == nullptr) {
|
||||
Game::Lua::PushNil(L);
|
||||
return 1;
|
||||
|
||||
+3
-4
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
@@ -40,8 +41,7 @@ bool ReadGuid(const void *cgObject, uint32_t *lo, uint32_t *hi) {
|
||||
if (cgObject == nullptr)
|
||||
return false;
|
||||
auto *base = static_cast<const uint8_t *>(cgObject);
|
||||
auto *inst = *reinterpret_cast<const uint8_t *const *>(
|
||||
base + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *inst = Item::InstanceBlock(base);
|
||||
if (inst == nullptr)
|
||||
return false;
|
||||
*lo = *reinterpret_cast<const uint32_t *>(inst + Offsets::OFF_INSTANCE_BLOCK_GUID);
|
||||
@@ -257,8 +257,7 @@ bool MoveCount(void *L, int srcBag, int srcSlot, int dstBag, int dstSlot, int co
|
||||
// server treats as a merge for same-item destinations (up to
|
||||
// maxStack). Route there for count == srcStack so callers don't
|
||||
// have to special-case "move everything".
|
||||
auto *srcDescriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
srcItem + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *srcDescriptor = Item::ObjectFields(srcItem);
|
||||
const int srcStack = srcDescriptor == nullptr ? 0 :
|
||||
static_cast<int>(*reinterpret_cast<const uint32_t *>(
|
||||
srcDescriptor + Offsets::OFF_DESCRIPTOR_STACK_COUNT));
|
||||
|
||||
+6
-18
@@ -18,7 +18,9 @@
|
||||
#include "item/Link.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/QualityColor.h"
|
||||
#include "item/Record.h"
|
||||
#include "item/TooltipItem.h"
|
||||
#include "object/Resolve.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
@@ -138,21 +140,6 @@ static int __fastcall Script_GameTooltipSetInventoryItemByID(void *L) {
|
||||
}
|
||||
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
|
||||
static const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
using ResolveObjectByGuid_t = void *(__fastcall *)(int type, const char *debugName,
|
||||
uint32_t guidLo, uint32_t guidHi,
|
||||
int priority);
|
||||
|
||||
// Resolves a stored item GUID into a CGItem via the engine's own
|
||||
// resolver. Same path Item::Count uses for direct bank reads — no
|
||||
// gating, no inventory walk, works for any object the engine has
|
||||
@@ -161,8 +148,9 @@ using ResolveObjectByGuid_t = void *(__fastcall *)(int type, const char *debugNa
|
||||
static void *ResolveItemByGuid(uint32_t guidLo, uint32_t guidHi) {
|
||||
if (guidLo == 0 && guidHi == 0)
|
||||
return nullptr;
|
||||
auto fn = reinterpret_cast<ResolveObjectByGuid_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
return fn(Offsets::OBJ_TYPE_ITEM, "GameTooltip:GetItem", guidLo, guidHi, 0x172);
|
||||
return Object::ByGuid(Offsets::TYPEMASK_ITEM,
|
||||
(static_cast<uint64_t>(guidHi) << 32) | guidLo,
|
||||
"GameTooltip:GetItem", 0x172);
|
||||
}
|
||||
|
||||
// `GameTooltip:GetItem()` → (name, link, itemID) for whichever item
|
||||
@@ -248,7 +236,7 @@ static int __fastcall Script_GameTooltipGetItem(void *L) {
|
||||
// OFF_TOOLTIP_COMPARE_SUFFIX — include it (in the link's suffix field)
|
||||
// when the compare-descriptor flag is set, so the link round-trips the
|
||||
// suffix for stat comparison. Matches 3.3.5's auction GetItem.
|
||||
const uint8_t *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
const uint8_t *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(static_cast<uint32_t>(itemID));
|
||||
return 0;
|
||||
|
||||
+2
-15
@@ -42,6 +42,7 @@
|
||||
#include "item/Data.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -49,25 +50,11 @@ namespace Item::Uniqueness {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid,
|
||||
void *callback, void *userData,
|
||||
int unused);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD));
|
||||
auto *cache = reinterpret_cast<void *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_ITEMDB_CACHE));
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
// Returns the item's `m_maxCount` or -1 if the record isn't cached.
|
||||
// `-1` is a "warm-and-bail" sentinel; caller pushes nothing on -1
|
||||
// so the Lua side sees the modern "MayReturnNothing" behaviour.
|
||||
int ReadMaxCount(uint32_t itemID) {
|
||||
const uint8_t *record = PeekItemRecord(itemID);
|
||||
const uint8_t *record = Item::PeekRecord(itemID);
|
||||
if (record == nullptr) {
|
||||
Item::Data::WarmCache(itemID);
|
||||
return -1;
|
||||
|
||||
+2
-13
@@ -40,6 +40,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/Arg.h"
|
||||
#include "item/Record.h"
|
||||
#include "item/Spell.h"
|
||||
#include "spell/Lookup.h"
|
||||
|
||||
@@ -49,21 +50,9 @@ namespace Item::Usable {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
|
||||
using SpellIsUsable_t = int(__fastcall *)(const uint8_t *spellRecord, int *outNoMana);
|
||||
|
||||
// Same item-cache peek pattern as the other item modules (no shared
|
||||
// helper — each call site is one line different). Sync, no load fired.
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
const uint8_t *PlayerDescriptor() {
|
||||
auto resolve = reinterpret_cast<ResolveUnitToken_t>(Offsets::FUN_RESOLVE_UNIT_TOKEN);
|
||||
auto *player = static_cast<const uint8_t *>(resolve("player"));
|
||||
@@ -91,7 +80,7 @@ Usability ComputeUsability(int itemID) {
|
||||
if (itemID <= 0)
|
||||
return r;
|
||||
|
||||
auto *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
auto *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr)
|
||||
return r; // not cached → sync "false", no load fired
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -52,8 +53,7 @@ EnchantInfo ReadTempEnchant(int paperdollSlot) {
|
||||
const uint8_t *item = Item::Location::ResolveEquipmentSlot(paperdollSlot);
|
||||
if (item == nullptr)
|
||||
return r;
|
||||
auto *desc = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *desc = Item::ObjectFields(item);
|
||||
if (desc == nullptr)
|
||||
return r;
|
||||
auto *slot = reinterpret_cast<const uint32_t *>(desc + OFF_TEMP_ENCHANT_SLOT);
|
||||
|
||||
+2
-20
@@ -47,6 +47,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Names.h"
|
||||
#include "event/Custom.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
@@ -107,25 +108,6 @@ uint32_t ClassIdFromRecord(const uint8_t *rec) {
|
||||
: 0;
|
||||
}
|
||||
|
||||
// ChrClasses.dbc record ID -> class token ("WARRIOR", "MAGE", …). The DBC's
|
||||
// filename field is the token; RAID_CLASS_COLORS et al. key on it. nullptr if
|
||||
// the ID is out of range or the record is missing.
|
||||
const char *ClassTokenForId(uint32_t classId) {
|
||||
if (classId == 0)
|
||||
return nullptr;
|
||||
const int count = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CHRCLASSES_COUNT));
|
||||
const uint8_t *const *records = *reinterpret_cast<const uint8_t *const *const *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CHRCLASSES_RECORDS));
|
||||
if (records == nullptr || static_cast<int>(classId) > count)
|
||||
return nullptr;
|
||||
const uint8_t *rec = records[classId];
|
||||
if (rec == nullptr)
|
||||
return nullptr;
|
||||
return *reinterpret_cast<const char *const *>(
|
||||
rec + Offsets::OFF_CHRCLASSES_FILENAME);
|
||||
}
|
||||
|
||||
constexpr int kNameLen = 48; // engine NameCache inline name[48]
|
||||
|
||||
void CopyName(char *dst, const char *src) {
|
||||
@@ -506,7 +488,7 @@ int __fastcall Script_GetPlayerInfo(void *L) {
|
||||
Game::Lua::PushString(L, r.name); // 1 name
|
||||
else
|
||||
Game::Lua::PushNil(L);
|
||||
const char *classToken = ClassTokenForId(r.classId); // 2 class token
|
||||
const char *classToken = DBC::ClassToken(r.classId); // 2 class token
|
||||
if (classToken != nullptr)
|
||||
Game::Lua::PushString(L, classToken);
|
||||
else
|
||||
|
||||
+2
-18
@@ -14,6 +14,7 @@
|
||||
#include "../Game.h"
|
||||
#include "../Offsets.h"
|
||||
#include "../guid/Guid.h"
|
||||
#include "../object/Resolve.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -62,19 +63,6 @@ using GetPosition_t = const C3Vector *(__thiscall *)(const void *self,
|
||||
C3Vector *outBuf);
|
||||
constexpr int VTBL_GET_POSITION_OFFSET = 0x14;
|
||||
|
||||
// `ClntObjMgrObjectPtr(typeMask, debugMessage, guid_lo, guid_hi, debugCode)`
|
||||
// — resolves a 64-bit GUID to the loaded `CGObject_C *` it currently
|
||||
// refers to, filtered by `typeMask`. Returns NULL when no live object
|
||||
// matches the GUID *and* the typeMask. Splitting the GUID into lo/hi
|
||||
// DWORDs on the stack is equivalent to the engine's
|
||||
// `__fastcall(uint32_t, const char*, uint64_t, int)` signature once the
|
||||
// `uint64_t` argument is placed in the same stack slots.
|
||||
using ClntObjMgrObjectPtr_t = void *(__fastcall *)(uint32_t typeMask,
|
||||
const char *debugMsg,
|
||||
uint32_t guidLo,
|
||||
uint32_t guidHi,
|
||||
int debugCode);
|
||||
|
||||
// Reads `(unit.m_objectFields[+0x224] & UNIT_DYNFLAG_LOOTABLE) != 0`
|
||||
// — the server-driven bit it sets when the local player has loot
|
||||
// rights on this unit. Works uniformly for live and dead CGUnit
|
||||
@@ -157,11 +145,7 @@ struct ScanCtx {
|
||||
};
|
||||
|
||||
int __fastcall ScanCallback(ScanCtx *ctx, void * /*unusedEdx*/, uint64_t guid) {
|
||||
auto ObjectPtr = reinterpret_cast<ClntObjMgrObjectPtr_t>(
|
||||
Offsets::FUN_CLNT_OBJ_MGR_OBJECT_PTR);
|
||||
void *obj = ObjectPtr(Offsets::TYPEMASK_UNIT, nullptr,
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), 0);
|
||||
void *obj = Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, nullptr, 0);
|
||||
if (obj == nullptr)
|
||||
return 1; // GUID isn't a unit; continue
|
||||
|
||||
|
||||
+3
-15
@@ -40,6 +40,7 @@
|
||||
#include "../event/Custom.h"
|
||||
#include "../event/SignalHook.h"
|
||||
#include "../guid/Guid.h"
|
||||
#include "../object/Resolve.h"
|
||||
#include "../tick/WorldTick.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -104,11 +105,6 @@ using ClntObjMgrEnumVisibleObjectsCallback_t = int(__fastcall *)(void *ctx,
|
||||
uint64_t guid);
|
||||
using ClntObjMgrEnumVisibleObjects_t =
|
||||
int(__fastcall *)(ClntObjMgrEnumVisibleObjectsCallback_t cb, void *ctx);
|
||||
using ClntObjMgrObjectPtr_t = void *(__fastcall *)(uint32_t typeMask,
|
||||
const char *debugMsg,
|
||||
uint32_t guidLo,
|
||||
uint32_t guidHi,
|
||||
int debugCode);
|
||||
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
|
||||
using LootUnit_t = void(__thiscall *)(void *player, void *target,
|
||||
char useDistanceCheck);
|
||||
@@ -290,11 +286,7 @@ void TryStartNext() {
|
||||
}
|
||||
|
||||
void StartLoot(uint64_t guid) {
|
||||
auto ObjectPtr = reinterpret_cast<ClntObjMgrObjectPtr_t>(
|
||||
Offsets::FUN_CLNT_OBJ_MGR_OBJECT_PTR);
|
||||
void *target = ObjectPtr(Offsets::TYPEMASK_UNIT, nullptr,
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), 0);
|
||||
void *target = Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, nullptr, 0);
|
||||
if (target == nullptr) {
|
||||
TryStartNext();
|
||||
return;
|
||||
@@ -423,11 +415,7 @@ struct EnumCtx {
|
||||
};
|
||||
|
||||
int __fastcall EnumCallback(EnumCtx *ctx, void * /*unusedEdx*/, uint64_t guid) {
|
||||
auto ObjectPtr = reinterpret_cast<ClntObjMgrObjectPtr_t>(
|
||||
Offsets::FUN_CLNT_OBJ_MGR_OBJECT_PTR);
|
||||
void *obj = ObjectPtr(Offsets::TYPEMASK_UNIT, nullptr,
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), 0);
|
||||
void *obj = Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, nullptr, 0);
|
||||
if (obj == nullptr)
|
||||
return 1;
|
||||
if (!IsLootableUnit(obj))
|
||||
|
||||
+2
-10
@@ -14,6 +14,7 @@
|
||||
#include "../Game.h"
|
||||
#include "../Offsets.h"
|
||||
#include "../guid/Guid.h"
|
||||
#include "../object/Resolve.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -21,11 +22,6 @@ namespace Loot::Unit {
|
||||
|
||||
namespace {
|
||||
|
||||
using ClntObjMgrObjectPtr_t = void *(__fastcall *)(uint32_t typeMask,
|
||||
const char *debugMsg,
|
||||
uint32_t guidLo,
|
||||
uint32_t guidHi,
|
||||
int debugCode);
|
||||
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
|
||||
|
||||
// `FUN_CMSG_LOOT_UNIT` is `__thiscall(player, target, useDistanceCheck)`.
|
||||
@@ -71,11 +67,7 @@ int __fastcall Script_LootUnit(void *L) {
|
||||
if (*reinterpret_cast<void *volatile *>(Offsets::VAR_LOCAL_PLAYER_PTR) == nullptr)
|
||||
return 0;
|
||||
|
||||
auto ObjectPtr = reinterpret_cast<ClntObjMgrObjectPtr_t>(
|
||||
Offsets::FUN_CLNT_OBJ_MGR_OBJECT_PTR);
|
||||
void *target = ObjectPtr(Offsets::TYPEMASK_UNIT, nullptr,
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), 0);
|
||||
void *target = Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, nullptr, 0);
|
||||
if (target == nullptr)
|
||||
return 0;
|
||||
|
||||
|
||||
+2
-10
@@ -23,6 +23,7 @@
|
||||
#include "../Game.h"
|
||||
#include "../Offsets.h"
|
||||
#include "../guid/Guid.h"
|
||||
#include "../object/Resolve.h"
|
||||
#include "../tick/WorldTick.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -38,11 +39,6 @@ enum class State {
|
||||
WaitingOpen,
|
||||
};
|
||||
|
||||
using ClntObjMgrObjectPtr_t = void *(__fastcall *)(uint32_t typeMask,
|
||||
const char *debugMsg,
|
||||
uint32_t guidLo,
|
||||
uint32_t guidHi,
|
||||
int debugCode);
|
||||
using ResolveUnitToken_t = void *(__fastcall *)(const char *token);
|
||||
using LootUnit_t = void(__thiscall *)(void *player, void *target,
|
||||
char useDistanceCheck);
|
||||
@@ -176,11 +172,7 @@ int __fastcall Script_LootUnitItem(void *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto ObjectPtr = reinterpret_cast<ClntObjMgrObjectPtr_t>(
|
||||
Offsets::FUN_CLNT_OBJ_MGR_OBJECT_PTR);
|
||||
void *target = ObjectPtr(Offsets::TYPEMASK_UNIT, nullptr,
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), 0);
|
||||
void *target = Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, nullptr, 0);
|
||||
if (target == nullptr) {
|
||||
Game::Lua::PushBool(L, false);
|
||||
return 1;
|
||||
|
||||
+5
-8
@@ -32,6 +32,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "dbc/Names.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -48,10 +49,8 @@ int __fastcall Script_GetAreaInfo(void *L) {
|
||||
}
|
||||
const int areaID = static_cast<int>(Game::Lua::ToNumber(L, 1));
|
||||
const char *name =
|
||||
(areaID > 0) ? DBC::LocalizedField(Offsets::VAR_AREATABLE_RECORDS,
|
||||
Offsets::VAR_AREATABLE_COUNT,
|
||||
static_cast<uint32_t>(areaID),
|
||||
Offsets::OFF_AREATABLE_NAMES)
|
||||
(areaID > 0) ? DBC::AreaName(static_cast<uint32_t>(areaID),
|
||||
/*resolveToParent=*/false)
|
||||
: nullptr;
|
||||
if (name == nullptr) {
|
||||
Game::Lua::PushNil(L);
|
||||
@@ -71,10 +70,8 @@ int __fastcall Script_GetAreas(void *L) {
|
||||
const int count =
|
||||
*reinterpret_cast<const int *>(Offsets::VAR_AREATABLE_COUNT);
|
||||
for (int id = 1; id <= count; ++id) {
|
||||
const char *name = DBC::LocalizedField(Offsets::VAR_AREATABLE_RECORDS,
|
||||
Offsets::VAR_AREATABLE_COUNT,
|
||||
static_cast<uint32_t>(id),
|
||||
Offsets::OFF_AREATABLE_NAMES);
|
||||
const char *name =
|
||||
DBC::AreaName(static_cast<uint32_t>(id), /*resolveToParent=*/false);
|
||||
if (name == nullptr)
|
||||
continue;
|
||||
Game::Lua::PushNumber(L, static_cast<double>(id));
|
||||
|
||||
+5
-21
@@ -32,7 +32,9 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
#include "unit/Identity.h"
|
||||
#include "tick/WorldTick.h"
|
||||
|
||||
@@ -43,10 +45,6 @@ namespace Merchant::Frame {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(
|
||||
void *cache, uint32_t itemID, const uint64_t *guid,
|
||||
void *callback, void *userData, bool requestIfMissing);
|
||||
|
||||
// Read the 64-bit merchant NPC GUID. Both halves zero means no
|
||||
// merchant window is open and the rest of the merchant globals are
|
||||
// stale.
|
||||
@@ -63,8 +61,7 @@ bool MerchantOpen(uint32_t &outGuidLo, uint32_t &outGuidHi) {
|
||||
int ItemIDFromCGItem(const uint8_t *cgItem) {
|
||||
if (cgItem == nullptr)
|
||||
return 0;
|
||||
auto *instance = *reinterpret_cast<const uint8_t *const *>(
|
||||
cgItem + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *instance = Item::InstanceBlock(cgItem);
|
||||
if (instance == nullptr)
|
||||
return 0;
|
||||
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
|
||||
@@ -75,31 +72,18 @@ int ItemIDFromCGItem(const uint8_t *cgItem) {
|
||||
uint64_t ItemGUIDFromCGItem(const uint8_t *cgItem) {
|
||||
if (cgItem == nullptr)
|
||||
return 0;
|
||||
auto *instance = *reinterpret_cast<const uint8_t *const *>(
|
||||
cgItem + Offsets::OFF_ITEM_INSTANCE_BLOCK);
|
||||
auto *instance = Item::InstanceBlock(cgItem);
|
||||
if (instance == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint64_t *>(
|
||||
instance + Offsets::OFF_INSTANCE_BLOCK_GUID);
|
||||
}
|
||||
|
||||
// Same `PeekItemRecord` pattern Item::Bag / Item::Equipment use —
|
||||
// inline cache peek with a null callback (no network round-trip on
|
||||
// miss). Same call shape `Item::Info::FetchItemRecord` uses; not
|
||||
// shared because each module has its own slightly different needs.
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(
|
||||
Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, false);
|
||||
}
|
||||
|
||||
// Looks up `itemID` in the ItemStats cache and reads quality from
|
||||
// `+0x1C`. Quality 0 = Poor (grey junk). Returns -1 on cache miss
|
||||
// so callers can distinguish "not loaded" from "loaded poor-quality".
|
||||
int ItemQuality(uint32_t itemID) {
|
||||
auto *record = PeekItemRecord(itemID);
|
||||
auto *record = Item::PeekRecord(itemID);
|
||||
if (record == nullptr)
|
||||
return -1;
|
||||
return static_cast<int>(*reinterpret_cast<const uint32_t *>(
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include "Offsets.h"
|
||||
#include "guid/Guid.h"
|
||||
#include "nameplate/Walk.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "ui/FrameObject.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -68,9 +69,6 @@ using NamePlate::Walk::ForEachNamePlatedUnit;
|
||||
using NamePlate::Walk::kOffUnitNamePlate;
|
||||
|
||||
using TokenToGUID_t = uint64_t(__fastcall *)(const char *token);
|
||||
using ResolveByGUID_t = void *(__fastcall *)(int type, const char *debugName,
|
||||
uint32_t guidLo, uint32_t guidHi,
|
||||
int priority);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -130,13 +128,8 @@ static void PushNamePlateForGUID(void *L, uint64_t guid) {
|
||||
Game::Lua::PushNil(L);
|
||||
return;
|
||||
}
|
||||
auto resolve = reinterpret_cast<ResolveByGUID_t>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID));
|
||||
auto *unit = static_cast<uint8_t *>(
|
||||
resolve(Offsets::OBJ_TYPE_UNIT, "NamePlate",
|
||||
static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32),
|
||||
0x172));
|
||||
Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, "NamePlate", 0x172));
|
||||
if (unit == nullptr) {
|
||||
Game::Lua::PushNil(L);
|
||||
return;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "unit/Position.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -31,12 +32,6 @@ using EnumCallback_t = int(__fastcall *)(void *ctx, void *unusedEdx,
|
||||
uint64_t guid);
|
||||
using EnumVisibleObjects_t = int(__fastcall *)(EnumCallback_t cb, void *ctx);
|
||||
|
||||
// `ClntObjMgrObjectPtr(typeMask, dbg, guidLo, guidHi, dbgCode)` — resolves
|
||||
// a GUID to its live `CGObject_C *`, filtered by typeMask; NULL if none.
|
||||
using ObjectPtr_t = void *(__fastcall *)(uint32_t typeMask, const char *dbg,
|
||||
uint32_t guidLo, uint32_t guidHi,
|
||||
int dbgCode);
|
||||
|
||||
struct ScanCtx {
|
||||
uint32_t typeMask;
|
||||
Guid::Type guidType;
|
||||
@@ -54,10 +49,7 @@ int __fastcall ScanCallback(ScanCtx *ctx, void * /*unusedEdx*/, uint64_t guid) {
|
||||
if (entry != ctx->wantEntry)
|
||||
return 1;
|
||||
|
||||
auto ObjectPtr =
|
||||
reinterpret_cast<ObjectPtr_t>(Offsets::FUN_CLNT_OBJ_MGR_OBJECT_PTR);
|
||||
void *obj = ObjectPtr(ctx->typeMask, nullptr, static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), 0);
|
||||
void *obj = Object::ByGuid(ctx->typeMask, guid, nullptr, 0);
|
||||
if (obj == nullptr)
|
||||
return 1;
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "Resolve.h"
|
||||
|
||||
#include "Offsets.h"
|
||||
|
||||
namespace Object {
|
||||
|
||||
void *ByGuid(int typeMask, uint64_t guid, const char *debugName, int priority) {
|
||||
using Fn = void *(__fastcall *)(int typeMask, const char *debugName,
|
||||
uint32_t guidLo, uint32_t guidHi,
|
||||
int priority);
|
||||
auto fn = reinterpret_cast<Fn>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID));
|
||||
return fn(typeMask, debugName, static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), priority);
|
||||
}
|
||||
|
||||
} // namespace Object
|
||||
@@ -0,0 +1,39 @@
|
||||
// This file is part of ClassicAPI.
|
||||
//
|
||||
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
||||
// of the GNU General Public License as published by the Free Software Foundation, either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Shared wrapper over the engine's object-manager GUID resolver
|
||||
// (`FUN_OBJECT_RESOLVE_BY_GUID` at 0x00468460). Every caller used to
|
||||
// re-declare the same `__fastcall` function-pointer typedef and split the
|
||||
// GUID by hand; this centralizes it.
|
||||
|
||||
namespace Object {
|
||||
|
||||
// Resolve `guid` to its live client object. `typeMask` is a bitmask of
|
||||
// `Offsets::TYPEMASK_*` (e.g. `TYPEMASK_UNIT | TYPEMASK_PLAYER`, or
|
||||
// `TYPEMASK_UNIT` / `TYPEMASK_OBJECT`). Returns nullptr when the GUID isn't
|
||||
// currently in the object table (out of range, despawned, pre-world).
|
||||
// Non-throwing — safe from any context (Lua callback, world tick, packet
|
||||
// hook). `priority` mirrors the engine's call-site priority argument: 0x172
|
||||
// for a normal resolve, 0 on the loot/enumeration paths. `debugName` is an
|
||||
// engine diagnostic label (may be nullptr).
|
||||
//
|
||||
// Returns `void *` — callers static_cast to the concrete object type they
|
||||
// expect (the engine hands back the same pointer regardless of type).
|
||||
void *ByGuid(int typeMask, uint64_t guid, const char *debugName = nullptr,
|
||||
int priority = 0x172);
|
||||
|
||||
} // namespace Object
|
||||
@@ -54,6 +54,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "item/Arg.h"
|
||||
#include "item/Record.h"
|
||||
#include "spell/Lookup.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
@@ -63,9 +64,6 @@ namespace Player::CanUseItem {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetItemRecord_t = const uint8_t *(__thiscall *)(void *cache, uint32_t itemID,
|
||||
const uint64_t *guid, void *callback,
|
||||
void *userData, int unused);
|
||||
// `__thiscall(player /*ecx*/, skillLineID) -> slot` (-1 if the player
|
||||
// doesn't have the skill line). See VAR docs on FUN_SKILL_LINE_TO_SLOT.
|
||||
using SkillLineToSlot_t = int(__thiscall *)(void *player, uint32_t skillLineID);
|
||||
@@ -76,13 +74,6 @@ using RepStanding_t = int(__fastcall *)(int factionID);
|
||||
// higher rank in spellID's chain. See FUN_SPELL_RANK_CHAIN_KNOWN.
|
||||
using SpellRankChainKnown_t = int(__thiscall *)(void *player, uint32_t spellID);
|
||||
|
||||
const uint8_t *PeekItemRecord(uint32_t itemID) {
|
||||
auto fn = reinterpret_cast<GetItemRecord_t>(Offsets::FUN_DBCACHE_ITEMSTATS_GET_RECORD);
|
||||
auto *cache = reinterpret_cast<void *>(Offsets::VAR_ITEMDB_CACHE);
|
||||
const uint64_t zeroGuid = 0;
|
||||
return fn(cache, itemID, &zeroGuid, nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
// True iff `mask` restricts a 1-based `index` (class/race) the player
|
||||
// isn't part of. Mask 0 and 0xFFFFFFFF both mean "no restriction".
|
||||
bool RestrictedOut(uint32_t mask, uint32_t index1Based) {
|
||||
@@ -236,7 +227,7 @@ bool RequiredReputationMet(const uint8_t *record) {
|
||||
bool ComputeCanUse(int itemID) {
|
||||
if (itemID <= 0)
|
||||
return false;
|
||||
auto *record = PeekItemRecord(static_cast<uint32_t>(itemID));
|
||||
auto *record = Item::PeekRecord(static_cast<uint32_t>(itemID));
|
||||
if (record == nullptr)
|
||||
return false; // not cached → sync false, no load fired
|
||||
auto *player = Unit::Identity::PlayerObject();
|
||||
|
||||
@@ -54,6 +54,8 @@
|
||||
#include "Offsets.h"
|
||||
#include "equipmentset/Locations.h"
|
||||
#include "event/Custom.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "player/StatSignal.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
@@ -79,14 +81,9 @@ const Event::Custom::AutoReserve _r2{kEvtDurability};
|
||||
// player object can be mid-create and momentarily unresolvable — a Lua
|
||||
// error thrown from there unwinds through raw engine code.
|
||||
bool SlotHasItem(uint32_t guidLo, uint32_t guidHi, int slot0Based) {
|
||||
using ResolveByGUID_t = void *(__fastcall *)(uint32_t typeMask,
|
||||
const char *debugName,
|
||||
uint32_t guidLo, uint32_t guidHi,
|
||||
int line);
|
||||
auto resolve =
|
||||
reinterpret_cast<ResolveByGUID_t>(Offsets::FUN_OBJECT_RESOLVE_BY_GUID);
|
||||
auto *player = static_cast<const uint8_t *>(resolve(
|
||||
Offsets::OBJ_TYPE_PLAYER, "ClassicAPI", guidLo, guidHi, 0x172));
|
||||
auto *player = static_cast<const uint8_t *>(Object::ByGuid(
|
||||
Offsets::TYPEMASK_PLAYER,
|
||||
(static_cast<uint64_t>(guidHi) << 32) | guidLo, "ClassicAPI", 0x172));
|
||||
if (player == nullptr)
|
||||
return false;
|
||||
const uint8_t *invMgr = player + Offsets::OFF_PLAYER_INVENTORY_MANAGER;
|
||||
@@ -197,8 +194,7 @@ uint32_t ItemDurability(uint64_t guid) {
|
||||
const uint8_t *item = EquipmentSet::Locations::ResolveItemByGUID(guid);
|
||||
if (item == nullptr)
|
||||
return 0;
|
||||
const uint8_t *descriptor = *reinterpret_cast<const uint8_t *const *>(
|
||||
item + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
const uint8_t *descriptor = Item::ObjectFields(item);
|
||||
if (descriptor == nullptr)
|
||||
return 0;
|
||||
return *reinterpret_cast<const uint32_t *>(
|
||||
|
||||
+31
-38
@@ -37,8 +37,10 @@
|
||||
#include "Game.h"
|
||||
#include "NameCache.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "dbc/Names.h"
|
||||
#include "friendlist/FriendList.h"
|
||||
#include "guid/Guid.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -108,18 +110,10 @@ int __fastcall Script_GetPlayerInfoByGUID(void *L) {
|
||||
realm = "";
|
||||
}
|
||||
|
||||
const char *englishClass = DBC::StringField(
|
||||
Offsets::VAR_CHRCLASSES_RECORDS, Offsets::VAR_CHRCLASSES_COUNT,
|
||||
classID, Offsets::OFF_CHRCLASSES_FILENAME);
|
||||
const char *localizedClass = DBC::LocalizedField(
|
||||
Offsets::VAR_CHRCLASSES_RECORDS, Offsets::VAR_CHRCLASSES_COUNT,
|
||||
classID, Offsets::OFF_CHRCLASSES_NAMES);
|
||||
const char *englishRace = DBC::StringField(
|
||||
Offsets::VAR_CHRRACES_RECORDS, Offsets::VAR_CHRRACES_COUNT,
|
||||
race, Offsets::OFF_CHRRACES_FILENAME);
|
||||
const char *localizedRace = DBC::LocalizedField(
|
||||
Offsets::VAR_CHRRACES_RECORDS, Offsets::VAR_CHRRACES_COUNT,
|
||||
race, Offsets::OFF_CHRRACES_NAMES);
|
||||
const char *englishClass = DBC::ClassToken(classID);
|
||||
const char *localizedClass = DBC::ClassName(classID);
|
||||
const char *englishRace = DBC::RaceToken(race);
|
||||
const char *localizedRace = DBC::RaceName(race);
|
||||
|
||||
Game::Lua::PushString(L, localizedClass ? localizedClass : "");
|
||||
Game::Lua::PushString(L, englishClass ? englishClass : "");
|
||||
@@ -143,18 +137,10 @@ int __fastcall Script_GetPlayerInfoByGUID(void *L) {
|
||||
// inside the Entry value.
|
||||
int PushFromNameCacheEntry(void *L, const char *name,
|
||||
const NameCache::Entry &e) {
|
||||
const char *englishClass = DBC::StringField(
|
||||
Offsets::VAR_CHRCLASSES_RECORDS, Offsets::VAR_CHRCLASSES_COUNT,
|
||||
e.classID, Offsets::OFF_CHRCLASSES_FILENAME);
|
||||
const char *localizedClass = DBC::LocalizedField(
|
||||
Offsets::VAR_CHRCLASSES_RECORDS, Offsets::VAR_CHRCLASSES_COUNT,
|
||||
e.classID, Offsets::OFF_CHRCLASSES_NAMES);
|
||||
const char *englishRace = DBC::StringField(
|
||||
Offsets::VAR_CHRRACES_RECORDS, Offsets::VAR_CHRRACES_COUNT,
|
||||
e.raceID, Offsets::OFF_CHRRACES_FILENAME);
|
||||
const char *localizedRace = DBC::LocalizedField(
|
||||
Offsets::VAR_CHRRACES_RECORDS, Offsets::VAR_CHRRACES_COUNT,
|
||||
e.raceID, Offsets::OFF_CHRRACES_NAMES);
|
||||
const char *englishClass = DBC::ClassToken(e.classID);
|
||||
const char *localizedClass = DBC::ClassName(e.classID);
|
||||
const char *englishRace = DBC::RaceToken(e.raceID);
|
||||
const char *localizedRace = DBC::RaceName(e.raceID);
|
||||
|
||||
Game::Lua::PushString(L, localizedClass ? localizedClass : "");
|
||||
Game::Lua::PushString(L, englishClass ? englishClass : "");
|
||||
@@ -180,9 +166,12 @@ int PushFromNameCacheEntry(void *L, const char *name,
|
||||
// `FUN_OBJECT_GET_NAME` on it; this routes through the player
|
||||
// NameCache for players AND the creature cache for NPCs, so it
|
||||
// works for both with a single call.
|
||||
// 2. If the unit isn't currently synced (ex-target who logged off,
|
||||
// player encountered earlier in chat but no longer visible),
|
||||
// fall back to the persistent NameCache (when enabled).
|
||||
// 2. Friends list. It keeps name + GUID for online AND offline
|
||||
// friends (SMSG_FRIEND_LIST), so a friend resolves even while
|
||||
// unsynced and never seen in chat. Always on (not opt-in).
|
||||
// 3. If still unresolved (ex-target who logged off, player
|
||||
// encountered earlier in chat but no longer visible), fall back
|
||||
// to the persistent NameCache (when enabled).
|
||||
//
|
||||
// `realm` is always `""` in vanilla — the engine doesn't populate
|
||||
// per-player realm names and 1.12 has no cross-realm interaction.
|
||||
@@ -194,8 +183,8 @@ int PushFromNameCacheEntry(void *L, const char *name,
|
||||
// - Missing or non-string arg (raises an error rather than return).
|
||||
// - Unparseable GUID string.
|
||||
// - Zero / NULL GUID.
|
||||
// - GUID not resolvable in the object manager AND not in persistent
|
||||
// NameCache (i.e., we've never seen this unit).
|
||||
// - GUID not resolvable in the object manager, not on the friends
|
||||
// list, AND not in the persistent NameCache (never seen this unit).
|
||||
//
|
||||
// Doesn't trigger a network query on miss — passive read, same as
|
||||
// `GetPlayerInfoByGUID`. Use `C_PlayerCache.RememberPlayer` or let
|
||||
@@ -217,16 +206,10 @@ int __fastcall Script_UnitNameFromGUID(void *L) {
|
||||
// safely returns the "UNKNOWNOBJECT" sentinel for non-unit
|
||||
// objects (gameobjects etc.), so we just gate on the sentinel
|
||||
// rather than pre-filtering by typemask.
|
||||
using ObjectPtr_t = void *(__fastcall *)(uint32_t typeMask,
|
||||
const char *debugMsg,
|
||||
uint32_t guidLo,
|
||||
uint32_t guidHi,
|
||||
int debugCode);
|
||||
using GetName_t = const char *(__thiscall *)(void *obj, int *outFlags);
|
||||
|
||||
auto objectPtr = reinterpret_cast<ObjectPtr_t>(
|
||||
Offsets::FUN_CLNT_OBJ_MGR_OBJECT_PTR);
|
||||
void *obj = objectPtr(Offsets::TYPEMASK_OBJECT, nullptr, lo, hi, 0);
|
||||
void *obj = Object::ByGuid(Offsets::TYPEMASK_OBJECT,
|
||||
(static_cast<uint64_t>(hi) << 32) | lo, nullptr, 0);
|
||||
if (obj != nullptr) {
|
||||
auto getName = reinterpret_cast<GetName_t>(Offsets::FUN_OBJECT_GET_NAME);
|
||||
const char *name = getName(obj, nullptr);
|
||||
@@ -239,6 +222,16 @@ int __fastcall Script_UnitNameFromGUID(void *L) {
|
||||
}
|
||||
}
|
||||
|
||||
// Friends-list fallback: the friend list keeps name + GUID for online
|
||||
// AND offline friends, so a friend resolves even while unsynced and
|
||||
// uncached. It needs no race/sex (this API returns only name + realm).
|
||||
if (const char *fname = FriendList::NameForGuid(
|
||||
(static_cast<uint64_t>(hi) << 32) | lo)) {
|
||||
Game::Lua::PushString(L, fname);
|
||||
Game::Lua::PushString(L, "");
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Object-manager miss / sentinel — fall back to the persistent
|
||||
// NameCache (when enabled). Covers ex-units no longer in the
|
||||
// engine's sync window.
|
||||
|
||||
@@ -50,8 +50,9 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "dbc/Names.h"
|
||||
#include "guid/Guid.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -61,8 +62,6 @@ namespace Player::LocationInfo {
|
||||
namespace {
|
||||
|
||||
using TokenToGuid_t = uint64_t(__fastcall *)(const char *token);
|
||||
using ResolveObject_t = void *(__fastcall *)(uint32_t typeMask, const char *dbg,
|
||||
uint32_t guidLo, uint32_t guidHi, int line);
|
||||
using GetName_t = const char *(__thiscall *)(void *obj, int *outFlags);
|
||||
using GroupLookup_t = void *(__fastcall *)(const uint64_t *guid);
|
||||
|
||||
@@ -105,10 +104,8 @@ bool LocationGuid(void *L, int locIdx, uint64_t *out) {
|
||||
|
||||
// Resolves a GUID to its currently-synced CGUnit, or null if not resident.
|
||||
const uint8_t *ResolveUnit(uint64_t guid) {
|
||||
auto resolve = reinterpret_cast<ResolveObject_t>(Offsets::FUN_CLNT_OBJ_MGR_OBJECT_PTR);
|
||||
return static_cast<const uint8_t *>(
|
||||
resolve(Offsets::OBJ_TYPE_UNIT, "ClassicAPI", static_cast<uint32_t>(guid),
|
||||
static_cast<uint32_t>(guid >> 32), 0));
|
||||
Object::ByGuid(Offsets::TYPEMASK_UNIT, guid, "ClassicAPI", 0));
|
||||
}
|
||||
|
||||
// Reads a UNIT_FIELD_BYTES_0 byte: the login-time mirror global when `guid` is
|
||||
@@ -164,16 +161,10 @@ int __fastcall Script_GetClass(void *L) {
|
||||
return 0;
|
||||
// className / classFile from ChrClasses.dbc — same reads as
|
||||
// C_CreatureInfo.GetClassInfo(classID).
|
||||
const char *classFile = DBC::StringField(Offsets::VAR_CHRCLASSES_RECORDS,
|
||||
Offsets::VAR_CHRCLASSES_COUNT,
|
||||
static_cast<uint32_t>(classID),
|
||||
Offsets::OFF_CHRCLASSES_FILENAME);
|
||||
const char *classFile = DBC::ClassToken(static_cast<uint32_t>(classID));
|
||||
if (classFile == nullptr)
|
||||
return 0; // classID with no ChrClasses row
|
||||
const char *className = DBC::LocalizedField(Offsets::VAR_CHRCLASSES_RECORDS,
|
||||
Offsets::VAR_CHRCLASSES_COUNT,
|
||||
static_cast<uint32_t>(classID),
|
||||
Offsets::OFF_CHRCLASSES_NAMES);
|
||||
const char *className = DBC::ClassName(static_cast<uint32_t>(classID));
|
||||
|
||||
Game::Lua::PushString(L, className); // NULL → nil via lua_pushstring
|
||||
Game::Lua::PushString(L, classFile);
|
||||
|
||||
@@ -66,7 +66,9 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Names.h"
|
||||
#include "guid/Guid.h"
|
||||
#include "object/Resolve.h"
|
||||
#include "settings/Account.h"
|
||||
#include "unit/Identity.h"
|
||||
|
||||
@@ -511,12 +513,6 @@ using EnumVisibleObjects_t = bool(__fastcall *)(void *callback, void *context);
|
||||
using EnumVisibleObjectsCallback_t = int(__fastcall *)(void *context, void *edx,
|
||||
uint64_t guid);
|
||||
|
||||
// GUID → CGObject pointer resolver with type-mask filter. Returns
|
||||
// NULL if the GUID isn't loaded or its object type doesn't match the
|
||||
// mask. We pass TYPEMASK_PLAYER for our player-only sweep.
|
||||
using ObjectPtr_t = void *(__fastcall *)(uint32_t typeMask, void *unused,
|
||||
uint64_t guid, int unused2);
|
||||
|
||||
// CGObject vftable's GetName slot. Slot 22 = byte offset 22 * 4 = 0x58.
|
||||
// VanillaMinimapTracking calls obj->vftable->GetName(obj) the same way
|
||||
// in its NameLookupCallback; verified working against the 1.12 binary.
|
||||
@@ -585,9 +581,7 @@ int __fastcall ScanCallback(void * /*context*/, void * /*edx*/, uint64_t guid) {
|
||||
// we hit when calling GetName on the local CGPlayer's vftable.
|
||||
if (guid == LocalPlayerGUID())
|
||||
return 1;
|
||||
auto resolver = reinterpret_cast<ObjectPtr_t>(
|
||||
static_cast<uintptr_t>(Offsets::FUN_CLNT_OBJ_MGR_OBJECT_PTR));
|
||||
void *obj = resolver(Offsets::TYPEMASK_PLAYER, nullptr, guid, 0);
|
||||
void *obj = Object::ByGuid(Offsets::TYPEMASK_PLAYER, guid, nullptr, 0);
|
||||
if (obj == nullptr)
|
||||
return 1; // not a player (or not currently loaded)
|
||||
const char *name = CallGetName(obj);
|
||||
@@ -636,80 +630,6 @@ bool ParseGUID(const char *str, uint64_t *outGUID) {
|
||||
return Guid::Parse(str, outGUID);
|
||||
}
|
||||
|
||||
// Returns the ChrClasses.dbc record ID for a class token like
|
||||
// `"WARRIOR"`, `"MAGE"`, etc. Case-insensitive. 0 if not matched.
|
||||
// 1.12 has 9 player classes; we walk the DBC each call (cheap — 9
|
||||
// records, each filename a few bytes) rather than building a static
|
||||
// table that risks getting out-of-sync.
|
||||
uint32_t ResolveClassToken(const char *token) {
|
||||
if (token == nullptr || *token == '\0')
|
||||
return 0;
|
||||
const int count = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CHRCLASSES_COUNT));
|
||||
const uint8_t *const *records = *reinterpret_cast<const uint8_t *const *const *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CHRCLASSES_RECORDS));
|
||||
if (records == nullptr)
|
||||
return 0;
|
||||
for (int i = 1; i <= count; ++i) {
|
||||
const uint8_t *rec = records[i];
|
||||
if (rec == nullptr)
|
||||
continue;
|
||||
const char *filename = *reinterpret_cast<const char *const *>(
|
||||
rec + Offsets::OFF_CHRCLASSES_FILENAME);
|
||||
if (filename == nullptr)
|
||||
continue;
|
||||
// Case-insensitive compare; vanilla tokens are uppercase
|
||||
// ("WARRIOR", "MAGE", ...) and modern Classic uses the same.
|
||||
const char *a = filename;
|
||||
const char *b = token;
|
||||
bool match = true;
|
||||
while (*a && *b) {
|
||||
char ca = *a, cb = *b;
|
||||
if (ca >= 'a' && ca <= 'z') ca -= 32;
|
||||
if (cb >= 'a' && cb <= 'z') cb -= 32;
|
||||
if (ca != cb) { match = false; break; }
|
||||
++a; ++b;
|
||||
}
|
||||
if (match && *a == '\0' && *b == '\0')
|
||||
return static_cast<uint32_t>(i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Same shape as ResolveClassToken but walks ChrRaces.dbc.
|
||||
uint32_t ResolveRaceToken(const char *token) {
|
||||
if (token == nullptr || *token == '\0')
|
||||
return 0;
|
||||
const int count = *reinterpret_cast<const int *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CHRRACES_COUNT));
|
||||
const uint8_t *const *records = *reinterpret_cast<const uint8_t *const *const *>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_CHRRACES_RECORDS));
|
||||
if (records == nullptr)
|
||||
return 0;
|
||||
for (int i = 1; i <= count; ++i) {
|
||||
const uint8_t *rec = records[i];
|
||||
if (rec == nullptr)
|
||||
continue;
|
||||
const char *filename = *reinterpret_cast<const char *const *>(
|
||||
rec + Offsets::OFF_CHRRACES_FILENAME);
|
||||
if (filename == nullptr)
|
||||
continue;
|
||||
const char *a = filename;
|
||||
const char *b = token;
|
||||
bool match = true;
|
||||
while (*a && *b) {
|
||||
char ca = *a, cb = *b;
|
||||
if (ca >= 'a' && ca <= 'z') ca -= 32;
|
||||
if (cb >= 'a' && cb <= 'z') cb -= 32;
|
||||
if (ca != cb) { match = false; break; }
|
||||
++a; ++b;
|
||||
}
|
||||
if (match && *a == '\0' && *b == '\0')
|
||||
return static_cast<uint32_t>(i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// `C_PlayerCache.RememberPlayer(guid, name, classToken [, raceToken
|
||||
// [, sex]])` — stores the entry in the persistent cache. Class and
|
||||
// race tokens are uppercase engine tokens (`"WARRIOR"`, `"NIGHTELF"`,
|
||||
@@ -740,13 +660,13 @@ int __fastcall Script_C_PlayerCache_RememberPlayer(void *L) {
|
||||
return 1;
|
||||
}
|
||||
const char *classToken = Game::Lua::ToString(L, 3);
|
||||
const uint32_t classID = ResolveClassToken(classToken);
|
||||
const uint32_t classID = DBC::ClassIdForToken(classToken);
|
||||
// Optional race + sex. Missing / non-string / unknown values
|
||||
// resolve to 0, which Remember() treats as "leave existing value
|
||||
// alone" — so a 3-arg call preserves any prior race/sex data.
|
||||
uint32_t raceID = 0;
|
||||
if (Game::Lua::IsString(L, 4))
|
||||
raceID = ResolveRaceToken(Game::Lua::ToString(L, 4));
|
||||
raceID = DBC::RaceIdForToken(Game::Lua::ToString(L, 4));
|
||||
uint32_t sex = 0;
|
||||
if (Game::Lua::IsNumber(L, 5)) {
|
||||
const double raw = Game::Lua::ToNumber(L, 5);
|
||||
|
||||
@@ -59,8 +59,10 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "item/CGItem.h"
|
||||
#include "item/ID.h"
|
||||
#include "item/Location.h"
|
||||
#include "item/Record.h"
|
||||
#include "item/StatAccum.h"
|
||||
#include "player/StatSignal.h"
|
||||
#include "spell/HealingAura.h"
|
||||
@@ -119,10 +121,9 @@ long ItemFlatHealing(const uint8_t *cgItem) {
|
||||
const int itemID = Item::ID::FromCGItem(cgItem);
|
||||
if (itemID > 0)
|
||||
Item::StatAccum::AccumulateRecord(
|
||||
acc, Item::StatAccum::FetchRecord(static_cast<uint32_t>(itemID)), +1);
|
||||
acc, Item::PeekRecord(static_cast<uint32_t>(itemID)), +1);
|
||||
|
||||
auto *desc = *reinterpret_cast<const uint8_t *const *>(
|
||||
cgItem + Offsets::OFF_ITEM_DESCRIPTOR);
|
||||
auto *desc = Item::ObjectFields(cgItem);
|
||||
if (desc != nullptr) {
|
||||
// Random suffix ("… of Restoration") + applied permanent (slot 0) and
|
||||
// temporary (slot 1) enchants (Healing Power, Mana Oil, …).
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user