Exemple #1
0
        public ScnBlock(ref BinaryReader reader)
        {
            Header = new BlockHeader(ref reader, "$SCN");
            Data   = reader.ReadBytes(Header.DataLength);

            Utils.ReadPadding(ref reader);

            ResourceBlock = new RsiBlock(ref reader);
        }
Exemple #2
0
        public TxiBlock(ref BinaryReader reader)
        {
            Header         = new BlockHeader(ref reader, "$TXI");
            Unk1           = reader.ReadInt32();
            Unk2           = reader.ReadInt32();
            Unk3           = reader.ReadInt32();
            Unk4           = reader.ReadBytes(4);
            Unk5           = reader.ReadInt32();
            OutputFilename = Utils.ReadNullTerminatedString(ref reader);

            Utils.ReadPadding(ref reader);

            ResourceBlock = new RsiBlock(ref reader);
        }
Exemple #3
0
        public TxrBlock(ref BinaryReader reader)
        {
            Header = new BlockHeader(ref reader, "$TXR");

            Unk1        = reader.ReadInt32(); // 01 00 00 00
            Swizzle     = reader.ReadInt16();
            DispWidth   = reader.ReadInt16();
            DispHeight  = reader.ReadInt16();
            Scanline    = reader.ReadInt16();
            Format      = reader.ReadByte();
            MipmapCount = reader.ReadByte();
            Palette     = reader.ReadByte();
            PaletteId   = reader.ReadByte();

            Utils.ReadPadding(ref reader);  // Might be unnecessary

            ResourceBlock = new RsiBlock(ref reader);
        }
Exemple #4
0
        public static Srd FromFile(string srdPath)
        {
            Srd result = new Srd();

            FileInfo srdInfo = new FileInfo(srdPath);

            if (!srdInfo.Exists)
            {
                Console.WriteLine("ERROR: Input file does not exist.");
                return(null);
            }

            if (srdInfo.Extension.ToLower() != ".srd")
            {
                Console.WriteLine("ERROR: Input file does not have the \".srd\" extension.");
                return(null);
            }

            result.Filepath = srdPath;


            BinaryReader reader = new BinaryReader(new FileStream(srdPath, FileMode.Open));

            result.Blocks = new List <Block>();

            // Read blocks
            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                Block block;

                string blockType = new ASCIIEncoding().GetString(reader.ReadBytes(4));
                switch (blockType)
                {
                case "$CFH":
                    block = new CfhBlock(ref reader);
                    break;

                case "$CT0":
                    block = new Ct0Block(ref reader);
                    break;

                case "$RSF":
                    block = new RsfBlock(ref reader);
                    result.ResourceFolder = (RsfBlock)block;
                    break;

                case "$RSI":
                    block = new RsiBlock(ref reader);
                    break;

                case "$TRE":
                    block = new TreBlock(ref reader);
                    break;

                case "$TXI":
                    block = new TxiBlock(ref reader);
                    break;

                case "$TXR":
                    block = new TxrBlock(ref reader);
                    break;

                case "$VTX":
                    block = new VtxBlock(ref reader);
                    break;

                default:
                    block = new UnknownBlock(ref reader, blockType);
                    break;
                }
                result.Blocks.Add(block);

                Utils.ReadPadding(ref reader);
            }

            reader.Close();
            return(result);
        }
Exemple #5
0
        public TreBlock(ref BinaryReader reader)
        {
            Header = new BlockHeader(ref reader, "$TRE");

            long startPosition = reader.BaseStream.Position;

            Unk1 = reader.ReadInt32();
            Unk2 = reader.ReadInt16();
            Unk3 = reader.ReadInt16();
            Unk4 = reader.ReadInt16();
            Unk5 = reader.ReadInt16();
            Unk6 = reader.ReadInt32();

            // Read non-endpoint tree entries
            TreeEntries = new List <TreeEntry>();
            for (int i = 0; i < Unk3; i++)
            {
                TreeEntries.Add(new TreeEntry
                {
                    StringOffset = reader.ReadInt32(),
                    Unk1         = reader.ReadInt32(),
                    Unk2         = reader.ReadInt32(),
                    Unk3         = reader.ReadInt32(),
                });
            }

            // Read endpoint tree entries
            TreeEndpoints = new List <TreeEndpoint>();
            for (int i = 0; i < Unk4; i++)
            {
                TreeEndpoints.Add(new TreeEndpoint
                {
                    StringOffset = reader.ReadInt32(),
                    Unk1         = reader.ReadInt32()
                });
            }

            // Read unknown (tree structure?) data
            UnkTree = new List <List <int> >();
            for (int i = 0; i < Unk1; i++)
            {
                List <int> branch = new List <int>();
                for (int j = 0; j < (Unk3 + 1); j++)
                {
                    branch.Add(reader.ReadInt32());
                }
                UnkTree.Add(branch);
            }

            // Read the final entry in the unknown data
            List <int> lastBranch = new List <int>();

            lastBranch.Add(reader.ReadInt32());
            UnkTree.Add(lastBranch);


            // Read tree strings
            TreeStrings = new List <string>();
            for (int s = 0; s < (Unk3 + Unk5); s++)
            {
                string str = Utils.ReadNullTerminatedString(ref reader);
                TreeStrings.Add(str);
            }

            Utils.ReadPadding(ref reader);

            ResourceBlock = new RsiBlock(ref reader);
        }