Exemple #1
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);
        }
Exemple #2
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;
        }
        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);
        }