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 Mar 29, 2024
2 parents a1dc18c + fb42769 commit 3612449
Show file tree
Hide file tree
Showing 23 changed files with 890 additions and 306 deletions.
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(ASMJIT_STATIC ON CACHE BOOL "" FORCE)
set(DYNAMIC_LOADER ON CACHE BOOL "" FORCE) # OpenXR
set(BUILD_TOOLS OFF CACHE BOOL "" FORCE) # DirectXTK
set(SAFETYHOOK_FETCH_ZYDIS ON)

if ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT")
Expand Down Expand Up @@ -113,6 +114,16 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(directxtk12)

message(STATUS "Fetching safetyhook (44200343bf803f78862426e301e9382e5b28ea2c)...")
FetchContent_Declare(
safetyhook
GIT_REPOSITORY
https://github.com/cursey/safetyhook
GIT_TAG
44200343bf803f78862426e301e9382e5b28ea2c
)
FetchContent_MakeAvailable(safetyhook)

message(STATUS "Fetching bddisasm (v1.34.10)...")
FetchContent_Declare(
bddisasm
Expand Down Expand Up @@ -490,9 +501,13 @@ set(CMKR_TARGET utility)
set(utility_SOURCES "")

list(APPEND utility_SOURCES
"shared/utility/Exceptions.cpp"
"shared/utility/FunctionHook.cpp"
"shared/utility/FunctionHookMinHook.cpp"
"shared/utility/Relocate.cpp"
"shared/utility/Exceptions.hpp"
"shared/utility/FunctionHook.hpp"
"shared/utility/FunctionHookMinHook.hpp"
"shared/utility/Relocate.hpp"
)

Expand Down Expand Up @@ -520,6 +535,7 @@ target_compile_options(utility PUBLIC
target_link_libraries(utility PUBLIC
spdlog
minhook
safetyhook
kananlib
)

Expand Down Expand Up @@ -12804,7 +12820,7 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${example_plugin_SOURCES})

target_compile_features(example_plugin PUBLIC
cxx_std_20
cxx_std_23
)

target_include_directories(example_plugin PUBLIC
Expand Down Expand Up @@ -12859,7 +12875,7 @@ if(REF_BUILD_FRAMEWORK AND CMAKE_SIZEOF_VOID_P EQUAL 8) # build-framework
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${weapon_stay_big_plugin_SOURCES})

target_compile_features(weapon_stay_big_plugin PUBLIC
cxx_std_20
cxx_std_23
)

target_include_directories(weapon_stay_big_plugin PUBLIC
Expand Down
7 changes: 6 additions & 1 deletion cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(ASMJIT_STATIC ON CACHE BOOL "" FORCE)
set(DYNAMIC_LOADER ON CACHE BOOL "" FORCE) # OpenXR
set(BUILD_TOOLS OFF CACHE BOOL "" FORCE) # DirectXTK
set(SAFETYHOOK_FETCH_ZYDIS ON)
if ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT")
Expand Down Expand Up @@ -111,6 +112,9 @@ include-directories = [
]
condition = "build-framework-dependencies"

[fetch-content.safetyhook]
git = "https://github.com/cursey/safetyhook"
tag = "44200343bf803f78862426e301e9382e5b28ea2c"

[target.imgui]
type = "static"
Expand Down Expand Up @@ -182,6 +186,7 @@ compile-features = ["cxx_std_23"]
link-libraries = [
"spdlog",
"minhook",
"safetyhook",
"kananlib"
]

Expand Down Expand Up @@ -342,7 +347,7 @@ type = "game"
[template.plugin]
type = "shared"
include-directories = ["include/"]
compile-features = ["cxx_std_20"]
compile-features = ["cxx_std_23"]
condition = "build-framework"

[template.plugin.properties]
Expand Down
137 changes: 124 additions & 13 deletions shared/sdk/REContext.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <windows.h>
#include <dbghelp.h>

#include <shared_mutex>
#include <spdlog/spdlog.h>

#include "utility/Scan.hpp"
#include "utility/Module.hpp"
#include "utility/Exceptions.hpp"

#include "reframework/API.hpp"
#include "ReClass.hpp"
Expand Down Expand Up @@ -397,9 +401,37 @@ namespace sdk {
spdlog::info("VMContext: Caught exception code {:x}", code);

switch (code) {
case EXCEPTION_ACCESS_VIOLATION:
spdlog::info("VMContext: Attempting to handle access violation.");

case EXCEPTION_ACCESS_VIOLATION: {
spdlog::info("VMContext: Attempting to handle access violation. Attempting to dump callstack...");

spdlog::error("RIP: {:x}", exc->ContextRecord->Rip);
spdlog::error("RSP: {:x}", exc->ContextRecord->Rsp);
spdlog::error("RCX: {:x}", exc->ContextRecord->Rcx);
spdlog::error("RDX: {:x}", exc->ContextRecord->Rdx);
spdlog::error("R8: {:x}", exc->ContextRecord->R8);
spdlog::error("R9: {:x}", exc->ContextRecord->R9);
spdlog::error("R10: {:x}", exc->ContextRecord->R10);
spdlog::error("R11: {:x}", exc->ContextRecord->R11);
spdlog::error("R12: {:x}", exc->ContextRecord->R12);
spdlog::error("R13: {:x}", exc->ContextRecord->R13);
spdlog::error("R14: {:x}", exc->ContextRecord->R14);
spdlog::error("R15: {:x}", exc->ContextRecord->R15);
spdlog::error("RAX: {:x}", exc->ContextRecord->Rax);
spdlog::error("RBX: {:x}", exc->ContextRecord->Rbx);
spdlog::error("RBP: {:x}", exc->ContextRecord->Rbp);
spdlog::error("RSI: {:x}", exc->ContextRecord->Rsi);
spdlog::error("RDI: {:x}", exc->ContextRecord->Rdi);
spdlog::error("EFLAGS: {:x}", exc->ContextRecord->EFlags);
spdlog::error("CS: {:x}", exc->ContextRecord->SegCs);
spdlog::error("DS: {:x}", exc->ContextRecord->SegDs);
spdlog::error("ES: {:x}", exc->ContextRecord->SegEs);
spdlog::error("FS: {:x}", exc->ContextRecord->SegFs);
spdlog::error("GS: {:x}", exc->ContextRecord->SegGs);
spdlog::error("SS: {:x}", exc->ContextRecord->SegSs);

utility::exceptions::dump_callstack(exc);

} break;
default:
break;
}
Expand Down Expand Up @@ -445,7 +477,15 @@ namespace sdk {

::REManagedObject* VM::create_sbyte(int8_t value) {
static auto sbyte_type = ::sdk::find_type_definition("System.SByte");
static auto value_field = sbyte_type->get_field("mValue");
static auto value_field = [&]() {
auto f = sbyte_type->get_field("mValue");
if (f == nullptr) {
f = sbyte_type->get_field("m_value");
}

return f;
}();

auto new_obj = sbyte_type->create_instance_full();

if (new_obj == nullptr) {
Expand All @@ -458,7 +498,14 @@ namespace sdk {

::REManagedObject* VM::create_byte(uint8_t value) {
static auto byte_type = ::sdk::find_type_definition("System.Byte");
static auto value_field = byte_type->get_field("mValue");
static auto value_field = [&]() {
auto f = byte_type->get_field("mValue");
if (f == nullptr) {
f = byte_type->get_field("m_value");
}

return f;
}();
auto new_obj = byte_type->create_instance_full();

if (new_obj == nullptr) {
Expand All @@ -471,7 +518,15 @@ namespace sdk {

::REManagedObject* VM::create_int16(int16_t value) {
static auto int16_type = ::sdk::find_type_definition("System.Int16");
static auto value_field = int16_type->get_field("mValue");
static auto value_field = [&]() {
auto f = int16_type->get_field("mValue");
if (f == nullptr) {
f = int16_type->get_field("m_value");
}

return f;
}();

auto new_obj = int16_type->create_instance_full();

if (new_obj == nullptr) {
Expand All @@ -484,7 +539,15 @@ namespace sdk {

::REManagedObject* VM::create_uint16(uint16_t value) {
static auto uint16_type = ::sdk::find_type_definition("System.UInt16");
static auto value_field = uint16_type->get_field("mValue");
static auto value_field = [&]() {
auto f = uint16_type->get_field("mValue");
if (f == nullptr) {
f = uint16_type->get_field("m_value");
}

return f;
}();

auto new_obj = uint16_type->create_instance_full();

if (new_obj == nullptr) {
Expand All @@ -497,7 +560,15 @@ namespace sdk {

::REManagedObject* VM::create_int32(int32_t value) {
static auto int32_type = ::sdk::find_type_definition("System.Int32");
static auto value_field = int32_type->get_field("mValue");
static auto value_field = [&]() {
auto f = int32_type->get_field("mValue");
if (f == nullptr) {
f = int32_type->get_field("m_value");
}

return f;
}();

auto new_obj = int32_type->create_instance_full();

if (new_obj == nullptr) {
Expand All @@ -510,7 +581,15 @@ namespace sdk {

::REManagedObject* VM::create_uint32(uint32_t value) {
static auto uint32_type = ::sdk::find_type_definition("System.UInt32");
static auto value_field = uint32_type->get_field("mValue");
static auto value_field = [&]() {
auto f = uint32_type->get_field("mValue");
if (f == nullptr) {
f = uint32_type->get_field("m_value");
}

return f;
}();

auto new_obj = uint32_type->create_instance_full();

if (new_obj == nullptr) {
Expand All @@ -523,7 +602,15 @@ namespace sdk {

::REManagedObject* VM::create_int64(int64_t value) {
static auto int64_type = ::sdk::find_type_definition("System.Int64");
static auto value_field = int64_type->get_field("mValue");
static auto value_field = [&]() {
auto f = int64_type->get_field("mValue");
if (f == nullptr) {
f = int64_type->get_field("m_value");
}

return f;
}();

auto new_obj = int64_type->create_instance_full();

if (new_obj == nullptr) {
Expand All @@ -536,7 +623,15 @@ namespace sdk {

::REManagedObject* VM::create_uint64(uint64_t value) {
static auto uint64_type = ::sdk::find_type_definition("System.UInt64");
static auto value_field = uint64_type->get_field("mValue");
static auto value_field = [&]() {
auto f = uint64_type->get_field("mValue");
if (f == nullptr) {
f = uint64_type->get_field("m_value");
}

return f;
}();

auto new_obj = uint64_type->create_instance_full();

if (new_obj == nullptr) {
Expand All @@ -550,7 +645,15 @@ namespace sdk {

::REManagedObject* VM::create_single(float value) {
static auto float_type = ::sdk::find_type_definition("System.Single");
static auto value_field = float_type->get_field("mValue");
static auto value_field = [&]() {
auto f = float_type->get_field("mValue");
if (f == nullptr) {
f = float_type->get_field("m_value");
}

return f;
}();

auto new_obj = float_type->create_instance_full();

if (new_obj == nullptr) {
Expand All @@ -563,7 +666,15 @@ namespace sdk {

::REManagedObject* VM::create_double(double value) {
static auto double_type = ::sdk::find_type_definition("System.Double");
static auto value_field = double_type->get_field("mValue");
static auto value_field = [&]() {
auto f = double_type->get_field("mValue");
if (f == nullptr) {
f = double_type->get_field("m_value");
}

return f;
}();

auto new_obj = double_type->create_instance_full();

if (new_obj == nullptr) {
Expand Down
14 changes: 14 additions & 0 deletions shared/sdk/RETypeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ const char* REMethodDefinition::get_name() const {
return tdb->get_string(name_offset);
}

std::unordered_set<REMethodDefinition*> logged_encoded_0_methods{};
std::shared_mutex logged_encoded_0_methods_mtx{};

void* REMethodDefinition::get_function() const {
#if TDB_VER >= 71
if (this->encoded_offset == 0) {
Expand All @@ -416,6 +419,17 @@ void* REMethodDefinition::get_function() const {
}
}*/

{
std::shared_lock _{ logged_encoded_0_methods_mtx };

if (logged_encoded_0_methods.contains(const_cast<REMethodDefinition*>(this))) {
return nullptr;
}
}

std::unique_lock _{ logged_encoded_0_methods_mtx };
logged_encoded_0_methods.insert(const_cast<REMethodDefinition*>(this));

auto decl_type = this->get_declaring_type();
auto name = decl_type != nullptr ? decl_type->get_full_name() : std::string{"null"};
spdlog::error("[REMethodDefinition::get_function] Encoded offset is 0 (vindex {}) (method: {}.{})", this->get_virtual_index(), name, this->get_name());
Expand Down
Loading

0 comments on commit 3612449

Please sign in to comment.