public StarterCollection(IRtdxRom rom, ILuaGenerator luaGenerator, ICSharpGenerator cSharpGenerator) { this.rom = rom ?? throw new ArgumentNullException(nameof(rom)); this.luaGenerator = luaGenerator ?? throw new ArgumentNullException(nameof(luaGenerator)); this.cSharpGenerator = cSharpGenerator ?? throw new ArgumentNullException(nameof(cSharpGenerator)); this.Starters = LoadStarters(); this.OriginalStarters = Starters.Select(s => s.Clone()).ToArray(); }
/// <summary> /// Saves changes to <see cref="Starters"/> to the underlying file structures (without saving the file structures themselves) /// </summary> public void Flush() { var mainExecutable = rom.GetMainExecutable(); var natureDiagnosis = rom.GetNatureDiagnosis(); var fixedPokemon = rom.GetFixedPokemon(); for (int i = 0; i < Starters.Length; i++) { var starter = Starters[i]; var oldPokemon = OriginalStarters[i]; var map = mainExecutable.StarterFixedPokemonMaps.First(m => m.PokemonId == oldPokemon.PokemonId); map.PokemonId = starter.PokemonId; var fixedPokemonEntry = fixedPokemon.Entries[(int)map.FixedPokemonId]; fixedPokemonEntry.PokemonId = starter.PokemonId; fixedPokemonEntry.Move1 = starter.Move1; fixedPokemonEntry.Move2 = starter.Move2; fixedPokemonEntry.Move3 = starter.Move3; fixedPokemonEntry.Move4 = starter.Move4; var ndEntry = natureDiagnosis.m_pokemonNatureAndTypeList.First(p => p.m_nameLabel == oldPokemon.PokemonId); ndEntry.m_nameLabel = starter.PokemonId; var natureDiagnosisActorMale = mainExecutable.ActorDatabase.ActorDataList .FirstOrDefault(a => a.SymbolName == ndEntry.m_symbolName); if (natureDiagnosisActorMale != null) { natureDiagnosisActorMale.PokemonIndex = starter.PokemonId; } // This may work in some cases but not all of them // I expect this will fail in-game for any Pokemon without a Female form //var natureDiagnosisActorFemale = mainExecutable.ActorDatabase.ActorDataList // .FirstOrDefault(a => a.SymbolName == ndEntry.m_symbolNameFemale); //if (natureDiagnosisActorFemale != null) //{ // natureDiagnosisActorFemale.PokemonIndex = starter.PokemonId; //} } this.OriginalStarters = Starters.Select(s => s.Clone()).ToArray(); }