From 4f133501dbb83678103ad9def602163db7a059f2 Mon Sep 17 00:00:00 2001 From: Truman Kilen <t@kilen.me> Date: Sun, 3 Nov 2024 21:57:13 -0600 Subject: [PATCH] Switch to proxy_dll --- Cargo.lock | 35 ++++++++++++++++++++++++++++++++--- hook/Cargo.toml | 1 + hook/src/lib.rs | 45 +++++---------------------------------------- 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b947250..516839f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2454,6 +2454,7 @@ dependencies = [ "mint_lib", "patternsleuth", "postcard", + "proxy_dll", "repak", "retour", "serde", @@ -3287,6 +3288,12 @@ dependencies = [ "url", ] +[[package]] +name = "msvc_def" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceed45db162aa13e647de49ecdde6ca4e8e7a0ebb2cd964414bed01879074862" + [[package]] name = "naga" version = "22.1.0" @@ -4158,6 +4165,28 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afbdc74edc00b6f6a218ca6a5364d6226a259d4b8ea1af4a0ea063f27e179f4d" +[[package]] +name = "proxy_dll" +version = "0.1.0" +source = "git+https://github.com/trumank/proxy_dll.git#ad0cee8b74597ee1819d0d2eeb516b812035bbeb" +dependencies = [ + "msvc_def", + "proxy_dll_proc", + "windows-sys 0.59.0", +] + +[[package]] +name = "proxy_dll_proc" +version = "0.1.0" +source = "git+https://github.com/trumank/proxy_dll.git#ad0cee8b74597ee1819d0d2eeb516b812035bbeb" +dependencies = [ + "msvc_def", + "proc-macro2", + "quote", + "syn 2.0.86", + "windows-sys 0.59.0", +] + [[package]] name = "pulldown-cmark" version = "0.12.2" @@ -4233,14 +4262,14 @@ dependencies = [ "once_cell", "socket2 0.5.5", "tracing", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] diff --git a/hook/Cargo.toml b/hook/Cargo.toml index 37d759e..99e29af 100644 --- a/hook/Cargo.toml +++ b/hook/Cargo.toml @@ -33,3 +33,4 @@ bitflags = "2.6.0" widestring = "1.1.0" tokio = { workspace = true, features = ["full"] } tracing-appender = "0.2.3" +proxy_dll = { git = "https://github.com/trumank/proxy_dll.git", version = "0.1.0" } diff --git a/hook/src/lib.rs b/hook/src/lib.rs index 8375409..cd7d6d2 100644 --- a/hook/src/lib.rs +++ b/hook/src/lib.rs @@ -8,48 +8,13 @@ use fs_err as fs; use hooks::{FnLoadGameFromMemory, FnSaveGameToMemory}; use mint_lib::mod_info::Meta; use tracing::{info, warn}; -use windows::Win32::{ - Foundation::HMODULE, - System::{ - SystemServices::*, - Threading::{GetCurrentThread, QueueUserAPC}, - }, -}; - -// x3daudio1_7.dll -#[no_mangle] -#[allow(non_snake_case, unused_variables)] -extern "system" fn X3DAudioCalculate() {} -#[no_mangle] -#[allow(non_snake_case, unused_variables)] -extern "system" fn X3DAudioInitialize() {} - -// d3d9.dll -#[no_mangle] -#[allow(non_snake_case, unused_variables)] -extern "system" fn D3DPERF_EndEvent() {} -#[no_mangle] -#[allow(non_snake_case, unused_variables)] -extern "system" fn D3DPERF_BeginEvent() {} - -#[no_mangle] -#[allow(non_snake_case, unused_variables)] -extern "system" fn DllMain(dll_module: HMODULE, call_reason: u32, _: *mut ()) -> bool { - unsafe { - match call_reason { - DLL_PROCESS_ATTACH => { - QueueUserAPC(Some(init), GetCurrentThread(), 0); - } - DLL_PROCESS_DETACH => (), - _ => (), - } - true - } -} +proxy_dll::proxy_dll!([x3daudio1_7, d3d9], init); -unsafe extern "system" fn init(_: usize) { - patch().ok(); +fn init() { + unsafe { + patch().ok(); + } } static mut GLOBALS: Option<Globals> = None;