fix: remove hkcheck as it's not needed (yet?)

This commit is contained in:
amizing25
2025-03-15 05:48:53 +07:00
parent 8861b07cb8
commit bc651397e6
2 changed files with 68 additions and 45 deletions

View File

@@ -2,7 +2,7 @@ use std::sync::{LazyLock, OnceLock};
use windows::{Win32::System::LibraryLoader::GetModuleHandleA, core::s}; use windows::{Win32::System::LibraryLoader::GetModuleHandleA, core::s};
use crate::util::{scan_il2cpp_section, scan_unity_player_section}; use crate::util::scan_il2cpp_section;
const PTR_TO_STRING_ANSI: &str = "E8 ? ? ? ? 48 ? ? 48 85 C0 75 ? 48 8D 4C 24"; const PTR_TO_STRING_ANSI: &str = "E8 ? ? ? ? 48 ? ? 48 85 C0 75 ? 48 8D 4C 24";
const MAKE_INITIAL_URL: &str = "55 41 56 56 57 53 48 83 EC ? 48 8D 6C 24 ? 48 C7 45 ? ? ? ? ? 48 89 D6 48 89 CF E8 ? ? ? ? 84 C0"; // TODO const MAKE_INITIAL_URL: &str = "55 41 56 56 57 53 48 83 EC ? 48 8D 6C 24 ? 48 C7 45 ? ? ? ? ? 48 89 D6 48 89 CF E8 ? ? ? ? 84 C0"; // TODO
@@ -10,8 +10,8 @@ const SET_ELEVATION_DITHER: &str = "E9 ? ? ? ? 0F 28 74 24 ? 48 83 C4 ? 5B 5F 5E
const SET_DISTANCE_DITHER: &str = "E8 ? ? ? ? 49 8B 46 ? 48 85 C0 0F 84 ? ? ? ? 48 8B 4D"; // TODO const SET_DISTANCE_DITHER: &str = "E8 ? ? ? ? 49 8B 46 ? 48 85 C0 0F 84 ? ? ? ? 48 8B 4D"; // TODO
const SET_DITHER_ALPHA: &str = "56 57 48 83 EC ? 0F 29 74 24 ? 44 89 C6 0F 28 F1 48 89 CF 80 3D ? ? ? ? ? 75 ? 80 7F"; // TODO const SET_DITHER_ALPHA: &str = "56 57 48 83 EC ? 0F 29 74 24 ? 44 89 C6 0F 28 F1 48 89 CF 80 3D ? ? ? ? ? 75 ? 80 7F"; // TODO
const SET_DITHER_ALPHA_ANIM: &str = "56 57 55 53 48 83 EC ? 44 0F 29 44 24 ? 0F 29 7C 24 ? 0F 29 74 24 ? 44 0F 28 C3 0F 28 F2 0F 28 F9"; // TODO const SET_DITHER_ALPHA_ANIM: &str = "56 57 55 53 48 83 EC ? 44 0F 29 44 24 ? 0F 29 7C 24 ? 0F 29 74 24 ? 44 0F 28 C3 0F 28 F2 0F 28 F9"; // TODO
const HK_CHECK1: &str = "55 41 56 56 57 53 48 81 EC 00 01 00 00 48 8D AC 24 80 00 00 00 C7 45 7C 00 00 00 00"; // const HK_CHECK1: &str = "55 41 56 56 57 53 48 81 EC 00 01 00 00 48 8D AC 24 80 00 00 00 C7 45 7C 00 00 00 00";
const HK_CHECK2: &str = "55 41 57 41 56 41 55 41 54 56 57 53 48 81 EC B8 02 00 00"; // const HK_CHECK2: &str = "55 41 57 41 56 41 55 41 54 56 57 53 48 81 EC B8 02 00 00";
#[derive(Default)] #[derive(Default)]
pub struct RVAConfig { pub struct RVAConfig {
@@ -34,22 +34,24 @@ pub fn rva_config() -> &'static mut RVAConfig {
pub static GAME_ASSEMBLY_BASE: LazyLock<usize> = pub static GAME_ASSEMBLY_BASE: LazyLock<usize> =
LazyLock::new(|| unsafe { GetModuleHandleA(s!("GameAssembly.dll")).unwrap().0 as usize }); LazyLock::new(|| unsafe { GetModuleHandleA(s!("GameAssembly.dll")).unwrap().0 as usize });
pub static UNITY_PLAYER_BASE: LazyLock<usize> = // pub static UNITY_PLAYER_BASE: LazyLock<usize> =
LazyLock::new(|| unsafe { GetModuleHandleA(s!("UnityPlayer.dll")).unwrap().0 as usize }); // LazyLock::new(|| unsafe { GetModuleHandleA(s!("UnityPlayer.dll")).unwrap().0 as usize });
macro_rules! set_rva { macro_rules! set_rva {
($config:ident, $field:ident, $scan_fn:ident, $rva_pat:expr, $fallback:expr) => { ($base:ident, $config:ident, $field:ident, $scan_fn:ident, $rva_pat:expr, $fallback:expr) => {
if let Some(addr) = unsafe { $scan_fn($rva_pat) } { if let Some(addr) = unsafe { $scan_fn($rva_pat) } {
$config.$field = addr - *GAME_ASSEMBLY_BASE; $config.$field = addr - *$base;
println!( println!(
"[hkrpg::addr::set_rva] Found relative address for {} -> 0x{:X}", "[hkrpg::addr::set_rva] Found relative address for {} [{}] -> 0x{:X}",
stringify!($field), stringify!($field),
stringify!($base),
$config.$field $config.$field
); );
} else { } else {
eprintln!( eprintln!(
"[hkrpg::addr::set_rva] Failed to find pattern for {} using {}", "[hkrpg::addr::set_rva] Failed to find pattern for {} [{}] using {}",
stringify!($field), stringify!($field),
stringify!($base),
stringify!($scan_fn) stringify!($scan_fn)
); );
@@ -63,6 +65,7 @@ pub unsafe fn init_rvas() {
// ptr_to_string_ansi // ptr_to_string_ansi
set_rva!( set_rva!(
GAME_ASSEMBLY_BASE,
config, config,
ptr_to_string_ansi, ptr_to_string_ansi,
scan_il2cpp_section, scan_il2cpp_section,
@@ -72,6 +75,7 @@ pub unsafe fn init_rvas() {
// make_initial_url // make_initial_url
set_rva!( set_rva!(
GAME_ASSEMBLY_BASE,
config, config,
make_initial_url, make_initial_url,
scan_il2cpp_section, scan_il2cpp_section,
@@ -81,6 +85,7 @@ pub unsafe fn init_rvas() {
// set_elevation_dither // set_elevation_dither
set_rva!( set_rva!(
GAME_ASSEMBLY_BASE,
config, config,
set_elevation_dither, set_elevation_dither,
scan_il2cpp_section, scan_il2cpp_section,
@@ -89,6 +94,7 @@ pub unsafe fn init_rvas() {
); );
// set_distance_dither // set_distance_dither
set_rva!( set_rva!(
GAME_ASSEMBLY_BASE,
config, config,
set_distance_dither, set_distance_dither,
scan_il2cpp_section, scan_il2cpp_section,
@@ -97,6 +103,7 @@ pub unsafe fn init_rvas() {
); );
// set_dither_alpha // set_dither_alpha
set_rva!( set_rva!(
GAME_ASSEMBLY_BASE,
config, config,
set_dither_alpha, set_dither_alpha,
scan_il2cpp_section, scan_il2cpp_section,
@@ -105,6 +112,7 @@ pub unsafe fn init_rvas() {
); );
// set_dither_alpha_anim // set_dither_alpha_anim
set_rva!( set_rva!(
GAME_ASSEMBLY_BASE,
config, config,
set_dither_alpha_anim, set_dither_alpha_anim,
scan_il2cpp_section, scan_il2cpp_section,
@@ -112,6 +120,20 @@ pub unsafe fn init_rvas() {
0x0 0x0
); );
set_rva!(config, hk_check1, scan_unity_player_section, HK_CHECK1, 0x0); // set_rva!(
set_rva!(config, hk_check2, scan_unity_player_section, HK_CHECK2, 0x0); // UNITY_PLAYER_BASE,
// config,
// hk_check1,
// scan_unity_player_section,
// HK_CHECK1,
// 0x0
// );
// set_rva!(
// UNITY_PLAYER_BASE,
// config,
// hk_check2,
// scan_unity_player_section,
// HK_CHECK2,
// 0x0
// );
} }

View File

@@ -10,7 +10,7 @@ use windows::{
core::s, core::s,
}; };
use crate::addr::{GAME_ASSEMBLY_BASE, UNITY_PLAYER_BASE}; use crate::addr::GAME_ASSEMBLY_BASE;
#[allow(static_mut_refs)] #[allow(static_mut_refs)]
unsafe fn game_assembly_slice() -> &'static [u8] { unsafe fn game_assembly_slice() -> &'static [u8] {
@@ -38,39 +38,14 @@ unsafe fn game_assembly_slice() -> &'static [u8] {
} }
} }
#[allow(static_mut_refs)]
unsafe fn unity_player_slice() -> &'static [u8] {
static mut SLICE: OnceCell<&[u8]> = OnceCell::new();
unsafe {
SLICE.get_or_init(|| {
let module = GetModuleHandleA(s!("UnityPlayer.dll")).unwrap();
let mut module_info = MODULEINFO {
lpBaseOfDll: std::ptr::null_mut(),
SizeOfImage: 0,
EntryPoint: std::ptr::null_mut(),
};
GetModuleInformation(
GetCurrentProcess(),
module,
&mut module_info,
std::mem::size_of::<MODULEINFO>() as u32,
)
.unwrap();
std::slice::from_raw_parts(
module.0 as *const u8,
module_info.SizeOfImage.try_into().unwrap(),
)
})
}
}
pub unsafe fn scan_il2cpp_section(pat: &str) -> Option<usize> { pub unsafe fn scan_il2cpp_section(pat: &str) -> Option<usize> {
let mut slice = unsafe { game_assembly_slice() }; let mut slice = unsafe { game_assembly_slice() };
scan_first_match(&mut slice, pat).unwrap().map(|address| { scan_first_match(&mut slice, pat).unwrap().map(|address| {
let slice = unsafe { game_assembly_slice() }; let slice = unsafe { game_assembly_slice() };
let instruction = &slice[address..address + 1][0]; let instruction = &slice[address..address + 1][0];
if *instruction == 0xE8 { if *instruction == 0xE8 {
let offset = i32::from_le_bytes((&slice[address + 1..address + 1 + 4]).try_into().unwrap()); let offset =
i32::from_le_bytes((&slice[address + 1..address + 1 + 4]).try_into().unwrap());
let pointer = offset as usize + 5 + address; let pointer = offset as usize + 5 + address;
return GAME_ASSEMBLY_BASE.wrapping_add(pointer); return GAME_ASSEMBLY_BASE.wrapping_add(pointer);
} }
@@ -78,9 +53,35 @@ pub unsafe fn scan_il2cpp_section(pat: &str) -> Option<usize> {
}) })
} }
pub unsafe fn scan_unity_player_section(pat: &str) -> Option<usize> { // #[allow(static_mut_refs)]
let mut slice = unsafe { unity_player_slice() }; // unsafe fn unity_player_slice() -> &'static [u8] {
scan_first_match(&mut slice, pat) // static mut SLICE: OnceCell<&[u8]> = OnceCell::new();
.unwrap() // unsafe {
.map(|loc| UNITY_PLAYER_BASE.wrapping_add(loc)) // SLICE.get_or_init(|| {
} // let module = GetModuleHandleA(s!("UnityPlayer.dll")).unwrap();
// let mut module_info = MODULEINFO {
// lpBaseOfDll: std::ptr::null_mut(),
// SizeOfImage: 0,
// EntryPoint: std::ptr::null_mut(),
// };
// GetModuleInformation(
// GetCurrentProcess(),
// module,
// &mut module_info,
// std::mem::size_of::<MODULEINFO>() as u32,
// )
// .unwrap();
// std::slice::from_raw_parts(
// module.0 as *const u8,
// module_info.SizeOfImage.try_into().unwrap(),
// )
// })
// }
// }
// pub unsafe fn scan_unity_player_section(pat: &str) -> Option<usize> {
// let mut slice = unsafe { unity_player_slice() };
// scan_first_match(&mut slice, pat)
// .unwrap()
// .map(|loc| UNITY_PLAYER_BASE.wrapping_add(loc))
// }