Beispiel #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "All Files (*.*)|*.*";
            saveFileDialog1.ShowDialog();

            if (saveFileDialog1.FileName != null)
            {
                byte[] bytes            = System.IO.File.ReadAllBytes(openFileDialog1.FileName);
                var    decompressedBlob = ZlibStream.UncompressBuffer(bytes);

                try
                {
                    System.IO.FileStream _FileStream = (System.IO.FileStream)saveFileDialog1.OpenFile();
                    _FileStream.Write(decompressedBlob, 0, decompressedBlob.Length);
                    _FileStream.Close();
                }
                catch
                { }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var utf8 = new UTF8Encoding();

            using (var client = new SubscriberSocket())
            {
                client.Options.ReceiveHighWatermark = 1000;
                client.Connect("tcp://cedar.canonn.tech:9500");
                client.SubscribeToAnyTopic();
                while (true)
                {
                    var bytes        = client.ReceiveFrameBytes();
                    var uncompressed = ZlibStream.UncompressBuffer(bytes);

                    var result = utf8.GetString(uncompressed);

                    Console.WriteLine(result);
                }
            }
        }
Beispiel #3
0
 static void Main(string[] args)
 {
     if (args[0] == "-d")
     {
         FileStream fs            = File.OpenRead(args[1]);
         int        BufferSz      = ReadInt32(fs);
         byte[]     RunDataBuffer = new byte[BufferSz];
         fs.Read(RunDataBuffer, 0x00, BufferSz);
         byte[] RunDataUncompressed = ZlibStream.UncompressBuffer(RunDataBuffer);
         File.WriteAllBytes(args[2], RunDataUncompressed);
     }
     if (args[0] == "-e")
     {
         byte[]     RunDataUncompressed = File.ReadAllBytes(args[1]);
         FileStream fs = File.OpenWrite(args[2]);
         byte[]     RunDataCompressed = Compress(RunDataUncompressed);
         WriteInt32(fs, RunDataCompressed.Length);
         fs.Write(RunDataCompressed, 0x00, RunDataCompressed.Length);
     }
 }
Beispiel #4
0
        public static void MapChunkBulk(MinecraftClient client, IPacket _packet)
        {
            var packet = (MapChunkBulkPacket)_packet;
            var data   = ZlibStream.UncompressBuffer(packet.ChunkData);

            var offset = 0;

            foreach (var metadata in packet.ChunkMetadata)
            {
                var chunkLength = (BlockDataLength + (NibbleDataLength * 2) + (packet.LightIncluded ? NibbleDataLength : 0)) *
                                  GetSectionCount(metadata.PrimaryBitMap) +
                                  NibbleDataLength * GetSectionCount(metadata.AddBitMap) + (Chunk.Width * Chunk.Depth);

                var chunkData = new byte[chunkLength];
                Array.Copy(data, offset, chunkData, 0, chunkLength);
                AddChunk(client, metadata.ChunkX, metadata.ChunkZ, metadata.PrimaryBitMap, metadata.AddBitMap, packet.LightIncluded, true, chunkData);

                offset += chunkLength;
            }
        }
Beispiel #5
0
        public byte[] Decompress(byte[] file, string type)
        {
            byte[] align        = new byte[4]; Array.Copy(file, 4, align, 0, 4); //used for byte alignment. But it's being fudged by the dll.
            byte[] compressed   = new byte[4]; Array.Copy(file, 8, compressed, 0, 4);
            byte[] uncompressed = new byte[4]; Array.Copy(file, 12, uncompressed, 0, 4);
            byte[] input        = new byte[BitConverter.ToInt32(compressed, 0)]; Array.Copy(file, 16, input, 0, file.Length - 16);
            byte[] output       = new byte[BitConverter.ToInt32(uncompressed, 0)];
            int    padding      = BitConverter.ToInt32(uncompressed, 0) - BitConverter.ToInt32(compressed, 0);

            if (type == "BPE ")
            {
                yukes_bpe(input, BitConverter.ToInt32(compressed, 0), output, BitConverter.ToInt32(uncompressed, 0), padding);
            }
            if (type == "ZLIB")
            {
                output = ZlibStream.UncompressBuffer(input);
            }

            return(output);
        }
Beispiel #6
0
    // Use this for initialization
    void Start()
    {
        FileStream input            = new FileStream("E:/gamecheat/resource/ttlz/dump.txt", FileMode.Open, FileAccess.ReadWrite);
        FileStream output           = new FileStream("E:/gamecheat/resource/ttlz/dump.dll", FileMode.OpenOrCreate, FileAccess.ReadWrite);
        string     FileName_HashKey = "dump";
        long       FileSize         = input.Length;

        byte[] data = new byte[FileSize];
        input.Read(data, 0, (int)FileSize);
        System.Random random = new System.Random(FileName_HashKey.GetHashCode());
        for (int i = 0; i < data.Length; i++)
        {
            data[i] ^= (byte)random.Next(256);
        }
        byte[] temp = ZlibStream.UncompressBuffer(data);
        for (int i = 0; i < temp.Length; i++)
        {
            output.WriteByte(temp[i]);
        }
    }
Beispiel #7
0
        private bool ReadCompressed(ClientWrapper client, NetworkStream clientStream, int dlength)
        {
            var buffie = new byte[dlength];
            int receivedData;

            receivedData = clientStream.Read(buffie, 0, buffie.Length);
            buffie       = ZlibStream.UncompressBuffer(buffie);

            if (receivedData > 0)
            {
                var buf = new DataBuffer(client);

                if (client.Decrypter != null)
                {
                    var date = new byte[4096];
                    client.Decrypter.TransformBlock(buffie, 0, buffie.Length, date, 0);
                    buf.BufferedData = date;
                }
                else
                {
                    buf.BufferedData = buffie;
                }

                buf.BufferedData = buffie;

                buf.Size = dlength;
                var packid = buf.ReadVarInt();

                if (!new PackageFactory(client, buf).Handle(packid))
                {
                    ConsoleFunctions.WriteWarningLine("Unknown packet received! \"0x" + packid.ToString("X2") + "\"");
                }

                buf.Dispose();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #8
0
        public static IEnumerable <ZlibFile> Open(string path)
        {
            var files = new List <ZlibFile>();

            using (var reader = new BinaryReader(File.OpenRead(path)))
            {
                byte[] header = reader.ReadBytes(0x10);
                int    count  = reader.ReadInt32();

                byte[] separator = reader.ReadBytes(1);
                for (int i = 0; i != count; i++)
                {
                    int id     = reader.ReadInt32();
                    int offset = reader.ReadInt32();

                    long previous = reader.BaseStream.Position;
                    reader.BaseStream.Seek(offset, SeekOrigin.Begin);

                    int    creation       = reader.ReadInt32();
                    int    size           = reader.ReadInt32();
                    int    compressedSize = reader.ReadInt32();
                    bool   compressed     = Convert.ToBoolean(reader.ReadBytes(1)[0]);
                    byte[] data           = reader.ReadBytes(compressedSize);

                    if (compressed)
                    {
                        data = ZlibStream.UncompressBuffer(data);
                    }

                    files.Add(new ZlibFile
                    {
                        Id      = id,
                        Content = data
                    });

                    reader.BaseStream.Seek(previous, SeekOrigin.Begin);
                }
            }

            return(files);
        }
Beispiel #9
0
 private static double[] ReadBase64EncodedDoubleArray(string base64EncodedData, int wordLengthInBytes, bool zlibCompressed)
 {
     byte[] bytes = Convert.FromBase64String(base64EncodedData);
     if(zlibCompressed)
     {
         bytes = ZlibStream.UncompressBuffer(bytes);
     }
     double[] doubles = new double[bytes.Length / wordLengthInBytes];
     if(wordLengthInBytes == 4)
     {
         for(int i = doubles.GetLowerBound(0); i <= doubles.GetUpperBound(0); i++)
         {
             doubles[i] = BitConverter.ToSingle(bytes, i * wordLengthInBytes);
         }
     }
     else if(wordLengthInBytes == 8)
     {
         Buffer.BlockCopy(bytes, 0, doubles, 0, bytes.Length);
     }
     return doubles;
 }
Beispiel #10
0
        public static ModelEntry FillModelEntry(string filename, List <string> subnames, TreeView tree, BinaryReader br, int c, int ID, Type filetype = null)
        {
            ModelEntry  modentry = new ModelEntry();
            List <byte> BTemp    = new List <byte>();

            FillEntry(filename, subnames, tree, br, c, ID, modentry, filetype);

            //Decompression Time.
            modentry.UncompressedData = ZlibStream.UncompressBuffer(modentry.CompressedData);

            //Type Specific Work Here.
            using (MemoryStream LmtStream = new MemoryStream(modentry.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(LmtStream))
                {
                    BuildModelEntry(bnr, modentry);
                }
            }

            return(modentry);
        }
Beispiel #11
0
 public static byte[] Uncompress(this byte[] compressed, int sizeUncompressed, bool checkSizeDifference)
 {
     if (compressed.Length == sizeUncompressed)
     {
         return(compressed);
     }
     byte[] uncompressed;
     try
     {
         uncompressed = ZlibStream.UncompressBuffer(compressed);
     }
     catch (Exception x)
     {
         throw new IOException(Resources.UtilDB_Uncompress_Failure_uncompressing_data, x);
     }
     if (checkSizeDifference && (uncompressed.Length != sizeUncompressed))
     {
         throw new IOException(Resources.UtilDB_Uncompress_Failure_uncompressing_data);
     }
     return(uncompressed);
 }
        public static EffectListEntry FillEFLEntry(string filename, List <string> subnames, TreeView tree, BinaryReader br, int c, int ID, Type filetype = null)
        {
            EffectListEntry effectList = new EffectListEntry();
            List <byte>     BTemp      = new List <byte>();

            FillEntry(filename, subnames, tree, br, c, ID, effectList, filetype);

            //Decompression Time.
            effectList.UncompressedData = ZlibStream.UncompressBuffer(effectList.CompressedData);

            //Type Specific Work Here.
            using (MemoryStream LmtStream = new MemoryStream(effectList.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(LmtStream))
                {
                    BuildEffectListEntry(bnr, effectList);
                }
            }

            return(effectList);
        }
Beispiel #13
0
        private static void DecompressZLIB(string fileName, string targetFileName)
        {
            byte[] header = new byte[HeaderLength];
            HeaderFWS.CopyTo(header, 0);

            byte[] uncompressed;
            using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open)))
            {
                reader.BaseStream.Seek(HeaderTypeLength, SeekOrigin.Begin);
                reader.Read(header, HeaderTypeLength, HeaderVersionLength + HeaderSizeLength);

                reader.BaseStream.Seek(HeaderLength, SeekOrigin.Begin);
                byte[] data = new byte[reader.BaseStream.Length - HeaderLength];
                reader.Read(data, 0, data.Length);
                uncompressed = ZlibStream.UncompressBuffer(data);
            }

            byte[] combined = CombineBytes(header, uncompressed);

            File.WriteAllBytes(targetFileName, combined);
        }
        public static MaterialEntry FillMatEntry(string filename, List <string> subnames, TreeView tree, BinaryReader br, int c, int ID, Type filetype = null)
        {
            var         MATEntry = new MaterialEntry();
            List <byte> BTemp    = new List <byte>();

            FillEntry(filename, subnames, tree, br, c, ID, MATEntry);

            //Decompression Time.
            MATEntry.UncompressedData = ZlibStream.UncompressBuffer(MATEntry.CompressedData);

            //Material specific work here.
            using (MemoryStream MatStream = new MemoryStream(MATEntry.UncompressedData))
            {
                using (BinaryReader MBR = new BinaryReader(MatStream))
                {
                    BuildMatEntry(MBR, MATEntry);
                }
            }

            return(MATEntry);
        }
Beispiel #15
0
        public float[] ExtractFloatArray()
        {
            if (string.IsNullOrEmpty(Base64Data))
            {
                return(Array.Empty <float>());
            }

            byte[] bytes = Convert.FromBase64String(Base64Data);
            bytes = Compression switch
            {
                Compression.Uncompressed => bytes,
                Compression.Zlib => ZlibStream.UncompressBuffer(bytes),
                _ => throw new ArgumentOutOfRangeException("Compression", "Unknown compression")
            };

            return(Bitness switch
            {
                Bitness.IEEE754FloatLittleEndian => GetFloats(bytes),
                Bitness.IEEE754DoubleLittleEndian => GetFloatsFromDoubles(bytes),
                _ => throw new ArgumentOutOfRangeException("Bitness", "Unknown bitness")
            });
        public ClientExample(string endpoint)
        {
            var utf8 = new UTF8Encoding();

            using (var client = new SubscriberSocket())
            {
                client.Options.ReceiveHighWatermark = 1000;
                client.Connect(endpoint);
                client.SubscribeToAnyTopic();
                while (true)
                {
                    var bytes        = client.ReceiveFrameBytes();
                    var uncompressed = ZlibStream.UncompressBuffer(bytes);

                    var result = utf8.GetString(uncompressed).Remove(2, 1);
                    var obj    = JsonConvert.DeserializeObject <BaseDataModel <JournalMessage> >(result);
                    Console.WriteLine(obj.Message.StarSystem);
                    // var obj = JsonConvert.DeserializeObject<BasicJsonModel>(result);
                    // if (obj.schemaRef == "https://eddn.edcd.io/schemas/journal/1")
                    // {
                    //     var msg = JsonConvert.DeserializeObject<JournalMessage>(obj.message);
                    // }
                    // else if (obj.schemaRef == "https://eddn.edcd.io/schemas/outfitting/2")
                    // {
                    //     var msg = JsonConvert.DeserializeObject<OutfittingMessage>(obj.message);
                    // }
                    // else if (obj.schemaRef == "https://eddn.edcd.io/schemas/shipyard/2")
                    // {
                    //     var msg = JsonConvert.DeserializeObject<ShipyardMessage>(obj.message);
                    // }
                    // else if (obj.schemaRef == "https://eddn.edcd.io/schemas/commodity/3")
                    // {
                    //     var message = JsonConvert.DeserializeObject<CommodityMessage>(obj.message);
                    //     Console.WriteLine(message.systemName);
                    // }

                    // Console.WriteLine(result);
                }
            }
        }
Beispiel #17
0
        // 通信結果解凍.サーバーからのレスポンスはzip圧縮されて返ってくる想定.
        private System.Object[] UnpackObject(byte[] data)
        {
            if (data == null || data.Length <= 0)
            {
                this.IsServerError = true;
                return(null);
            }
            for (int i = 0; i < data.Length; ++i)
            {
                data[i] = (byte)(data[i] ^ 0x9A);
            }
            this.ResultObjectBytes = ZlibStream.UncompressBuffer(data);                         // 解凍にはIonic.Zlib.dllを使用.

            var packer = new BoxingPacker();
            var result = packer.Unpack(this.ResultObjectBytes) as System.Object[];              // IMsgPackのデシリアライズ

            if (result == null)
            {
                this.IsServerError = true;
            }
            return(result);
        }
Beispiel #18
0
        public static byte[] Decompress(Stream stream, bool skipType = false)
        {
            using (var reader = new BinaryReader(stream))
            {
                if (!skipType)
                {
                    var type = reader.ReadInt32();
                }

                var realSize       = reader.ReadInt32();
                var compressedSize = reader.ReadInt32();

                var decompressed = ZlibStream.UncompressBuffer(reader.ReadBytes(compressedSize));

                if (decompressed.Length != realSize)
                {
                    throw new Exception("Decompressed size does not match the header's value.");
                }

                return(decompressed);
            }
        }
Beispiel #19
0
        // Decryption Routine: Base64 -> AES -> Zlib
        private static byte[] Decrypt(PackVersion version, uint size, uint sizeCompressed, Encryption flag, byte[] src)
        {
            if (flag.HasFlag(Encryption.Aes))
            {
                // Get the AES Key/IV for transformation
                CipherKeys.GetKeyAndIV(version, sizeCompressed, out byte[] key, out byte[] iv);

                // Decode the base64 encoded string
                src = Convert.FromBase64String(Encoding.UTF8.GetString(src));

                // Decrypt the AES encrypted block
                AESCipher pCipher = new AESCipher(key, iv);
                pCipher.TransformBlock(src, 0, size, src, 0);
            }
            else if (flag.HasFlag(Encryption.Xor))
            {
                // Decrypt the XOR encrypted block
                src = EncryptXor(version, src, size, sizeCompressed);
            }

            return(flag.HasFlag(Encryption.Zlib) ? ZlibStream.UncompressBuffer(src) : src);
        }
Beispiel #20
0
        public static void LoadRundata(int projectVersion, string outputPath)
        {
            string AppDir      = AppDomain.CurrentDomain.BaseDirectory;
            string fname       = "rundata" + projectVersion.ToString();
            string RundataPath = Path.Combine(AppDir, fname);

            if (!File.Exists(RundataPath))
            {
                throw new Exception("Unable to find matching rundata file, expected at " + RundataPath);
            }

            byte[] file    = File.ReadAllBytes(RundataPath);
            byte[] rawsize = new byte[4];
            Array.Copy(file, rawsize, rawsize.Length);
            int size = BitConverter.ToInt32(file);

            byte[] zlib = new byte[size];
            Array.Copy(file, rawsize.Length, zlib, 0, size);

            byte[] unpacked = ZlibStream.UncompressBuffer(zlib);
            File.WriteAllBytes(outputPath, unpacked);
        }
Beispiel #21
0
        public byte[] DecompressFileEntry(int fileIndex)
        {
            // Open the archive for reading.
            if (OpenArchive(false) == false)
            {
                // Failed to open the archive.
                return(null);
            }

            // Seek to the start of the file's compressed data
            this.reader.BaseStream.Position = this.fileEntries[fileIndex].DataOffset;

            // Read the compressed data.
            byte[] compressedData = this.reader.ReadBytes(this.fileEntries[fileIndex].CompressedSize);

            // Decompress data.
            byte[] decompressedData = ZlibStream.UncompressBuffer(compressedData);

            // Close the archive and return.
            CloseArchive();
            return(decompressedData);
        }
Beispiel #22
0
        private static void UE4ChunkUnzip(string source, string destination)
        {
            using (BinaryReader inReader = new BinaryReader(File.Open(source, FileMode.Open)))
            {
                using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(destination, FileMode.Create)))
                {
                    FCompressedChunkInfo fcompressedChunkInfo1 = new FCompressedChunkInfo();
                    fcompressedChunkInfo1.Serialize(inReader);
                    FCompressedChunkInfo fcompressedChunkInfo2 = new FCompressedChunkInfo();
                    fcompressedChunkInfo2.Serialize(inReader);

                    long num1 = fcompressedChunkInfo1.CompressedSize;
                    long num2 = fcompressedChunkInfo1.UncompressedSize;
                    if (num2 == 2653586369L)
                    {
                        num2 = 131072L;
                    }
                    long length = (fcompressedChunkInfo2.UncompressedSize + num2 - 1L) / num2;

                    FCompressedChunkInfo[] fcompressedChunkInfoArray = new FCompressedChunkInfo[length];
                    long val2 = 0L;

                    for (int index = 0; index < length; ++index)
                    {
                        fcompressedChunkInfoArray[index] = new FCompressedChunkInfo();
                        fcompressedChunkInfoArray[index].Serialize(inReader);
                        val2 = Math.Max(fcompressedChunkInfoArray[index].CompressedSize, val2);
                    }

                    for (long index = 0L; index < length; ++index)
                    {
                        FCompressedChunkInfo fcompressedChunkInfo3 = fcompressedChunkInfoArray[index];
                        byte[] buffer = ZlibStream.UncompressBuffer(inReader.ReadBytes((int)fcompressedChunkInfo3.CompressedSize));
                        binaryWriter.Write(buffer);
                    }
                }
            }
        }
        public async Task DownloadPart(string uri, string filename)
        {
            var progressReporter = _patcherContext.CreateProgressIndicator();

            var fileDirectory = Path.GetDirectoryName(filename);

            if (!Directory.Exists(fileDirectory))
            {
                Directory.CreateDirectory(fileDirectory);
            }

            Task.Run(async() =>
            {
                await AsyncDownloader.DownloadFileWithCallbackAsync(uri, filename, (d, s) =>
                {
                    progressReporter.SetLeftText(Path.GetFileName(filename));
                    progressReporter.SetRightText(s);
                    progressReporter.SetProgressBar(d);
                }, true);
            }).Wait();

            progressReporter.SetIsIndeterminate(true);
            progressReporter.SetRightText(Properties.Resources.Decompressing);

            using (var fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
                using (var ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    var buffer = ms.ToArray();
                    buffer = ZlibStream.UncompressBuffer(buffer);
                    fs.SetLength(buffer.Length);
                    fs.Position = 0;
                    fs.Write(buffer, 0, buffer.Length);
                    fs.Flush();
                }

            _patcherContext.DestroyProgressIndicator(progressReporter);
        }
Beispiel #24
0
        public static GemEntry FillGEMEntry(string filename, List <string> subnames, TreeView tree, BinaryReader br, int c, int ID, Type filetype = null)
        {
            GemEntry GEMentry = new GemEntry();

            FillEntry(filename, subnames, tree, br, c, ID, GEMentry, filetype);

            GEMentry._FileLength = GEMentry.DSize;

            ASCIIEncoding ascii = new ASCIIEncoding();

            GEMentry.UncompressedData = ZlibStream.UncompressBuffer(GEMentry.CompressedData);

            //Type Specific Work Here.
            using (MemoryStream LmtStream = new MemoryStream(GEMentry.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(LmtStream))
                {
                    BuildGemEntry(bnr, GEMentry, ascii);
                }
            }

            return(GEMentry);
        }
Beispiel #25
0
        public byte[] GetUncompressedData()
        {
            if (_data != null)
            {
                return(_data);
            }

            Span <byte> newData = stackalloc byte[(int)Header.CompressedSizeAligned];

            _owner.GetCompressedBytes(Header.FileOffset, Header.CompressedSizeAligned).CopyTo(newData);

            if (Header.Flags.HasFlag(FileFlag.Mixed))
            {
                DecodeFull(newData, Header.CompressedSize);
            }
            else if (Header.Flags.HasFlag(FileFlag.DES))
            {
                DecodeHeader(newData);
            }

            _data = ZlibStream.UncompressBuffer(newData.ToArray());
            return(_data);
        }
Beispiel #26
0
        /// <summary>
        /// Extracts all files to the specified directory while maintaining file hierarchy
        /// </summary>
        /// <param name="outputFolder">Output folder to saves files to</param>
        /// <returns>True if the files were successfully extracted, false otherwise</returns>
        public bool ExtractAllFiles(string outputFolder)
        {
            // Open the archive for reading.
            if (OpenArchive(false) == false)
            {
                // Failed to open the archive.
                return(false);
            }

            // Loop through all of the files and extract each one.
            for (int i = 0; i < this.fileEntries.Count; i++)
            {
                // Format the folder name and check if it already exists.
                string fileName       = this.FileEntries[i].FileName;
                string fileFolderPath = outputFolder + "\\" + fileName.Substring(0, fileName.LastIndexOf("\\"));
                if (Directory.Exists(fileFolderPath) == false)
                {
                    // Create the directory now.
                    Directory.CreateDirectory(fileFolderPath);
                }

                // Seek to the start of the file's compressed data.
                this.reader.BaseStream.Position = this.fileEntries[i].DataOffset;

                // Read the compressed data.
                byte[] compressedData = this.reader.ReadBytes(this.fileEntries[i].CompressedSize);

                // Decompress and write to file.
                byte[] decompressedData = ZlibStream.UncompressBuffer(compressedData);
                File.WriteAllBytes(string.Format("{0}\\{1}.{2}", fileFolderPath, fileName.Substring(fileName.LastIndexOf("\\") + 1),
                                                 this.fileEntries[i].FileType.ToString()), decompressedData);
            }

            // Close the archive and return.
            CloseArchive();
            return(true);
        }
Beispiel #27
0
        public static byte[] DecompressData(FileStream stream)
        {
            List <byte> decompressed = new List <byte>();
            var         header       = ReadHeader(stream);

            for (int i = 0; i < header.BlockOffset.Count; i++)
            {
                stream.Seek(header.BlockOffset[i], SeekOrigin.Begin);
                uint count = 0;
                if (i == header.BlockOffset.Count - 1) //处理最后一个
                {
                    count = (uint)stream.Length - header.BlockOffset[i];
                }
                else
                {
                    count = header.BlockOffset[i + 1] - header.BlockOffset[i];
                }
                byte[] temp = new byte[count];
                stream.Read(temp, 0, temp.Length);
                byte[] dtemp = ZlibStream.UncompressBuffer(temp);
                decompressed.AddRange(dtemp);
            }
            return(decompressed.ToArray());
        }
        private static byte[] DecompressRpmsg(byte[] compressedBytes)
        {
            LogUtils.Log("");

            using (MemoryStream fsOut = new MemoryStream())
            {
                using (MemoryStream fsIn = new MemoryStream(compressedBytes))
                {
                    byte[] header         = new byte[12];
                    byte[] compressedData = new byte[1];

                    fsIn.Seek(RPMSG_PREFIX.Length, SeekOrigin.Begin);
                    while (true)
                    {
                        if (fsIn.Read(header, 0, 12) != 12)
                        {
                            break;
                        }

                        //						int marker = BitConverter.ToInt32(header, 0);
                        //						int sizeUncompressed = BitConverter.ToInt32(header, 4);
                        int sizeCompressed = BitConverter.ToInt32(header, 8);

                        if (sizeCompressed > compressedData.Length)
                        {
                            compressedData = new byte[sizeCompressed];
                        }

                        fsIn.Read(compressedData, 0, sizeCompressed);
                        fsOut.Write(compressedData, 0, sizeCompressed);
                    }
                }

                return(ZlibStream.UncompressBuffer(fsOut.ToArray()));
            }
        }
Beispiel #29
0
        public static byte[] Convert(XmlData data, string json)
        {
            var obj = JsonConvert.DeserializeObject <json_dat>(json);

            byte[] dat = ZlibStream.UncompressBuffer(obj.data);

            var tileDict = new Dictionary <short, TerrainTile>();

            for (int i = 0; i < obj.dict.Length; i++)
            {
                loc o = obj.dict[i];
                tileDict[(short)i] = new TerrainTile
                {
                    TileId  = o.ground == null ? (ushort)0xff : data.IdToTileType[o.ground],
                    TileObj = o.objs == null ? null : o.objs[0].id,
                    Name    = o.objs == null ? "" : o.objs[0].name ?? "",
                    Terrain = TerrainType.None,
                    Region  =
                        o.regions == null
                            ? TileRegion.None
                            : (TileRegion)Enum.Parse(typeof(TileRegion), o.regions[0].id.Replace(' ', '_'))
                };
            }

            var tiles = new TerrainTile[obj.width, obj.height];

            using (var rdr = new NReader(new MemoryStream(dat)))
                for (int y = 0; y < obj.height; y++)
                {
                    for (int x = 0; x < obj.width; x++)
                    {
                        tiles[x, y] = tileDict[rdr.ReadInt16()];
                    }
                }
            return(WorldMapExporter.Export(tiles));
        }
Beispiel #30
0
        private static void Extract()
        {
            var stream = File.OpenRead("playlists.aggr");
            var reader = new BinaryReader(stream);

            var streams = new List <byte[]>();

            while (reader.ReadUInt16() == 1)
            {
                var offset = reader.ReadUInt16();
                var length = reader.ReadUInt16();

                var oldPos = stream.Position;
                stream.Position = offset;

                var bytes = reader.ReadBytes(length);
                streams.Add(ZlibStream.UncompressBuffer(bytes));

                stream.Position = oldPos;
            }

            File.WriteAllBytes("playlists.info", streams[0]);
            File.WriteAllBytes("stuff.info", streams[1]);
        }