Skip to content

levilamina::native

The native escape hatch: engine addresses and native detours, for an engine call that no other module wraps.

The host checks nothing a mod does with an address. The caller answers for signatures, calling conventions, the object layouts of this exact engine build, threads and lifetimes. Getting an address is therefore safe and every use of it is unsafe at the caller. The host's config.json has to set "native_detour": true; until it does, every call returns an Err saying so and enabled returns false.

Functions

native::enabled

Rust
pub fn enabled() -> bool

Whether the host answers the native calls, which its config.json decides.

native::resolve_symbol

Rust
pub fn resolve_symbol(symbol: &str) -> Result<*mut c_void>

The address of an engine function by its decorated symbol name.

native::resolve_signature

Rust
pub fn resolve_signature(pattern: &str) -> Result<*mut c_void>

The first match of a byte pattern such as "48 8B ?? 08" in the engine executable.

native::module_export

Rust
pub fn module_export(module: &str, name: &str) -> Result<*mut c_void>

An export of a module already loaded into the process; an empty module names the engine executable. LeviLamina's API is an export of LeviLamina.dll.

  • Parameters:
    • module : &str
    • name : &str
  • Return type: Result<*mut c_void>
  • Slots: native_module_export

native::object

Rust
pub fn object(kind: NativeObject) -> Result<*mut c_void>

The address of one engine service object. An Err while it does not exist yet.

  • Parameters:
    • kind : NativeObject
  • Return type: Result<*mut c_void>
  • Slots: native_object

native::player

Rust
pub fn player(player: &crate::Player) -> Result<*mut c_void>

The engine's Player object of an online player. Valid while the player stays online.

  • Parameters:
    • player : &crate::Player
  • Return type: Result<*mut c_void>
  • Slots: native_player

native::actor

Rust
pub fn actor(entity: &crate::Entity) -> Result<*mut c_void>

The engine's Actor object of a loaded actor. Valid while the actor stays loaded.

  • Parameters:
    • entity : &crate::Entity
  • Return type: Result<*mut c_void>
  • Slots: native_actor

native::dimension

Rust
pub fn dimension(dim: i32) -> Result<*mut c_void>

The engine's Dimension object of a dimension id, custom dimensions included.

  • Parameters:
    • dim : i32
  • Return type: Result<*mut c_void>
  • Slots: native_dimension

native::block_source

Rust
pub fn block_source(dim: i32) -> Result<*mut c_void>

The engine's BlockSource of a dimension id.

native::hook_install

Rust
1
2
3
4
5
pub unsafe fn hook_install(
    target: *mut c_void,
    detour: *mut c_void,
    priority: i32,
) -> Result<NativeHook>

Installs a detour on target through ll::memory::hook, at a PRIORITY_* value.

The host removes a detour this mod still holds when the mod unloads, before the dll is unmapped, and does not wait for a call already inside it on another thread.

Safety detour must be an extern function with the exact signature and calling convention of target. It must not unwind, and it reaches the engine through original only.

  • Parameters:
    • target : *mut c_void
    • detour : *mut c_void
    • priority : i32
  • Return type: Result<NativeHook>
  • Slots: native_hook_install

native::hook_remove

Rust
pub fn hook_remove(hook: NativeHook) -> Result<()>

Removes a detour this mod installed.

NativeObject

Rust
pub enum NativeObject {
        Minecraft,
        Level,
        ServerNetworkHandler,
        ServerInstance,
        CommandRegistry,
        NetworkSystem,
        DbStorage,
        /// Client hosts only.
        ClientInstance,
        /// Client hosts only: the level the client renders.
        MultiPlayerLevel,
}

The engine service objects object hands out.

  • Implements: Debug, Clone, Copy, PartialEq, Eq

NativeHook

Rust
1
2
3
4
pub struct NativeHook {
    pub id: u64,
    pub original: *mut c_void,
}

One installed detour: the id hook_remove takes, and the address through which the detour calls the next detour or the engine.

  • Implements: Debug, Clone, Copy, PartialEq, Eq

Constants

Name Value Description
PRIORITY_HIGHEST 0 ll::memory::HookPriority::Highest: runs first.
PRIORITY_HIGH 100 ll::memory::HookPriority::High.
PRIORITY_NORMAL 200 ll::memory::HookPriority::Normal.
PRIORITY_LOW 300 ll::memory::HookPriority::Low.
PRIORITY_LOWEST 400 ll::memory::HookPriority::Lowest: runs last.