From 48d15c78ce5335ba22a5354f0d68615536fc98ed Mon Sep 17 00:00:00 2001 From: Ethan Green Date: Tue, 2 Jul 2024 23:21:29 -0400 Subject: [PATCH] fix: build failure caused by isize, itertools deps --- Cargo.lock | 1 + crates/lovely-core/src/lib.rs | 22 +++++++++++----------- crates/lovely-win/Cargo.toml | 1 + crates/lovely-win/src/lib.rs | 9 +++++---- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d6fba9a..3da54de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -415,6 +415,7 @@ name = "lovely-win" version = "0.1.0" dependencies = [ "forward-dll", + "itertools", "libc", "lovely-core", "once_cell", diff --git a/crates/lovely-core/src/lib.rs b/crates/lovely-core/src/lib.rs index f2b68ea..63c041f 100644 --- a/crates/lovely-core/src/lib.rs +++ b/crates/lovely-core/src/lib.rs @@ -65,14 +65,14 @@ impl Lovely { .join("Mods"); let log_dir = mod_dir.join("lovely").join("log"); - + log::init(&log_dir).unwrap_or_else(|e| panic!("Failed to initialize logger: {e:?}")); - + let version = env!("CARGO_PKG_VERSION"); info!("Lovely {version}"); let mut is_vanilla = false; - + while let Some(opt) = opts.next_arg().expect("Failed to parse argument.") { match opt { Arg::Long("mod-dir") => mod_dir = opts.value().map(PathBuf::from).unwrap_or(mod_dir), @@ -97,7 +97,7 @@ impl Lovely { // Validate that an older Lovely install doesn't already exist within the game directory. let exe_path = env::current_exe().unwrap(); let game_dir = exe_path.parent().unwrap(); - let dwmapi = game_dir.join("dwmapi.dll"); + let dwmapi = game_dir.join("dwmapi.dll"); if dwmapi.is_file() { panic!( @@ -108,12 +108,12 @@ impl Lovely { info!("Game directory is at {game_dir:?}"); info!("Writing logs to {log_dir:?}"); - + if !mod_dir.is_dir() { info!("Creating mods directory at {mod_dir:?}"); fs::create_dir_all(&mod_dir).unwrap(); } - + info!("Using mod directory at {mod_dir:?}"); let patch_table = PatchTable::load(&mod_dir) .with_loadbuffer(loadbuffer); @@ -124,7 +124,7 @@ impl Lovely { fs::remove_dir_all(&dump_dir) .unwrap_or_else(|e| panic!("Failed to recursively delete dumps directory at {dump_dir:?}: {e:?}")); } - + info!("Initialization complete in {}ms", start.elapsed().as_millis()); Lovely { @@ -137,7 +137,7 @@ impl Lovely { } /// Apply patches onto the raw buffer. - /// + /// /// # Safety /// This function is unsafe because /// - It interacts and manipulates memory directly through native pointers @@ -162,7 +162,7 @@ impl Lovely { } // Prepare buffer for patching (Check and remove the last byte if it is a null terminator) - let last_byte = *buf_ptr.add(size - 1); + let last_byte = *buf_ptr.add((size - 1) as usize); let actual_size = if last_byte == 0 { size - 1 } else { size }; // Convert the buffer from cstr ptr, to byte slice, to utf8 str. @@ -263,7 +263,7 @@ impl PatchTable { // Load n > 0 patch files from the patch directory, collecting them for later processing. for patch_file in patch_files { let patch_dir = patch_file.parent().unwrap(); - + // Determine the mod directory from the location of the lovely patch file. let mod_dir = if patch_dir.file_name().unwrap() == "lovely" { patch_dir.parent().unwrap() @@ -452,7 +452,7 @@ impl PatchTable { } else { info!("Applied {patch_count} patches to '{target}'"); } - + // Compute the integrity hash of the patched file. let mut hasher = Sha256::new(); hasher.update(patched.as_bytes()); diff --git a/crates/lovely-win/Cargo.toml b/crates/lovely-win/Cargo.toml index abb8bd9..1dbe8b3 100644 --- a/crates/lovely-win/Cargo.toml +++ b/crates/lovely-win/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] [dependencies] lovely-core = { version ="0.5.0-beta7", path = "../lovely-core" } +itertools = "0.13.0" libc = "0.2.141" once_cell = "1.19.0" widestring = "1.0.2" diff --git a/crates/lovely-win/src/lib.rs b/crates/lovely-win/src/lib.rs index ccc65b0..1e92e9b 100644 --- a/crates/lovely-win/src/lib.rs +++ b/crates/lovely-win/src/lib.rs @@ -6,6 +6,7 @@ use lovely_core::log::*; use lovely_core::Lovely; use lovely_core::sys::LuaState; +use itertools::Itertools; use once_cell::sync::OnceCell; use retour::static_detour; use widestring::U16CString; @@ -32,7 +33,7 @@ unsafe extern "system" fn DllMain(_: HINSTANCE, reason: u32, _: *const c_void) - if reason != 1 { return 1; } - + panic::set_hook(Box::new(|x| unsafe { let message = format!("lovely-injector has crashed: \n{x}"); error!("{message}"); @@ -47,21 +48,21 @@ unsafe extern "system" fn DllMain(_: HINSTANCE, reason: u32, _: *const c_void) - })); let args = env::args().collect_vec(); - if !args.contains(&"--disable-console".to_string()) { + if !args.contains(&"--disable-console".to_string()) { let _ = AllocConsole(); } // Initialize the lovely runtime. let rt = Lovely::init(&|a, b, c, d| LuaLoadbuffer_Detour.call(a, b, c, d)); RUNTIME.set(rt).unwrap_or_else(|_| panic!("Failed to instantiate runtime.")); - + // Quick and easy hook injection. Load the lua51.dll module at runtime, determine the address of the luaL_loadbuffer fn, hook it. let handle = LoadLibraryW(w!("lua51.dll")).unwrap(); let proc = GetProcAddress(handle, s!("luaL_loadbuffer")).unwrap(); let fn_target = std::mem::transmute::<_, unsafe extern "C" fn(*mut c_void, *const u8, isize, *const u8) -> u32>(proc); LuaLoadbuffer_Detour.initialize( - fn_target, + fn_target, |a, b, c, d| lua_loadbuffer_detour(a, b, c, d) ) .unwrap()