Skip to content

Commit 505d664

Browse files
committed
add fix siege beggar satisfaction bonus mod
1 parent da472db commit 505d664

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

.github/workflows/release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
mkdir mods
1717
mv target/i686-pc-windows-msvc/release/fix_market_hall_production_town.dll ./mods/
1818
mv target/i686-pc-windows-msvc/release/fix_new_settlement_ware_production.dll ./mods/
19+
mv target/i686-pc-windows-msvc/release/fix_siege_beggar_satisfaction_bonus.dll ./mods/
1920
mv target/i686-pc-windows-msvc/release/increase_alderman_found_settlement_mission_limit.dll ./mods/
2021
mv target/i686-pc-windows-msvc/release/scrollmap_render_all_ships.dll ./mods/
2122
mv target/i686-pc-windows-msvc/release/tavern_show_all_sailors.dll ./mods/

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"cprcli",
77
"mod-fix-market-hall-production-town",
88
"mod-fix-new-settlement-ware-production",
9+
"mod-fix-siege-beggar-satisfaction-bonus",
910
"mod-increase-alderman-found-settlement-mission-limit",
1011
"mod-scrollmap-render-all-ships",
1112
"mod-tavern-show-all-sailors",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "mod-fix-siege-beggar-satisfaction-bonus"
3+
edition = "2021"
4+
version.workspace = true
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
name="fix_siege_beggar_satisfaction_bonus"
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,32 @@
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 = 0x00629A51;
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 = 0x03;
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub(crate) mod ffi;

0 commit comments

Comments
 (0)