示例#1
0
 static void DumpAllCompressedFiles(PackedFileReader fileMgr, string directory)
 {
     foreach (string f in fileMgr.GetFileList())
     {
         DumpCompressedFile(fileMgr, directory, f);
     }
 }
示例#2
0
        static void DumpCompressedFile(PackedFileReader fileMgr, string directory, string filename)
        {
            byte[]     data = fileMgr.GetCompressedFileData(filename);
            FileStream s    = File.Open(directory + "/" + filename, FileMode.Create);

            s.Write(data, 0, data.Length);
            s.Close();
        }
示例#3
0
        public static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("No options specified.");
                return(1);
            }

            switch (args[0])
            {
            // Pack a directory of files into DATA.001, DATA.DIR, DATA.RUN.
            case "--packfiles": {
                var cmpArchive          = new Archive(args[1]);
                var uncmpArchive        = new Archive(args[2]);
                PackedFileWriter writer = new PackedFileWriter(cmpArchive, uncmpArchive);
                writer.Save(args[3]);
                break;
            }

            // Decompress a file
            case "--compressfile": {
                byte[]     data    = File.ReadAllBytes(args[1]);
                byte[]     cmpData = LZSS.Encode(data);
                FileStream output  = File.Open(args[2], FileMode.Create);
                output.WriteByte((byte)(data.Length & 0xff));
                output.WriteByte((byte)(data.Length >> 8));
                output.Write(cmpData, 0, cmpData.Length);
                output.Close();
                break;
            }

            // Decompress a given file
            case "--decompressfile": {
                FileStream stream    = File.OpenRead(args[1]);
                byte[]     cmpData   = new byte[stream.Length - 2];
                UInt16     uncmpSize = (UInt16)(stream.ReadByte() + (stream.ReadByte() << 8));
                stream.Read(cmpData, 0, cmpData.Length);
                byte[] data = LZSS.Decode(cmpData, cmpData.Length, uncmpSize);

                FileStream output = File.Open(args[2], FileMode.Create);
                output.Write(data, 0, data.Length);
                output.Close();
                break;
            }

            // Dump uncompressed versions of all files
            case "--dumpallfiles": {
                var archive = new Archive(args[1]);
                var fileMgr = new PackedFileReader(archive);
                DumpAllFiles(fileMgr, args[2]);
                break;
            }

            // Dump compressed versions of all files
            case "--dumpallfilescmp": {
                var archive = new Archive(args[1]);
                var fileMgr = new PackedFileReader(archive);
                DumpAllCompressedFiles(fileMgr, args[2]);
                break;
            }

            // Dump text from an RDF file
            case "--dumprdftext": {
                byte[] data    = File.ReadAllBytes(args[1]);
                int    textPos = Int32.Parse(args[2]);
                Console.Write("\"");
                while (data[textPos] != '\0')
                {
                    char c = (char)(data[textPos++]);
                    if (c == '\\' || c == '"')
                    {
                        Console.Write("\\");
                    }
                    Console.Write(c);
                }
                Console.Write("\",\n");
                break;
            }

            // Dump table of text from an RDF file
            case "--dumprdftexttable": {
                byte[] data = File.ReadAllBytes(args[1]);
                int    pos  = Int32.Parse(args[2]);
                Console.WriteLine("const char *text[] = {");
                do
                {
                    int textPos = Helper.ReadUInt16(data, pos);
                    Console.Write("\t\"");
                    while (data[textPos] != '\0')
                    {
                        char c = (char)(data[textPos++]);
                        if (c == '\\' || c == '"')
                        {
                            Console.Write("\\");
                        }
                        Console.Write(c);
                    }
                    Console.Write("\",\n");
                    pos += 2;
                }while (Helper.ReadUInt16(data, pos) != 0);
                Console.WriteLine("\t\"\"\n};");
                break;
            }

            case "--dumpscript": {
                if (args.Length >= 3)
                {
                    DumpScript(args[1], args[2]);
                }
                else
                {
                    DumpScript(args[1], null);
                }
                break;
            }

            // Dump "scripts" (x86 code) from RDF files into txt files (uses objdump to disassemble)
            case "--dumpallscripts": {
                var    directory = args[1];
                var    outputDir = args[2];
                string sfxDir    = (args.Length >= 3 ? args[2] : null);
                foreach (String s in Directory.GetFiles(directory))
                {
                    if (s.EndsWith(".RDF"))
                    {
                        DumpScript(s, sfxDir, outputDir);
                    }
                }
                break;
            }

            default:
                Console.WriteLine("Unrecognized option \"" + args[0] + "\".");
                return(1);
            }

            return(0);
        }