Skip to content

Memory Hook Macros

Purpose

pl/api/memory/Hook.h provides C++ macros for declaring and registering hooks with less boilerplate.

cpp
#include <pl/api/memory/Hook.h>
cpp
namespace memory {
enum class HookPriority : int {
  Highest,
  High,
  Normal,
  Low,
  Lowest,
};
}

Common Macros

MacroPurpose
LL_STATIC_HOOKStatic function hook, manual registration
LL_AUTO_STATIC_HOOKStatic function hook, automatic registration
LL_INSTANCE_HOOKMember function hook, manual registration
LL_AUTO_INSTANCE_HOOKMember function hook, automatic registration
LL_TYPED_STATIC_HOOKStatic hook that inherits from a custom type
LL_AUTO_TYPED_STATIC_HOOKAuto typed static hook
LL_TYPED_HOOKMember hook that inherits from a custom type
LL_AUTO_TYPED_INSTANCE_HOOKAuto typed member hook

Parameters

cpp
LL_STATIC_HOOK(DefType, priority, identifier, module, Ret, ...)
ParameterDescription
DefTypeGenerated hook type name
prioritymemory::HookPriority
identifierTarget address, function pointer, function name, or pattern
moduleTarget module name
RetReturn type
...Target function parameter list

Static Function Example

cpp
#include <pl/api/memory/Hook.h>

LL_STATIC_HOOK(MyTickHook,
               memory::HookPriority::Normal,
               "Game_tick",
               "libminecraftpe.so",
               void,
               void *self) {
  origin(self);
}

void install() {
  MyTickHook::hook();
}

Notes

  • origin(...) calls the original or next function in the hook chain.
  • Detour parameters and return type must match the target function.
  • Automatic registration may fail if the target function is not available yet.