unreal-sdk/sdk-serializer/src/lib.rs
2023-06-21 18:57:07 +02:00

60 lines
2 KiB
Rust

use pdb_helper as pdb;
use simple_logger::SimpleLogger;
use std::time::Duration;
use windows::s;
#[no_mangle]
pub extern "win64" fn DllMain(_module: usize, reason: u32, _: usize) -> bool {
match reason {
1 => {
if std::env::current_exe()
.expect("current exe")
.file_name()
.expect("file name")
.to_string_lossy()
== "ShooterGame.exe"
{
SimpleLogger::new().init().unwrap();
log::info!("hello");
std::thread::spawn(move || {
let _wnd = loop {
let window = unsafe {
windows::Win32::UI::WindowsAndMessaging::FindWindowA(
None,
s!("ARK: Survival Evolved"),
)
};
if window.0 != 0 {
log::debug!("found window: {window:?}");
break window;
}
log::trace!("window was 0");
std::thread::sleep(std::time::Duration::from_millis(150));
};
let globals = pdb::get_pdb().find_ue_globals().expect("globals");
unreal_sdk::global_tables::names::GNAMES
.write()
.unwrap()
.set_names(globals.names.cast());
unreal_sdk::global_tables::objects::GOBJECTS
.write()
.unwrap()
.set_objects(globals.objects.cast());
std::thread::sleep(Duration::from_secs(30));
let sdk = unreal_sdk::sdk::repr::Sdk::build().expect("sdk");
sdk.save_to_path("z:/tmp/sdk.ron").expect("writing sdk");
log::info!("done.");
});
}
}
_ => {}
}
true
}