Skip to content

Commit

Permalink
Add tavern-show-all-sailors mod
Browse files Browse the repository at this point in the history
  • Loading branch information
Trolldemorted committed Sep 16, 2024
1 parent 37812e6 commit cdc5a86
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
1 change: 0 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
- uses: actions/checkout@v4
- run: rustup target add i686-pc-windows-msvc
- run: cargo build
- run: Compress-Archive -Path ./target/i686-pc-windows-msvc/debug -DestinationPath release.zip
- uses: actions/upload-artifact@v4
with:
path: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- run: |
mkdir mods
mv target/i686-pc-windows-msvc/release/scrollmap_render_all_ships.dll ./mods/
mv target/i686-pc-windows-msvc/release/tavern_show_all_sailors.dll ./mods/
mkdir files
mv target/i686-pc-windows-msvc/release/aimcli.exe ./files
mv target/i686-pc-windows-msvc/release/cprcli.exe ./files
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"
members = [
"aimcli",
"cprcli",
"mod-scrollmap-render-all-ships",
"mod-scrollmap-render-all-ships", "mod-tavern-show-all-sailors",
#"p3-agent",
"p3-agent-loader",
"p3-aim",
Expand Down
20 changes: 20 additions & 0 deletions mod-tavern-show-all-sailors/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "mod-tavern-show-all-sailors"
edition = "2021"
version.workspace = true

[lib]
crate-type = ["cdylib"]
name="tavern_show_all_sailors"

[dependencies]
p3-api = { path = "../p3-api" }
log = { workspace = true }
win_dbg_logger = { workspace = true }

[dependencies.windows]
version = "0.48"
features = [
"Win32_Foundation",
"Win32_System_Memory",
]
32 changes: 32 additions & 0 deletions mod-tavern-show-all-sailors/src/ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use log::{debug, error};
use windows::Win32::{
Foundation::{GetLastError, WIN32_ERROR},
System::Memory::{VirtualProtect, PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS},
};

const PATCH_ADDRESS: u32 = 0x005D4CD6;

#[no_mangle]
pub unsafe extern "C" fn start() -> u32 {
let _ = log::set_logger(&win_dbg_logger::DEBUGGER_LOGGER);
log::set_max_level(log::LevelFilter::Trace);
let patch_ptr: *mut u8 = PATCH_ADDRESS as _;

let mut old_flags: PAGE_PROTECTION_FLAGS = windows::Win32::System::Memory::PAGE_PROTECTION_FLAGS(0);
if !VirtualProtect(patch_ptr as _, 5, PAGE_EXECUTE_READWRITE, &mut old_flags).as_bool() {
let error: WIN32_ERROR = GetLastError();
error!("VirtualProtect PAGE_EXECUTE_READWRITE failed: {:?}", error);
return 1;
}

debug!("Patching comparison at {:#x}", PATCH_ADDRESS);
*patch_ptr = 0x64;

if !VirtualProtect(patch_ptr as _, 5, old_flags, &mut old_flags).as_bool() {
let error: WIN32_ERROR = GetLastError();
error!("VirtualProtect restore failed: {:?}", error);
return 2;
}

0
}
1 change: 1 addition & 0 deletions mod-tavern-show-all-sailors/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod ffi;

0 comments on commit cdc5a86

Please sign in to comment.