11#include " unrealsdk/pch.h"
22
3+ #include " unrealsdk/config.h"
34#include " unrealsdk/unreal/class_name.h"
45#include " unrealsdk/unreal/classes/uclass.h"
56#include " unrealsdk/unreal/find_class.h"
@@ -13,13 +14,47 @@ decltype(UClass::ClassDefaultObject_internal)& UClass::ClassDefaultObject(void)
1314 void ) const {
1415 return this ->get_field (&UClass::ClassDefaultObject_internal);
1516}
17+
18+ // To further complicate things, UClass::Interfaces also shifts between BL2 + TPS
19+ #ifdef UE3
20+
21+ // This is awful hacky code to get a working release out sooner, the whole system needs a rework.
22+ // Check if the size of UClass is that we've observed in TPS, and if so use it's hardcoded offset.
23+ namespace {
24+
25+ const constexpr auto UCLASS_SIZE_TPS = 0x18C ;
26+ const constexpr auto UCLASS_INTERFACES_OFFSET_TPS = 0x160 ;
27+
28+ } // namespace
29+
30+ decltype (UClass::Interfaces_internal)& UClass::Interfaces(void ) {
31+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
32+ return const_cast <decltype (UClass::Interfaces_internal)&>(
33+ const_cast <const UClass*>(this )->Interfaces ());
34+ }
35+ [[nodiscard]] const decltype (UClass::Interfaces_internal)& UClass::Interfaces(void ) const {
36+ static const auto use_tps_offset =
37+ unrealsdk::config::get_bool (" unrealsdk.__force_uclass_interfaces_tps_offset" )
38+ .value_or (this ->Class ->get_struct_size () == UCLASS_SIZE_TPS);
39+
40+ if (use_tps_offset) {
41+ return *reinterpret_cast <decltype (UClass::Interfaces_internal)*>(
42+ reinterpret_cast <uintptr_t >(this ) + UCLASS_INTERFACES_OFFSET_TPS);
43+ }
44+
45+ return this ->get_field (&UClass::Interfaces_internal);
46+ }
47+ #else
48+
1649decltype (UClass::Interfaces_internal)& UClass::Interfaces(void ) {
1750 return this ->get_field (&UClass::Interfaces_internal);
1851}
1952[[nodiscard]] const decltype (UClass::Interfaces_internal)& UClass::Interfaces(void ) const {
2053 return this ->get_field (&UClass::Interfaces_internal);
2154}
2255
56+ #endif
57+
2358bool UClass::implements (const UClass* iface, FImplementedInterface* impl_out) const {
2459 // For each class in the inheritance chain
2560 for (const UObject* superfield : this ->superfields ()) {
0 commit comments