Пример #1
0
    public AreaEditor8a(GameManagerPLA rom)
    {
        ROM = rom;

        Resident = (GFPack)ROM.GetFile(GameFile.Resident);
        var bin_settings = Resident.GetDataFullPath("bin/field/resident/AreaSettings.bin");

        Settings = FlatBufferConverter.DeserializeFrom <AreaSettingsTable8a>(bin_settings);

        AreaNames = Settings.Table.Select(z => z.Name).ToArray();

        const string startingArea = "ha_area01";

        (AreaIndex, Area) = LoadAreaByName(startingArea);

        InitializeComponent();

        PG_RandSettings.SelectedObject = EditUtil.Settings.Species;

        Loading = true;
        CB_Area.Items.AddRange(AreaNames);
        CB_Area.SelectedIndex = AreaIndex;
        LoadArea();
        Loading = false;
    }
Пример #2
0
        public void EditTrade()
        {
            var arc  = ROM.GetFile(GameFile.EncounterTrade);
            var data = arc[0];
            var objs = FlatBufferConverter.DeserializeFrom <EncounterTrade8Archive>(data);

            var trades = objs.Table;
            var names  = Enumerable.Range(0, trades.Length).Select(z => $"{z:000}").ToArray();
            var cache  = new DirectCache <EncounterTrade8>(trades);

            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 trades)
                {
                    // what you receive
                    t.Species       = srand.GetRandomSpecies(t.Species);
                    t.Form          = (byte)frand.GetRandomForme(t.Species, false, false, true, true, ROM.Data.PersonalData.Table);
                    t.AbilityNumber = (byte)Randomization.Util.Random.Next(1, 4); // 1, 2, or H
                    t.Ball          = (Ball)Randomization.Util.Random.Next(1, EncounterTrade8.BallToItem.Length);
                    t.HeldItem      = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)];
                    t.Nature        = (int)Nature.Random25;
                    t.Gender        = (int)FixedGender.Random;
                    t.ShinyLock     = (int)Shiny.Random;
                    t.Relearn1      = 0;
                    if (t.IV_HP != -4 && t.IVs.Any(z => z != 31))
                    {
                        t.IVs = new[] { -1, -1, -1, -1, -1, -1 }
                    }
                    ;

                    // what you trade
                    t.RequiredSpecies = srand.GetRandomSpecies(t.RequiredSpecies);
                    t.RequiredForm    = (byte)frand.GetRandomForme(t.RequiredSpecies, false, false, true, true, ROM.Data.PersonalData.Table);
                    t.RequiredNature  = (int)Nature.Random25; // any
                }
            }

            using var form = new GenericEditor <EncounterTrade8>(cache, names, "In-Game Trades Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                arc.CancelEdits();
            }
            else
            {
                arc[0] = FlatBufferConverter.SerializeFrom(objs);
            }
        }
Пример #3
0
        public void EditSymbolBehave()
        {
            bool altRand = Control.ModifierKeys == Keys.Alt;
            var  obj     = ROM.GetFile(GameFile.SymbolBehave);
            var  data    = obj[0];
            var  root    = FlatBufferConverter.DeserializeFrom <SymbolBehaveRoot>(data);
            var  cache   = new DataCache <SymbolBehave>(root.Table);
            var  names   = root.Table.Select(z => $"{z.Species}{(z.Form != 0 ? $"-{z.Form}" : "")}").ToArray();

            using var form = new GenericEditor <SymbolBehave>(cache, names, "Symbol Behavior Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                return;
            }
            obj[0] = FlatBufferConverter.SerializeFrom(root);

            void Randomize()
            {
                var mode = altRand
                    ? "WaterDash"  // Sharpedo dash homing -- good luck running!
                    : "Anawohoru"; // Diglett - Disappear when approached, pop out elsewhere

                foreach (var t in root.Table)
                {
                    t.Behavior = mode;
                }
            }
        }
Пример #4
0
        public void EditRaidRewards()
        {
            IFileContainer fp         = ROM.GetFile(GameFile.NestData);
            var            data_table = new GFPack(fp[0]);
            const string   nest       = "nest_hole_drop_rewards.bin";

            byte[] originalData = data_table.GetDataFileName(nest);
            var    nest_drops   = FlatBufferConverter.DeserializeFrom <NestHoleReward8Archive>(originalData);

            var arr   = nest_drops.Tables;
            var cache = new DataCache <NestHoleReward8Table>(arr);
            var names = arr.Select((z, i) => $"{z.TableID}").ToArray();

            using var form = new GenericEditor <NestHoleReward8Table>(cache, names, "Raid Rewards");
            form.ShowDialog();
            if (!form.Modified)
            {
                return;
            }

            var data = FlatBufferConverter.SerializeFrom(nest_drops);

            data_table.SetDataFileName(nest, data);
            fp[0] = data_table.Write();
        }
Пример #5
0
        private void PopWildEdit(string file)
        {
            IFileContainer fp         = ROM.GetFile(GameFile.NestData);
            var            data_table = new GFPack(fp[0]);
            var            sdo        = data_table.GetDataFileName($"encount_symbol_{file}.bin");
            var            hdo        = data_table.GetDataFileName($"encount_{file}.bin");
            var            s          = FlatBufferConverter.DeserializeFrom <EncounterArchive8>(sdo);
            var            h          = FlatBufferConverter.DeserializeFrom <EncounterArchive8>(hdo);

            while (s.EncounterTables[0].SubTables.Length != 9)
            {
                s = FlatBufferConverter.DeserializeFrom <EncounterArchive8>(sdo);
                h = FlatBufferConverter.DeserializeFrom <EncounterArchive8>(hdo);
            }

            using var form = new SSWE(ROM, s, h);
            form.ShowDialog();
            if (!form.Modified)
            {
                return;
            }

            var sd = FlatBufferConverter.SerializeFrom(s);
            var hd = FlatBufferConverter.SerializeFrom(h);

            data_table.SetDataFileName($"encount_symbol_{file}.bin", sd);
            data_table.SetDataFileName($"encount_{file}.bin", hd);

            fp[0] = data_table.Write();
        }
Пример #6
0
    public void EditHa_Shop_Data()
    {
        var names  = ROM.GetStrings(TextName.ItemNames);
        var data   = ROM.GetFile(GameFile.HaShop);
        var obj    = FlatBufferConverter.DeserializeFrom <HaShopTable8a>(data[0]);
        var result = PopFlat(obj.Table, "ha_shop_data Editor", z => names[z.ItemID], Randomize);

        if (!result)
        {
            return;
        }

        void Randomize()
        {
            foreach (var t in obj.Table)
            {
                if (Legal.Pouch_Recipe_LA.Contains((ushort)t.ItemID)) // preserve recipes
                {
                    continue;
                }
                t.ItemID = Legal.Pouch_Items_LA[Randomization.Util.Random.Next(Legal.Pouch_Items_LA.Length)];
            }
        }

        data[0] = FlatBufferConverter.SerializeFrom(obj);
    }
Пример #7
0
        public void EditRBonusRewards()
        {
            IFileContainer fp         = ROM.GetFile(GameFile.NestData);
            var            data_table = new GFPack(fp[0]);
            const string   nest       = "nest_hole_bonus_rewards.bin";
            var            nest_bonus = FlatBufferConverter.DeserializeFrom <NestHoleReward8Archive>(data_table.GetDataFileName(nest));

            var arr   = nest_bonus.Table;
            var cache = new DataCache <NestHoleReward8Table>(arr);
            var names = arr.Select(z => $"{z.TableID}").ToArray();

            void Randomize()
            {
                int[] PossibleHeldItems = Legal.GetRandomItemList(ROM.Info.Game);
                foreach (var t in arr)
                {
                    foreach (var i in t.Entries)
                    {
                        i.ItemID = (uint)PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)];
                    }
                }
            }

            using var form = new GenericEditor <NestHoleReward8Table>(cache, names, "Raid Bonus Rewards Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                return;
            }
            var data = FlatBufferConverter.SerializeFrom(nest_bonus);

            data_table.SetDataFileName(nest, data);
            fp[0] = data_table.Write();
        }
Пример #8
0
        public void EditStatic()
        {
            var arc  = ROM.GetFile(GameFile.EncounterStatic);
            var data = arc[0];
            var objs = FlatBufferConverter.DeserializeFrom <EncounterStatic8Archive>(data);

            var encounters = objs.Table;
            var names      = Enumerable.Range(0, encounters.Length).Select(z => $"{z:000}").ToArray();
            var cache      = new DirectCache <EncounterStatic8>(encounters);

            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 encounters)
                {
                    if (t.Species >= (int)Species.Zacian && t.Species <= (int)Species.Eternatus) // Eternatus crashes when changed, keep Zacian and Zamazenta to make final boss battle fair
                    {
                        continue;
                    }
                    t.Species   = srand.GetRandomSpecies(t.Species);
                    t.Form      = (byte)frand.GetRandomForme(t.Species, false, false, true, true, ROM.Data.PersonalData.Table);
                    t.Ability   = Randomization.Util.Random.Next(1, 4); // 1, 2, or H
                    t.HeldItem  = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)];
                    t.Nature    = (int)Nature.Random25;
                    t.Gender    = (int)FixedGender.Random;
                    t.ShinyLock = (int)Shiny.Random;
                    t.Moves     = new[] { 0, 0, 0, 0 };
                    if (t.IV_HP != -4 && t.IVs.Any(z => z != 31))
                    {
                        t.IVs = new[] { -1, -1, -1, -1, -1, -1 }
                    }
                    ;
                }
            }

            using var form = new GenericEditor <EncounterStatic8>(cache, names, "Static Encounter Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                arc.CancelEdits();
            }
            else
            {
                arc[0] = FlatBufferConverter.SerializeFrom(objs);
            }
        }
Пример #9
0
    private T2[] TryRead <T1, T2>(string path) where T1 : class, IFlatBufferArchive <T2> where T2 : class
    {
        var index = Resident.GetIndexFull(path);

        if (index == -1)
        {
            return(Array.Empty <T2>());
        }

        var data = Resident[index];

        return(FlatBufferConverter.DeserializeFrom <T1>(data).Table);
    }
Пример #10
0
    public void EditStatic()
    {
        var names   = ROM.GetStrings(TextName.SpeciesNames);
        var obj     = ROM.GetFile(GameFile.EncounterStatic);
        var data    = obj[0];
        var root    = FlatBufferConverter.DeserializeFrom <EventEncount8aArchive>(data);
        var entries = root.Table;
        var result  = PopFlat(entries, "Static Encounter Editor", z => $"{z.EncounterName} ({GetDetail(z, names)})", () => Randomize(entries));

        if (result)
        {
            obj[0] = FlatBufferConverter.SerializeFrom(root);
        }
Пример #11
0
    public void EditArea_Weather()
    {
        var gfp    = (GFPack)ROM.GetFile(GameFile.Resident);
        var data   = gfp[2065];
        var obj    = FlatBufferConverter.DeserializeFrom <AreaWeatherTable8a>(data);
        var result = PopFlat(obj.Table, "Area Weather Editor", z => z.Hash.ToString("X16"));

        if (!result)
        {
            return;
        }
        gfp[2065] = FlatBufferConverter.SerializeFrom(obj);
    }
Пример #12
0
    public void EditMoveShop()
    {
        var names  = ROM.GetStrings(TextName.MoveNames);
        var data   = ROM.GetFile(GameFile.MoveShop);
        var obj    = FlatBufferConverter.DeserializeFrom <MoveShopTable8a>(data[0]);
        var result = PopFlat(obj.Table, "Move Shop Editor", z => names[z.Move]);

        if (!result)
        {
            return;
        }
        data[0] = FlatBufferConverter.SerializeFrom(obj);
    }
Пример #13
0
    public void PopFlat <T1, T2>(GameFile file, string title, Func <T2, string> getName, Action?rand = null, bool canSave = true) where T1 : class, IFlatBufferArchive <T2> where T2 : class
    {
        var obj  = ROM.GetFile(file);
        var data = obj[0];
        var root = FlatBufferConverter.DeserializeFrom <T1>(data);
        var arr  = root.Table;

        if (!PopFlat(arr, title, getName, rand, canSave))
        {
            return;
        }
        obj[0] = FlatBufferConverter.SerializeFrom(root);
    }
Пример #14
0
        public void EditRaids()
        {
            IFileContainer fp            = ROM.GetFile(GameFile.NestData);
            var            data_table    = new GFPack(fp[0]);
            const string   nest          = "nest_hole_encount.bin";
            var            nest_encounts = FlatBufferConverter.DeserializeFrom <EncounterNest8Archive>(data_table.GetDataFileName(nest));

            var arr   = nest_encounts.Table;
            var cache = new DataCache <EncounterNest8Table>(arr);
            var games = new[] { "Sword", "Shield" };
            var names = arr.Select((z, i) => $"{games[z.GameVersion - 1]} - {i / 2}").ToArray();

            void Randomize()
            {
                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 arr)
                {
                    foreach (var p in t.Entries)
                    {
                        p.Species      = srand.GetRandomSpecies(p.Species);
                        p.Form         = frand.GetRandomForme(p.Species, false, false, true, true, ROM.Data.PersonalData.Table);
                        p.Ability      = 4;     // "A4" -- 1, 2, or H
                        p.Gender       = 0;     // random
                        p.IsGigantamax = false; // don't allow gmax flag on non-gmax species
                    }
                }
            }

            using var form = new GenericEditor <EncounterNest8Table>(cache, names, "Max Raid Battles Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                return;
            }
            var data = FlatBufferConverter.SerializeFrom(nest_encounts);

            data_table.SetDataFileName(nest, data);
            fp[0] = data_table.Write();
        }
Пример #15
0
        private void PopWildEdit(GameFile type)
        {
            var file = ROM.GetFile(type);
            var data = file[0];
            var obj  = FlatBufferConverter.DeserializeFrom <EncounterArchive7b>(data);

            using var form = new GGWE(ROM, obj);
            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            data    = FlatBufferConverter.SerializeFrom(obj);
            file[0] = data;
        }
Пример #16
0
        private void PopWildEdit(string file)
        {
            var winner = Path.Combine(ROM.PathRomFS, "bin", "field", "param", "encount", file);
            var obj    = FlatBufferConverter.DeserializeFrom <EncounterArchive7b>(winner);

            using var form = new GGWE(ROM, obj);
            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var data = FlatBufferConverter.SerializeFrom(obj);

            FileMitm.WriteAllBytes(winner, data);
        }
Пример #17
0
        private bool CreateGenericEditor <TA, T1>(ref byte[] data, string title, string[] names = null) where TA : IFlatBufferArchive <T1> where T1 : class
        {
            var objs = FlatBufferConverter.DeserializeFrom <TA>(data);

            if (names == null)
            {
                names = Enumerable.Range(1, objs.Table.Length).Select(z => z.ToString()).ToArray();
            }
            var result = PopEdit(objs.Table, title, names);

            if (result)
            {
                data = FlatBufferConverter.SerializeFrom(objs);
            }
            return(result);
        }
Пример #18
0
        public void EditRental()
        {
            var obj     = ROM[GameFile.Rentals];
            var data    = obj[0];
            var rentals = FlatBufferConverter.DeserializeFrom <Rental8Archive>(data);
            var cache   = new DataCache <Rental8>(rentals.Table);
            var names   = rentals.Table.Select((z, i) => $"{i:000} {z.Hash1:X16}").ToArray();

            using var form = new GenericEditor <Rental8>(cache, names, "Rental Editor");
            form.ShowDialog();
            if (!form.Modified)
            {
                cache.CancelEdits();
                return;
            }
            obj[0] = FlatBufferConverter.SerializeFrom(rentals);
        }
Пример #19
0
        public void EditPlacement()
        {
            var arc        = ROM.GetFile(GameFile.Placement);
            var placement  = new GFPack(arc[0]);
            var area_names = new AHTB(placement.GetDataFileName("AreaNameHashTable.tbl")).ToDictionary();

            List <PlacementArea8Archive> areas = new();
            List <string> names = new();

            foreach (var area in area_names)
            {
                var areaName = area.Value;
                var fileName = $"{areaName}.bin";
                if (placement.GetIndexFileName(fileName) < 0)
                {
                    continue;
                }

                var bin  = placement.GetDataFileName(fileName);
                var data = FlatBufferConverter.DeserializeFrom <PlacementArea8Archive>(bin);

                names.Add(fileName);
                areas.Add(data);
            }

            var arr     = areas.ToArray();
            var nameArr = names.ToArray();
            var cache   = new DataCache <PlacementArea8Archive>(arr);
            var form    = new GenericEditor <PlacementArea8Archive>(cache, nameArr, "Placement", canSave: true);

            form.ShowDialog();
            if (!form.Modified)
            {
                return;
            }

            // Stuff files back into the gfpak and save
            for (int i = 0; i < arr.Length; i++)
            {
                var obj = arr[i];
                var bin = FlatBufferConverter.SerializeFrom(obj);
                placement.SetDataFileName(nameArr[i], bin);
            }
            arc[0] = placement.Write();
        }
Пример #20
0
        private void PopWildEdit(string file)
        {
            IFileContainer fp         = ROM.GetFile(GameFile.NestData);
            var            data_table = new GFPack(fp[0]);
            var            s          = FlatBufferConverter.DeserializeFrom <EncounterArchive8>(data_table.GetDataFileName($"encount_symbol_{file}.bin"));
            var            h          = FlatBufferConverter.DeserializeFrom <EncounterArchive8>(data_table.GetDataFileName($"encount_{file}.bin"));

            using var form = new SSWE(ROM, s, h);
            form.ShowDialog();

            var sd = FlatBufferConverter.SerializeFrom(s);
            var hd = FlatBufferConverter.SerializeFrom(s);

            data_table.SetDataFileName($"encount_symbol_{file}.bin", sd);
            data_table.SetDataFileName($"encount_{file}.bin", hd);

            fp[0] = data_table.Write();
        }
Пример #21
0
        public void EditDynamaxAdv()
        {
            var arc  = ROM.GetFile(GameFile.DynamaxDens);
            var data = arc[0];
            var objs = FlatBufferConverter.DeserializeFrom <EncounterUnderground8Archive>(data);

            var table = objs.Table;
            var names = Enumerable.Range(0, table.Length).Select(z => $"{z:000}").ToArray();
            var cache = new DirectCache <EncounterUnderground8>(table);

            void Randomize()
            {
                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 table)
                {
                    // what you receive
                    t.Species = srand.GetRandomSpecies(t.Species);
                    t.Form    = (byte)frand.GetRandomForme(t.Species, false, false, true, true, ROM.Data.PersonalData.Table);
                    t.Ability = (uint)Randomization.Util.Random.Next(1, 4); // 1, 2, or H
                    t.Move0   = t.Move1 = t.Move2 = t.Move3 = 0;
                }
            }

            using var form = new GenericEditor <EncounterUnderground8>(cache, names, "Dynamax Adventures Encounter Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                arc.CancelEdits();
            }
            else
            {
                arc[0] = FlatBufferConverter.SerializeFrom(objs);
            }
        }
Пример #22
0
        public MapViewer8a(GameManagerPLA rom, GFPack resident)
        {
            ROM      = rom;
            Resident = resident;
            var bin_settings = resident.GetDataFullPath("bin/field/resident/AreaSettings.bin");

            Settings = FlatBufferConverter.DeserializeFrom <AreaSettingsTable8a>(bin_settings);

            InitializeComponent();

            Areas = ResidentAreaSet.AreaNames.Select(z => AreaInstance8a.Create(Resident, z, Settings)).ToArray();
            var speciesNames = ROM.GetStrings(TextName.SpeciesNames);

            CB_Map.Items.AddRange(Areas.Select(z => z.ParentArea?.AreaName ?? z.AreaName).ToArray());

            var pt       = rom.Data.PersonalData;
            var nameList = new List <ComboItem>();

            foreach (var e in pt.Table.OfType <PersonalInfoLA>())
            {
                if (!e.IsPresentInGame)
                {
                    continue;
                }

                var species = e.Species;
                if (nameList.All(z => z.Value != species))
                {
                    nameList.Add(new(speciesNames[species], species));
                }
            }

            nameList.Insert(0, new("(Any)", -1));
            nameList.Sort((x, y) => string.Compare(x.Text, y.Text, StringComparison.InvariantCulture));

            CB_Species.DisplayMember = nameof(ComboItem.Text);
            CB_Species.ValueMember   = nameof(ComboItem.Value);
            CB_Species.DataSource    = new BindingSource(nameList, null);

            CB_Species.SelectedValue = 399;
            Loading = false;
            CB_Map.SelectedIndex = 0;
        }
Пример #23
0
        private void ResetData()
        {
            var pbin       = this[GameFile.PersonalStats][0];
            var personal   = FlatBufferConverter.DeserializeFrom <PersonalTableLA>(pbin);
            var evos       = this[GameFile.Evolutions][0];
            var evoTable   = FlatBufferConverter.DeserializeFrom <EvolutionTable8>(evos);
            var learn      = this[GameFile.Learnsets][0];
            var learnTable = FlatBufferConverter.DeserializeFrom <Learnset8a>(learn);

            Data = new GameData8a
            {
                // Folders
                MoveData = GetMoves(),

                // Custom
                PersonalData = new PersonalTable(personal.Table.Select(z => new PersonalInfoLA(z)).ToArray(), 905),

                // Single Files
                LevelUpData   = new DataCache <Learnset8aMeta>(learnTable.Table),
                EvolutionData = new DataCache <EvolutionSet8a>(evoTable.Table),
            };
        }
Пример #24
0
        public void EditRaid()
        {
            IFileContainer fp            = ROM.GetFile(GameFile.NestData);
            var            data_table    = new GFPack(fp[0]);
            const string   nest          = "nest_hole_encount.bin";
            var            nest_encounts = FlatBufferConverter.DeserializeFrom <EncounterNest8Archive>(data_table.GetDataFileName(nest));

            var arr   = nest_encounts.Tables;
            var cache = new DataCache <EncounterNest8Table>(arr);
            var games = new[] { "Sword", "Shield" };
            var names = arr.Select((z, i) => $"{games[z.GameVersion - 1]} - {i / 2}").ToArray();

            using var form = new GenericEditor <EncounterNest8Table>(cache, names, "Raid Encounters");
            form.ShowDialog();
            if (!form.Modified)
            {
                return;
            }

            var data = FlatBufferConverter.SerializeFrom(nest_encounts);

            data_table.SetDataFileName(nest, data);
            fp[0] = data_table.Write();
        }
Пример #25
0
        private void EditShop(bool shop2)
        {
            var arc  = ROM.GetFile(GameFile.Shops);
            var data = arc[0];

            int[] PossibleHeldItems = Legal.GetRandomItemList(ROM.Game);
            var   shop = FlatBufferConverter.DeserializeFrom <ShopInventory>(data);

            if (!shop2)
            {
                var table = shop.Shop1;
                var names = table.Select((z, _) => $"{(z.LGPE.TryGetValue(z.Hash, out var shopName) ? shopName : z.Hash.ToString("X"))}").ToArray();
                var cache = new DirectCache <Shop1>(table);
                using var form = new GenericEditor <Shop1>(cache, names, $"{nameof(Shop1)} Editor", Randomize);
                form.ShowDialog();
                if (!form.Modified)
                {
                    arc.CancelEdits();
                    return;
                }

                void Randomize()
                {
                    for (int s = 1; s < table.Length; s++) // skip first table with TMs (unobtainable otherwise)
                    {
                        var shopDefinition = table[s];
                        var items          = shopDefinition.Inventory.Items;
                        for (int i = 0; i < items.Length; i++)
                        {
                            items[i] = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)];
                        }
                    }
                }
            }
            else
            {
                var table = shop.Shop2;
                var names = table.Select((z, _) => $"{(z.LGPE.TryGetValue(z.Hash, out var shopName) ? shopName : z.Hash.ToString("X"))}").ToArray();
                var cache = new DirectCache <Shop2>(table);
                using var form = new GenericEditor <Shop2>(cache, names, $"{nameof(Shop2)} Editor", Randomize);
                form.ShowDialog();
                if (!form.Modified)
                {
                    arc.CancelEdits();
                    return;
                }

                void Randomize()
                {
                    foreach (var shopDefinition in table)
                    {
                        foreach (var inv in shopDefinition.Inventories)
                        {
                            var items = inv.Items;
                            for (int i = 0; i < items.Length; i++)
                            {
                                items[i] = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)];
                            }
                        }
                    }
                }
            }
            arc[0] = FlatBufferConverter.SerializeFrom(shop);
        }
Пример #26
0
        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 and kubfu for other gmax capable species
                    if (t.CanGigantamax || t.Species == (int)Species.Kubfu)
                    {
                        t.Species = Legal.GigantamaxForms[Randomization.Util.Random.Next(Legal.GigantamaxForms.Length)];
                        t.Form    = (byte)(t.Species == (int)Species.Pikachu || t.Species == (int)Species.Meowth ? 0 : frand.GetRandomForme(t.Species, false, false, false, false, ROM.Data.PersonalData.Table)); // Pikachu & Meowth altforms can't gmax
                    }
                    else
                    {
                        t.Species = srand.GetRandomSpecies(t.Species);
                        t.Form    = (byte)frand.GetRandomForme(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, EncounterGift8.BallToItem.Length);
                    t.HeldItem  = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)];
                    t.Nature    = (int)Nature.Random25;
                    t.Gender    = (byte)FixedGender.Random;
                    t.ShinyLock = (int)Shiny.Random;
                    if (t.IV_HP != -4 && t.IVs.Any(z => z != 31))
                    {
                        t.IVs = new[] { -1, -1, -1, -1, -1, -1 }
                    }
                    ;
                }

                UpdateStarters(); // update placement critter data to match new randomized species
            }

            void UpdateStarters()
            {
                var container = ROM.GetFile(GameFile.Placement);
                var placement = new GFPack(container[0]);

                // a_r0501_i0101.bin for Toxel
                // a_bt0101.bin for Type: Null
                // a_wr0201_i0101.bin for Bulbasaur, Squirtle, Porygon, and Kubfu
                // a_wr0301_i0401.bin for Cosmog
                // a_d0901.bin for Poipole
                const string file     = "a_0101.bin";
                var          table    = placement.GetDataFileName(file);
                var          obj      = FlatBufferConverter.DeserializeFrom <PlacementArea8Archive>(table);
                var          critters = obj.Table[0].Critters;

                // Grookey
                critters[3].Species = (uint)gifts[0].Species;
                critters[3].Form    = gifts[0].Form;

                // Scorbunny
                critters[1].Species = (uint)gifts[3].Species;
                critters[1].Form    = gifts[3].Form;

                // Sobble
                critters[2].Species = (uint)gifts[4].Species;
                critters[2].Form    = gifts[4].Form;

                var bin = FlatBufferConverter.SerializeFrom(obj);

                placement.SetDataFileName(file, bin);
                container[0] = placement.Write();
            }

            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);
            }
        }
Пример #27
0
        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 and kubfu for other gmax capable species
                    if (t.CanGigantamax || t.Species == Species.Kubfu)
                    {
                        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);
            }
        }