Skip to content

Commit c93984f

Browse files
committed
Add fix_invulnerable_ship_artillery_slots mod
1 parent 55d058c commit c93984f

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- run: |
1616
mkdir mods
1717
mv target/i686-pc-windows-msvc/release/fix_damage_to_offside_ship_artillery.dll ./mods/
18+
mv target/i686-pc-windows-msvc/release/fix_invulnerable_ship_artillery_slots.dll ./mods/
1819
mv target/i686-pc-windows-msvc/release/fix_market_hall_production_town.dll ./mods/
1920
mv target/i686-pc-windows-msvc/release/fix_new_settlement_ware_production.dll ./mods/
2021
mv target/i686-pc-windows-msvc/release/fix_siege_beggar_satisfaction_bonus.dll ./mods/

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"aimcli",
66
"cprcli",
77
"mod-fix-damage-to-offside-ship-artillery",
8+
"mod-fix-invulnerable-ship-artillery-slots",
89
"mod-fix-market-hall-production-town",
910
"mod-fix-new-settlement-ware-production",
1011
"mod-fix-siege-beggar-satisfaction-bonus",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "mod-fix-invulnerable-ship-artillery-slots"
3+
edition = "2021"
4+
version.workspace = true
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
name="fix_invulnerable_ship_artillery_slots"
9+
10+
[dependencies]
11+
p3-api = { path = "../p3-api" }
12+
log = { workspace = true }
13+
win_dbg_logger = { workspace = true }
14+
hooklet = { workspace = true }
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
use std::{arch::global_asm, ffi::c_void};
2+
3+
use hooklet::X86Rel32Type;
4+
use log::{debug, LevelFilter};
5+
6+
const PATCH_ADDRESS_1: u32 = 0x0061FDDB;
7+
const PATCH_ADDRESS_2: u32 = 0x0061FE8E;
8+
9+
static CONTINUATION_1: u32 = 0x0061FDE2;
10+
static CONTINUATION_2: u32 = 0x0061FE96;
11+
12+
#[no_mangle]
13+
pub unsafe extern "C" fn start() -> u32 {
14+
let _ = log::set_logger(&win_dbg_logger::DEBUGGER_LOGGER);
15+
log::set_max_level(LevelFilter::Trace);
16+
17+
if hooklet::deploy_rel32_raw(PATCH_ADDRESS_1 as _, (&fix_index_calc1) as *const _ as _, X86Rel32Type::Jump).is_err() {
18+
return 1;
19+
}
20+
21+
if hooklet::deploy_rel32_raw(PATCH_ADDRESS_2 as _, (&fix_index_calc2) as *const _ as _, X86Rel32Type::Jump).is_err() {
22+
return 2;
23+
}
24+
25+
0
26+
}
27+
28+
#[no_mangle]
29+
pub unsafe extern "cdecl" fn get_correct_index(index: u32) -> u32 {
30+
let multiplied_index = index * 2;
31+
let correct_index = match multiplied_index {
32+
4 => 0,
33+
_ => 2,
34+
};
35+
debug!("Correcting artillery slot index from {multiplied_index} to {correct_index}");
36+
37+
correct_index
38+
}
39+
40+
extern "C" {
41+
static fix_index_calc1: c_void;
42+
static fix_index_calc2: c_void;
43+
}
44+
45+
global_asm!(
46+
"
47+
.global {fix_index_calc1}
48+
{fix_index_calc1}:
49+
# save regs
50+
push ecx
51+
push edx
52+
53+
push eax
54+
call {get_correct_index}
55+
pop edx
56+
57+
# restore regs
58+
pop edx
59+
pop ecx
60+
61+
jmp [{continuation}]
62+
",
63+
fix_index_calc1 = sym fix_index_calc1,
64+
get_correct_index = sym get_correct_index,
65+
continuation = sym CONTINUATION_1
66+
);
67+
68+
global_asm!(
69+
"
70+
.global {fix_index_calc2}
71+
{fix_index_calc2}:
72+
# save regs
73+
push eax
74+
push edx
75+
76+
push ecx
77+
call {get_correct_index}
78+
mov ecx, eax
79+
pop edx
80+
81+
# restore regs
82+
pop edx
83+
pop eax
84+
85+
jmp [{continuation}]
86+
",
87+
fix_index_calc2 = sym fix_index_calc2,
88+
get_correct_index = sym get_correct_index,
89+
continuation = sym CONTINUATION_2
90+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub(crate) mod ffi;

0 commit comments

Comments
 (0)