#![no_main] use std::thread; use winapi::shared::minwindef::{BOOL, HINSTANCE, LPVOID, TRUE}; use winapi::um::libloaderapi::DisableThreadLibraryCalls; use winapi::um::winnt::DLL_PROCESS_ATTACH; use mono_lib::Mono; use mono_lib::{c_str, make_fn, mem::CStr}; fn main_thread() { let mono = Mono::new(); let domain = mono.get_domain(); println!("Mono Domain = {:?}", domain); mono.attach_thread(); println!("Mono Thread Attached"); let game_object = mono.get_class( c_str!("UnityEngine.CoreModule"), c_str!("UnityEngine"), c_str!("GameObject"), ); println!("GameObject Class = {:?}", game_object); let find_game_object_ptr = mono.compile_method(mono.get_method(game_object, c_str!("Find"), 1)); println!("GameObject.Find() = {:?}", find_game_object_ptr); let find_game_object = make_fn!(find_game_object_ptr, *const usize, *const usize); let game_world = find_game_object(mono.new_string(c_str!("GameWorld"))); println!("GameWorld = {:?}", game_world); } #[no_mangle] #[allow(non_snake_case)] extern "system" fn DllMain(h_module: HINSTANCE, dw_reason: u32, _: LPVOID) -> BOOL { if dw_reason == DLL_PROCESS_ATTACH { unsafe { DisableThreadLibraryCalls(h_module); } thread::spawn(|| { main_thread(); }); } TRUE }