public static void Gen345Shiny(this PKM pkm, Shiny type)
        {
            bool flag = pkm.IsEgg || pkm.WasEgg || pkm.Met_Level <= 1;

            if (flag)
            {
                pkm.SetPIDGender(pkm.Gender);
                CommonEdits.SetShiny(pkm, type);
                return;
            }

            if (pkm.Format == 3)
            {
                pkm.Gen3Shiny(type);
            }
            if (pkm.Format == 4)
            {
                pkm.Gen4Shiny(type);
            }
            if (pkm.Format == 5)
            {
                pkm.Gen5Shiny(type);
            }

            SetBasicData(pkm);
        }
Esempio n. 2
0
        private void LoadExtraInstructions(List <string> lines)
        {
            for (var i = 0; i < lines.Count; i++)
            {
                var line  = lines[i];
                var split = line.Split(ExtraSplitter, 0);
                if (split.Length != 2)
                {
                    continue;
                }
                var type  = split[0];
                var value = split[1];

                switch (type)
                {
                case "Ball":
                    Ball = Aesthetics.GetBallFromString(value);
                    break;

                case "Shiny":
                    ShinyType = Aesthetics.GetShinyType(value);
                    if (ShinyType != Core.Shiny.Random)
                    {
                        Shiny = ShinyType != Core.Shiny.Never;
                    }
                    break;

                default:
                    continue;
                }
                // Remove from lines
                lines.RemoveAt(i--);
            }
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (Costume != 0)
            {
                hash ^= Costume.GetHashCode();
            }
            if (Gender != 0)
            {
                hash ^= Gender.GetHashCode();
            }
            if (Shiny != false)
            {
                hash ^= Shiny.GetHashCode();
            }
            if (Form != 0)
            {
                hash ^= Form.GetHashCode();
            }
            if (WeatherBoostedCondition != 0)
            {
                hash ^= WeatherBoostedCondition.GetHashCode();
            }
            return(hash);
        }
Esempio n. 4
0
        public static void ApplyDetails(PKM pk, EncounterCriteria criteria, Shiny shiny = Shiny.FixedValue, int flawless = -1)
        {
            if (shiny == Shiny.FixedValue)
            {
                shiny = criteria.Shiny is Shiny.Random or Shiny.Never ? Shiny.Never : Shiny.Always;
            }
            if (flawless == -1)
            {
                flawless = 0;
            }

            int       ctr         = 0;
            const int maxAttempts = 50_000;
            var       rnd         = Util.Rand;

            do
            {
                ulong s0   = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
                ulong s1   = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
                var   xors = new XorShift128(s0, s1);
                if (TryApplyFromSeed(pk, criteria, shiny, flawless, xors))
                {
                    return;
                }
            } while (++ctr != maxAttempts);

            {
                ulong s0   = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
                ulong s1   = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
                var   xors = new XorShift128(s0, s1);
                TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, xors);
            }
        }
        public static void Gen4Shiny(this PKM pkm, Shiny shinyType)
        {
            if (pkm.GenNumber == 3)
            {
                if (pkm.Met_Location == 55 && pkm.Ball == 4)
                {
                    pkm.SetPIDGender(pkm.Gender);
                    CommonEdits.SetShiny(pkm, shinyType);
                    return;
                }
                Gen3Shiny(pkm, shinyType);
                return;
            }

            RNG     rng  = RNG.LCRNG;
            PIDType type = PIDType.Method_1;

            if (pkm.Met_Location == 233)
            {
                type = PIDType.Pokewalker;
            }

            IEnumerable <uint> seeds;

            do
            {
                pkm.SetPIDGender(pkm.Gender);
                CommonEdits.SetShiny(pkm, shinyType);
                seeds = GetSeedsFromPID(pkm.PID, rng);
            } while (!pkm.IsShiny || seeds == null);

            PIDGenerator.SetValuesFromSeed(pkm, type, seeds.ElementAt(0));
        }
Esempio n. 6
0
        public static void ApplyDetails(PKM pk, EncounterCriteria criteria, Shiny shiny = Shiny.FixedValue, int flawless = -1)
        {
            if (shiny == Shiny.FixedValue)
            {
                shiny = criteria.Shiny is Shiny.Random or Shiny.Never ? Shiny.Never : Shiny.Always;
            }
            if (flawless == -1)
            {
                flawless = 0;
            }

            int       ctr         = 0;
            const int maxAttempts = 50_000;
            var       rnd         = Util.Rand;

            do
            {
                var seed = rnd.Rand32();
                if (TryApplyFromSeed(pk, criteria, shiny, flawless, seed))
                {
                    return;
                }
            } while (++ctr != maxAttempts);
            TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, rnd.Rand32());
        }
Esempio n. 7
0
        private static bool IsPIDValid(PKM pk, uint pid, Shiny shiny)
        {
            if (shiny == Shiny.Random)
            {
                return(pid == pk.PID);
            }

            if (pid == pk.PID)
            {
                return(true);
            }

            // Check forced shiny
            if (pk.IsShiny)
            {
                if (GetIsShiny(pk.TID, pk.SID, pid))
                {
                    return(false);
                }

                pid = GetShinyPID(pk.TID, pk.SID, pid, 0);
                return(pid == pk.PID);
            }

            // Check forced non-shiny
            if (!GetIsShiny(pk.TID, pk.SID, pid))
            {
                return(false);
            }

            pid ^= 0x1000_0000;
            return(pid == pk.PID);
        }
Esempio n. 8
0
        public static bool ValidateOverworldEncounter(PKM pk, uint seed, Shiny shiny = Shiny.FixedValue, int flawless = -1)
        {
            // is the seed Xoroshiro determined, or just truncated state?
            if (seed == uint.MaxValue)
            {
                return(false);
            }

            var xoro = new Xoroshiro128Plus(seed);
            var ec   = (uint)xoro.NextInt(uint.MaxValue);

            if (ec != pk.EncryptionConstant)
            {
                return(false);
            }

            var pid = (uint)xoro.NextInt(uint.MaxValue);

            if (!IsPIDValid(pk, pid, shiny))
            {
                return(false);
            }

            var actualCount = flawless == -1 ? GetIsMatchEnd(pk, xoro) : GetIsMatchEnd(pk, xoro, flawless, flawless);

            return(actualCount != NoMatchIVs);
        }
Esempio n. 9
0
 public static bool IsValid(this Shiny s, PKM pkm)
 {
     return(s switch
     {
         Shiny.Always => pkm.IsShiny,
         Shiny.Never => !pkm.IsShiny,
         _ => true
     });
Esempio n. 10
0
 public RegenSet(ICollection <string> lines, int format, Shiny shiny = Shiny.Never)
 {
     Extra = new RegenSetting {
         ShinyType = shiny
     };
     HasExtraSettings   = Extra.SetRegenSettings(lines);
     HasTrainerSettings = RegenUtil.GetTrainerInfo(lines, format, out var tr);
     Trainer            = tr;
     Batch = new StringInstructionSet(lines);
 }
Esempio n. 11
0
 public static bool IsValid(this Shiny s, PKM pkm)
 {
     return(s switch
     {
         Shiny.Always => pkm.IsShiny,
         Shiny.Never => !pkm.IsShiny,
         Shiny.AlwaysSquare => pkm.ShinyXor == 0,
         Shiny.AlwaysStar => pkm.ShinyXor == 1,
         _ => true
     });
Esempio n. 12
0
        public EncounterSlot7GO(EncounterArea7g area, int species, int form, Shiny shiny, PogoType type) : base(area)
        {
            Species  = species;
            Form     = form;
            LevelMin = type.GetMinLevel();
            LevelMax = EncountersGO.MAX_LEVEL;

            Shiny = shiny;
            Type  = type;
        }
Esempio n. 13
0
        protected EncounterSlotGO(EncounterArea area, int start, int end, Shiny shiny, PogoType type) : base(area)
        {
            LevelMin = type.GetMinLevel();
            LevelMax = EncountersGO.MAX_LEVEL;

            Start = start;
            End   = end;

            Shiny = shiny;
            Type  = type;
        }
Esempio n. 14
0
        public static bool IsValid(this Shiny s, PKM pkm)
        {
            switch (s)
            {
            case Shiny.Always: return(pkm.IsShiny);

            case Shiny.Never:  return(!pkm.IsShiny);

            default:
                return(true);
            }
        }
Esempio n. 15
0
        public EncounterSlot8GO(EncounterArea8g area, int species, int form, GameVersion gameVersion, PogoType type, Shiny shiny, int start, int end) : base(area)
        {
            Species  = species;
            Form     = form;
            LevelMin = type.GetMinLevel();
            LevelMax = 40;
            Start    = start;
            End      = end;

            Shiny = shiny;
            Type  = type;

            OriginGroup = gameVersion;
        }
Esempio n. 16
0
 public override int GetHashCode()
 {
     return
         (RGBA.GetHashCode() ^
          RepeatU.GetHashCode() ^
          RepeatV.GetHashCode() ^
          OffsetU.GetHashCode() ^
          OffsetV.GetHashCode() ^
          Rotation.GetHashCode() ^
          Glow.GetHashCode() ^
          Bump.GetHashCode() ^
          Shiny.GetHashCode() ^
          Fullbright.GetHashCode() ^
          MediaFlags.GetHashCode() ^
          TexMapType.GetHashCode() ^
          TextureID.GetHashCode());
 }
Esempio n. 17
0
        protected T RngRoutineSWSH(T pkm, IBattleTemplate template, Shiny shiny)
        {
            if (pkm.Species is (int)Species.Alcremie)
            {
                var data = pkm.Data;
                var deco = (uint)Random.Next(7);
                pkm.ChangeFormArgument(deco);
            }

            var laInit = new LegalityAnalysis(pkm);
            var nature = pkm.Nature;

            pkm.Nature = pkm.Species switch
            {
                (int)Species.Toxtricity => pkm.Form > 0 ? TradeExtensions <PK8> .LowKey[Random.Next(TradeExtensions <PK8> .LowKey.Length)] : TradeExtensions <PK8> .Amped[Random.Next(TradeExtensions <PK8> .Amped.Length)],
                _ => Random.Next(25),
            };
Esempio n. 18
0
 public static uint AdaptPID(PKM pk, Shiny shiny, uint pid)
 {
     if (shiny == Shiny.Never)
     {
         if (GetIsShiny(pk.TID, pk.SID, pid))
         {
             pid ^= 0x1000_0000;
         }
     }
     else if (shiny != Shiny.Random)
     {
         if (!GetIsShiny(pk.TID, pk.SID, pid))
         {
             pid = GetShinyPID(pk.TID, pk.SID, pid, 0);
         }
     }
     return(pid);
 }
Esempio n. 19
0
    public void NewShiny()
    {
        shiny          = Instantiate(shinyPrefab);
        shiny.sceneMan = this;
        for (int i = 0; i < jellies.Count; i++)
        {
            jellies[i].target = shiny;
        }
        //keep location somewhat nearby flock so they can possibly reach it
        float randX;
        float randZ;

        if (flockCenter.transform.position.x > 700)
        {
            randX = flockCenter.transform.position.x - Random.Range(50, 150);
        }
        else if (flockCenter.transform.position.x < 100)
        {
            randX = flockCenter.transform.position.x + Random.Range(50, 150);
        }
        else
        {
            randX = flockCenter.transform.position.x + Random.Range(-100, 150);
        }
        if (flockCenter.transform.position.z > 700)
        {
            randZ = flockCenter.transform.position.z - Random.Range(50, 150);
        }
        else if (flockCenter.transform.position.z < 100)
        {
            randZ = flockCenter.transform.position.z + Random.Range(50, 150);
        }
        else
        {
            randZ = flockCenter.transform.position.z + Random.Range(-100, 150);
        }

        //check terrainheight at random location and set y accordingly
        float terrainHeight = Terrain.activeTerrain.SampleHeight(new Vector3(randX, 0f, randZ));

        shiny.transform.position = new Vector3(randX, terrainHeight + 100f, randZ);
    }
Esempio n. 20
0
        public static void Gen3Shiny(this PKM pkm, Shiny shinyType)
        {
            RNG     rng  = RNG.LCRNG;
            PIDType type = PIDType.Method_1;

            if (pkm.Species == 201)
            {
                type = PIDType.Method_1_Unown;
            }

            IEnumerable <uint> seeds;

            do
            {
                pkm.SetPIDGender(pkm.Gender);
                CommonEdits.SetShiny(pkm, shinyType);
                seeds = GetSeedsFromPID(pkm.PID, rng);
            } while (!pkm.IsShiny || seeds == null);

            PIDGenerator.SetValuesFromSeed(pkm, type, seeds.ElementAt(0));
        }
Esempio n. 21
0
        public static bool ValidateOverworldEncounter(PKM pk, Shiny shiny = Shiny.FixedValue, int flawless = -1)
        {
            var seed = GetOriginalSeed(pk);

            return(ValidateOverworldEncounter(pk, seed, shiny, flawless));
        }
Esempio n. 22
0
        public int CompareTo(PogoEntry?p)
        {
            if (p == null)
            {
                return(1);
            }

            if (p.Start != null)
            {
                if (Start == null)
                {
                    return(1);
                }
                var date = Start.CompareTo(p.Start);
                if (date != 0)
                {
                    return(date);
                }
            }
            else
            {
                if (Start != null)
                {
                    return(-1);
                }
            }

            if (p.End != null)
            {
                if (End == null)
                {
                    return(1);
                }
                var date = End.CompareTo(p.End);
                if (date != 0)
                {
                    return(date);
                }
            }
            else
            {
                if (End != null)
                {
                    return(-1);
                }
            }

            if (Type != p.Type)
            {
                return(Type.CompareTo(p.Type));
            }

            if (Shiny != p.Shiny)
            {
                return(Shiny.CompareTo(p.Shiny));
            }
            if (Gender != p.Gender)
            {
                return(Gender.CompareTo(p.Gender));
            }

            return(string.Compare(Comment, p.Comment, StringComparison.OrdinalIgnoreCase));
        }
Esempio n. 23
0
        public EncounterSlot8GO(EncounterArea8g area, int species, int form, int start, int end, Shiny shiny, PogoType type, GameVersion originGroup)
            : base(area, start, end, shiny, type)
        {
            Species = species;
            Form    = form;

            OriginGroup = originGroup;
        }
Esempio n. 24
0
        public static bool TryApplyFromSeed(PKM pk, EncounterCriteria criteria, Shiny shiny, int flawless, XorShift128 xors, AbilityPermission ability)
        {
            // Encryption Constant
            pk.EncryptionConstant = xors.NextUInt();

            // PID
            var fakeTID = xors.NextUInt(); // fakeTID
            var pid     = xors.NextUInt();

            pid = GetRevisedPID(fakeTID, pid, pk);
            if (shiny == Shiny.Never)
            {
                if (GetIsShiny(pk.TID, pk.SID, pid))
                {
                    return(false);
                }
            }
            else if (shiny != Shiny.Random)
            {
                if (!GetIsShiny(pk.TID, pk.SID, pid))
                {
                    return(false);
                }

                if (shiny == Shiny.AlwaysSquare && pk.ShinyXor != 0)
                {
                    return(false);
                }
                if (shiny == Shiny.AlwaysStar && pk.ShinyXor == 0)
                {
                    return(false);
                }
            }
            pk.PID = pid;

            // Check IVs: Create flawless IVs at random indexes, then the random IVs for not flawless.
            Span <int> ivs        = stackalloc[] { UNSET, UNSET, UNSET, UNSET, UNSET, UNSET };
            const int  MAX        = 31;
            var        determined = 0;

            while (determined < flawless)
            {
                var idx = (int)xors.NextUInt(6);
                if (ivs[idx] != UNSET)
                {
                    continue;
                }
                ivs[idx] = 31;
                determined++;
            }

            for (var i = 0; i < ivs.Length; i++)
            {
                if (ivs[i] == UNSET)
                {
                    ivs[i] = xors.NextInt(0, MAX + 1);
                }
            }

            if (!criteria.IsIVsCompatible(ivs, 8))
            {
                return(false);
            }

            pk.IV_HP  = ivs[0];
            pk.IV_ATK = ivs[1];
            pk.IV_DEF = ivs[2];
            pk.IV_SPA = ivs[3];
            pk.IV_SPD = ivs[4];
            pk.IV_SPE = ivs[5];

            // Ability
            var n = ability switch
            {
                AbilityPermission.Any12 => (int)xors.NextUInt(2),
                AbilityPermission.Any12H => (int)xors.NextUInt(3),
                _ => (int)ability >> 1,
            };

            pk.SetAbilityIndex(n);

            // Gender (skip this if gender is fixed)
            var genderRatio = PersonalTable.BDSP.GetFormEntry(pk.Species, pk.Form).Gender;

            if (genderRatio == PersonalInfo.RatioMagicGenderless)
            {
                pk.Gender = 2;
            }
            else if (genderRatio == PersonalInfo.RatioMagicMale)
            {
                pk.Gender = 0;
            }
            else if (genderRatio == PersonalInfo.RatioMagicFemale)
            {
                pk.Gender = 1;
            }
            else
            {
                var next = (((int)xors.NextUInt(253) + 1 < genderRatio) ? 1 : 0);
                if (criteria.Gender is 0 or 1 && next != criteria.Gender)
                {
                    return(false);
                }
                pk.Gender = next;
            }

            if (criteria.Nature is Nature.Random)
            {
                pk.Nature = (int)xors.NextUInt(25);
            }
            else // Skip nature, assuming Synchronize
            {
                pk.Nature = (int)criteria.Nature;
            }
            pk.StatNature = pk.Nature;

            // Remainder
            var scale = (IScaledSize)pk;

            scale.HeightScalar = (byte)((int)xors.NextUInt(0x81) + (int)xors.NextUInt(0x80));
            scale.WeightScalar = (byte)((int)xors.NextUInt(0x81) + (int)xors.NextUInt(0x80));

            // Item, don't care
            return(true);
        }
        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. 26
0
 public static bool IsValid(this Shiny s, PKM pkm) => s switch
 {
Esempio n. 27
0
 public EncounterSlot7GO(EncounterArea7g area, int species, int form, int start, int end, Shiny shiny, PogoType type)
     : base(area, start, end, shiny, type)
 {
     Species = species;
     Form    = form;
 }
        public static string SetAnalysis(this IBattleTemplate set, ITrainerInfo sav, PKM blank)
        {
            if (blank.Version == 0)
            {
                blank.Version = sav.Game;
            }
            var species_name = SpeciesName.GetSpeciesNameGeneration(set.Species, (int)LanguageID.English, sav.Generation);
            var analysis     = set.Form == 0 ? string.Format(SPECIES_UNAVAILABLE, species_name)
                                     : string.Format(SPECIES_UNAVAILABLE_FORM, species_name, set.FormName);

            // Species checks
            var gv = (GameVersion)sav.Game;

            if (!gv.ExistsInGame(set.Species, set.Form))
            {
                return(analysis); // Species does not exist in the game
            }
            // Species exists -- check if it has at least one move.
            // If it has no moves and it didn't generate, that makes the mon still illegal in game (moves are set to legal ones)
            var moves = set.Moves.Where(z => z != 0).ToArray();
            var count = set.Moves.Count(z => z != 0);

            // Reusable data
            var batchedit = false;
            IReadOnlyList <StringInstruction>?filters = null;

            if (set is RegenTemplate r)
            {
                filters   = r.Regen.Batch.Filters;
                batchedit = APILegality.AllowBatchCommands && r.Regen.HasBatchSettings;
            }
            var destVer = (GameVersion)sav.Game;

            if (destVer <= 0 && sav is SaveFile s)
            {
                destVer = s.Version;
            }
            var gamelist = APILegality.FilteredGameList(blank, destVer, batchedit ? filters : null);

            // Move checks
            List <IEnumerable <int> > move_combinations = new();

            for (int i = count; i >= 1; i--)
            {
                move_combinations.AddRange(GetKCombs(moves, i));
            }

            int[] original_moves = new int[4];
            set.Moves.CopyTo(original_moves, 0);
            int[] successful_combination = GetValidMoves(set, sav, move_combinations, blank, gamelist);
            if (!new HashSet <int>(original_moves.Where(z => z != 0)).SetEquals(successful_combination))
            {
                var invalid_moves = string.Join(", ", original_moves.Where(z => !successful_combination.Contains(z) && z != 0).Select(z => $"{(Move)z}"));
                return(successful_combination.Length > 0 ? string.Format(INVALID_MOVES, species_name, invalid_moves) : ALL_MOVES_INVALID);
            }

            // All moves possible, get encounters
            blank.ApplySetDetails(set);
            blank.SetMoves(original_moves);
            blank.SetRecordFlags(Array.Empty <int>());

            var encounters   = EncounterMovesetGenerator.GenerateEncounters(pk: blank, moves: original_moves, gamelist).ToList();
            var initialcount = encounters.Count;

            if (set is RegenTemplate rt && rt.Regen.EncounterFilters is { } x)
            {
                encounters.RemoveAll(enc => !BatchEditing.IsFilterMatch(x, enc));
            }

            // No available encounters
            if (encounters.Count == 0)
            {
                return(string.Format(EXHAUSTED_ENCOUNTERS, initialcount, initialcount));
            }

            // Level checks, check if level is impossible to achieve
            if (encounters.All(z => !APILegality.IsRequestedLevelValid(set, z)))
            {
                return(string.Format(LEVEL_INVALID, species_name, encounters.Min(z => z.LevelMin)));
            }
            encounters.RemoveAll(enc => !APILegality.IsRequestedLevelValid(set, enc));

            // Shiny checks, check if shiny is impossible to achieve
            Shiny shinytype = set.Shiny ? Shiny.Always : Shiny.Never;

            if (set is RegenTemplate ret && ret.Regen.HasExtraSettings)
            {
                shinytype = ret.Regen.Extra.ShinyType;
            }
            if (encounters.All(z => !APILegality.IsRequestedShinyValid(set, z)))
            {
                return(string.Format(SHINY_INVALID, shinytype));
            }
            encounters.RemoveAll(enc => !APILegality.IsRequestedShinyValid(set, enc));

            // Alpha checks
            if (encounters.All(z => !APILegality.IsRequestedAlphaValid(set, z)))
            {
                return(ALPHA_INVALID);
            }
            encounters.RemoveAll(enc => !APILegality.IsRequestedAlphaValid(set, enc));

            // Ability checks
            var abilityreq = APILegality.GetRequestedAbility(blank, set);

            if (abilityreq == AbilityRequest.NotHidden && encounters.All(z => z is EncounterStatic {
                Ability: AbilityPermission.OnlyHidden
            }))
Esempio n. 29
0
        private static bool TryApplyFromSeed(PKM pk, EncounterCriteria criteria, Shiny shiny, int flawless, uint seed)
        {
            var xoro = new Xoroshiro128Plus(seed);

            // Encryption Constant
            pk.EncryptionConstant = (uint)xoro.NextInt(uint.MaxValue);

            // PID
            var pid = (uint)xoro.NextInt(uint.MaxValue);

            if (shiny == Shiny.Never)
            {
                if (GetIsShiny(pk.TID, pk.SID, pid))
                {
                    pid ^= 0x1000_0000;
                }
            }
            else if (shiny != Shiny.Random)
            {
                if (!GetIsShiny(pk.TID, pk.SID, pid))
                {
                    pid = GetShinyPID(pk.TID, pk.SID, pid, 0);
                }

                if (shiny == Shiny.AlwaysSquare && pk.ShinyXor != 0)
                {
                    return(false);
                }
                if (shiny == Shiny.AlwaysStar && pk.ShinyXor == 0)
                {
                    return(false);
                }
            }

            pk.PID = pid;

            // IVs
            Span <int> ivs = stackalloc[] { UNSET, UNSET, UNSET, UNSET, UNSET, UNSET };
            const int  MAX = 31;

            for (int i = 0; i < flawless; i++)
            {
                int index;
                do
                {
                    index = (int)xoro.NextInt(6);
                }while (ivs[index] != UNSET);

                ivs[index] = MAX;
            }

            for (int i = 0; i < ivs.Length; i++)
            {
                if (ivs[i] == UNSET)
                {
                    ivs[i] = (int)xoro.NextInt(32);
                }
            }

            if (!criteria.IsIVsCompatible(ivs, 8))
            {
                return(false);
            }

            pk.IV_HP  = ivs[0];
            pk.IV_ATK = ivs[1];
            pk.IV_DEF = ivs[2];
            pk.IV_SPA = ivs[3];
            pk.IV_SPD = ivs[4];
            pk.IV_SPE = ivs[5];

            // Remainder
            var scale = (IScaledSize)pk;

            scale.HeightScalar = (byte)((int)xoro.NextInt(0x81) + (int)xoro.NextInt(0x80));
            scale.WeightScalar = (byte)((int)xoro.NextInt(0x81) + (int)xoro.NextInt(0x80));

            return(true);
        }
Esempio n. 30
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);
            }
        }