private void Read(StreamPart streamFile, string name) { GetType(streamFile); int index = 0; streamFile.Stream.Position = streamFile.Position; using (BinaryReader reader = IOTools.OpenReadFile(streamFile.Stream, IsLittleEndian)) do { int Size = reader.ReadInt32(); if (streamFile.Position + streamFile.Size < Size + streamFile.Stream.Position) { throw new Exception("TBL error"); } byte[] tempdata = reader.ReadBytes(Size); FormatEnum fileType = GameFormatHelper.GetFormat(tempdata); string ext = Path.GetExtension(name); string tempName = name.Substring(0, name.Length - ext.Length) + "(" + index++.ToString().PadLeft(2, '0') + ")"; if (fileType == FormatEnum.Unknown) { tempName += ".DAT"; } else { tempName += "." + fileType.ToString(); } SubFiles.Add(GameFormatHelper.OpenFile(tempName, tempdata, fileType == FormatEnum.Unknown ? FormatEnum.DAT : fileType)); reader.BaseStream.Position += IOTools.Alignment(reader.BaseStream.Position - streamFile.Position, 16); } while (streamFile.Stream.Position < streamFile.Position + streamFile.Size); }
public void SetName(string name) { foreach (var a in SubFiles) { FormatEnum fileType = a.GameData.Type; string ext = Path.GetExtension(name); if (fileType == FormatEnum.DAT) { a.Name = name.Substring(0, name.Length - ext.Length) + "(" + ((int)a.Tag).ToString().PadLeft(2, '0') + ").DAT"; } else { a.Name = name.Substring(0, name.Length - ext.Length) + "." + fileType.ToString(); } } }
private void Open(Stream stream) { stream.Position = 0x10; if (stream.ReadByte() == 0) { IsLittleEndian = false; } else { IsLittleEndian = true; } BinaryReader reader = IOTools.OpenReadFile(stream, IsLittleEndian); stream.Position = 0x4; int fileSize = reader.ReadInt32(); stream.Position = 0x10; int tablecount = reader.ReadInt32(); Unknown = reader.ReadBytes(12); stream.Position = 0x20; Table = reader.ReadInt32ArrayArray(tablecount, 4); Sizes = new int[Table.Length]; for (int i = 0; i < Table.Length; i++) { Sizes[i] = Table[i][1]; } foreach (var element in Table) { if (element[1] * element[2] > 0) { reader.BaseStream.Position = element[3]; string tempN; FormatEnum type = FormatEnum.DAT; if (MAP.ContainsKey(element[0])) { type = MAP[element[0]]; } tempN = "." + type.ToString(); if (fileSize == element[3] + element[1] * element[2]) { endIndex = element[0]; } byte[] data = reader.ReadBytes(element[1] * element[2]); var item = GameFormatHelper.OpenFile(tempN, data, type); if (item == null) { item = GameFormatHelper.OpenFile(tempN, data, FormatEnum.DAT); } item.Tag = element[0]; SubFiles.Add(item); } } if (endIndex == -1) { throw new Exception("BF: endIndex"); } }