From 10c453f9186d664246ed252bc667560ddeec039d Mon Sep 17 00:00:00 2001 From: praydog Date: Wed, 6 Mar 2024 13:14:31 -0800 Subject: [PATCH] Plugins: Add UScriptStruct and get/set_bool_property --- CMakeLists.txt | 2 + include/uevr/API.h | 14 ++++++- include/uevr/API.hpp | 39 +++++++++++++++++++ src/mods/PluginLoader.cpp | 12 +++++- .../pluginloader/UScriptStructFunctions.cpp | 20 ++++++++++ .../pluginloader/UScriptStructFunctions.hpp | 12 ++++++ 6 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/mods/pluginloader/UScriptStructFunctions.cpp create mode 100644 src/mods/pluginloader/UScriptStructFunctions.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e0df61f..4be5fae9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -676,6 +676,7 @@ list(APPEND uevr_SOURCES "src/mods/pluginloader/FRHITexture2DFunctions.cpp" "src/mods/pluginloader/FRenderTargetPoolHook.cpp" "src/mods/pluginloader/FUObjectArrayFunctions.cpp" + "src/mods/pluginloader/UScriptStructFunctions.cpp" "src/mods/uobjecthook/SDKDumper.cpp" "src/mods/vr/Bindings.cpp" "src/mods/vr/CVarManager.cpp" @@ -715,6 +716,7 @@ list(APPEND uevr_SOURCES "src/mods/pluginloader/FRHITexture2DFunctions.hpp" "src/mods/pluginloader/FRenderTargetPoolHook.hpp" "src/mods/pluginloader/FUObjectArrayFunctions.hpp" + "src/mods/pluginloader/UScriptStructFunctions.hpp" "src/mods/uobjecthook/SDKDumper.hpp" "src/mods/vr/CVarManager.hpp" "src/mods/vr/D3D11Component.hpp" diff --git a/include/uevr/API.h b/include/uevr/API.h index 440c80e9..82b59332 100644 --- a/include/uevr/API.h +++ b/include/uevr/API.h @@ -36,7 +36,7 @@ SOFTWARE. #define UEVR_OUT #define UEVR_PLUGIN_VERSION_MAJOR 2 -#define UEVR_PLUGIN_VERSION_MINOR 16 +#define UEVR_PLUGIN_VERSION_MINOR 17 #define UEVR_PLUGIN_VERSION_PATCH 0 #define UEVR_RENDERER_D3D11 0 @@ -75,6 +75,7 @@ DECLARE_UEVR_HANDLE(UEVR_IConsoleVariableHandle); DECLARE_UEVR_HANDLE(UEVR_TArrayHandle); DECLARE_UEVR_HANDLE(UEVR_FMallocHandle); DECLARE_UEVR_HANDLE(UEVR_FRHITexture2DHandle); +DECLARE_UEVR_HANDLE(UEVR_UScriptStructHandle); /* OpenXR stuff */ DECLARE_UEVR_HANDLE(UEVR_XrInstance); @@ -309,6 +310,9 @@ typedef struct { void (*call_function)(UEVR_UObjectHandle object, const wchar_t* name, void* params); UEVR_FNameHandle (*get_fname)(UEVR_UObjectHandle object); + + bool (*get_bool_property)(UEVR_UObjectHandle object, const wchar_t* name); + void (*set_bool_property)(UEVR_UObjectHandle object, const wchar_t* name, bool value); } UEVR_UObjectFunctions; DECLARE_UEVR_HANDLE(UEVR_UObjectHookMotionControllerStateHandle); @@ -371,6 +375,13 @@ typedef struct { void* (*get_native_resource)(UEVR_FRHITexture2DHandle texture); } UEVR_FRHITexture2DFunctions; +DECLARE_UEVR_HANDLE(UEVR_StructOpsHandle); + +typedef struct { + UEVR_StructOpsHandle (*get_struct_ops)(UEVR_UScriptStructHandle script_struct); + int (*get_struct_size)(UEVR_UScriptStructHandle script_struct); +} UEVR_UScriptStructFunctions; + typedef struct { const UEVR_SDKFunctions* functions; const UEVR_SDKCallbacks* callbacks; @@ -389,6 +400,7 @@ typedef struct { const UEVR_FRenderTargetPoolHookFunctions* render_target_pool_hook; const UEVR_FFakeStereoRenderingHookFunctions* stereo_hook; const UEVR_FRHITexture2DFunctions* frhitexture2d; + const UEVR_UScriptStructFunctions* uscriptstruct; } UEVR_SDKData; DECLARE_UEVR_HANDLE(UEVR_IVRSystem); diff --git a/include/uevr/API.hpp b/include/uevr/API.hpp index f11b4868..a138a27e 100644 --- a/include/uevr/API.hpp +++ b/include/uevr/API.hpp @@ -118,6 +118,8 @@ class API { struct UStruct; struct UClass; struct UFunction; + struct UScriptStruct; + struct UStructOps; struct FField; struct FProperty; struct FFieldClass; @@ -477,6 +479,43 @@ class API { } }; + struct UScriptStruct : public UStruct { + inline UEVR_UScriptStructHandle to_handle() { return (UEVR_UScriptStructHandle)this; } + inline UEVR_UScriptStructHandle to_handle() const { return (UEVR_UScriptStructHandle)this; } + + static UClass* static_class() { + static auto result = API::get()->find_uobject(L"Class /Script/CoreUObject.ScriptStruct"); + return result; + } + + struct StructOps { + virtual ~StructOps() {}; + + int32_t size; + int32_t alignment; + }; + + StructOps* get_struct_ops() const { + static const auto fn = initialize()->get_struct_ops; + return (StructOps*)fn(to_handle()); + } + + int32_t get_struct_size() const { + static const auto fn = initialize()->get_struct_size; + return fn(to_handle()); + } + + private: + static inline const UEVR_UScriptStructFunctions* s_functions{nullptr}; + inline static const UEVR_UScriptStructFunctions* initialize() { + if (s_functions == nullptr) { + s_functions = API::get()->sdk()->uscriptstruct; + } + + return s_functions; + } + }; + // Wrapper class for UField AND FField struct FField { inline UEVR_FFieldHandle to_handle() { return (UEVR_FFieldHandle)this; } diff --git a/src/mods/PluginLoader.cpp b/src/mods/PluginLoader.cpp index 202af65d..742c31a9 100644 --- a/src/mods/PluginLoader.cpp +++ b/src/mods/PluginLoader.cpp @@ -26,6 +26,7 @@ #include "pluginloader/FRenderTargetPoolHook.hpp" #include "pluginloader/FRHITexture2DFunctions.hpp" #include "pluginloader/FUObjectArrayFunctions.hpp" +#include "pluginloader/UScriptStructFunctions.hpp" #include "UObjectHook.hpp" #include "VR.hpp" @@ -367,6 +368,14 @@ UEVR_UObjectFunctions g_uobject_functions { [](UEVR_UObjectHandle obj) { return (UEVR_FNameHandle)&UOBJECT(obj)->get_fname(); }, + // get_bool_property + [](UEVR_UObjectHandle obj, const wchar_t* name) { + return UOBJECT(obj)->get_bool_property(name); + }, + // set_bool_property + [](UEVR_UObjectHandle obj, const wchar_t* name, bool value) { + UOBJECT(obj)->set_bool_property(name, value); + }, }; #define FFIELD(x) ((sdk::FField*)x) @@ -776,7 +785,8 @@ UEVR_SDKData g_sdk_data { &g_malloc_functions, &uevr::render_target_pool_hook::functions, &uevr::stereo_hook::functions, - &uevr::frhitexture2d::functions + &uevr::frhitexture2d::functions, + &uevr::uscriptstruct::functions }; namespace uevr { diff --git a/src/mods/pluginloader/UScriptStructFunctions.cpp b/src/mods/pluginloader/UScriptStructFunctions.cpp new file mode 100644 index 00000000..6a3d42ff --- /dev/null +++ b/src/mods/pluginloader/UScriptStructFunctions.cpp @@ -0,0 +1,20 @@ +#include + +#include "UScriptStructFunctions.hpp" + +namespace uevr { +namespace uscriptstruct { +UEVR_StructOpsHandle get_struct_ops(UEVR_UScriptStructHandle script_struct) { + return (UEVR_StructOpsHandle)((sdk::UScriptStruct*)script_struct)->get_struct_ops(); +} + +int get_struct_size(UEVR_UScriptStructHandle script_struct) { + return ((sdk::UScriptStruct*)script_struct)->get_struct_size(); +} + +UEVR_UScriptStructFunctions functions { + .get_struct_ops = get_struct_ops, + .get_struct_size = get_struct_size +}; +} +} \ No newline at end of file diff --git a/src/mods/pluginloader/UScriptStructFunctions.hpp b/src/mods/pluginloader/UScriptStructFunctions.hpp new file mode 100644 index 00000000..31f9824e --- /dev/null +++ b/src/mods/pluginloader/UScriptStructFunctions.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "uevr/API.h" + +namespace uevr { +namespace uscriptstruct { +UEVR_StructOpsHandle get_struct_ops(UEVR_UScriptStructHandle script_struct); +int get_struct_size(UEVR_UScriptStructHandle script_struct); + +extern UEVR_UScriptStructFunctions functions; +} +} \ No newline at end of file