コード例 #1
0
ファイル: TestScripts.cs プロジェクト: khadoran/reanimator
        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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: khadoran/reanimator
        // really should make a base for .drl and .rom
        public static void CookLevelRulesFiles(IEnumerable<String> levelRulesFiles)
        {
            Console.WriteLine("Processing level rules...");
            foreach (String filePath in levelRulesFiles)
            {
                try
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(filePath);

                    LevelRulesFile levelRulesFile = new LevelRulesFile(filePath, null);
                    levelRulesFile.ParseXmlDocument(xmlDocument);
                    byte[] fileBytes = levelRulesFile.ToByteArray();

                    File.WriteAllBytes(filePath.Replace(LevelRulesFile.ExtensionDeserialised, LevelRulesFile.Extension), fileBytes);
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);
                    Console.WriteLine(String.Format("Error: Failed to serialize file {0}", filePath));
                }
            }
        }