コード例 #1
0
        public static List <byte[]> Unchunk(byte[] input, string dat)
        {
            var ms  = new MemoryStream();
            var min = new MemoryStream(input);

            min.Position = 4;
            Lzs.Decode(min, ms);
            System.Diagnostics.Debug.WriteLine("FF:Unchunk:LZS expanded {0} bytes to {1} bytes", input.Length, ms.Length);
            byte[] scratch    = new byte[4];
            byte[] all        = new byte[ms.Length];
            int    numsection = 6; // 7, but starts from 0

            System.Diagnostics.Debug.WriteLine("FF:Unchunk:{0} sections", numsection, 0);
            List <byte[]> sections = new List <byte[]>();

            foreach (int i in Enumerable.Range(0, numsection))
            {
                ms.Position = 0 + i * 4;         // Jumps to next header offset (4-byte)
                ms.Read(scratch, 0, 4);          // Reads the header offset for section start
                ms.Read(all, 0, (int)ms.Length); // Reads the header offset for section start
                using (var stream = new FileStream(dat, FileMode.Append))
                {
                    stream.Write(all, 0, all.Length);
                }
                ms.Position = BitConverter.ToInt32(scratch, 0); // Sets position to header offset
                ms.Read(scratch, 0, 4);                         // Reads the section header for section length
                int len = BitConverter.ToInt32(scratch, 0);     // Converts section length into integer

                byte[] s = new byte[len];                       // Creates a buffer equal to length
                ms.Read(s, 0, len);                             // Writes data to the buffer
                sections.Add(s);                                // Adds the section to a collection which will be returned at the end
            }
            return(sections);
        }
コード例 #2
0
ファイル: FieldFile.cs プロジェクト: Segachief/GodoFlevel
        public static List <byte[]> Unchunk(byte[] input)
        {
            var ms  = new MemoryStream();
            var min = new MemoryStream(input);

            min.Position = 4;
            Lzs.Decode(min, ms);
            System.Diagnostics.Debug.WriteLine("FF:Unchunk:LZS expanded {0} bytes to {1} bytes", input.Length, ms.Length);
            byte[] scratch = new byte[4];
            ms.Position = 2;
            ms.Read(scratch, 0, 4);
            int numsection = BitConverter.ToInt32(scratch, 0);

            System.Diagnostics.Debug.WriteLine("FF:Unchunk:{0} sections", numsection, 0);
            List <byte[]> sections = new List <byte[]>();

            foreach (int i in Enumerable.Range(0, numsection))
            {
                if (i == 8) // Actually section9, as we started counting from 0. Lovely.
                {
                    ms.Position = 6 + i * 4;
                    ms.Read(scratch, 0, 4);
                    ms.Position = BitConverter.ToInt32(scratch, 0);
                    ms.Read(scratch, 0, 4);
                    int len = BitConverter.ToInt32(scratch, 0);

                    // Section 9
                    byte[] s = new byte[len];
                    ms.Read(s, 0, len);
                    sections.Add(s);

                    // Section '10' (terminator)
                    int    finalLen = 14;
                    byte[] x        = new byte[finalLen];
                    ms.Read(x, 0, finalLen);
                    sections.Add(x);
                }
                else
                {
                    ms.Position = 6 + i * 4;
                    ms.Read(scratch, 0, 4);
                    ms.Position = BitConverter.ToInt32(scratch, 0);
                    ms.Read(scratch, 0, 4);
                    int len = BitConverter.ToInt32(scratch, 0);

                    byte[] s = new byte[len];
                    ms.Read(s, 0, len);
                    sections.Add(s);
                }
            }
            return(sections);
        }