示例#1
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();
            }
        }
示例#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
                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;
            }
        }