diff --git a/src/lib.rs b/src/lib.rs index f0b706f..ef3298f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ use std::{sync::RwLock, time::Duration}; use lazy_static::lazy_static; +use modules::Misc; use windows::core::PCSTR; use windows::Win32::System::Console; use windows::Win32::System::SystemServices::DLL_PROCESS_ATTACH; @@ -23,12 +24,13 @@ unsafe fn thread_func() { util::disable_memprotect_guard(); Console::AllocConsole().unwrap(); - println!("Genshin Impact encryption patch\nMade by xeondev\nTo work with MualaniImpact: git.xeondev.com/reversedrooms/MualaniImpact"); + println!("Genshin Impact encryption patch\nMade by xeondev\nTo work with XilonenImpact: git.xeondev.com/reversedrooms/XilonenImpact"); println!("Base: {:X}", base); let mut module_manager = MODULE_MANAGER.write().unwrap(); module_manager.enable(MhyContext::::new(base)); module_manager.enable(MhyContext::::new(base)); + module_manager.enable(MhyContext::::new(base)); println!("Successfully initialized!"); } diff --git a/src/modules/http.rs b/src/modules/http.rs index bd55ffe..0d19ce8 100644 --- a/src/modules/http.rs +++ b/src/modules/http.rs @@ -48,9 +48,11 @@ unsafe extern "win64" fn on_make_initial_url(reg: *mut Registers, _: usize) { new_url.push_str(s); }); - println!("Redirect: {url} -> {new_url}"); - (*reg).rcx = - marshal::ptr_to_string_ansi(CString::new(new_url.as_str()).unwrap().as_c_str()) as u64; + if !url.contains("/query_cur_region") { + println!("Redirect: {url} -> {new_url}"); + (*reg).rcx = + marshal::ptr_to_string_ansi(CString::new(new_url.as_str()).unwrap().as_c_str()) as u64; + } } unsafe extern "win64" fn on_browser_load_url(reg: *mut Registers, _: usize) { diff --git a/src/modules/misc.rs b/src/modules/misc.rs new file mode 100644 index 0000000..2ab8a7c --- /dev/null +++ b/src/modules/misc.rs @@ -0,0 +1,52 @@ +use std::ffi::CStr; + +use super::{MhyContext, MhyModule, ModuleType}; +use anyhow::Result; +use ilhook::x64::Registers; +use windows::{core::PCSTR, Win32::System::LibraryLoader::GetModuleHandleA}; + +pub struct Misc; + +const DYNAMIC_IMPORT: usize = 0x3F5240; +const SET_CUSTOM_PROPERTY_FLOAT: usize = 0x11E1880; + +impl MhyModule for MhyContext { + unsafe fn init(&mut self) -> Result<()> { + // CNCBWin5.0.50 sound fix + self.interceptor + .attach(self.assembly_base + DYNAMIC_IMPORT, on_dynamic_import)?; + + // Dither + self.interceptor.replace( + self.assembly_base + SET_CUSTOM_PROPERTY_FLOAT, + set_custom_property_float_replacement, + ) + } + + unsafe fn de_init(&mut self) -> Result<()> { + Ok(()) + } + + fn get_module_type(&self) -> super::ModuleType { + ModuleType::Misc + } +} + +unsafe extern "win64" fn on_dynamic_import(reg: *mut Registers, _: usize) { + let symbol_name_ptr = *((*reg).rcx.wrapping_add(16) as *const usize); + let symbol_name = CStr::from_ptr(symbol_name_ptr as *const i8); + + // Hoyo forgot to package updated sound library and that's the missing export + if symbol_name.to_string_lossy() == "GetMusicSyncCallbackInfoPlayingSeq" { + let base = GetModuleHandleA(PCSTR::null()).unwrap().0 as usize; + *((*reg).rcx.wrapping_add(16) as *mut usize) = base + 0x2F6CD04; + } +} + +unsafe extern "win64" fn set_custom_property_float_replacement( + _: *mut Registers, + _: usize, + _: usize, +) -> usize { + 0 +} diff --git a/src/modules/mod.rs b/src/modules/mod.rs index ed792fa..68332ca 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -5,9 +5,11 @@ use anyhow::Result; use crate::interceptor::Interceptor; mod http; +mod misc; mod security; pub use http::Http; +pub use misc::Misc; pub use security::Security; #[derive(Default)] @@ -38,6 +40,7 @@ impl ModuleManager { pub enum ModuleType { Http, Security, + Misc, } pub trait MhyModule {