Skip to content

Commit

Permalink
Plugins: Add various FUObjectArray functions
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Mar 4, 2024
1 parent 0ffc799 commit 3d90c52
Show file tree
Hide file tree
Showing 11 changed files with 339 additions and 142 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ list(APPEND uevr_SOURCES
"src/mods/pluginloader/FFakeStereoRenderingFunctions.cpp"
"src/mods/pluginloader/FRHITexture2DFunctions.cpp"
"src/mods/pluginloader/FRenderTargetPoolHook.cpp"
"src/mods/pluginloader/FUObjectArrayFunctions.cpp"
"src/mods/uobjecthook/SDKDumper.cpp"
"src/mods/vr/Bindings.cpp"
"src/mods/vr/CVarManager.cpp"
Expand Down Expand Up @@ -713,6 +714,7 @@ list(APPEND uevr_SOURCES
"src/mods/pluginloader/FFakeStereoRenderingFunctions.hpp"
"src/mods/pluginloader/FRHITexture2DFunctions.hpp"
"src/mods/pluginloader/FRenderTargetPoolHook.hpp"
"src/mods/pluginloader/FUObjectArrayFunctions.hpp"
"src/mods/uobjecthook/SDKDumper.hpp"
"src/mods/vr/CVarManager.hpp"
"src/mods/vr/D3D11Component.hpp"
Expand Down
295 changes: 170 additions & 125 deletions examples/example_plugin/Plugin.cpp

Large diffs are not rendered by default.

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 15
#define UEVR_PLUGIN_VERSION_MINOR 16
#define UEVR_PLUGIN_VERSION_PATCH 0

#define UEVR_RENDERER_D3D11 0
Expand Down Expand Up @@ -257,8 +257,20 @@ typedef struct {
void (*command_execute)(UEVR_IConsoleCommandHandle cmd, const wchar_t* args);
} UEVR_ConsoleFunctions;

DECLARE_UEVR_HANDLE(UEVR_FUObjectItemHandle);

typedef struct {
UEVR_UObjectHandle (*find_uobject)(const wchar_t* name);

bool (*is_chunked)();
bool (*is_inlined)();
unsigned int (*get_objects_offset)();
unsigned int (*get_item_distance)();

int (*get_object_count)(UEVR_UObjectArrayHandle array);
void* (*get_objects_ptr)(UEVR_UObjectArrayHandle array);
UEVR_UObjectHandle (*get_object)(UEVR_UObjectArrayHandle array, int index);
UEVR_FUObjectItemHandle (*get_item)(UEVR_UObjectArrayHandle array, int index);
} UEVR_UObjectArrayFunctions;

typedef struct {
Expand Down
64 changes: 63 additions & 1 deletion include/uevr/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class API {
return s_functions;
}
};

struct UObject {
inline UEVR_UObjectHandle to_handle() { return (UEVR_UObjectHandle)this; }
inline UEVR_UObjectHandle to_handle() const { return (UEVR_UObjectHandle)this; }
Expand Down Expand Up @@ -694,9 +694,71 @@ class API {
};

struct FUObjectArray {
inline UEVR_UObjectArrayHandle to_handle() { return (UEVR_UObjectArrayHandle)this; }
inline UEVR_UObjectArrayHandle to_handle() const { return (UEVR_UObjectArrayHandle)this; }

static FUObjectArray* get() {
return API::get()->get_uobject_array();
}

static bool is_chunked() {
static const auto fn = initialize()->is_chunked;
return fn();
}

static bool is_inlined() {
static const auto fn = initialize()->is_inlined;
return fn();
}

static size_t get_objects_offset() {
static const auto fn = initialize()->get_objects_offset;
return (size_t)fn();
}

static size_t get_item_distance() {
static const auto fn = initialize()->get_item_distance;
return (size_t)fn();
}

int32_t get_object_count() const {
static const auto fn = initialize()->get_object_count;
return fn(to_handle());
}

void* get_objects_ptr() const {
static const auto fn = initialize()->get_objects_ptr;
return fn(to_handle());
}

UObject* get_object(int32_t index) const {
static const auto fn = initialize()->get_object;
return (UObject*)fn(to_handle(), index);
}

// Generally the same structure most of the time, not too much to worry about
// Not that this would generally be used raw - instead prefer get_object
struct FUObjectItem {
API::UObject* object;
int32_t flags;
int32_t cluster_index;
int32_t serial_number;
};

FUObjectItem* get_item(int32_t index) const {
static const auto fn = initialize()->get_item;
return (FUObjectItem*)fn(to_handle(), index);
}

private:
static inline const UEVR_UObjectArrayFunctions* s_functions{nullptr};
static inline const UEVR_UObjectArrayFunctions* initialize() {
if (s_functions == nullptr) {
s_functions = API::get()->sdk()->uobject_array;
}

return s_functions;
}
};

// One of the very few non-opaque structs
Expand Down
4 changes: 2 additions & 2 deletions src/CommitHash.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#define UEVR_COMMIT_HASH "3fe2879d17b4ea3cda92fb25b22e48ab95ffd47a"
#define UEVR_BUILD_DATE "03.03.2024"
#define UEVR_COMMIT_HASH "0ffc79987629f6bd09f564ec9fe61c1a77ef7efc"
#define UEVR_BUILD_DATE "04.03.2024"
#define UEVR_BUILD_TIME "00:00"
10 changes: 2 additions & 8 deletions src/mods/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "pluginloader/FFakeStereoRenderingFunctions.hpp"
#include "pluginloader/FRenderTargetPoolHook.hpp"
#include "pluginloader/FRHITexture2DFunctions.hpp"
#include "pluginloader/FUObjectArrayFunctions.hpp"

#include "UObjectHook.hpp"
#include "VR.hpp"
Expand Down Expand Up @@ -368,13 +369,6 @@ UEVR_UObjectFunctions g_uobject_functions {
},
};

UEVR_UObjectArrayFunctions g_uobject_array_functions {
// find_uobject
[](const wchar_t* name) {
return (UEVR_UObjectHandle)sdk::find_uobject(name);
},
};

#define FFIELD(x) ((sdk::FField*)x)

UEVR_FFieldFunctions g_ffield_functions {
Expand Down Expand Up @@ -769,7 +763,7 @@ UEVR_SDKData g_sdk_data {
&g_sdk_functions,
&g_sdk_callbacks,
&g_uobject_functions,
&g_uobject_array_functions,
&uevr::fuobjectarray::functions,
&g_ffield_functions,
&g_fproperty_functions,
&g_ustruct_functions,
Expand Down
4 changes: 2 additions & 2 deletions src/mods/pluginloader/FFakeStereoRenderingFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ UEVR_FRHITexture2DHandle stereo_hook::get_ui_render_target() {
}

UEVR_FFakeStereoRenderingHookFunctions stereo_hook::functions {
&stereo_hook::get_scene_render_target,
&stereo_hook::get_ui_render_target
.get_scene_render_target = &stereo_hook::get_scene_render_target,
.get_ui_render_target = &stereo_hook::get_ui_render_target
};
}
2 changes: 1 addition & 1 deletion src/mods/pluginloader/FRHITexture2DFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void* get_native_resource(UEVR_FRHITexture2DHandle handle) {
}

UEVR_FRHITexture2DFunctions functions {
&uevr::frhitexture2d::get_native_resource
.get_native_resource = &uevr::frhitexture2d::get_native_resource
};
}
}
4 changes: 2 additions & 2 deletions src/mods/pluginloader/FRenderTargetPoolHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ UEVR_IPooledRenderTargetHandle render_target_pool_hook::get_render_target(const
}

UEVR_FRenderTargetPoolHookFunctions render_target_pool_hook::functions {
&render_target_pool_hook::activate,
&render_target_pool_hook::get_render_target
.activate = &render_target_pool_hook::activate,
.get_render_target = &render_target_pool_hook::get_render_target
};
}
63 changes: 63 additions & 0 deletions src/mods/pluginloader/FUObjectArrayFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <sdk/UObjectArray.hpp>

#include "FUObjectArrayFunctions.hpp"


namespace uevr {
namespace fuobjectarray {
UEVR_UObjectHandle find_uobject(const wchar_t* name) {
return (UEVR_UObjectHandle)sdk::find_uobject(name);
}

bool is_chunked() {
return sdk::FUObjectArray::is_chunked();
}

bool is_inlined() {
return sdk::FUObjectArray::is_inlined();
}

unsigned int get_objects_offset() {
return sdk::FUObjectArray::get_objects_offset();
}

unsigned int get_item_distance() {
return sdk::FUObjectArray::get_item_distance();
}

int get_object_count(UEVR_UObjectArrayHandle array) {
return ((sdk::FUObjectArray*)array)->get_object_count();
}

void* get_objects_ptr(UEVR_UObjectArrayHandle array) {
return ((sdk::FUObjectArray*)array)->get_objects_ptr();
}

UEVR_UObjectHandle get_object(UEVR_UObjectArrayHandle array, int index) {
auto item = ((sdk::FUObjectArray*)array)->get_object(index);

if (item == nullptr) {
return nullptr;
}

return (UEVR_UObjectHandle)item->object;
}

// messed up naming, I know
UEVR_FUObjectItemHandle get_item(UEVR_UObjectArrayHandle array, int index) {
return (UEVR_FUObjectItemHandle)((sdk::FUObjectArray*)array)->get_object(index);
}

UEVR_UObjectArrayFunctions functions {
.find_uobject = uevr::fuobjectarray::find_uobject,
.is_chunked = uevr::fuobjectarray::is_chunked,
.is_inlined = uevr::fuobjectarray::is_inlined,
.get_objects_offset = uevr::fuobjectarray::get_objects_offset,
.get_item_distance = uevr::fuobjectarray::get_item_distance,
.get_object_count = uevr::fuobjectarray::get_object_count,
.get_objects_ptr = uevr::fuobjectarray::get_objects_ptr,
.get_object = uevr::fuobjectarray::get_object,
.get_item = uevr::fuobjectarray::get_item
};
}
}
19 changes: 19 additions & 0 deletions src/mods/pluginloader/FUObjectArrayFunctions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "uevr/API.h"

namespace uevr {
namespace fuobjectarray {
UEVR_UObjectHandle find_uobject(const wchar_t* name);
bool is_chunked();
bool is_inlined();
unsigned int get_objects_offset();
unsigned int get_item_distance();
int get_object_count(UEVR_UObjectArrayHandle array);
void* get_objects_ptr(UEVR_UObjectArrayHandle array);
UEVR_UObjectHandle get_object(UEVR_UObjectArrayHandle array, int index);
UEVR_FUObjectItemHandle get_item(UEVR_UObjectArrayHandle array, int index);

extern UEVR_UObjectArrayFunctions functions;
}
}

0 comments on commit 3d90c52

Please sign in to comment.