public void TableUpdate() { int startOffset = 0x20 + Table.Length * 0x10; foreach (var element in Table) { int tempsize = 0; var sub = SubFiles.Find(x => (int)x.Tag == element[0]); if (sub != null) { tempsize = sub.GameData.GetSize(); if (tempsize % element[1] == 0) { element[2] = tempsize / element[1]; } else { throw new Exception("BF: Wrong subfile"); } } else { element[2] = 0; } element[3] = startOffset; startOffset += tempsize; } }
private void WriteUnnamed(Dictionary <int, byte[][]> data) { var unnamedFiles = SubFiles.FindAll(x => !MainFileList.Contains((int)(x.Tag as object[])[0])); foreach (var a in unnamedFiles) { byte[][] type = new byte[1][]; var temp = a.GameData.GetData(); int align = IOTools.Alignment(temp.Length, 16); byte[] tempType = null; if (align == 0) { tempType = temp; } else { tempType = new byte[temp.Length + align]; Buffer.BlockCopy(temp, 0, tempType, 0, temp.Length); } type[0] = tempType; data.Add((int)(a.Tag as object[])[0], type); } }
private void ReadUnnamed(Dictionary <int, byte[][]> data) { int index = 0; foreach (var el in data) { if (!MainFileList.Contains(el.Key)) { foreach (var a in el.Value) { //throw new Exception("PM1: Unknown"); string name = $"Noname({index.ToString().PadLeft(2, '0')}).DAT"; while (SubFiles.Exists(x => x.Name == name)) { index++; name = $"Noname({index.ToString().PadLeft(2, '0')}).DAT"; } var temp = GameFormatHelper.OpenFile(name, a, FormatEnum.DAT); temp.Tag = new object[] { el.Key }; SubFiles.Add(temp); } } } }
/// <summary> /// リソースをアンロードして、メモリを解放 /// </summary> public void Unload() { if (FileInfo.StrageType == AssetFileStrageType.Resources) { UnloadResources(); } else { if (FileInfo.IsAssetBundle) { UnloadAssetBundle(); } else { UnloadWWW(); } } foreach (AssetFile subFile in SubFiles.Values) { subFile.Unuse(this); } SubFiles.Clear(); memSize = 0; Priority = AssetFileLoadPriority.DownloadOnly; status = STAUS.LOAD_WAIT; }
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); }
/// <summary> /// 派生ファイルを追加してロードを開始させる /// </summary> public void LoadAndAddSubFile(string path) { if (!SubFiles.ContainsKey(path)) { AssetFile file = AssetFileManager.Load(path, this.Version, this); SubFiles.Add(path, file); } }
private void ReadBMD(BinaryReader reader, string[] names, int[] bmd) { reader.BaseStream.Position = bmd[3]; var returned = Utilities.PersonaFile.OpenFile(names[0], reader.ReadBytes(bmd[1]), FileType.BMD); returned.Tag = new object[] { bmd[0] }; SubFiles.Add(returned); }
public int Size() { int returned = 0; returned += 0x20 + Table.Length * 0x10; SubFiles.ForEach(x => returned += (x.Object as IPersonaFile).Size()); return(returned); }
public Folder(DirectoryInfo directoryInfo) : base(directoryInfo) { SubFolders = InitSubFolders(directoryInfo); SubFiles = directoryInfo.EnumerateFiles() .Select(d => new File(d)) .ToList(); Size = new FileSize(SubFiles.Sum(f => f.Size.SizeByByte)); }
public int Size() { int returned = 0; returned += 0x20; // Add Header returned += SubFiles.Count * 0x30; // Add Textures Header returned += KeyList.Count * 0xa0; // Add Keys SubFiles.ForEach(x => returned += (x.Object as Graphic.DDS).Size()); // Add Textures return(returned); }
public byte[] Get() { byte[] returned; using (MemoryStream MS = new MemoryStream()) using (BinaryWriter writer = new BinaryWriter(MS, Encoding.ASCII, true)) { writer.Write(MagicNumber); writer.Write(0x2); writer.Write(Size()); writer.Write(0); writer.Write(0x20); writer.Write((ushort)SubFiles.Count); writer.Write((ushort)KeyList.Count); writer.Write(0x20); writer.Write(0x20 + SubFiles.Count * 0x30); List <int> pos = new List <int>(); SubFiles.ForEach(x => writer.Write(new byte[0x30])); KeyList.ForEach(x => x.Get(writer)); SubFiles.ForEach(x => { pos.Add((int)MS.Position); writer.Write((x.Object as Graphic.DDS).Get()); }); MS.Position = 0x20; for (int i = 0; i < SubFiles.Count; i++) { if (SubFiles[i].Object is Graphic.DDS dds) { writer.Write(i + 1); writer.Write(0); writer.Write(pos[i]); writer.Write(dds.Size()); writer.Write(dds.Header.Width); writer.Write(dds.Header.Height); writer.Write(0); writer.Write(0); byte[] temp = new byte[0x10]; string temp2 = Path.GetFileNameWithoutExtension(SubFiles[i].Name); Encoding.ASCII.GetBytes(temp2, 0, temp2.Length, temp, 0); writer.Write(temp); } } returned = MS.ToArray(); } return(returned); }
private void Write(Stream stream) { Dictionary <int, byte[][]> blocks = new Dictionary <int, byte[][]>(); var namedFiles = SubFiles.FindAll(x => MainFileList.Contains((int)(x.Tag as object[])[0])); byte[][] fileNames = new byte[namedFiles.Count][]; for (int i = 0; i < namedFiles.Count; i++) { var temp = Encoding.ASCII.GetBytes(namedFiles[i].Name); var name = new byte[32]; Buffer.BlockCopy(temp, 0, name, 0, temp.Length); fileNames[i] = name; } blocks.Add((int)TypeMap.FileList, fileNames); WriteNamed(blocks); WriteUnnamed(blocks); UpdateOffsets(blocks); var table = CreateTable(blocks); using (BinaryWriter writer = IOTools.OpenWriteFile(stream, IsLittleEndian)) { writer.Write(0); writer.Write(0); writer.Write(MagicNumber); writer.Write(0); writer.Write(table.Length); writer.Write(Unknown); foreach (var a in table) { writer.WriteInt32Array(a); } foreach (var a in table) { var temp = blocks[a[0]]; foreach (var b in temp) { writer.Write(b); } } int fileSize = (int)stream.Position; stream.Position = 4; writer.Write(fileSize); } }
private void ReadRMD(BinaryReader reader, string[] names, int[] rmdhead) { reader.BaseStream.Position = rmdhead[3]; int[][] RMD = reader.ReadInt32ArrayArray(rmdhead[2], 8); for (int i = 0; i < RMD.Length; i++) { reader.BaseStream.Position = RMD[i][4]; var returned = Utilities.PersonaFile.OpenFile(names[i], reader.ReadBytes(RMD[i][5]), FileType.DAT); returned.Tag = new object[] { (int)TypeMap.RMD, RMD[i] }; SubFiles.Add(returned); } }
/// <summary> /// 派生ファイルを追加してロードを開始させる /// </summary> public void LoadAndAddSubFile(string path) { if (!SubFiles.ContainsKey(path)) { if (IsDownloadOnly) { AssetFile file = AssetFileManager.GetFileCreateIfMissing(path); file.Version = this.Version; AssetFileManager.Download(file); } else { SubFiles.Add(path, AssetFileManager.Load(path, this.Version, this)); } } }
private void ReadEPL(BinaryReader reader, string[] names, int[] eplhead, int[] epl) { reader.BaseStream.Position = eplhead[3]; int[][] eplpos = reader.ReadInt32ArrayArray(eplhead[2], 4); reader.BaseStream.Position = epl[3]; byte[] EPL = reader.ReadBytes(epl[1]); var splited = Utilities.Array.SplitArray(EPL, eplpos.Select(x => x[1] - epl[3]).ToArray()); for (int i = 0; i < splited.Count; i++) { var returned = Utilities.PersonaFile.OpenFile(names[i], splited[i], FileType.DAT); returned.Tag = new object[] { (int)TypeMap.EPL, eplpos[i] }; SubFiles.Add(returned); } }
private void Open(Stream stream) { stream.Position = 0x10; if (stream.ReadByte() == 0) { IsLittleEndian = false; } else { IsLittleEndian = true; } stream.Position = 0x10; BinaryReader reader = Utilities.IO.OpenReadFile(stream, IsLittleEndian); int tablecount = reader.ReadInt32(); Unknown = reader.ReadBytes(12); stream.Position = 0x20; Table = reader.ReadInt32ArrayArray(tablecount, 4); foreach (var element in Table) { if (element[1] * element[2] > 0) { reader.BaseStream.Position = element[3]; string tempN; FileType type = MAP[element[0]]; tempN = "." + type.ToString(); byte[] data = reader.ReadBytes(element[1] * element[2]); var item = Utilities.PersonaFile.OpenFile(tempN, data, type); if (item.Object == null) { item = Utilities.PersonaFile.OpenFile(tempN, data, FileType.DAT); } item.Tag = element[0]; SubFiles.Add(item); } } }
public byte[] Get() { byte[] returned = new byte[0]; using (MemoryStream MS = new MemoryStream()) { BinaryWriter writer = Utilities.IO.OpenWriteFile(MS, IsLittleEndian); if (GetTable(Table, SubFiles, 0x20)) { var temp = Table.FirstOrDefault(x => x[0] == 0x4); if (temp == null) { return(new byte[0]); } writer.Write(0); writer.Write(Size() - temp[1] * temp[2]); writer.Write(Encoding.ASCII.GetBytes("FLW0")); writer.Write(0); writer.Write(Table.Length); writer.Write(Unknown); foreach (var a in Table) { foreach (var b in a) { writer.Write(b); } } } else { return(new byte[0]); } SubFiles.ForEach(x => writer.Write((x.Object as IPersonaFile).Get())); returned = MS.ToArray(); } return(returned); }
private void ReadTexture(StreamFile streamFile, int pos, int count) { streamFile.Stream.Position = streamFile.Position + pos; using (BinaryReader reader = new BinaryReader(streamFile.Stream, Encoding.ASCII, true)) for (int i = 0; i < count; i++) { streamFile.Stream.Position += 8; long texPos = reader.ReadUInt32(); int texSize = reader.ReadInt32(); streamFile.Stream.Position += 16; string name = Encoding.ASCII.GetString(reader.ReadBytes(16)).TrimEnd('\0'); long tempPos = streamFile.Stream.Position; streamFile.Stream.Position = texPos; SubFiles.Add(Utilities.PersonaFile.OpenFile(name + ".dds", reader.ReadBytes(texSize), Interfaces.FileType.DDS)); streamFile.Stream.Position = tempPos; } }
public override void LoadFromXml(XmlElement xml) { base.LoadFromXml(xml); var fsx = xml.FindElement("FileSystem"); if (fsx != null) { var fs = (IVirtualFileSystem)VirtualFileSystemAddonType.Instance.LoadAddon(fsx); var px = xml.FindElement("Path"); if (px != null) { File = fs.GetFile(px.InnerText); } foreach (XmlElement x in xml.SelectNodes("SubFile")) { SubFiles.Add(fs.GetFile(x.InnerText)); } } }
private void Open(byte[] data) { using (BinaryReader reader = IOTools.OpenReadFile(new MemoryStream(data), IsLittleEndian)) { List <int[]> Entry = new List <int[]>(); do { Entry.Add(reader.ReadInt32Array(3)); } while (Entry[Entry.Count - 1][1] != 0); for (int i = 0; i < Entry.Count - 1; i++) { FlagList.Add(Entry[i][0]); reader.BaseStream.Position = Entry[i][1]; string name = Path.GetFileNameWithoutExtension(Name) + "(" + i.ToString().PadLeft(3, '0') + ").BMD"; SubFiles.Add(GameFormatHelper.OpenFile(name, reader.ReadBytes(Entry[i][2]), FormatEnum.BMD)); } } }
private void Open(BinaryReader reader) { Header = new SPRHeader(reader); for (int i = 0; i < Header.TextureCount; i++) { reader.ReadUInt32(); TextureOffsetList.Add(reader.ReadInt32()); } for (int i = 0; i < Header.KeyFrameCount; i++) { reader.ReadUInt32(); KeyOffsetList.Add(reader.ReadInt32()); } KeyList = new SPRKeyList(reader, Header.KeyFrameCount); foreach (var a in TextureOffsetList) { var tmx = new Sprite.TMX(new StreamPart(reader.BaseStream, -1, a)); SubFiles.Add(new GameFile(tmx.Comment + ".tmx", tmx)); } }
private void Open(BinaryReader reader) { Header = new SPRHeader(reader); for (int i = 0; i < Header.TextureCount; i++) { reader.ReadUInt32(); TextureOffsetList.Add(reader.ReadInt32()); } for (int i = 0; i < Header.KeyFrameCount; i++) { reader.ReadUInt32(); KeyOffsetList.Add(reader.ReadInt32()); } KeyList = new SPRKeyList(reader, Header.KeyFrameCount); foreach (var a in TextureOffsetList) { var tmx = new Graphic.TMX(reader.BaseStream, a); SubFiles.Add(new ObjectFile(tmx.Name, tmx)); } }
private void ReadTexture(StreamPart streamFile, int pos, int count) { streamFile.Stream.Position = streamFile.Position + pos; using (BinaryReader reader = new BinaryReader(streamFile.Stream, Encoding.ASCII, true)) for (int i = 0; i < count; i++) { int tag = reader.ReadInt32(); streamFile.Stream.Position += 4; long texPos = reader.ReadUInt32(); int texSize = reader.ReadInt32(); streamFile.Stream.Position += 16; string name = Encoding.ASCII.GetString(reader.ReadBytes(16)).TrimEnd('\0'); long tempPos = streamFile.Stream.Position; streamFile.Stream.Position = texPos; var text = GameFormatHelper.OpenFile(name + ".dds", reader.ReadBytes(texSize), FormatEnum.DDS); text.Tag = tag; SubFiles.Add(text); streamFile.Stream.Position = tempPos; } }
/// <summary> /// 派生ファイルを追加してロードを開始させる /// </summary> public virtual void LoadAndAddSubFile(string path) { AssetFile file = AssetFileManager.Load(path, this.Version, this); SubFiles.Add(path, file); }
private void WriteNamed(Dictionary <int, byte[][]> data) { void WriteSingleFile(TypeMap typeMap) { var TYPE = SubFiles.Find(x => (int)(x.Tag as object[])[0] == (int)typeMap); if (TYPE != null) { byte[][] type = new byte[1][]; var temp = TYPE.GameData.GetData(); int align = IOTools.Alignment(temp.Length, 16); byte[] tempType = null; if (align == 0) { tempType = temp; } else { tempType = new byte[temp.Length + align]; Buffer.BlockCopy(temp, 0, tempType, 0, temp.Length); } type[0] = tempType; data.Add((int)typeMap, type); } } // Write T3 WriteSingleFile(TypeMap.T3); // Write RMD var RMD = SubFiles.FindAll(x => (int)(x.Tag as object[])[0] == (int)TypeMap.RMD); if (RMD.Count != 0) { byte[][] rmdHeader = new byte[RMD.Count][]; byte[][] rmd = new byte[1][]; int offset = 0; using (MemoryStream MS = new MemoryStream()) { for (int i = 0; i < RMD.Count; i++) { byte[] temp = RMD[i].GameData.GetData(); byte[] tempRMD = new byte[temp.Length + IOTools.Alignment(temp.Length, 16)]; Buffer.BlockCopy(temp, 0, tempRMD, 0, temp.Length); MS.Write(tempRMD, 0, tempRMD.Length); var tempHeader = (RMD[i].Tag as object[])[1] as int[]; tempHeader[4] = offset; tempHeader[5] = temp.Length; using (MemoryStream headerMS = new MemoryStream()) using (BinaryWriter writer = IOTools.OpenWriteFile(headerMS, IsLittleEndian)) { writer.WriteInt32Array(tempHeader); rmdHeader[i] = headerMS.ToArray(); } offset += tempRMD.Length; } rmd[0] = MS.ToArray(); } data.Add((int)TypeMap.RMD, rmd); data.Add((int)TypeMap.RMDHead, rmdHeader); } // Write BMD WriteSingleFile(TypeMap.BMD); // Write EPL var EPL = SubFiles.FindAll(x => (int)(x.Tag as object[])[0] == (int)TypeMap.EPL); if (EPL.Count != 0) { byte[][] eplHeader = new byte[EPL.Count][]; byte[][] epl = new byte[1][]; int offset = 0; using (MemoryStream MS = new MemoryStream()) { for (int i = 0; i < EPL.Count; i++) { byte[] temp = EPL[i].GameData.GetData(); byte[] tempEPL = new byte[temp.Length + IOTools.Alignment(temp.Length, 16)]; Buffer.BlockCopy(temp, 0, tempEPL, 0, temp.Length); MS.Write(tempEPL, 0, tempEPL.Length); var tempHeader = (EPL[i].Tag as object[])[1] as int[]; tempHeader[1] = offset; using (MemoryStream headerMS = new MemoryStream()) using (BinaryWriter writer = IOTools.OpenWriteFile(headerMS, IsLittleEndian)) { writer.WriteInt32Array(tempHeader); eplHeader[i] = headerMS.ToArray(); } offset += tempEPL.Length; } epl[0] = MS.ToArray(); } data.Add((int)TypeMap.EPL, epl); data.Add((int)TypeMap.EPLHead, eplHeader); } // Write TMX var TMX = SubFiles.FindAll(x => (int)(x.Tag as object[])[0] == (int)TypeMap.TMX); if (TMX.Count != 0) { byte[][] tmxHeader = new byte[TMX.Count][]; byte[][] tmx = new byte[1][]; int offset = 0; using (MemoryStream MS = new MemoryStream()) { for (int i = 0; i < TMX.Count; i++) { byte[] temp = TMX[i].GameData.GetData(); byte[] tempTMX = new byte[temp.Length + IOTools.Alignment(temp.Length, 16)]; Buffer.BlockCopy(temp, 0, tempTMX, 0, temp.Length); MS.Write(tempTMX, 0, tempTMX.Length); var tempHeader = (TMX[i].Tag as object[])[1] as int[]; tempHeader[1] = offset; using (MemoryStream headerMS = new MemoryStream()) using (BinaryWriter writer = IOTools.OpenWriteFile(headerMS, IsLittleEndian)) { writer.WriteInt32Array(tempHeader); tmxHeader[i] = headerMS.ToArray(); } offset += tempTMX.Length; } tmx[0] = MS.ToArray(); } data.Add((int)TypeMap.TMX, tmx); data.Add((int)TypeMap.TMXHead, tmxHeader); } // Write CTable WriteSingleFile(TypeMap.CTable); }
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"); } }
private void ReadNamed(Dictionary <int, byte[][]> data) { string[] fileNameList = new string[0]; int fileNameIndex = 0; void ReadSingleFile(TypeMap typeMap) { if (data[(int)typeMap].Length > 1) { throw new Exception($"PM1 Read: {typeMap.ToString()}'s count more than 1"); } string name = fileNameList[fileNameIndex++]; var singleFile = GameFormatHelper.OpenFile(name, data[(int)typeMap][0], GameFormatHelper.GetFormat(name)); if (singleFile == null) { singleFile = GameFormatHelper.OpenFile(name, data[(int)typeMap][0], FormatEnum.DAT); } singleFile.Tag = new object[] { (int)typeMap }; SubFiles.Add(singleFile); } if (data.ContainsKey((int)TypeMap.FileList)) { fileNameList = data[(int)TypeMap.FileList].Select(x => Encoding.ASCII.GetString(x).TrimEnd('\0')).ToArray(); } else { foreach (var a in MainFileList) { if (data.ContainsKey(a)) { throw new Exception("PM1 Read: file contains named files"); } } } // Read T3 if (data.ContainsKey((int)TypeMap.T3)) { ReadSingleFile(TypeMap.T3); } // Read RMD if (data.ContainsKey((int)TypeMap.RMDHead)) { if (data.ContainsKey((int)TypeMap.RMD)) { if (data[(int)TypeMap.RMD].Length > 1) { throw new Exception("PM1 Read: RMD's count more than 1"); } using (BinaryReader RMDreader = IOTools.OpenReadFile(data[(int)TypeMap.RMD][0], IsLittleEndian)) { var rmdHeaders = data[(int)TypeMap.RMDHead] .Select(x => { using (BinaryReader BR = IOTools.OpenReadFile(x, IsLittleEndian)) return(BR.ReadInt32Array(8)); }) .ToArray(); for (int i = 0; i < rmdHeaders.Length; i++) { RMDreader.BaseStream.Position = rmdHeaders[i][4] - rmdHeaders[0][4]; var rmd = GameFormatHelper.OpenFile(fileNameList[fileNameIndex++], RMDreader.ReadBytes(rmdHeaders[i][5]), FormatEnum.DAT); rmd.Tag = new object[] { (int)TypeMap.RMD, rmdHeaders[i] }; SubFiles.Add(rmd); } } } else { throw new Exception("PM1 Read: file contain RMD Header, but not RMD"); } } // Read BMD if (data.ContainsKey((int)TypeMap.BMD)) { ReadSingleFile(TypeMap.BMD); } // Read EPL if (data.ContainsKey((int)TypeMap.EPLHead)) { if (data.ContainsKey((int)TypeMap.EPL)) { if (data[(int)TypeMap.EPL].Length > 1) { throw new Exception("PM1 Read: EPL's count more than 1"); } var eplHeaders = data[(int)TypeMap.EPLHead] .Select(x => { using (BinaryReader BR = IOTools.OpenReadFile(x, IsLittleEndian)) return(BR.ReadInt32Array(4)); }) .ToArray(); var eplList = data[(int)TypeMap.EPL][0].Split(eplHeaders.Select(x => x[1] - eplHeaders[0][1]).ToArray()).ToArray(); for (int i = 0; i < eplList.Length; i++) { var epl = GameFormatHelper.OpenFile(fileNameList[fileNameIndex++], eplList[i], FormatEnum.DAT); epl.Tag = new object[] { (int)TypeMap.EPL, eplHeaders[i] }; SubFiles.Add(epl); } } else { throw new Exception("PM1 Read: file contain EPL Header, but not EPL"); } } // Read TMX if (data.ContainsKey((int)TypeMap.TMXHead)) { if (data.ContainsKey((int)TypeMap.TMX)) { if (data[(int)TypeMap.TMX].Length > 1) { throw new Exception("PM1 Read: TMX's count more than 1"); } var tmxHeaders = data[(int)TypeMap.TMXHead] .Select(x => { using (BinaryReader BR = IOTools.OpenReadFile(x, IsLittleEndian)) return(BR.ReadInt32Array(4)); }) .ToArray(); var tmxList = data[(int)TypeMap.TMX][0].Split(tmxHeaders.Select(x => x[1] - tmxHeaders[0][1]).ToArray()).ToArray(); for (int i = 0; i < tmxList.Length; i++) { var name = fileNameList[fileNameIndex++]; var tmx = GameFormatHelper.OpenFile(name, tmxList[i], GameFormatHelper.GetFormat(name)); tmx.Tag = new object[] { (int)TypeMap.TMX, tmxHeaders[i] }; SubFiles.Add(tmx); } } else { throw new Exception("PM1 Read: file contain TMX Header, but not TMX"); } } // Read CTable if (data.ContainsKey((int)TypeMap.CTable)) { ReadSingleFile(TypeMap.CTable); } if (fileNameIndex != fileNameList.Length) { throw new Exception("PM1 Read: not all files are read"); } }
public byte[] Get() { using (MemoryStream MS = new MemoryStream()) { BinaryWriter writer = Utilities.IO.OpenWriteFile(MS, IsLittleEndian); var RMD = SubFiles.FindAll(x => (int)(x.Tag as object[])[0] == (int)TypeMap.RMD); var BMD = SubFiles.Find(x => (int)(x.Tag as object[])[0] == (int)TypeMap.BMD); var EPL = SubFiles.FindAll(x => (int)(x.Tag as object[])[0] == (int)TypeMap.EPL); MS.Position = 0x20 + 0x10 * (1 + (RMD.Count == 0 ? 0 : 2) + (BMD == null ? 0 : 1) + (EPL.Count == 0 ? 0 : 2) + HidList.GroupBy(x => (int)x.Tag).Count()); List <int[]> table = new List <int[]>(); var filelist = SubFiles.Select(x => x.Name).ToArray(); table.Add(new int[] { (int)TypeMap.FileList, textsize, filelist.Length, (int)MS.Position }); foreach (var file in filelist) { writer.WriteString(file, textsize); } long RMDHeadPos = 0; if (RMD.Count != 0) { table.Add(new int[] { (int)TypeMap.RMDHead, 0x20, RMD.Count, (int)MS.Position }); RMDHeadPos = MS.Position; MS.Position += RMD.Count * 0x20; table.Add(new int[] { (int)TypeMap.RMD, 0, 1, (int)MS.Position }); } if (BMD != null) { byte[] bmd = (BMD.Object as IPersonaFile).Get(); table.Add(new int[] { (int)TypeMap.BMD, bmd.Length + Utilities.Utilities.Alignment(bmd.Length, 0x10), 1, (int)MS.Position }); writer.Write(bmd); writer.Write(new byte[Utilities.Utilities.Alignment(bmd.Length, 0x10)]); } long EPLHeadPos = 0; if (EPL.Count != 0) { table.Add(new int[] { (int)TypeMap.EPLHead, 0x10, EPL.Count, (int)MS.Position }); EPLHeadPos = MS.Position; MS.Position += EPL.Count * 0x10; table.Add(new int[] { (int)TypeMap.EPL, 0, 1, (int)MS.Position }); } foreach (var a in EPL) { byte[] epl = (a.Object as IPersonaFile).Get(); table.Find(x => x[0] == (int)TypeMap.EPL)[1] += epl.Length + Utilities.Utilities.Alignment(epl.Length, 0x10); int[] eplhead = (int[])(a.Tag as object[])[1]; eplhead[1] = (int)MS.Position; writer.Write(epl); MS.Position += Utilities.Utilities.Alignment(epl.Length, 0x10); } foreach (var a in RMD) { byte[] rmd = (a.Object as IPersonaFile).Get(); table.Find(x => x[0] == (int)TypeMap.RMD)[1] += rmd.Length + Utilities.Utilities.Alignment(rmd.Length, 0x10); int[] rmdhead = (int[])(a.Tag as object[])[1]; rmdhead[4] = (int)MS.Position; rmdhead[5] = rmd.Length; writer.Write(rmd); MS.Position += Utilities.Utilities.Alignment(rmd.Length, 0x10); } if (EPLHeadPos != 0) { writer.BaseStream.Position = EPLHeadPos; foreach (var a in EPL) { writer.WriteInt32Array((int[])(a.Tag as object[])[1]); } } if (RMDHeadPos != 0) { writer.BaseStream.Position = RMDHeadPos; foreach (var a in RMD) { writer.WriteInt32Array((int[])(a.Tag as object[])[1]); } } // table.AddRange(Table.Where(x => !table.Exists(y => y[0] == x[0]))); table = table.OrderBy(x => x[0]).ToList(); MS.Position = 0x4; writer.Write((int)MS.Length); writer.Write(Encoding.ASCII.GetBytes("PMD1")); MS.Position = 0x10; writer.Write(table.Count); writer.Write(Unknown); MS.Position = 0x20; foreach (var a in table) { writer.WriteInt32Array(a); } return(MS.ToArray()); } }
public List <string> Enumerate() { return(SubFiles.Select(sub => sub.Name).ToList()); }