Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("SRD Tool by CaptainSwag101\n" +
                              "Version 0.0.5, built on 2019/01/06\n");

            if (args.Length == 0)
            {
                Console.WriteLine("ERROR: No input file specified.");
                // Display usage info
                Console.WriteLine("Usage: SrdTool.exe <Input SRD file> [replacement PNG file] [texture ID to replace] [generate mipmaps (true/false)]");
                return;
            }


            Srd srd = Srd.FromFile(args[0]);

            if (srd == null)
            {
                return;
            }


            if (args.Length == 1)
            {
                srd.ExtractImages();
            }
            else if (args.Length > 1 && args.Length < 5)
            {
                if (!int.TryParse(args[2], out int indexToReplace))
                {
                    indexToReplace = 0;
                }
                if (!bool.TryParse(args[2], out bool generateMipmaps))
                {
                    generateMipmaps = true;
                }

                srd.ReplaceImages(args[1], indexToReplace, generateMipmaps);
            }
            else
            {
                // Display usage info
                Console.WriteLine("Usage: SrdTool.exe <Input SRD file> [replacement PNG file] [texture ID to replace] [generate mipmaps (true/false)]");
            }
        }
Ejemplo n.º 2
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);
        }