Skip to content

Commit a316c28

Browse files
authored
Merge pull request #59 from apple1417/master
handle tps's different `UClass::Interfaces` offset
2 parents dd818f6 + fb16165 commit a316c28

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.25)
22

3-
project(unrealsdk VERSION 1.6.0)
3+
project(unrealsdk VERSION 1.6.1)
44

55
set(UNREALSDK_UE_VERSION "UE4" CACHE STRING "The unreal engine version to build the SDK for. One of 'UE3' or 'UE4'.")
66
set(UNREALSDK_ARCH "x64" CACHE STRING "The architecture to build the sdk for. One of 'x86' or 'x64'.")

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.6.1
4+
5+
- Handled `UClass::Interfaces` also having a different offset between BL2 and TPS.
6+
7+
[287c5802](https://github.com/bl-sdk/unrealsdk/commit/287c5802)
8+
39
## v1.6.0
410

511
- Handled `UStruct` differing in size between BL2 and TPS.

src/unrealsdk/unreal/classes/uclass.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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+
1649
decltype(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+
2358
bool 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

Comments
 (0)