-
Notifications
You must be signed in to change notification settings - Fork 281
/
Copy pathIoStoreDefines.h
354 lines (301 loc) · 8.01 KB
/
IoStoreDefines.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
#pragma once
#include "CoreMinimal.h"
#include "CommonDefines.h"
#if ENABLE_IO_STORE_ANALYZER
#include "IO/IoDispatcher.h"
#include "IO/IoContainerHeader.h"
#include "Serialization/AsyncLoading2.h"
#include "IO/PackageStore.h"
#include "PakFileEntry.h"
/**
* I/O store container format version
*/
enum class EIoStoreTocVersion : uint8
{
Invalid = 0,
Initial,
DirectoryIndex,
PartitionSize,
PerfectHash,
PerfectHashWithOverflow,
OnDemandMetaData,
RemovedOnDemandMetaData,
ReplaceIoChunkHashWithIoHash,
LatestPlusOne,
Latest = LatestPlusOne - 1
};
/**
* I/O Store TOC header.
*/
struct FIoStoreTocHeader
{
static constexpr char TocMagicImg[] = "-==--==--==--==-";
uint8 TocMagic[16];
uint8 Version;
uint8 Reserved0 = 0;
uint16 Reserved1 = 0;
uint32 TocHeaderSize;
uint32 TocEntryCount;
uint32 TocCompressedBlockEntryCount;
uint32 TocCompressedBlockEntrySize; // For sanity checking
uint32 CompressionMethodNameCount;
uint32 CompressionMethodNameLength;
uint32 CompressionBlockSize;
uint32 DirectoryIndexSize;
uint32 PartitionCount = 0;
FIoContainerId ContainerId;
FGuid EncryptionKeyGuid;
EIoContainerFlags ContainerFlags;
uint8 Reserved3 = 0;
uint16 Reserved4 = 0;
uint32 TocChunkPerfectHashSeedsCount = 0;
uint64 PartitionSize = 0;
uint32 TocChunksWithoutPerfectHashCount = 0;
uint32 Reserved7 = 0;
uint64 Reserved8[5] = { 0 };
void MakeMagic()
{
FMemory::Memcpy(TocMagic, TocMagicImg, sizeof TocMagic);
}
bool CheckMagic() const
{
return FMemory::Memcmp(TocMagic, TocMagicImg, sizeof TocMagic) == 0;
}
};
/**
* Compression block entry.
*/
struct FIoStoreTocCompressedBlockEntry
{
static constexpr uint32 OffsetBits = 40;
static constexpr uint64 OffsetMask = (1ull << OffsetBits) - 1ull;
static constexpr uint32 SizeBits = 24;
static constexpr uint32 SizeMask = (1 << SizeBits) - 1;
static constexpr uint32 SizeShift = 8;
inline uint64 GetOffset() const
{
const uint64* Offset = reinterpret_cast<const uint64*>(Data);
return *Offset & OffsetMask;
}
inline void SetOffset(uint64 InOffset)
{
uint64* Offset = reinterpret_cast<uint64*>(Data);
*Offset = InOffset & OffsetMask;
}
inline uint32 GetCompressedSize() const
{
const uint32* Size = reinterpret_cast<const uint32*>(Data) + 1;
return (*Size >> SizeShift) & SizeMask;
}
inline void SetCompressedSize(uint32 InSize)
{
uint32* Size = reinterpret_cast<uint32*>(Data) + 1;
*Size |= (uint32(InSize) << SizeShift);
}
inline uint32 GetUncompressedSize() const
{
const uint32* UncompressedSize = reinterpret_cast<const uint32*>(Data) + 2;
return *UncompressedSize & SizeMask;
}
inline void SetUncompressedSize(uint32 InSize)
{
uint32* UncompressedSize = reinterpret_cast<uint32*>(Data) + 2;
*UncompressedSize = InSize & SizeMask;
}
inline uint8 GetCompressionMethodIndex() const
{
const uint32* Index = reinterpret_cast<const uint32*>(Data) + 2;
return static_cast<uint8>(*Index >> SizeBits);
}
inline void SetCompressionMethodIndex(uint8 InIndex)
{
uint32* Index = reinterpret_cast<uint32*>(Data) + 2;
*Index |= uint32(InIndex) << SizeBits;
}
private:
/* 5 bytes offset, 3 bytes for size / uncompressed size and 1 byte for compresseion method. */
uint8 Data[5 + 3 + 3 + 1];
};
/**
* Combined offset and length.
*/
struct FIoOffsetAndLength
{
public:
inline uint64 GetOffset() const
{
return OffsetAndLength[4]
| (uint64(OffsetAndLength[3]) << 8)
| (uint64(OffsetAndLength[2]) << 16)
| (uint64(OffsetAndLength[1]) << 24)
| (uint64(OffsetAndLength[0]) << 32)
;
}
inline uint64 GetLength() const
{
return OffsetAndLength[9]
| (uint64(OffsetAndLength[8]) << 8)
| (uint64(OffsetAndLength[7]) << 16)
| (uint64(OffsetAndLength[6]) << 24)
| (uint64(OffsetAndLength[5]) << 32)
;
}
inline void SetOffset(uint64 Offset)
{
OffsetAndLength[0] = uint8(Offset >> 32);
OffsetAndLength[1] = uint8(Offset >> 24);
OffsetAndLength[2] = uint8(Offset >> 16);
OffsetAndLength[3] = uint8(Offset >> 8);
OffsetAndLength[4] = uint8(Offset >> 0);
}
inline void SetLength(uint64 Length)
{
OffsetAndLength[5] = uint8(Length >> 32);
OffsetAndLength[6] = uint8(Length >> 24);
OffsetAndLength[7] = uint8(Length >> 16);
OffsetAndLength[8] = uint8(Length >> 8);
OffsetAndLength[9] = uint8(Length >> 0);
}
private:
// We use 5 bytes for offset and size, this is enough to represent
// an offset and size of 1PB
uint8 OffsetAndLength[5 + 5];
};
enum class FIoStoreTocEntryMetaFlags : uint8
{
None,
Compressed = (1 << 0),
MemoryMapped = (1 << 1)
};
ENUM_CLASS_FLAGS(FIoStoreTocEntryMetaFlags);
/**
* TOC entry meta data
*/
struct FIoStoreTocEntryMeta
{
// Source data hash (i.e. not the on disk data)
FIoHash ChunkHash;
FIoStoreTocEntryMetaFlags Flags = FIoStoreTocEntryMetaFlags::None;
uint8 Pad[3] = { 0 };
};
/**
* Container TOC data.
*/
struct FIoStoreTocResourceInfo
{
enum { CompressionMethodNameLen = 32 };
FIoStoreTocHeader Header;
int64 TocFileSize = 0;
TArray<FIoChunkId> ChunkIds;
TArray<FIoOffsetAndLength> ChunkOffsetLengths; // Added field
TArray<int32> ChunkPerfectHashSeeds; // Used for Perfect Hash lookups
TArray<int32> ChunkIndicesWithoutPerfectHash; // Fallback lookup
TArray<FIoStoreTocCompressedBlockEntry> CompressionBlocks;
TArray<FName> CompressionMethods;
FSHAHash SignatureHash; // Added field
TArray<FSHAHash> ChunkBlockSignatures;
TArray<uint8> DirectoryIndexBuffer;
TArray<FIoStoreTocEntryMeta> ChunkMetas;
static int32 HashChunkIdWithSeed(const FIoChunkId& ChunkId, const TArray<int32>& Seeds)
{
if (Seeds.Num() == 0)
{
return INDEX_NONE;
}
uint32 HashValue = GetTypeHash(ChunkId); // Hash the chunk ID
return HashValue % Seeds.Num(); // Get index using modulus
}
};
struct FScriptObjectDesc
{
FName Name;
FName FullName;
FPackageObjectIndex GlobalImportIndex;
FPackageObjectIndex OuterIndex;
};
struct FPackageStoreExportEntry
{
FPackageStoreExportEntry(const FFilePackageStoreEntry& InEntry)
//: ExportBundlesSize(InEntry.ExportBundlesSize)
// : ExportCount(InEntry.ExportCount)
// , ExportBundleCount(InEntry.ExportBundleCount)
//, LoadOrder(InEntry.LoadOrder)
//, Pad(InEntry.Pad)
{
DependencyPackages.SetNum(InEntry.ImportedPackages.Num());
for (uint32 i = 0; i < InEntry.ImportedPackages.Num(); ++i)
{
DependencyPackages[i] = InEntry.ImportedPackages[i];
}
}
//uint64 ExportBundlesSize = 0;
int32 ExportCount = 0;
int32 ExportBundleCount = 0;
//uint32 LoadOrder = 0;
//uint32 Pad = 0;
TArray<FPackageId> DependencyPackages;
};
struct FContainerInfo
{
FIoContainerId Id;
FGuid EncryptionKeyGuid;
bool bCompressed;
bool bSigned;
bool bEncrypted;
bool bIndexed;
FPakFileSumary Summary;
TSharedPtr<FIoStoreReader> Reader;
TMap<FPackageId, FPackageStoreExportEntry> StoreEntryMap;
};
struct FIoStoreExport
{
FName Name;
FName FullName;
uint64 PublicExportHash = 0;
FPackageObjectIndex OuterIndex;
FPackageObjectIndex ClassIndex;
FPackageObjectIndex SuperIndex;
FPackageObjectIndex TemplateIndex;
//FPackageObjectIndex GlobalImportIndex;
uint64 SerialOffset = 0;
uint64 SerialSize = 0;
EObjectFlags ObjectFlags = EObjectFlags::RF_NoFlags;
EExportFilterFlags FilterFlags = EExportFilterFlags::None;
struct FStorePackageInfo* Package = nullptr;
};
struct FIoStoreImport
{
FName Name;
FPackageObjectIndex GlobalImportIndex;
};
struct FStorePackageInfo
{
FName PackageName;
FPackageId PackageId;
int32 ContainerIndex;
FIoChunkId ChunkId;
EIoChunkType ChunkType;
FIoStoreTocChunkInfo ChunkInfo;
uint32 CookedHeaderSize = 0;
uint32 SerializeSize = 0;
uint32 CompressionBlockSize = 0;
uint32 CompressionBlockCount = 0;
FName CompressionMethod;
FString ChunkHash;
FName Extension;
TArray<FIoStoreImport> Imports;
TArray<FIoStoreExport> Exports;
FAssetSummaryPtr AssetSummary;
TArray<FPackageId> DependencyPackages;
FName DefaultClassName;
TArray<uint64> ImportedPublicExportHashes;
inline bool operator ==(const FStorePackageInfo& Rhs) const
{
return ChunkId == Rhs.ChunkId;
}
inline bool operator !=(const FStorePackageInfo& Rhs) const
{
return !(*this == Rhs);
}
};
#endif // ENABLE_IO_STORE_ANALYZER