-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forgot to commit files from last commit
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |