mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
128 lines
5.3 KiB
C++
128 lines
5.3 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 Lesser 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 Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License along with
|
|
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
namespace Game {
|
|
|
|
using FrameScript_Initialize_t = bool(__fastcall *)();
|
|
using FrameScript_Execute_t = bool(__fastcall *)(const char *script, const char *scriptName);
|
|
using LoadScriptFunctions_t = void(__fastcall *)();
|
|
|
|
namespace Lua {
|
|
using CFunction = int(__fastcall *)(void *L);
|
|
|
|
// Lua 5.0 pseudo-index used to read/write entries on the globals table.
|
|
constexpr int GLOBALS_INDEX = -10001;
|
|
|
|
// Type tag values returned by `Type()` (lua_type).
|
|
constexpr int TYPE_NIL = 0;
|
|
constexpr int TYPE_BOOLEAN = 1;
|
|
constexpr int TYPE_LIGHTUSERDATA = 2;
|
|
constexpr int TYPE_NUMBER = 3;
|
|
constexpr int TYPE_STRING = 4;
|
|
constexpr int TYPE_TABLE = 5;
|
|
constexpr int TYPE_FUNCTION = 6;
|
|
|
|
using lua_isnumber_t = bool(__fastcall *)(void *L, int index);
|
|
using lua_isstring_t = bool(__fastcall *)(void *L, int index);
|
|
using lua_tonumber_t = double(__fastcall *)(void *L, int index);
|
|
using lua_tostring_t = const char *(__fastcall *)(void *L, int index);
|
|
using lua_pushnumber_t = void(__fastcall *)(void *L, double n);
|
|
using lua_pushnil_t = void(__fastcall *)(void *L);
|
|
using lua_pushboolean_t = void(__fastcall *)(void *L, int b);
|
|
using lua_pushstring_t = void(__fastcall *)(void *L, const char *s);
|
|
using lua_pushvalue_t = void(__fastcall *)(void *L, int idx);
|
|
using lua_pushcclosure_t = void(__fastcall *)(void *L, CFunction fn, int upvals);
|
|
using lua_newtable_t = void(__fastcall *)(void *L);
|
|
using lua_gettable_t = void(__fastcall *)(void *L, int idx);
|
|
using lua_rawget_t = void(__fastcall *)(void *L, int idx);
|
|
using lua_settable_t = void(__fastcall *)(void *L, int idx);
|
|
using lua_rawset_t = void(__fastcall *)(void *L, int idx);
|
|
using lua_insert_t = void(__fastcall *)(void *L, int idx);
|
|
using lua_settop_t = void(__fastcall *)(void *L, int idx);
|
|
using lua_type_t = int(__fastcall *)(void *L, int index);
|
|
using lua_error_t = void(__cdecl *)(void *L, const char *);
|
|
|
|
extern const lua_isnumber_t IsNumber;
|
|
extern const lua_isstring_t IsString;
|
|
extern const lua_tonumber_t ToNumber;
|
|
extern const lua_tostring_t ToString;
|
|
extern const lua_pushnumber_t PushNumber;
|
|
extern const lua_pushnil_t PushNil;
|
|
extern const lua_pushboolean_t PushBoolean;
|
|
extern const lua_pushstring_t PushString;
|
|
extern const lua_pushvalue_t PushValue;
|
|
extern const lua_pushcclosure_t PushCClosure;
|
|
extern const lua_newtable_t NewTable;
|
|
extern const lua_gettable_t GetTable;
|
|
extern const lua_rawget_t RawGet;
|
|
extern const lua_settable_t SetTable;
|
|
extern const lua_rawset_t RawSet;
|
|
extern const lua_insert_t Insert;
|
|
extern const lua_settop_t SetTop;
|
|
extern const lua_type_t Type;
|
|
extern const lua_error_t Error;
|
|
|
|
// Returns the global `lua_State *` (read on demand from the engine's global).
|
|
// Callable outside a Lua callback, e.g. during LoadScriptFunctions setup.
|
|
void *State();
|
|
|
|
// Registers a single global Lua function (e.g. `GetSpellInfo`). The function
|
|
// must use the WoW Lua C function ABI: `int __fastcall(void *L)`.
|
|
void RegisterGlobalFunction(const char *name, CFunction func);
|
|
|
|
// Frame-method registration entry: { name, func } pairs walked by the engine's
|
|
// per-frame-type method-table iterator. Layout matches what the engine expects
|
|
// natively — name first, then function pointer.
|
|
struct FrameMethodEntry {
|
|
const char *name;
|
|
CFunction func;
|
|
};
|
|
|
|
// Registers a batch of methods on a per-frame-type registry (e.g.
|
|
// GameTooltipMethodRegistry for `tooltip:Foo()` calls). `context` is the
|
|
// registry address — see Offsets::VAR_*_METHOD_REGISTRY.
|
|
void RegisterFrameMethods(void *context, const FrameMethodEntry *table, int count);
|
|
|
|
// Registers `func` at `_G[tableName][methodName]`, creating the namespace
|
|
// table if it doesn't already exist. This is how modern WoW C_*-style APIs
|
|
// are bound — the engine has no built-in support for table-bound Lua
|
|
// functions, so we manipulate the globals table directly via the Lua C API.
|
|
void RegisterTableFunction(const char *tableName, const char *methodName,
|
|
CFunction func);
|
|
} // namespace Lua
|
|
|
|
extern const FrameScript_Execute_t FrameScript_Execute;
|
|
|
|
// Self-registration for API modules. Each module .cpp declares a file-scope
|
|
// `static const Game::ModuleAutoRegister _r{&RegisterLuaFunctions};`, which
|
|
// chains itself onto a global list at DLL-load time. `RunModuleRegistrations`
|
|
// is called once from the LoadScriptFunctions post-hook to fire them all,
|
|
// so DllMain.cpp doesn't need to know the modules exist.
|
|
//
|
|
// Order is unspecified (LIFO of static-init order across TUs). Modules must
|
|
// not depend on each other's registration side effects.
|
|
struct ModuleAutoRegister {
|
|
using Fn = void (*)();
|
|
explicit ModuleAutoRegister(Fn fn);
|
|
Fn fn;
|
|
ModuleAutoRegister *next;
|
|
};
|
|
|
|
void RunModuleRegistrations();
|
|
|
|
} // namespace Game
|