From 09e70869a6443d1ae76265a1ff488e0d583ae089 Mon Sep 17 00:00:00 2001 From: rkr35 Date: Sun, 28 Jun 2020 16:16:29 -0400 Subject: [PATCH] cargo fmt --- src/dump/mod.rs | 10 ++++++---- src/hook/bitfield.rs | 2 +- src/hook/mod.rs | 25 ++++++++++++++++++++----- src/lib.rs | 42 +++++++++++++++++++++++++++++------------- 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/dump/mod.rs b/src/dump/mod.rs index a0ae7be..d66cdd5 100644 --- a/src/dump/mod.rs +++ b/src/dump/mod.rs @@ -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> { @@ -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__") { diff --git a/src/hook/bitfield.rs b/src/hook/bitfield.rs index ac32627..a940b0f 100644 --- a/src/hook/bitfield.rs +++ b/src/hook/bitfield.rs @@ -11,4 +11,4 @@ pub fn set_bit(bitfield: &mut u32, bit: u8, value: bool) { } else { *bitfield &= !mask; } -} \ No newline at end of file +} diff --git a/src/hook/mod.rs b/src/hook/mod.rs index 96320ff..51c9fe8 100644 --- a/src/hook/mod.rs +++ b/src/hook/mod.rs @@ -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; @@ -31,7 +34,7 @@ macro_rules! det { } else { Err(Error::Detour(stringify!($call), error_code)) } - }} + }}; } pub struct Hook; @@ -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; @@ -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); -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index bee6f73..62cca66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -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; 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; 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; @@ -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(()) }