Files
OpenPrestige/injector/crates/loader/src/lib.rs
T
aidanandClaude Opus 5.5 05d169a2dd Sync local working tree: injector, engine, mixin and build updates
Add compatibility notes, resource-provider and hook checks, and payload
bundling script. Remove generated engine mixin stubs, engine target lists
and prebuilt binaries now produced by the build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-10 17:27:24 -06:00

66 lines
2.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! prestige_native.dll: loads the exact Minecraft 1.21.1–1.21.11 Fabric payload for the running JVM.
//!
//! The DLL worker waits for the JVM, appends the embedded Prestige payload jar to Fabric's Knot class loader, registers the
//! JVMTI-backed natives of `dev.zprestige.prestige.inject.NativeBridge` and starts `Bootstrap`, which transforms the already
//! loaded game classes and initialises the client.
mod bridge;
mod jni;
mod log;
#[path = "../../paths.rs"]
mod paths;
mod worker;
use std::ffi::c_void;
#[cfg(windows)]
const DLL_PROCESS_ATTACH: u32 = 1;
#[cfg(windows)]
extern "system" {
fn DisableThreadLibraryCalls(module: *mut c_void) -> i32;
}
#[cfg(windows)]
pub(crate) static mut MODULE: *mut c_void = std::ptr::null_mut();
#[cfg(windows)]
#[no_mangle]
pub extern "system" fn DllMain(module: *mut c_void, reason: u32, _reserved: *mut c_void) -> i32 {
if reason == DLL_PROCESS_ATTACH {
unsafe {
MODULE = module;
DisableThreadLibraryCalls(module);
}
// Nothing but thread creation may happen under the loader lock.
let _ = std::thread::Builder::new().name("prestige-loader".into()).spawn(worker::run);
}
1
}
/// The JavaVM handed to Agent_OnAttach / Agent_OnLoad by the JVM (unix); read by the worker.
#[cfg(unix)]
pub(crate) static VM: std::sync::atomic::AtomicPtr<c_void> = std::sync::atomic::AtomicPtr::new(std::ptr::null_mut());
#[cfg(unix)]
fn start_worker(vm: *mut c_void) -> i32 {
VM.store(vm, std::sync::atomic::Ordering::SeqCst);
match std::thread::Builder::new().name("prestige-loader".into()).spawn(worker::run) {
Ok(_) => 0,
Err(_) => -1,
}
}
/// Called by HotSpot when the library is loaded through the attach protocol (JVMTI.agent_load).
#[cfg(unix)]
#[no_mangle]
pub extern "C" fn Agent_OnAttach(vm: *mut c_void, _options: *mut std::ffi::c_char, _reserved: *mut c_void) -> i32 {
start_worker(vm)
}
/// Called by the JVM when the library is given as -agentpath at start-up.
#[cfg(unix)]
#[no_mangle]
pub extern "C" fn Agent_OnLoad(vm: *mut c_void, _options: *mut std::ffi::c_char, _reserved: *mut c_void) -> i32 {
start_worker(vm)
}