Skip to content

Commit 572faa2

Browse files
committed
Fix new settlement wares mod (whaleoil)
1 parent 5faca7e commit 572faa2

File tree

3 files changed

+35
-40
lines changed

3 files changed

+35
-40
lines changed

mod-fix-new-settlement-ware-production/Cargo.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,4 @@ name="fix_new_settlement_ware_production"
1010
[dependencies]
1111
log = { workspace = true }
1212
win_dbg_logger = { workspace = true }
13-
14-
[dependencies.windows]
15-
version = "0.48"
16-
features = [
17-
"Win32_Foundation",
18-
"Win32_System_Memory",
19-
]
13+
hooklet = { workspace = true }
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
use log::{debug, error};
2-
use windows::Win32::{
3-
Foundation::{GetLastError, WIN32_ERROR},
4-
System::Memory::{VirtualProtect, PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS},
5-
};
6-
7-
const PATCH_ADDRESS: u32 = 0x00532FF3;
8-
9-
#[no_mangle]
10-
pub unsafe extern "C" fn start() -> u32 {
11-
let _ = log::set_logger(&win_dbg_logger::DEBUGGER_LOGGER);
12-
log::set_max_level(log::LevelFilter::Trace);
13-
let patch_ptr: *mut u8 = PATCH_ADDRESS as _;
14-
15-
let mut old_flags: PAGE_PROTECTION_FLAGS = windows::Win32::System::Memory::PAGE_PROTECTION_FLAGS(0);
16-
if !VirtualProtect(patch_ptr as _, 5, PAGE_EXECUTE_READWRITE, &mut old_flags).as_bool() {
17-
let error: WIN32_ERROR = GetLastError();
18-
error!("VirtualProtect PAGE_EXECUTE_READWRITE failed: {:?}", error);
19-
return 1;
20-
}
21-
22-
debug!("Patching comparison at {:#x}", PATCH_ADDRESS);
23-
*patch_ptr = 0x04;
24-
25-
if !VirtualProtect(patch_ptr as _, 5, old_flags, &mut old_flags).as_bool() {
26-
let error: WIN32_ERROR = GetLastError();
27-
error!("VirtualProtect restore failed: {:?}", error);
28-
return 2;
29-
}
30-
31-
0
32-
}
1+
use hooklet::windows::x86::replace_slice_rwx;
2+
use log::{debug, error};
3+
4+
const SUBTRACTION_PATCH_ADDRESS: u32 = 0x00532FF3;
5+
const WHALEOIL_PATCH_ADDRESS: u32 = 0x00533013;
6+
7+
#[no_mangle]
8+
pub unsafe extern "C" fn start() -> u32 {
9+
let _ = log::set_logger(&win_dbg_logger::DEBUGGER_LOGGER);
10+
log::set_max_level(log::LevelFilter::Trace);
11+
12+
debug!("Patching `sub` immediate value at {:#x}", SUBTRACTION_PATCH_ADDRESS);
13+
let subtraction_patch = [4];
14+
match replace_slice_rwx(SUBTRACTION_PATCH_ADDRESS, &subtraction_patch) {
15+
Ok(_) => {}
16+
Err(e) => {
17+
error!("Failed to deploy patch: {:?}", e);
18+
return 1;
19+
}
20+
}
21+
22+
debug!("Patching whaleoil `or` immediate value at {:#x}", SUBTRACTION_PATCH_ADDRESS);
23+
let whaleoil_patch = 0x20002u32.to_le_bytes();
24+
match replace_slice_rwx(WHALEOIL_PATCH_ADDRESS, &whaleoil_patch) {
25+
Ok(_) => {}
26+
Err(e) => {
27+
error!("Failed to deploy patch: {:?}", e);
28+
return 2;
29+
}
30+
}
31+
32+
0
33+
}

mod-town-hall-details/src/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::{
55
sync::atomic::{AtomicPtr, Ordering},
66
};
77

8-
use hooklet::windows::x86::{deploy_rel32_raw, hook_call_rel32, CallRel32Hook, FunctionPointerHook, X86Rel32Type};
98
use hooklet::windows::x86::hook_function_pointer;
9+
use hooklet::windows::x86::{deploy_rel32_raw, hook_call_rel32, CallRel32Hook, FunctionPointerHook, X86Rel32Type};
1010
use log::debug;
1111
use p3_api::ui::ui_town_hall_window::UITownHallWindowPtr;
1212
use windows::core::PCSTR;

0 commit comments

Comments
 (0)