/// <summary> /// Creates a text block using a file reader class to read from the file /// </summary> /// <param name="startChar">The character that begins a text block (usually {)</param> /// <param name="endChar">Th character that ends a text block (usually })</param> /// <param name="reader">The file reader from which to read the text</param> public textBlock(char startChar, char endChar, fileReader reader) { start = startChar; int level = 0; end = endChar; lines = new List <string>(); string line = reader.readLine(); bool started = false; //While we are not done - we've started the text block, haven't finished it, and haven't finished the file while ((!started || level > 0) && !reader.atEnd()) { if (line != "") { lines.Add(line); } level += line.Split(start).Length - 1; if (level > 0) { started = true; } level -= line.Split(end).Length - 1; line = reader.readLine(); } int k = 0; while (k < lines.Count) { lines[k] = lines[k].Replace("\n", ""); lines[k] = lines[k].Replace("\r", ""); k++; } }
/// <summary> /// Eliminates the aggressive expansion opinion penalty for one or more countries /// </summary> /// <param name="reader">The reader for the save file</param> /// <param name="input">A string containing a comma separated list of country tags</param> public static void alterAggExp(fileReader reader, string input) { string[] tags = input.Replace(" ", "").Split(','); int[] locations = reader.findAll("active_relations="); foreach (int location in locations) { reader.setLineNum(location); reader.setCharNum(0); textBlock relationsBlock = new textBlock('{', '}', reader); foreach (string tag in tags) { int pos = relationsBlock.getPosition("\t\t\t" + tag + "=", false, 1); if (pos != -1) { reader.goTo(location + pos); textBlock relations = new textBlock('{', '}', reader); int innerPos = relations.getPosition("modifier=\"aggressive_expansion\"", false, 2); if (innerPos != -1) { reader.changeLine(location + pos + innerPos + 2, "\t\t\t\t\tcurrent_opinion=0.000"); } } } } }
/// <summary> /// Initialize a monarchAbilitiesForm, displaying the monarchs and heirs in a specified country /// </summary> /// <param name="readerIn">A reader for the save file we're editing</param> /// <param name="Loc">the line at which the relevant country text starts</param> /// <param name="tag">the three letter identifier for the relevant country (e.g. FRA for France)</param> public monarchAbilitiesForm(fileReader readerIn, int Loc, string Tag) { reader = readerIn; countryLoc = Loc; tag = Tag; InitializeComponent(); initialize(); }
/// <summary> /// Initialize a main menu form /// </summary> /// <param name="saveFile">The save file to edit</param> public EU4SaveGameEditor(string saveFile) { currentState = 0; InitializeComponent(); inputFile = saveFile; reader = new fileReader(saveFile); instructionText.AppendText("Save game successfully read. Please select an option below.\r\n"); aggExpButton.Visible = true; techLevelButton.Visible = true; monarchAbilitiesButton.Visible = true; countryResourcesButton.Visible = true; provinceButton.Visible = true; writeButton.Visible = true; inputTextRight.Enabled = false; }
/// <summary> /// Launches the country resource change form for one or more countries /// </summary> /// <param name="reader">The reader for the save file</param> /// <param name="input">A string containing a comma separated list of country tags</param> public static void changeCountyResouces(fileReader reader, string inputText) { string[] tags = inputText.Replace(" ", "").Split(','); int countriesLoc = reader.getPosition("countries=\r", 0, '{', '}', true); reader.setLineNum(countriesLoc); reader.setCharNum(0); textBlock countries = new textBlock('{', '}', reader); foreach (string tag in tags) { int countryLoc = countries.getPosition(tag + "="); countryResources resources = new countryResources(reader, countriesLoc + countryLoc, tag); resources.ShowDialog(); } }
/// <summary> /// Launches the technology level change form for one or more countries /// </summary> /// <param name="reader">The reader for the save file</param> /// <param name="input">A string containing a comma separated list of country tags</param> public static void alterTechLevel(fileReader reader, string input) { string[] tags = input.Replace(" ", "").Split(','); int countriesLoc = reader.getPosition("countries=\r", 0, '{', '}', true); reader.setLineNum(countriesLoc); reader.setCharNum(0); textBlock countries = new textBlock('{', '}', reader); foreach (string tag in tags) { int countryLoc = countries.getPosition(tag + "="); techLevelForm techLevel = new techLevelForm(reader, countriesLoc + countryLoc, tag); techLevel.ShowDialog(); } }
/// <summary> /// Initialize a tech level editing form /// </summary> /// <param name="readerIn">The reader containing the file to edit</param> /// <param name="Loc">The location in the reader of the country to edit</param> /// <param name="tag">The three letter identifier of the country to edit (e.g. FRA for france)</param> public techLevelForm(fileReader readerIn, int Loc, string tag) { loc = Loc; reader = readerIn; InitializeComponent(); reader.goTo(Loc); country = new textBlock('{', '}', reader); techLoc = country.getPosition("technology="); reader.goTo(Loc + techLoc + 2); string currentTech = reader.peekLine(); oldAdmLabel.Text = currentTech.Split('=')[1].Trim(); reader.moveBy(1); currentTech = reader.peekLine(); oldDipLabel.Text = currentTech.Split('=')[1].Trim(); reader.moveBy(1); currentTech = reader.peekLine(); oldMilLabel.Text = currentTech.Split('=')[1].Trim(); instructionText.Text = "Please enter new tech values for country " + tag + "\nor leave a box blank to leave that text level unchanged."; }
fileReader reader;//reader containing save to change /// <summary> /// Initialize province editing form /// </summary> /// <param name="readerIn">reader containing save to edit</param> public provinceEditor(fileReader readerIn) { reader = readerIn; InitializeComponent(); }
/// <summary> /// Initialize a form for changing country resources /// </summary> /// <param name="readerIn">a reader for the save to edit</param> /// <param name="Loc">the index for the beginning of the relevant country text block</param> /// <param name="tag">the three letter identifier for the country to edit (e.g. FRA for France)</param> public countryResources(fileReader readerIn, int Loc, string tag) { //read in all the current values from the save loc = Loc; countryTag = tag; reader = readerIn; InitializeComponent(); reader.goTo(loc); country = new textBlock('{', '}', reader); cash = country.getLine(country.getPosition("treasury=")).Split('=')[1]; manpower = country.getLine(country.getPosition("manpower=")).Split('=')[1]; int powerLoc = country.getPosition("powers="); adm = country.getLine(powerLoc + 2).Split(' ')[0].Trim(); dip = country.getLine(powerLoc + 2).Split(' ')[1].Trim(); mil = country.getLine(powerLoc + 2).Split(' ')[2].Trim(); techGroup = country.getLine(country.getPosition("technology_group=")).Split('=')[1]; capital = country.getLine(country.getPosition("capital=")).Split('=')[1]; stability = country.getLine(country.getPosition("stability=")).Split('=')[1]; cultures = new List <string>(); cultures.Add(country.getLine(country.getPosition("primary_culture=")).Split('=')[1]); int[] acceptedCultureLocs = country.findAll("accepted_culture="); foreach (int pos in acceptedCultureLocs) { cultures.Add(country.getLine(pos).Split('=')[1]); } religion = country.getLine(country.getPosition("religion=")).Split('=')[1]; government = country.getLine(country.getPosition("government=")).Split('=')[1]; int warExPos = country.getPosition("war_exhaustion="); if (warExPos != -1) { warExhaustion = country.getLine(country.getPosition("war_exhaustion=")).Split('=')[1]; } else { warExhaustion = "0.000"; } cashLabel.Text = cash; manpowerLabel.Text = manpower; admLabel.Text = adm; dipLabel.Text = dip; milLabel.Text = mil; techGroupLabel.Text = techGroup; capitalLabel.Text = capital; stabilityLabel.Text = stability; cultureLabel.Text = string.Join(", ", cultures); religionLabel.Text = religion; governmentLabel.Text = government; warExhaustionLabel.Text = warExhaustion; int dipPosition = reader.getPosition("diplomacy=", 0, '{', '}'); reader.goTo(dipPosition); textBlock diplomacy = new textBlock('{', '}', reader); int[] vassalages = diplomacy.findAll("vassal="); string overlord = ""; foreach (int i in vassalages) { reader.goTo(dipPosition + i); textBlock vassal = new textBlock('{', '}', reader); if (vassal.getLine(vassal.getPosition("second=")).Split('=')[1] == "\"" + tag + "\"") { overlord = vassal.getLine(vassal.getPosition("first=")).Split('=')[1].Replace("\"", ""); vassalLoc = dipPosition + i; break; } } if (overlord == "") { vassalLabel.Text = "none"; vassalLoc = dipPosition + 2; } else { vassalLabel.Text = overlord; } }
/// <summary> /// Write the (altered) save game to file /// </summary> /// <param name="reader">The reader containing the file</param> /// <param name="outputFile">Where to write the file</param> public static void writeFile(fileReader reader, string outputFile) { reader.writeFile(outputFile); }