Skip to content

Commit 5110351

Browse files
committed
Detour DoesSaveGameExist
1 parent fe79bcf commit 5110351

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

hook/src/lib.rs

+26
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ unsafe fn patch() -> Result<()> {
111111
SaveGameToSlot,
112112
LoadGameFromMemory,
113113
LoadGameFromSlot,
114+
DoesSaveGameExist,
114115
}
115116

116117
let patterns = [
@@ -119,6 +120,7 @@ unsafe fn patch() -> Result<()> {
119120
(Sig::SaveGameToSlot, "48 89 5c 24 08 48 89 74 24 10 57 48 83 ec 40 48 8b da 33 f6 48 8d 54 24 30 48 89 74 24 30 48 89 74 24 38 41 8b f8"),
120121
(Sig::LoadGameFromMemory, "40 55 48 8d ac 24 00 ff ff ff 48 81 ec 00 02 00 00 83 79 08 00"),
121122
(Sig::LoadGameFromSlot, "48 8b c4 55 57 48 8d a8 d8 fe ff ff 48 81 ec 18 02 00 00"),
123+
(Sig::DoesSaveGameExist, "48 89 5C 24 08 57 48 83 EC 20 8B FA 48 8B D9 E8 ?? ?? ?? ?? 48 8B C8 4C 8B 00 41 FF 50 40 48 8B C8 48 85 C0 74 38 83 7B 08 00 74 17 48 8B 00 44 8B C7 48 8B 13 48 8B 5C 24 30 48 83 C4 20 5F 48 FF 60 08 48 8B 00 48 8D ?? ?? ?? ?? ?? 44 8B C7 48 8B 5C 24 30 48 83 C4 20 5F 48 FF 60 08 48 8B 5C 24 30 48 83 C4 20 5F C3"),
122124
].iter().map(|(name, pattern)| Ok((name, patternsleuth_scanner::Pattern::new(pattern)?))).collect::<Result<Vec<_>>>()?;
123125
let pattern_refs = patterns
124126
.iter()
@@ -210,6 +212,15 @@ unsafe fn patch() -> Result<()> {
210212
.enable()?;
211213
}
212214
}
215+
216+
if let Some(rva) = get_sig(Sig::DoesSaveGameExist) {
217+
let address = module_addr.add(rva);
218+
219+
let target: FnDoesSaveGameExist = std::mem::transmute(address);
220+
DoesSaveGameExist
221+
.initialize(target, does_save_game_exist_detour)?
222+
.enable()?;
223+
}
213224
}
214225
Ok(())
215226
}
@@ -268,11 +279,13 @@ type FnSaveGameToSlot = unsafe extern "system" fn(*const USaveGame, *const FStri
268279
type FnSaveGameToMemory = unsafe extern "system" fn(*const USaveGame, *mut TArray<u8>) -> bool;
269280
type FnLoadGameFromSlot = unsafe extern "system" fn(*const FString, i32) -> *const USaveGame;
270281
type FnLoadGameFromMemory = unsafe extern "system" fn(*const TArray<u8>) -> *const USaveGame;
282+
type FnDoesSaveGameExist = unsafe extern "system" fn(*const FString, i32) -> bool;
271283

272284
static_detour! {
273285
static GetServerName: unsafe extern "system" fn(*const c_void, *const c_void) -> *const FString;
274286
static SaveGameToSlot: unsafe extern "system" fn(*const USaveGame, *const FString, i32) -> bool;
275287
static LoadGameFromSlot: unsafe extern "system" fn(*const FString, i32) -> *const USaveGame;
288+
static DoesSaveGameExist: unsafe extern "system" fn(*const FString, i32) -> bool;
276289
}
277290

278291
#[allow(non_upper_case_globals)]
@@ -349,6 +362,19 @@ fn load_game_from_slot_detour(slot_name: *const FString, user_index: i32) -> *co
349362
}
350363
}
351364

365+
fn does_save_game_exist_detour(slot_name: *const FString, user_index: i32) -> bool {
366+
unsafe {
367+
let slot_name = &*slot_name;
368+
if slot_name.to_os_string().to_string_lossy() == "Player" {
369+
DoesSaveGameExist.call(slot_name, user_index)
370+
} else if let Some(path) = get_path_for_slot(slot_name) {
371+
path.exists()
372+
} else {
373+
false
374+
}
375+
}
376+
}
377+
352378
fn get_server_name_detour(a: *const c_void, b: *const c_void) -> *const FString {
353379
unsafe {
354380
let name: *mut FString = GetServerName.call(a, b) as *mut _;

0 commit comments

Comments
 (0)