Skip to content

Commit

Permalink
Forgot to commit files from last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 19, 2024
1 parent 4d0d36e commit d474aa0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions shared/sdk/REGameObject.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
9 changes: 9 additions & 0 deletions shared/sdk/REGameObject.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "REManagedObject.hpp"

namespace utility {
namespace re_game_object {
std::string get_name(::REGameObject* obj);
}
}

0 comments on commit d474aa0

Please sign in to comment.