Skip to content

Commit 437a8ff

Browse files
authored
Merge pull request #853 from UE4SS-RE/chore-tobjectptrapi
Updates to source for TObjectPtr api changes and to start move to safer pointer use
2 parents a83f160 + e63bb12 commit 437a8ff

File tree

10 files changed

+49
-36
lines changed

10 files changed

+49
-36
lines changed

UE4SS/src/LuaType/LuaUObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ namespace RC::LuaType
509509
// params.data = Start of the struct
510510
// params.property = The corresponding FStructProperty
511511
auto* struct_property = Unreal::CastField<Unreal::FStructProperty>(params.property);
512-
auto* script_struct = struct_property->GetStruct();
512+
Unreal::UScriptStruct* script_struct = struct_property->GetStruct();
513513

514514
auto iterate_struct_and_turn_into_lua_table = [&](const LuaMadeSimple::Lua& lua, void* data_ptr) {
515515
auto* data = static_cast<unsigned char*>(data_ptr);

UE4SS/src/ObjectDumper/ObjectToString.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,63 +183,63 @@ namespace RC::ObjectDumper
183183

184184
property_trivial_dump_to_string(p_this, out_line);
185185
// mc = MetaClass
186-
out_line.append(fmt::format(STR(" [mc: {:016X}]"), reinterpret_cast<uintptr_t>(typed_this->GetMetaClass())));
186+
out_line.append(fmt::format(STR(" [mc: {:016X}]"), reinterpret_cast<UPTRINT>(ToRawPtr(typed_this->GetMetaClass()))));
187187
}
188188

189189
auto delegateproperty_to_string(void* p_this, StringType& out_line) -> void
190190
{
191191
property_trivial_dump_to_string(p_this, out_line);
192192

193193
FDelegateProperty* p_typed_this = static_cast<FDelegateProperty*>(p_this);
194-
out_line.append(fmt::format(STR(" [df: {:016X}]"), reinterpret_cast<uintptr_t>(p_typed_this->GetSignatureFunction())));
194+
out_line.append(fmt::format(STR(" [df: {:016X}]"), reinterpret_cast<UPTRINT>(ToRawPtr(p_typed_this->GetSignatureFunction()))));
195195
}
196196

197197
auto fieldpathproperty_to_string(void* p_this, StringType& out_line) -> void
198198
{
199199
FFieldPathProperty* typed_this = static_cast<FFieldPathProperty*>(p_this);
200200

201201
property_trivial_dump_to_string(p_this, out_line);
202-
out_line.append(fmt::format(STR(" [pc: {:016X}]"), reinterpret_cast<uintptr_t>(typed_this->GetPropertyClass())));
202+
out_line.append(fmt::format(STR(" [pc: {:016X}]"), reinterpret_cast<UPTRINT>(ToRawPtr(typed_this->GetPropertyClass()))));
203203
}
204204

205205
auto interfaceproperty_to_string(void* p_this, StringType& out_line) -> void
206206
{
207207
FInterfaceProperty* typed_this = static_cast<FInterfaceProperty*>(p_this);
208208

209209
property_trivial_dump_to_string(p_this, out_line);
210-
out_line.append(fmt::format(STR(" [ic: {:016X}]"), reinterpret_cast<uintptr_t>(typed_this->GetInterfaceClass())));
210+
out_line.append(fmt::format(STR(" [ic: {:016X}]"), reinterpret_cast<UPTRINT>(ToRawPtr(typed_this->GetInterfaceClass()))));
211211
}
212212

213213
auto multicastdelegateproperty_to_string(void* p_this, StringType& out_line) -> void
214214
{
215215
property_trivial_dump_to_string(p_this, out_line);
216216

217217
FMulticastDelegateProperty* p_typed_this = static_cast<FMulticastDelegateProperty*>(p_this);
218-
out_line.append(fmt::format(STR(" [df: {:016X}]"), reinterpret_cast<uintptr_t>(p_typed_this->GetSignatureFunction())));
218+
out_line.append(fmt::format(STR(" [df: {:016X}]"), reinterpret_cast<UPTRINT>(ToRawPtr(p_typed_this->GetSignatureFunction()))));
219219
}
220220

221221
auto objectproperty_to_string(void* p_this, StringType& out_line) -> void
222222
{
223223
FObjectProperty* typed_this = static_cast<FObjectProperty*>(p_this);
224224

225225
property_trivial_dump_to_string(p_this, out_line);
226-
out_line.append(fmt::format(STR(" [pc: {:016X}]"), reinterpret_cast<uintptr_t>(typed_this->GetPropertyClass())));
226+
out_line.append(fmt::format(STR(" [pc: {:016X}]"), reinterpret_cast<UPTRINT>(ToRawPtr(typed_this->GetPropertyClass()))));
227227
}
228228

229229
auto structproperty_to_string(void* p_this, StringType& out_line) -> void
230230
{
231231
FStructProperty* typed_this = static_cast<FStructProperty*>(p_this);
232232

233233
property_trivial_dump_to_string(p_this, out_line);
234-
out_line.append(fmt::format(STR(" [ss: {:016X}]"), reinterpret_cast<uintptr_t>(typed_this->GetStruct())));
234+
out_line.append(fmt::format(STR(" [ss: {:016X}]"), reinterpret_cast<UPTRINT>(ToRawPtr(typed_this->GetStruct()))));
235235
}
236236

237237
auto enumproperty_to_string(void* p_this, StringType& out_line) -> void
238238
{
239239
property_trivial_dump_to_string(p_this, out_line);
240240

241241
auto* typed_this = static_cast<FEnumProperty*>(p_this);
242-
out_line.append(fmt::format(STR(" [em: {:016X}]"), reinterpret_cast<uintptr_t>(typed_this->GetEnum())));
242+
out_line.append(fmt::format(STR(" [em: {:016X}]"), reinterpret_cast<UPTRINT>(ToRawPtr(typed_this->GetEnum()))));
243243
}
244244

245245
auto boolproperty_to_string(void* p_this, StringType& out_line) -> void

UE4SS/src/SDKGenerator/Common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ namespace RC::UEGenerator
277277

278278
if (auto* object_property = CastField<FObjectPtrProperty>(property); object_property)
279279
{
280-
auto* property_class = object_property->GetPropertyClass();
280+
UClass* property_class = object_property->GetPropertyClass();
281281

282282
if (!property_class)
283283
{
@@ -589,7 +589,7 @@ namespace RC::UEGenerator
589589

590590
if (auto* object_property = CastField<FObjectPtrProperty>(property); object_property)
591591
{
592-
auto* property_class = object_property->GetPropertyClass();
592+
UClass* property_class = object_property->GetPropertyClass();
593593

594594
if (!property_class)
595595
{

UE4SS/src/SDKGenerator/Generator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ namespace RC::UEGenerator
282282
if (return_property->IsA<FStructProperty>())
283283
{
284284
// Can StructProperty even be forward declared ? I don't know if it's ever a pointer to a struct
285-
auto* script_struct = static_cast<FStructProperty*>(return_property)->GetStruct();
285+
UScriptStruct* script_struct = static_cast<FStructProperty*>(return_property)->GetStruct();
286286
if (m_classes_dumped.contains(script_struct))
287287
{
288288
auto& property_class_info = m_classes_dumped[script_struct];
@@ -295,7 +295,7 @@ namespace RC::UEGenerator
295295
else if (return_property->IsA<FClassProperty>())
296296
{
297297
// Can ClassProperty be forward declared ? Maybe ?
298-
auto* meta_class = static_cast<FClassProperty*>(return_property)->GetMetaClass();
298+
UClass* meta_class = static_cast<FClassProperty*>(return_property)->GetMetaClass();
299299
if (m_classes_dumped.contains(meta_class))
300300
{
301301
auto& property_class_info = m_classes_dumped[meta_class];
@@ -307,7 +307,7 @@ namespace RC::UEGenerator
307307
}
308308
else if (return_property->IsA<FObjectProperty>())
309309
{
310-
auto* property_class = static_cast<FObjectProperty*>(return_property)->GetPropertyClass();
310+
UClass* property_class = static_cast<FObjectProperty*>(return_property)->GetPropertyClass();
311311
if (m_classes_dumped.contains(property_class))
312312
{
313313
auto& property_class_info = m_classes_dumped[property_class];

UE4SS/src/SDKGenerator/UEHeaderGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@ namespace RC::UEGenerator
24732473

24742474
if (auto* object_property = CastField<FObjectPtrProperty>(property); object_property)
24752475
{
2476-
auto* property_class = object_property->GetPropertyClass();
2476+
UClass* property_class = object_property->GetPropertyClass();
24772477

24782478
if (!property_class)
24792479
{

assets/Default_UVTD_Configs/Config/object_items.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@
134134
"valid_for_vtable": 1,
135135
"valid_for_member_vars": 0
136136
},
137-
{
138-
"name": "UDataTable",
139-
"valid_for_vtable": 0,
140-
"valid_for_member_vars": 0
141-
},
142137
{
143138
"name": "UScriptStruct",
144139
"valid_for_vtable": 1,

assets/Default_UVTD_Configs/Config/types_not_to_dump.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,10 @@
9090
"UObjectReferencer",
9191
"FNamedNetDriver",
9292
"FSeamlessTravelHandler",
93-
"FLevelStreamingStatus"
93+
"FLevelStreamingStatus",
94+
"UWorld::FOnAllLevelsChangedEvent",
95+
"FEndClothSimulationFunction",
96+
"UWorld::FOnBeginPlay",
97+
"FStartClothSimulationFunction",
98+
"ULocalPlayer::FOnPlayerControllerChanged"
9499
]

assets/Default_UVTD_Configs/Config/virtual_generator_includes.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
"UClass",
2424
"World",
2525
"UEnum",
26-
"UEngine",
2726
"FWorldContext",
2827
"FArchive",
2928
"AGameModeBase",
3029
"AGameMode",
3130
"UPlayer",
3231
"ULocalPlayer",
33-
"ITextData"
32+
"ITextData",
33+
"UGameViewportClient"
3434
]

deps/first/Unreal

docs/upgrade-guide.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,34 @@ public:
3636
TObjectPtr(TYPE_OF_NULLPTR) : Ptr(nullptr) {}
3737
TObjectPtr(const TObjectPtr& Other) : Ptr(Other.Ptr) {}
3838
explicit TObjectPtr(ElementType* InPtr) : Ptr(InPtr) {}
39-
39+
4040
// Assignment operators
4141
TObjectPtr& operator=(const TObjectPtr& Other) { Ptr = Other.Ptr; return *this; }
4242
TObjectPtr& operator=(TYPE_OF_NULLPTR) { Ptr = nullptr; return *this; }
4343
TObjectPtr& operator=(ElementType* InPtr) { Ptr = InPtr; return *this; }
44-
45-
// Pointer operators
46-
ElementType& operator*() const { return *Ptr; }
47-
ElementType* operator->() const { return Ptr; }
48-
49-
// Conversion operator
50-
operator ElementType*() const { return Ptr; }
51-
44+
45+
// Conversion operators
46+
FORCEINLINE operator T* () const { return Get(); }
47+
template <typename U>
48+
UE_OBJPTR_DEPRECATED(5.0, "Explicit cast to other raw pointer types is deprecated. Please use the Cast API or get the raw pointer with ToRawPtr and cast that instead.")
49+
explicit FORCEINLINE operator U* () const { return (U*)Get(); }
50+
explicit FORCEINLINE operator UPTRINT() const { return (UPTRINT)Get(); }
51+
FORCEINLINE T* operator->() const { return Get(); }
52+
FORCEINLINE T& operator*() const { return *Get(); }
53+
5254
// Comparison operators
5355
bool operator==(const TObjectPtr& Other) const { return Ptr == Other.Ptr; }
5456
bool operator!=(const TObjectPtr& Other) const { return Ptr != Other.Ptr; }
5557
bool operator==(const ElementType* InPtr) const { return Ptr == InPtr; }
5658
bool operator!=(const ElementType* InPtr) const { return Ptr != InPtr; }
5759
bool operator==(TYPE_OF_NULLPTR) const { return Ptr == nullptr; }
5860
bool operator!=(TYPE_OF_NULLPTR) const { return Ptr != nullptr; }
59-
60-
// Additional API compatibility
61+
62+
// Additional API compatibility with UE's TObjectPtr
6163
bool operator!() const { return Ptr == nullptr; }
6264
explicit operator bool() const { return Ptr != nullptr; }
6365
ElementType* Get() const { return Ptr; }
64-
66+
6567
private:
6668
ElementType* Ptr;
6769
};
@@ -92,6 +94,17 @@ private:
9294
&ObjectPtr
9395
```
9496

97+
3. For pointer-to-integer conversions (e.g., formatting addresses):
98+
```cpp
99+
// Old
100+
uintptr_t addr = reinterpret_cast<uintptr_t>(ObjectPtr.UnderlyingObjectPointer);
101+
102+
// New
103+
uintptr_t addr = reinterpret_cast<uintptr_t>(ObjectPtr.Get());
104+
// or
105+
uintptr_t addr = reinterpret_cast<uintptr_t>(ToRawPtr(ObjectPtr)); // using helper to extract a raw pointer from TObjectPtr
106+
```
107+
95108
#### FString API Changes
96109

97110
##### `GetCharArray()` Behavior Change

0 commit comments

Comments
 (0)