public LevelRulesEditor(FileManager fileManager, PackFileEntry fileEntry)
        {
            InitializeComponent();
            DoubleBuffered = true;

            _fileManager = fileManager;
            byte[] fileBytes = fileManager.GetFileBytes(fileEntry);
            _levelRules = new LevelRulesFile(fileEntry.Path, null);
            _levelRules.ParseFileBytes(fileBytes);

            foreach (LevelRulesFile.LevelRule levelRule in _levelRules.LevelRules)
            {
                if (levelRule.StaticRooms != null)
                {
                    _LoadRooms(levelRule.StaticRooms, fileEntry.Path);
                }
                else
                {
                    foreach (LevelRulesFile.Room[] levelRules in levelRule.Rules)
                    {
                        _LoadRooms(levelRules, fileEntry.Path);
                    }
                }
            }
        }
Exemple #2
0
        public static void TestAllLevelRules(bool doTCv4=false)
        {
            //const String root = @"D:\Games\Hellgate London\data\background\";
            //List<String> drlFiles = new List<String>(Directory.GetFiles(root, "*.drl", SearchOption.AllDirectories));

            String debugPath = @"C:\drl_debug\";
            FileManager.ClientVersions clientVersion = FileManager.ClientVersions.SinglePlayer;
            if (doTCv4)
            {
                debugPath = Path.Combine(debugPath, "tcv4");
                clientVersion = FileManager.ClientVersions.TestCenter;
            }
            debugPath += @"\"; // lazy
            Directory.CreateDirectory(debugPath);

            FileManager fileManager = new FileManager(Config.HglDir, clientVersion);
            fileManager.BeginAllDatReadAccess();
            fileManager.LoadTableFiles();

            int tested = 0;
            int failed = 0;
            //foreach (String drlFilePath in drlFiles)
            foreach (PackFileEntry fileEntry in fileManager.FileEntries.Values)
            {
                if (!fileEntry.Path.EndsWith(LevelRulesFile.Extension)) continue;
                tested++;
                failed++;

                //String path = drlFilePath;
                String path = fileEntry.Path;
                //path = @"D:\Games\Hellgate London\data\background\catacombs\ct_rule_100.drl";
                //path = @"D:\Games\Hellgate London\data\background\city\rule_pmt02.drl";

                //byte[] levelRulesBytes = File.ReadAllBytes(path);
                byte[] bytes = fileManager.GetFileBytes(fileEntry);
                LevelRulesFile bytesObj = new LevelRulesFile();

                //String fileName = path.Replace(@"D:\Games\Hellgate London\data\background\", "");
                String fileName = Path.GetFileName(path);
                String xmlPath = path.Replace(LevelRulesFile.Extension, LevelRulesFile.ExtensionDeserialised);
                Console.WriteLine("Loading: " + fileName);
                try
                {
                    bytesObj.ParseFileBytes(bytes);
                    byte[] bytesObjXml = bytesObj.ExportAsDocument();
                    MemoryStream ms = new MemoryStream(bytesObjXml);
                    //File.WriteAllBytes(xmlPath, xmlBytes);

                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(ms);//.Load(xmlPath);
                    LevelRulesFile bytesObjXmlObj = new LevelRulesFile();
                    bytesObjXmlObj.ParseXmlDocument(xmlDocument);
                    byte[] bytesObjXmlObjXml = bytesObjXmlObj.ExportAsDocument();
                    byte[] bytesObjXmlObjXmlBytes = bytesObjXmlObj.ToByteArray();

                    if (!bytesObjXml.SequenceEqual(bytesObjXmlObjXml))
                    {
                        File.WriteAllBytes(debugPath + fileName + "0.bytesObjXml.xml", bytesObjXml);
                        File.WriteAllBytes(debugPath + fileName + "1.bytesObjXmlObjXml.xml", bytesObjXmlObjXml);
                    }

                    // note: ct_rule_100.drl has unreferenced rules (only one found out of all files)
                    if (bytes.Length != bytesObjXmlObjXmlBytes.Length && !path.Contains("ct_rule_100"))
                    {
                        File.WriteAllBytes(debugPath + fileName + "0.bytesObjXml.xml", bytesObjXml);
                        File.WriteAllBytes(debugPath + fileName + "1.bytesObjXmlObjXml.xml", bytesObjXmlObjXml);
                        File.WriteAllBytes(debugPath + fileName + "2.bytes", bytes);
                        File.WriteAllBytes(debugPath + fileName + "3.bytesObjXmlObjXmlBytes", bytesObjXmlObjXmlBytes);
                    }

                    failed--;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to load file!\n" + e);
                    continue;
                }
            }

            Console.WriteLine("Tested: " + tested);
            Console.WriteLine("Failed: " + failed);
        }
Exemple #3
0
        private void _QuickLevelRulesWorker(ProgressForm progressForm, Object param)
        {
            const int progressStepRate = 50;
            const String outputResultsName = "conversion_results_drl.txt";
            ExtractPackPatchArgs extractPatchArgs = (ExtractPackPatchArgs)param;

            TextWriter consoleOut = Console.Out;
            TextWriter textWriter = new StreamWriter(outputResultsName);
            Console.SetOut(textWriter);
            Console.WriteLine("Results of most recent conversion of *.drl files. Please scroll to end for tallied results.");

            // get files
            List<PackFileEntry> drlFiles = _fileManager.FileEntries.Values.Where(fileEntry => fileEntry.Name.EndsWith(LevelRulesFile.Extension)).ToList();
            _fileManager.BeginAllDatReadAccess();

            // loop through file entries
            int count = drlFiles.Count();
            progressForm.ConfigBar(1, count, progressStepRate);
            progressForm.SetLoadingText("Converting *.drl files... (" + count + ")");
            int i = 0;
            int successful = 0;
            int readFailed = 0;
            int exportFailed = 0;
            int saveFailed = 0;
            int failed = 0;
            foreach (PackFileEntry fileEntry in drlFiles)
            {
                // update progress
                if (i % progressStepRate == 0)
                {
                    progressForm.SetCurrentItemText(fileEntry.Path);
                }
                i++;

                // get file and convert
                Console.WriteLine("Processing file " + fileEntry.Path + "...");
                byte[] fileBytes;
                LevelRulesFile levelRulesFile = new LevelRulesFile();

                try
                {
                    fileBytes = _fileManager.GetFileBytes(fileEntry);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    Console.WriteLine("Error: FileManager failed to read file!\n");
                    readFailed++;
                    continue;
                }

                try
                {
                    levelRulesFile.ParseFileBytes(fileBytes);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    Console.WriteLine("Warning: Failed to convert file: " + fileEntry.Name + "\n");
                    failed++;
                    continue;
                }

                // generate file
                String savePath = Path.Combine(extractPatchArgs.RootDir, fileEntry.Path);

                byte[] documentBytes;
                try
                {
                    documentBytes = levelRulesFile.ExportAsDocument();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    Console.WriteLine("Warning: ExportAsDocument() failed for file: " + savePath + "\n");
                    exportFailed++;
                    continue;
                }

                // save file
                String filePath = savePath.Replace(LevelRulesFile.Extension, LevelRulesFile.ExtensionDeserialised);
                try
                {
                    String directoryName = Path.GetDirectoryName(savePath);
                    Debug.Assert(directoryName != null);

                    Directory.CreateDirectory(directoryName);

                    // FormTools.WriteFileWithRetry(filePath, documentBytes); should use this - but want a way to "cancel all" first, or will get endless questions for big failures
                    File.WriteAllBytes(filePath, documentBytes);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    Console.WriteLine("Warning: WriteAllBytes() failed for file: " + filePath + "\n");
                    saveFailed++;
                    continue;
                }

                successful++;
            }

            _fileManager.EndAllDatAccess();

            // output final results
            Console.WriteLine("\nFiles Found: " + count);
            Console.WriteLine("\nFiles Created: " + successful);
            if (readFailed > 0) Console.WriteLine(readFailed + " file(s) could not be read from the data files.");
            if (exportFailed > 0) Console.WriteLine(readFailed + " file(s) could not be exported.");
            if (saveFailed > 0) Console.WriteLine(readFailed + " file(s) could not be saved.");
            if (failed > 0) Console.WriteLine(failed + " file(s) failed.");
            textWriter.Close();
            Console.SetOut(consoleOut);

            try
            {
                Process process = new Process { StartInfo = { FileName = Config.TxtEditor, Arguments = outputResultsName } };
                process.Start();
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    "Failed to open results!\nThe " + outputResultsName + " can be found in your Reanimator folder.\n" +
                    e, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }