Skip to content

Commit

Permalink
Plugins: Add UScriptStruct and get/set_bool_property
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Mar 6, 2024
1 parent 3d90c52 commit 10c453f
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
14 changes: 13 additions & 1 deletion include/uevr/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
39 changes: 39 additions & 0 deletions include/uevr/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class API {
struct UStruct;
struct UClass;
struct UFunction;
struct UScriptStruct;
struct UStructOps;
struct FField;
struct FProperty;
struct FFieldClass;
Expand Down Expand Up @@ -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<UClass>(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; }
Expand Down
12 changes: 11 additions & 1 deletion src/mods/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions src/mods/pluginloader/UScriptStructFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <sdk/UClass.hpp>

#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
};
}
}
12 changes: 12 additions & 0 deletions src/mods/pluginloader/UScriptStructFunctions.hpp
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 10c453f

Please sign in to comment.