private void Clear() { VersionHash = default; DepHash1 = default; DepHash2 = default; DepNop = default; StrUnknown1 = default; PtrN = default; Data = default; Dependencies.Clear(); NestedChunks.Clear(); DataChunks.Clear(); Strings.Clear(); }
private void ReadChunk(ILoader loader, BinaryReader br) { long initialPos = br.BaseStream.Position; string fourcc = Encoding.ASCII.GetString(BitConverter.GetBytes(br.ReadInt32()).Flip()); int size = br.ReadInt32(); switch (fourcc) { case "Vers": VersionHash = br.ReadUInt64(); break; case "DepN": long entryCount = br.ReadInt64(); DepHash1 = br.ReadUInt64(); DepHash2 = br.ReadUInt64(); DepNop = br.ReadInt32(); int sz = br.ReadInt32(); for (long i = 0; i < entryCount; i++) { string name = br.ReadLenString(sz); Dependencies.Add(name); } break; case "StrN": StrUnknown1 = br.ReadInt64(); break; case "DatN": // Handled in ExpN break; case "ExpN": long nestedChunkCount = br.ReadInt64(); for (long i = 0; i < nestedChunkCount; i++) { NestedChunk chunk = new NestedChunk(); chunk.Hash = br.ReadUInt64(); chunk.EntryTypeHash = br.ReadUInt64(); chunk.DataChunkSize = br.ReadInt32(); chunk.DataChunkPosition = br.ReadInt32(); NestedChunks.Add(chunk); long pos = br.BaseStream.Position; br.BaseStream.Position = chunk.DataChunkPosition; if (chunk.EntryTypeHash == 0xAD303B8F42B3307E) { DataChunk dataChunk = new DataChunk(); dataChunk.CollectionHash = br.ReadUInt64(); dataChunk.ClassHash = br.ReadUInt64(); dataChunk.Unknown1 = br.ReadBytes(8); dataChunk.ItemCount = br.ReadInt32(); dataChunk.Unknown2 = br.ReadInt32(); dataChunk.ItemCountDup = br.ReadInt32(); dataChunk.ParameterCount = br.ReadInt16(); dataChunk.ParametersToRead = br.ReadInt16(); dataChunk.Unknown3 = br.ReadBytes(8); dataChunk.ParameterTypeHashes = new ulong[dataChunk.ParameterCount]; for (int j = 0; j < dataChunk.ParameterCount; j++) { dataChunk.ParameterTypeHashes[j] = br.ReadUInt64(); } for (int j = 0; j < (dataChunk.ParametersToRead - dataChunk.ParameterCount); j++) { br.ReadUInt64(); // zero } dataChunk.Items = new DataItem[dataChunk.ItemCount]; for (int j = 0; j < dataChunk.ItemCount; j++) { DataItem item = new DataItem(); item.Hash = br.ReadUInt64(); item.Unknown1 = br.ReadBytes(4); item.ParameterIdx = br.ReadInt16(); item.Unknown2 = br.ReadInt16(); } DataChunks.Add(dataChunk); } else { throw new ReadFailedError("Unknown entry type: " + chunk.EntryTypeHash); } br.BaseStream.Position = pos; } break; case "PtrN": // Unknown int dataSize = size - 8; PtrN = new PtrChunk(); PtrN.Mode1Data = new List <PtrChunkData>(); PtrN.Mode2Data = new List <PtrChunkData>(); bool mode1 = false; for (int i = 0; i < dataSize / 16; i++) { PtrChunkData data = new PtrChunkData(); data.Ptr = br.ReadUInt32(); short type = br.ReadInt16(); short flag = br.ReadInt16(); data.Data = br.ReadUInt64(); if (type == 2) { mode1 = (flag == 1); } else if (type == 0) { break; } else if (type == 3) { if (mode1) { PtrN.Mode1Data.Add(data); } else { PtrN.Mode2Data.Add(data); } } else { throw new ReadFailedError("Unknown PtrN type: " + type); } } break; /*case "StrE": // In Binary Section?? * String1 = br.ReadCString(); * String2 = br.ReadCString(); * ExhastID = br.ReadCString(); * String4 = br.ReadCString(); * break;*/ default: throw new ReadFailedError("Unknown Chunk: " + fourcc); } br.BaseStream.Position = initialPos + size; /*long pos = br.BaseStream.Position; * * if (pos % 16 != 0) * { * pos += pos % 16; * br.BaseStream.Position = pos; * }*/ }