Skip to content

Commit dd818f6

Browse files
authored
Merge pull request #58 from apple1417/master
handle UStruct differing in size between bl2 + tps
2 parents 9d5303b + 4670120 commit dd818f6

File tree

14 files changed

+200
-45
lines changed

14 files changed

+200
-45
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.5.1)
3+
project(unrealsdk VERSION 1.6.0)
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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Changelog
22

3-
## v1.5.1
3+
## v1.6.0
4+
5+
- Handled `UStruct` differing in size between BL2 and TPS.
6+
7+
This affects all members on it's subclasses - `UClass::ClassDefaultObject`, `UClass::Interfaces`,
8+
`UFunction::FunctionFlags`, `UFunction::NumParams`, `UFunction::ParamsSize`,
9+
`UFunction::ReturnValueOffset`, and `UScriptStruct::StructFlags` have all now changed to methods
10+
which return a reference.
11+
12+
[70854d65](https://github.com/bl-sdk/unrealsdk/commit/70854d65)
413

514
- Fixed all BL3 console output being treated as console commands instead.
615

src/unrealsdk/game/bl2/console.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool say_crash_fix_hook(hook_manager::Details& hook) {
125125
static const auto get_timestamp_string_func =
126126
hook.obj->Class->find_func_and_validate(L"GetTimestampString"_fn);
127127
static const auto default_save_game_manager =
128-
find_class(L"WillowSaveGameManager"_fn)->ClassDefaultObject;
128+
find_class(L"WillowSaveGameManager"_fn)->ClassDefaultObject();
129129
static const auto time_format_prop =
130130
default_save_game_manager->Class->find_prop_and_validate<UStrProperty>(L"TimeFormat"_fn);
131131

src/unrealsdk/game/bl3/console.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ bool inject_console_hook(hook_manager::Details& hook) {
167167
console = viewport->get(console_property);
168168

169169
if (console == nullptr) {
170-
auto default_console = console_property->get_property_class()->ClassDefaultObject;
170+
auto default_console = console_property->get_property_class()->ClassDefaultObject();
171171
console = unrealsdk::construct_object(default_console->Class, default_console->Outer);
172172
viewport->set<UObjectProperty>(L"ViewportConsole"_fn, console);
173173
}

src/unrealsdk/unreal/classes/uclass.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66

77
namespace unrealsdk::unreal {
88

9+
decltype(UClass::ClassDefaultObject_internal)& UClass::ClassDefaultObject(void) {
10+
return this->get_field(&UClass::ClassDefaultObject_internal);
11+
}
12+
[[nodiscard]] const decltype(UClass::ClassDefaultObject_internal)& UClass::ClassDefaultObject(
13+
void) const {
14+
return this->get_field(&UClass::ClassDefaultObject_internal);
15+
}
16+
decltype(UClass::Interfaces_internal)& UClass::Interfaces(void) {
17+
return this->get_field(&UClass::Interfaces_internal);
18+
}
19+
[[nodiscard]] const decltype(UClass::Interfaces_internal)& UClass::Interfaces(void) const {
20+
return this->get_field(&UClass::Interfaces_internal);
21+
}
22+
923
bool UClass::implements(const UClass* iface, FImplementedInterface* impl_out) const {
1024
// For each class in the inheritance chain
1125
for (const UObject* superfield : this->superfields()) {
@@ -16,7 +30,7 @@ bool UClass::implements(const UClass* iface, FImplementedInterface* impl_out) co
1630
auto cls = reinterpret_cast<const UClass*>(superfield);
1731

1832
// For each interface on that class
19-
for (auto our_iface : cls->Interfaces) {
33+
for (auto our_iface : cls->Interfaces()) {
2034
// If the interface matches
2135
if (our_iface.Class == iface) {
2236
// Output the implementation, if necessary

src/unrealsdk/unreal/classes/uclass.h

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,13 @@ class UClass : public UStruct {
3030

3131
// NOLINTBEGIN(readability-magic-numbers, readability-identifier-naming)
3232

33-
#ifdef UE4
3433
private:
34+
#ifdef UE4
3535
uint8_t UnknownData00[0x70];
36-
37-
public:
38-
UObject* ClassDefaultObject;
39-
40-
private:
36+
UObject* ClassDefaultObject_internal;
4137
uint8_t UnknownData01[0xA0];
42-
43-
public:
44-
TArray<FImplementedInterface> Interfaces;
38+
TArray<FImplementedInterface> Interfaces_internal;
4539
#else
46-
private:
4740
// Misc Fields I found within this block in BL2, but which we don't care about enough for me to
4841
// find in UE4, or to want to increase the compile times by including
4942

@@ -53,16 +46,16 @@ class UClass : public UStruct {
5346
// 0x10C: TArray<FName> AutoExpandCategories;
5447

5548
uint8_t UnknownData00[0xCC];
56-
57-
public:
58-
UObject* ClassDefaultObject;
59-
60-
private:
49+
UObject* ClassDefaultObject_internal;
6150
uint8_t UnknownData01[0x48];
51+
TArray<FImplementedInterface> Interfaces_internal;
52+
#endif
6253

6354
public:
64-
TArray<FImplementedInterface> Interfaces;
65-
#endif
55+
decltype(ClassDefaultObject_internal)& ClassDefaultObject(void);
56+
[[nodiscard]] const decltype(ClassDefaultObject_internal)& ClassDefaultObject(void) const;
57+
decltype(Interfaces_internal)& Interfaces(void);
58+
[[nodiscard]] const decltype(Interfaces_internal)& Interfaces(void) const;
6659

6760
// NOLINTEND(readability-magic-numbers, readability-identifier-naming)
6861

src/unrealsdk/unreal/classes/ufunction.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,33 @@
55

66
namespace unrealsdk::unreal {
77

8+
decltype(UFunction::FunctionFlags_internal)& UFunction::FunctionFlags(void) {
9+
return this->get_field(&UFunction::FunctionFlags_internal);
10+
}
11+
[[nodiscard]] const decltype(UFunction::FunctionFlags_internal)& UFunction::FunctionFlags(
12+
void) const {
13+
return this->get_field(&UFunction::FunctionFlags_internal);
14+
}
15+
decltype(UFunction::NumParams_internal)& UFunction::NumParams(void) {
16+
return this->get_field(&UFunction::NumParams_internal);
17+
}
18+
[[nodiscard]] const decltype(UFunction::NumParams_internal)& UFunction::NumParams(void) const {
19+
return this->get_field(&UFunction::NumParams_internal);
20+
}
21+
decltype(UFunction::ParamsSize_internal)& UFunction::ParamsSize(void) {
22+
return this->get_field(&UFunction::ParamsSize_internal);
23+
}
24+
[[nodiscard]] const decltype(UFunction::ParamsSize_internal)& UFunction::ParamsSize(void) const {
25+
return this->get_field(&UFunction::ParamsSize_internal);
26+
}
27+
decltype(UFunction::ReturnValueOffset_internal)& UFunction::ReturnValueOffset(void) {
28+
return this->get_field(&UFunction::ReturnValueOffset_internal);
29+
}
30+
[[nodiscard]] const decltype(UFunction::ReturnValueOffset_internal)& UFunction::ReturnValueOffset(
31+
void) const {
32+
return this->get_field(&UFunction::ReturnValueOffset_internal);
33+
}
34+
835
UProperty* UFunction::find_return_param(void) const {
936
for (auto prop : this->properties()) {
1037
if ((prop->PropertyFlags & UProperty::PROP_FLAG_RETURN) != 0) {

src/unrealsdk/unreal/classes/ufunction.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,40 @@ class UFunction : public UStruct {
2929

3030
// NOLINTBEGIN(readability-magic-numbers, readability-identifier-naming)
3131

32-
#ifdef UE4
33-
uint32_t FunctionFlags;
34-
uint8_t NumParams;
35-
uint16_t ParamsSize;
36-
uint16_t ReturnValueOffset;
37-
3832
private:
33+
#ifdef UE4
34+
uint32_t FunctionFlags_internal;
35+
uint8_t NumParams_internal;
36+
uint16_t ParamsSize_internal;
37+
uint16_t ReturnValueOffset_internal;
3938
uint16_t RPCId;
4039
uint16_t RPCResponseId;
4140
UProperty* FirstPropertyToInit;
4241
UFunction* EventGraphFunction;
4342
int32_t EventGraphCallOffset;
4443
void* Func;
4544
#else
46-
uint32_t FunctionFlags;
47-
48-
private:
45+
uint32_t FunctionFlags_internal;
4946
uint16_t iNative;
5047
uint16_t RepOffset;
5148
FName FriendlyName;
5249
uint8_t OperPrecedence;
53-
54-
public:
55-
uint8_t NumParams;
56-
uint16_t ParamsSize;
57-
uint16_t ReturnValueOffset;
58-
59-
private:
50+
uint8_t NumParams_internal;
51+
uint16_t ParamsSize_internal;
52+
uint16_t ReturnValueOffset_internal;
6053
uint8_t UnknownData00[0x6];
6154
void* Func;
6255
#endif
63-
6456
public:
57+
decltype(FunctionFlags_internal)& FunctionFlags(void);
58+
[[nodiscard]] const decltype(FunctionFlags_internal)& FunctionFlags(void) const;
59+
decltype(NumParams_internal)& NumParams(void);
60+
[[nodiscard]] const decltype(NumParams_internal)& NumParams(void) const;
61+
decltype(ParamsSize_internal)& ParamsSize(void);
62+
[[nodiscard]] const decltype(ParamsSize_internal)& ParamsSize(void) const;
63+
decltype(ReturnValueOffset_internal)& ReturnValueOffset(void);
64+
[[nodiscard]] const decltype(ReturnValueOffset_internal)& ReturnValueOffset(void) const;
65+
6566
/**
6667
* @brief Finds the return param for this function (if it exists).
6768
*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "unrealsdk/pch.h"
2+
#include "unrealsdk/unreal/classes/uscriptstruct.h"
3+
#include "unrealsdk/unreal/classes/ustruct.h"
4+
5+
namespace unrealsdk::unreal {
6+
7+
decltype(UScriptStruct::StructFlags_internal)& UScriptStruct::StructFlags(void) {
8+
return this->get_field(&UScriptStruct::StructFlags_internal);
9+
}
10+
[[nodiscard]] const decltype(UScriptStruct::StructFlags_internal)& UScriptStruct::StructFlags(
11+
void) const {
12+
return this->get_field(&UScriptStruct::StructFlags_internal);
13+
}
14+
15+
} // namespace unrealsdk::unreal

src/unrealsdk/unreal/classes/uscriptstruct.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ class UScriptStruct : public UStruct {
1919
UScriptStruct& operator=(UScriptStruct&&) = delete;
2020
~UScriptStruct() = delete;
2121

22-
// NOLINTNEXTLINE(readability-identifier-naming)
23-
uint32_t StructFlags;
22+
// NOLINTBEGIN(readability-identifier-naming)
23+
24+
private:
25+
uint32_t StructFlags_internal;
26+
27+
public:
28+
decltype(StructFlags_internal)& StructFlags(void);
29+
[[nodiscard]] const decltype(StructFlags_internal)& StructFlags(void) const;
30+
31+
// NOLINTEND(readability-identifier-naming)
2432
};
2533

2634
template <>

0 commit comments

Comments
 (0)