Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rkr35 committed Jun 28, 2020
1 parent 0552faa commit 09e7086
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
10 changes: 6 additions & 4 deletions src/dump/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ fn add_crate_attributes(scope: &mut Scope) {
}

fn add_imports(scope: &mut Scope) {
scope.raw("use crate::game::{Array, FString, NameIndex, ScriptDelegate, ScriptInterface};\n\
use crate::hook::bitfield::{is_bit_set, set_bit};\n\
use std::ops::{Deref, DerefMut};");
scope.raw(
"use crate::game::{Array, FString, NameIndex, ScriptDelegate, ScriptInterface};\n\
use crate::hook::bitfield::{is_bit_set, set_bit};\n\
use std::ops::{Deref, DerefMut};",
);
}

unsafe fn write_object(sdk: &mut Scope, object: *const Object) -> Result<(), Error> {
Expand Down Expand Up @@ -184,7 +186,7 @@ unsafe fn write_enumeration(sdk: &mut Scope, object: *const Object) -> Result<()
self.variants.iter().map(|n| n.name())
}
}

let name = helper::resolve_duplicate(object)?;

if name.starts_with("Default__") {
Expand Down
2 changes: 1 addition & 1 deletion src/hook/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ pub fn set_bit(bitfield: &mut u32, bit: u8, value: bool) {
} else {
*bitfield &= !mask;
}
}
}
25 changes: 20 additions & 5 deletions src/hook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::PROCESS_EVENT;
use std::ffi::c_void;
use std::mem;

use detours_sys::{DetourTransactionBegin, DetourUpdateThread, DetourAttach, DetourDetach, DetourTransactionCommit, LONG as DetourErrorCode};
use detours_sys::{
DetourAttach, DetourDetach, DetourTransactionBegin, DetourTransactionCommit,
DetourUpdateThread, LONG as DetourErrorCode,
};
use log::{error, info, warn};
use thiserror::Error;
use winapi::um::processthreadsapi::GetCurrentThread;
Expand All @@ -31,7 +34,7 @@ macro_rules! det {
} else {
Err(Error::Detour(stringify!($call), error_code))
}
}}
}};
}

pub struct Hook;
Expand Down Expand Up @@ -69,8 +72,20 @@ unsafe fn unhook_process_event() -> Result<(), Error> {
Ok(())
}

unsafe extern "fastcall" fn my_process_event(this: &game::Object, edx: usize, function: &game::Function, parameters: *mut c_void, return_value: *mut c_void) {
type ProcessEvent = unsafe extern "fastcall" fn (this: &game::Object, _edx: usize, function: &game::Function, parameters: *mut c_void, return_value: *mut c_void);
unsafe extern "fastcall" fn my_process_event(
this: &game::Object,
edx: usize,
function: &game::Function,
parameters: *mut c_void,
return_value: *mut c_void,
) {
type ProcessEvent = unsafe extern "fastcall" fn(
this: &game::Object,
_edx: usize,
function: &game::Function,
parameters: *mut c_void,
return_value: *mut c_void,
);

if let Some(full_name) = function.full_name() {
use std::collections::HashSet;
Expand All @@ -89,4 +104,4 @@ unsafe extern "fastcall" fn my_process_event(this: &game::Object, edx: usize, fu

let original = mem::transmute::<*mut c_void, ProcessEvent>(PROCESS_EVENT);
original(this, edx, function, parameters, return_value);
}
}
42 changes: 29 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ unsafe fn find_global_names(game: &Module) -> Result<*const Names, Error> {
None,
];

let global_names = game
.find_pattern(&PATTERN)
.ok_or(Error::NamesNotFound)?;
let global_names = game.find_pattern(&PATTERN).ok_or(Error::NamesNotFound)?;

let global_names = (global_names + 8) as *const *const Names;

Expand All @@ -115,20 +113,36 @@ unsafe fn find_global_objects(game: &Module) -> Result<*const Objects, Error> {
Some(0xB9),
];

let global_objects = game
.find_pattern(&PATTERN)
.ok_or(Error::ObjectsNotFound)?;
let global_objects = game.find_pattern(&PATTERN).ok_or(Error::ObjectsNotFound)?;

let global_objects = (global_objects + 2) as *const *const Objects;

Ok(global_objects.read_unaligned())
}

unsafe fn find_process_event(game: &Module) -> Result<*mut c_void, Error> {
const PATTERN: [Option<u8>; 15] = [Some(0x50), Some(0x51), Some(0x52), Some(0x8B), Some(0xCE), Some(0xE8), None, None, None, None, Some(0x5E), Some(0x5D), Some(0xC2), Some(0x0C), Some(0x00)];
const PATTERN: [Option<u8>; 15] = [
Some(0x50),
Some(0x51),
Some(0x52),
Some(0x8B),
Some(0xCE),
Some(0xE8),
None,
None,
None,
None,
Some(0x5E),
Some(0x5D),
Some(0xC2),
Some(0x0C),
Some(0x00),
];

// 1. Find the first address A that matches the above pattern.
let a = game.find_pattern(&PATTERN).ok_or(Error::ProcessEventNotFound)?;
let a = game
.find_pattern(&PATTERN)
.ok_or(Error::ProcessEventNotFound)?;

// 2. Offset A by six bytes to get the address of the CALL immediate. Call that address B.
let b = a + 6;
Expand Down Expand Up @@ -162,18 +176,20 @@ unsafe fn find_globals() -> Result<(), Error> {

unsafe fn run() -> Result<(), Error> {
find_globals()?;

#[cfg(feature = "dump")] {

#[cfg(feature = "dump")]
{
// dump::names()?;
// dump::objects()?;
dump::sdk()?;
}

#[cfg(feature = "hook")] {
#[cfg(feature = "hook")]
{
let _hook = hook::Hook::new()?;
idle();
}

Ok(())
}

Expand Down

0 comments on commit 09e7086

Please sign in to comment.