public static void ApplyEdeaFix(FileSource battleSource, FileSource fieldSource) { // clone encounter var encFile = EncounterFile.FromSource(battleSource); encFile.Encounters[845] = encFile.Encounters[136]; battleSource.ReplaceFile(EncounterFile.Path, encFile.Encode()); // redirect field script to clone var fieldName = "glyagu1"; var field = Field.FieldScript.FromSource(fieldSource, fieldName); var script = field.Entities[2].Scripts[4].Instructions; for (int i = 0; i < script.Count - 2; i++) { if (script[i].OpCode == Field.FieldScript.OpCodesReverse["pshn_l"] && script[i].Param == 136) { if (script[i + 2].OpCode == Field.FieldScript.OpCodesReverse["battle"]) { field.Entities[2].Scripts[4].Instructions[i].Param = 845; } } } StorySkip.SaveToSource(fieldSource, fieldName, field.Encode()); }
public static void Apply(FileSource fieldSource, Dictionary <int, int> shuffle) { // take a script from the start field var scriptField = "start0"; var scriptEntity = 0; var scriptId = 0; var script = App.ReadEmbeddedFile(string.Format("FF8Mod.Maelstrom.FieldScripts.{0}.{1}.{2}.txt", scriptField, scriptEntity, scriptId)); // move cards to their assigned decks foreach (var card in shuffle.Keys) { // if you getcard before you setcard, it reveals the location in the card menu // script += Environment.NewLine + GetCard(i); script += Environment.NewLine + SetCard(shuffle[card], card); } // save the script var field = FieldScript.FromSource(fieldSource, scriptField); field.ReplaceScript(scriptEntity, scriptId, script); StorySkip.SaveToSource(fieldSource, scriptField, field.Encode()); // todo: put this somewhere more sensible }
public static void Apply(FileSource fieldSource, Dictionary <int, int> shuffle) { var musicOps = new int[] { FieldScript.OpCodesReverse["setbattlemusic"], FieldScript.OpCodesReverse["musicload"] }; // load list of scripts to search for music changes var scripts = MusicLoads.Select(m => new Tuple <string, int, int>(m.FieldName, m.Entity, m.Script)).ToList(); // add any extra changes from free roam boss clouds scripts.AddRange(Boss.Bosses.Where(b => !string.IsNullOrEmpty(b.FieldID)).Select(b => new Tuple <string, int, int>(b.FieldID, b.FieldEntity, b.FieldScript))); // remove duplicates scripts = scripts.Distinct().ToList(); // search all these scripts & replace the music IDs with random ones foreach (var fieldName in scripts.Select(s => s.Item1).Distinct()) { var field = FieldScript.FromSource(fieldSource, fieldName); foreach (var s in scripts.Where(s => s.Item1 == fieldName)) { var script = field.Entities[s.Item2].Scripts[s.Item3]; for (int i = 0; i < script.Instructions.Count; i++) { if (musicOps.Contains(script.Instructions[i].OpCode) && i > 0) { // update the previous instruction (where the track ID is pushed onto the stack) var prevParam = script.Instructions[i - 1].Param; if (shuffle.ContainsKey(prevParam)) { field.Entities[s.Item2].Scripts[s.Item3].Instructions[i - 1].Param = shuffle[prevParam]; } } } } StorySkip.SaveToSource(fieldSource, fieldName, field.Encode()); // todo: this still needs moving } }
// update field archive (and af3dn.p) private static void FieldOps(int seed, string seedString, SpoilerFile spoilerFile) { Debug.WriteLine("field ops start"); while (true) { try { CreateOrRestoreArchiveBackup(Globals.FieldPath); var fieldSource = new FileSource(Globals.FieldPath); // apply free roam if (Properties.Settings.Default.StorySkip) { StorySkip.Apply(fieldSource, seedString, seed); } else { StorySkip.Remove(); } // apply card shuffle if (Properties.Settings.Default.CardShuffle) { var shuffle = CardShuffle.Shuffle(seed); if (Properties.Settings.Default.SpoilerFile) { spoilerFile.AddCards(shuffle); } CardShuffle.Apply(fieldSource, shuffle); } // apply music shuffle if (Properties.Settings.Default.MusicShuffle) { var shuffle = MusicShuffle.Shuffle(seed); if (Properties.Settings.Default.SpoilerFile) { spoilerFile.AddMusic(shuffle); } MusicShuffle.Apply(fieldSource, shuffle); } // write to file if (Properties.Settings.Default.StorySkip || Properties.Settings.Default.CardShuffle) { fieldSource.Encode(); } break; } catch (Exception x) { if (x is IOException || x is UnauthorizedAccessException || x is FileNotFoundException) { if (HandleFileException(Globals.FieldPath) == false) { break; } } else { throw; } } } Debug.WriteLine("field ops end"); }