Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit e50f9f5

Browse files
committedAug 23, 2021
Print UFunction calls through ProcessEvent
1 parent 419fb44 commit e50f9f5

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed
 

‎Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎common/src/object.rs

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ pub struct UFunction {
350350
FirstPropertyToInit: *const c_void,
351351
EventGraphFunction: *const UFunction,
352352
EventGraphCallOffset: i32,
353+
pub seen_count: u32,
353354
Func: FNativeFuncPtr,
354355
}
355356

‎hook/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ crate-type = ["cdylib"]
88

99
[dependencies]
1010
common = { path = "../common" }
11-
macros = { path = "../macros" }
11+
macros = { path = "../macros" }
12+
sdk = { path = "../sdk" }

‎hook/src/lib.rs

+36-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ extern "C" {}
1010
#[link(name = "vcruntime")]
1111
extern "C" {}
1212

13-
use common::{self, win, UFunction, UObject};
13+
use common::{self, win, EClassCastFlags, List, UFunction, UObject};
1414
use core::ffi::c_void;
1515
use core::mem::{self, ManuallyDrop};
1616
use core::slice;
17+
use sdk::Engine::Actor;
1718

1819
#[derive(macros::NoPanicErrorDebug)]
1920
enum Error {
@@ -224,20 +225,47 @@ unsafe fn run() -> Result<(), Error> {
224225

225226
common::idle();
226227

228+
for &function in RESET_THESE_SEEN_COUNTS.iter() {
229+
(*function).seen_count = 0;
230+
}
231+
227232
Ok(())
228233
}
229234

230235
unsafe fn on_detach() {}
231236

237+
static mut RESET_THESE_SEEN_COUNTS: List<*mut UFunction, 4096> = List::new();
238+
232239
unsafe extern "C" fn my_process_event(
233240
object: *mut UObject,
234241
function: *mut UFunction,
235-
parameters: *mut c_void,
242+
_parameters: *mut c_void,
236243
) {
237-
common::log!(
238-
"my_process_event({}, {}, {})",
239-
*object,
240-
*function,
241-
parameters as usize
242-
);
244+
const MAX_PRINTS: u32 = 1;
245+
246+
let seen_count = (*function).seen_count;
247+
248+
if seen_count == 0 && RESET_THESE_SEEN_COUNTS.push(function).is_err() {
249+
common::log!("Warning: RESET_THESE_SEEN_COUNTS reached its max capacity of {}. We won't print any more unseen UFunctions.", RESET_THESE_SEEN_COUNTS.capacity());
250+
return;
251+
}
252+
253+
if seen_count < MAX_PRINTS {
254+
(*function).seen_count += 1;
255+
256+
let is_actor = (*object).fast_is(EClassCastFlags::CASTCLASS_AActor);
257+
258+
common::log!("{}{}\n\t{}", if is_actor { "\n" } else { "" }, (*object).name(), *function);
259+
260+
if is_actor {
261+
let mut owner = (*object.cast::<Actor>()).Owner;
262+
263+
while !owner.is_null() {
264+
common::log!("owned by\n\t{}", (*owner.cast::<UObject>()).name());
265+
owner = (*owner).Owner;
266+
}
267+
268+
common::log!();
269+
}
270+
}
243271
}

0 commit comments

Comments
 (0)
This repository has been archived.