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 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 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); }
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()); } }