Skip to content

Commit

Permalink
WIP reflection data stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed Oct 12, 2024
1 parent 4641eb0 commit 9a26ab9
Showing 1 changed file with 144 additions and 0 deletions.
144 changes: 144 additions & 0 deletions hook/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,83 @@ use crate::{

retour::static_detour! {
static HookUFunctionBind: unsafe extern "system" fn(*mut ue::UFunction);
static HookUClassBind: unsafe extern "system" fn(*mut *mut ue::UClass, *const UE4CodeGen_Private_FClassParams);
static SaveGameToSlot: unsafe extern "system" fn(*const USaveGame, *const ue::FString, i32) -> bool;
static LoadGameFromSlot: unsafe extern "system" fn(*const ue::FString, i32) -> *const USaveGame;
static DoesSaveGameExist: unsafe extern "system" fn(*const ue::FString, i32) -> bool;
static UObjectTemperatureComponentTimerCallback: unsafe extern "system" fn(*mut c_void);
static WinMain: unsafe extern "system" fn(*mut (), *mut (), *mut (), i32, *const ()) -> i32;

}
#[derive(Debug, Clone)]
#[repr(C)]
struct UE4CodeGen_Private_FClassParams {
/* offset 0x000 */
ClassNoRegisterFunc: unsafe extern "system" fn() -> *const ue::UClass,

Check failure on line 40 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `ClassNoRegisterFunc` should have a snake case name

error: structure field `ClassNoRegisterFunc` should have a snake case name --> hook/src/hooks/mod.rs:40:5 | 40 | ClassNoRegisterFunc: unsafe extern "system" fn() -> *const ue::UClass, | ^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `class_no_register_func` | = note: `-D non-snake-case` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(non_snake_case)]`
/* offset 0x008 */ ClassConfigNameUTF8: *const (),

Check failure on line 41 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `ClassConfigNameUTF8` should have a snake case name

error: structure field `ClassConfigNameUTF8` should have a snake case name --> hook/src/hooks/mod.rs:41:24 | 41 | /* offset 0x008 */ ClassConfigNameUTF8: *const (), | ^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `class_config_name_utf8`
/* offset 0x010 */ CppClassInfo: *const (),

Check failure on line 42 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `CppClassInfo` should have a snake case name

error: structure field `CppClassInfo` should have a snake case name --> hook/src/hooks/mod.rs:42:24 | 42 | /* offset 0x010 */ CppClassInfo: *const (), | ^^^^^^^^^^^^ help: convert the identifier to snake case: `cpp_class_info`
/* offset 0x018 */ DependencySingletonFuncArray: *const (),

Check failure on line 43 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `DependencySingletonFuncArray` should have a snake case name

error: structure field `DependencySingletonFuncArray` should have a snake case name --> hook/src/hooks/mod.rs:43:24 | 43 | /* offset 0x018 */ DependencySingletonFuncArray: *const (), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `dependency_singleton_func_array`
/* offset 0x020 */ FunctionLinkArray: *const (),

Check failure on line 44 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `FunctionLinkArray` should have a snake case name

error: structure field `FunctionLinkArray` should have a snake case name --> hook/src/hooks/mod.rs:44:24 | 44 | /* offset 0x020 */ FunctionLinkArray: *const (), | ^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `function_link_array`
/* offset 0x028 */
PropertyArray: *const *const UE4CodeGen_Private_FPropertyParamsBase,

Check failure on line 46 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `PropertyArray` should have a snake case name

error: structure field `PropertyArray` should have a snake case name --> hook/src/hooks/mod.rs:46:5 | 46 | PropertyArray: *const *const UE4CodeGen_Private_FPropertyParamsBase, | ^^^^^^^^^^^^^ help: convert the identifier to snake case: `property_array`
/* offset 0x030 */ ImplementedInterfaceArray: *const (),

Check failure on line 47 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `ImplementedInterfaceArray` should have a snake case name

error: structure field `ImplementedInterfaceArray` should have a snake case name --> hook/src/hooks/mod.rs:47:24 | 47 | /* offset 0x030 */ ImplementedInterfaceArray: *const (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `implemented_interface_array`
/* offset 0x038 */ NumDependencySingletons: i32,

Check failure on line 48 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `NumDependencySingletons` should have a snake case name

error: structure field `NumDependencySingletons` should have a snake case name --> hook/src/hooks/mod.rs:48:24 | 48 | /* offset 0x038 */ NumDependencySingletons: i32, | ^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `num_dependency_singletons`
/* offset 0x03c */ NumFunctions: i32,

Check failure on line 49 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `NumFunctions` should have a snake case name

error: structure field `NumFunctions` should have a snake case name --> hook/src/hooks/mod.rs:49:24 | 49 | /* offset 0x03c */ NumFunctions: i32, | ^^^^^^^^^^^^ help: convert the identifier to snake case: `num_functions`
/* offset 0x040 */ NumProperties: i32,

Check failure on line 50 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `NumProperties` should have a snake case name

error: structure field `NumProperties` should have a snake case name --> hook/src/hooks/mod.rs:50:24 | 50 | /* offset 0x040 */ NumProperties: i32, | ^^^^^^^^^^^^^ help: convert the identifier to snake case: `num_properties`
/* offset 0x044 */ NumImplementedInterfaces: i32,

Check failure on line 51 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `NumImplementedInterfaces` should have a snake case name

error: structure field `NumImplementedInterfaces` should have a snake case name --> hook/src/hooks/mod.rs:51:24 | 51 | /* offset 0x044 */ NumImplementedInterfaces: i32, | ^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `num_implemented_interfaces`
/* offset 0x048 */ ClassFlags: u32,

Check failure on line 52 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `ClassFlags` should have a snake case name

error: structure field `ClassFlags` should have a snake case name --> hook/src/hooks/mod.rs:52:24 | 52 | /* offset 0x048 */ ClassFlags: u32, | ^^^^^^^^^^ help: convert the identifier to snake case: `class_flags`
}

#[derive(Debug, Clone)]
#[repr(C)]
struct UE4CodeGen_Private_FPropertyParamsBase {
/* offset 0x000 */ NameUTF8: *const char,

Check failure on line 58 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `NameUTF8` should have a snake case name

error: structure field `NameUTF8` should have a snake case name --> hook/src/hooks/mod.rs:58:24 | 58 | /* offset 0x000 */ NameUTF8: *const char, | ^^^^^^^^ help: convert the identifier to snake case: `name_utf8`
/* offset 0x008 */ RepNotifyFuncUTF8: *const char,

Check failure on line 59 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `RepNotifyFuncUTF8` should have a snake case name

error: structure field `RepNotifyFuncUTF8` should have a snake case name --> hook/src/hooks/mod.rs:59:24 | 59 | /* offset 0x008 */ RepNotifyFuncUTF8: *const char, | ^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `rep_notify_func_utf8`
/* offset 0x010 */ PropertyFlags: ue::EPropertyFlags,

Check failure on line 60 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `PropertyFlags` should have a snake case name

error: structure field `PropertyFlags` should have a snake case name --> hook/src/hooks/mod.rs:60:24 | 60 | /* offset 0x010 */ PropertyFlags: ue::EPropertyFlags, | ^^^^^^^^^^^^^ help: convert the identifier to snake case: `property_flags`
/* offset 0x018 */ Flags: UE4CodeGen_Private_EPropertyGenFlags,

Check failure on line 61 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `Flags` should have a snake case name

error: structure field `Flags` should have a snake case name --> hook/src/hooks/mod.rs:61:24 | 61 | /* offset 0x018 */ Flags: UE4CodeGen_Private_EPropertyGenFlags, | ^^^^^ help: convert the identifier to snake case (notice the capitalization): `flags`
/* offset 0x01c */ ObjectFlags: ue::EObjectFlags,

Check failure on line 62 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `ObjectFlags` should have a snake case name

error: structure field `ObjectFlags` should have a snake case name --> hook/src/hooks/mod.rs:62:24 | 62 | /* offset 0x01c */ ObjectFlags: ue::EObjectFlags, | ^^^^^^^^^^^ help: convert the identifier to snake case: `object_flags`
/* offset 0x020 */ ArrayDim: i32,

Check failure on line 63 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `ArrayDim` should have a snake case name

error: structure field `ArrayDim` should have a snake case name --> hook/src/hooks/mod.rs:63:24 | 63 | /* offset 0x020 */ ArrayDim: i32, | ^^^^^^^^ help: convert the identifier to snake case: `array_dim`
/* offset 0x024 */
Offset: i32, // TODO actually UE4CodeGen_Private::FGenericPropertyParams

Check failure on line 65 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

structure field `Offset` should have a snake case name

error: structure field `Offset` should have a snake case name --> hook/src/hooks/mod.rs:65:5 | 65 | Offset: i32, // TODO actually UE4CodeGen_Private::FGenericPropertyParams | ^^^^^^ help: convert the identifier to snake case (notice the capitalization): `offset`
}

#[derive(Debug, Clone)]
#[repr(u32)]
enum UE4CodeGen_Private_EPropertyGenFlags {

Check failure on line 70 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

type `UE4CodeGen_Private_EPropertyGenFlags` should have an upper camel case name

error: type `UE4CodeGen_Private_EPropertyGenFlags` should have an upper camel case name --> hook/src/hooks/mod.rs:70:6 | 70 | enum UE4CodeGen_Private_EPropertyGenFlags { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to upper camel case: `Ue4codeGenPrivateEpropertyGenFlags` | = note: `-D non-camel-case-types` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(non_camel_case_types)]`
Byte = 0x0,

Check failure on line 71 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

multiple variants are never constructed

error: multiple variants are never constructed --> hook/src/hooks/mod.rs:71:5 | 70 | enum UE4CodeGen_Private_EPropertyGenFlags { | ------------------------------------ variants in this enum 71 | Byte = 0x0, | ^^^^ 72 | Int8 = 0x1, | ^^^^ 73 | Int16 = 0x2, | ^^^^^ 74 | Int = 0x3, | ^^^ 75 | Int64 = 0x4, | ^^^^^ 76 | UInt16 = 0x5, | ^^^^^^ 77 | UInt32 = 0x6, | ^^^^^^ 78 | UInt64 = 0x7, | ^^^^^^ 79 | UnsizedInt = 0x8, | ^^^^^^^^^^ 80 | UnsizedUInt = 0x9, | ^^^^^^^^^^^ 81 | Float = 0xa, 82 | Double = 0xb, | ^^^^^^ 83 | Bool = 0xc, | ^^^^ 84 | SoftClass = 0xd, | ^^^^^^^^^ 85 | WeakObject = 0xe, | ^^^^^^^^^^ 86 | LazyObject = 0xf, | ^^^^^^^^^^ 87 | SoftObject = 0x10, | ^^^^^^^^^^ 88 | Class = 0x11, | ^^^^^ 89 | Object = 0x12, | ^^^^^^ 90 | Interface = 0x13, | ^^^^^^^^^ 91 | Name = 0x14, | ^^^^ 92 | Str = 0x15, | ^^^ 93 | Array = 0x16, | ^^^^^ 94 | Map = 0x17, | ^^^ 95 | Set = 0x18, | ^^^ 96 | Struct = 0x19, | ^^^^^^ 97 | Delegate = 0x1a, | ^^^^^^^^ 98 | InlineMulticastDelegate = 0x1b, | ^^^^^^^^^^^^^^^^^^^^^^^ 99 | SparseMulticastDelegate = 0x1c, | ^^^^^^^^^^^^^^^^^^^^^^^ 100 | Text = 0x1d, | ^^^^ 101 | Enum = 0x1e, | ^^^^ 102 | FieldPath = 0x1f, | ^^^^^^^^^ 103 | NativeBool = 0x20, | ^^^^^^^^^^ | = note: `UE4CodeGen_Private_EPropertyGenFlags` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]`
Int8 = 0x1,
Int16 = 0x2,
Int = 0x3,
Int64 = 0x4,
UInt16 = 0x5,
UInt32 = 0x6,
UInt64 = 0x7,
UnsizedInt = 0x8,
UnsizedUInt = 0x9,
Float = 0xa,
Double = 0xb,
Bool = 0xc,
SoftClass = 0xd,
WeakObject = 0xe,
LazyObject = 0xf,
SoftObject = 0x10,
Class = 0x11,
Object = 0x12,
Interface = 0x13,
Name = 0x14,
Str = 0x15,
Array = 0x16,
Map = 0x17,
Set = 0x18,
Struct = 0x19,
Delegate = 0x1a,
InlineMulticastDelegate = 0x1b,
SparseMulticastDelegate = 0x1c,
Text = 0x1d,
Enum = 0x1e,
FieldPath = 0x1f,
NativeBool = 0x20,
}

#[repr(C)]
pub struct USaveGame;
Expand Down Expand Up @@ -88,6 +158,80 @@ pub unsafe fn initialize() -> Result<()> {
)?;
HookUFunctionBind.enable()?;

HookUClassBind.initialize(
std::mem::transmute(0x141d63510usize),
move |class, params| {
let p = &*params;
let static_class = &*(p.ClassNoRegisterFunc)();
let path = static_class
.ustruct
.ufield
.uobject
.uobject_base_utility
.uobject_base
.get_path_name(None);

if path == "/Script/FSD.EnemyWaveManager" {
tracing::info!("{static_class:p}");
let mut params = (*params).clone();
let mut new_props =
std::slice::from_raw_parts(params.PropertyArray, params.NumProperties as usize)
.to_vec();

let ex_prop = [
UE4CodeGen_Private_FPropertyParamsBase {
NameUTF8: "InjectedReflectionProp\0".as_ptr() as *const char,

Check failure on line 183 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

manually constructing a nul-terminated string

error: manually constructing a nul-terminated string --> hook/src/hooks/mod.rs:183:35 | 183 | NameUTF8: "InjectedReflectionProp\0".as_ptr() as *const char, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"InjectedReflectionProp"` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals = note: `-D clippy::manual-c-str-literals` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::manual_c_str_literals)]`
RepNotifyFuncUTF8: std::ptr::null(),
PropertyFlags: ue::EPropertyFlags::CPF_Edit
| ue::EPropertyFlags::CPF_BlueprintVisible
| ue::EPropertyFlags::CPF_BlueprintReadOnly
| ue::EPropertyFlags::CPF_Protected
| ue::EPropertyFlags::CPF_NativeAccessSpecifierProtected,
Flags: UE4CodeGen_Private_EPropertyGenFlags::Float,
ObjectFlags: ue::EObjectFlags::RF_Public
| ue::EObjectFlags::RF_MarkAsNative
| ue::EObjectFlags::RF_Transient,
ArrayDim: 1,
Offset: 0x134,
},
UE4CodeGen_Private_FPropertyParamsBase {
NameUTF8: "InjectedReflectionProp2\0".as_ptr() as *const char,

Check failure on line 198 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

manually constructing a nul-terminated string

error: manually constructing a nul-terminated string --> hook/src/hooks/mod.rs:198:35 | 198 | NameUTF8: "InjectedReflectionProp2\0".as_ptr() as *const char, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"InjectedReflectionProp2"` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals
RepNotifyFuncUTF8: std::ptr::null(),
PropertyFlags: ue::EPropertyFlags::CPF_Edit
| ue::EPropertyFlags::CPF_BlueprintVisible
| ue::EPropertyFlags::CPF_BlueprintReadOnly
| ue::EPropertyFlags::CPF_Protected
| ue::EPropertyFlags::CPF_NativeAccessSpecifierProtected,
Flags: UE4CodeGen_Private_EPropertyGenFlags::Float,
ObjectFlags: ue::EObjectFlags::RF_Public
| ue::EObjectFlags::RF_MarkAsNative
| ue::EObjectFlags::RF_Transient,
ArrayDim: 1,
Offset: 0x138,
},
];

new_props.extend(ex_prop.iter().map(|p| std::ptr::from_ref(p)));

Check failure on line 214 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant closure

error: redundant closure --> hook/src/hooks/mod.rs:214:53 | 214 | new_props.extend(ex_prop.iter().map(|p| std::ptr::from_ref(p))); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `std::ptr::from_ref` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure = note: `-D clippy::redundant-closure` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]`

//new_props.sort_by_key(|p| (**p).Offset);

params.PropertyArray = new_props.as_ptr();
params.NumProperties = new_props.len() as i32;
HookUClassBind.call(class, &params);
} else {
HookUClassBind.call(class, params);
}

if path == "/Script/FSD.EnemyWaveManager" {
tracing::info!("UClass::Bind({:?})", path);
for (struct_, prop) in (&**class).ustruct.properties() {

Check failure on line 227 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression borrows a value the compiler would automatically borrow

error: this expression borrows a value the compiler would automatically borrow --> hook/src/hooks/mod.rs:227:40 | 227 | for (struct_, prop) in (&**class).ustruct.properties() { | ^^^^^^^^^^ help: change this to: `(**class)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Check failure on line 227 in hook/src/hooks/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `struct_`

error: unused variable: `struct_` --> hook/src/hooks/mod.rs:227:22 | 227 | for (struct_, prop) in (&**class).ustruct.properties() { | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_struct_`
tracing::info!("prop {:?}", prop.ffield.name_private.to_string())
}
}
},
)?;
HookUClassBind.enable()?;

server_list::init_hooks()?;

if !globals().meta.config.disable_fix_exploding_gas {
Expand Down

0 comments on commit 9a26ab9

Please sign in to comment.