Skip to content

Commit 7794c75

Browse files
committed
Use cached native via GameObject accessors
1 parent aaef79a commit 7794c75

2 files changed

Lines changed: 26 additions & 30 deletions

File tree

shared/sdk/REComponent.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33
#include "ReClass.hpp"
44

55
namespace utility::re_component {
6+
namespace detail {
7+
::REGameObject* get_game_object_via_property(::REComponent* comp);
8+
}
9+
610
static auto get_game_object(::REComponent* comp) {
711
if (comp == nullptr) {
812
return (::REGameObject*)nullptr;
913
}
1014

11-
if (comp->ownerGameObject != nullptr) {
12-
return comp->ownerGameObject;
13-
}
14-
15-
if (auto reflected = utility::re_managed_object::get_field<::REGameObject*>(comp, "GameObject"); reflected != nullptr) {
16-
return reflected;
17-
}
18-
19-
if (auto reflected = utility::re_managed_object::get_field<::REGameObject*>(comp, "OwnerGameObject"); reflected != nullptr) {
20-
return reflected;
15+
if (auto game_object = detail::get_game_object_via_property(comp); game_object != nullptr) {
16+
return game_object;
2117
}
2218

23-
return utility::re_managed_object::get_field<::REGameObject*>(comp, "_OwnerGameObject_k__BackingField");
19+
return comp->ownerGameObject;
2420
}
2521

2622
static auto get_valid(::REComponent* comp) {

shared/sdk/REGameObject.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
#include "RETypeDB.hpp"
22

3+
#include "REComponent.hpp"
34
#include "REGameObject.hpp"
45

6+
namespace utility::re_component::detail {
7+
::REGameObject* get_game_object_via_property(::REComponent* comp) {
8+
if (comp == nullptr) {
9+
return nullptr;
10+
}
11+
12+
static const auto component_t = sdk::find_type_definition("via.Component");
13+
static const auto get_game_object_method = component_t != nullptr ? component_t->get_method("get_GameObject") : nullptr;
14+
15+
if (get_game_object_method == nullptr) {
16+
return nullptr;
17+
}
18+
19+
return get_game_object_method->call<::REGameObject*>(sdk::get_thread_context(), comp);
20+
}
21+
}
22+
523
namespace utility::re_game_object {
624
std::string get_name(REGameObject* obj) {
725
if (obj == nullptr) {
@@ -33,33 +51,15 @@ RETransform* get_transform(REGameObject* obj) {
3351
return nullptr;
3452
}
3553

36-
if (obj->transform != nullptr) {
37-
return obj->transform;
38-
}
39-
4054
static const auto game_object_t = sdk::find_type_definition("via.GameObject");
4155
static const auto get_transform_fn = game_object_t != nullptr ? game_object_t->get_method("get_Transform") : nullptr;
42-
static const auto transform_field = game_object_t != nullptr ? game_object_t->get_field("Transform") : nullptr;
43-
static const auto transform_field_lower = game_object_t != nullptr ? game_object_t->get_field("transform") : nullptr;
4456

4557
if (get_transform_fn != nullptr) {
4658
if (auto transform = get_transform_fn->call<::RETransform*>(sdk::get_thread_context(), obj); transform != nullptr) {
4759
return transform;
4860
}
4961
}
5062

51-
if (transform_field != nullptr) {
52-
if (auto transform = transform_field->get_data<::RETransform*>(obj); transform != nullptr) {
53-
return transform;
54-
}
55-
}
56-
57-
if (transform_field_lower != nullptr) {
58-
if (auto transform = transform_field_lower->get_data<::RETransform*>(obj); transform != nullptr) {
59-
return transform;
60-
}
61-
}
62-
63-
return nullptr;
63+
return obj->transform;
6464
}
6565
}

0 commit comments

Comments
 (0)