Example #1
0
        //loads the configuration file
        public bool Load(string configurationFile)
        {
            XmlDocument docConfig = new XmlDocument();
            XmlNode     xmlNode;

            try
            {
                docConfig.Load(configurationFile);

                //read server path
                xmlNode    = docConfig.GetElementsByTagName("server")[0];
                ServerPath = xmlNode.Attributes["path"].Value;
                if (ServerPath != "" && !ServerPath.EndsWith("/"))
                {
                    ServerPath += "/";
                }

                //read game path
                xmlNode  = docConfig.GetElementsByTagName("game")[0];
                GamePath = xmlNode.Attributes["path"].Value;
                if (GamePath != "" && !GamePath.EndsWith("/"))
                {
                    GamePath += "/";
                }
                GameConfigurationFile = xmlNode.Attributes["configFile"].Value;

                //read relative server path of the Updater
                xmlNode = docConfig.GetElementsByTagName("updater")[0];
                RelUpdaterPathOnServer = xmlNode.Attributes["serverpath"].Value;
                if (RelUpdaterPathOnServer != "" && !RelUpdaterPathOnServer.EndsWith("/"))
                {
                    RelUpdaterPathOnServer += "/";
                }

                //set absolute server path of the Updater
                AbsUpdaterPathOnServer = ServerPath + RelUpdaterPathOnServer;

                //read name of the administrated versions configuration file
                xmlNode = docConfig.GetElementsByTagName("versionsFile")[0];
                VersionsConfigurationFile = xmlNode.Attributes["name"].Value;

                //read name of a update configuration file
                xmlNode = docConfig.GetElementsByTagName("updateConfig")[0];
                UpdateConfigurationFile = xmlNode.Attributes["name"].Value;

                //read name of a full version configuration file
                xmlNode = docConfig.GetElementsByTagName("fullVersionConfig")[0];
                FullVersionConfigurationFile = xmlNode.Attributes["name"].Value;

                //read name of the temporary download folder
                xmlNode    = docConfig.GetElementsByTagName("temp")[0];
                TempFolder = xmlNode.Attributes["path"].Value;

                //read name of the Udater executeable
                xmlNode    = docConfig.GetElementsByTagName("updaterExe")[0];
                UpdaterExe = xmlNode.Attributes["name"].Value;

                //read name of the Installer executeable
                xmlNode      = docConfig.GetElementsByTagName("installerExe")[0];
                InstallerExe = xmlNode.Attributes["name"].Value;

                //read version of the Updater
                xmlNode       = docConfig.GetElementsByTagName("version")[0];
                VersionNumber = xmlNode.Attributes["name"].Value;

                //check version syntax
                if (!Version.CheckVersionSyntax(VersionNumber))
                {
                    return(false);
                }

                //read number of last background image and image-update flag
                xmlNode = docConfig.GetElementsByTagName("pictures")[0];
                LastBackgroundImgNumber = int.Parse(xmlNode.Attributes["lastNumber"].Value);
                UpdatePictures          = bool.Parse(xmlNode.Attributes["update"].Value);

                //read all background images
                foreach (XmlNode pictureNode in xmlNode.ChildNodes)
                {
                    BackgroundImgList.Add(int.Parse(pictureNode.Attributes["number"].Value),
                                          pictureNode.Attributes["path"].Value);
                }

                //set next background image number
                NextBackgroundImgNumber = GetNextBackgroundImgNumber(LastBackgroundImgNumber);
            }
            catch (Exception e)
            {
                ErrorLog.Add(this, e.Message);
                return(false);
            }

            return(true);
        }
Example #2
0
        static void Main(string[] args)
        {
            var options = new Options();

            CommandLine.Parser parser = new CommandLine.Parser(s =>
            {
                s.MutuallyExclusive = true;
                s.CaseSensitive     = true;
                s.HelpWriter        = Console.Out;
            });

            if (parser.ParseArguments(args, options))
            {
                //Package p = new Package(options.TargetFile);
                //endProgram(0);
                // Values are available here
                if (options.Verbose)
                {
                    Verbose = true;
                    writeVerboseLine("Verbose logging is enabled");
                }
                if (options.Compress && !Environment.Is64BitProcess)
                {
                    Console.WriteLine("Not 64-bit process - Disabling compression due to bugs in zlib.");
                    options.Compress = false;
                }

                if (options.GameDir != null)
                {
                    if (Directory.Exists(options.GameDir))
                    {
                        GamePath = options.GameDir;
                        if (!GamePath.EndsWith("\\"))
                        {
                            GamePath += "\\";
                        }
                        Console.WriteLine("Game path set to " + GamePath);
                    }
                    else
                    {
                        Console.Error.WriteLine("Specified game dir doesn't exist: " + options.GameDir);
                        endProgram(CODE_INPUT_FOLDER_NOT_FOUND);
                    }
                }

                if (options.InputFile == null && options.InputFolder == null)
                {
                    Console.Error.WriteLine("--inputfile or --inputfolder argument is required for all operations.");
                    Console.Error.WriteLine(options.GetUsage());
                    endProgram(CODE_NO_INPUT);
                }

                if (options.InputFile != null && !File.Exists(options.InputFile))
                {
                    Console.Error.WriteLine("Input file does not exist: " + options.InputFile);
                    endProgram(CODE_INPUT_FILE_NOT_FOUND);
                }
                if (options.InputFolder != null && !options.InputFolder.EndsWith(@"\"))
                {
                    options.InputFolder = options.InputFolder + @"\";
                }

                if (options.InputFolder != null && !Directory.Exists(options.InputFolder))
                {
                    Console.Error.WriteLine("Input folder does not exist: " + options.InputFolder);
                    endProgram(CODE_INPUT_FOLDER_NOT_FOUND);
                }

                if (options.OutputFolder != null)
                {
                    if (!options.OutputFolder.EndsWith("\\"))
                    {
                        options.OutputFolder += "\\";
                    }
                    Console.WriteLine("Redirecting output to " + options.OutputFolder);
                }

                //Operation Switch
                if (options.VerifyPCC)
                {
                    if (options.InputFile != null)
                    {
                        Console.WriteLine("Checking PCC can load " + options.TargetFile);
                        int result = VerifyPCC(options.InputFile);
                    }
                    else
                    {
                        Console.Error.WriteLine("Can only verify single pcc integrity, --inputfile is the only allowed input for this operation.");
                        endProgram(CODE_INPUT_FILE_NOT_FOUND);
                    }
                }
                else if (options.PathFindingDump)
                {
                    if (options.InputFile != null)
                    {
                        Console.WriteLine("Dumping Pathfinding on file " + options.InputFile);
                        bool[] dumpargs = new bool[] { false, false, false, false, false, false, false, false, true, false }; //meshmap only
                        dumpPCCFile(options.InputFile, dumpargs, options.OutputFolder);
                    }
                    endProgram(0);
                }
                else if (options.GUIScan)
                {
                    if (options.InputFile != null)
                    {
                        Console.WriteLine("Scanning for whitelisted GFxMovieInfo exports on " + options.InputFile);
                        endProgram(doesPCCContainGUIs(options.InputFile, false) ? 1 : 0);
                    }
                    else
                    {
                        Console.Error.WriteLine("Can only scan 1 pcc at a time, --inputfile is the only allowed input for this operation.");
                        endProgram(2);
                    }
                }
                else if (options.DMSQL)
                {
                    if (options.InputFile != null)
                    {
                        Console.WriteLine("Dumping SQL from " + options.InputFile);
                        dumpDynamicMixInsFromPCC(options.InputFile);
                        Console.WriteLine("done");
                        endProgram(0);
                    }
                    else
                    {
                        Console.Error.WriteLine("Can only scan 1 pcc at a time, --inputfile is the only allowed input for this operation.");
                        endProgram(2);
                    }
                }
                else if (options.DWSQL)
                {
                    if (options.InputFolder != null)
                    {
                        Console.WriteLine("Dumping Weapon SQL from " + options.InputFolder);
                        dumpModMakerWeaponDynamicSQL(options.InputFolder);
                        Console.WriteLine("done");
                        endProgram(0);
                    }
                    else
                    {
                        Console.Error.WriteLine("Can only scan 1 pcc at a time, --inputfile is the only allowed input for this operation.");
                        endProgram(2);
                    }
                }
                else if (options.Inject)
                {
                    if (options.TargetFile == null)
                    {
                        Console.Error.WriteLine("--targetfile is required for this operation.");
                        endProgram(CODE_INPUT_FILE_NOT_FOUND);
                    }

                    if (!File.Exists(options.TargetFile))
                    {
                        Console.Error.WriteLine("Target file does not exist: " + options.TargetFile);
                        endProgram(CODE_INPUT_FILE_NOT_FOUND);
                    }

                    if (options.Compress)
                    {
                        Console.WriteLine("Compression option is enabled.");
                    }

                    if (options.InputFile != null)
                    {
                        Console.WriteLine("Injecting SWF into " + options.TargetFile);
                        endProgram(replaceSingleSWF(options.InputFile, options.TargetFile, options.TargetExport));
                    }
                    else if (options.InputFolder != null)
                    {
                        Console.WriteLine("Injecting SWFs into " + options.TargetFile);
                        endProgram(replaceSWFs_MEM(options.InputFolder, options.TargetFile, options.Compress));
                    }
                }
                else if (options.GuiExtract)
                {
                    if (options.InputFile != null)
                    {
                        writeVerboseLine("Extracting GFX files from " + options.InputFile);
                        extractAllGFxMovies(options.InputFile, options.OutputFolder);
                    }
                    else if (options.InputFolder != null)
                    {
                        writeVerboseLine("Extracting GFX files from " + options.InputFolder);
                        extractAllGFxMoviesFromFolder(options.InputFolder, options.OutputFolder);
                    }
                }
                else if (options.ExecDump)
                {
                    if (options.InputFile != null)
                    {
                        writeVerboseLine("Dumping all Exec functions from " + options.InputFile);
                        dumpAllExecFromFile(options.InputFile, options.OutputFolder);
                    }
                    if (options.InputFolder != null)
                    {
                        writeVerboseLine("Dumping all Exec functions from " + options.InputFolder);
                        dumpAllExecFromFolder(options.InputFolder, options.OutputFolder);
                    }
                }
                else if (options.Extract)
                {
                    if (options.Imports || options.Exports || options.Data || options.Scripts || options.Coalesced || options.Names || options.SWFs)
                    {
                        if (options.Data)
                        {
                            options.Exports = true;
                        }
                        bool[] dumpargs = new bool[] { options.Imports, options.Exports, options.Data, options.Scripts, options.Coalesced, options.Names, !options.LineSeparator, options.Properties, false, options.SWFs };


                        if ((options.InputFile != null || options.InputFolder != null) && options.TlkCachePath != null && Directory.Exists(options.TlkCachePath))
                        {
                            //Load TLKs
                            var ext = new List <string> {
                                "tlk"
                            };
                            var tlks = Directory.EnumerateFiles(options.TlkCachePath, "*INT.tlk", SearchOption.AllDirectories);
                            Console.WriteLine("Loading " + tlks.Count() + " TLK(s) from " + options.TlkCachePath);
                            foreach (string tlk in tlks)
                            {
                                TalkFiles.addTLK(tlk);
                            }
                        }

                        if (options.InputFile != null)
                        {
                            Console.Out.WriteLine("Dumping pcc data of " + options.InputFile +
                                                  " [Imports: " + options.Imports + ", Exports: " + options.Exports + ", Data: " + options.Data + ", Scripts: " + options.Scripts +
                                                  ", Coalesced: " + options.Coalesced + ", Names: " + options.Names + ", Properties: " + options.Properties + ", SWF: " + options.SWFs + "]");
                            dumpPCCFile(options.InputFile, dumpargs, options.OutputFolder);
                        }
                        if (options.InputFolder != null)
                        {
                            Console.Out.WriteLine("Dumping pcc data from " + options.InputFolder +
                                                  " [Imports: " + options.Imports + ", Exports: " + options.Exports + ", Data: " + options.Data + ", Scripts: " + options.Scripts +
                                                  ", Coalesced: " + options.Coalesced + ", Names: " + options.Names + ", Properties: " + options.Properties + ", SWF: " + options.SWFs + "]");
                            dumpPCCFolder(options.InputFolder, dumpargs, options.OutputFolder);
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine("Nothing was selected to dump. Use --scripts, --names, --data, --imports, --exports, --swf or --coalesced to dump items from a pcc.");
                        endProgram(CODE_NO_DATA_TO_DUMP);
                    }
                }
                else if (options.Transplant)
                {
                    if (options.InputFile == null)
                    {
                        Console.Error.WriteLine("--transplant requires --inputfile.");
                        endProgram(CODE_INPUT_FILE_NOT_FOUND);
                    }
                    if (options.TargetFile == null)
                    {
                        Console.Error.WriteLine("--targetfile is required for this operation.");
                        endProgram(CODE_INPUT_FILE_NOT_FOUND);
                    }
                    if (!File.Exists(options.TargetFile))
                    {
                        Console.Error.WriteLine("Target file does not exist: " + options.TargetFile);
                        endProgram(CODE_INPUT_FILE_NOT_FOUND);
                    }

                    if (options.TargetFile.ToLower() == options.InputFile.ToLower())
                    {
                        Console.Error.WriteLine("Cannot transplant GUI files into self");
                        endProgram(CODE_SAME_IN_OUT_FILE);
                    }

                    Console.WriteLine("Transplanting GUI files from " + options.InputFile + " to " + options.TargetFile);
                    Console.WriteLine("Extracting GUI files");
                    string gfxfolder = AppDomain.CurrentDomain.BaseDirectory + @"extractedgfx\";
                    writeVerboseLine("Extracting GFX Files from source to " + gfxfolder);
                    extractAllGFxMovies(options.InputFile, gfxfolder);
                    Console.WriteLine("Installing GUI files");
                    replaceSWFs(gfxfolder, options.TargetFile, options.Compress);
                }
                else
                {
                    Console.Error.WriteLine("No operation was specified");
                    Console.Error.WriteLine(options.GetUsage());
                    endProgram(CODE_NO_OPERATION);
                }
            }
            endProgram(0);
        }