Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Removed static_detour from ac6
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankvdStam committed Jul 12, 2024
1 parent 448bbd0 commit e776b83
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions soulmemory-rs/src/games/armored_core_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

use std::any::Any;
use std::mem;
use std::ops::Deref;
use std::sync::{Arc, Mutex};
use retour::static_detour;
use ilhook::x64::{CallbackOption, Hooker, HookFlags, HookPoint, HookType, Registers};
use log::info;
use mem_rs::prelude::*;
use crate::App;
use crate::games::traits::buffered_event_flags::{BufferedEventFlags, EventFlag};
use crate::games::dx_version::DxVersion;
use crate::games::game::Game;

static_detour!{ static STATIC_DETOUR_SET_EVENT_FLAG: fn(u64, u32, i32); }
use crate::games::GameExt;

type FnGetEventFlag = fn(event_flag_man: u64, event_flag: u32) -> u8;

Expand All @@ -36,6 +37,7 @@ pub struct ArmoredCore6
virtual_memory_flag: Pointer,
fn_get_event_flag: FnGetEventFlag,
set_event_flag_address: usize,
set_event_flag_hook: Option<HookPoint>,
}

impl ArmoredCore6
Expand All @@ -50,6 +52,7 @@ impl ArmoredCore6
virtual_memory_flag: Pointer::default(),
fn_get_event_flag: |_,_|{0},
set_event_flag_address: 0,
set_event_flag_hook: None,
}
}
}
Expand Down Expand Up @@ -86,13 +89,12 @@ impl Game for ArmoredCore6
let get_event_flag_address = self.process.scan_abs("get_event_flag", "44 8b 41 1c 44 8b da 33 d2 41 8b c3 41 f7 f0 4c 8b d1 45 33 c9 44 0f af c0", 0, Vec::new())?.get_base_address();
self.fn_get_event_flag = mem::transmute(get_event_flag_address);

let event_flags = Arc::clone(&self.event_flags);
STATIC_DETOUR_SET_EVENT_FLAG.initialize(mem::transmute(self.set_event_flag_address), move |rdx: u64, event_flag_id: u32, value: i32|
#[cfg(target_arch = "x86_64")]
{
let mut guard = event_flags.lock().unwrap();
guard.push(EventFlag::new(chrono::offset::Local::now(), event_flag_id, value == 1));
STATIC_DETOUR_SET_EVENT_FLAG.call(rdx, event_flag_id, value);
}).unwrap().enable().unwrap();
let h = Hooker::new(self.set_event_flag_address, HookType::JmpBack(set_event_flag_hook_fn), CallbackOption::None, 0, HookFlags::empty());
self.set_event_flag_hook = Some(h.hook().unwrap());
}


info!("event_flag_man base address: 0x{:x}", self.virtual_memory_flag.get_base_address());
info!("set event flag address : 0x{:x}", self.set_event_flag_address);
Expand All @@ -106,8 +108,14 @@ impl Game for ArmoredCore6
if byte == 0x48
{
info!("re-hook set event flag");
STATIC_DETOUR_SET_EVENT_FLAG.disable().unwrap();
STATIC_DETOUR_SET_EVENT_FLAG.enable().unwrap();
let hookpoint = self.set_event_flag_hook.take();
hookpoint.unwrap().unhook().unwrap();

#[cfg(target_arch = "x86_64")]
{
let h = Hooker::new(self.set_event_flag_address, HookType::JmpBack(set_event_flag_hook_fn), CallbackOption::None, 0, HookFlags::empty());
self.set_event_flag_hook = Some(h.hook().unwrap());
}
}

self.process.refresh()?;
Expand All @@ -127,3 +135,19 @@ impl Game for ArmoredCore6
}
fn as_any_mut(&mut self) -> &mut dyn Any { self }
}


unsafe extern "win64" fn set_event_flag_hook_fn(registers: *mut Registers, _:usize)
{
let instance = App::get_instance();
let app = instance.lock().unwrap();

if let Some(game) = GameExt::get_game_ref::<ArmoredCore6>(app.game.deref())
{
let event_flag_id = (*registers).rdx as u32;
let value = (*registers).r8 as u8;

let mut guard = game.event_flags.lock().unwrap();
guard.push(EventFlag::new(chrono::offset::Local::now(), event_flag_id, value != 0));
}
}

0 comments on commit e776b83

Please sign in to comment.