public static sFolder Unpack(string file, string name) { BinaryReader br = new BinaryReader(File.OpenRead(file)); sFolder folder = new sFolder(); folder.id = 0xFFFF; #region Read nxarc file // Header NXAR nxarc = new NXAR(); nxarc.header.type = br.ReadChars(4); nxarc.header.num_folders = br.ReadUInt16(); nxarc.header.num_files = br.ReadUInt16(); nxarc.header.fatOffset = br.ReadUInt32(); nxarc.header.filesOffset = br.ReadUInt32(); nxarc.header.folderTableSize = br.ReadUInt32(); nxarc.header.unknown = br.ReadUInt32(); nxarc.header.padding = br.ReadUInt64(); // Folder table nxarc.folders = new sFolder[nxarc.header.num_folders]; for (int i = 0; i < nxarc.header.num_folders; i++) { nxarc.folders[i] = new sFolder(); nxarc.folders[i].files = new List <sFile>(br.ReadUInt16()); nxarc.folders[i].id = br.ReadUInt16(); // ID of the first file } for (int i = 0; i < nxarc.header.num_folders; i++) { char c = '\x0'; for (; ;) { c = (char)br.ReadByte(); if (c == '\x0') { break; } nxarc.folders[i].name += c; } } // File offset table br.BaseStream.Position = nxarc.header.fatOffset; nxarc.files = new sFile[nxarc.header.num_files]; for (int i = 0; i < nxarc.header.num_files; i++) { nxarc.files[i] = new sFile(); nxarc.files[i].name = name + '_' + i.ToString() + ".bin"; nxarc.files[i].path = file; nxarc.files[i].offset = br.ReadUInt32(); nxarc.files[i].offset += nxarc.header.filesOffset; nxarc.files[i].size = br.ReadUInt32(); nxarc.files[i].id = (ushort)i; } br.Close(); #endregion // Work with the file folder.folders = new List <sFolder>(); for (int i = 0; i < nxarc.header.num_folders; i++) { folder = ReorderFolder(folder, nxarc.folders[i], nxarc.folders[i].name); } for (int i = 0; i < nxarc.header.num_files; i++) { folder = AddFile(nxarc.files[i], folder); } return(folder); }
public static sFolder Unpack(string file, string name) { BinaryReader br = new BinaryReader(File.OpenRead(file)); sFolder folder = new sFolder(); folder.id = 0xFFFF; #region Read nxarc file // Header NXAR nxarc = new NXAR(); nxarc.header.type = br.ReadChars(4); nxarc.header.num_folders = br.ReadUInt16(); nxarc.header.num_files = br.ReadUInt16(); nxarc.header.fatOffset = br.ReadUInt32(); nxarc.header.filesOffset = br.ReadUInt32(); nxarc.header.folderTableSize = br.ReadUInt32(); nxarc.header.unknown = br.ReadUInt32(); nxarc.header.padding = br.ReadUInt64(); // Folder table nxarc.folders = new sFolder[nxarc.header.num_folders]; for (int i = 0; i < nxarc.header.num_folders; i++) { nxarc.folders[i] = new sFolder(); nxarc.folders[i].files = new List<sFile>(br.ReadUInt16()); nxarc.folders[i].id = br.ReadUInt16(); // ID of the first file } for (int i = 0; i < nxarc.header.num_folders; i++) { char c = '\x0'; for (; ; ) { c = (char)br.ReadByte(); if (c == '\x0') break; nxarc.folders[i].name += c; } } // File offset table br.BaseStream.Position = nxarc.header.fatOffset; nxarc.files = new sFile[nxarc.header.num_files]; for (int i = 0; i < nxarc.header.num_files; i++) { nxarc.files[i] = new sFile(); nxarc.files[i].name = name + '_' + i.ToString() + ".bin"; nxarc.files[i].path = file; nxarc.files[i].offset = br.ReadUInt32(); nxarc.files[i].offset += nxarc.header.filesOffset; nxarc.files[i].size = br.ReadUInt32(); nxarc.files[i].id = (ushort)i; } br.Close(); #endregion // Work with the file folder.folders = new List<sFolder>(); for (int i = 0; i < nxarc.header.num_folders; i++) { folder = ReorderFolder(folder, nxarc.folders[i], nxarc.folders[i].name); } for (int i = 0; i < nxarc.header.num_files; i++) { folder = AddFile(nxarc.files[i], folder); } return folder; }