Skip to main content

Module rewrite

Module rewrite 

Source
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§

intercept_assembly
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.