> xur-stub
Loading the stub
Run Xur scripts inside another process: preloaded, injected, or loaded through a proxy
library. Inside it, scripts get the std::stub modules listed in the menu.
Synopsis
XUR_STUB_PATH=mod.xur LD_PRELOAD=libxur_stub.so ./game
xur stub inject --pid 1234 mod.xurDescription
The Xur stub is a shared library (libxur_stub.so on Linux, xur_stub.dll on Windows, built from the xur-stub crate) that runs Xur scripts inside the process that loads it. Scripts get the whole standard library plus the stub-only std::stub modules (see MODULES), which hook functions and reach into game engines from the inside.
Inside the stub, std::xur::invoked_by() returns "stub" (it is "cli" under xur run), so one script can tell which way it was started.
Loading the stub
LD_PRELOADStart the host with
LD_PRELOAD=/path/to/libxur_stub.so(and usuallyXUR_STUB_PATH). The stub's constructor runs before the host'smain, so scripts can install hooks before the program starts.xur stub injectLoad the stub into an already running process (Linux x86-64, via ptrace) and run a script there; see
xur(1). The stub's constructor still runs on load but, with no script source configured in the target, does nothing; the injector then calls the exported entry pointxur_stub_runwith the script's path.xur stub generate-proxyBuild a proxy for a library the host loads (PE
.dllor ELF.so): it forwards the real library's exports to a renamed copy and depends on the stub, so the OS loader loads the stub too. Useful whereLD_PRELOADisn't available, e.g. Windows games.xur stub add-neededAdd a
DT_NEEDEDentry for the stub to one of the host's own ELF libraries, so the loader loads the stub with it.
The proxy and DT_NEEDED routes load the stub at startup like LD_PRELOAD, so its constructor finds scripts the same way.
Finding scripts
When the stub's constructor runs, it looks for scripts in:
XUR_STUB_PATH, if set: a .xur file, or a directory. If it names neither, the stub logs an error and runs nothing.
Otherwise, a directory named xur beside the host executable (<host exe dir>/xur/). If there is none, the stub logs that and runs nothing.
For a directory, if it has a main.xur only that is run (it can import the rest); otherwise every *.xur file in it is run, in sorted path order. Each script is compiled into its own VM, so scripts share no globals. A script with compile errors is logged and skipped.
Lifecycle
ctor()If a script defines
fn ctor(), it runs first, for every script in turn, while the host waits: the stub's library constructor blocks until allctor()functions have returned, so they finish before the host'smainstarts. Put early hooks here (e.g.egui::init()). Keep it short: the host is stalled until it returns. Errors are logged.stub_main()Then each script's
fn stub_main()— orfn main()if it has nostub_main— starts on its own background thread, and the host carries on. It may run forever (e.g. an overlay's draw loop). Definingstub_mainlets one file be both a CLI program (main, forxur run) and a stub payload. A runtime error, or anErrit returns, is logged.
Script threads run with a 256 MiB stack. What a script prints with std::io goes to the host's standard error.
xur_stub_run(path) is the entry xur stub inject uses: a C function taking a NUL-terminated path to a .xur file or directory. It finds scripts there as above, then runs the ctor() functions and starts the stub_main() threads, all on a new thread of its own, and returns at once. Nothing waits for ctor() here, since the host is already running.
Logging
The stub truncates /tmp/xur-stub.log when it loads, then appends a line for each step (scripts found and compiled, compile errors, each script started, errors from ctor() and stub_main()). Each line also goes to standard error with a [xur-stub] prefix. Rust panics inside the stub are logged with their location and a backtrace.
On Unix the stub also installs a crash handler for SIGSEGV, SIGBUS and SIGABRT: it logs the signal, the faulting address, the instruction pointer and the main registers, and the module and offset the instruction pointer is in, then re-raises the signal so the process dies as it would have.
Scripts can log to their own file with std::log (see xur.std.log(7)).
Modules
On top of xur.std(7), the stub registers these modules (each behind a cargo feature of xur-stub, all on by default):
std::stub::hookingInline function hooks by address or symbol; see
xur.std.stub.hooking(7).std::stub::il2cppUnity Il2Cpp classes, fields, methods and hooks; see
xur.std.stub.il2cpp(7).std::stub::unity::eguiAn egui overlay drawn by a Unity game; see
xur.std.stub.unity.egui(7).std::stub::re::unity::timeUnity's time scale and frame timing; see
xur.std.stub.re.unity.time(7).std::stub::coreclrCalling, reading and hooking a CoreCLR (.NET) runtime; see
xur.std.stub.coreclr(7).std::stub::godotAttach to a Godot .NET game, run code on its main thread, walk its scene tree; see
xur.std.stub.godot(7).std::stub::overlay::eguiAn egui overlay for any OpenGL or Vulkan game; see
xur.std.stub.overlay.egui(7).std::stub::unrealUnreal Engine 4/5 object and class introspection; see
xur.std.stub.unreal(7).std::stub::re::unity,std::stub::re::il2cpp_runtime,std::stub::re::godotData types of the engine libraries the modules above are built on.
Environment
XUR_STUB_PATHThe script file or directory to run when the stub loads.
LD_PRELOADHow to load the stub into a program at launch on Linux.
Files
/tmp/xur-stub.logThe stub's log.
- <host exe dir>
/xur/ Where scripts are looked for when
XUR_STUB_PATHisn't set.
Examples
A script that hooks early and then runs alongside the host:
use std::log;
use std::xur;
fn ctor() {
// Runs before the host's main; keep it short.
log::info("loaded by {}", xur::invoked_by());
}
fn stub_main() {
// Runs on its own thread for as long as it likes.
}
fn main() {
// Only used by `xur run`.
}Run it at launch, or inject it into a running process:
XUR_STUB_PATH=mod.xur LD_PRELOAD=target/release/libxur_stub.so ./game
xur stub inject --name game mod.xurSee also
xur(1), xur.std(7), xur.std.stub.coreclr(7), xur.std.stub.godot(7), xur.std.stub.hooking(7), xur.std.stub.il2cpp(7), xur.std.stub.overlay.egui(7), xur.std.stub.re.unity.time(7), xur.std.stub.unity.egui(7), xur.std.stub.unreal(7)
> examples
From xur-stub/example in xur's repository.
› hello.xur A simple stub script: runs when the stub is loaded into a process
// A simple stub script: runs when the stub is loaded into a process.
//
// Test with:
// XUR_STUB_PATH=xur-stub/example/hello.xur LD_PRELOAD=target/debug/libxur_stub.so /bin/true
use std::io;
use std::re::proc;
fn main() -> Result<()> {
let pid = proc::current_pid();
io::println("[hello.xur] running inside pid {}", pid);
Ok(())
}› egui_overlay.xur An egui overlay like hao's egui_demo, but written entirely in Xur
// An egui overlay like hao's egui_demo, but written entirely in Xur.
//
// The script creates its own windows, handles F1 toggling, and shows
// process info alongside time-scale controls.
//
// cargo build --release -p xur-stub --features egui
// XUR_STUB_PATH=xur-stub/example/egui_overlay.xur \
// LD_PRELOAD=target/release/libxur_stub.so %command%
use std::fmt;
use std::xur;
use std::log;
use std::stub::unity::egui;
use std::stub::re::unity::time;
fn ctor() {
log::subscriber().to_file("/tmp/egui_overlay.log").with_max_level(log::Level::Debug).init();
egui::init();
}
fn stub_main() {
let visible = true;
let f1_down = false;
egui::run(|ctx| {
let f1 = ctx.key("f1");
if f1 && !f1_down {
visible = !visible;
}
f1_down = f1;
if !visible {
return;
}
ctx.window("hao + egui (xur)", |ui| {
ui.label(fmt::format("invoked by: {}", xur::invoked_by()));
ui.label(fmt::format("frames rendered: {}", egui::frame_count()));
ui.separator();
let scale = time::scale();
ui.label(fmt::format("Time.timeScale (from game): {}", scale));
scale = ui.slider_float("", scale, 0.0, 3.0);
time::set_scale(scale);
ui.horizontal(|row| {
if row.button("pause (0x)") {
time::set_scale(0.0);
}
if row.button("normal (1x)") {
time::set_scale(1.0);
}
if row.button("fast (2x)") {
time::set_scale(2.0);
}
});
});
});
}› game_inspector.xur A game inspector mod, loaded into a Unity Il2Cpp game via LD_PRELOAD
// A game inspector mod, loaded into a Unity Il2Cpp game via LD_PRELOAD.
//
// Like hao's egui_demo, this runs inside the game process. It finds the
// game's Il2Cpp metadata, dumps the type tree, and reads memory at the
// GameAssembly's base address.
//
// Build the stub, then launch a Unity game with it:
//
// cargo build --release -p xur-stub
// # Steam > game > Properties > Launch options:
// XUR_STUB_PATH=xur-stub/example LD_PRELOAD=target/release/libxur_stub.so %command%
//
// Or test without a real game (shows process info only):
//
// XUR_STUB_PATH=xur-stub/example/game_inspector.xur \
// LD_PRELOAD=target/debug/libxur_stub.so /bin/true
use std::io;
use std::fs;
use std::re::proc;
use std::re::dotnet::il2cpp;
fn main() -> Result<()> {
let pid = proc::current_pid();
io::println("[game_inspector] pid {}", pid);
// Open our own process to list loaded modules.
let handle = proc::open_current()?;
let modules = handle.modules()?;
io::println("[game_inspector] {} modules loaded", modules.len());
// Find the GameAssembly module — the sign we're inside a Unity Il2Cpp game.
let game_assembly_base = 0;
let game_assembly_size = 0;
let game_assembly_path = "";
let found = false;
for m in modules {
if m.name.starts_with("GameAssembly") {
game_assembly_base = m.base;
game_assembly_size = m.size;
game_assembly_path = m.path;
found = true;
}
}
if !found {
io::println("[game_inspector] no GameAssembly found — not a Unity Il2Cpp game");
io::println("[game_inspector] loaded modules:");
for m in modules {
io::println(" {} at 0x{} ({} bytes)", m.name, m.base.to_hex(), m.size);
}
return Ok(());
}
io::println("[game_inspector] GameAssembly at 0x{} ({} bytes)",
game_assembly_base.to_hex(), game_assembly_size);
// Read the first 16 bytes of the GameAssembly (the ELF/PE header).
let header = handle.read(game_assembly_base, 16)?;
io::println("[game_inspector] header: {}", header.to_hex());
// The game directory is the parent of the GameAssembly path.
let parts = game_assembly_path.split("/");
let dir_parts = [];
let i = 0;
for part in parts {
if i < parts.len() - 1 {
dir_parts.push(part);
}
i = i + 1;
}
let game_dir = dir_parts.join("/");
io::println("[game_inspector] game directory: {}", game_dir);
let game = il2cpp::open(game_dir)?;
let images = game.image_names();
io::println("[game_inspector] {} assemblies:", images.len());
for name in images {
io::println(" {}", name);
}
// Dump type summary.
let types = game.types();
io::println("[game_inspector] {} types total", types.len());
io::println("");
// Show the first 50 types with their fields and methods.
let limit = if types.len() < 50 { types.len() } else { 50 };
let shown = 0;
for ty in types {
if shown >= limit { break; }
io::println("{}", ty.full_name());
for field in ty.fields() {
io::println(" {} {}{}", field.type_name(), field.name(),
if field.is_static() { " (static)" } else { "" });
}
for method in ty.methods() {
io::println(" {}({}){}", method.name(),
method.parameter_type_names().join(", "),
if method.is_static() { " static" } else { "" });
}
shown = shown + 1;
}
if types.len() > limit {
io::println("... and {} more types", types.len() - limit);
}
// Generate proxy assemblies.
let paths = game.write_assemblies("/tmp/xur-game-proxies")?;
io::println("[game_inspector] wrote {} proxy assemblies to /tmp/xur-game-proxies/",
paths.len());
Ok(())
}› godot_scene.xur Godot scene tree viewer — LD_PRELOAD overlay that shows the game's
// Godot scene tree viewer — LD_PRELOAD overlay that shows the game's
// live node hierarchy in an egui window.
//
// Hooks SceneTree._Process from GodotSharp for the per-frame pump —
// works for any Godot game, no game-specific types needed.
//
// cargo build --release -p xur-stub
// # Steam > Game > Properties > Launch options:
// XUR_STUB_PATH=xur-stub/example/godot_scene.xur \
// LD_PRELOAD=target/release/libxur_stub.so %command%
use std::cell;
use std::fmt;
use std::gui;
use std::log;
use std::stub::coreclr;
use std::stub::godot;
use std::stub::overlay::egui;
// ---------------------------------------------------------------------------
// Scene tree snapshot — captured on the game thread, drawn on the render thread
// ---------------------------------------------------------------------------
pub struct TreeNode {
name: str
child_count: i32
children: [TreeNode]
}
fn capture_node(node: coreclr::ManagedObject, depth: i32) -> TreeNode {
let name = godot::node_name(node).unwrap_or("?");
let count = godot::child_count(node).unwrap_or(0);
let children = [];
if depth < 6 {
let i = 0;
while i < count {
match godot::child(node, i) {
Ok(child) => children.push(capture_node(child, depth + 1)),
Err(_) => {}
}
i = i + 1;
}
}
TreeNode { name: name, child_count: count, children: children }
}
fn draw_node(ui: gui::Ui, node: TreeNode, depth: i32) {
let indent = "";
let d = 0;
while d < depth {
indent = indent + " ";
d = d + 1;
}
let label = if node.child_count > 0 {
fmt::format("{}▸ {} ({})", indent, node.name, node.child_count)
} else {
fmt::format("{} {}", indent, node.name)
};
ui.small(label);
for child in node.children {
draw_node(ui, child, depth + 1);
}
}
// ---------------------------------------------------------------------------
// Entry points
// ---------------------------------------------------------------------------
fn ctor() {
log::subscriber().to_file("/tmp/godot-scene.log").truncate().with_max_level(log::Level::Info).init();
egui::init();
egui::set_scale(0.75);
godot::hook_scene_tree();
}
fn stub_main() {
log::info("Scene tree viewer starting — waiting for CoreCLR...");
let rt = match godot::init(9) {
Ok(r) => r,
Err(e) => {
log::info(fmt::format("CLR init failed: {}", e));
return;
}
};
log::info("starting overlay");
let snapshot: Option<TreeNode> = None;
let frame_count = cell::new(0);
// Capture scene tree on the game thread every 60 frames.
// The bindings resolve lazily on first call (OnceLock) — this is
// safe because on_process runs on the game thread where the CLR lives.
godot::on_process(|| {
let fc = frame_count.get() + 1;
frame_count.set(fc);
if snapshot.is_none() || fc % 60 == 0 {
match godot::root() {
Ok(root) => snapshot = Some(capture_node(root, 0)),
Err(e) => {
if fc % 300 == 0 {
log::info(fmt::format("root() failed: {}", e));
}
}
}
}
});
let visible = true;
let f1_down = false;
// Draw the last captured snapshot on the render thread.
egui::run(|ctx| {
let f1 = ctx.key("f1");
if f1 && !f1_down {
visible = !visible;
}
f1_down = f1;
if !visible { return; }
ctx.window_sized("Scene Tree", 450.0, |win| {
match snapshot {
Some(tree) => {
draw_node(win, tree, 0);
}
None => {
win.small("waiting for scene tree...");
}
}
});
});
}› godot.xur Godot (.NET / CoreCLR) game inspector
// Godot (.NET / CoreCLR) game inspector.
//
// Lists loaded modules, attaches to the Godot runtime, and prints
// types from the game's managed assemblies. Derived from hao-godot's
// call and godot_types examples.
//
// cargo build --release -p xur-stub --features godot
// # Steam > game > Properties > Launch options:
// XUR_STUB_PATH=xur-stub/example/godot.xur \
// LD_PRELOAD=target/release/libxur_stub.so %command%
use std::io;
use std::fmt;
use std::re::proc;
use std::stub::re::godot;
use std::log;
fn ctor() {
log::subscriber().with_max_level(log::Level::Info).init();
}
fn main() -> Result<()> {
let pid = proc::current_pid();
io::println("[godot] running inside pid {}", pid);
let handle = proc::open_current()?;
let modules = handle.modules()?;
io::println("[godot] {} modules loaded", modules.len());
for m in modules {
if m.name.contains("coreclr") || m.name.contains("Godot") || m.name.contains("hostfxr") {
io::println(" {} at 0x{} ({} bytes)", m.name, m.base.to_hex(), m.size);
}
}
// std::stub::re::godot exposes the hao-godot reflection roots.
// In a real game, the runtime types would be available here after
// CoreCLR has initialized.
io::println("[godot] godot reflection module loaded");
Ok(())
}› hooking.xur Inline function hooking with hooking-rs
// Inline function hooking with hooking-rs.
//
// Demonstrates the hooking API. In a real mod, `destination` would be
// the address of your detour function (e.g. from an Il2Cpp method
// pointer). This example shows the module's API shape; running it
// requires a target process with symbols to hook.
//
// cargo build -p xur-stub
// XUR_STUB_PATH=xur-stub/example/hooking.xur \
// LD_PRELOAD=target/debug/libxur_stub.so ./some_target
use std::io;
use std::stub::hooking;
fn main() -> Result<()> {
io::println("[hooking] stub::hooking API:");
io::println(" hooking::create(target_addr, dest_addr) — hook by address");
io::println(" hooking::by_name(symbol, dest) — hook by symbol");
io::println(" hooking::by_name(module, symbol, dest) — hook in a specific module");
io::println(" hook.apply()? — install the detour");
io::println(" hook.remove()? — restore original code");
io::println(" hook.original()? — address of the relocated original");
io::println(" hook.target()? — address of the hooked function");
// The hook ops return a Result, so thread them with `?`.
// Example (requires real addresses):
//
// let hook = hooking::by_name("puts", my_detour_addr)?;
// hook.apply()?;
// // ... puts() now redirects to my_detour_addr
// let original = hook.original()?; // call this to reach the real puts
// hook.remove()?;
Ok(())
}› il2cpp_hooks.xur Il2Cpp method hooking patterns — intercept any method, inspect args,
// Il2Cpp method hooking patterns — intercept any method, inspect args,
// modify args, call the original, and override return values.
//
// Requires a Unity Il2Cpp game. For a full working example see
// megabonk/ which hooks DamagePlayer for godmode.
//
// cargo build --release -p xur-stub --features egui
// XUR_STUB_PATH=xur-stub/example/il2cpp_hooks.xur \
// LD_PRELOAD=target/release/libxur_stub.so ./some_game
use std::cell;
use std::stub::hooking;
use std::stub::il2cpp;
use std::log;
fn main() -> Result<()> {
let rt = il2cpp::loaded()?;
let asm = "Assembly-CSharp";
// --- Pattern 1: Block a method (godmode) --------------------------
//
// Return Some(value) to skip the original; None to let it run.
// For void methods, use hooking::Skip() to skip.
let health_cls = rt.class(asm, "Game", "PlayerHealth")?;
let damage = health_cls.method("DamagePlayer", 3)?;
let godmode = cell::new(false);
damage.hook(|ctx| {
if godmode.get() { Some(hooking::Skip()) } else { None }
});
// Toggle from UI:
// godmode.set(!godmode.get());
// --- Pattern 2: Log arguments -------------------------------------
//
// ctx.arg(index) or ctx.arg("name") reads a parameter.
// ctx.args() returns all of them as a list.
// Return None to pass through without changes.
let player_cls = rt.class(asm, "Game", "Player")?;
let take_hit = player_cls.method("TakeHit", 2)?;
take_hit.hook(|ctx| {
log::info("TakeHit: {} damage from {}",
ctx.arg("amount"), ctx.arg("source"));
None
});
// --- Pattern 3: Modify arguments ----------------------------------
//
// ctx.set_arg changes an argument before passing through.
// The modified value is written back to the CPU registers.
let set_speed = player_cls.method("SetSpeed", 1)?;
set_speed.hook(|ctx| {
let speed = ctx.arg("speed");
ctx.set_arg("speed", speed * 2.0);
None
});
// --- Pattern 4: Call original and modify the return ----------------
//
// ctx.call() invokes the original method with (possibly modified)
// args, returns its result. Then return Some(modified) to override.
let get_gold = rt.class(asm, "Game", "Inventory")?
.method("GetGold", 0)?;
get_gold.hook(|ctx| {
let real_gold = ctx.call();
Some(real_gold * 2)
});
// --- Pattern 5: Conditional override ------------------------------
//
// Call the original, inspect the result, decide whether to change it.
let loot_roll = rt.class(asm, "Game", "LootTable")?
.method("Roll", 1)?;
let always_legendary = cell::new(false);
loot_roll.hook(|ctx| {
let result = ctx.call();
if always_legendary.get() {
Some(5) // legendary tier
} else {
Some(result) // unchanged
}
});
log::info("hooks installed");
Ok(())
}› megabonk_disasm.xur Megabonk static disassembly — reads the game binary offline
// Megabonk static disassembly — reads the game binary offline.
//
// xur run xur-stub/example/megabonk_disasm.xur
use std::io;
use std::re::dotnet::il2cpp;
use std::re::elf;
use std::re::asm::x86;
fn disasm(binary: elf::ElfFile, method: il2cpp::MethodView, max_insns: i32) {
let addr = match method.code_address() {
Some(a) => a,
None => {
io::println("--- {} --- (no code address)", method);
return;
}
};
io::println("--- {} @ 0x{} ---", method, addr.to_hex());
let data = match binary.read(addr, 512) {
Some(b) => b,
None => {
io::println(" (could not read at 0x{})", addr.to_hex());
return;
}
};
let insns = x86::decode(64, data, addr);
let count = 0;
for insn in insns {
io::println(" 0x{}: {}", insn.ip().to_hex(), insn);
count = count + 1;
if count >= max_insns { break; }
let fc = insn.flow_control();
if fc == "Return" { break; }
}
io::println("");
}
fn disasm_methods(game: il2cpp::Game, binary: elf::ElfFile, type_name: str, methods: [str], params: [i32], max: i32) {
match game.find_type(type_name) {
Ok(ty) => {
for i in 0..methods.len() {
let name = methods[i];
let pc = params[i];
let found = false;
for m in ty.methods() {
if m.name() == name && m.parameter_type_names().len() == pc {
disasm(binary, m, max);
found = true;
break;
}
}
if !found {
io::println("--- {}.{}({}) NOT FOUND ---", type_name, name, pc);
io::println("");
}
}
}
Err(e) => io::println("type not found: {}", type_name)
}
}
fn main() {
let game_dir = "/games/SteamLibrary/steamapps/common/Megabonk";
let so_path = game_dir + "/GameAssembly.so";
let game = match il2cpp::open(game_dir) {
Ok(g) => g,
Err(e) => { io::println("failed to open: {}", e); return; }
};
let binary = match elf::ElfFile::open(so_path) {
Ok(b) => b,
Err(e) => { io::println("failed to open ELF: {}", e); return; }
};
io::println("=== PlayerCamera ===");
disasm_methods(game, binary, "PlayerCamera",
["UpdateZoom", "SetZoom", "PlayerCam", "Update", "AdjustCameraFar"],
[0, 1, 1, 0, 0], 60);
io::println("=== GameManager ===");
disasm_methods(game, binary, "GameManager",
["Update", "GetStageTimeMax", "GetAliveTime"],
[0, 0, 0], 80);
io::println("=== GameTimer ===");
disasm_methods(game, binary, "GameTimer",
["UpdateTimers", "GetForcedTime"],
[0, 0], 60);
io::println("=== PlayerMovement ===");
disasm_methods(game, binary, "PlayerMovement",
["PushPlayer", "BouncePlayer", "PushPlayerButKeepMovement", "NoclipMovement"],
[1, 1, 0, 0], 40);
io::println("=== DONE ===");
}› megabonk_discover.xur Megabonk class discovery — reads the game's Il2Cpp metadata offline
// Megabonk class discovery — reads the game's Il2Cpp metadata offline
// to find class names, fields, and methods.
//
// No game launch needed — parses GameAssembly and global-metadata.dat
// directly from disk.
//
// xur run xur-stub/example/megabonk_discover.xur
use std::fmt;
use std::io;
use std::re::dotnet::il2cpp;
fn dump(game: il2cpp::Game, full_name: str) {
match game.find_type(full_name) {
Ok(ty) => {
io::println(fmt::format("=== {} (ns: {}, image: {}) ===",
ty.full_name(), ty.namespace(), ty.image_name()));
let base = ty.base_type_name();
match base {
Some(b) => io::println(fmt::format(" base: {}", b)),
None => {}
}
io::println(" fields:");
for f in ty.fields() {
let tag = if f.is_static() { " (static)" } else { "" };
io::println(fmt::format(" {}: {}{}", f.name(), f.type_name(), tag));
}
io::println(" methods:");
for m in ty.methods() {
let tag = if m.is_static() { " (static)" } else { "" };
io::println(fmt::format(" {} {}({}){}", m.return_type(), m.name(),
m.parameter_type_names().join(", "), tag));
}
io::println("");
}
Err(e) => {
io::println(fmt::format("NOT FOUND: {}", full_name));
}
}
}
fn main() {
let game = match il2cpp::open("/games/SteamLibrary/steamapps/common/Megabonk") {
Ok(g) => g,
Err(e) => {
io::println(e);
return;
}
};
io::println("=== Assembly-CSharp classes ===");
io::println("");
// Dump every game class (skip Unity/System/.NET framework types).
for ty in game.types() {
if ty.image_name() != "Assembly-CSharp.dll" { continue; }
let name = ty.full_name();
// Skip compiler-generated types.
if name.contains("<>") { continue; }
if name.contains("<Module>") { continue; }
io::println(fmt::format("{} (ns: {})", name, ty.namespace()));
}
io::println("");
io::println("=== Key classes detail ===");
io::println("");
dump(game, "Assets.Scripts.Actors.Player.MyPlayer");
dump(game, "Assets.Scripts.Inventory__Items__Pickups.PlayerHealth");
dump(game, "PlayerInventory");
dump(game, "Assets.Scripts.Inventory__Items__Pickups.Items.ItemInventory");
dump(game, "Assets.Scripts.Inventory__Items__Pickups.Weapons.WeaponInventory");
dump(game, "DataManager");
dump(game, "EWeapon");
dump(game, "Assets.Scripts.Inventory__Items__Pickups.Items.EItem");
dump(game, "ECharacter");
dump(game, "Assets.Scripts._Data.Tomes.ETome");
dump(game, "TomeData");
dump(game, "WeaponData");
dump(game, "ItemData");
dump(game, "Assets.Scripts.Inventory__Items__Pickups.TomeInventory");
}› sts2_discover.xur Slay the Spire 2 class discovery — reads sts2.dll offline to find
// Slay the Spire 2 class discovery — reads sts2.dll offline to find
// game classes, fields, and methods for building a trainer.
//
// xur run xur-stub/example/sts2_discover.xur
use std::fmt;
use std::io;
use std::re::dotnet;
fn dump_type(module: dotnet::Module, full_name: str) {
let ty = module.find_type_by_full_name(full_name);
if ty == () {
io::println(fmt::format("NOT FOUND: {}", full_name));
return;
}
io::println(fmt::format("=== {} ===", ty.full_name()));
let base = ty.base_type();
if base != () {
io::println(fmt::format(" base: {}", base));
}
io::println(" fields:");
for f in ty.fields() {
let tag = if f.is_static() { " (static)" } else { "" };
io::println(" " + f.name() + tag);
}
io::println(" methods:");
for m in ty.methods() {
let tag = if m.is_static() { " (static)" } else { "" };
let pub_tag = if m.is_public() { "pub " } else { "" };
io::println(" " + pub_tag + m.name() + tag);
}
io::println("");
}
fn main() -> Result<()> {
let path = "/games/SteamLibrary/steamapps/common/Slay the Spire 2/data_sts2_linuxbsd_x86_64/sts2.dll";
let data = std::fs::read(path)?;
let module = dotnet::parse(data)?;
io::println(fmt::format("Loaded {} ({} types)", module.name(), module.all_types().len()));
io::println("");
let targets = [
"MegaCrit.Sts2.Core.Runs.RunManager",
"MegaCrit.Sts2.Core.Runs.RunState",
"MegaCrit.Sts2.Core.Combat.CombatRoom",
];
for name in targets {
dump_type(module, name);
}
Ok(())
}› tracing.xur Structured logging with std::log
// Structured logging with std::log.
//
// Sets up a subscriber with file output, then emits log messages at
// various levels.
//
// cargo build -p xur-stub
// XUR_STUB_PATH=xur-stub/example/tracing.xur \
// LD_PRELOAD=target/debug/libxur_stub.so /bin/true
use std::io;
use std::log;
fn ctor() {
log::subscriber().with_max_level(log::Level::Debug).init();
}
fn main() -> Result<()> {
log::info("application started");
log::debug("debug details: x={}", 42);
log::warn("something to watch");
log::error("this would be an error");
io::println("[tracing] log messages emitted — check stderr or log file");
// To log to a file instead:
// log::subscriber().to_file("/tmp/game.log").with_max_level(log::Level::Debug).init();
//
// Other subscriber options:
// .with_target(false) — hide module path
// .with_ansi(false) — no ANSI colors
// .json() — JSON output format
// .compact() — compact format
// .pretty() — pretty-printed format
// .with_filter("my_mod=debug") — per-module filtering
Ok(())
}