Skip to content

Commit 427c226

Browse files
committed
add fix damage to offside ship artillery mod
1 parent 505d664 commit 427c226

File tree

6 files changed

+61
-1
lines changed

6 files changed

+61
-1
lines changed

.github/workflows/release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- run: cargo build --release
1515
- run: |
1616
mkdir mods
17+
mv target/i686-pc-windows-msvc/release/fix_damage_to_offside_ship_artillery.dll ./mods/
1718
mv target/i686-pc-windows-msvc/release/fix_market_hall_production_town.dll ./mods/
1819
mv target/i686-pc-windows-msvc/release/fix_new_settlement_ware_production.dll ./mods/
1920
mv target/i686-pc-windows-msvc/release/fix_siege_beggar_satisfaction_bonus.dll ./mods/

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ resolver = "2"
44
members = [
55
"aimcli",
66
"cprcli",
7+
"mod-fix-damage-to-offside-ship-artillery",
78
"mod-fix-market-hall-production-town",
89
"mod-fix-new-settlement-ware-production",
910
"mod-fix-siege-beggar-satisfaction-bonus",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "mod-fix-damage-to-offside-ship-artillery"
3+
edition = "2021"
4+
version.workspace = true
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
name="fix_damage_to_offside_ship_artillery"
9+
10+
[dependencies]
11+
log = { workspace = true }
12+
win_dbg_logger = { workspace = true }
13+
14+
[dependencies.windows]
15+
version = "0.48"
16+
features = [
17+
"Win32_Foundation",
18+
"Win32_System_Memory",
19+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
const PATCH_ADDRESS: u32 = 0x0067AB30;
7+
8+
static HITBOXES: &[u8] = &[
9+
0x00, 0x00, 0xC9, 0xFF, 0x13, 0x00, 0xE1, 0xFF, 0x13, 0x00, 0x2F, 0x00, 0xED, 0xFF, 0x2F, 0x00, 0xED, 0xFF, 0xE1, 0xFF, 0x00, 0x00, 0xBE, 0xFF, 0x15, 0x00,
10+
0xDC, 0xFF, 0x13, 0x00, 0x37, 0x00, 0xED, 0xFF, 0x37, 0x00, 0xEB, 0xFF, 0xDC, 0xFF, 0x00, 0x00, 0xCA, 0xFF, 0x19, 0x00, 0xF2, 0xFF, 0x13, 0x00, 0x43, 0x00,
11+
0xED, 0xFF, 0x43, 0x00, 0xE7, 0xFF, 0xF2, 0xFF, 0x00, 0x00, 0xBD, 0xFF, 0x16, 0x00, 0xE7, 0xFF, 0x13, 0x00, 0x51, 0x00, 0xED, 0xFF, 0x51, 0x00, 0xEA, 0xFF,
12+
0xE7, 0xFF,
13+
];
14+
15+
#[no_mangle]
16+
pub unsafe extern "C" fn start() -> u32 {
17+
let _ = log::set_logger(&win_dbg_logger::DEBUGGER_LOGGER);
18+
log::set_max_level(log::LevelFilter::Trace);
19+
let patch_ptr: *mut u8 = PATCH_ADDRESS as _;
20+
21+
let mut old_flags: PAGE_PROTECTION_FLAGS = windows::Win32::System::Memory::PAGE_PROTECTION_FLAGS(0);
22+
if !VirtualProtect(patch_ptr as _, 5, PAGE_EXECUTE_READWRITE, &mut old_flags).as_bool() {
23+
let error: WIN32_ERROR = GetLastError();
24+
error!("VirtualProtect PAGE_EXECUTE_READWRITE failed: {:?}", error);
25+
return 1;
26+
}
27+
28+
debug!("Patching hitboxes at {:#x}", PATCH_ADDRESS);
29+
patch_ptr.copy_from(HITBOXES.as_ptr(), HITBOXES.len());
30+
31+
if !VirtualProtect(patch_ptr as _, 5, old_flags, &mut old_flags).as_bool() {
32+
let error: WIN32_ERROR = GetLastError();
33+
error!("VirtualProtect restore failed: {:?}", error);
34+
return 2;
35+
}
36+
37+
0
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub(crate) mod ffi;

mod-fix-siege-beggar-satisfaction-bonus/src/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub unsafe extern "C" fn start() -> u32 {
1919
return 1;
2020
}
2121

22-
debug!("Patching comparison at {:#x}", PATCH_ADDRESS);
22+
debug!("Patching loop count at {:#x}", PATCH_ADDRESS);
2323
*patch_ptr = 0x03;
2424

2525
if !VirtualProtect(patch_ptr as _, 5, old_flags, &mut old_flags).as_bool() {

0 commit comments

Comments
 (0)