public void EditGift() { var arc = ROM.GetFile(GameFile.EncounterGift); var data = arc[0]; var objs = FlatBufferConverter.DeserializeFrom <EncounterGift8Archive>(data); var gifts = objs.Table; var names = Enumerable.Range(0, gifts.Length).Select(z => $"{z:000}").ToArray(); var cache = new DirectCache <EncounterGift8>(gifts); void Randomize() { int[] PossibleHeldItems = Legal.GetRandomItemList(ROM.Game); var pt = ROM.Data.PersonalData; int[] ban = pt.Table.Take(ROM.Info.MaxSpeciesID + 1) .Select((z, i) => new { Species = i, Present = ((PersonalInfoSWSH)z).IsPresentInGame }) .Where(z => !z.Present).Select(z => z.Species).ToArray(); var spec = EditUtil.Settings.Species; var srand = new SpeciesRandomizer(ROM.Info, ROM.Data.PersonalData); var frand = new FormRandomizer(ROM.Data.PersonalData); srand.Initialize(spec, ban); foreach (var t in gifts) { // swap gmax gifts for other gmax capable species if (t.CanGigantamax) { t.Species = (Species)Legal.GigantamaxForms[Randomization.Util.Random.Next(Legal.GigantamaxForms.Length)]; t.AltForm = t.Species == Species.Pikachu || t.Species == Species.Meowth ? 0 : frand.GetRandomForme((int)t.Species, false, false, false, false, ROM.Data.PersonalData.Table); // Pikachu & Meowth altforms can't gmax } else { t.Species = (Species)srand.GetRandomSpecies((int)t.Species); t.AltForm = frand.GetRandomForme((int)t.Species, false, false, true, true, ROM.Data.PersonalData.Table); } t.Ability = Randomization.Util.Random.Next(1, 4); // 1, 2, or H t.Ball = (Ball)Randomization.Util.Random.Next(1, 15); // packed bit, only allows for 15 balls t.HeldItem = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)]; t.Nature = Nature.Random25; t.Gender = FixedGender.Random; t.ShinyLock = Shiny.Random; if (t.IV_Hp != -4) { t.IV_Hp = t.IV_Atk = t.IV_Def = t.IV_SpAtk = t.IV_SpDef = t.IV_Spe = -1; } } } using var form = new GenericEditor <EncounterGift8>(cache, names, "Gift Pokémon Editor", Randomize); form.ShowDialog(); if (!form.Modified) { arc.CancelEdits(); } else { arc[0] = FlatBufferConverter.SerializeFrom(objs); } }