diff --git a/CoDLuaDecompiler.Decompiler/LuaFile/LuaFileFactory.cs b/CoDLuaDecompiler.Decompiler/LuaFile/LuaFileFactory.cs index 3f55d7e..687216f 100644 --- a/CoDLuaDecompiler.Decompiler/LuaFile/LuaFileFactory.cs +++ b/CoDLuaDecompiler.Decompiler/LuaFile/LuaFileFactory.cs @@ -57,9 +57,33 @@ public static ILuaFile Create(string filePath, bool usesDebugInfo = false) } using var stream = File.OpenRead(filePath); - using var reader = new BinaryReader(stream); + BinaryReader? reader; + + int b1 = stream.ReadByte(); + stream.Seek(0, SeekOrigin.Begin); + + if (b1 == 0x78) + { + // zlib file, need decompress + byte[] buffer = new byte[0x1000]; + using (MemoryStream ms = new MemoryStream()) + using (ZLibStream zlibStream = new ZLibStream(stream, CompressionMode.Decompress, false)) + { + int read; + while ((read = zlibStream.Read(buffer, 0, buffer.Length)) > 0) + { + ms.Write(buffer, 0, read); + } + reader = new BinaryReader(new MemoryStream(ms.ToArray())); + } + + } + else + { + reader = new BinaryReader(stream); + } return Create(reader, filePath, usesDebugInfo); } } -} \ No newline at end of file +}