示例#1
0
        static void Main(string[] args)
        {
            File.WriteAllText(logFile, null);
            string         dumpDir = @"E:\JX3DUMP";
            FileStream     fs      = new FileStream(@"E:\JX3\Main\JX3HD\PakV3\TRUNK.DIR", FileMode.Open);
            TrunkReader    tr      = new TrunkReader(fs);
            PackageManager pm      = new PackageManager(@"E:\JX3\Main\JX3HD\PakV3\");

            Log($"Total Length = {tr.TotalLength}");
            int totalLengthStrLen = tr.TotalLength.ToString().Length;
            int i = 0;
            PackageDataDecompressor decomp = new PackageDataDecompressor();
            Stopwatch sw = new Stopwatch();

            sw.Restart();
            while (true)
            {
                try
                {
                    int           packageId = 0;
                    TrunkAddress  item      = tr.ReadNextResource();
                    string        name      = item.Token.ToString("X16");
                    PackageData   data      = new PackageData(pm.GetData(item.Offset, item.Length, out packageId));
                    byte[]        content   = decomp.GetDecompressedData(data.CompressType, data.RawData, data.DecompressedLength);
                    string        extension = JX3FileTypeRecognizer.GetExtension(content);
                    DirectoryInfo dir       = new DirectoryInfo($"{dumpDir}\\{packageId}");
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                    File.WriteAllBytes($"{dir}\\{name}.{extension}", content);
                    Log($"{(++i).ToString()} / {tr.TotalLength}    Dumped: {name}.{extension} at 0x{item.Offset.ToString("X")}, source length is {item.Length}, data block length is {data.RawLength}, compress type is {data.CompressType.ToString()}, decompressed length is {data.DecompressedLength}");
                }
                catch (EndOfStreamException ex)
                {
                    break;
                }
                catch (Exception ex)
                {
                    Log($">>> Error: {ex.Message}");
                }
            }
            sw.Stop();
            Log($"Finished, elapsed time = {sw.Elapsed.ToString("dd':'hh':'mm':'ss'.'fff")}");
            Console.ReadKey();
        }
示例#2
0
        public TrunkAddress ReadNextResource()
        {
            byte[] buffer = new byte[20];
            int    read   = this.BaseStream.Read(buffer, 0, buffer.Length);

            if (read < 20)
            {
                throw new EndOfStreamException("无法读取下一个完整对象, 已经读取到末尾?");
            }
            TrunkAddress address = new TrunkAddress()
            {
                Token  = BitConverter.ToUInt64(buffer.Take(8).Reverse().ToArray(), 0),
                Offset = BitConverter.ToInt64(buffer.Skip(8).Take(8).ToArray(), 0),
                Length = BitConverter.ToInt32(buffer.Skip(16).Take(4).ToArray(), 0)
            };

            return(address);
        }