Skip to content

Commit

Permalink
Add WIP SDK generator
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Dec 23, 2023
1 parent 433c8f5 commit 4085037
Show file tree
Hide file tree
Showing 8 changed files with 640 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ FetchContent_Declare(safetyhook
)
FetchContent_MakeAvailable(safetyhook)

message(STATUS "Fetching sdkgenny (f58077f8da8a271490c17558e93b75843b3afd19)...")
FetchContent_Declare(sdkgenny
GIT_REPOSITORY
"https://github.com/cursey/sdkgenny"
GIT_TAG
f58077f8da8a271490c17558e93b75843b3afd19
)
FetchContent_MakeAvailable(sdkgenny)

message(STATUS "Fetching openxr (458984d7f59d1ae6dc1b597d94b02e4f7132eaba)...")
FetchContent_Declare(openxr
GIT_REPOSITORY
Expand Down Expand Up @@ -790,6 +799,7 @@ list(APPEND ue4poc_SOURCES
"src/mods/PluginLoader.cpp"
"src/mods/UObjectHook.cpp"
"src/mods/VR.cpp"
"src/mods/uobjecthook/SDKDumper.cpp"
"src/mods/vr/Bindings.cpp"
"src/mods/vr/CVarManager.cpp"
"src/mods/vr/D3D11Component.cpp"
Expand Down Expand Up @@ -822,6 +832,7 @@ list(APPEND ue4poc_SOURCES
"src/mods/PluginLoader.hpp"
"src/mods/UObjectHook.hpp"
"src/mods/VR.hpp"
"src/mods/uobjecthook/SDKDumper.hpp"
"src/mods/vr/CVarManager.hpp"
"src/mods/vr/D3D11Component.hpp"
"src/mods/vr/D3D12Component.hpp"
Expand Down Expand Up @@ -895,6 +906,7 @@ target_link_libraries(ue4poc PUBLIC
TracyClient
DirectXTK
DirectXTK12
sdkgenny
)

target_link_libraries(ue4poc PUBLIC
Expand Down
7 changes: 6 additions & 1 deletion cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ cmake-before="""
set(SAFETYHOOK_FETCH_ZYDIS ON)
"""

[fetch-content.sdkgenny]
git = "https://github.com/cursey/sdkgenny"
tag = "f58077f8da8a271490c17558e93b75843b3afd19"

[fetch-content.openxr]
git = "https://github.com/KhronosGroup/OpenXR-SDK"
tag = "458984d7f59d1ae6dc1b597d94b02e4f7132eaba"
Expand Down Expand Up @@ -249,7 +253,8 @@ link-libraries = [
"Version",
"TracyClient",
"DirectXTK",
"DirectXTK12"
"DirectXTK12",
"sdkgenny"
]

[template.ue4template.properties]
Expand Down
15 changes: 14 additions & 1 deletion shared/sdk/UObjectArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ struct FUObjectArray {
return s_is_chunked;
}

static bool is_inlined() {
return s_is_inlined_array;
}

static size_t get_objects_offset() {
return OBJECTS_OFFSET;
}

static size_t get_item_distance() {
return s_item_distance;
}

int32_t get_object_count() {
if (s_is_inlined_array) {
constexpr auto offs = OBJECTS_OFFSET + (MAX_INLINED_CHUNKS * sizeof(void*));
Expand Down Expand Up @@ -80,14 +92,15 @@ struct FUObjectArray {
return *(void**)((uintptr_t)this + OBJECTS_OFFSET);
}

private:
public:
// for <= 4.10
constexpr static inline auto MAX_INLINED_CHUNKS = ((8 * 1024 * 1024) + 16384 - 1) / 16384;
constexpr static inline auto OBJECTS_PER_CHUNK_INLINED = 16384;

// for some newer versions
constexpr static inline auto OBJECTS_PER_CHUNK = 64 * 1024;

private:
// has remained true for a long time
constexpr static inline auto OBJECTS_OFFSET = 0x10;

Expand Down
24 changes: 24 additions & 0 deletions shared/sdk/UObjectBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ class UObjectBase {
return s_outer_private_offset + sizeof(void*);
}

static uint32_t get_process_event_index() {
return s_process_event_index;
}

static uint32_t get_object_flags_offset() {
return s_object_flags_offset;
}

static uint32_t get_internal_index_offset() {
return s_internal_index_offset;
}

static uint32_t get_class_private_offset() {
return s_class_private_offset;
}

static uint32_t get_fname_offset() {
return s_fname_offset;
}

static uint32_t get_outer_private_offset() {
return s_outer_private_offset;
}

static std::optional<uintptr_t> get_vtable();
static std::optional<uintptr_t> get_destructor();
static std::optional<uintptr_t> get_add_object();
Expand Down
11 changes: 10 additions & 1 deletion src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <sdk/FObjectProperty.hpp>
#include <sdk/FArrayProperty.hpp>

#include "uobjecthook/SDKDumper.hpp"
#include "VR.hpp"

#include "UObjectHook.hpp"
Expand Down Expand Up @@ -1522,7 +1523,7 @@ sdk::UObject* UObjectHook::StatePath::resolve() const {
break;
}

// Need to handle StructProperty and ArrayProperty but whatever.
// Need to handle StructProperty but whatever.
default:
SPDLOG_ERROR("[UObjectHook] Unsupported persistent property type {}", utility::narrow(prop_t_name));
break;
Expand Down Expand Up @@ -1579,6 +1580,8 @@ void UObjectHook::on_draw_sidebar_entry(std::string_view in_entry) {
draw_main();
} else if (in_entry == "Config") {
draw_config();
} else if (in_entry == "Developer") {
draw_developer();
}
}

Expand All @@ -1588,6 +1591,12 @@ void UObjectHook::draw_config() {
m_attach_lerp_speed->draw("Attach Lerp Speed");
}

void UObjectHook::draw_developer() {
if (ImGui::Button("Dump SDK")) {
SDKDumper::dump();
}
}

void UObjectHook::draw_main() {
if (!m_motion_controller_attached_components.empty()) {
const auto made = ImGui::TreeNode("Attached Components");
Expand Down
4 changes: 3 additions & 1 deletion src/mods/UObjectHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class UObjectHook : public Mod {
std::vector<SidebarEntryInfo> get_sidebar_entries() override {
return {
{ "Main", true },
{ "Config", false }
{ "Config", false },
{ "Developer", true }
};
}

Expand All @@ -64,6 +65,7 @@ class UObjectHook : public Mod {
void on_draw_ui() override;

void draw_config();
void draw_developer();
void draw_main();

void on_pre_calculate_stereo_view_offset(void* stereo_device, const int32_t view_index, Rotator<float>* view_rotation,
Expand Down
Loading

0 comments on commit 4085037

Please sign in to comment.