internal Connection(KnuddelsClient client) { _client = client; string huffmantree = Encoding.UTF8.GetString(Resources.huffmantree); compress = new Compress(huffmantree); decompress = new Decompress(huffmantree); }
public void symbolic_links_are_merged_if_external_and_relinked_if_internal() { Compress.FolderToFile(@"W:\Temp\linkTest", @"W:\Temp\linktest.inpkg"); Decompress.FromFileToFolder(@"W:\Temp\linktest.inpkg", @"W:\Temp\DataResult\linkResult"); // todo: check the new output is identical to the input. File.Delete(@"W:\Temp\linktest.inpkg"); }
public void compress_a_folder_then_uncompress_results_in_same_files() { Compress.FolderToFile(@"W:\Temp\DataToCompress", @"W:\Temp\Compressed.inpkg"); Decompress.FromFileToFolder(@"W:\Temp\Compressed.inpkg", @"W:\Temp\DataResult\Pseudopseudohypoparathyroidism\Pneumonoultramicroscopicsilicovolcanoconiosis\Floccinaucinihilipilification\Antidisestablishmentarianism\Honorificabilitudinitatibus\Donaudampfschiffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft"); // todo: check the new output is identical to the input. File.Delete(@"W:\Temp\Compressed.inpkg"); }
/** * <summary>Décompresse un fichier</summary> */ private void Decompress() { // décompresse le zip Decompress decompress = new Decompress() { Source = $"{Path.Combine(InstallPath, TempDirectory)}/{File}", Destination = InstallPath }; decompress.Extract(); }
public void try_decompres_recomp_decomp_overworld(byte[] originalCompressed, byte[] expectedDecompress) { int compsize = 0; var decompressed = Decompress.ALTTPDecompressOverworld(originalCompressed, 0, originalCompressed.Length, ref compsize); int i = 0; while (i < expectedDecompress.Length && i < decompressed.Length) { if (expectedDecompress[i] != decompressed[i]) { output.WriteLine($"mismatch at {i}, expected: {expectedDecompress[i].ToString("X2")} decompressed: {decompressed[i].ToString("X2")}"); } i++; } Assert.Equal(expectedDecompress, decompressed); // recompress var recomp = Compress.ALTTPCompressOverworld(decompressed, 0, decompressed.Length); bool same = false; try { i = 0; while (i < originalCompressed.Length && i < recomp.Length) { if (originalCompressed[i] != recomp[i]) { output.WriteLine($"recompress mismatch at {i}, expected: {originalCompressed[i].ToString("X2")} recomp: {recomp[i].ToString("X2")}"); } i++; } Assert.Equal(originalCompressed, recomp); same = true; } catch (Exception ex) { same = false; } output.WriteLine($"recompress is same as original compresssed? {same}"); decompressed = Decompress.ALTTPDecompressOverworld(recomp, 0, recomp.Length, ref compsize); i = 0; while (i < expectedDecompress.Length && i < decompressed.Length) { if (expectedDecompress[i] != decompressed[i]) { output.WriteLine($"mismatch at {i}, expected: {expectedDecompress[i].ToString("X2")} decompressed: {decompressed[i].ToString("X2")}"); } i++; } Assert.Equal(expectedDecompress, decompressed); }
public async Task DecompressFiles() { var path = this.Request.Query.ElementAt(0).Key; var watch = System.Diagnostics.Stopwatch.StartNew(); var t = Task.Run(() => Decompress.TransverseDirectory(path)); //t.Wait(); await t; Debug.WriteLine(watch.ElapsedMilliseconds); //JsonResult result = new JsonResult(); //return result; }
public void should_decompress_file_moldorm_bin_and_recompress_and_decompress_to_same() { var file = File.ReadAllBytes("moldorm.bin"); int compsize = 0; var decompressed = Decompress.ALTTPDecompressGraphics(file, 0, file.Length, ref compsize); File.WriteAllBytes("moldormdecomp1.bin", decompressed); var compressed = Compress.ALTTPCompressGraphics(decompressed, 0, decompressed.Length); Assert.NotNull(compressed); File.WriteAllBytes("moldormrecomp.bin", compressed); var decomp2 = Decompress.ALTTPDecompressGraphics(compressed, 0, compressed.Length, ref compsize); Assert.Equal(decompressed, decomp2); }
public void enforce_signature() { if (Directory.Exists(@"C:\Temp\DataResult\CsvArchive")) { Directory.Delete(@"C:\Temp\DataResult\CsvArchive", true); } Compress.FolderToFile( @"C:\Temp\CsvArchive", @"C:\Temp\CsvArchive.inpkg"); Assert.Throws <System.Security.SecurityException>(() => Decompress.FromFileToFolder( @"C:\Temp\CsvArchive.inpkg", @"C:\Temp\DataResult\CsvArchive", ".\\certs\\core.example.com.pfx.cer")); }
public void can_sign_an_archive() { if (Directory.Exists(@"C:\Temp\DataResult\CsvArchive")) { Directory.Delete(@"C:\Temp\DataResult\CsvArchive", true); } Compress.FolderToFile( @"C:\Temp\CsvArchive", @"C:\Temp\CsvArchive.inpkg", ".\\certs\\core.example.com.pfx", "password"); Decompress.FromFileToFolder( @"C:\Temp\CsvArchive.inpkg", @"C:\Temp\DataResult\CsvArchive", ".\\certs\\core.example.com.pfx.cer"); }
public void should_decompress_file_ganon1_bin_and_be_same_as_ganon1_gfx() { var file = File.ReadAllBytes("ganon1.bin"); var expected = File.ReadAllBytes("ganontest.gfx"); int compsize = 0; var decompressed = Decompress.ALTTPDecompressGraphics(file, 0, file.Length, ref compsize); int i = 0; while (i < expected.Length && i < decompressed.Length) { if (expected[i] != decompressed[i]) { output.WriteLine($"mismatch at {i}, expected: {expected[i].ToString("X2")} decompressed: {decompressed[i].ToString("X2")}"); } i++; } Assert.Equal(expected, decompressed); }
public void SetInputSecurityCodec(byte[] key, bool compress) { lock (this) { Codec chain = inputCodecBuffer; if (compress) { chain = new Decompress(chain); } if (null != key) { chain = new Decrypt(chain, key); } inputCodecChain?.Dispose(); inputCodecChain = chain; IsInputSecurity = true; } }
private void button4_Click(object sender, EventArgs e) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Huffman_Tree.Comp = new FileStream("Compressed_Picture.bin", FileMode.Open); Huffman_Tree.Comp_w = new BinaryReader(Huffman_Tree.Comp); Decompress.GetReconstruct(); Decompress.GetBuildDecompress(); Huffman_Tree.Comp.Close(); Huffman_Tree.Comp_w.Close(); stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; Decompress.elapsedTime = String.Format ("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Output print = new Output(); print.Show(); }
public void DecompressAllMapTiles() { //locat functions int genPointer(int address, int i) => PointerRead.LongRead_LoHiBank(address + i * 3); byte[] Decomp(int pointer, ref int compressedSize) => Decompress.ALTTPDecompressOverworld(ROM.DATA, pointer, 1000, ref compressedSize); int npos = 0; for (int i = 0; i < 160; i++) { int p1 = genPointer(ConstantsReader.GetAddress("compressedAllMap32PointersHigh"), i), p2 = genPointer(ConstantsReader.GetAddress("compressedAllMap32PointersLow"), i); int ttpos = 0, compressedSize1 = 0, compressedSize2 = 0; byte[] bytes = Decomp(p2, ref compressedSize1), bytes2 = Decomp(p1, ref compressedSize2); for (int y = 0; y < 16; y++) { for (int x = 0, tpos; x < 16; x++, npos++, ttpos++) { tpos = (ushort)((bytes2[ttpos] << 8) + bytes[ttpos]); if (tpos < tiles32.Count) { map16tiles[npos] = new Tile32(tiles32[tpos].tile0, tiles32[tpos].tile1, tiles32[tpos].tile2, tiles32[tpos].tile3); } else { Console.WriteLine("Found 0,0,0,0"); map16tiles[npos] = new Tile32(0, 0, 0, 0); } } } } }
public void Run() { IMediaFormatProvider mediaFormat = DetermineMediaFormat(RequestModel); List <IMediaFilterProvider> filters = GetFilters(RequestModel); switch (RequestModel.ActionToPerform) { case ActionToPerform.Play: ICommand playCommand = new Play(mediaFormat, filters); _commands.Add(playCommand); playCommand.Execute(RequestModel); break; case ActionToPerform.Decompress: ICommand deCompressCommand = new Decompress(mediaFormat); _commands.Add(deCompressCommand); deCompressCommand.Execute(RequestModel); break; default: throw new ArgumentException("This function is not yet supported by MyMediaPlayer."); } }
public static DDSImage Load(Stream Source) { DDSImage _dds = new DDSImage(); using (BinaryReader _data = new BinaryReader(Source)) { if (_data.ReadInt32() != DDSImage.MAGIC_NUMBER) { throw new FileFormatException("DDSImage.Load() requires a .dds texture file stream"); } _dds.Format = CompressionMode.Unknown; _dds.Header.dwSize = _data.ReadInt32(); _dds.Header.dwFlags = _data.ReadInt32(); _dds.Header.dwHeight = _data.ReadInt32(); _dds.Header.dwWidth = _data.ReadInt32(); _dds.Header.dwPitchOrLinearSize = _data.ReadInt32(); _dds.Header.dwDepth = _data.ReadInt32(); _dds.Header.dwMipMapCount = _data.ReadInt32(); // Unused Reserved1 Fields _data.ReadBytes(11 * sizeof(int)); // Image Pixel Format _dds.PixelFormat.dwSize = _data.ReadUInt32(); _dds.PixelFormat.dwFlags = _data.ReadUInt32(); _dds.PixelFormat.dwFourCC = _data.ReadUInt32(); _dds.PixelFormat.dwRGBBitCount = _data.ReadUInt32(); _dds.PixelFormat.dwRBitMask = _data.ReadUInt32(); _dds.PixelFormat.dwGBitMask = _data.ReadUInt32(); _dds.PixelFormat.dwBBitMask = _data.ReadUInt32(); _dds.PixelFormat.dwABitMask = _data.ReadUInt32(); _dds.Header.dwCaps = _data.ReadInt32(); _dds.Header.dwCaps2 = _data.ReadInt32(); _dds.Header.dwCaps3 = _data.ReadInt32(); _dds.Header.dwCaps4 = _data.ReadInt32(); _dds.Header.dwReserved2 = _data.ReadInt32(); if ((_dds.PixelFormat.dwFlags & DDPF_FOURCC) != 0) { switch (_dds.PixelFormat.dwFourCC) { case FOURCC_DX10: _dds.Format = CompressionMode.DX10; throw new System.IO.FileFormatException("DX10 textures not supported at this time."); case FOURCC_DXT1: _dds.Format = CompressionMode.DXT1; break; case FOURCC_DXT5: _dds.Format = CompressionMode.DXT5; break; default: switch (_dds.PixelFormat.dwFourCC) { case FOURCC_DXT2: _dds.Format = CompressionMode.DXT2; break; case FOURCC_DXT3: _dds.Format = CompressionMode.DXT3; break; case FOURCC_DXT4: _dds.Format = CompressionMode.DXT4; break; } throw new System.IO.FileFormatException("Only DXT1 and DXT5 compression formats are supported at this time."); } } if ((_dds.PixelFormat.dwFlags & DDPF_FOURCC) == 0) { // Uncompressed. How many BPP? bool _supportedBpp = false; switch (_dds.PixelFormat.dwRGBBitCount) { case 8: _dds.Format = CompressionMode.RGBI8; break; case 15: _dds.Format = CompressionMode.RGB15; break; case 16: _dds.Format = CompressionMode.RGB16; break; case 24: _dds.Format = CompressionMode.RGB24; _supportedBpp = true; break; case 32: _dds.Format = CompressionMode.RGB32; _supportedBpp = true; break; } if (!_supportedBpp) { throw new Exception("Only R8G8B8 and A8R8G8B8 pixel formats are supported for uncompressed textures."); } } _dds.MipMapCount = 1; if ((_dds.Header.dwFlags & DDSD_MIPMAPCOUNT) != 0) { _dds.MipMapCount = (_dds.Header.dwMipMapCount == 0) ? 1 : _dds.Header.dwMipMapCount; } _dds.Images = new Bitmap[_dds.MipMapCount]; int _imageSize; int _w = (_dds.Header.dwWidth < 0) ? -_dds.Header.dwWidth : _dds.Header.dwWidth; int _h = (_dds.Header.dwHeight < 0) ? -_dds.Header.dwHeight : _dds.Header.dwHeight; // DDS Documentation recommends ignoring the dwLinearOrPitchSize value and calculating on your own. if ((_dds.PixelFormat.dwFlags & DDPF_RGB) != 0) { // Linear Size _imageSize = (_w * _h * ((int)_dds.PixelFormat.dwRGBBitCount + 7) >> 3); } else { // Compressed _imageSize = 16 * ((_w + 3) >> 2) * (((_h + 3) >> 2)); if (_dds.PixelFormat.dwFourCC == FOURCC_DXT1) { _imageSize >>= 1; } } byte[] _imageBits; for (int _level = 0; _level < _dds.MipMapCount; _level++) { try { _imageBits = _data.ReadBytes(_imageSize >> (_level << 1)); int _w2 = _w >> _level; int _h2 = _h >> _level; uint _compressionMode = _dds.PixelFormat.dwFourCC; if ((_dds.PixelFormat.dwFlags & DDPF_RGB) != 0) { _compressionMode = _dds.PixelFormat.dwRGBBitCount; _dds.Format = (_dds.PixelFormat.dwRGBBitCount == 24) ? CompressionMode.RGB24 : CompressionMode.RGB32; } else if ((_dds.PixelFormat.dwFlags & DDPF_FOURCC) == 0 && _dds.PixelFormat.dwRGBBitCount == 16 && _dds.PixelFormat.dwRBitMask == 0x00FF && _dds.PixelFormat.dwGBitMask == 0xFF00 && _dds.PixelFormat.dwBBitMask == 0x0000 && _dds.PixelFormat.dwABitMask == 0x0000) { _dds.Format = CompressionMode.V8U8; _compressionMode = FOURCC_V8U8; } _dds.Images[_level] = Decompress.Image(_imageBits, _w2, _h2, _compressionMode); } catch { // Unexpected end of file. Perhaps mipmaps weren't fully written to file. // We'll at least provide them with what we've extracted so far. _dds.MipMapCount = _level; if (_level == 0) { _dds.Images = null; throw new FileFormatException("Unable to read pixel data."); } else { Array.Resize <Bitmap>(ref _dds.Images, _level); } } } } return(_dds); }
private List <GenericVertex> ParseBuffer(byte[] buffer) { List <GenericVertex> Vertices = new List <GenericVertex>(); byte[] attributeBuffer = new byte[0]; int stride = 0; int vertexCount = 0; using (DataReader r = new DataReader(new System.IO.MemoryStream(buffer))) { r.Seek(0x4); uint attOffset = r.ReadUInt16(); int attSomething = r.ReadInt16(); uint verOffset = r.ReadUInt16(); stride = r.ReadInt16(); vertexCount = r.ReadInt32(); attributeBuffer = Decompress.Level5Decom(r.GetSection(attOffset, attSomething)); buffer = Decompress.Level5Decom(r.GetSection(verOffset, (int)(r.Length - verOffset))); } int[] ACount = new int[10]; int[] AOffet = new int[10]; int[] ASize = new int[10]; int[] AType = new int[10]; using (DataReader r = new DataReader(new System.IO.MemoryStream(attributeBuffer))) { for (int i = 0; i < 10; i++) { ACount[i] = r.ReadByte(); AOffet[i] = r.ReadByte(); ASize[i] = r.ReadByte(); AType[i] = r.ReadByte(); if (ACount[i] > 0 && i != 0 && i != 1 && i != 2 && i != 4 && i != 7 && i != 8 && i != 9) { Console.WriteLine(i + " " + ACount[i] + " " + AOffet[i] + " " + ASize[i] + " " + AType[i]); } } } using (DataReader r = new DataReader(new System.IO.MemoryStream(buffer))) { for (int i = 0; i < vertexCount; i++) { GenericVertex vert = new GenericVertex(); vert.Clr = new Vector4(1, 1, 1, 1); for (int j = 0; j < 10; j++) { r.Seek((uint)(i * stride + AOffet[j])); switch (j) { case 0: //Position vert.Pos = ReadAttribute(r, AType[j], ACount[j]).Xyz; break; case 1: //Tangent break; case 2: //Normal vert.Nrm = ReadAttribute(r, AType[j], ACount[j]).Xyz; break; case 4: //UV0 vert.UV0 = ReadAttribute(r, AType[j], ACount[j]).Xy; break; case 7: //Bone Weight vert.Weights = ReadAttribute(r, AType[j], ACount[j]); break; case 8: //Bone Index Vector4 vn = ReadAttribute(r, AType[j], ACount[j]); if (NodeTable.Length > 0 && NodeTable.Length != 1) { vert.Bones = new Vector4(NodeTable[(int)vn.X], NodeTable[(int)vn.Y], NodeTable[(int)vn.Z], NodeTable[(int)vn.W]); } break; case 9: // Color vert.Clr = ReadAttribute(r, AType[j], ACount[j]).Yzwx; break; } } Vertices.Add(vert); } } // return(Vertices); }
/// <summary> /// Create Snes Data Gfx (3 and 2 bpp) snes format /// </summary> /// <param name="CreateAllGfxDataRaw"></param> /// <returns></returns> public static byte[] CreateAllGfxDataRaw(byte[] romData) { //0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 bytes //113-114 -> compressed 2bpp -> (decompressed each) 0x800 bytes //115-126 -> uncompressed 3bpp sprites -> (each) 0x600 bytes //127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 bytes //218-222 -> compressed 2bpp -> (decompressed each) 0x800 bytes byte[] buffer = new byte[0x54A00]; int bufferPos = 0; byte[] data = new byte[0x600]; int compressedSize = 0; LogData.AddLine("====GFX Creation - Start===="); for (int i = 0; i < 223; i++) { bool c = true; if (i >= 0 && i <= 112) //compressed 3bpp bgr { isbpp3[i] = true; } else if (i >= 113 && i <= 114) //compressed 2bpp { isbpp3[i] = false; } else if (i >= 115 && i <= 126) //uncompressed 3bpp sprites { isbpp3[i] = true; c = false; } else if (i >= 127 && i <= 217) //compressed 3bpp sprites { isbpp3[i] = true; } else if (i >= 218 && i <= 222) //compressed 2bpp { isbpp3[i] = false; } if (c)//if data is compressed decompress it { data = Decompress.ALTTPDecompressGraphics(romData, GetPCGfxAddress(romData, (byte)i), 0x800, ref compressedSize); LogData.AddLine("Gfx " + i.ToString() + " Size Decompressed:0x" + data.Length.ToString("X4") + " Compressed:0x" + compressedSize.ToString("X4")); } else { data = new byte[0x600]; int startAddress = GetPCGfxAddress(romData, (byte)i); for (int j = 0; j < 0x600; j++) { data[j] = romData[j + startAddress]; } LogData.AddLine("2bpp Gfx " + i.ToString() + " Size Decompressed:0x" + data.Length.ToString("X4") + " Compressed:NULL"); } for (int j = 0; j < data.Length; j++) { buffer[j + bufferPos] = data[j]; } bufferPos += data.Length; } return(buffer); }
public void should_decompress_feesh_mode_rom() { var file = File.ReadAllBytes("Feesh_Mode_Patched.sfc"); int compsize = 0; var decompressed = Decompress.ALTTPDecompressGraphics(file, 0x08B800, file.Length - 0x08B800, ref compsize); }
public static byte[] DecompressTiles() //to gfx.bin { int gfxPointer1 = Addresses.snestopc((ROM.DATA[ConstantsReader.GetAddress("gfx_1_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("gfx_1_pointer")])), gfxPointer2 = Addresses.snestopc((ROM.DATA[ConstantsReader.GetAddress("gfx_2_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("gfx_2_pointer")])), gfxPointer3 = Addresses.snestopc((ROM.DATA[ConstantsReader.GetAddress("gfx_3_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("gfx_3_pointer")])); byte[] buffer = new byte[0x6F800], // (185) bufferBlock; int bufferPos = 0; for (int i = 0; i < 96; i++) { byte[] b = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 }; int addr = BitConverter.ToInt32(b, 0); addresses[i] = Addresses.snestopc(addr); //Console.WriteLine(Addresses.snestopc(addr).ToString("X6")); byte[] tbufferBlock = Decompress.ALTTPDecompressGraphics(ROM.DATA, Addresses.snestopc(addr), 0x800, ref blockSize[i]); bufferBlock = tbufferBlock; if (tbufferBlock.Length != 0x600) { bpp[i] = 2; bufferBlock = new byte[0x600]; for (int j = 0; j < 0x600; j++) { bufferBlock[j] = tbufferBlock[j]; } } else { bpp[i] = 3; } //bufferBlock = Decompress(Addresses.snestopc(addr), ROM.DATA); for (int j = 0; j < bufferBlock.Length; j++) { buffer[bufferPos] = bufferBlock[j]; bufferPos++; } } for (int i = 96; i < 223; i++) { bpp[i] = 3; if (i < 115 || i > 126) //not compressed { byte[] b = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 }; int addr = BitConverter.ToInt32(b, 0); addresses[i] = Addresses.snestopc(addr); byte[] tbufferBlock = Decompress.ALTTPDecompressGraphics(ROM.DATA, Addresses.snestopc(addr), 0x800, ref blockSize[i]); bufferBlock = tbufferBlock; if (tbufferBlock.Length != 0x600) { bpp[i] = 2; bufferBlock = new byte[0xC00]; //Console.WriteLine(tbufferBlock.Length); for (int j = 0; j < tbufferBlock.Length; j++) { bufferBlock[j] = tbufferBlock[j]; } //Console.WriteLine("Buffer Size :" + tbufferBlock.Length.ToString("X4")); } for (int j = 0; j < bufferBlock.Length; j++) { buffer[bufferPos] = bufferBlock[j]; bufferPos++; } } else { byte[] b = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 }; int addr = BitConverter.ToInt32(b, 0); addr = Addresses.snestopc(addr); bpp[i] = 3; for (int j = 0; j < 0x600; j++) { buffer[bufferPos] = ROM.DATA[addr + j]; bufferPos++; } } } /*FileStream fs = new FileStream("testgfx.gfx", FileMode.OpenOrCreate, FileAccess.Write); * fs.Write(buffer.ToArray(), 0, buffer.Length); * fs.Close();*/ return(buffer); }
public void Open(byte[] data) { using (DataReader r = new DataReader(new MemoryStream(data))) { r.Seek(0x10); Height = r.ReadInt16(); Width = r.ReadInt16(); r.Seek(0xA); int type = r.ReadByte(); r.Seek(0x1C); int someTable = r.ReadInt16(); r.Seek(0x38); int someTableSize = r.ReadInt32(); int imageDataOffset = someTable + someTableSize; byte[] _tileData = Decompress.Level5Decom(r.GetSection((uint)someTable, someTableSize)); if (_tileData.Length > 2 && _tileData[0] == 0x53 && _tileData[1] == 0x04) { SwitchFile = true; } using (DataReader tileData = new DataReader(new MemoryStream(_tileData))) { int tileCount = 0; while (tileData.Position + 2 <= tileData.BaseStream.Length) { int i = SwitchFile ? tileData.ReadInt32() : tileData.ReadInt16(); if (i > tileCount) { tileCount = i; } Tiles.Add(i); } } switch (type) { case 0x1: type = 0x4; break; case 0x3: type = 0x1; break; case 0x4: type = 0x3; break; case 0x1B: type = 0xC; break; case 0x1C: type = 0xD; break; case 0x1D: case 0x1F: break; default: //File.WriteAllBytes("texture.bin", Decompress.Level5Decom(r.GetSection((uint)imageDataOffset, (int)(r.BaseStream.Length - imageDataOffset)))); throw new Exception("Unknown Texture Type " + type.ToString("x")); //break; } ImageFormat = (byte)type; ImageData = Decompress.Level5Decom(r.GetSection((uint)imageDataOffset, (int)(r.BaseStream.Length - imageDataOffset))); } }
public Level5_Resource(byte[] data) { data = Decompress.Level5Decom(data); using (DataReader r = new DataReader(new System.IO.MemoryStream(data))) { var magic = new string(r.ReadChars(6)); if (magic != "CHRC00" && magic != "CHRN01") { throw new FormatException("RES file is corrupt"); } // ----------------------- var unknown0 = r.ReadInt16(); var stringTableOffset = r.ReadInt16() << 2; var unknown1 = r.ReadInt16(); var materialTableOffset = r.ReadInt16() << 2; var materialTableSectionCount = r.ReadInt16(); var resourceNodeOffsets = r.ReadInt16() << 2; var resourceNodeCount = r.ReadInt16(); r.Seek((uint)stringTableOffset); while (r.Position < r.BaseStream.Length) { string mname = r.ReadString(); if (mname == "") { break; } if (!ResourceNames.ContainsKey(CRC32.Crc32C(mname))) { ResourceNames.Add(CRC32.Crc32C(mname), mname); } } r.Seek((uint)materialTableOffset); for (int i = 0; i < materialTableSectionCount; i++) { var offset = r.ReadInt16() << 2; var count = r.ReadInt16(); var unknown = r.ReadInt16(); var size = r.ReadInt16(); if (unknown == 0x270F) { continue; } var temp = r.Position; for (int j = 0; j < count; j++) { r.Position = (uint)(offset + j * size); var key = r.ReadUInt32(); string resourceName = (ResourceNames.ContainsKey(key) ? ResourceNames[key] : key.ToString("X")); //Console.WriteLine(resourceName + " " + unknown.ToString("X") + " " + size.ToString("X")); if (unknown == 0xF0) { TextureNames.Add(resourceName); } if (unknown == 0x122) { Level5_Material mat = new Level5_Material(); mat.Name = resourceName; r.Skip(12); key = r.ReadUInt32(); resourceName = (ResourceNames.ContainsKey(key) ? ResourceNames[key] : key.ToString("X")); mat.TexName = resourceName; Console.WriteLine(resourceName + " " + unknown.ToString("X") + " " + size.ToString("X")); Materials.Add(mat); } } r.Seek(temp); } r.Seek((uint)resourceNodeOffsets); for (int i = 0; i < resourceNodeCount; i++) { var offset = r.ReadInt16() << 2; var count = r.ReadInt16(); var unknown = r.ReadInt16(); var size = r.ReadInt16(); if (unknown == 0x270F) { continue; } var temp = r.Position; r.Seek((uint)offset); for (int j = 0; j < count; j++) { var key = r.ReadUInt32(); //Console.WriteLine((ResourceNames.ContainsKey(key) ? ResourceNames[key] : key.ToString("X")) + " " + unknown.ToString("X") + " " + size.ToString("X")); r.Position += (uint)(size - 4); } r.Seek(temp); } } }
public static List <string> skipped = new List <string>(); // Define the skipped list for error tracking /// <summary> /// Installs the specified mods (requires for statement iteration for more than one mod). /// </summary> /// <param name="mod">File path to the mod's INI file.</param> /// <param name="name">Name of the mod by Title key.</param> public static void InstallMods(string mod, string name) { string platform = INI.DeserialiseKey("Platform", mod); // Deserialise 'Platform' key bool merge = false; // Deserialise 'Merge' key string[] read_only = INI.DeserialiseKey("Read-only", mod).Split(','); // Deserialise 'Read-only' key try { // Attempt to parse as a Boolean value merge = bool.Parse(INI.DeserialiseKey("Merge", mod)); } catch { merge = false; } //Skip the mod if the platform is invalid string system = Literal.System(Properties.Settings.Default.Path_GameDirectory); if (system != platform && platform != "All Systems") { skipped.Add($"► {name} (failed because the mod was not targeted for the {system})"); return; } // Search for all files with specified LINQ filters List <string> files = Directory.GetFiles(Path.GetDirectoryName(mod), "*.*", SearchOption.AllDirectories) .Where(s => s.Contains(".ar") || s.EndsWith(".arl") || s.EndsWith(".dds") || s.EndsWith("default.xex") || s.EndsWith("EBOOT.BIN") || s.EndsWith(".sfd") || s.EndsWith(".pfd") || s.EndsWith(".csb") || s.EndsWith(".cpk")).ToList(); foreach (string file in files) { // Absolute file path string filePath = file.Remove(0, Path.GetDirectoryName(mod).Length); // Absolute file path (from the mod) combined with the game directory string vanillaFilePath = Path.Combine(Path.GetDirectoryName(Properties.Settings.Default.Path_GameDirectory), filePath.Substring(1)); // Define string to store backed up file string targetFilePath = string.Empty; // Proceed with backup if ((targetFilePath = Content.CreateBackup(vanillaFilePath)) != string.Empty) { // Decompress backed up ARL to compare AR count with later if (Path.GetExtension(vanillaFilePath) == ".arl") { Decompress.DecompressBySystem(targetFilePath); } // Merge modified data if (Path.GetFileName(file).Contains(".ar") && merge && !read_only.Contains(Path.GetFileName(file))) { if (RushInterface._debug) { Console.WriteLine($"Merging: {file}"); } Content.Merge(vanillaFilePath, file); // Copy the modified data } else { if (RushInterface._debug) { Console.WriteLine($"Copying: {file}"); } File.Copy(file, vanillaFilePath, true); } } else { if (RushInterface._debug) { Console.WriteLine($"Copying: {file}"); } File.Copy(file, vanillaFilePath, true); } } }
public void Open(FileItem file) { anim.Name = file.FilePath; using (DataReader r = new DataReader(file)) { r.BigEndian = false; r.Seek(0x08); var decomSize = r.ReadInt32(); var nameOffset = r.ReadUInt32(); var compDataOffset = r.ReadUInt32(); var positionCount = r.ReadInt32(); var rotationCount = r.ReadInt32(); var scaleCount = r.ReadInt32(); var unknownCount = r.ReadInt32(); var boneCount = r.ReadInt32(); r.Seek(0x54); anim.FrameCount = r.ReadInt32(); r.Seek(nameOffset); var hash = r.ReadUInt32(); anim.Name = r.ReadString(r.Position, -1); var data = Decompress.Level5Decom(r.GetSection(compDataOffset, (int)(r.Length - compDataOffset))); using (DataReader d = new DataReader(data)) { // Header var boneHashTableOffset = d.ReadUInt32(); var trackInfoOffset = d.ReadUInt32(); var dataOffset = d.ReadUInt32(); // Bone Hashes List <uint> boneNameHashes = new List <uint>(); d.Seek(boneHashTableOffset); while (d.Position < trackInfoOffset) { boneNameHashes.Add(d.ReadUInt32()); } // Track Information List <AnimTrack> Tracks = new List <AnimTrack>(); for (int i = 0; i < 4; i++) { d.Seek((uint)(trackInfoOffset + 2 * i)); d.Seek(d.ReadUInt16()); Tracks.Add(new AnimTrack() { Type = d.ReadByte(), DataType = d.ReadByte(), unk = d.ReadByte(), DataCount = d.ReadByte(), Start = d.ReadUInt16(), End = d.ReadUInt16() }); } foreach (var v in Tracks) { Console.WriteLine(v.Type + " " + v.DataType + " " + v.DataCount + " " + v.Start.ToString("X") + " " + v.End.ToString("X")); } // Data foreach (var v in boneNameHashes) { var node = new GenericAnimationTransform(); node.Hash = v; node.HashType = AnimNodeHashType.CRC32C; anim.TransformNodes.Add(node); } var offset = 0; ReadFrameData(d, offset, positionCount, dataOffset, boneCount, Tracks[0]); offset += positionCount; ReadFrameData(d, offset, rotationCount, dataOffset, boneCount, Tracks[1]); offset += rotationCount; ReadFrameData(d, offset, scaleCount, dataOffset, boneCount, Tracks[2]); offset += scaleCount; //ReadFrameData(d, unknownCount, dataOffset, boneCount, Tracks[3]); } } }
public static Dds Load(Stream Source) { var _dds = new Dds(); using (var _data = new BinaryReader(Source)) { if (_data.ReadInt32() != Dds.MAGIC_NUMBER) { throw new FileFormatException("DDSImage.Load() requires a .dds texture file stream"); } _dds.Format = CompressionMode.Unknown; _dds.Header.dwSize = _data.ReadInt32(); _dds.Header.dwFlags = _data.ReadInt32(); _dds.Header.dwHeight = _data.ReadInt32(); _dds.Header.dwWidth = _data.ReadInt32(); _dds.Header.dwPitchOrLinearSize = _data.ReadInt32(); _dds.Header.dwDepth = _data.ReadInt32(); _dds.Header.dwMipMapCount = _data.ReadInt32(); // Unused Reserved1 Fields _data.ReadBytes(11 * sizeof(int)); // Image Pixel Format _dds.PixelFormat.dwSize = _data.ReadUInt32(); _dds.PixelFormat.dwFlags = _data.ReadUInt32(); _dds.PixelFormat.dwFourCC = _data.ReadUInt32(); _dds.PixelFormat.dwRGBBitCount = _data.ReadUInt32(); _dds.PixelFormat.dwRBitMask = _data.ReadUInt32(); _dds.PixelFormat.dwGBitMask = _data.ReadUInt32(); _dds.PixelFormat.dwBBitMask = _data.ReadUInt32(); _dds.PixelFormat.dwABitMask = _data.ReadUInt32(); _dds.Header.dwCaps = _data.ReadInt32(); _dds.Header.dwCaps2 = _data.ReadInt32(); _dds.Header.dwCaps3 = _data.ReadInt32(); _dds.Header.dwCaps4 = _data.ReadInt32(); _dds.Header.dwReserved2 = _data.ReadInt32(); if ((_dds.PixelFormat.dwFlags & DDPF_FOURCC) != 0) { switch (_dds.PixelFormat.dwFourCC) { case FOURCC_DX10: _dds.Format = CompressionMode.DX10; throw new FileFormatException("DX10 textures not supported at this time."); case FOURCC_DXT1: _dds.Format = CompressionMode.DXT1; break; case FOURCC_DXT2: _dds.Format = CompressionMode.DXT2; break; case FOURCC_DXT3: _dds.Format = CompressionMode.DXT3; break; case FOURCC_DXT4: _dds.Format = CompressionMode.DXT4; break; case FOURCC_DXT5: _dds.Format = CompressionMode.DXT5; break; default: throw new FileFormatException("Unsupported compression format"); } } if ((_dds.PixelFormat.dwFlags & DDPF_FOURCC) == 0) { // Uncompressed. How many BPP? var _supportedBpp = false; switch (_dds.PixelFormat.dwRGBBitCount) { case 16: if (_dds.PixelFormat.dwABitMask == 0) { _dds.Format = CompressionMode.R5G6B5; } else { _dds.Format = CompressionMode.A1R5G5B5; } _supportedBpp = true; break; case 24: _dds.Format = CompressionMode.RGB24; _supportedBpp = true; break; case 32: _dds.Format = CompressionMode.RGB32; _supportedBpp = true; break; } if (!_supportedBpp) { throw new Exception( "Only 16, 24, and 32-bit pixel formats are supported for uncompressed textures."); } } _dds.MipMapCount = 1; if ((_dds.Header.dwFlags & DDSD_MIPMAPCOUNT) != 0) { _dds.MipMapCount = _dds.Header.dwMipMapCount == 0 ? 1 : _dds.Header.dwMipMapCount; } _dds.Images = new Image[_dds.MipMapCount]; int _imageSize; var _w = _dds.Header.dwWidth < 0 ? -_dds.Header.dwWidth : _dds.Header.dwWidth; var _h = _dds.Header.dwHeight < 0 ? -_dds.Header.dwHeight : _dds.Header.dwHeight; // DDS Documentation recommends ignoring the dwLinearOrPitchSize value and calculating on your own. if ((_dds.PixelFormat.dwFlags & DDPF_RGB) != 0) { // Linear Size _imageSize = _w * _h * ((int)_dds.PixelFormat.dwRGBBitCount + 7) >> 3; } else { // Compressed _imageSize = ((_w + 3) >> 2) * ((_h + 3) >> 2); switch (_dds.PixelFormat.dwFourCC) { case FOURCC_DXT1: _imageSize <<= 3; // 64 bits color per block break; case FOURCC_DXT2: case FOURCC_DXT3: _imageSize <<= 4; // 64 bits alpha + 64 bits color per block break; case FOURCC_DXT4: case FOURCC_DXT5: _imageSize <<= 4; // 64 bits alpha + 64 bits color per block break; } } byte[] _imageBits; for (var _level = 0; _level < _dds.MipMapCount; _level++) { try { _imageBits = _data.ReadBytes(_imageSize >> (_level << 1)); var _w2 = _w >> _level; var _h2 = _h >> _level; var _compressionMode = _dds.PixelFormat.dwFourCC; if ((_dds.PixelFormat.dwFlags & DDPF_RGB) != 0) { _compressionMode = (uint)_dds.Format; } else if ((_dds.PixelFormat.dwFlags & DDPF_FOURCC) == 0 && _dds.PixelFormat.dwRGBBitCount == 16 && _dds.PixelFormat.dwRBitMask == 0x00FF && _dds.PixelFormat.dwGBitMask == 0xFF00 && _dds.PixelFormat.dwBBitMask == 0x0000 && _dds.PixelFormat.dwABitMask == 0x0000) { _dds.Format = CompressionMode.V8U8; _compressionMode = FOURCC_V8U8; } _dds.Images[_level] = Decompress.Image(_imageBits, _w2, _h2, _compressionMode); _dds.Images[_level].SwapRB(); //_dds.Images[_level].FlipY(); } catch (Exception e) { // Unexpected end of file. Perhaps mipmaps weren't fully written to file. // We'll at least provide them with what we've extracted so far. _dds.MipMapCount = _level; if (_level == 0) { _dds.Images = null; throw new FileFormatException("Unable to read pixel data."); } else { Array.Resize <Image>(ref _dds.Images, _level); } } } } return(_dds); }
private List <uint> ParseIndexBuffer(byte[] buffer) { List <uint> Indices = new List <uint>(); int PrimitiveType = 0; int FaceCount = 0; using (DataReader r = new DataReader(new System.IO.MemoryStream(buffer))) { r.Seek(0x04); PrimitiveType = r.ReadInt16(); uint faceOffset = r.ReadUInt16(); FaceCount = r.ReadInt32(); buffer = Decompress.Level5Decom(r.GetSection(faceOffset, (int)(r.Length - faceOffset))); } if (PrimitiveType != 2 && PrimitiveType != 0) { throw new NotSupportedException("Primitve Type no implemented"); } if (PrimitiveType == 0) { using (DataReader r = new DataReader(new System.IO.MemoryStream(buffer))) { r.Seek(0); for (int i = 0; i < FaceCount / 2; i++) { Indices.Add(r.ReadUInt16()); } } } if (PrimitiveType == 2) { using (DataReader r = new DataReader(new System.IO.MemoryStream(buffer))) { //Console.WriteLine(PrimitiveType + " " + FaceCount + " " + r.BaseStream.Length / 2); r.Seek(0); int f1 = r.ReadInt16(); int f2 = r.ReadInt16(); int f3; int dir = -1; int startdir = -1; for (int i = 0; i < FaceCount - 2; i++) { if (r.Position + 2 > r.Length) { break; } //if (r.Position + 2 > r.Length) // break; f3 = r.ReadInt16(); if (f3 == 0xFFFF || f3 == -1) { f1 = r.ReadInt16(); f2 = r.ReadInt16(); dir = startdir; } else { dir *= -1; if (f1 != f2 && f2 != f3 && f3 != f1) { /*if (f1 > vCount || f2 > vCount || f3 > vCount) * { * f1 = 0; * }*/ if (dir > 0) { Indices.Add((uint)f1); Indices.Add((uint)f2); Indices.Add((uint)f3); } else { Indices.Add((uint)f1); Indices.Add((uint)f3); Indices.Add((uint)f2); } } f1 = f2; f2 = f3; } } } } return(Indices); }
public async Task DownloadFile(string url, string fileName) { using (WebClient client = new WebClient()) { string filePath = Path.Combine(AppPath, fileName); string unZipFolderName = Path.GetFileNameWithoutExtension(fileName); string directoryPath = Path.Combine(AppPath, Path.GetDirectoryName(fileName)); //string realFileName = Android.Webkit.URLUtil.GuessFileName(url, null, null); if (!string.IsNullOrEmpty(directoryPath) && !Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } client.DownloadFileCompleted += (sender, e) => { float freeSpace = FreeMemory(); if (e.Error != null) { System.Diagnostics.Debug.WriteLine("Error : " + e.Error.Message); } if (!e.Cancelled) { try { if (File.Exists(filePath)) { FileInfo file = new FileInfo(filePath); if (Path.GetExtension(filePath) == ".zip") { string unZipFile = Path.Combine(AppPath, unZipFolderName); if (!Directory.Exists(unZipFile)) { Directory.CreateDirectory(unZipFile); } Decompress decompress = new Decompress(filePath, unZipFile); decompress.UnZip(); File.Delete(filePath); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error : " + ex.Message); } } }; try { await client.DownloadFileTaskAsync(url, filePath); //System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; ////client. //client.DownloadDataAsync(new Uri(url)); //client.DownloadDataCompleted += (sen, e) => //{ // if (e.Error == null) // { // byte[] bytes = e.Result; // float sizeMb = bytes.Length / 1024F / 1024F; // float freeMemoryMb = FreeMemory(); // if (freeMemoryMb > (2 * sizeMb)) // { // using (FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write)) // { // fs.Write(bytes, 0, bytes.Length); // } // if (File.Exists(filePath)) // { // if (Path.GetExtension(filePath) == ".zip") // { // freeMemoryMb = FreeMemory(); // if (freeMemoryMb > (5 * sizeMb)) // { // //string unZipFile = Path.Combine(AppPath); // string unZipFile = Path.Combine(AppPath, "12.1"); // if (!Directory.Exists(unZipFile)) { // Directory.CreateDirectory(unZipFile); // } // Decompress decompress = new Decompress(filePath, unZipFile); // decompress.UnZip(); // File.Delete(filePath); // } // else { // System.Diagnostics.Debug.WriteLine("Espacio no disponible para descomprimir el archivo"); // } // } // } // } // else { // System.Diagnostics.Debug.WriteLine("Espacio no disponible para la descarga."); // } // } //}; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error : " + ex.Message); } } }
public void should_decompress_file_moldorm_bin() { var file = File.ReadAllBytes("moldorm.bin"); int compsize = 0; var decompressed = Decompress.ALTTPDecompressGraphics(file, 0, file.Length, ref compsize); }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Enter the seed name too."); return; } //todo better (or any lol) file checking string fileName = args[0]; //string fileName = "test0.sfc"; byte[] data = File.ReadAllBytes(fileName); int table_address = 0x27ce0; int c_table_length = 799; Random rnd = new Random(); string spoiler = ""; // decompress the enemy damage table from the ROM (thanks Zarby) int f = 0; byte[] sdata = Decompress.ALTTPDecompressOverworld(data, 0x27ce0, c_table_length, ref f); byte[] udata = new byte[3000]; byte[] enemy_table = new byte[5000]; // expanding the array (unsure if needed) for (int i = 0; i < udata.Length; i++) { if (i < sdata.Length) { udata[i] = sdata[i]; } else { udata[i] = 0; } } // split bytes for (int i = 0; i < 5000; i += 2) { enemy_table[i] = (byte)(udata[i / 2] >> 4); enemy_table[i + 1] = (byte)(udata[i / 2] & 0x0F); } // normalize the enemy damage table byte[] new_enemy_table = Enemy_Table_Setup(enemy_table); // recombine bytes byte[] combined_table = new byte[2048]; for (int i = 0; i < 2048; i += 1) { combined_table[i] = (byte)((new_enemy_table[(i * 2)] << 4) | new_enemy_table[(i * 2) + 1]); } // recompress table byte[] compressed_enemy_table = Compress.ALTTPCompressOverworld(combined_table, 0, combined_table.Length); // write table to ROM data - table cannot exceed 799 bytes length for (int i = 0; (i < c_table_length & i < compressed_enemy_table.Length); i++) { data[table_address + i] = compressed_enemy_table[i]; } // create new damage table and write to ROM data byte[] new_damage_table = Create_Damage_Table(); int damage_table_address = 0x6B8F1; for (int i = 0; i < 128; i++) { data[damage_table_address + i] = new_damage_table[i]; } // write spoiler info string[] weaponClassNames = new string[] { "Boomerang", "Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Bow", "Hookshot", "Bombs", "Silvers", "Powder", "Fire Rod", "Ice Rod", "Bombos", "Ether", "Quake" }; for (int i = 0; i < 16; i++) { spoiler += weaponClassNames[i] + ": " + Convert.ToString(new_damage_table[i * 8 + 1]) + "\r\n"; } // randomize powder fairy prize int fairy_address = 0x36DD0; // fairy, bees, appl, fish, heart, $5, $20, bomb, magic byte[] fairy_options = new byte[] { 0xE3, 0x79, 0xAC, 0xD2, 0xD8, 0xDA, 0xDB, 0xDC, 0xDF }; data[fairy_address] = fairy_options[rnd.Next(fairy_options.Length)]; spoiler += "Fairy prize: " + Convert.ToString(data[fairy_address] + "\r\n"); // randomize bomb timers lol int bomb_timer_address = 0x41543; // write fuse timer to ROM, first byte - setting to 00 causes max timer data[bomb_timer_address] = (byte)(rnd.Next(254) + 1); spoiler += "Bomb timers: " + Convert.ToString(data[bomb_timer_address]) + ", "; // bomb explosion speed is next 10 bytes byte[,] rates = new byte[, ] { { 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02 }, // fastest { 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03 }, // double speed { 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x06, 0x06, 0x06 }, // default { 0x0C, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0C, 0x0C, 0x0C, 0x0C }, // half speed { 0x18, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x18, 0x18, 0x18, 0x18 }, // quarter speed lol // repeat 'moderate' ones to increase weight { 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03 }, // double speed { 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x06, 0x06, 0x06 }, // default { 0x0C, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0C, 0x0C, 0x0C, 0x0C }, // half speed // repeat default again for most weight { 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x06, 0x06, 0x06 } }; // default // choose one of the 9 rows int row = rnd.Next(9); // write to ROM for (int i = 0; i < 10; i++) { data[bomb_timer_address + i + 1] = rates[row, i]; spoiler += Convert.ToString(rates[row, i]) + " "; } spoiler += "\r\n"; File.WriteAllText("wpn_" + fileName + ".txt", spoiler); FileStream fs = new FileStream("wpn_" + fileName, FileMode.CreateNew, FileAccess.Write); fs.Write(data, 0, data.Length); fs.Close(); }
public void Open(FileItem File) { using (DataReader r = new DataReader(new MemoryStream(File.GetFileBinary()))) { if (!new string(r.ReadChars(4)).Equals("XPCK")) { throw new Exception("File header error"); } uint fileCount = (uint)(r.ReadUInt16() & 0xFFF); var fileInfoOffset = r.ReadUInt16() * 4; var fileTableOffset = r.ReadUInt16() * 4; var dataOffset = r.ReadUInt16() * 4; r.ReadUInt16(); var filenameTableSize = r.ReadUInt16() * 4; var hashToData = new Dictionary <uint, byte[]>(); r.Seek((uint)fileInfoOffset); for (int i = 0; i < fileCount; i++) { var nameCRC = r.ReadUInt32(); r.ReadInt16(); var offset = (uint)r.ReadUInt16(); var size = (uint)r.ReadUInt16(); var offsetExt = (uint)r.ReadByte(); var sizeExt = (uint)r.ReadByte(); offset |= offsetExt << 16; size |= sizeExt << 16; offset = (uint)(offset * 4 + dataOffset); var data = r.GetSection(offset, (int)size); //Decompress.CheckLevel5Zlib(data, out data); hashToData.Add(nameCRC, data); } byte[] nameTable = r.GetSection((uint)fileTableOffset, filenameTableSize); if (!Decompress.CheckLevel5Zlib(nameTable, out nameTable)) { nameTable = Decompress.lzss_Decompress(nameTable); } using (DataReader nt = new DataReader(new MemoryStream(nameTable))) { for (int i = 0; i < fileCount; i++) { var name = nt.ReadString(); if (hashToData.ContainsKey(CRC32.Crc32C(name))) { Files.Add(name, hashToData[CRC32.Crc32C(name)]); } else { Console.WriteLine("Couldn't find " + name + " " + CRC32.Crc32C(name).ToString("X")); } } } } }