Beispiel #1
0
        public override IEnumerable <string> ConfigErrors(LootAffixDef parentDef)
        {
            foreach (string configError in base.ConfigErrors(parentDef))
            {
                yield return(configError);
            }

            // Check for reflection errors
            FieldInfo field = AccessTools.Field(typeof(VerbProperties), affectedField);
            Type      type  = field.FieldType;

            if (!ConvertHelper.CanConvert(1f, type))
            {
                yield return("Unsupported type: " + type);
            }

            // ValueModifierSet sanity checks
            if (valueModifier == null)
            {
                yield return("The valueModifer is not set!");

                yield break;
            }

            foreach (string configError in valueModifier.ConfigErrors(parentDef, this))
            {
                yield return(configError);
            }
        }
        public static bool Equal(object value1, object value2, Type compareAs)
        {
            if (value1 == value2)
            {
                return(true);
            }
            if (compareAs == null)
            {
                if (value1 == null)
                {
                    return(value2 == null);
                }
                Type type = value1.GetType();
                if (!ConvertHelper.CanConvert(value2, type))
                {
                    return(false);
                }
                object obj = ConvertHelper.Convert(value2, type);
                return(value1.Equals(obj));
            }
            if (!ConvertHelper.CanConvert(value1, compareAs) || !ConvertHelper.CanConvert(value2, compareAs))
            {
                return(false);
            }
            object obj2 = ConvertHelper.Convert(value1, compareAs);
            object obj3 = ConvertHelper.Convert(value2, compareAs);

            return(obj2?.Equals(obj3) ?? (obj3 == null));
        }
        private void replaceAudioToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Ensure FFmpeg binaries are present before attempting to continue.
            if (!ConvertHelper.CanConvert())
            {
                MessageBox.Show("FFmpeg was not found, please re-download Black Ops II Sound Studio.",
                                "Black Ops II Sound Studio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            var entry = (SndAssetBankEntry)audioEntriesDataGridView.SelectedRows[0].Tag;

            if (entry.Format == AudioFormat.XMA4)
            {
                MessageBox.Show("Audio replacement for this format is currently not supported.",
                                "Black Ops II Sound Studio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            using (var openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter = "All supported formats|*.mp3;*.wav;*.flac;*.ogg;*.m4a;*.wma;*.avi;*.flv;*.mp4;*.webm;*.mkv;*.wmv;*.3gp|All files|*.*";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    ReplaceAudio(entry, openFileDialog.FileName);
                }
            }
        }
        public bool TryGetConvertedValue <TAnything>(Slate slate, out TAnything value)
        {
            if (slateRef == null)
            {
                value = default(TAnything);
                return(true);
            }
            tmpCurSlate = slate;
            string text = HighPriorityVarsRegex.Replace(slateRef, RegexMatchEvaluatorConcatenate);

            if (!SlateRefUtility.CheckSingleVariableSyntax(text, slate, out var obj, out var exists))
            {
                obj    = MathExprRegex.Replace(text, RegexMatchEvaluatorEvaluateMathExpressionCached);
                obj    = VarsRegex.Replace((string)obj, RegexMatchEvaluatorConcatenateCached);
                exists = true;
            }
            tmpCurSlate = null;
            if (!exists)
            {
                value = default(TAnything);
                return(false);
            }
            if (obj == null)
            {
                value = default(TAnything);
                return(true);
            }
            if (obj is TAnything)
            {
                value = (TAnything)obj;
                return(true);
            }
            if (ConvertHelper.CanConvert <TAnything>(obj))
            {
                value = ConvertHelper.Convert <TAnything>(obj);
                return(true);
            }
            Log.Error("Could not convert SlateRef \"" + slateRef + "\" (" + obj.GetType().Name + ") to " + typeof(TAnything).Name);
            value = default(TAnything);
            return(false);
        }
Beispiel #5
0
 public bool TryGet <T>(string name, out T var, bool isAbsoluteName = false)
 {
     if (name.NullOrEmpty())
     {
         var = default(T);
         return(false);
     }
     if (!isAbsoluteName && !prefix.NullOrEmpty())
     {
         name = prefix + "/" + name;
     }
     name = QuestGenUtility.NormalizeVarPath(name);
     if (allowNonPrefixedLookup)
     {
         name = TryResolveFirstAvailableName(name);
     }
     if (!vars.TryGetValue(name, out object value))
     {
         var = default(T);
         return(false);
     }
     if (value == null)
     {
         var = default(T);
         return(true);
     }
     if (value is T)
     {
         var = (T)value;
         return(true);
     }
     if (ConvertHelper.CanConvert <T>(value))
     {
         var = ConvertHelper.Convert <T>(value);
         return(true);
     }
     Log.Error("Could not convert slate variable \"" + name + "\" (" + value.GetType().Name + ") to " + typeof(T).Name);
     var = default(T);
     return(false);
 }
Beispiel #6
0
 private static void AddSlateVar(ref GrammarRequest req, string absoluteName, object obj)
 {
     if (obj == null)
     {
         return;
     }
     if (obj is BodyPartRecord)
     {
         req.Rules.AddRange(GrammarUtility.RulesForBodyPartRecord(absoluteName, (BodyPartRecord)obj));
     }
     else if (obj is Def)
     {
         req.Rules.AddRange(GrammarUtility.RulesForDef(absoluteName, (Def)obj));
     }
     else if (obj is Faction)
     {
         Faction faction = (Faction)obj;
         req.Rules.AddRange(GrammarUtility.RulesForFaction(absoluteName, faction));
         if (faction.leader != null)
         {
             req.Rules.AddRange(GrammarUtility.RulesForPawn(absoluteName + "_leader", faction.leader, req.Constants));
         }
     }
     else if (obj is Pawn)
     {
         Pawn pawn = (Pawn)obj;
         req.Rules.AddRange(GrammarUtility.RulesForPawn(absoluteName, pawn, req.Constants));
         if (pawn.Faction != null)
         {
             req.Rules.AddRange(GrammarUtility.RulesForFaction(absoluteName + "_faction", pawn.Faction));
         }
     }
     else if (obj is WorldObject)
     {
         req.Rules.AddRange(GrammarUtility.RulesForWorldObject(absoluteName, (WorldObject)obj));
     }
     else if (obj is Map)
     {
         req.Rules.AddRange(GrammarUtility.RulesForWorldObject(absoluteName, ((Map)obj).Parent));
     }
     else if (obj is IntVec2)
     {
         req.Rules.Add(new Rule_String(absoluteName, ((IntVec2)obj).ToStringCross()));
     }
     else if (obj is IEnumerable && !(obj is string))
     {
         if (obj is IEnumerable <Thing> )
         {
             req.Rules.Add(new Rule_String(absoluteName, GenLabel.ThingsLabel(((IEnumerable <Thing>)obj).Where((Thing x) => x != null))));
         }
         else if (obj is IEnumerable <Pawn> )
         {
             req.Rules.Add(new Rule_String(absoluteName, GenLabel.ThingsLabel(((IEnumerable <Pawn>)obj).Where((Pawn x) => x != null).Cast <Thing>())));
         }
         else if (obj is IEnumerable <object> && ((IEnumerable <object>)obj).Any() && ((IEnumerable <object>)obj).All((object x) => x is Thing))
         {
             req.Rules.Add(new Rule_String(absoluteName, GenLabel.ThingsLabel(((IEnumerable <object>)obj).Where((object x) => x != null).Cast <Thing>())));
         }
         else
         {
             List <string> list = new List <string>();
             foreach (object item in (IEnumerable)obj)
             {
                 if (item != null)
                 {
                     list.Add(item.ToString());
                 }
             }
             req.Rules.Add(new Rule_String(absoluteName, list.ToCommaList(useAnd: true)));
         }
         req.Rules.Add(new Rule_String(absoluteName + "_count", ((IEnumerable)obj).EnumerableCount().ToString()));
         int num = 0;
         foreach (object item2 in (IEnumerable)obj)
         {
             AddSlateVar(ref req, absoluteName + num, item2);
             num++;
         }
     }
     else
     {
         req.Rules.Add(new Rule_String(absoluteName, obj.ToString()));
         if (ConvertHelper.CanConvert <int>(obj))
         {
             req.Rules.Add(new Rule_String(absoluteName + "_duration", ConvertHelper.Convert <int>(obj).ToStringTicksToPeriod(allowSeconds: true, shortForm: false, canUseDecimals: true, allowYears: false).Colorize(ColoredText.DateTimeColor)));
         }
         if (ConvertHelper.CanConvert <float>(obj))
         {
             req.Rules.Add(new Rule_String(absoluteName + "_money", ConvertHelper.Convert <float>(obj).ToStringMoney()));
         }
         if (ConvertHelper.CanConvert <float>(obj))
         {
             req.Rules.Add(new Rule_String(absoluteName + "_percent", ConvertHelper.Convert <float>(obj).ToStringPercent()));
         }
         if (ConvertHelper.CanConvert <FloatRange>(obj))
         {
             AddSlateVar(ref req, absoluteName + "_average", ConvertHelper.Convert <FloatRange>(obj).Average);
         }
         if (ConvertHelper.CanConvert <FloatRange>(obj))
         {
             AddSlateVar(ref req, absoluteName + "_min", ConvertHelper.Convert <FloatRange>(obj).min);
         }
         if (ConvertHelper.CanConvert <FloatRange>(obj))
         {
             AddSlateVar(ref req, absoluteName + "_max", ConvertHelper.Convert <FloatRange>(obj).max);
         }
     }
     if (obj is Def)
     {
         if (!req.Constants.ContainsKey(absoluteName))
         {
             req.Constants.Add(absoluteName, ((Def)obj).defName);
         }
     }
     else if (obj is Faction)
     {
         if (!req.Constants.ContainsKey(absoluteName))
         {
             req.Constants.Add(absoluteName, ((Faction)obj).def.defName);
         }
     }
     else if ((obj.GetType().IsPrimitive || obj is string || obj.GetType().IsEnum) && !req.Constants.ContainsKey(absoluteName))
     {
         req.Constants.Add(absoluteName, obj.ToString());
     }
     if (obj is IEnumerable && !(obj is string))
     {
         string key = absoluteName + "_count";
         if (!req.Constants.ContainsKey(key))
         {
             req.Constants.Add(key, ((IEnumerable)obj).EnumerableCount().ToString());
         }
     }
 }