forked from BynBang/OpenPrestige
UPDATE
Add Linux and macOS support, batch class transformations with a disk cache, and add cross-platform release packaging. Also improve runtime namespace handling, keybind editing, and startup behavior.
This commit is contained in:
1 parent
910a126f04
commit
38ff6d387c
29 files changed
+2234
-491
No files matched your search
@@ -1,21 +1,55 @@
|
||||
use std::ffi::c_void;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::OnceLock;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
#[cfg(windows)]
|
||||
extern "system" {
|
||||
fn GetModuleFileNameW(module: *mut c_void, buf: *mut u16, size: u32) -> u32;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[repr(C)]
|
||||
struct DlInfo {
|
||||
dli_fname: *const std::ffi::c_char,
|
||||
dli_fbase: *mut c_void,
|
||||
dli_sname: *const std::ffi::c_char,
|
||||
dli_saddr: *mut c_void,
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
extern "C" {
|
||||
fn dladdr(addr: *const c_void, info: *mut DlInfo) -> i32;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn module_path() -> PathBuf {
|
||||
fn anchor() {}
|
||||
let mut info = DlInfo { dli_fname: std::ptr::null(), dli_fbase: std::ptr::null_mut(), dli_sname: std::ptr::null(), dli_saddr: std::ptr::null_mut() };
|
||||
let ok = unsafe { dladdr(anchor as fn() as usize as *const c_void, &mut info) };
|
||||
if ok != 0 && !info.dli_fname.is_null() {
|
||||
let name = unsafe { std::ffi::CStr::from_ptr(info.dli_fname) };
|
||||
PathBuf::from(std::ffi::OsStr::from_bytes(name.to_bytes()))
|
||||
} else {
|
||||
std::env::temp_dir().join("libprestige_native")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn module_path() -> PathBuf {
|
||||
let mut buf = [0u16; 1024];
|
||||
let len = unsafe { GetModuleFileNameW(crate::MODULE, buf.as_mut_ptr(), buf.len() as u32) } as usize;
|
||||
PathBuf::from(String::from_utf16_lossy(&buf[..len]))
|
||||
}
|
||||
|
||||
fn log_path() -> &'static PathBuf {
|
||||
static PATH: OnceLock<PathBuf> = OnceLock::new();
|
||||
PATH.get_or_init(|| {
|
||||
let mut buf = [0u16; 1024];
|
||||
let len = unsafe { GetModuleFileNameW(crate::MODULE, buf.as_mut_ptr(), buf.len() as u32) } as usize;
|
||||
let dll = PathBuf::from(String::from_utf16_lossy(&buf[..len]));
|
||||
dll.with_file_name("prestige-native.log")
|
||||
module_path().with_file_name("prestige-native.log")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user