// Mirror Changes private void updateStarterText() { var gr = Main.Config.getGARCReference("storytext"); for (int i = 0; i < 10; i++) { // get Story Text var sr = gr.getRelativeGARC(i, gr.Name); var s = Main.Config.getGARCByReference(sr); byte[][] storytextdata = s.Files; string[] storyText = TextFile.getStrings(storytextdata[41]); for (int j = 0; j < 3; j++) { int oldSpecies = oldStarters[j]; int species = Gifts[j].Species; // Replace Story Text string line = storyText[1 + j]; // Replace Species line = line.Replace(specieslist[oldSpecies], specieslist[species]); int oldIndex = Main.Config.Personal.getFormeIndex(oldSpecies, Gifts[j].Form); int oldtype0 = Main.Config.Personal[oldIndex].Types[0]; int newIndex = Main.Config.Personal.getFormeIndex(species, Gifts[j].Form); int newtype0 = Main.Config.Personal[newIndex].Types[0]; line = line.Replace(types[oldtype0], types[newtype0]); storyText[1 + j] = line; } storytextdata[41] = TextFile.getBytes(storyText); s.Files = storytextdata; s.Save(); } }
private void exportTextFile(string fileName, bool newline) { using (MemoryStream ms = new MemoryStream()) { ms.Write(new byte[] { 0xFF, 0xFE }, 0, 2); // Write Unicode BOM using (TextWriter tw = new StreamWriter(ms, new UnicodeEncoding())) { for (int i = 0; i < files.Length; i++) { // Get Strings for the File string[] data = TextFile.getStrings(files[i]); // Append the File Header tw.WriteLine("~~~~~~~~~~~~~~~"); tw.WriteLine("Text File : " + i); tw.WriteLine("~~~~~~~~~~~~~~~"); // Write the String to the File if (data == null) { continue; } foreach (string line in data) { tw.WriteLine(newline ? line.Replace("\\n\\n", " ") .Replace("\\n", " ") .Replace("\\c", "") .Replace("\\r", "") .Replace("\\\\", "\\") .Replace("\\[", "[") : line); } } } File.WriteAllBytes(fileName, ms.ToArray()); } }
// Exposed Methods internal static string[] getStrings(byte[] data) { TextFile t; try { t = new TextFile(data); } catch { return null; } return t.Lines; }