Skip to content

Commit

Permalink
Merge branch 'praydog:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyhodge authored Apr 22, 2024
2 parents f80a4e1 + 4e55776 commit d06657c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
23 changes: 23 additions & 0 deletions shared/sdk/REContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "utility/Scan.hpp"
#include "utility/Module.hpp"
#include "utility/Exceptions.hpp"
#include <utility/ScopeGuard.hpp>

#include "reframework/API.hpp"
#include "ReClass.hpp"
Expand All @@ -17,6 +18,7 @@ namespace sdk {
VM** VM::s_global_context{ nullptr };
sdk::InvokeMethod* VM::s_invoke_tbl{nullptr};
VM::ThreadContextFn VM::s_get_thread_context{ nullptr };
bool VM::s_fully_updated_pointers{false};
int32_t VM::s_static_tbl_offset{ 0 };
int32_t VM::s_type_db_offset{ 0 };

Expand Down Expand Up @@ -65,6 +67,13 @@ namespace sdk {

void VM::update_pointers() {
{
// Originally this was always locking the lock in read mode
// however that was WAY too much which was reducing performance
// so just checking this bool is enough.
if (s_fully_updated_pointers) {
return;
}

// Lock a shared lock for the s_mutex
std::shared_lock lock(s_mutex);

Expand All @@ -76,6 +85,11 @@ namespace sdk {
// Create a unique lock for the s_mutex as we get to the meat of the function
std::unique_lock lock{ s_mutex };

utility::ScopeGuard sg{ [&]() {
s_fully_updated_pointers = true;
}
};

spdlog::info("[VM::update_pointers] Updating...");

// Version 1
Expand Down Expand Up @@ -284,12 +298,17 @@ namespace sdk {
}

static std::shared_mutex s_pointers_mtx{};
static bool s_fully_updated_vm_context_pointers{false};
static void* (*s_context_unhandled_exception_fn)(::REThreadContext*) = nullptr;
static void* (*s_context_local_frame_gc_fn)(::REThreadContext*) = nullptr;
static void* (*s_context_end_global_frame_fn)(::REThreadContext*) = nullptr;

void sdk::VMContext::update_pointers() {
{
if (s_fully_updated_vm_context_pointers) {
return;
}

std::shared_lock _{s_pointers_mtx};

if (s_context_unhandled_exception_fn != nullptr && s_context_local_frame_gc_fn != nullptr && s_context_end_global_frame_fn != nullptr) {
Expand All @@ -299,6 +318,10 @@ namespace sdk {

std::unique_lock _{s_pointers_mtx};

utility::ScopeGuard sg{[] {
s_fully_updated_vm_context_pointers = true;
}};

spdlog::info("Locating funcs");

// Version 1
Expand Down
1 change: 1 addition & 0 deletions shared/sdk/REContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class VM {
static sdk::InvokeMethod* s_invoke_tbl;
static ThreadContextFn s_get_thread_context;

static bool s_fully_updated_pointers;
static int32_t s_static_tbl_offset;
static int32_t s_type_db_offset;
};
Expand Down
16 changes: 16 additions & 0 deletions shared/utility/FunctionHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,33 @@ class FunctionHook {
bool create();

auto get_original() const {
if (m_init_finished) {
return m_inline_hook->trampoline().address();
}

std::shared_lock _{ m_initialization_mutex };
m_init_finished = true;
return m_inline_hook->trampoline().address();
}

template <typename T>
T* get_original() const {
if (m_init_finished) {
return m_inline_hook->original<T*>();
}

std::shared_lock _{ m_initialization_mutex };
m_init_finished = true;
return m_inline_hook->original<T*>();
}

auto is_valid() const {
if (m_init_finished) {
return is_valid_unsafe();
}

std::shared_lock _{ m_initialization_mutex };
m_init_finished = true;
return is_valid_unsafe();
}

Expand All @@ -44,6 +59,7 @@ class FunctionHook {

std::expected<SafetyHookInline, SafetyHookInline::Error> m_inline_hook;
mutable std::shared_mutex m_initialization_mutex{};
mutable bool m_init_finished{ false };

uintptr_t m_target{ 0 };
uintptr_t m_destination{ 0 };
Expand Down
8 changes: 8 additions & 0 deletions src/REFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ REFramework::REFramework(HMODULE reframework_module)

spdlog::info("REFramework entry");

spdlog::info("Commit hash: {}", REF_COMMIT_HASH);
spdlog::info("Tag: {}", REF_TAG);
spdlog::info("Commits past tag: {}", REF_COMMITS_PAST_TAG);
spdlog::info("Branch: {}", REF_BRANCH);
spdlog::info("Total commits: {}", REF_TOTAL_COMMITS);
spdlog::info("Build date: {}", REF_BUILD_DATE);
spdlog::info("Build time: {}", REF_BUILD_TIME);

const auto module_size = *utility::get_module_size(m_game_module);

spdlog::info("Game Module Addr: {:x}", (uintptr_t)m_game_module);
Expand Down

0 comments on commit d06657c

Please sign in to comment.