@@ -115,99 +115,96 @@ pybind11::object FHelper::GetProperty(UProperty *prop) {
115
115
return py::none ();
116
116
}
117
117
118
- bool FHelper::SetProperty (class UStructProperty *prop, py::object val) {
118
+ void FHelper::SetProperty (class UStructProperty *prop, py::object val) {
119
119
if (py::isinstance<py::tuple>(val))
120
120
{
121
121
py::tuple tup = (py::tuple)val;
122
122
123
123
unsigned int currentIndex = 0 ;
124
+ for (UProperty* Child = (UProperty *)prop->GetStruct ()->Children ; Child; Child = (UProperty *)Child->Next )
125
+ currentIndex++;
126
+
127
+ if (tup.size () > currentIndex) {
128
+ throw std::exception (Util::Format (" FHelper::SetProperty: Not all tuple values converted for struct!\n " ).c_str ());
129
+ }
130
+
131
+ currentIndex = 0 ;
124
132
for (UProperty* Child = (UProperty *)prop->GetStruct ()->Children ; Child; Child = (UProperty *)Child->Next ) {
125
133
Logging::LogD (" Child = %s, %d\n " , Child->GetFullName ().c_str (), Child->Offset_Internal );
126
134
if (currentIndex < tup.size ())
127
135
((FHelper *)(((char *)this ) + prop->Offset_Internal ))->SetProperty (Child, tup[currentIndex++]);
128
136
}
129
- if (tup.size () > currentIndex) {
130
- Logging::LogF (" Not all tuple values converted for struct!\n " );
131
- return false ;
132
- }
133
- return true ;
134
137
}
135
- else if (py::isinstance<FStruct>(val)) {
136
- Logging::LogD (" FSTRUCT OMG\n " );
137
- }
138
- return false ;
138
+ else
139
+ throw std::exception (Util::Format (" FHelper::SetProperty: Got unexpected type, expected tuple!\n " ).c_str ());
139
140
}
140
141
141
- bool FHelper::SetProperty (class UStrProperty *prop, py::object val) {
142
+ void FHelper::SetProperty (class UStrProperty *prop, py::object val) {
142
143
if (!py::isinstance<py::str>(val))
143
- return false ;
144
+ throw std::exception ( Util::Format ( " FHelper::SetProperty: Got unexpected type, expected string! \n " ). c_str ()) ;
144
145
memcpy (((char *)this ) + prop->Offset_Internal , &FString (val.cast <std::string>().c_str ()), sizeof (FString));
145
- return true ;
146
146
}
147
147
148
- bool FHelper::SetProperty (class UObjectProperty *prop, py::object val) {
149
- if (!py::isinstance<UObject>(val))
150
- return false ;
148
+ void FHelper::SetProperty (class UObjectProperty *prop, py::object val) {
149
+ if (!py::isinstance<UObject>(val) && !py::isinstance<py::none>(val) )
150
+ throw std::exception ( Util::Format ( " FHelper::SetProperty: Got unexpected type, expected UObject! \n " ). c_str ()) ;
151
151
((UObject **)(((char *)this ) + prop->Offset_Internal ))[0 ] = val.cast <UObject *>();
152
- return true ;
153
152
}
154
153
155
- bool FHelper::SetProperty (class UComponentProperty *prop, py::object val) {
156
- if (!py::isinstance<UComponent>(val))
157
- return false ;
154
+ void FHelper::SetProperty (class UComponentProperty *prop, py::object val) {
155
+ if (!py::isinstance<UComponent>(val) && !py::isinstance<py::none>(val) )
156
+ throw std::exception ( Util::Format ( " FHelper::SetProperty: Got unexpected type, expected UComponent! \n " ). c_str ()) ;
158
157
((UComponent **)(((char *)this ) + prop->Offset_Internal ))[0 ] = val.cast <UComponent *>();
159
- return true ;
160
158
}
161
159
162
- bool FHelper::SetProperty (class UClassProperty *prop, py::object val) {
163
- if (!py::isinstance<UClass>(val))
164
- return false ;
160
+ void FHelper::SetProperty (class UClassProperty *prop, py::object val) {
161
+ if (!py::isinstance<UClass>(val) && !py::isinstance<py::none>(val) )
162
+ throw std::exception ( Util::Format ( " FHelper::SetProperty: Got unexpected type, expected UClass! \n " ). c_str ()) ;
165
163
((UClass **)(((char *)this ) + prop->Offset_Internal ))[0 ] = val.cast <UClass *>();
166
- return true ;
167
164
}
168
165
169
- bool FHelper::SetProperty (class UNameProperty *prop, py::object val) {
166
+ void FHelper::SetProperty (class UNameProperty *prop, py::object val) {
170
167
if (!py::isinstance<py::str>(val))
171
- return false ;
168
+ throw std::exception ( Util::Format ( " FHelper::SetProperty: Got unexpected type, expected string! \n " ). c_str ()) ;
172
169
memcpy (((char *)this ) + prop->Offset_Internal , &FName (val.cast <std::string>().c_str ()), sizeof (FName));
173
- return true ;
174
170
}
175
171
176
- bool FHelper::SetProperty (class UInterfaceProperty *prop, py::object val) {
177
- if (!py::isinstance<UInterface>(val))
178
- return false ;
179
- ((UInterface **)(((char *)this ) + prop->Offset_Internal ))[0 ] = val.cast <UInterface *>();
180
- return true ;
172
+ void FHelper::SetProperty (class UInterfaceProperty *prop, py::object val) {
173
+ if (!py::isinstance<UObject>(val) && !py::isinstance<py::none>(val))
174
+ throw std::exception (Util::Format (" FHelper::SetProperty: Got unexpected type, expected UObject!\n " ).c_str ());
175
+ if (py::isinstance<py::none>(val))
176
+ ((FScriptInterface *)(((char *)this ) + prop->Offset_Internal ))[0 ] = FScriptInterface{0 , 0 };
177
+ else {
178
+ UObject *ObjVal = val.cast <UObject *>();
179
+ FScriptInterface interf = ObjVal->QueryInterface (prop->GetInterfaceClass ());
180
+ ((FScriptInterface *)(((char *)this ) + prop->Offset_Internal ))[0 ] = interf;
181
+ }
181
182
}
182
183
183
- bool FHelper::SetProperty (class UDelegateProperty *prop, py::object val) {
184
+ void FHelper::SetProperty (class UDelegateProperty *prop, py::object val) {
184
185
if (!py::isinstance<FScriptDelegate>(val))
185
- return false ;
186
+ throw std::exception ( Util::Format ( " FHelper::SetProperty: Got unexpected type, expected FScriptDelegate! \n " ). c_str ()) ;
186
187
memcpy (((char *)this ) + prop->Offset_Internal , &FScriptDelegate (val.cast <FScriptDelegate>()), sizeof (FScriptDelegate));
187
- return true ;
188
188
}
189
189
190
- bool FHelper::SetProperty (class UFloatProperty *prop, py::object val) {
190
+ void FHelper::SetProperty (class UFloatProperty *prop, py::object val) {
191
191
Logging::LogD (" Set %f\n " , val.cast <float >());
192
192
((float *)(((char *)this ) + prop->Offset_Internal ))[0 ] = val.cast <float >();
193
- return true ;
194
193
}
195
194
196
- bool FHelper::SetProperty (class UIntProperty *prop, py::object val) {
195
+ void FHelper::SetProperty (class UIntProperty *prop, py::object val) {
197
196
if (!py::isinstance<py::int_>(val))
198
- return false ;
197
+ throw std::exception ( Util::Format ( " FHelper::SetProperty: Got unexpected type, expected int! \n " ). c_str ()) ;
199
198
((int *)(((char *)this ) + prop->Offset_Internal ))[0 ] = val.cast <int >();
200
- return true ;
201
199
}
202
200
203
- bool FHelper::SetProperty (class UByteProperty *prop, py::object val) {
204
- if (!py::isinstance<int >(val) && val. cast < int >() <= 255 )
205
- return false ;
201
+ void FHelper::SetProperty (class UByteProperty *prop, py::object val) {
202
+ if (!py::isinstance<py::int_ >(val))
203
+ throw std::exception ( Util::Format ( " FHelper::SetProperty: Got unexpected type, expected (char! \n " ). c_str ()) ;
206
204
(((char *)this ) + prop->Offset_Internal )[0 ] = (char )val.cast <int >();
207
- return true ;
208
205
}
209
206
210
- bool FHelper::SetProperty (class UBoolProperty *prop, py::object val) {
207
+ void FHelper::SetProperty (class UBoolProperty *prop, py::object val) {
211
208
try {
212
209
Logging::LogD (" SetBoolProperty %d, mask: 0x%x, base: 0x%x, offset: 0x%x\n " , val.cast <bool >(), prop->GetMask (), this , prop->Offset_Internal );
213
210
if (val.cast <bool >())
@@ -216,60 +213,59 @@ bool FHelper::SetProperty(class UBoolProperty *prop, py::object val) {
216
213
((unsigned int *)(((char *)this ) + prop->Offset_Internal ))[0 ] &= ~prop->GetMask ();
217
214
}
218
215
catch (std::exception e) {
219
- Logging::LogF ( e.what ());
216
+ throw std::exception ( Util::Format ( " FHelper::SetProperty: %s \n " , e.what ()). c_str ());
220
217
}
221
- return true ;
222
218
}
223
219
224
- bool FHelper::SetProperty (class UArrayProperty *prop, py::object val) {
220
+ void FHelper::SetProperty (class UArrayProperty *prop, py::object val) {
225
221
if (!py::isinstance<py::sequence>(val))
226
- return false ;
222
+ throw std::exception ( Util::Format ( " FHelper::SetProperty: Got unexpected type, expected list! \n " ). c_str ()) ;
227
223
auto s = py::reinterpret_borrow<py::sequence>(val);
228
- Logging::LogD (" A\n " );
229
- char *Data = (char *)((tMalloc)BL2SDK::pGMalloc[0 ]->VfTable [1 ])(BL2SDK::pGMalloc[0 ], prop->GetInner ()->ElementSize * s.size (), 8 );
230
- Logging::LogD (" C %d %d %p %p %d %p\n " , prop->GetInner ()->ElementSize , prop->Offset_Internal , this , Data, s.size (), (TArray<void *> *)(((char *)this ) + prop->Offset_Internal ));
231
- memset (Data, 0 , prop->GetInner ()->ElementSize * s.size ());
232
- ((TArray<void *> *)(((char *)this ) + prop->Offset_Internal ))->Data = (void **)Data;
233
- ((TArray<void *> *)(((char *)this ) + prop->Offset_Internal ))->Count = s.size ();
234
- ((TArray<void *> *)(((char *)this ) + prop->Offset_Internal ))->Max = s.size ();
224
+ if (s.size () > ((TArray<void *> *)(((char *)this ) + prop->Offset_Internal ))->Count ) {
225
+ char *Data = (char *)((tMalloc)BL2SDK::pGMalloc[0 ]->VfTable [1 ])(BL2SDK::pGMalloc[0 ], prop->GetInner ()->ElementSize * s.size (), 8 );
226
+ memset (Data, 0 , prop->GetInner ()->ElementSize * s.size ());
227
+ ((TArray<char > *)(((char *)this ) + prop->Offset_Internal ))->Data = Data;
228
+ ((TArray<char > *)(((char *)this ) + prop->Offset_Internal ))->Max = s.size ();
229
+ }
230
+ ((TArray<char > *)(((char *)this ) + prop->Offset_Internal ))->Count = s.size ();
231
+ char *Data = ((TArray<char > *)(((char *)this ) + prop->Offset_Internal ))->Data ;
235
232
int x = 0 ;
236
233
for (auto it : val) {
237
- Logging::LogD (" %x\n " , (Data + prop->GetInner ()->ElementSize * x));
238
234
((FHelper *)(Data + prop->GetInner ()->ElementSize * x++))->SetProperty (prop->GetInner (), py::reinterpret_borrow<py::object>(it));
239
235
}
240
- return true ;
241
236
}
242
237
243
- bool FHelper::SetProperty (class UProperty *prop, py::object val) {
238
+ void FHelper::SetProperty (class UProperty *prop, py::object val) {
244
239
Logging::LogD (" FHelper::SetProperty Called with '%s'\n " , prop->GetFullName ().c_str ());
240
+ bool ret = false ;
245
241
if (!strcmp (prop->Class ->GetName ().c_str (), " StructProperty" ))
246
- return SetProperty ((UStructProperty *)prop, val);
242
+ SetProperty ((UStructProperty *)prop, val);
247
243
else if (!strcmp (prop->Class ->GetName ().c_str (), " StrProperty" ))
248
- return SetProperty ((UStrProperty *)prop, val);
244
+ SetProperty ((UStrProperty *)prop, val);
249
245
else if (!strcmp (prop->Class ->GetName ().c_str (), " ObjectProperty" ))
250
- return SetProperty ((UObjectProperty *)prop, val);
246
+ SetProperty ((UObjectProperty *)prop, val);
251
247
else if (!strcmp (prop->Class ->GetName ().c_str (), " ComponentProperty" ))
252
- return SetProperty ((UComponentProperty *)prop, val);
248
+ SetProperty ((UComponentProperty *)prop, val);
253
249
else if (!strcmp (prop->Class ->GetName ().c_str (), " ClassProperty" ))
254
- return SetProperty ((UClassProperty *)prop, val);
250
+ SetProperty ((UClassProperty *)prop, val);
255
251
else if (!strcmp (prop->Class ->GetName ().c_str (), " NameProperty" ))
256
- return SetProperty ((UNameProperty *)prop, val);
252
+ SetProperty ((UNameProperty *)prop, val);
257
253
else if (!strcmp (prop->Class ->GetName ().c_str (), " IntProperty" ))
258
- return SetProperty ((UIntProperty *)prop, val);
254
+ SetProperty ((UIntProperty *)prop, val);
259
255
else if (!strcmp (prop->Class ->GetName ().c_str (), " InterfaceProperty" ))
260
- return SetProperty ((UInterfaceProperty *)prop, val);
256
+ SetProperty ((UInterfaceProperty *)prop, val);
261
257
else if (!strcmp (prop->Class ->GetName ().c_str (), " FloatProperty" ))
262
- return SetProperty ((UFloatProperty *)prop, val);
258
+ SetProperty ((UFloatProperty *)prop, val);
263
259
else if (!strcmp (prop->Class ->GetName ().c_str (), " DelegateProperty" ))
264
- return SetProperty ((UDelegateProperty *)prop, val);
260
+ SetProperty ((UDelegateProperty *)prop, val);
265
261
else if (!strcmp (prop->Class ->GetName ().c_str (), " ByteProperty" ))
266
- return SetProperty ((UByteProperty *)prop, val);
262
+ SetProperty ((UByteProperty *)prop, val);
267
263
else if (!strcmp (prop->Class ->GetName ().c_str (), " BoolProperty" ))
268
- return SetProperty ((UBoolProperty *)prop, val);
264
+ SetProperty ((UBoolProperty *)prop, val);
269
265
else if (!strcmp (prop->Class ->GetName ().c_str (), " ArrayProperty" ))
270
- return SetProperty ((UArrayProperty *)prop, val);
271
- throw std::exception ( Util::Format ( " FHelper::SetProperty got unexpected property type '%s' " , prop-> GetFullName (). c_str ()). c_str ());
272
- return false ;
266
+ SetProperty ((UArrayProperty *)prop, val);
267
+ else
268
+ throw std::exception ( Util::Format ( " FHelper::SetProperty got unexpected property type '%s' " , prop-> GetFullName (). c_str ()). c_str ()) ;
273
269
}
274
270
275
271
TArray< UObject* >* UObject::GObjects ()
@@ -429,15 +425,21 @@ pybind11::object UObject::GetProperty(std::string PropName) {
429
425
return pybind11::none ();
430
426
}
431
427
432
- bool UObject::SetProperty (std::string& PropName, py::object val) {
428
+ void UObject::SetProperty (std::string& PropName, py::object val) {
433
429
class UObject *obj = this ->Class ->FindChildByName (FName (PropName));
434
430
if (!obj)
435
- return false ;
431
+ return ;
436
432
auto prop = reinterpret_cast <UProperty *>(obj);
437
433
if (!strcmp (obj->Class ->GetName ().c_str (), " Function" ))
438
- return ((FHelper *)((char *)this ))->SetProperty ((UObjectProperty *)prop, val);
434
+ ((FHelper *)((char *)this ))->SetProperty ((UObjectProperty *)prop, val);
439
435
else
440
- return ((FHelper *)((char *)this ))->SetProperty (prop, val);
436
+ ((FHelper *)((char *)this ))->SetProperty (prop, val);
437
+ if (BL2SDK::CallPostEdit) {
438
+ FPropertyChangedEvent ChangeEvent{};
439
+ ChangeEvent.Property = prop;
440
+ ChangeEvent.ChangeType = 1 ;
441
+ PostEditChangeProperty (&ChangeEvent);
442
+ }
441
443
}
442
444
443
445
@@ -3865,7 +3867,7 @@ FScriptInterface UObject::QueryInterface(class UClass* InterfaceClass)
3865
3867
{
3866
3868
static auto fn = (UFunction *)UObject::Find (" Function" , " Core.Object.QueryInterface" );
3867
3869
3868
- UObject_QueryInterface_Params params;
3870
+ struct UObject_QueryInterface_Params params;
3869
3871
params.InterfaceClass = InterfaceClass;
3870
3872
3871
3873
auto flags = fn->FunctionFlags ;
0 commit comments