Esempio n. 1
0
        public SAV_Trainer8(SaveFile sav)
        {
            InitializeComponent();
            WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
            SAV     = (SAV8)(Origin = sav).Clone();
            Loading = true;
            if (Main.Unicode)
            {
                try { TB_OTName.Font = FontUtil.GetPKXFont(11); }
                catch (Exception e) { WinFormsUtil.Alert("Font loading failed...", e.ToString()); }
            }

            B_MaxCash.Click += (sender, e) => MT_Money.Text = SAV.MaxMoney.ToString();

            CB_Gender.Items.Clear();
            CB_Gender.Items.AddRange(Main.GenderSymbols.Take(2).ToArray()); // m/f depending on unicode selection

            TrainerStats.LoadRecords(SAV, Records.RecordList_8);
            TrainerStats.GetToolTipText = UpdateTip;

            GetComboBoxes();
            GetTextBoxes();

            Loading = false;
        }
        private async Task DoSeededEncounter(CancellationToken token, EncounterType type)
        {
            SAV8 sav = await GetFakeTrainerSAV(token).ConfigureAwait(false);

            while (!token.IsCancellationRequested)
            {
                var pkm = await ReadOwPokemon(ZOwOffset, sav, token).ConfigureAwait(false);

                if (pkm == null)
                {
                    await RerollSeedEncounter(token).ConfigureAwait(false);
                }
                else
                {
                    if (await HandleEncounter(pkm, true, token).ConfigureAwait(false))
                    {
                        return;
                    }
                    else
                    {
                        await RerollSeedEncounter(token).ConfigureAwait(false);
                    }
                }
            }
        }
Esempio n. 3
0
        public SAV_PokedexSWSH(SaveFile sav)
        {
            InitializeComponent();
            WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
            SAV = (SAV8)(Origin = sav).Clone();
            Dex = SAV.Zukan;
            CP  = new[] { CHK_P1, CHK_P2, CHK_P3, CHK_P4, CHK_P5, CHK_P6, CHK_P7, CHK_P8, CHK_P9, };
            CL  = new[] { CHK_L1, CHK_L2, CHK_L3, CHK_L4, CHK_L5, CHK_L6, CHK_L7, CHK_L8, CHK_L9, };

            editing = true;
            // Clear Listbox and ComboBox
            LB_Species.Items.Clear();
            CB_Species.Items.Clear();
            LB_Forms.Items.Clear();

            // Fill List
            CB_Species.InitializeBinding();
            CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), null);

            var Species = GameInfo.Strings.Species;
            var names   = Dex.GetEntryNames(Species);

            foreach (var n in names)
            {
                LB_Species.Items.Add(n);
            }

            editing = false;
            LB_Species.SelectedIndex = 0;
            CB_Species.KeyDown      += WinFormsUtil.RemoveDropCB;
        }
        public async Task <List <PK8> > ReadOwPokemonFromBlock(byte[] KCoordinates, SAV8 sav, CancellationToken token)
        {
            List <PK8> PK8s = new List <PK8>();

            int i          = 8;
            int j          = 0;
            int last_index = 8;
            int count      = 0;

            while (!token.IsCancellationRequested && i < KCoordinates.Length)
            {
                //If someone finds a better way to run through the block and find the spawns, feel free to improve this function.
                if (j == 12)
                {
                    if (KCoordinates[i - 68] != 0 && KCoordinates[i - 68] != 255)
                    {
                        byte[] Bytes = KCoordinates.Slice(i - 68, 56);
                        j          = 0;
                        i          = last_index + 8;
                        last_index = i;
                        count++;
                        var pkm = await ReadOwPokemon(0, 0, Bytes, sav, token).ConfigureAwait(false);

                        if (pkm != null)
                        {
                            PK8s.Add(pkm);
                        }
                    }
                }

                if (KCoordinates[i] == 255)
                {
                    if (i % 8 == 0)
                    {
                        last_index = i;
                    }
                    i++;
                    j++;
                }
                else
                {
                    j = 0;
                    if (i == last_index)
                    {
                        i         += 8;
                        last_index = i;
                    }
                    else
                    {
                        i          = last_index + 8;
                        last_index = i;
                    }
                }
            }
            return(PK8s);
        }
Esempio n. 5
0
        private async Task DoSeededEncounter(CancellationToken token)
        {
            ScanMode type = Hub.Config.SWSH_OverworldScan.EncounteringType;
            SAV8     sav  = await GetFakeTrainerSAV(token).ConfigureAwait(false);

            Species dexn   = 0;
            uint    offset = 0x00;

            if (type == ScanMode.G_Articuno)
            {
                dexn   = (Species)144;
                offset = CrownTundraSnowslideSlopeSpawns;
            }
            else if (type == ScanMode.G_Zapdos)
            {
                dexn   = (Species)145;
                offset = WildAreaMotostokeSpawns;
            }
            else if (type == ScanMode.G_Moltres)
            {
                dexn   = (Species)146;
                offset = IsleOfArmorStationSpaws;
            }
            else if (type == ScanMode.IoA_Wailord)
            {
                dexn   = (Species)321;
                offset = IsleOfArmorStationSpaws;
            }

            while (!token.IsCancellationRequested && offset != 0)
            {
                var pkm = await ReadOwPokemon(dexn, offset, null, sav, token).ConfigureAwait(false);

                if (pkm != null && await HandleEncounter(pkm, IsPKLegendary(pkm.Species), token).ConfigureAwait(false))
                {
                    await Click(X, 2_000, token).ConfigureAwait(false);
                    await Click(R, 2_000, token).ConfigureAwait(false);
                    await Click(A, 5_000, token).ConfigureAwait(false);
                    await Click(X, 2_000, token).ConfigureAwait(false);

                    Log($"The overworld encounter has been found. The progresses has been saved and the game is paused, you can now go and catch {SpeciesName.GetSpeciesName((int)dexn, 2)}");
                    return;
                }
                else
                {
                    await FlyToRerollSeed(token).ConfigureAwait(false);
                }
            }
        }
        private async Task Overworld(CancellationToken token)
        {
            await ResetStick(token).ConfigureAwait(false);

            SAV8 sav = await GetFakeTrainerSAV(token).ConfigureAwait(false);

            List <int[]> movementslist = ParseMovements();

            byte[]     KCoordinates;
            List <PK8> PK8s;

            while (!token.IsCancellationRequested)
            {
                KCoordinates = await ReadKCoordinates(token).ConfigureAwait(false);

                PK8s = await ReadOwPokemonFromBlock(KCoordinates, sav, token).ConfigureAwait(false);

                if (PK8s.Count > 0)
                {
                    foreach (PK8 pkm in PK8s)
                    {
                        //Log($"{(Species)pkm.Species}");
                        if (await LogPKMs(pkm, IsPKLegendary(pkm.Species), token).ConfigureAwait(false))
                        {
                            //Save the game to update KCoordinates block
                            if (!await IsInBattle(token).ConfigureAwait(false))
                            {
                                await Click(X, 2_000, token).ConfigureAwait(false);
                                await Click(R, 2_000, token).ConfigureAwait(false);
                                await Click(A, 5_000, token).ConfigureAwait(false);
                                await Click(X, 2_000, token).ConfigureAwait(false);
                            }
                            return;
                        }
                    }
                }
                else
                {
                    Log("Empty list, no overworld data in KCoordinates!");
                }

                //Check if encountered an unwanted pokemon
                if (await IsInBattle(token).ConfigureAwait(false))
                {
                    // Offsets are flickery so make sure we see it 3 times.
                    for (int i = 0; i < 3; i++)
                    {
                        await ReadUntilChanged(BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false);
                    }
                    Log("Unwanted encounter started, running away...");
                    await FleeToOverworld(token).ConfigureAwait(false);

                    // Extra delay to be sure we're fully out of the battle.
                    await Task.Delay(0_250, token).ConfigureAwait(false);
                }
                else
                {
                    if (Hub.Config.SWSH_OverworldScan.GetOnOffBike)
                    {
                        await Click(PLUS, 0_600, token).ConfigureAwait(false);
                        await Click(PLUS, 5_500, token).ConfigureAwait(false);
                    }

                    //Movements/Delay/Actions routines
                    if (Hub.Config.SWSH_OverworldScan.WaitMsBeforeSave > 0)
                    {
                        await Task.Delay(Hub.Config.SWSH_OverworldScan.WaitMsBeforeSave, token).ConfigureAwait(false);
                    }

                    foreach (int[] move in movementslist)
                    {
                        await ResetStick(token).ConfigureAwait(false);
                        await SetStick(LEFT, (short)(move[0]), (short)(move[1]), move[2], token).ConfigureAwait(false);

                        //Check again is a wild encounter popped up while moving
                        if (await IsInBattle(token).ConfigureAwait(false))
                        {
                            await ResetStick(token).ConfigureAwait(false);

                            for (int i = 0; i < 3; i++)
                            {
                                await ReadUntilChanged(BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false);
                            }
                            Log("Unwanted encounter started, running away...");
                            await FleeToOverworld(token).ConfigureAwait(false);

                            await Task.Delay(0_250, token).ConfigureAwait(false);
                        }
                        await ResetStick(token).ConfigureAwait(false);
                    }

                    //Save the game to update KCoordinates block
                    await Click(X, 2_000, token).ConfigureAwait(false);
                    await Click(R, 2_000, token).ConfigureAwait(false);
                    await Click(A, 5_000, token).ConfigureAwait(false);

                    Log("Game saved, reading new details...");
                }
            }
        }
        public async Task <PK8?> ReadOwPokemon(Species target, uint startoffset, byte[]?mondata, SAV8 TrainerData, CancellationToken token)
        {
            byte[]? data = null;
            Species species = 0;
            uint    offset  = startoffset;
            int     i       = 0;

            if (target != (Species)0)
            {
                do
                {
                    data = await Connection.ReadBytesAsync(offset, 56, token).ConfigureAwait(false);

                    species = (Species)BitConverter.ToUInt16(data.Slice(0, 2), 0);
                    offset += 192;
                    i++;
                } while (target != 0 && species != 0 && target != species && i <= 40);
                if (i > 40)
                {
                    data = null;
                }
            }
            else if (mondata != null)
            {
                data    = mondata;
                species = (Species)BitConverter.ToUInt16(data.Slice(0, 2), 0);
            }

            if (data != null && data[20] == 1)
            {
                PK8 pk = new PK8
                {
                    Species      = (int)species,
                    Form         = data[2],
                    CurrentLevel = data[4],
                    Met_Level    = data[4],
                    Gender       = (data[10] == 1) ? 0 : 1,
                    OT_Name      = TrainerData.OT,
                    TID          = TrainerData.TID,
                    SID          = TrainerData.SID,
                    OT_Gender    = TrainerData.Gender,
                    HT_Name      = TrainerData.OT,
                    HT_Gender    = TrainerData.Gender,
                    Move1        = BitConverter.ToUInt16(data.Slice(48, 2), 0),
                    Move2        = BitConverter.ToUInt16(data.Slice(50, 2), 0),
                    Move3        = BitConverter.ToUInt16(data.Slice(52, 2), 0),
                    Move4        = BitConverter.ToUInt16(data.Slice(54, 2), 0),
                    Version      = 44,
                };
                pk.SetNature(data[8]);
                pk.SetAbility(data[12] - 1);
                if (data[22] != 255)
                {
                    pk.SetRibbonIndex((RibbonIndex)data[22]);
                }
                if (!pk.IsGenderValid())
                {
                    pk.Gender = 2;
                }
                if (data[14] == 1)
                {
                    pk.HeldItem = data[16];
                }

                Shiny shinyness = (Shiny)(data[6] + 1);
                int   ivs       = data[18];
                uint  seed      = BitConverter.ToUInt32(data.Slice(24, 4), 0);

                pk = OverworldSWSHRNG.CalculateFromSeed(pk, shinyness, ivs, seed);
                return(pk);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 8
0
        public async Task <PK8?> ReadOwPokemon(uint offset, SAV8 TrainerData, CancellationToken token)
        {
            byte[] data = await Connection.ReadBytesAsync(offset, 56, token).ConfigureAwait(false);

            Log("RAM data: " + BitConverter.ToString(data));

            if (data[20] == 1)
            {
                PK8?pk = new PK8
                {
                    Species      = BitConverter.ToUInt16(data.Slice(0, 2), 0),
                    Form         = data[2],
                    CurrentLevel = data[4],
                    Met_Level    = data[4],
                    Gender       = (data[10] == 1) ? 0 : 1,
                    OT_Name      = TrainerData.OT,
                    TID          = TrainerData.TID,
                    SID          = TrainerData.SID,
                    TrainerID7   = TrainerData.TrainerID7,
                    TrainerSID7  = TrainerData.TrainerSID7,
                    OT_Gender    = TrainerData.Gender,
                    HT_Name      = TrainerData.OT,
                    HT_Gender    = TrainerData.Gender,
                    Move1        = BitConverter.ToUInt16(data.Slice(48, 2), 0),
                    Move2        = BitConverter.ToUInt16(data.Slice(50, 2), 0),
                    Move3        = BitConverter.ToUInt16(data.Slice(52, 2), 0),
                    Move4        = BitConverter.ToUInt16(data.Slice(54, 2), 0),
                };
                pk.SetNature(data[8]);
                pk.SetAbility(data[12] - 1);
                if (data[22] != 255)
                {
                    pk.SetRibbonIndex((RibbonIndex)data[22]);
                }
                if (!pk.IsGenderValid())
                {
                    pk.Gender = 2;
                }
                if (data[14] == 1)
                {
                    pk.HeldItem = data[16];
                }

                Shiny shinyness = (Shiny)(data[6] + 1);
                int   ivs       = data[18];
                uint  seed      = BitConverter.ToUInt32(data.Slice(24, 4), 0);

                Log($"Stats in RAM: Shinyness {shinyness}, IVs {ivs}, Seed: {String.Format("{0:X}", seed)}");

                pk = Overworld8RNG.CalculateFromSeed(pk, shinyness, ivs, seed);
                if (pk != null)
                {
                    return(pk);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 9
0
 public BoxLayout8(SAV8 sav, int offset) : base(sav) => Offset = offset;
Esempio n. 10
0
 public Party8(SAV8 sav, SCBlock block) : base(sav, block.Data)
 {
 }