diff --git a/Cargo.toml b/Cargo.toml index 1c9a6f9..f4815aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ widestring = "1.0.2" zerocopy = "0.7.29" paste = "1.0.14" region = "3.0.0" +pelite = "0.10.0" [dependencies.windows] version = "0.52.0" diff --git a/src/dll.rs b/src/dll.rs index 1ef748b..a891dc7 100644 --- a/src/dll.rs +++ b/src/dll.rs @@ -2,6 +2,7 @@ use std::os::windows::fs::FileExt; use std::{ops::Range, fs::File}; use std::sync::OnceLock; +use crate::{post_udk_init, udk_log}; use sha2::{Digest, Sha256}; use windows::{ @@ -19,10 +20,14 @@ use windows::{ core::Error, }; -pub fn dll_main(_hinst_dll: HINSTANCE, fdw_reason: u32, _lpv_reserved: usize) -> i32 { +#[no_mangle] +pub extern "stdcall" fn dll_main(_hinst_dll: HINSTANCE, fdw_reason: u32, _lpv_reserved: usize) -> i32 { match fdw_reason { DLL_PROCESS_ATTACH => { - dll_attach() + dll_attach(); + if let Err(error) = post_udk_init() { + udk_log::log(udk_log::LogType::Error, &format!("An error occurred initializing the library: {}", error)) + } } DLL_PROCESS_DETACH => {} diff --git a/src/lib.rs b/src/lib.rs index fc37ef9..34c06ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,4 +5,9 @@ mod xaudio27; mod dll; mod udk_log; -mod udk_xaudio; \ No newline at end of file +mod udk_xaudio; + +pub fn post_udk_init() -> anyhow::Result<()> { + udk_xaudio::init()?; + Ok(()) +} \ No newline at end of file diff --git a/src/udk_log.rs b/src/udk_log.rs index f23f16f..d083fb9 100644 --- a/src/udk_log.rs +++ b/src/udk_log.rs @@ -25,7 +25,7 @@ pub enum LogType { //Debug = 0x36c, //Log = 0x2f8, Warning = 0x2ff, - //Error = 0x315, + Error = 0x315, //Critical = 0x2f9, } diff --git a/src/udk_xaudio.rs b/src/udk_xaudio.rs index 6ed1461..0fca5eb 100644 --- a/src/udk_xaudio.rs +++ b/src/udk_xaudio.rs @@ -2,7 +2,7 @@ use anyhow::Context; use retour::static_detour; -use crate::get_udk_ptr; +use crate::dll::get_udk_ptr; use crate::udk_log::{log, LogType}; use crate::xaudio27::{IXAudio27, XAudio27Wrapper};