Ejemplo n.º 1
0
        public void setPartySlot(PKM pkm, int offset, bool?trade = null, bool?dex = null)
        {
            if (pkm == null)
            {
                return;
            }
            if (pkm.GetType() != PKMType)
            {
                throw new InvalidCastException($"PKM Format needs to be {PKMType} when setting to a Gen{Generation} Save File.");
            }
            if (trade ?? SetUpdatePKM)
            {
                setPKM(pkm);
            }
            if (dex ?? SetUpdateDex)
            {
                setDex(pkm);
            }

            for (int i = 0; i < 6; i++)
            {
                if (getPartyOffset(i) == offset)
                {
                    if (PartyCount <= i)
                    {
                        PartyCount = i + 1;
                    }
                }
            }

            setData(pkm.EncryptedPartyData, offset);
            Console.WriteLine("");
            Edited = true;
        }
Ejemplo n.º 2
0
        private void populateRegimens(string Type, TableLayoutPanel TLP, List <RegimenInfo> list)
        {
            // Get a list of all Regimen Attregutes in the PKM
            var RegimenNames = ReflectUtil.getPropertiesStartWithPrefix(pkm.GetType(), Type);

            list.AddRange(from RegimenName in RegimenNames
                          let RegimenValue = ReflectUtil.GetValue(pkm, RegimenName)
                                             where RegimenValue is bool
                                             select new RegimenInfo(RegimenName, (bool)RegimenValue));
            TLP.ColumnCount = 1;
            TLP.RowCount    = 0;

            // Add Regimens
            foreach (var reg in list)
            {
                addRegimenChoice(reg, TLP);
            }

            // Force auto-size
            foreach (RowStyle style in TLP.RowStyles)
            {
                style.SizeType = SizeType.AutoSize;
            }
            foreach (ColumnStyle style in TLP.ColumnStyles)
            {
                style.SizeType = SizeType.AutoSize;
            }
        }
Ejemplo n.º 3
0
        private static ModifyResult ProcessPKM(PKM PKM, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions)
        {
            if (!PKM.ChecksumValid || PKM.Species == 0)
            {
                return(ModifyResult.Invalid);
            }

            Type pkm = PKM.GetType();

            foreach (var cmd in Filters)
            {
                try
                {
                    if (!pkm.HasProperty(cmd.PropertyName))
                    {
                        return(ModifyResult.Filtered);
                    }
                    if (ReflectUtil.GetValueEquals(PKM, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator)
                    {
                        return(ModifyResult.Filtered);
                    }
                }
                catch
                {
                    Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}.");
                    return(ModifyResult.Filtered);
                }
            }

            ModifyResult result = ModifyResult.Error;

            foreach (var cmd in Instructions)
            {
                try
                {
                    if (cmd.PropertyValue == CONST_RAND && (cmd.PropertyName == "PID" || cmd.PropertyName == "EncryptionConstant"))
                    {
                        ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32().ToString());
                    }
                    else if (cmd.PropertyValue == CONST_SHINY && cmd.PropertyName == "PID")
                    {
                        PKM.setShinyPID();
                    }
                    else if (cmd.PropertyValue == "0" && cmd.PropertyName == "Species")
                    {
                        PKM.Data = new byte[PKM.Data.Length];
                    }
                    else
                    {
                        ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.PropertyValue);
                    }

                    result = ModifyResult.Modified;
                }
                catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); }
            }
            return(result);
        }
Ejemplo n.º 4
0
        private static ModifyResult ProcessPKM(PKM PKM, IEnumerable<StringInstruction> Filters, IEnumerable<StringInstruction> Instructions)
        {
            if (!PKM.ChecksumValid || PKM.Species == 0)
                return ModifyResult.Invalid;

            Type pkm = PKM.GetType();

            foreach (var cmd in Filters)
            {
                try
                {
                    if (!pkm.HasProperty(cmd.PropertyName))
                        return ModifyResult.Filtered;
                    if (ReflectUtil.GetValueEquals(PKM, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator)
                        return ModifyResult.Filtered;
                }
                catch
                {
                    Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}.");
                    return ModifyResult.Filtered;
                }
            }

            ModifyResult result = ModifyResult.Error;
            foreach (var cmd in Instructions)
            {
                try
                {
                    if (cmd.PropertyName == "MetDate")
                        PKM.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
                    else if (cmd.PropertyName == "EggMetDate")
                        PKM.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
                    else if (cmd.PropertyName == "EncryptionConstant" && cmd.PropertyValue == CONST_RAND)
                        ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32().ToString());
                    else if(cmd.PropertyName == "PID" && cmd.PropertyValue == CONST_RAND)
                        PKM.setPIDGender(PKM.Gender);
                    else if (cmd.PropertyName == "EncryptionConstant" && cmd.PropertyValue == "PID")
                        PKM.EncryptionConstant = PKM.PID;
                    else if (cmd.PropertyName == "PID" && cmd.PropertyValue == CONST_SHINY)
                        PKM.setShinyPID();
                    else if (cmd.PropertyName == "Species" && cmd.PropertyValue == "0")
                        PKM.Data = new byte[PKM.Data.Length];
                    else
                        ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.PropertyValue);

                    result = ModifyResult.Modified;
                }
                catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); }
            }
            return result;
        }
Ejemplo n.º 5
0
        protected void TransferPropertiesWithReflection(PKM Source, PKM Destination)
        {
            var SourceProperties      = ReflectUtil.getPropertiesCanWritePublic(Source.GetType());
            var DestinationProperties = ReflectUtil.getPropertiesCanWritePublic(Destination.GetType());

            foreach (string property in SourceProperties.Intersect(DestinationProperties).Where(prop => prop != nameof(Data)))
            {
                var prop = ReflectUtil.GetValue(this, property);
                if (prop == null)
                {
                    continue;
                }
                ReflectUtil.SetValue(Destination, property, prop);
            }
        }
Ejemplo n.º 6
0
        public void setStoredSlot(PKM pkm, int offset, bool?trade = null, bool?dex = null)
        {
            if (pkm == null)
            {
                return;
            }
            if (pkm.GetType() != PKMType)
            {
                throw new InvalidCastException($"PKM Format needs to be {PKMType} when setting to a Gen{Generation} Save File.");
            }
            if (trade ?? SetUpdatePKM)
            {
                setPKM(pkm);
            }
            if (dex ?? SetUpdateDex)
            {
                setDex(pkm);
            }

            setData(pkm.EncryptedBoxData, offset);
            Edited = true;
        }
Ejemplo n.º 7
0
        private void populateRibbons()
        {
            // Get a list of all Ribbon Attributes in the PKM
            var RibbonNames = ReflectUtil.getPropertiesStartWithPrefix(pkm.GetType(), "Ribbon");

            foreach (var RibbonName in RibbonNames)
            {
                object RibbonValue = ReflectUtil.GetValue(pkm, RibbonName);
                if (RibbonValue is int)
                {
                    riblist.Add(new RibbonInfo(RibbonName, (int)RibbonValue));
                }
                if (RibbonValue is bool)
                {
                    riblist.Add(new RibbonInfo(RibbonName, (bool)RibbonValue));
                }
            }
            TLP_Ribbons.ColumnCount = 2;
            TLP_Ribbons.RowCount    = 0;

            // Add Ribbons
            foreach (var rib in riblist)
            {
                addRibbonSprite(rib);
                addRibbonChoice(rib);
            }

            // Force auto-size
            foreach (RowStyle style in TLP_Ribbons.RowStyles)
            {
                style.SizeType = SizeType.AutoSize;
            }
            foreach (ColumnStyle style in TLP_Ribbons.ColumnStyles)
            {
                style.SizeType = SizeType.AutoSize;
            }
        }
Ejemplo n.º 8
0
        private static ModifyResult ProcessPKM(PKM PKM, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions)
        {
            if (!PKM.ChecksumValid || PKM.Species == 0)
            {
                return(ModifyResult.Invalid);
            }

            Type pkm = PKM.GetType();

            foreach (var cmd in Filters)
            {
                try
                {
                    if (!pkm.HasProperty(cmd.PropertyName))
                    {
                        return(ModifyResult.Filtered);
                    }
                    if (ReflectUtil.GetValueEquals(PKM, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator)
                    {
                        return(ModifyResult.Filtered);
                    }
                }
                catch
                {
                    Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}.");
                    return(ModifyResult.Filtered);
                }
            }

            ModifyResult result = ModifyResult.Error;

            foreach (var cmd in Instructions)
            {
                try
                {
                    if (cmd.PropertyName == "MetDate")
                    {
                        PKM.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
                    }
                    else if (cmd.PropertyName == "EggMetDate")
                    {
                        PKM.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
                    }
                    else if (cmd.PropertyName == "EncryptionConstant" && cmd.PropertyValue == CONST_RAND)
                    {
                        ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32().ToString());
                    }
                    else if (cmd.PropertyName == "PID" && cmd.PropertyValue == CONST_RAND)
                    {
                        PKM.setPIDGender(PKM.Gender);
                    }
                    else if (cmd.PropertyName == "EncryptionConstant" && cmd.PropertyValue == "PID")
                    {
                        PKM.EncryptionConstant = PKM.PID;
                    }
                    else if (cmd.PropertyName == "PID" && cmd.PropertyValue == CONST_SHINY)
                    {
                        PKM.setShinyPID();
                    }
                    else if (cmd.PropertyName == "Species" && cmd.PropertyValue == "0")
                    {
                        PKM.Data = new byte[PKM.Data.Length];
                    }
                    else
                    {
                        ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.PropertyValue);
                    }

                    result = ModifyResult.Modified;
                }
                catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); }
            }
            return(result);
        }
Ejemplo n.º 9
0
        internal static PKM convertToFormat(PKM pk, Type PKMType, out string comment)
        {
            if (pk == null || pk.Species == 0)
            {
                comment = "Null input. Aborting.";
                return(null);
            }

            Type fromType   = pk.GetType();
            int  fromFormat = int.Parse(fromType.Name.Last().ToString());
            int  toFormat   = int.Parse(PKMType.Name.Last().ToString());

            Console.WriteLine($"Trying to convert {fromType.Name} to {PKMType.Name}.");

            PKM pkm = null;

            if (fromType == PKMType)
            {
                comment = "No need to convert, current format matches requested format.";
                return(pk);
            }
            if (fromFormat <= toFormat || fromFormat == 2)
            {
                pkm = pk.Clone();
                if (pkm.IsEgg) // force hatch
                {
                    pkm.IsEgg = false;
                    if (pkm.AO)
                    {
                        pkm.Met_Location = 318; // Battle Resort
                    }
                    else if (pkm.XY)
                    {
                        pkm.Met_Location = 38; // Route 7
                    }
                    else if (pkm.Gen5)
                    {
                        pkm.Met_Location = 16; // Route 16
                    }
                    else
                    {
                        pkm.Met_Location = 30001; // Pokétransfer
                    }
                }
                switch (fromType.Name)
                {
                case "PK1":
                    if (toFormat == 2)
                    {
                        pkm = PKMType == typeof(PK2) ? ((PK1)pk).convertToPK2() : null;
                        break;
                    }
                    if (toFormat == 7)
                    {
                        pkm = null;     // pkm.convertPK1toPK7();
                    }
                    break;

                case "PK2":
                    if (PKMType == typeof(PK1))
                    {
                        if (pk.Species > 151)
                        {
                            comment = $"Cannot convert a {PKX.getSpeciesName(pkm.Species, ((PK2)pkm).Japanese ? 1 : 2)} to {PKMType.Name}";
                            return(null);
                        }
                        pkm = ((PK2)pk).convertToPK1();
                    }
                    else
                    {
                        pkm = null;
                    }
                    break;

                case "CK3":
                case "XK3":
                    // interconverting C/XD needs to visit main series format
                    // ends up stripping purification/shadow etc stats
                    pkm = pkm.convertToPK3();
                    goto case "PK3";     // fall through

                case "PK3":
                    if (toFormat == 3)     // Gen3 Inter-trading
                    {
                        switch (PKMType.Name)
                        {
                        case "CK3": pkm = pkm.convertToCK3(); break;

                        case "XK3": pkm = pkm.convertToXK3(); break;

                        case "PK3": pkm = pkm.convertToPK3(); break;         // already converted, instantly returns

                        default: throw new FormatException();
                        }
                        break;
                    }
                    if (fromType.Name != "PK3")
                    {
                        pkm = pkm.convertToPK3();
                    }

                    pkm = ((PK3)pkm).convertToPK4();
                    if (toFormat == 4)
                    {
                        if (PKMType == typeof(BK4))
                        {
                            pkm = ((PK4)pkm).convertToBK4();
                        }
                        break;
                    }
                    pkm = ((PK4)pkm).convertToPK5();
                    if (toFormat == 5)
                    {
                        break;
                    }
                    pkm = ((PK5)pkm).convertToPK6();
                    if (toFormat == 6)
                    {
                        break;
                    }
                    pkm = new PK7(pkm.Data, pkm.Identifier);
                    break;

                case "PK4":
                    if (PKMType == typeof(BK4))
                    {
                        pkm = ((PK4)pkm).convertToBK4();
                        break;
                    }
                    pkm = ((PK4)pkm).convertToPK5();
                    if (toFormat == 5)
                    {
                        break;
                    }
                    pkm = ((PK5)pkm).convertToPK6();
                    if (toFormat == 6)
                    {
                        break;
                    }
                    pkm = new PK7(pkm.Data, pkm.Identifier);
                    break;

                case "BK4":
                    pkm = ((BK4)pkm).convertToPK4();
                    if (toFormat == 4)
                    {
                        break;
                    }
                    pkm = ((PK4)pkm).convertToPK5();
                    if (toFormat == 5)
                    {
                        break;
                    }
                    pkm = ((PK5)pkm).convertToPK6();
                    if (toFormat == 6)
                    {
                        break;
                    }
                    pkm = new PK7(pkm.Data, pkm.Identifier);
                    break;

                case "PK5":
                    pkm = ((PK5)pkm).convertToPK6();
                    break;

                case "PK6":
                    pkm = new PK7(pkm.Data, pkm.Identifier);
                    break;
                }
            }

            comment = pkm == null
                ? $"Cannot convert a {fromType.Name} to a {PKMType.Name}."
                : $"Converted from {fromType.Name} to {PKMType.Name}.";

            return(pkm);
        }
Ejemplo n.º 10
0
        internal static PKM convertToFormat(PKM pk, Type PKMType, out string comment)
        {
            if (pk == null || pk.Species == 0)
            {
                comment = "Null input. Aborting.";
                return null;
            }

            Type fromType = pk.GetType();
            int fromFormat = int.Parse(fromType.Name.Last().ToString());
            int toFormat = int.Parse(PKMType.Name.Last().ToString());
            Console.WriteLine($"Trying to convert {fromType.Name} to {PKMType.Name}.");

            PKM pkm = null;

            if (fromType == PKMType)
            {
                comment = "No need to convert, current format matches requested format.";
                return pk;
            }
            if (fromFormat <= toFormat || fromFormat == 2)
            {
                pkm = pk.Clone();
                if (pkm.IsEgg) // force hatch
                {
                    pkm.IsEgg = false;
                    if (pkm.AO)
                        pkm.Met_Location = 318; // Battle Resort
                    else if (pkm.XY)
                        pkm.Met_Location = 38; // Route 7
                    else if (pkm.Gen5)
                        pkm.Met_Location = 16; // Route 16
                    else
                        pkm.Met_Location = 30001; // Pokétransfer
                }
                switch (fromType.Name)
                {
                    case "PK1":
                        if (toFormat == 2)
                        {
                            pkm = PKMType == typeof (PK2) ? ((PK1) pk).convertToPK2() : null;
                            break;
                        }
                        if (toFormat == 7)
                            pkm = null; // pkm.convertPK1toPK7();
                        break;
                    case "PK2":
                        if (PKMType == typeof (PK1))
                        {
                            if (pk.Species > 151)
                            {
                                comment = $"Cannot convert a {PKX.getSpeciesName(pkm.Species, ((PK2)pkm).Japanese ? 1 : 2)} to {PKMType.Name}";
                                return null;
                            }
                            pkm = ((PK2) pk).convertToPK1();
                        }
                        else
                            pkm = null;
                        break;
                    case "CK3":
                    case "XK3":
                        // interconverting C/XD needs to visit main series format
                        // ends up stripping purification/shadow etc stats
                        pkm = pkm.convertToPK3();
                        goto case "PK3"; // fall through
                    case "PK3":
                        if (toFormat == 3) // Gen3 Inter-trading
                        {
                            switch (PKMType.Name)
                            {
                                case "CK3": pkm = pkm.convertToCK3(); break;
                                case "XK3": pkm = pkm.convertToXK3(); break;
                                case "PK3": pkm = pkm.convertToPK3(); break; // already converted, instantly returns
                                default: throw new FormatException();
                            }
                            break;
                        }
                        if (fromType.Name != "PK3")
                            pkm = pkm.convertToPK3();

                        pkm = ((PK3)pkm).convertToPK4();
                        if (toFormat == 4)
                        {
                            if (PKMType == typeof (BK4))
                                pkm = ((PK4) pkm).convertToBK4();
                            break;
                        }
                        pkm = ((PK4)pkm).convertToPK5();
                        if (toFormat == 5)
                            break;
                        pkm = ((PK5)pkm).convertToPK6();
                        if (toFormat == 6)
                            break;
                        pkm = new PK7(pkm.Data, pkm.Identifier);
                        break;
                    case "PK4":
                        if (PKMType == typeof(BK4))
                        {
                            pkm = ((PK4)pkm).convertToBK4();
                            break;
                        }
                        pkm = ((PK4)pkm).convertToPK5();
                        if (toFormat == 5)
                            break;
                        pkm = ((PK5)pkm).convertToPK6();
                        if (toFormat == 6)
                            break;
                        pkm = new PK7(pkm.Data, pkm.Identifier);
                        break;
                    case "BK4":
                        pkm = ((BK4)pkm).convertToPK4();
                        if (toFormat == 4)
                            break;
                        pkm = ((PK4)pkm).convertToPK5();
                        if (toFormat == 5)
                            break;
                        pkm = ((PK5)pkm).convertToPK6();
                        if (toFormat == 6)
                            break;
                        pkm = new PK7(pkm.Data, pkm.Identifier);
                        break;
                    case "PK5":
                        pkm = ((PK5)pkm).convertToPK6();
                        break;
                    case "PK6":
                        pkm = new PK7(pkm.Data, pkm.Identifier);
                        break;
                }
            }

            comment = pkm == null
                ? $"Cannot convert a {fromType.Name} to a {PKMType.Name}."
                : $"Converted from {fromType.Name} to {PKMType.Name}.";

            return pkm;
        }
Ejemplo n.º 11
0
        public override void setStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
        {
            if (pkm == null) return;
            if (pkm.GetType() != PKMType)
                throw new InvalidCastException($"PKM Format needs to be {PKMType} when setting to a Gen{Generation} Save File.");
            if (trade ?? SetUpdatePKM)
                setPKM(pkm);
            if (dex ?? SetUpdateDex)
                setDex(pkm);
            byte[] data = pkm.EncryptedBoxData;
            setData(data, offset);

            BitConverter.GetBytes((ushort)pkm.TID).CopyTo(Data, offset + data.Length + 0);
            BitConverter.GetBytes((ushort)pkm.SID).CopyTo(Data, offset + data.Length + 2);
            Edited = true;
        }