-
Notifications
You must be signed in to change notification settings - Fork 29
/
UObject.h
673 lines (632 loc) · 19.4 KB
/
UObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
#ifndef UOBJECT_H
#define UOBJECT_H
#include <vector>
#include <string>
#include <iostream>
#include <utility>
#include "UPKInfo.h"
#include "CustomTFC.h"
#define LOD_BIAS_BAD 100500
/// global type enumeration
enum class GlobalType
{
None = 0,
UObject = 1,
UField = 2,
UConst = 3,
UEnum = 4,
UProperty = 5,
UByteProperty = 6,
UIntProperty = 7,
UBoolProperty = 8,
UFloatProperty = 9,
UObjectProperty = 10,
UClassProperty = 11,
UNameProperty = 12,
UStructProperty = 13,
UStrProperty = 14,
UArrayProperty = 15,
UStruct = 16,
UScriptStruct = 17,
UFunction = 18,
UState = 19,
UClass = 20,
UTextBuffer = 21,
UObjectUnknown = 22,
UFixedArrayProperty = 23,
UComponentProperty = 24,
UDelegateProperty = 25,
UInterfaceProperty = 26,
UMapProperty = 27,
ULevel = 28,
USurface = 29,
UTexture = 30,
UTexture2D = 31
};
/*///pixel format enums (Texture2D)
enum class EPixelFormat
{
PF_Unknown,
PF_A32B32G32R32F,
PF_A8R8G8B8,
PF_G8,
PF_G16,
PF_DXT1,
PF_DXT2,
PF_DXT3,
PF_DXT4,
PF_DXT5,
PF_UYVY,
PF_FloatRGB,
PF_FloatRGBA,
PF_DepthStencil,
PF_ShadowDepth,
PF_FilteredShadowDepth,
PF_R32F,
PF_G16R16,
PF_G16R16F,
PF_G32R32F,
PF_A2B10G10R10,
PF_A16B16G16R16,
PF_D24
};*/
class UBulkDataMirror
{
public:
UBulkDataMirror() {}
std::string Deserialize(std::istream& stream, UPKInfo& info, UObjectReference owner);
std::string Serialize();
std::string Serialize(uint32_t offset);
bool ExportToExternalFile(CustomTFC& T2DFile, std::string ObjName);
bool TryLzoCompression();
uint32_t CalculateSerializedSize();
///flags
bool IsDataCompressed();
bool IsDataStoredElsewhere();
bool IsDataEmpty();
bool GetDataFlag(UBulkDataFlags flg);
void SetDataFlag(UBulkDataFlags flg, bool val);
void ToggleDataFlag(UBulkDataFlags flg);
///setters
void SetEmpty();
void SetBulkDataRaw(std::vector<char> Data);
void SetBulkData(std::vector<char> Data) { BulkData = Data; }
void SetFileOffset(uint32_t offset) { SavedBulkDataOffsetInFile = offset; }
void SetSavedBulkDataFlags(uint32_t flags) { SavedBulkDataFlags = flags; }
void SetSavedElementCount(uint32_t elementCount) { SavedElementCount = elementCount; }
void SetExternalFileName(std::string filename) { externalFileName = filename; }
///getters
std::vector<char> GetBulkData() { return BulkData; }
uint32_t GetBulkDataRelOffset() { return 16; }
uint32_t GetSavedBulkDataFlags() { return SavedBulkDataFlags; }
uint32_t GetSavedElementCount() { return SavedElementCount; }
uint32_t GetSavedBulkDataSizeOnDisk() { return SavedBulkDataSizeOnDisk; }
uint32_t GetSavedBulkDataOffsetInFile() { return SavedBulkDataOffsetInFile; }
std::string GetExternalFileName() { return externalFileName; }
bool GetWasCompressed() { return WasCompressed; }
bool GetWasInExternalFile() { return WasInExternalFile; }
protected:
/// persistent
uint32_t SavedBulkDataFlags = 0;
uint32_t SavedElementCount = 0;
uint32_t SavedBulkDataSizeOnDisk = 0;
uint32_t SavedBulkDataOffsetInFile = 0xFFFFFFFF;
std::vector<char> BulkData;
/// memory
std::string externalFileName;
bool DoNotCompress = false;
bool LockFileOffset = false;
bool WasCompressed = false;
bool WasInExternalFile = false;
/// internal methods
bool ReadDataChunkFromExternalFile();
};
class UTexture2DMipMap : public UBulkDataMirror
{
public:
UTexture2DMipMap() {}
std::string Deserialize(std::istream& stream, UPKInfo& info, UObjectReference owner);
std::string Serialize(uint32_t offset);
uint32_t CalculateSerializedSize();
uint32_t GetSizeX() { return SizeX; }
uint32_t GetSizeY() { return SizeY; }
void SetSizeX(uint32_t x) { SizeX = x; }
void SetSizeY(uint32_t y) { SizeY = y; }
protected:
/// persistent
uint32_t SizeX = 0;
uint32_t SizeY = 0;
};
class UDefaultProperty
{
public:
/// constructors and destructors
UDefaultProperty(): Name("None"), Type("None"), OwnerRef(0), TryUnsafe(0), QuickMode(0) {}
~UDefaultProperty() {}
void Init(UObjectReference owner, bool unsafe = false, bool quick = false) { OwnerRef = owner; TryUnsafe = unsafe; QuickMode = quick; }
void MakeByteProperty(std::string name, std::string innerName, std::string value, UPKInfo& info);
void MakeNameProperty(std::string name, std::string value, UPKInfo& info);
void MakeIntProperty(std::string name, int32_t value, UPKInfo& info);
void MakeBoolProperty(std::string name, bool value, UPKInfo& info);
///serialization and deserialization
std::string Deserialize(std::istream& stream, UPKInfo& info, UObjectReference owner, bool unsafe = false, bool quick = false);
std::string DeserializeValue(std::istream& stream, UPKInfo& info);
std::string FindArrayType(std::string ArrName, std::istream& stream, UPKInfo& info);
std::string GuessArrayType(std::string ArrName);
std::string Serialize(UPKInfo& info);
std::string SerializeBatmanAC(UPKInfo& info);
///BatmanAC specific
std::string DeserializeBatmanAC(std::istream& stream, UPKInfo& info, UObjectReference owner, bool unsafe = false, bool quick = false);
/// getters
uint32_t GetInnerValueOffset(uint16_t ver = VER_XCOM);
std::string GetName() { return Name; }
std::string GetType() { return Type; }
UNameIndex GetValueNameIdx() { return valueNameIdx; }
uint32_t GetValueInt() { return valueInt; }
uint32_t GetValueBool() { return BoolValue; }
protected:
/// persistent
UNameIndex NameIdx;
UNameIndex TypeIdx;
uint32_t PropertySize;
uint32_t ArrayIdx;
uint8_t BoolValue; /// for BoolProperty only
uint32_t BoolValueOld; /// older engine versions (batman)
UNameIndex InnerNameIdx; /// for StructProperty and ByteProperty only
std::vector<char> InnerValue;
/// memory
std::string Name;
std::string Type;
UObjectReference OwnerRef;
bool TryUnsafe;
bool QuickMode;
/// possible values
int32_t valueInt = 0;
float valueFloat = 0;
UObjectReference valueObjRef;
UNameIndex valueNameIdx;
std::string valueString;
};
class UDefaultPropertiesList
{
public:
UDefaultPropertiesList() {}
~UDefaultPropertiesList() {}
std::string Deserialize(std::istream& stream, UPKInfo& info, UObjectReference owner, bool unsafe = false, bool quick = false);
std::vector<UDefaultProperty> GetDefaultProperties() { return DefaultProperties; }
protected:
std::vector<UDefaultProperty> DefaultProperties;
uint32_t PropertyOffset;
uint32_t PropertySize;
};
/// parent class of all Unreal objects
class UObject
{
public:
UObject(): Type(GlobalType::UObject), ThisRef(0), FlagsOffset(0), TryUnsafe(0), QuickMode(0) {}
virtual ~UObject() {}
virtual std::string Deserialize(std::istream& stream, UPKInfo& info);
void SetRef(UObjectReference thisRef) { ThisRef = thisRef; }
void SetUnsafe(bool val) { TryUnsafe = val; }
void SetQuickMode(bool val) { QuickMode = val; }
virtual bool IsStructure() { return false; }
virtual bool IsProperty() { return false; }
virtual bool IsState() { return false; }
void SetClassVarFromProperty(UDefaultProperty& property, UPKInfo& info) {}
uint32_t GetUObjExportEntrySize() { return UObjExportEntrySize; }
protected:
/// persistent
UObjectReference ObjRef; /// Next object (Linker-related)
UDefaultPropertiesList DefaultProperties; /// for non-Class objects only
/// memory
GlobalType Type;
UObjectReference ThisRef;
uint32_t FlagsOffset;
bool TryUnsafe;
bool QuickMode;
uint32_t UObjExportEntrySize = -1;
};
class UObjectNone: public UObject
{
public:
UObjectNone() { Type = GlobalType::None; }
~UObjectNone() {}
protected:
};
class UField: public UObject
{
public:
UField() { Type = GlobalType::UField; }
~UField() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
UObjectReference GetNextRef() { return NextRef; }
uint32_t GetNextRefOffset() { return NextRefOffset; }
protected:
/// persistent
UObjectReference NextRef;
UObjectReference ParentRef; /// for Struct objects only
/// memory
uint32_t FieldOffset;
uint32_t FieldSize;
uint32_t NextRefOffset;
};
class UStruct: public UField
{
public:
UStruct() { Type = GlobalType::UStruct; }
~UStruct() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
bool IsStructure() { return true; }
UObjectReference GetFirstChildRef() { return FirstChildRef; }
uint32_t GetScriptSerialSize() { return ScriptSerialSize; }
uint32_t GetScriptMemorySize() { return ScriptMemorySize; }
uint32_t GetScriptOffset() { return ScriptOffset; }
uint32_t GetFirstChildRefOffset() { return FirstChildRefOffset; }
protected:
/// persistent
UObjectReference ScriptTextRef;
UObjectReference FirstChildRef;
UObjectReference CppTextRef;
uint32_t Line;
uint32_t TextPos;
uint32_t ScriptMemorySize;
uint32_t ScriptSerialSize;
std::vector<char> DataScript;
/// memory
uint32_t StructOffset;
uint32_t StructSize;
uint32_t ScriptOffset;
uint32_t FirstChildRefOffset;
};
class UFunction: public UStruct
{
public:
UFunction() { Type = GlobalType::UFunction; }
~UFunction() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
uint16_t NativeToken;
uint8_t OperPrecedence;
uint32_t FunctionFlags;
uint16_t RepOffset;
UNameIndex NameIdx;
/// memory
uint32_t FunctionOffset;
uint32_t FunctionSize;
};
class UScriptStruct: public UStruct
{
public:
UScriptStruct() { Type = GlobalType::UScriptStruct; }
~UScriptStruct() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
uint32_t StructFlags;
UDefaultPropertiesList StructDefaultProperties;
/// memory
uint32_t ScriptStructOffset;
uint32_t ScriptStructSize;
};
class UState: public UStruct
{
public:
UState() { Type = GlobalType::UState; }
~UState() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
bool IsState() { return true; }
protected:
/// persistent
uint32_t ProbeMask;
uint16_t LabelTableOffset;
uint32_t StateFlags;
uint32_t StateMapSize;
std::vector<std::pair<UNameIndex, UObjectReference> > StateMap;
/// memory
uint32_t StateOffset;
uint32_t StateSize;
};
class UClass: public UState
{
public:
UClass() { Type = GlobalType::UClass; }
~UClass() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
uint32_t ClassFlags;
UObjectReference WithinRef;
UNameIndex ConfigNameIdx;
uint32_t NumComponents;
std::vector<std::pair<UNameIndex, UObjectReference> > Components;
uint32_t NumInterfaces;
std::vector<std::pair<UObjectReference, uint32_t> > Interfaces;
uint32_t NumDontSortCategories;
std::vector<UNameIndex> DontSortCategories;
uint32_t NumHideCategories;
std::vector<UNameIndex> HideCategories;
uint32_t NumAutoExpandCategories;
std::vector<UNameIndex> AutoExpandCategories;
uint32_t NumAutoCollapseCategories;
std::vector<UNameIndex> AutoCollapseCategories;
uint32_t ForceScriptOrder;
uint32_t NumClassGroups;
std::vector<UNameIndex> ClassGroups;
uint32_t NativeClassNameLength;
std::string NativeClassName;
UNameIndex DLLBindName;
UObjectReference DefaultRef;
};
class UConst: public UField
{
public:
UConst() { Type = GlobalType::UConst; }
~UConst() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
uint32_t ValueLength;
std::string Value;
};
class UEnum: public UField
{
public:
UEnum() { Type = GlobalType::UEnum; }
~UEnum() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
uint32_t NumNames;
std::vector<UNameIndex> Names;
};
class UProperty: public UField
{
public:
UProperty() { Type = GlobalType::UProperty; }
~UProperty() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
bool IsProperty() { return true; }
protected:
/// persistent
uint16_t ArrayDim;
uint16_t ElementSize;
uint32_t PropertyFlagsL;
uint32_t PropertyFlagsH;
UNameIndex CategoryIndex;
UObjectReference ArrayEnumRef;
uint16_t RepOffset;
};
class UByteProperty: public UProperty
{
public:
UByteProperty() { Type = GlobalType::UByteProperty; }
~UByteProperty() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
UObjectReference EnumObjRef;
};
class UIntProperty: public UProperty
{
public:
UIntProperty() { Type = GlobalType::UIntProperty; }
~UIntProperty() {}
protected:
};
class UBoolProperty: public UProperty
{
public:
UBoolProperty() { Type = GlobalType::UBoolProperty; }
~UBoolProperty() {}
protected:
};
class UFloatProperty: public UProperty
{
public:
UFloatProperty() { Type = GlobalType::UFloatProperty; }
~UFloatProperty() {}
protected:
};
class UObjectProperty: public UProperty
{
public:
UObjectProperty() { Type = GlobalType::UObjectProperty; }
~UObjectProperty() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
UObjectReference OtherObjRef;
};
class UClassProperty: public UObjectProperty
{
public:
UClassProperty() { Type = GlobalType::UClassProperty; }
~UClassProperty() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
UObjectReference ClassObjRef;
};
class UComponentProperty: public UObjectProperty
{
public:
UComponentProperty() { Type = GlobalType::UComponentProperty; }
~UComponentProperty() {}
protected:
};
class UNameProperty: public UProperty
{
public:
UNameProperty() { Type = GlobalType::UNameProperty; }
~UNameProperty() {}
protected:
};
class UStructProperty: public UProperty
{
public:
UStructProperty() { Type = GlobalType::UStructProperty; }
~UStructProperty() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
UObjectReference StructObjRef;
};
class UStrProperty: public UProperty
{
public:
UStrProperty() { Type = GlobalType::UStrProperty; }
~UStrProperty() {}
protected:
};
class UFixedArrayProperty: public UProperty
{
public:
UFixedArrayProperty() { Type = GlobalType::UFixedArrayProperty; }
~UFixedArrayProperty() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
UObjectReference InnerObjRef;
uint32_t Count;
};
class UArrayProperty: public UProperty
{
public:
UArrayProperty() { Type = GlobalType::UArrayProperty; }
~UArrayProperty() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
UObjectReference GetInner() { return InnerObjRef; }
protected:
/// persistent
UObjectReference InnerObjRef;
};
class UDelegateProperty: public UProperty
{
public:
UDelegateProperty() { Type = GlobalType::UDelegateProperty; }
~UDelegateProperty() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
UObjectReference FunctionObjRef;
UObjectReference DelegateObjRef;
};
class UInterfaceProperty: public UProperty
{
public:
UInterfaceProperty() { Type = GlobalType::UInterfaceProperty; }
~UInterfaceProperty() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
UObjectReference InterfaceObjRef;
};
class UMapProperty: public UProperty
{
public:
UMapProperty() { Type = GlobalType::UMapProperty; }
~UMapProperty() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// persistent
UObjectReference KeyObjRef;
UObjectReference ValueObjRef;
};
class ULevel: public UObject
{
public:
ULevel() { Type = GlobalType::ULevel; }
~ULevel() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
/// database
std::vector<UObjectReference> Actors;
};
class USurface: public UObject
{
public:
USurface() {}
~USurface() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
};
class UTexture: public USurface
{
public:
UTexture() {}
~UTexture() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
};
class UTexture2D: public UTexture
{
public:
///constructors and destructors
UTexture2D() {}
~UTexture2D() {}
///serialization
std::string Deserialize(std::istream& stream, UPKInfo& info);
std::string SerializeTexture2DData(uint32_t offset);
bool TryLzoCompression(int minResolution = -1);
bool ExportToExternalFile(CustomTFC& T2DFile, UPKInfo& info, bool compressedOnly = true);
uint32_t CalculateTexture2DDataSize();
///getters
std::vector<UTexture2DMipMap> GetMipMaps() { return MipMaps; }
uint32_t GetHeight() { return Height; }
uint32_t GetWidth() { return Width; }
uint32_t GetMipMapCount() { return MipMapCount; }
uint32_t GetPitchOrLinearSize() { return PitchOrLinearSize; }
std::string GetPixelFormat() { return Format; }
std::string GetTextureFileCacheName() { return TextureFileCacheName; }
bool GetNeverStream() { return NeverStream; }
bool GetDoNotReadTFC() { return DoNotReadTFC; }
bool GetHasCompressedMipMaps() { return HasCompressedMipMaps; }
int GetMinObservedResForCompression() { return MinObservedResForCompression; }
int GetNumEmptyMipMaps() { return NumEmptyMipMaps; }
int GetNumTFCMipMaps() { return NumTFCMipMaps; }
///setters
void SetMipMaps(std::vector<UTexture2DMipMap> mmaps) { MipMaps = mmaps; }
void SetHeight(uint32_t h) { Height = h; }
void SetWidth(uint32_t w) { Width = w; }
void SetMipMapCount(uint32_t cnt) { MipMapCount = cnt; }
void SetPitchOrLinearSize(uint32_t sz) { PitchOrLinearSize = sz; }
void SetPixelFormat(std::string fmt) { Format = fmt; }
void SetTextureFileCacheName(std::string tfcName) { TextureFileCacheName = tfcName; }
void SetNeverStream(bool ns) { NeverStream = ns; }
void SetDoNotReadTFC(bool val) { DoNotReadTFC = val; }
protected:
uint32_t Height = 0;
uint32_t Width = 0;
uint32_t MipTailBaseIdx = 0;
std::string Format; ///actually an enum
std::string LODGroup; ///actually an enum
int LODBias = 0;
bool NeverStream = false;
std::string TextureFileCacheName;
uint32_t PitchOrLinearSize = 0;
uint32_t MipMapCount = 0;
std::vector<UTexture2DMipMap> MipMaps;
///unknown data
uint32_t Unknown1 = 0;
uint32_t Unknown2 = 0;
uint32_t Unknown3 = 0;
std::vector<char> UnknownData;
///memory vars
bool DoNotReadTFC = false;
bool HasCompressedMipMaps = false;
int MinObservedResForCompression = -1;
int NumEmptyMipMaps = 0;
int NumTFCMipMaps = -1; ///BAC: number of high-res mipmaps stored in external tfc
///internal methods
void SetClassVarFromProperty(UDefaultProperty& property, UPKInfo& info);
};
class UObjectUnknown: public UObject
{
public:
UObjectUnknown() { Type = GlobalType::UObjectUnknown; }
~UObjectUnknown() {}
std::string Deserialize(std::istream& stream, UPKInfo& info);
protected:
};
#endif // UOBJECT_H