示例#1
0
        public static void Main(string[] args)
        {
            OpenFileDialog openDialog = new OpenFileDialog();

            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                string     saveFile = openDialog.FileName;
                EsfFile    file     = EsfCodecUtil.LoadEsfFile(saveFile);
                ParentNode parent   = file.RootNode as ParentNode;
                for (int i = 0; i < pathToCamera.Length; i++)
                {
                    if (parent == null)
                    {
                        break;
                    }
                    parent = parent[pathToCamera[i]];
                }
                if (parent == null || parent.Values.Count == 0)
                {
                    MessageBox.Show("Could not find path to camera in save file :(");
                    return;
                }
                EsfValueNode <uint> node = parent.Values[0] as EsfValueNode <uint>;
                node.FromString("1");

                SaveFileDialog saveDialog = new SaveFileDialog {
                    InitialDirectory = Path.GetDirectoryName(openDialog.FileName)
                };
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    EsfCodecUtil.WriteEsfFile(saveDialog.FileName, file);
                }
            }
        }
 private void Save(string filename)
 {
     try {
         EsfCodecUtil.WriteEsfFile(filename, EditedFile);
         editEsfComponent.RootNode.Modified = false;
     } catch (Exception e) {
         MessageBox.Show(string.Format("Could not save {0}: {1}", filename, e));
     }
 }
示例#3
0
        static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                Console.WriteLine("Error. No arguments to parse were detected. Terminating...");
                return;
            }

            if (args.Length < 2)
            {
                Console.WriteLine("Error. Not all of the required arguments were passed. Terminating...");
                return;
            }

            if (args.Length > 2)
            {
                Console.WriteLine("Warning. Detected more than 2 arguments! Extra arguments will be ignored.");
            }

            if (!uint.TryParse(args[0], out uint newCapitalId))
            {
                Console.WriteLine("Failed to parse new capital id argument!");
                return;
            }

            string game        = args[1].ToLower();
            var    appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var    directory   = new DirectoryInfo($@"{appDataPath}\The Creative Assembly\{game}\save_games");

            if (!directory.EnumerateFiles().Any())
            {
                Console.WriteLine("Error. No save files were found. Terminating...");
                return;
            }

            var latestSaveFile = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();

            var saveFile = EsfCodecUtil.LoadEsfFile(latestSaveFile.FullName);
            var campaign_save_game_node = saveFile.RootNode as ParentNode;
            var compressed_data_node    = campaign_save_game_node.Children.Find(n => n.GetName() == "COMPRESSED_DATA");
            var campaign_env_node       = compressed_data_node.Children.Find(n => n.GetName() == "CAMPAIGN_ENV");
            var campaign_model_node     = campaign_env_node.Children.Find(n => n.GetName() == "CAMPAIGN_MODEL");
            var world_node                = campaign_model_node.Children.Find(n => n.GetName() == "WORLD");
            var faction_array_node        = world_node.Children.Find(n => n.GetName() == "FACTION_ARRAY");
            var player_faction_node       = faction_array_node.Children.First().Children.First();                               // Note: It's assumed that the first child of the faction array is a player faction!!!
            var og_capital_id_value_node  = player_faction_node.Value[21] as OptimizedUIntNode;                                 // Assuming that the original capital id node is located at index 7 of the faction node
            var cur_capital_id_value_node = player_faction_node.Value[22] as OptimizedUIntNode;                                 // Assuming that the current capital id node is located at index 8 of the faction node

            // Replace capital Id
            og_capital_id_value_node.Value  = newCapitalId;
            cur_capital_id_value_node.Value = newCapitalId;

            EsfCodecUtil.WriteEsfFile(latestSaveFile.FullName, saveFile);
        }
示例#4
0
 private void Save(string filename)
 {
     try
     {
         EsfCodecUtil.WriteEsfFile(filename, EditedFile);
         _editEsfComponent.RootNode.Modified = false;
     }
     catch (Exception arg)
     {
         MessageBox.Show($"Could not save {filename}: {arg}");
     }
 }
示例#5
0
        public string RunTest(string file, ToolStripProgressBar progress, ToolStripStatusLabel statusLabel)
        {
            string originalTitle = statusLabel.Text;

            statusLabel.Text = string.Format("Loading file {0}", Path.GetFileName(file));
            Application.DoEvents();
            string result;

            // ProgressUpdater updater = new ProgressUpdater(progress);
            using (Stream s = File.OpenRead(file)) {
                try {
                    EsfCodec codec = EsfCodecUtil.GetCodec(File.OpenRead(file));
                    if (codec != null)
                    {
                        //updater.StartLoading(file, codec);
                        TestsRun++;
                        EsfFile esfFile      = new EsfFile(s, codec);
                        string  testFileName = file + "_test";
                        EsfCodecUtil.WriteEsfFile(testFileName, esfFile);
//                        using (BinaryWriter writer = new BinaryWriter(File.Create(testFileName))) {
//                            codec.EncodeRootNode(writer, esfFile.RootNode);
//                        }
                        statusLabel.Text = string.Format("Saving file {0}", Path.GetFileName(file));
                        Application.DoEvents();
                        using (Stream reloadStream = File.OpenRead(testFileName)) {
                            EsfFile reloadedFile = new EsfFile(reloadStream, codec);
                            if (esfFile.Equals(reloadedFile))
                            {
                                TestSuccesses++;
                                result = string.Format("success Test {0}", file);
                            }
                            else
                            {
                                result = string.Format("FAIL Test {0}: Reload of save file different from original", file);
                            }
                        }
                        Application.DoEvents();
                        File.Delete(testFileName);
                    }
                    else
                    {
                        result = string.Format("not running test on {0}", file);
                    }
                } catch (Exception e) {
                    result = string.Format("FAIL Test of {0}: {1}", file, e);
                }
                s.Close();
                //updater.LoadingFinished();
            }
            statusLabel.Text = originalTitle;
            return(result);
        }
示例#6
0
        public string RunTest(string file, ToolStripProgressBar progress, ToolStripStatusLabel statusLabel)
        {
            string text = statusLabel.Text;

            statusLabel.Text = $"Loading file {Path.GetFileName(file)}";
            Application.DoEvents();
            string result;

            using (Stream stream = File.OpenRead(file))
            {
                try
                {
                    EsfCodec codec = EsfCodecUtil.GetCodec(File.OpenRead(file));
                    if (codec != null)
                    {
                        TestsRun++;
                        EsfFile esfFile = new EsfFile(stream, codec);
                        string  text2   = file + "_test";
                        EsfCodecUtil.WriteEsfFile(text2, esfFile);
                        statusLabel.Text = $"Saving file {Path.GetFileName(file)}";
                        Application.DoEvents();
                        using (Stream stream2 = File.OpenRead(text2))
                        {
                            EsfFile obj = new EsfFile(stream2, codec);
                            if (esfFile.Equals(obj))
                            {
                                TestSuccesses++;
                                result = $"success Test {file}";
                            }
                            else
                            {
                                result = $"FAIL Test {file}: Reload of save file different from original";
                            }
                        }
                        Application.DoEvents();
                        File.Delete(text2);
                    }
                    else
                    {
                        result = $"not running test on {file}";
                    }
                }
                catch (Exception arg)
                {
                    result = $"FAIL Test of {file}: {arg}";
                }
                stream.Close();
            }
            statusLabel.Text = text;
            return(result);
        }
示例#7
0
        public static void Main(string[] args)
        {
            AbcaFileCodec codec = new AbcaFileCodec
            {
                Header = new EsfHeader
                {
                    ID = 0xABCA
                }
            };
            RecordNode root = new RecordNode(codec)
            {
                Name = "root"
            };
            RecordNode child = new RecordNode(codec)
            {
                Name = "copySource"
            };
            EsfValueNode <string> utf16String = (EsfValueNode <string>)codec.CreateValueNode(EsfType.UTF16);

            utf16String.Value = "utf16";
            child.Value.Add(utf16String);
            root.Value.Add(child);
            child = new RecordNode(codec)
            {
                Name = "copyTarget"
            };
            EsfValueNode <string> copyString = (EsfValueNode <string>)utf16String.CreateCopy();

            // copyString.Value = "copy";
            copyString.FromString("copy");
            child.Value.Add(copyString);
            root.Value.Add(child);

            // this is needed for the file to create the record nodes properly
            SortedList <int, string> nodeNames = new SortedList <int, string>();

            nodeNames.Add(0, "root");
            nodeNames.Add(1, "copySource");
            nodeNames.Add(2, "copyTarget");
            // this property needs to be added to the EsfFileCodec, getting and setting EsfFileCodec#nodeNames
            codec.NodeNames = nodeNames;

            EsfFile file = new EsfFile(root, codec);

            EsfCodecUtil.WriteEsfFile("string_container.esf", file);
        }
示例#8
0
        static void testNew(string filename)
        {
            using (FileStream
                   logStream = File.Create(filename + "_log.txt"),
                   addressStream = File.Create(filename + "_address.txt")) {
                logWriter        = new StreamWriter(logStream);
                addressLogWriter = new StreamWriter(addressStream);
                EsfFile  file  = null;
                DateTime start = DateTime.Now;
                try {
                    Console.WriteLine("reading {0}", filename);
                    using (FileStream stream = File.OpenRead(filename)) {
                        EsfCodec codec = EsfCodecUtil.GetCodec(stream);
                        TicToc   timer = new TicToc();
                        codec.NodeReadStarting += timer.Tic;
                        codec.NodeReadFinished += timer.Toc;
                        // codec.NodeReadFinished += OutputNodeEnd;
                        file = EsfCodecUtil.LoadEsfFile(filename);
                        forceDecode(file.RootNode);
                        //file = new EsfFile(stream, codec);

                        timer.DumpAll();
                    }
                    Console.WriteLine("{0} read in {1} seconds", file, (DateTime.Now.Ticks - start.Ticks) / 10000000);
                    Console.WriteLine("Reading finished, saving now");
                } catch (Exception e) {
                    Console.WriteLine("Read failed: {0}, {1}", filename, e);
                }
                try {
                    string saveFile = filename + "_save";
                    if (file != null)
                    {
                        EsfCodecUtil.WriteEsfFile(saveFile, file);
                    }
                    //File.Delete(saveFile);
                } catch (Exception e) {
                    Console.WriteLine("Write {0} failed: {1}", filename, e);
                }
                logWriter.Flush();
                addressLogWriter.Flush();
            }
        }