Skip to content

Commit

Permalink
SDK: Fix get_underlying_type on new RE Engine versions
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Feb 26, 2025
1 parent c93ee5e commit bbe7765
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions shared/sdk/RETypeDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <execution>
#include <sstream>

#include <spdlog/spdlog.h>


#include <reframework/API.hpp>

Expand Down Expand Up @@ -350,9 +352,6 @@ sdk::RETypeDefinition* RETypeDefinition::get_underlying_type() const {
}

#if TDB_VER > 49
// get the underlying type of the enum
// and then hash the name of the type instead
static auto get_underlying_type_method = this->get_method("GetUnderlyingType");
const auto runtime_type = this->get_runtime_type();

// dont forget to do this, passing nullptr into GetUnderlyingType causes System.ArgumentNullException
Expand All @@ -362,11 +361,24 @@ sdk::RETypeDefinition* RETypeDefinition::get_underlying_type() const {
return nullptr;
}

// get the underlying type of the enum
// and then hash the name of the type instead
static const auto system_runtime_type_type = sdk::find_type_definition("System.RuntimeType");
static const auto old_get_underlying_type_method = system_runtime_type_type != nullptr ? system_runtime_type_type->get_method("GetUnderlyingType") : nullptr;
static const auto new_underlying_type_method = system_runtime_type_type != nullptr ? system_runtime_type_type->get_method("GetEnumUnderlyingType") : nullptr;
const auto get_underlying_type_method = old_get_underlying_type_method != nullptr ? old_get_underlying_type_method : new_underlying_type_method;

if (get_underlying_type_method == nullptr) {
std::unique_lock _{ g_underlying_mtx };
g_underlying_types[this] = nullptr;
SPDLOG_WARN("[RETypeDefinition] Failed to find GetUnderlyingType method for {}", this->get_full_name());
return nullptr;
}

const auto underlying_type = get_underlying_type_method->call<::REManagedObject*>(sdk::get_thread_context(), runtime_type);

if (underlying_type != nullptr) {
static auto system_runtime_type_type = sdk::find_type_definition("System.RuntimeType");
static auto get_name_method = system_runtime_type_type->get_method("get_FullName");
static const auto get_name_method = system_runtime_type_type->get_method("get_FullName");

const auto full_name = get_name_method->call<::REManagedObject*>(sdk::get_thread_context(), underlying_type);

Expand Down

0 comments on commit bbe7765

Please sign in to comment.