diff --git a/src/lib.rs b/src/lib.rs index c3b9c3e..446cabf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,11 +7,18 @@ mod udk_log; mod udk_offsets; mod udk_xaudio; +#[cfg(target_arch = "x86_64")] const UDK_KNOWN_HASH: [u8; 32] = [ 0x0D, 0xE6, 0x90, 0x31, 0xEA, 0x41, 0x01, 0xF2, 0x18, 0xB6, 0x61, 0x27, 0xFD, 0x14, 0x3A, 0x8E, 0xC3, 0xF7, 0x48, 0x3E, 0x31, 0x9C, 0x3D, 0x8D, 0xD5, 0x1F, 0xA2, 0x8D, 0x7C, 0xBF, 0x08, 0xF5, ]; +#[cfg(target_arch = "x86")] +const UDK_KNOWN_HASH: [u8; 32] = [ + 0xEF, 0xAF, 0xBA, 0x91, 0xD3, 0x05, 0x2D, 0x07, 0x07, 0xDD, 0xF2, 0xF2, 0x14, 0x15, 0x00, 0xFA, + 0x6C, 0x1E, 0x8F, 0x9E, 0xF0, 0x70, 0x40, 0xB8, 0xF9, 0x96, 0x73, 0x8A, 0x00, 0xFB, 0x90, 0x07, +]; + use anyhow::Context; use sha2::{Digest, Sha256}; diff --git a/src/udk_log.rs b/src/udk_log.rs index 01d5dab..251d967 100644 --- a/src/udk_log.rs +++ b/src/udk_log.rs @@ -1,6 +1,4 @@ //! This module contains functionality relevant to UDK logging. -use widestring::WideCStr; - use crate::get_udk_slice; use crate::udk_offsets::{DEBUG_FN_OFFSET, DEBUG_LOG_OFFSET}; @@ -11,24 +9,24 @@ type UDKLogFn = unsafe extern "C" fn(usize, u32, *const widestring::WideChar); /// This enum represents the UDK message types. #[repr(u32)] pub enum LogType { - Init = 762, - Warning = 767, + Init = 0x2fa, + //Debug = 0x36c, + //Log = 0x2f8, + Warning = 0x2ff, + //Error = 0x315, + //Critical = 0x2f9, } -pub fn log_wide(typ: LogType, wmsg: &WideCStr) { +/// Log a message via the UDK logging framework. +pub fn log(typ: LogType, msg: &str) { let udk_slice = get_udk_slice(); let log_obj = unsafe { udk_slice.as_ptr().add(DEBUG_LOG_OFFSET) }; let log_fn: UDKLogFn = unsafe { std::mem::transmute(udk_slice.as_ptr().add(DEBUG_FN_OFFSET)) }; + // Convert the UTF-8 Rust string into an OS wide string. + let wmsg: widestring::U16CString = widestring::WideCString::from_str(format!("TotemArts Extensions: {}", msg)).unwrap(); + unsafe { (log_fn)(log_obj as usize, typ as u32, wmsg.as_ptr()); } } - -/// Log a message via the UDK logging framework. -pub fn log(typ: LogType, msg: &str) { - // Convert the UTF-8 Rust string into an OS wide string. - let wmsg = widestring::WideCString::from_str(&msg).unwrap(); - - log_wide(typ, &wmsg) -} diff --git a/src/udk_offsets.rs b/src/udk_offsets.rs index 5e31775..d8a94fc 100644 --- a/src/udk_offsets.rs +++ b/src/udk_offsets.rs @@ -2,9 +2,18 @@ // Logging offsets. /// Offset from the beginning of UDK64.exe to the debug log object. -pub const DEBUG_LOG_OFFSET: usize = 0x0355_1720; +#[cfg(target_arch = "x86_64")] +const DEBUG_LOG_OFFSET: usize = 0x0355_1720; /// Address of UDK's log function. -pub const DEBUG_FN_OFFSET: usize = 0x0024_6A20; +#[cfg(target_arch = "x86_64")] +const DEBUG_FN_OFFSET: usize = 0x0024_6A20; + +/// Offset from the beginning of UDK64.exe to the debug log object. +#[cfg(target_arch = "x86")] +const DEBUG_LOG_OFFSET: usize = 0x029a_31a8; +/// Address of UDK's log function. +#[cfg(target_arch = "x86")] +const DEBUG_FN_OFFSET: usize = 0x0002_1c500; // XAudio2 offsets. // pub const UDK_INITHW_OFFSET: usize = 0x0171_1ED0;