Skip to content

Commit

Permalink
add some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed Nov 2, 2023
1 parent 20ff35e commit 8542f42
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion hook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ unsafe fn patch() -> Result<()> {
return Ok(());
}

let log_path = std::env::current_exe().unwrap().parent().unwrap().join("log.txt");
let mut log = std::fs::OpenOptions::new().create(true).write(true).truncate(true).open(log_path).unwrap();
use std::io::Write;
writeln!(log, "started")?;

let installation_type = DRGInstallationType::from_exe_path()?;

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -138,9 +143,14 @@ unsafe fn patch() -> Result<()> {
),
];

let scan = patternsleuth::process::internal::read_image()?.scan(&patterns)?;
writeln!(log, "reading image")?;
let image = patternsleuth::process::internal::read_image()?;
writeln!(log, "starting scan")?;
let scan = image.scan(&patterns)?;
writeln!(log, "scan done")?;

if let Ok(address) = scan.get_unique_sig_address(Sig::GetServerName) {
writeln!(log, "found GetServerName")?;
let address = address as *const c_void;

let resize_rip = address.add(53);
Expand All @@ -158,6 +168,7 @@ unsafe fn patch() -> Result<()> {

if matches!(installation_type, DRGInstallationType::Steam) {
if let Ok(address) = scan.get_unique_sig_address(Sig::Disable) {
writeln!(log, "found Disable")?;
let address = (address as *mut u8).add(29);
let patch = [0xB8, 0x01, 0x00, 0x00, 0x00];

Expand Down Expand Up @@ -195,6 +206,7 @@ unsafe fn patch() -> Result<()> {
);

if let Ok(address) = scan.get_unique_sig_address(Sig::SaveGameToSlot) {
writeln!(log, "found SaveGameToSlot")?;
let address = address as *const c_void;

let save_rip = address.add(39);
Expand All @@ -209,6 +221,7 @@ unsafe fn patch() -> Result<()> {
}

if let Ok(address) = scan.get_unique_sig_address(Sig::LoadGameFromMemory) {
writeln!(log, "found LoadGameFromMemory")?;
let address = address as *const c_void;
LoadGameFromMemory = Some(std::mem::transmute(address));

Expand All @@ -223,6 +236,7 @@ unsafe fn patch() -> Result<()> {
}

if let Ok(address) = scan.get_unique_sig_address(Sig::DoesSaveGameExist) {
writeln!(log, "found DoesSaveGameExist")?;
let address = address as *const c_void;

let target: FnDoesSaveGameExist = std::mem::transmute(address);
Expand Down

0 comments on commit 8542f42

Please sign in to comment.