From d474aa0a9b568a377f4d1e8749ad9a74cf75ba69 Mon Sep 17 00:00:00 2001 From: praydog Date: Sat, 19 Oct 2024 11:31:28 -0700 Subject: [PATCH] Forgot to commit files from last commit --- shared/sdk/REGameObject.cpp | 30 ++++++++++++++++++++++++++++++ shared/sdk/REGameObject.hpp | 9 +++++++++ 2 files changed, 39 insertions(+) create mode 100644 shared/sdk/REGameObject.cpp create mode 100644 shared/sdk/REGameObject.hpp diff --git a/shared/sdk/REGameObject.cpp b/shared/sdk/REGameObject.cpp new file mode 100644 index 00000000..cbbdfb18 --- /dev/null +++ b/shared/sdk/REGameObject.cpp @@ -0,0 +1,30 @@ +#include "RETypeDB.hpp" + +#include "REGameObject.hpp" + +namespace utility::re_game_object { +std::string get_name(REGameObject* obj) { + if (obj == nullptr) { + return {}; + } + + // Only doing this on newer versions where we know it works + // Haven't tested it on older versions so just to be safe. +#if TDB_VER >= 71 + static const auto game_object_t = sdk::find_type_definition("via.GameObject"); + static const auto get_name_fn = game_object_t != nullptr ? game_object_t->get_method("get_Name") : nullptr; + + if (get_name_fn != nullptr) { + auto str = get_name_fn->call<::SystemString*>(sdk::get_thread_context(), obj); + + if (str != nullptr) { + return utility::re_string::get_string(str); + } + } +#endif + + // We rely on the reflected function first because + // this offset might change between versions. + return utility::re_string::get_string(obj->name); +} +} \ No newline at end of file diff --git a/shared/sdk/REGameObject.hpp b/shared/sdk/REGameObject.hpp new file mode 100644 index 00000000..ffc5dba7 --- /dev/null +++ b/shared/sdk/REGameObject.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "REManagedObject.hpp" + +namespace utility { +namespace re_game_object { +std::string get_name(::REGameObject* obj); +} +} \ No newline at end of file