public static void Apply(FileSource menuSource) { // pull the relevant file out of the archive var file = menuSource.GetFile(ArchivePath); var mes3bytes = new ArraySegment <byte>(file, FileOffset, FileLength); var mes3 = TextFile.FromBytes(mes3bytes.ToArray(), true); // set names mes3.Pages[NamesPage].Strings[Squall] = Properties.Settings.Default.NameSquall; mes3.Pages[NamesPage].Strings[Rinoa] = Properties.Settings.Default.NameRinoa; mes3.Pages[NamesPage].Strings[Angelo] = Properties.Settings.Default.NameAngelo; mes3.Pages[NamesPage].Strings[Quezacotl] = Properties.Settings.Default.NameQuezacotl; mes3.Pages[NamesPage].Strings[Shiva] = Properties.Settings.Default.NameShiva; mes3.Pages[NamesPage].Strings[Ifrit] = Properties.Settings.Default.NameIfrit; mes3.Pages[NamesPage].Strings[Siren] = Properties.Settings.Default.NameSiren; mes3.Pages[NamesPage].Strings[Brothers] = Properties.Settings.Default.NameBrothers; mes3.Pages[NamesPage].Strings[Diablos] = Properties.Settings.Default.NameDiablos; mes3.Pages[NamesPage].Strings[Carbuncle] = Properties.Settings.Default.NameCarbuncle; mes3.Pages[NamesPage].Strings[Leviathan] = Properties.Settings.Default.NameLeviathan; mes3.Pages[NamesPage].Strings[Pandemona] = Properties.Settings.Default.NamePandemona; mes3.Pages[NamesPage].Strings[Cerberus] = Properties.Settings.Default.NameCerberus; mes3.Pages[NamesPage].Strings[Alexander] = Properties.Settings.Default.NameAlexander; mes3.Pages[NamesPage].Strings[Doomtrain] = Properties.Settings.Default.NameDoomtrain; mes3.Pages[NamesPage].Strings[Bahamut] = Properties.Settings.Default.NameBahamut; mes3.Pages[NamesPage].Strings[Cactuar] = Properties.Settings.Default.NameCactuar; mes3.Pages[NamesPage].Strings[Tonberry] = Properties.Settings.Default.NameTonberry; mes3.Pages[NamesPage].Strings[Eden] = Properties.Settings.Default.NameEden; mes3.Pages[NamesPage].Strings[Boko] = Properties.Settings.Default.NameBoko; mes3.Pages[NamesPage].Strings[Griever] = Properties.Settings.Default.NameGriever; // apply changes Array.Copy(mes3.Encode(), 0, file, FileOffset, FileLength); menuSource.ReplaceFile(ArchivePath, file); }
public static void Apply(FileSource menuSource, State settings) { // pull the relevant file out of the archive var file = menuSource.GetFile(ArchivePath); var mes3bytes = file.Skip(FileOffset).Take(FileLength); var mes3 = TextFile.FromBytes(mes3bytes, true); // set names mes3.Pages[NamesPage].Strings[Squall] = settings.NameSquall; mes3.Pages[NamesPage].Strings[Rinoa] = settings.NameRinoa; mes3.Pages[NamesPage].Strings[Angelo] = settings.NameAngelo; mes3.Pages[NamesPage].Strings[Quezacotl] = settings.NameQuezacotl; mes3.Pages[NamesPage].Strings[Shiva] = settings.NameShiva; mes3.Pages[NamesPage].Strings[Ifrit] = settings.NameIfrit; mes3.Pages[NamesPage].Strings[Siren] = settings.NameSiren; mes3.Pages[NamesPage].Strings[Brothers] = settings.NameBrothers; mes3.Pages[NamesPage].Strings[Diablos] = settings.NameDiablos; mes3.Pages[NamesPage].Strings[Carbuncle] = settings.NameCarbuncle; mes3.Pages[NamesPage].Strings[Leviathan] = settings.NameLeviathan; mes3.Pages[NamesPage].Strings[Pandemona] = settings.NamePandemona; mes3.Pages[NamesPage].Strings[Cerberus] = settings.NameCerberus; mes3.Pages[NamesPage].Strings[Alexander] = settings.NameAlexander; mes3.Pages[NamesPage].Strings[Doomtrain] = settings.NameDoomtrain; mes3.Pages[NamesPage].Strings[Bahamut] = settings.NameBahamut; mes3.Pages[NamesPage].Strings[Cactuar] = settings.NameCactuar; mes3.Pages[NamesPage].Strings[Tonberry] = settings.NameTonberry; mes3.Pages[NamesPage].Strings[Eden] = settings.NameEden; mes3.Pages[NamesPage].Strings[Boko] = settings.NameBoko; mes3.Pages[NamesPage].Strings[Griever] = settings.NameGriever; // apply changes var newFile = file.Take(FileOffset).ToList(); newFile.AddRange(mes3.Encode()); newFile.AddRange(file.Skip(FileOffset + FileLength)); menuSource.ReplaceFile(ArchivePath, newFile); }
public void EncoderTest() { // files tend to have 16 pages var textFile = new TextFile(); for (var i = 0; i < 16; i++) { textFile.Pages.Add(new MenuTextPage(0)); } // add some strings (locations & offsets don't matter beyond whether or not they're 0) textFile.Pages[2].Location = 36; for (var i = 0; i < 14; i++) { textFile.Pages[2].Offsets.Add(0); } textFile.Pages[2].Offsets[6] = 1; textFile.Pages[2].Offsets[7] = 1; textFile.Pages[2].Strings.Add("Squalf"); textFile.Pages[2].Strings.Add("Doritos"); textFile.Pages[3].Location = 92; for (var i = 0; i < 3; i++) { textFile.Pages[3].Offsets.Add(0); } textFile.Pages[3].Offsets[0] = 1; textFile.Pages[3].Offsets[2] = 1; textFile.Pages[3].Strings.Add("Rinoa"); textFile.Pages[3].Strings.Add("Quezacotl"); // run through the encoder & make sure everything is the same textFile = TextFile.FromBytes(textFile.Encode(), false); Assert.Equal(16, textFile.Pages.Count); // offsets per page Assert.Empty(textFile.Pages[0].Offsets); Assert.Empty(textFile.Pages[1].Offsets); Assert.Equal(14, textFile.Pages[2].Offsets.Count); Assert.Equal(3, textFile.Pages[3].Offsets.Count); Assert.Empty(textFile.Pages[4].Offsets); Assert.Empty(textFile.Pages[5].Offsets); // page 2 strings Assert.Equal(2, textFile.Pages[2].Strings.Count); Assert.Equal("Squalf", textFile.Pages[2].Strings[0]); Assert.Equal("Doritos", textFile.Pages[2].Strings[1]); // page 2 offsets Assert.Equal(0, textFile.Pages[2].Offsets[4]); Assert.Equal(0, textFile.Pages[2].Offsets[5]); Assert.NotEqual(0, textFile.Pages[2].Offsets[6]); Assert.NotEqual(0, textFile.Pages[2].Offsets[7]); Assert.Equal(0, textFile.Pages[2].Offsets[8]); Assert.Equal(0, textFile.Pages[2].Offsets[9]); // page 3 strings Assert.Equal(2, textFile.Pages[3].Strings.Count); Assert.Equal("Rinoa", textFile.Pages[3].Strings[0]); Assert.Equal("Quezacotl", textFile.Pages[3].Strings[1]); // page 3 offsets Assert.NotEqual(0, textFile.Pages[3].Offsets[0]); Assert.Equal(0, textFile.Pages[3].Offsets[1]); Assert.NotEqual(0, textFile.Pages[3].Offsets[2]); }