FileEntry CreateFileEntry(string FileName, ulong FileOffset, Type FileOffsetType, long FileOffsetPos, string TOCName, string FileType, bool encrypted) { FileEntry entry = new FileEntry { FileName = FileName, FileOffset = FileOffset, FileOffsetType = FileOffsetType, FileOffsetPos = FileOffsetPos, TOCName = TOCName, FileType = FileType, Encrypted = encrypted, }; return entry; }
public bool ReadTOC(EndianReader br, ulong TocOffset, ulong ContentOffset) { ulong add_offset = 0; if (ContentOffset < 0) add_offset = TocOffset; else { if (TocOffset < 0) add_offset = ContentOffset; else { if (ContentOffset < TocOffset) add_offset = ContentOffset; else add_offset = TocOffset; } } br.BaseStream.Seek((long)TocOffset, SeekOrigin.Begin); if (tools.ReadCString(br, 4) != "TOC ") { br.Close(); return false; } ReadUTFData(br); // Store unencrypted TOC TOC_packet = utf_packet; FileEntry toc_entry = FileTable.Where(x => x.FileName.ToString() == "TOC_HDR").Single(); toc_entry.Encrypted = isUtfEncrypted; toc_entry.FileSize = TOC_packet.Length; MemoryStream ms = new MemoryStream(utf_packet); EndianReader utfr = new EndianReader(ms, false); files = new UTF(tools); if (!files.ReadUTF(utfr)) { br.Close(); return false; } utfr.Close(); ms.Close(); FileEntry temp; for (int i = 0; i < files.num_rows; i++) { temp = new FileEntry(); temp.TOCName = "TOC"; temp.DirName = GetColumnData(files, i, "DirName"); temp.FileName = GetColumnData(files, i, "FileName"); temp.FileSize = GetColumnData(files, i, "FileSize"); temp.FileSizePos = GetColumnPostion(files, i, "FileSize"); temp.FileSizeType = GetColumnType(files, i, "FileSize"); temp.ExtractSize = GetColumnData(files, i, "ExtractSize"); temp.ExtractSizePos = GetColumnPostion(files, i, "ExtractSize"); temp.ExtractSizeType = GetColumnType(files, i, "ExtractSize"); temp.FileOffset = ((ulong)GetColumnData(files, i, "FileOffset") + (ulong)add_offset); temp.FileOffsetPos = GetColumnPostion(files, i, "FileOffset"); temp.FileOffsetType = GetColumnType(files, i, "FileOffset"); temp.FileType = "FILE"; temp.Offset = add_offset; temp.ID = GetColumnData(files, i, "ID"); temp.UserString = GetColumnData(files, i, "UserString"); FileTable.Add(temp); } files = null; return true; }
public void UpdateFileEntry(FileEntry fileEntry) { if (fileEntry.FileType == "FILE" || fileEntry.FileType == "HDR") { byte[] updateMe = null; switch (fileEntry.TOCName) { case "CPK": updateMe = CPK_packet; break; case "TOC": updateMe = TOC_packet; break; case "ITOC": updateMe = ITOC_packet; break; case "ETOC": updateMe = ETOC_packet; break; default: throw new Exception("I need to implement this TOC!"); break; } //Update ExtractSize if (fileEntry.ExtractSizePos > 0) UpdateValue(ref updateMe, fileEntry.ExtractSize, fileEntry.ExtractSizePos, fileEntry.ExtractSizeType); //Update FileSize if (fileEntry.FileSizePos > 0) UpdateValue(ref updateMe, fileEntry.FileSize, fileEntry.FileSizePos, fileEntry.FileSizeType); //Update FileOffset if (fileEntry.FileOffsetPos > 0) UpdateValue(ref updateMe, fileEntry.FileOffset - (ulong)((fileEntry.TOCName == "TOC") ? 0x800 : 0), fileEntry.FileOffsetPos, fileEntry.FileOffsetType); switch (fileEntry.TOCName) { case "CPK": updateMe = CPK_packet; break; case "TOC": TOC_packet = updateMe; break; case "ITOC": ITOC_packet = updateMe; break; case "ETOC": updateMe = ETOC_packet; break; default: throw new Exception("I need to implement this TOC!"); break; } } }
public bool ReadCPK(string sPath) { if (File.Exists(sPath)) { uint Files; ushort Align; EndianReader br = new EndianReader(File.OpenRead(sPath), true); MemoryStream ms; EndianReader utfr; if (tools.ReadCString(br, 4) != "CPK ") { br.Close(); return false; } ReadUTFData(br); CPK_packet = utf_packet; FileEntry CPAK_entry = new FileEntry { FileName = "CPK_HDR", FileOffsetPos = br.BaseStream.Position + 0x10, FileSize = CPK_packet.Length, Encrypted = isUtfEncrypted, FileType = "CPK" }; FileTable.Add(CPAK_entry); ms = new MemoryStream(utf_packet); utfr = new EndianReader(ms, false); utf = new UTF(tools); if (!utf.ReadUTF(utfr)) { br.Close(); return false; } utfr.Close(); ms.Close(); cpkdata = new Dictionary<string, object>(); try { for (int i = 0; i < utf.columns.Count; i++) { cpkdata.Add(utf.columns[i].name, utf.rows[0].rows[i].GetValue()); } } catch (Exception ex) { //MessageBox.Show(ex.ToString()); Console.WriteLine(ex.ToString()); } TocOffset = (ulong)GetColumsData2(utf, 0, "TocOffset", 3); long TocOffsetPos = GetColumnPostion(utf, 0, "TocOffset"); EtocOffset = (ulong)GetColumsData2(utf, 0, "EtocOffset", 3); long ETocOffsetPos = GetColumnPostion(utf, 0, "EtocOffset"); ItocOffset = (ulong)GetColumsData2(utf, 0, "ItocOffset", 3); long ITocOffsetPos = GetColumnPostion(utf, 0, "ItocOffset"); GtocOffset = (ulong)GetColumsData2(utf, 0, "GtocOffset", 3); long GTocOffsetPos = GetColumnPostion(utf, 0, "GtocOffset"); ContentOffset = (ulong)GetColumsData2(utf, 0, "ContentOffset", 3); long ContentOffsetPos = GetColumnPostion(utf, 0, "ContentOffset"); FileTable.Add(CreateFileEntry("CONTENT_OFFSET", ContentOffset, typeof(ulong), ContentOffsetPos, "CPK", "CONTENT", false)); Files = (uint)GetColumsData2(utf, 0, "Files", 2); Align = (ushort)GetColumsData2(utf, 0, "Align", 1); if (TocOffset != 0xFFFFFFFFFFFFFFFF) { FileEntry entry = CreateFileEntry("TOC_HDR", TocOffset, typeof(ulong), TocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadTOC(br, TocOffset, ContentOffset)) return false; } if (EtocOffset != 0xFFFFFFFFFFFFFFFF) { FileEntry entry = CreateFileEntry("ETOC_HDR", EtocOffset, typeof(ulong), ETocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadETOC(br, EtocOffset)) return false; } if (ItocOffset != 0xFFFFFFFFFFFFFFFF) { //FileEntry ITOC_entry = new FileEntry { // FileName = "ITOC_HDR", // FileOffset = ItocOffset, FileOffsetType = typeof(ulong), FileOffsetPos = ITocOffsetPos, // TOCName = "CPK", // FileType = "FILE", Encrypted = true, //}; FileEntry entry = CreateFileEntry("ITOC_HDR", ItocOffset, typeof(ulong), ITocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadITOC(br, ItocOffset, ContentOffset, Align)) return false; } if (GtocOffset != 0xFFFFFFFFFFFFFFFF) { FileEntry entry = CreateFileEntry("GTOC_HDR", GtocOffset, typeof(ulong), GTocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadGTOC(br, GtocOffset)) return false; } br.Close(); // at this point, we should have all needed file info //utf = null; files = null; return true; } return false; }
public bool ReadITOC(EndianReader br, ulong startoffset, ulong ContentOffset, ushort Align) { br.BaseStream.Seek((long)startoffset, SeekOrigin.Begin); if (tools.ReadCString(br, 4) != "ITOC") { br.Close(); return false; } ReadUTFData(br); ITOC_packet = utf_packet; FileEntry itoc_entry = FileTable.Where(x => x.FileName.ToString() == "ITOC_HDR").Single(); itoc_entry.Encrypted = isUtfEncrypted; itoc_entry.FileSize = ITOC_packet.Length; MemoryStream ms = new MemoryStream(utf_packet); EndianReader utfr = new EndianReader(ms, false); files = new UTF(tools); if (!files.ReadUTF(utfr)) { br.Close(); return false; } utfr.Close(); ms.Close(); //uint FilesL = (uint)GetColumnData(files, 0, "FilesL"); //uint FilesH = (uint)GetColumnData(files, 0, "FilesH"); byte[] DataL = (byte[])GetColumnData(files, 0, "DataL"); long DataLPos = GetColumnPostion(files, 0, "DataL"); byte[] DataH = (byte[])GetColumnData(files, 0, "DataH"); long DataHPos = GetColumnPostion(files, 0, "DataH"); //MemoryStream ms; //EndianReader ir; UTF utfDataL, utfDataH; Dictionary<int, uint> SizeTable, CSizeTable; Dictionary<int, long> SizePosTable, CSizePosTable; Dictionary<int, Type> SizeTypeTable, CSizeTypeTable; List<int> IDs = new List<int>(); SizeTable = new Dictionary<int, uint>(); SizePosTable = new Dictionary<int, long>(); SizeTypeTable = new Dictionary<int, Type>(); CSizeTable = new Dictionary<int, uint>(); CSizePosTable = new Dictionary<int, long>(); CSizeTypeTable = new Dictionary<int, Type>(); ushort ID, size1; uint size2; long pos; Type type; if (DataL != null) { ms = new MemoryStream(DataL); utfr = new EndianReader(ms, false); utfDataL = new UTF(tools); utfDataL.ReadUTF(utfr); for (int i = 0; i < utfDataL.num_rows; i++) { ID = (ushort)GetColumnData(utfDataL, i, "ID"); size1 = (ushort)GetColumnData(utfDataL, i, "FileSize"); SizeTable.Add((int)ID, (uint)size1); pos = GetColumnPostion(utfDataL, i, "FileSize"); SizePosTable.Add((int)ID, pos + DataLPos); type = GetColumnType(utfDataL, i, "FileSize"); SizeTypeTable.Add((int)ID, type); if ((GetColumnData(utfDataL, i, "ExtractSize")) != null) { size1 = (ushort)GetColumnData(utfDataL, i, "ExtractSize"); CSizeTable.Add((int)ID, (uint)size1); pos = GetColumnPostion(utfDataL, i, "ExtractSize"); CSizePosTable.Add((int)ID, pos + DataLPos); type = GetColumnType(utfDataL, i, "ExtractSize"); CSizeTypeTable.Add((int)ID, type); } IDs.Add(ID); } } if (DataH != null) { ms = new MemoryStream(DataH); utfr = new EndianReader(ms, false); utfDataH = new UTF(tools); utfDataH.ReadUTF(utfr); for (int i = 0; i < utfDataH.num_rows; i++) { ID = (ushort)GetColumnData(utfDataH, i, "ID"); size2 = (uint)GetColumnData(utfDataH, i, "FileSize"); SizeTable.Add(ID, size2); pos = GetColumnPostion(utfDataH, i, "FileSize"); SizePosTable.Add((int)ID, pos + DataHPos); type = GetColumnType(utfDataH, i, "FileSize"); SizeTypeTable.Add((int)ID, type); if ((GetColumnData(utfDataH, i, "ExtractSize")) != null) { size2 = (uint)GetColumnData(utfDataH, i, "ExtractSize"); CSizeTable.Add(ID, size2); pos = GetColumnPostion(utfDataH, i, "ExtractSize"); CSizePosTable.Add((int)ID, pos + DataHPos); type = GetColumnType(utfDataH, i, "ExtractSize"); CSizeTypeTable.Add((int)ID, type); } IDs.Add(ID); } } FileEntry temp; //int id = 0; uint value = 0, value2 = 0; ulong baseoffset = ContentOffset; // Seems ITOC can mix up the IDs..... but they'll alwaysy be in order... IDs = IDs.OrderBy(x => x).ToList(); for (int i = 0; i < IDs.Count; i++) { int id = IDs[i]; temp = new FileEntry(); SizeTable.TryGetValue(id, out value); CSizeTable.TryGetValue(id, out value2); temp.TOCName = "ITOC"; temp.DirName = null; temp.FileName = id.ToString("D4"); temp.FileSize = value; temp.FileSizePos = SizePosTable[id]; temp.FileSizeType = SizeTypeTable[id]; if (CSizeTable.Count > 0 && CSizeTable.ContainsKey(id)) { temp.ExtractSize = value2; temp.ExtractSizePos = CSizePosTable[id]; temp.ExtractSizeType = CSizeTypeTable[id]; } temp.FileType = "FILE"; temp.FileOffset = baseoffset; temp.ID = id; temp.UserString = null; FileTable.Add(temp); if ((value % Align) > 0) baseoffset += value + (Align - (value % Align)); else baseoffset += value; //id++; } files = null; utfDataL = null; utfDataH = null; ms.Close(); utfr.Close(); return true; }
public void UpdateFileEntry(FileEntry fileEntry) { if (fileEntry.FileType == "FILE" || fileEntry.FileType == "HDR") { byte[] updateMe = null; switch (fileEntry.TOCName) { case "CPK": updateMe = CPK_packet; break; case "TOC": updateMe = TOC_packet; break; case "ITOC": updateMe = ITOC_packet; break; case "ETOC": updateMe = ETOC_packet; break; default: throw new Exception("I need to implement this TOC!"); break; } //Update ExtractSize if (fileEntry.ExtractSizePos > 0) { UpdateValue(ref updateMe, fileEntry.ExtractSize, fileEntry.ExtractSizePos, fileEntry.ExtractSizeType); } //Update FileSize if (fileEntry.FileSizePos > 0) { UpdateValue(ref updateMe, fileEntry.FileSize, fileEntry.FileSizePos, fileEntry.FileSizeType); } //Update FileOffset if (fileEntry.FileOffsetPos > 0) { UpdateValue(ref updateMe, fileEntry.FileOffset - (ulong)((fileEntry.TOCName == "TOC") ? 0x800 : 0), fileEntry.FileOffsetPos, fileEntry.FileOffsetType); } switch (fileEntry.TOCName) { case "CPK": updateMe = CPK_packet; break; case "TOC": TOC_packet = updateMe; break; case "ITOC": ITOC_packet = updateMe; break; case "ETOC": updateMe = ETOC_packet; break; default: throw new Exception("I need to implement this TOC!"); break; } } }
public bool ReadITOC(EndianReader br, ulong startoffset, ulong ContentOffset, ushort Align) { br.BaseStream.Seek((long)startoffset, SeekOrigin.Begin); if (Tools.ReadCString(br, 4) != "ITOC") { br.Close(); return(false); } ReadUTFData(br); ITOC_packet = utf_packet; //Dump ITOC //File.WriteAllBytes("U_ITOC", ITOC_packet); FileEntry itoc_entry = FileTable.Where(x => x.FileName.ToString() == "ITOC_HDR").Single(); itoc_entry.Encrypted = isUtfEncrypted; itoc_entry.FileSize = ITOC_packet.Length; MemoryStream ms = new MemoryStream(utf_packet); EndianReader utfr = new EndianReader(ms, false); files = new UTF(); if (!files.ReadUTF(utfr)) { br.Close(); return(false); } utfr.Close(); ms.Close(); //uint FilesL = (uint)GetColumnData(files, 0, "FilesL"); //uint FilesH = (uint)GetColumnData(files, 0, "FilesH"); byte[] DataL = (byte[])GetColumnData(files, 0, "DataL"); long DataLPos = GetColumnPostion(files, 0, "DataL"); byte[] DataH = (byte[])GetColumnData(files, 0, "DataH"); long DataHPos = GetColumnPostion(files, 0, "DataH"); //MemoryStream ms; //EndianReader ir; UTF utfDataL, utfDataH; Dictionary <int, uint> SizeTable, CSizeTable; Dictionary <int, long> SizePosTable, CSizePosTable; Dictionary <int, Type> SizeTypeTable, CSizeTypeTable; List <int> IDs = new List <int>(); SizeTable = new Dictionary <int, uint>(); SizePosTable = new Dictionary <int, long>(); SizeTypeTable = new Dictionary <int, Type>(); CSizeTable = new Dictionary <int, uint>(); CSizePosTable = new Dictionary <int, long>(); CSizeTypeTable = new Dictionary <int, Type>(); ushort ID, size1; uint size2; long pos; Type type; if (DataL != null) { ms = new MemoryStream(DataL); utfr = new EndianReader(ms, false); utfDataL = new UTF(); utfDataL.ReadUTF(utfr); for (int i = 0; i < utfDataL.num_rows; i++) { ID = (ushort)GetColumnData(utfDataL, i, "ID"); size1 = (ushort)GetColumnData(utfDataL, i, "FileSize"); SizeTable.Add((int)ID, (uint)size1); pos = GetColumnPostion(utfDataL, i, "FileSize"); SizePosTable.Add((int)ID, pos + DataLPos); type = GetColumnType(utfDataL, i, "FileSize"); SizeTypeTable.Add((int)ID, type); if ((GetColumnData(utfDataL, i, "ExtractSize")) != null) { size1 = (ushort)GetColumnData(utfDataL, i, "ExtractSize"); CSizeTable.Add((int)ID, (uint)size1); pos = GetColumnPostion(utfDataL, i, "ExtractSize"); CSizePosTable.Add((int)ID, pos + DataLPos); type = GetColumnType(utfDataL, i, "ExtractSize"); CSizeTypeTable.Add((int)ID, type); } IDs.Add(ID); } } if (DataH != null) { ms = new MemoryStream(DataH); utfr = new EndianReader(ms, false); utfDataH = new UTF(); utfDataH.ReadUTF(utfr); for (int i = 0; i < utfDataH.num_rows; i++) { ID = (ushort)GetColumnData(utfDataH, i, "ID"); size2 = (uint)GetColumnData(utfDataH, i, "FileSize"); SizeTable.Add(ID, size2); pos = GetColumnPostion(utfDataH, i, "FileSize"); SizePosTable.Add((int)ID, pos + DataHPos); type = GetColumnType(utfDataH, i, "FileSize"); SizeTypeTable.Add((int)ID, type); if ((GetColumnData(utfDataH, i, "ExtractSize")) != null) { size2 = (uint)GetColumnData(utfDataH, i, "ExtractSize"); CSizeTable.Add(ID, size2); pos = GetColumnPostion(utfDataH, i, "ExtractSize"); CSizePosTable.Add((int)ID, pos + DataHPos); type = GetColumnType(utfDataH, i, "ExtractSize"); CSizeTypeTable.Add((int)ID, type); } IDs.Add(ID); } } FileEntry temp; //int id = 0; uint value = 0, value2 = 0; ulong baseoffset = ContentOffset; // Seems ITOC can mix up the IDs..... but they'll alwaysy be in order... IDs = IDs.OrderBy(x => x).ToList(); for (int i = 0; i < IDs.Count; i++) { int id = IDs[i]; temp = new FileEntry(); SizeTable.TryGetValue(id, out value); CSizeTable.TryGetValue(id, out value2); temp.TOCName = "ITOC"; temp.DirName = null; temp.FileName = id.ToString("D4"); temp.FileSize = value; temp.FileSizePos = SizePosTable[id]; temp.FileSizeType = SizeTypeTable[id]; if (CSizeTable.Count > 0 && CSizeTable.ContainsKey(id)) { temp.ExtractSize = value2; temp.ExtractSizePos = CSizePosTable[id]; temp.ExtractSizeType = CSizeTypeTable[id]; } temp.FileType = "FILE"; temp.FileOffset = baseoffset; temp.ID = id; temp.UserString = null; FileTable.Add(temp); if ((value % Align) > 0) { baseoffset += value + (Align - (value % Align)); } else { baseoffset += value; } //id++; } files = null; utfDataL = null; utfDataH = null; ms.Close(); utfr.Close(); return(true); }
public bool ReadCPK(string sPath) { if (File.Exists(sPath)) { uint Files; ushort Align; cName = sPath; EndianReader br = new EndianReader(File.OpenRead(sPath), true); MemoryStream ms; EndianReader utfr; if (Tools.ReadCString(br, 4) != "CPK ") { br.Close(); return(false); } ReadUTFData(br); CPK_packet = utf_packet; FileEntry CPAK_entry = new FileEntry { FileName = "CPK_HDR", FileOffsetPos = br.BaseStream.Position + 0x10, FileSize = CPK_packet.Length, Encrypted = isUtfEncrypted, FileType = "CPK" }; FileTable.Add(CPAK_entry); ms = new MemoryStream(utf_packet); utfr = new EndianReader(ms, false); utf = new UTF(); if (!utf.ReadUTF(utfr)) { br.Close(); return(false); } utfr.Close(); ms.Close(); TocOffset = (ulong)GetColumsData(utf, 0, "TocOffset", 3); long TocOffsetPos = GetColumnPostion(utf, 0, "TocOffset"); EtocOffset = (ulong)GetColumsData(utf, 0, "EtocOffset", 3); long ETocOffsetPos = GetColumnPostion(utf, 0, "EtocOffset"); ItocOffset = (ulong)GetColumsData(utf, 0, "ItocOffset", 3); long ITocOffsetPos = GetColumnPostion(utf, 0, "ItocOffset"); GtocOffset = (ulong)GetColumsData(utf, 0, "GtocOffset", 3); long GTocOffsetPos = GetColumnPostion(utf, 0, "GtocOffset"); ContentOffset = (ulong)GetColumsData(utf, 0, "ContentOffset", 3); long ContentOffsetPos = GetColumnPostion(utf, 0, "ContentOffset"); FileTable.Add(CreateFileEntry("CONTENT_OFFSET", ContentOffset, typeof(ulong), ContentOffsetPos, "CPK", "CONTENT", false)); Files = (uint)GetColumsData(utf, 0, "Files", 2); Align = (ushort)GetColumsData(utf, 0, "Align", 1); if (TocOffset != 0xFFFFFFFFFFFFFFFF) { FileEntry entry = CreateFileEntry("TOC_HDR", TocOffset, typeof(ulong), TocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadTOC(br, TocOffset, ContentOffset)) { return(false); } } if (EtocOffset != 0xFFFFFFFFFFFFFFFF) { FileEntry entry = CreateFileEntry("ETOC_HDR", EtocOffset, typeof(ulong), ETocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadETOC(br, EtocOffset)) { return(false); } } if (ItocOffset != 0xFFFFFFFFFFFFFFFF) { //FileEntry ITOC_entry = new FileEntry { // FileName = "ITOC_HDR", // FileOffset = ItocOffset, FileOffsetType = typeof(ulong), FileOffsetPos = ITocOffsetPos, // TOCName = "CPK", // FileType = "FILE", Encrypted = true, //}; FileEntry entry = CreateFileEntry("ITOC_HDR", ItocOffset, typeof(ulong), ITocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadITOC(br, ItocOffset, ContentOffset, Align)) { return(false); } } if (GtocOffset != 0xFFFFFFFFFFFFFFFF) { FileEntry entry = CreateFileEntry("GTOC_HDR", GtocOffset, typeof(ulong), GTocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadGTOC(br, GtocOffset)) { return(false); } } br.Close(); // at this point, we should have all needed file info //utf = null; files = null; return(true); } return(false); }
public bool ReadTOC(EndianReader br, ulong TocOffset, ulong ContentOffset) { ulong add_offset = 0; if (ContentOffset < 0) { add_offset = TocOffset; } else { if (TocOffset < 0) { add_offset = ContentOffset; } else { if (ContentOffset < TocOffset) { add_offset = ContentOffset; } else { add_offset = TocOffset; } } } br.BaseStream.Seek((long)TocOffset, SeekOrigin.Begin); if (Tools.ReadCString(br, 4) != "TOC ") { br.Close(); return(false); } ReadUTFData(br); // Store unencrypted TOC TOC_packet = utf_packet; //Dump TOC //File.WriteAllBytes("U_TOC", TOC_packet); FileEntry toc_entry = FileTable.Where(x => x.FileName.ToString() == "TOC_HDR").Single(); toc_entry.Encrypted = isUtfEncrypted; toc_entry.FileSize = TOC_packet.Length; MemoryStream ms = new MemoryStream(utf_packet); EndianReader utfr = new EndianReader(ms, false); files = new UTF(); if (!files.ReadUTF(utfr)) { br.Close(); return(false); } utfr.Close(); ms.Close(); FileEntry temp; for (int i = 0; i < files.num_rows; i++) { temp = new FileEntry(); temp.TOCName = "TOC"; temp.DirName = GetColumnData(files, i, "DirName"); temp.FileName = GetColumnData(files, i, "FileName"); temp.FileSize = GetColumnData(files, i, "FileSize"); temp.FileSizePos = GetColumnPostion(files, i, "FileSize"); temp.FileSizeType = GetColumnType(files, i, "FileSize"); temp.ExtractSize = GetColumnData(files, i, "ExtractSize"); temp.ExtractSizePos = GetColumnPostion(files, i, "ExtractSize"); temp.ExtractSizeType = GetColumnType(files, i, "ExtractSize"); temp.FileOffset = ((ulong)GetColumnData(files, i, "FileOffset") + (ulong)add_offset); temp.FileOffsetPos = GetColumnPostion(files, i, "FileOffset"); temp.FileOffsetType = GetColumnType(files, i, "FileOffset"); temp.FileType = "FILE"; temp.Offset = add_offset; temp.ID = GetColumnData(files, i, "ID"); temp.UserString = GetColumnData(files, i, "UserString"); FileTable.Add(temp); } files = null; return(true); }
public bool ReadCPK(string sPath) { if (File.Exists(sPath)) { uint Files; ushort Align; EndianReader br = new EndianReader(File.OpenRead(sPath), true); MemoryStream ms; EndianReader utfr; if (tools.ReadCString(br, 4) != "CPK ") { br.Close(); return(false); } ReadUTFData(br); CPK_packet = utf_packet; //Dump CPK //File.WriteAllBytes("U_CPK", CPK_packet); FileEntry CPAK_entry = new FileEntry { FileName = "CPK_HDR", FileOffsetPos = br.BaseStream.Position + 0x10, FileSize = CPK_packet.Length, Encrypted = isUtfEncrypted, FileType = "CPK" }; FileTable.Add(CPAK_entry); ms = new MemoryStream(utf_packet); utfr = new EndianReader(ms, false); utf = new UTF(tools); if (!utf.ReadUTF(utfr)) { br.Close(); return(false); } utfr.Close(); ms.Close(); cpkdata = new Dictionary <string, object>(); try { for (int i = 0; i < utf.columns.Count; i++) { cpkdata.Add(utf.columns[i].name, utf.rows[0].rows[i].GetValue()); } } catch (Exception ex) { //MessageBox.Show(ex.ToString()); Console.WriteLine(ex.ToString()); } TocOffset = (ulong)GetColumsData2(utf, 0, "TocOffset", 3); long TocOffsetPos = GetColumnPostion(utf, 0, "TocOffset"); EtocOffset = (ulong)GetColumsData2(utf, 0, "EtocOffset", 3); long ETocOffsetPos = GetColumnPostion(utf, 0, "EtocOffset"); ItocOffset = (ulong)GetColumsData2(utf, 0, "ItocOffset", 3); long ITocOffsetPos = GetColumnPostion(utf, 0, "ItocOffset"); GtocOffset = (ulong)GetColumsData2(utf, 0, "GtocOffset", 3); long GTocOffsetPos = GetColumnPostion(utf, 0, "GtocOffset"); ContentOffset = (ulong)GetColumsData2(utf, 0, "ContentOffset", 3); long ContentOffsetPos = GetColumnPostion(utf, 0, "ContentOffset"); FileTable.Add(CreateFileEntry("CONTENT_OFFSET", ContentOffset, typeof(ulong), ContentOffsetPos, "CPK", "CONTENT", false)); Files = (uint)GetColumsData2(utf, 0, "Files", 2); Align = (ushort)GetColumsData2(utf, 0, "Align", 1); if (TocOffset != 0xFFFFFFFFFFFFFFFF) { FileEntry entry = CreateFileEntry("TOC_HDR", TocOffset, typeof(ulong), TocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadTOC(br, TocOffset, ContentOffset)) { return(false); } } if (EtocOffset != 0xFFFFFFFFFFFFFFFF) { FileEntry entry = CreateFileEntry("ETOC_HDR", EtocOffset, typeof(ulong), ETocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadETOC(br, EtocOffset)) { return(false); } } if (ItocOffset != 0xFFFFFFFFFFFFFFFF) { //FileEntry ITOC_entry = new FileEntry { // FileName = "ITOC_HDR", // FileOffset = ItocOffset, FileOffsetType = typeof(ulong), FileOffsetPos = ITocOffsetPos, // TOCName = "CPK", // FileType = "FILE", Encrypted = true, //}; FileEntry entry = CreateFileEntry("ITOC_HDR", ItocOffset, typeof(ulong), ITocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadITOC(br, ItocOffset, ContentOffset, Align)) { return(false); } } if (GtocOffset != 0xFFFFFFFFFFFFFFFF) { FileEntry entry = CreateFileEntry("GTOC_HDR", GtocOffset, typeof(ulong), GTocOffsetPos, "CPK", "HDR", false); FileTable.Add(entry); if (!ReadGTOC(br, GtocOffset)) { return(false); } } br.Close(); // at this point, we should have all needed file info //utf = null; files = null; return(true); } return(false); }