mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
Returns the active chat-bubble Frame objects, matching modern WoW's 7.2.5 signature. Vanilla's CGChatBubbleFrames are full CSimpleFrames the engine creates in C++ without CreateFrame (same as default nameplates), kept on an intrusive Storm TSList at 0x00B6F038 (next link +0x318, low-bit sentinel). Mirror the engine's own walk (FUN_004b1060) and push each as its canonical engine wrapper, so the returned frames are real and method-capable and their text FontString (+0x31c) surfaces via :GetRegions(). includeForbidden is accepted and ignored (vanilla has no forbidden frames). Factor the ScriptRegister->rawgeti wrapper push out of nameplate/Info into a shared UI::FrameObject::Push; PushNamePlateFrame now forwards to it (no behavior change).
83 lines
3.6 KiB
C++
83 lines
3.6 KiB
C++
// 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_ChatBubbles.GetAllChatBubbles([includeForbidden])` — returns an
|
|
// array of the currently-active chat-bubble Frame objects, matching
|
|
// modern WoW's 7.2.5 signature. Addons use it to recolor / translate /
|
|
// reposition speech bubbles by reading the bubble's FontString region.
|
|
//
|
|
// Vanilla 1.12 chat bubbles are `CGChatBubbleFrame`s — full
|
|
// `CSimpleFrame`s created purely in C++ (never via `CreateFrame`), so
|
|
// they have no name and no Lua wrapper until something pushes them. This
|
|
// is exactly the default-nameplate case: we push each via the shared
|
|
// `UI::FrameObject::Push`, which delegates to the engine's own
|
|
// `FrameScript_Object::ScriptRegister` to lazily build the canonical
|
|
// wrapper. The returned frames respond to real frame methods — the
|
|
// FontString holding the spoken text (bubble + 0x31c, created with the
|
|
// bubble as its parent) shows up in `bubble:GetRegions()`, so the modern
|
|
// "iterate GetRegions, find the FontString, read GetText()" idiom works
|
|
// unchanged. This is the pre-7.2.5 "walk WorldFrame children" pattern the
|
|
// wiki describes, but handed the exact set instead of the whole world.
|
|
//
|
|
// The engine keeps active bubbles on an intrusive Storm `TSList` whose
|
|
// head is `VAR_CHAT_BUBBLE_LIST_HEAD` (`0x00B6F038`); each node's forward
|
|
// link sits at `+0x318` and the list terminator carries the low-bit
|
|
// sentinel. We mirror the engine's own walk in the per-frame update
|
|
// `FUN_004b1060` / teardown `FUN_004b0f80` verbatim. Bubbles whose owner
|
|
// unit has despawned are pruned on the engine's next update tick, so a
|
|
// just-orphaned bubble can linger one frame — harmless, and addons that
|
|
// care filter on `bubble:IsShown()` (a real method here) anyway.
|
|
//
|
|
// `includeForbidden` is accepted and ignored: vanilla has no forbidden
|
|
// frames, so every bubble is returned regardless.
|
|
|
|
#include "Game.h"
|
|
#include "ui/FrameObject.h"
|
|
|
|
#include <cstdint>
|
|
|
|
namespace ChatBubble::Info {
|
|
|
|
namespace {
|
|
|
|
// Storm TSList of live CGChatBubbleFrames. Head pointer, per-node
|
|
// forward link, and the end-of-list low-bit sentinel — see the engine
|
|
// walks at 0x004b1060 / 0x004b0f80.
|
|
constexpr uintptr_t kListHead = 0x00B6F038;
|
|
constexpr int kOffNextLink = 0x318;
|
|
|
|
} // namespace
|
|
|
|
static int __fastcall Script_GetAllChatBubbles(void *L) {
|
|
Game::Lua::NewTable(L);
|
|
|
|
uintptr_t node = *reinterpret_cast<const uintptr_t *>(kListHead);
|
|
int nextIndex = 1;
|
|
while (node != 0 && (node & 1) == 0) {
|
|
Game::Lua::PushNumber(L, static_cast<double>(nextIndex++));
|
|
UI::FrameObject::Push(L, reinterpret_cast<void *>(node));
|
|
Game::Lua::SetTable(L, -3);
|
|
node = *reinterpret_cast<const uintptr_t *>(node + kOffNextLink);
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static void RegisterLuaFunctions() {
|
|
Game::Lua::RegisterTableFunction("C_ChatBubbles", "GetAllChatBubbles",
|
|
&Script_GetAllChatBubbles);
|
|
}
|
|
|
|
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
|
|
|
} // namespace ChatBubble::Info
|