Skip to content

Native escape hatch

Section notes in abi.h

Native escape hatch (native_*); its section near the top of this file is the

contract. Filled on every host. While config.json leaves native_detour off, each slot but native_enabled answers PIER_NATIVE_DISABLED. Call them on the thread the host calls the mod on: the server thread, or the client thread on a client host. Every out is set to NULL or 0 first and written on PIER_NATIVE_OK only.

Slots

native_enabled

C
bool (*native_enabled)(void);

Whether native_detour is on, so the other native_* slots can answer. Logs nothing.

native_resolve_symbol

C
int32_t (*native_resolve_symbol)(PierModHandle mod, PierStr symbol, void** out);

The address of an engine function by its decorated symbol name, through the host's own resolution, ll::memory::SymbolView::resolve.

  • Call: api->native_resolve_symbol(mod, symbol, out)
  • Parameters:
    • mod : PierModHandle
    • symbol : PierStr
    • out : void**
  • Return type: int32_t
  • Section of abi.h: Native escape hatch (native_*); its section near the top of this file is the
  • Position in the table: slot 207, counting from 0
  • Callers in each binding:

native_resolve_signature

C
int32_t (*native_resolve_signature)(PierModHandle mod, PierStr pattern, void** out);

The first match of a byte pattern in the engine executable. pattern is tokens separated by spaces, each two hexadecimal digits or a wildcard written "?" or "??", such as "48 8B ?? 08". A token of any other shape refuses the call; it is never read as a byte.

  • Call: api->native_resolve_signature(mod, pattern, out)
  • Parameters:
    • mod : PierModHandle
    • pattern : PierStr
    • out : void**
  • Return type: int32_t
  • Section of abi.h: Native escape hatch (native_*); its section near the top of this file is the
  • Position in the table: slot 208, counting from 0
  • Callers in each binding:

native_module_export

C
int32_t (*native_module_export)(PierModHandle mod, PierStr module, PierStr name,
                                void** out);

An export of a module already loaded into the process, through GetModuleHandle and GetProcAddress. An empty module names the engine executable. LeviLamina's own API is reached this way, as an export of LeviLamina.dll under its decorated name. The host never loads a module for this call.

  • Call: api->native_module_export(mod, module, name, out)
  • Parameters:
    • mod : PierModHandle
    • module : PierStr
    • name : PierStr
    • out : void**
  • Return type: int32_t
  • Section of abi.h: Native escape hatch (native_*); its section near the top of this file is the
  • Position in the table: slot 209, counting from 0
  • Callers in each binding:

native_object

C
int32_t (*native_object)(PierModHandle mod, int32_t kind, void** out);

The address of one engine service object, kind a PIER_NATIVE_OBJ_* value. PIER_NATIVE_NOT_FOUND while the object does not exist, as the level before a world loads, and for a client-only kind on a server host.

  • Call: api->native_object(mod, kind, out)
  • Parameters:
    • mod : PierModHandle
    • kind : int32_t
    • out : void**
  • Return type: int32_t
  • Section of abi.h: Native escape hatch (native_*); its section near the top of this file is the
  • Position in the table: slot 210, counting from 0
  • Callers in each binding:

native_player

C
int32_t (*native_player)(PierModHandle mod, PierPlayerSel sel, void** out);

The Player object of an online player, resolved like every other selector.

  • Call: api->native_player(mod, sel, out)
  • Parameters:
    • mod : PierModHandle
    • sel : PierPlayerSel
    • out : void**
  • Return type: int32_t
  • Section of abi.h: Native escape hatch (native_*); its section near the top of this file is the
  • Position in the table: slot 211, counting from 0
  • Callers in each binding:

native_actor

C
int32_t (*native_actor)(PierModHandle mod, PierActorId id, void** out);

The Actor object of a loaded actor.

  • Call: api->native_actor(mod, id, out)
  • Parameters:
    • mod : PierModHandle
    • id : PierActorId
    • out : void**
  • Return type: int32_t
  • Section of abi.h: Native escape hatch (native_*); its section near the top of this file is the
  • Position in the table: slot 212, counting from 0
  • Callers in each binding:

native_dimension

C
int32_t (*native_dimension)(PierModHandle mod, int32_t dim, void** out);

The Dimension object of a dimension id, custom dimensions included. A custom dimension the engine has not built yet is built by this call, the same as a block write into it would build it.

  • Call: api->native_dimension(mod, dim, out)
  • Parameters:
    • mod : PierModHandle
    • dim : int32_t
    • out : void**
  • Return type: int32_t
  • Section of abi.h: Native escape hatch (native_*); its section near the top of this file is the
  • Position in the table: slot 213, counting from 0
  • Callers in each binding:

native_block_source

C
int32_t (*native_block_source)(PierModHandle mod, int32_t dim, void** out);

The BlockSource of a dimension id, under the same rule as native_dimension.

  • Call: api->native_block_source(mod, dim, out)
  • Parameters:
    • mod : PierModHandle
    • dim : int32_t
    • out : void**
  • Return type: int32_t
  • Section of abi.h: Native escape hatch (native_*); its section near the top of this file is the
  • Position in the table: slot 214, counting from 0
  • Callers in each binding:

native_hook_install

C
int32_t (*native_hook_install)(PierModHandle mod, void* target, void* detour,
                               int32_t priority, void** out_original, uint64_t* out_id);

Installs a native detour on target through ll::memory::hook.

detour must have the exact signature and calling convention of target, which the host cannot check. priority is 0 highest to 400 lowest with 200 normal, the values of ll::memory::HookPriority; a value outside 0..400 refuses the call. On PIER_NATIVE_OK *out_original receives the address through which the detour calls the next detour or the engine, and *out_id the id native_hook_remove takes.

The host records which mod installed what. When a mod unloads, every detour it still holds is removed before its dll is unmapped. A call already running inside a detour on another thread is not waited for, so a mod unloaded at runtime removes its detours itself first or keeps them off other threads. One (target, detour) pair installs once; a second install of the same pair is refused.

  • Call: api->native_hook_install(mod, target, detour, priority, out_original, out_id)
  • Parameters:
    • mod : PierModHandle
    • target : void*
    • detour : void*
    • priority : int32_t
    • out_original : void**
    • out_id : uint64_t*
  • Return type: int32_t
  • Section of abi.h: Native escape hatch (native_*); its section near the top of this file is the
  • Position in the table: slot 215, counting from 0
  • Callers in each binding:

native_hook_remove

C
int32_t (*native_hook_remove)(PierModHandle mod, uint64_t id);

Removes a detour this mod installed. PIER_NATIVE_NOT_FOUND for an id this mod does not hold, one already removed included. PIER_NATIVE_FAILED when the engine-side removal fails; the detour then stays recorded and is tried again at unload.

  • Call: api->native_hook_remove(mod, id)
  • Parameters:
    • mod : PierModHandle
    • id : uint64_t
  • Return type: int32_t
  • Section of abi.h: Native escape hatch (native_*); its section near the top of this file is the
  • Position in the table: slot 216, counting from 0
  • Callers in each binding:

PierNativeObject

native_object kinds.

Name Value Description
PIER_NATIVE_OBJ_MINECRAFT 0 ll::service::getMinecraft
PIER_NATIVE_OBJ_LEVEL 1 ll::service::getLevel
PIER_NATIVE_OBJ_SERVER_NETWORK_HANDLER 2 ll::service::getServerNetworkHandler
PIER_NATIVE_OBJ_SERVER_INSTANCE 3 ll::service::getServerInstance
PIER_NATIVE_OBJ_COMMAND_REGISTRY 4 ll::service::getCommandRegistry
PIER_NATIVE_OBJ_NETWORK_SYSTEM 5 ll::service::getNetworkSystem
PIER_NATIVE_OBJ_DB_STORAGE 6 ll::service::getDBStorage
PIER_NATIVE_OBJ_CLIENT_INSTANCE 7 ll::service::getClientInstance, client hosts
PIER_NATIVE_OBJ_MULTIPLAYER_LEVEL 8 ll::service::getMultiPlayerLevel, client hosts: the level the client renders

PIER_NATIVE_*

native_* return codes.

Name Value Description
PIER_NATIVE_OK 0 done; the outputs are written
PIER_NATIVE_DISABLED 1 config.json of the host does not set native_detour to true
PIER_NATIVE_NOT_FOUND 2 no such symbol, pattern match, export, object or actor now
PIER_NATIVE_REFUSED 3 a null or malformed argument, an unknown kind, a foreign id
PIER_NATIVE_FAILED 4 the engine-side call failed: a detour that did not install