Skip to main content

Module rewrite

Module rewrite 

Source
Available on crate feature hao only.
Expand description

Rewrite a managed assembly’s IL with hao before the runtime JITs it.

The Godot/CoreCLR modding path: a native mod intercepts the game assembly’s load (see intercept_assembly) and hands CoreCLR a hao-rewritten copy. The rewrite (patch_call) adds a [DllImport]-style P/Invoke to a function the mod exports and calls it from a lifecycle method — so the method the engine already runs each frame on the main thread now also calls back into Rust. No injected assembly, no C#; pure LD_PRELOAD + hao.

Functions§

arm_interceptionUnix and x86-64
Installs the open/openat hooks so registered targets are intercepted. Called automatically after coreclr_initialize returns — the CLR is loaded but managed assemblies haven’t been opened yet.
intercept_assemblyUnix and x86-64
Serves a rewritten copy of basename (matched by file name) whenever the runtime opens it. patch receives the original bytes and returns the replacement (see patch_call). Call it from a mod’s entry point, before the runtime loads the assembly.
patch_call
Rewrites assembly so type_name::method_name begins by calling the native function symbol, exported from library (resolved as a [DllImport]). Returns the patched assembly bytes.