Пример #1
0
        public void DecompressNameBlock(uint magic, byte[] CompressedBlock, SDFTOC_Header header)
        {
            byte[] decomp = null;
            if (magic == 0xDFF25B82 || magic == 0xFD2FB528)
            {
                decomp = STLibraryCompression.ZSTD.Decompress(CompressedBlock);
            }
            else if (magic == 0x184D2204 || header.Version >= 0x17)
            {
                decomp = STLibraryCompression.Type_LZ4.Decompress(CompressedBlock, 0, CompressedBlock.Length, (int)header.DecompressedSize);
            }
            else
            {
                decomp = STLibraryCompression.ZLIB.Decompress(CompressedBlock);
            }

            //Now it's decompressed lets parse!
            using (var reader = new FileReader(decomp))
            {
                ParseNames(reader);
            }

            CompressedBlock = new byte[0];
            decomp          = new byte[0];
            decomp          = null;
            CompressedBlock = null;
        }
Пример #2
0
        //Thanks to https://github.com/GoldFarmer/rouge_sdf/blob/master/main.cpp for docs/structs
        public void Load(System.IO.Stream stream)
        {
            using (var reader = new FileReader(stream))
            {
                reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;

                //Read header
                Header = new SDFTOC_Header();
                Header.Read(reader);

                //Read first id
                startId = new SDFTOC_ID(reader);

                //Check this flag
                byte Flag1 = reader.ReadByte();
                if (Flag1 != 0)
                {
                    byte[] unk = reader.ReadBytes(0x140);
                }

                //Read first block
                block1 = reader.ReadInt32s((int)Header.Block1Count);

                //Read ID blocks
                blockIds = new SDFTOC_ID[Header.Block1Count];
                for (int i = 0; i < Header.Block1Count; i++)
                {
                    blockIds[i] = new SDFTOC_ID(reader);
                }

                //Read block 2 (DDS headers)
                block2Array = new SDFTOC_Block2[Header.Block2Count];
                for (int i = 0; i < Header.Block2Count; i++)
                {
                    block2Array[i] = new SDFTOC_Block2(reader, Header);
                }

                //Here is the compressed block. Check the magic first
                uint magic = reader.ReadUInt32();
                reader.Seek(-4, SeekOrigin.Current);

                //Read and decompress the compressed block
                //Contains file names and block info
                DecompressNameBlock(magic, reader.ReadBytes((int)Header.CompressedSize), Header);

                //Read last id
                endId = new SDFTOC_ID(reader);

                Text = FileName;

                LoadTree();
            }
        }
Пример #3
0
 public SDFTOC_Block2(FileReader reader, SDFTOC_Header header)
 {
     if (header.Version == 22)
     {
         UsedBytes = reader.ReadUInt32();
         Data      = reader.ReadBytes(0xC8);
     }
     else
     {
         UsedBytes = reader.ReadUInt32();
         Data      = reader.ReadBytes(0x94);
     }
 }
Пример #4
0
        public void DecompressNameBlock(uint magic, byte[] CompressedBlock, SDFTOC_Header header)
        {
            byte[] decomp = null;
            if (magic == 0xDFF25B82 || magic == 0xFD2FB528)
            {
                decomp = STLibraryCompression.ZSTD.Decompress(CompressedBlock);
            }
            else if (header.Version > 22)
            {
                decomp = STLibraryCompression.Type_LZ4.Decompress(CompressedBlock);
            }
            else
            {
                decomp = STLibraryCompression.ZLIB.Decompress(CompressedBlock);
            }

            //Now it's decompressed lets parse!
            using (var reader = new FileReader(decomp))
            {
                ParseNames(reader);
            }
        }
Пример #5
0
        //Thanks to https://github.com/GoldFarmer/rouge_sdf/blob/master/main.cpp for docs/structs
        public void Load(System.IO.Stream stream)
        {
            using (var reader = new FileReader(stream))
            {
                reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;

                //Read header
                Header = new SDFTOC_Header();
                Header.Read(reader);

                //Read first id
                var startId = new SDFTOC_ID(reader);

                //Check this flag
                byte Flag1 = reader.ReadByte();
                if (Flag1 != 0)
                {
                    byte[] unk = reader.ReadBytes(0x140);
                }

                if (Header.DataOffset != 0)
                {
                    reader.SeekBegin(Header.DataOffset + 0x51);

                    //Here is the compressed block. Check the magic first
                    uint magic = reader.ReadUInt32();
                    reader.Seek(-4, SeekOrigin.Current);

                    //Read and decompress the compressed block
                    //Contains file names and block info
                    DecompressNameBlock(magic, reader.ReadBytes((int)Header.CompressedSize), Header);

                    //Read last id
                    var endId = new SDFTOC_ID(reader);
                }
                else
                {
                    //Read first block
                    var block1 = reader.ReadInt32s((int)Header.Block1Count);

                    //Read ID blocks
                    var blockIds = new SDFTOC_ID[Header.Block1Count];
                    for (int i = 0; i < Header.Block1Count; i++)
                    {
                        blockIds[i] = new SDFTOC_ID(reader);
                    }

                    //Read block 2 (DDS headers)
                    block2Array = new SDFTOC_Block2[Header.Block2Count];
                    for (int i = 0; i < Header.Block2Count; i++)
                    {
                        block2Array[i] = new SDFTOC_Block2(reader, Header);
                    }

                    //Here is the compressed block. Check the magic first
                    uint magic = reader.ReadUInt32();
                    reader.Seek(-4, SeekOrigin.Current);

                    //Read and decompress the compressed block
                    //Contains file names and block info
                    DecompressNameBlock(magic, reader.ReadBytes((int)Header.CompressedSize), Header);

                    //Read last id
                    var endId = new SDFTOC_ID(reader);
                }

                Dictionary <string, int> Extensions = new Dictionary <string, int>();
                for (int i = 0; i < FileEntries.Count; i++)
                {
                    string ext = Utils.GetExtension(FileEntries[i].FileName);
                    if (!Extensions.ContainsKey(ext))
                    {
                        Extensions.Add(ext, 1);
                    }
                    else
                    {
                        Extensions[ext]++;
                    }
                }

                for (int i = 0; i < FileEntries.Count; i++)
                {
                    string ext = Utils.GetExtension(FileEntries[i].FileName);

                    if (Extensions[ext] > 10000 && ext != ".mmb")
                    {
                        FileEntries[i].CanLoadFile = false;
                    }

                    files.Add(FileEntries[i]);
                }

                List <string> FilteredExtensions = new List <string>();
                foreach (var ext in Extensions)
                {
                    if (ext.Value > 10000 && ext.Key != ".mmb")
                    {
                        FilteredExtensions.Add(ext.Key);
                    }
                }

                if (FilteredExtensions.Count > 0)
                {
                    MessageBox.Show($"File extensions have a very large amount of nodes used." +
                                    $" This will be filtered out to prevent slow booting. {ExtsToString(FilteredExtensions.ToArray())}");
                }
                //Remove unused data
                startId = null;
                FilteredExtensions.Clear();
                Extensions.Clear();
                //      block1 = new int[0];
                //     blockIds = new SDFTOC_ID[0];
                //     endId = null;
            }
        }