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); } } }
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); }
// 打开文件 private void OpenFile(string openFilename) { string text = _statusLabel.Text; try { _fileToolStripMenuItem.Enabled = false; _optionsToolStripMenuItem.Enabled = false; _statusLabel.Text = $"Loading {openFilename}"; LogFileWriter logFileWriter = null; if (_writeLogFileToolStripMenuItem.Checked) { logFileWriter = new LogFileWriter(openFilename + ".xml"); } EditedFile = EsfCodecUtil.LoadEsfFile(openFilename); FileName = openFilename; logFileWriter?.Close(); // 自定义检索 try { Tw3kSearch.SearchFaction(EditedFile); } catch (Exception e) { Debug.WriteLine(e); throw; } // 自定义换词条 // ChangePersonality(EditedFile, 101, CeoCategory.Personality, // "3k_main_ceo_trait_personality_kind", "3k_main_ceo_trait_personality_humble", // "3k_main_ceo_trait_personality_fraternal"); Text = $"{Path.GetFileName(openFilename)} - EditSF {Application.ProductVersion}"; foreach (ToolStripItem dropDownItem in _bookmarksToolStripMenuItem.DropDownItems) { if (dropDownItem is BookmarkItem) { dropDownItem.Enabled = true; } } } catch (Exception value) { _statusLabel.Text = text; Console.WriteLine(value); } finally { _fileToolStripMenuItem.Enabled = true; _optionsToolStripMenuItem.Enabled = true; } }
private void OpenFile(string openFilename) { string oldStatus = statusLabel.Text; try { fileToolStripMenuItem.Enabled = false; optionsToolStripMenuItem.Enabled = false; // EsfCodec codec = EsfCodecUtil.GetCodec(stream); // updater.StartLoading(openFilename, codec); statusLabel.Text = string.Format("Loading {0}", openFilename); LogFileWriter logger = null; if (writeLogFileToolStripMenuItem.Checked) { logger = new LogFileWriter(openFilename + ".xml"); //codec.NodeReadFinished += logger.WriteEntry; //codec.Log += logger.WriteLogEntry; } EditedFile = EsfCodecUtil.LoadEsfFile(openFilename); //updater.LoadingFinished(); FileName = openFilename; if (logger != null) { logger.Close(); //codec.NodeReadFinished -= logger.WriteEntry; //codec.Log -= logger.WriteLogEntry; } Text = string.Format("{0} - EditSF {1}", Path.GetFileName(openFilename), Application.ProductVersion); foreach (ToolStripItem item in bookmarksToolStripMenuItem.DropDownItems) { if (item is BookmarkItem) { item.Enabled = true; } } } catch (Exception exception) { statusLabel.Text = oldStatus; Console.WriteLine(exception); } finally { fileToolStripMenuItem.Enabled = true; optionsToolStripMenuItem.Enabled = true; } }
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(); } }
private void OpenFile(string openFilename) { string oldStatus = statusLabel.Text; try { menuStrip1.Enabled = false; var stream = File.OpenRead(openFilename); //EsfCodec codec = EsfCodecUtil.GetCodec(stream); //updater.StartLoading(openFilename, codec); statusLabel.Text = string.Format("Loading {0}", openFilename); LogFileWriter logger = null; if (writeLogFileToolStripMenuItem.Checked) { logger = new LogFileWriter(openFilename + ".xml"); //codec.NodeReadFinished += logger.WriteEntry; //codec.Log += logger.WriteLogEntry; } EditedFile = EsfCodecUtil.LoadEsfFile(openFilename); //EditedFile = new EsfFile(codec.Parse(stream), codec); //updater.LoadingFinished(); FileName = openFilename; if (logger != null) { logger.Close(); //codec.NodeReadFinished -= logger.WriteEntry; //codec.Log -= logger.WriteLogEntry; } Text = string.Format("{0} - EditSFCharacters {1}", Path.GetFileName(openFilename), Application.ProductVersion); } catch (Exception exception) { statusLabel.Text = oldStatus; Console.WriteLine(exception); } finally { menuStrip1.Enabled = true; } }