|
1 | 1 | #include "RETypeDB.hpp" |
2 | 2 |
|
| 3 | +#include "REComponent.hpp" |
3 | 4 | #include "REGameObject.hpp" |
4 | 5 |
|
| 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 | + |
5 | 23 | namespace utility::re_game_object { |
6 | 24 | std::string get_name(REGameObject* obj) { |
7 | 25 | if (obj == nullptr) { |
@@ -33,33 +51,15 @@ RETransform* get_transform(REGameObject* obj) { |
33 | 51 | return nullptr; |
34 | 52 | } |
35 | 53 |
|
36 | | - if (obj->transform != nullptr) { |
37 | | - return obj->transform; |
38 | | - } |
39 | | - |
40 | 54 | static const auto game_object_t = sdk::find_type_definition("via.GameObject"); |
41 | 55 | 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; |
44 | 56 |
|
45 | 57 | if (get_transform_fn != nullptr) { |
46 | 58 | if (auto transform = get_transform_fn->call<::RETransform*>(sdk::get_thread_context(), obj); transform != nullptr) { |
47 | 59 | return transform; |
48 | 60 | } |
49 | 61 | } |
50 | 62 |
|
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; |
64 | 64 | } |
65 | 65 | } |
0 commit comments