コード例 #1
0
 public static CurvePoint FromString(string str)
 {
     return(new CurvePoint((Vector2)ParseHelper.FromString(str, typeof(Vector2))));
 }
コード例 #2
0
        public static T ObjectFromXml <T>(XmlNode xmlRoot, bool doPostLoad) where T : new()
        {
            MethodInfo methodInfo = DirectXmlToObject.CustomDataLoadMethodOf(typeof(T));

            if (methodInfo != null)
            {
                xmlRoot = XmlInheritance.GetResolvedNodeFor(xmlRoot);
                Type type = DirectXmlToObject.ClassTypeOf <T>(xmlRoot);
                DirectXmlToObject.currentlyInstantiatingObjectOfType.Push(type);
                T t;
                try
                {
                    t = (T)((object)Activator.CreateInstance(type));
                }
                finally
                {
                    DirectXmlToObject.currentlyInstantiatingObjectOfType.Pop();
                }
                try
                {
                    methodInfo.Invoke(t, new object[]
                    {
                        xmlRoot
                    });
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Exception in custom XML loader for ",
                        typeof(T),
                        ". Node is:\n ",
                        xmlRoot.OuterXml,
                        "\n\nException is:\n ",
                        ex.ToString()
                    }), false);
                    t = default(T);
                }
                if (doPostLoad)
                {
                    DirectXmlToObject.TryDoPostLoad(t);
                }
                return(t);
            }
            if (xmlRoot.ChildNodes.Count == 1 && xmlRoot.FirstChild.NodeType == XmlNodeType.CDATA)
            {
                if (typeof(T) != typeof(string))
                {
                    Log.Error("CDATA can only be used for strings. Bad xml: " + xmlRoot.OuterXml, false);
                    return(default(T));
                }
                return((T)((object)xmlRoot.FirstChild.Value));
            }
            else
            {
                if (xmlRoot.ChildNodes.Count == 1 && xmlRoot.FirstChild.NodeType == XmlNodeType.Text)
                {
                    try
                    {
                        return((T)((object)ParseHelper.FromString(xmlRoot.InnerText, typeof(T))));
                    }
                    catch (Exception ex2)
                    {
                        Log.Error(string.Concat(new object[]
                        {
                            "Exception parsing ",
                            xmlRoot.OuterXml,
                            " to type ",
                            typeof(T),
                            ": ",
                            ex2
                        }), false);
                    }
                    return(default(T));
                }
                if (Attribute.IsDefined(typeof(T), typeof(FlagsAttribute)))
                {
                    List <T> list = DirectXmlToObject.ListFromXml <T>(xmlRoot);
                    int      num  = 0;
                    foreach (T t2 in list)
                    {
                        int num2 = (int)((object)t2);
                        num |= num2;
                    }
                    return((T)((object)num));
                }
                if (typeof(T).HasGenericDefinition(typeof(List <>)))
                {
                    MethodInfo method           = typeof(DirectXmlToObject).GetMethod("ListFromXml", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                    Type[]     genericArguments = typeof(T).GetGenericArguments();
                    MethodInfo methodInfo2      = method.MakeGenericMethod(genericArguments);
                    object[]   parameters       = new object[]
                    {
                        xmlRoot
                    };
                    object obj = methodInfo2.Invoke(null, parameters);
                    return((T)((object)obj));
                }
                if (typeof(T).HasGenericDefinition(typeof(Dictionary <, >)))
                {
                    MethodInfo method2           = typeof(DirectXmlToObject).GetMethod("DictionaryFromXml", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                    Type[]     genericArguments2 = typeof(T).GetGenericArguments();
                    MethodInfo methodInfo3       = method2.MakeGenericMethod(genericArguments2);
                    object[]   parameters2       = new object[]
                    {
                        xmlRoot
                    };
                    object obj2 = methodInfo3.Invoke(null, parameters2);
                    return((T)((object)obj2));
                }
                if (!xmlRoot.HasChildNodes)
                {
                    if (typeof(T) == typeof(string))
                    {
                        return((T)((object)string.Empty));
                    }
                    XmlAttribute xmlAttribute = xmlRoot.Attributes["IsNull"];
                    if (xmlAttribute != null && xmlAttribute.Value.ToUpperInvariant() == "TRUE")
                    {
                        return(default(T));
                    }
                    if (typeof(T).IsGenericType)
                    {
                        Type genericTypeDefinition = typeof(T).GetGenericTypeDefinition();
                        if (genericTypeDefinition == typeof(List <>) || genericTypeDefinition == typeof(HashSet <>) || genericTypeDefinition == typeof(Dictionary <, >))
                        {
                            return(Activator.CreateInstance <T>());
                        }
                    }
                }
                xmlRoot = XmlInheritance.GetResolvedNodeFor(xmlRoot);
                Type type2 = DirectXmlToObject.ClassTypeOf <T>(xmlRoot);
                Type type3 = Nullable.GetUnderlyingType(type2) ?? type2;
                DirectXmlToObject.currentlyInstantiatingObjectOfType.Push(type3);
                T t3;
                try
                {
                    t3 = (T)((object)Activator.CreateInstance(type3));
                }
                finally
                {
                    DirectXmlToObject.currentlyInstantiatingObjectOfType.Pop();
                }
                List <string> list2 = null;
                if (xmlRoot.ChildNodes.Count > 1)
                {
                    list2 = new List <string>();
                }
                for (int i = 0; i < xmlRoot.ChildNodes.Count; i++)
                {
                    XmlNode xmlNode = xmlRoot.ChildNodes[i];
                    if (!(xmlNode is XmlComment))
                    {
                        if (xmlRoot.ChildNodes.Count > 1)
                        {
                            if (list2.Contains(xmlNode.Name))
                            {
                                Log.Error(string.Concat(new object[]
                                {
                                    "XML ",
                                    typeof(T),
                                    " defines the same field twice: ",
                                    xmlNode.Name,
                                    ".\n\nField contents: ",
                                    xmlNode.InnerText,
                                    ".\n\nWhole XML:\n\n",
                                    xmlRoot.OuterXml
                                }), false);
                            }
                            else
                            {
                                list2.Add(xmlNode.Name);
                            }
                        }
                        FieldInfo fieldInfo = DirectXmlToObject.GetFieldInfoForType(t3.GetType(), xmlNode.Name, xmlRoot);
                        if (fieldInfo == null)
                        {
                            foreach (FieldInfo fieldInfo2 in t3.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                            {
                                foreach (object obj3 in fieldInfo2.GetCustomAttributes(typeof(LoadAliasAttribute), true))
                                {
                                    string alias = ((LoadAliasAttribute)obj3).alias;
                                    if (alias.EqualsIgnoreCase(xmlNode.Name))
                                    {
                                        fieldInfo = fieldInfo2;
                                        break;
                                    }
                                }
                                if (fieldInfo != null)
                                {
                                    break;
                                }
                            }
                        }
                        if (fieldInfo != null && fieldInfo.TryGetAttribute <UnsavedAttribute>() != null)
                        {
                            Log.Error(string.Concat(new string[]
                            {
                                "XML error: ",
                                xmlNode.OuterXml,
                                " corresponds to a field in type ",
                                t3.GetType().Name,
                                " which has an Unsaved attribute. Context: ",
                                xmlRoot.OuterXml
                            }), false);
                        }
                        else if (fieldInfo == null)
                        {
                            bool flag = false;
                            foreach (object obj4 in t3.GetType().GetCustomAttributes(typeof(IgnoreSavedElementAttribute), true))
                            {
                                string elementToIgnore = ((IgnoreSavedElementAttribute)obj4).elementToIgnore;
                                if (string.Equals(elementToIgnore, xmlNode.Name, StringComparison.OrdinalIgnoreCase))
                                {
                                    flag = true;
                                    break;
                                }
                            }
                            if (!flag)
                            {
                                Log.Error(string.Concat(new string[]
                                {
                                    "XML error: ",
                                    xmlNode.OuterXml,
                                    " doesn't correspond to any field in type ",
                                    t3.GetType().Name,
                                    ". Context: ",
                                    xmlRoot.OuterXml
                                }), false);
                            }
                        }
                        else if (typeof(Def).IsAssignableFrom(fieldInfo.FieldType))
                        {
                            if (xmlNode.InnerText.NullOrEmpty())
                            {
                                fieldInfo.SetValue(t3, null);
                            }
                            else
                            {
                                DirectXmlCrossRefLoader.RegisterObjectWantsCrossRef(t3, fieldInfo, xmlNode.InnerText);
                            }
                        }
                        else
                        {
                            object value = null;
                            try
                            {
                                MethodInfo method3     = typeof(DirectXmlToObject).GetMethod("ObjectFromXml", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                                MethodInfo methodInfo4 = method3.MakeGenericMethod(new Type[]
                                {
                                    fieldInfo.FieldType
                                });
                                value = methodInfo4.Invoke(null, new object[]
                                {
                                    xmlNode,
                                    doPostLoad
                                });
                            }
                            catch (Exception ex3)
                            {
                                Log.Error("Exception loading from " + xmlNode.ToString() + ": " + ex3.ToString(), false);
                                goto IL_850;
                            }
                            if (!typeof(T).IsValueType)
                            {
                                fieldInfo.SetValue(t3, value);
                            }
                            else
                            {
                                object obj5 = t3;
                                fieldInfo.SetValue(obj5, value);
                                t3 = (T)((object)obj5);
                            }
                        }
                    }
                    IL_850 :;
                }
                if (doPostLoad)
                {
                    DirectXmlToObject.TryDoPostLoad(t3);
                }
                return(t3);
            }
        }
コード例 #3
0
        public static T ObjectFromXml <T>(XmlNode xmlRoot, bool doPostLoad)
        {
            MethodInfo methodInfo = CustomDataLoadMethodOf(typeof(T));

            if (methodInfo != null)
            {
                xmlRoot = XmlInheritance.GetResolvedNodeFor(xmlRoot);
                Type type = ClassTypeOf <T>(xmlRoot);
                currentlyInstantiatingObjectOfType.Push(type);
                T val;
                try
                {
                    val = (T)Activator.CreateInstance(type);
                }
                finally
                {
                    currentlyInstantiatingObjectOfType.Pop();
                }
                try
                {
                    methodInfo.Invoke(val, new object[1]
                    {
                        xmlRoot
                    });
                }
                catch (Exception ex)
                {
                    Log.Error("Exception in custom XML loader for " + typeof(T) + ". Node is:\n " + xmlRoot.OuterXml + "\n\nException is:\n " + ex.ToString());
                    val = default(T);
                }
                if (doPostLoad)
                {
                    TryDoPostLoad(val);
                }
                return(val);
            }
            if (typeof(ISlateRef).IsAssignableFrom(typeof(T)))
            {
                try
                {
                    return(ParseHelper.FromString <T>(InnerTextWithReplacedNewlinesOrXML(xmlRoot)));
                }
                catch (Exception ex2)
                {
                    Log.Error("Exception parsing " + xmlRoot.OuterXml + " to type " + typeof(T) + ": " + ex2);
                }
                return(default(T));
            }
            if (xmlRoot.ChildNodes.Count == 1 && xmlRoot.FirstChild.NodeType == XmlNodeType.CDATA)
            {
                if (typeof(T) != typeof(string))
                {
                    Log.Error("CDATA can only be used for strings. Bad xml: " + xmlRoot.OuterXml);
                    return(default(T));
                }
                return((T)(object)xmlRoot.FirstChild.Value);
            }
            if (xmlRoot.ChildNodes.Count == 1 && xmlRoot.FirstChild.NodeType == XmlNodeType.Text)
            {
                try
                {
                    return(ParseHelper.FromString <T>(xmlRoot.InnerText));
                }
                catch (Exception ex3)
                {
                    Log.Error("Exception parsing " + xmlRoot.OuterXml + " to type " + typeof(T) + ": " + ex3);
                }
                return(default(T));
            }
            if (Attribute.IsDefined(typeof(T), typeof(FlagsAttribute)))
            {
                List <T> list = ListFromXml <T>(xmlRoot);
                int      num  = 0;
                foreach (T item in list)
                {
                    int num2 = (int)(object)item;
                    num |= num2;
                }
                return((T)(object)num);
            }
            if (typeof(T).HasGenericDefinition(typeof(List <>)))
            {
                Func <XmlNode, object> value = null;
                if (!listFromXmlMethods.TryGetValue(typeof(T), out value))
                {
                    MethodInfo method           = typeof(DirectXmlToObject).GetMethod("ListFromXmlReflection", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                    Type[]     genericArguments = typeof(T).GetGenericArguments();
                    value = (Func <XmlNode, object>)Delegate.CreateDelegate(typeof(Func <XmlNode, object>), method.MakeGenericMethod(genericArguments));
                    listFromXmlMethods.Add(typeof(T), value);
                }
                return((T)value(xmlRoot));
            }
            if (typeof(T).HasGenericDefinition(typeof(Dictionary <, >)))
            {
                Func <XmlNode, object> value2 = null;
                if (!dictionaryFromXmlMethods.TryGetValue(typeof(T), out value2))
                {
                    MethodInfo method2           = typeof(DirectXmlToObject).GetMethod("DictionaryFromXmlReflection", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                    Type[]     genericArguments2 = typeof(T).GetGenericArguments();
                    value2 = (Func <XmlNode, object>)Delegate.CreateDelegate(typeof(Func <XmlNode, object>), method2.MakeGenericMethod(genericArguments2));
                    dictionaryFromXmlMethods.Add(typeof(T), value2);
                }
                return((T)value2(xmlRoot));
            }
            if (!xmlRoot.HasChildNodes)
            {
                if (typeof(T) == typeof(string))
                {
                    return((T)(object)"");
                }
                XmlAttribute xmlAttribute = xmlRoot.Attributes["IsNull"];
                if (xmlAttribute != null && xmlAttribute.Value.ToUpperInvariant() == "TRUE")
                {
                    return(default(T));
                }
                if (typeof(T).IsGenericType)
                {
                    Type genericTypeDefinition = typeof(T).GetGenericTypeDefinition();
                    if (genericTypeDefinition == typeof(List <>) || genericTypeDefinition == typeof(HashSet <>) || genericTypeDefinition == typeof(Dictionary <, >))
                    {
                        return(Activator.CreateInstance <T>());
                    }
                }
            }
            xmlRoot = XmlInheritance.GetResolvedNodeFor(xmlRoot);
            Type type2 = ClassTypeOf <T>(xmlRoot);
            Type type3 = Nullable.GetUnderlyingType(type2) ?? type2;

            currentlyInstantiatingObjectOfType.Push(type3);
            T val2;

            try
            {
                val2 = (T)Activator.CreateInstance(type3);
            }
            finally
            {
                currentlyInstantiatingObjectOfType.Pop();
            }
            HashSet <string> hashSet = null;

            if (xmlRoot.ChildNodes.Count > 1)
            {
                hashSet = new HashSet <string>();
            }
            for (int i = 0; i < xmlRoot.ChildNodes.Count; i++)
            {
                XmlNode xmlNode = xmlRoot.ChildNodes[i];
                if (xmlNode is XmlComment)
                {
                    continue;
                }
                if (xmlRoot.ChildNodes.Count > 1)
                {
                    if (hashSet.Contains(xmlNode.Name))
                    {
                        Log.Error("XML " + typeof(T) + " defines the same field twice: " + xmlNode.Name + ".\n\nField contents: " + xmlNode.InnerText + ".\n\nWhole XML:\n\n" + xmlRoot.OuterXml);
                    }
                    else
                    {
                        hashSet.Add(xmlNode.Name);
                    }
                }
                FieldInfo value3 = null;
                DeepProfiler.Start("GetFieldInfoForType");
                try
                {
                    value3 = GetFieldInfoForType(val2.GetType(), xmlNode.Name, xmlRoot);
                }
                finally
                {
                    DeepProfiler.End();
                }
                if (value3 == null)
                {
                    DeepProfiler.Start("Field search");
                    try
                    {
                        FieldAliasCache key = new FieldAliasCache(val2.GetType(), xmlNode.Name);
                        if (!fieldAliases.TryGetValue(key, out value3))
                        {
                            FieldInfo[] fields = val2.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                            foreach (FieldInfo fieldInfo in fields)
                            {
                                object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(LoadAliasAttribute), inherit: true);
                                for (int k = 0; k < customAttributes.Length; k++)
                                {
                                    if (((LoadAliasAttribute)customAttributes[k]).alias.EqualsIgnoreCase(xmlNode.Name))
                                    {
                                        value3 = fieldInfo;
                                        break;
                                    }
                                }
                                if (value3 != null)
                                {
                                    break;
                                }
                            }
                            fieldAliases.Add(key, value3);
                        }
                    }
                    finally
                    {
                        DeepProfiler.End();
                    }
                }
                if (value3 != null && value3.TryGetAttribute <UnsavedAttribute>() != null && !value3.TryGetAttribute <UnsavedAttribute>().allowLoading)
                {
                    Log.Error("XML error: " + xmlNode.OuterXml + " corresponds to a field in type " + val2.GetType().Name + " which has an Unsaved attribute. Context: " + xmlRoot.OuterXml);
                    continue;
                }
                if (value3 == null)
                {
                    DeepProfiler.Start("Field search 2");
                    try
                    {
                        bool         flag          = false;
                        XmlAttribute xmlAttribute2 = xmlNode.Attributes?["IgnoreIfNoMatchingField"];
                        if (xmlAttribute2 != null && xmlAttribute2.Value.ToUpperInvariant() == "TRUE")
                        {
                            flag = true;
                        }
                        else
                        {
                            object[] customAttributes = val2.GetType().GetCustomAttributes(typeof(IgnoreSavedElementAttribute), inherit: true);
                            for (int j = 0; j < customAttributes.Length; j++)
                            {
                                if (string.Equals(((IgnoreSavedElementAttribute)customAttributes[j]).elementToIgnore, xmlNode.Name, StringComparison.OrdinalIgnoreCase))
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        if (!flag)
                        {
                            Log.Error("XML error: " + xmlNode.OuterXml + " doesn't correspond to any field in type " + val2.GetType().Name + ". Context: " + xmlRoot.OuterXml);
                        }
                    }
                    finally
                    {
                        DeepProfiler.End();
                    }
                    continue;
                }
                if (typeof(Def).IsAssignableFrom(value3.FieldType))
                {
                    if (xmlNode.InnerText.NullOrEmpty())
                    {
                        value3.SetValue(val2, null);
                        continue;
                    }
                    XmlAttribute xmlAttribute3 = xmlNode.Attributes["MayRequire"];
                    DirectXmlCrossRefLoader.RegisterObjectWantsCrossRef(val2, value3, xmlNode.InnerText, xmlAttribute3?.Value.ToLower());
                    continue;
                }
                object obj = null;
                try
                {
                    obj = GetObjectFromXmlMethod(value3.FieldType)(xmlNode, doPostLoad);
                }
                catch (Exception ex4)
                {
                    Log.Error("Exception loading from " + xmlNode.ToString() + ": " + ex4.ToString());
                    continue;
                }
                if (!typeof(T).IsValueType)
                {
                    value3.SetValue(val2, obj);
                    continue;
                }
                object obj2 = val2;
                value3.SetValue(obj2, obj);
                val2 = (T)obj2;
            }
            if (doPostLoad)
            {
                TryDoPostLoad(val2);
            }
            return(val2);
        }
コード例 #4
0
 public void LoadDataFromXmlCustom(XmlNode xmlRoot)
 {
     DirectXmlCrossRefLoader.RegisterObjectWantsCrossRef(this, "skill", xmlRoot.Name);
     this.minLevel = (int)ParseHelper.FromString(xmlRoot.FirstChild.Value, typeof(int));
 }
コード例 #5
0
 public static CurvePoint FromString(string str)
 {
     return(new CurvePoint(ParseHelper.FromString <Vector2>(str)));
 }
コード例 #6
0
        private bool SetDefFieldAtPath(Type defType, string path, object value, Type ensureFieldType, bool errorOnDefNotFound, string fileSource, bool isPlaceholder, out string normalizedPath, out string suggestedPath, out string replacedString, out IEnumerable <string> replacedStringsList)
        {
            replacedString      = null;
            replacedStringsList = null;
            normalizedPath      = path;
            suggestedPath       = path;
            string defName = path.Split('.')[0];

            defName = BackCompatibility.BackCompatibleDefName(defType, defName, forDefInjections: true);
            object defSilentFail = GenDefDatabase.GetDefSilentFail(defType, defName, specialCaseForSoundDefs: false);

            if (defSilentFail != null)
            {
                bool flag = false;
                int  num  = 0;
                try
                {
                    List <string> list = path.Split('.').ToList();
                    object        obj  = GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), defType, "GetNamedSilentFail", list[0]);
                    if (obj == null)
                    {
                        throw new InvalidOperationException("Def named " + list[0] + " not found.");
                    }
                    list.RemoveAt(0);
                    num++;
                    string text;
                    int    result;
                    DefInjectionPathPartKind defInjectionPathPartKind;
                    while (true)
                    {
                        text   = list[0];
                        result = -1;
                        if (int.TryParse(text, out result))
                        {
                            defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex;
                        }
                        else if (GetFieldNamed(obj.GetType(), text) != null)
                        {
                            defInjectionPathPartKind = DefInjectionPathPartKind.Field;
                        }
                        else if (obj.GetType().GetProperty("Count") != null)
                        {
                            if (text.Contains('-'))
                            {
                                defInjectionPathPartKind = DefInjectionPathPartKind.ListHandleWithIndex;
                                string[] array = text.Split('-');
                                text   = array[0];
                                result = (int)ParseHelper.FromString(array[1], typeof(int));
                            }
                            else
                            {
                                defInjectionPathPartKind = DefInjectionPathPartKind.ListHandle;
                            }
                        }
                        else
                        {
                            defInjectionPathPartKind = DefInjectionPathPartKind.Field;
                        }
                        if (list.Count == 1)
                        {
                            break;
                        }
                        switch (defInjectionPathPartKind)
                        {
                        case DefInjectionPathPartKind.Field:
                        {
                            FieldInfo field = obj.GetType().GetField(text, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                            if (field == null)
                            {
                                throw new InvalidOperationException("Field " + text + " does not exist.");
                            }
                            if (field.HasAttribute <NoTranslateAttribute>())
                            {
                                throw new InvalidOperationException("Translated untranslatable field " + field.Name + " of type " + field.FieldType + " at path " + path + ". Translating this field will break the game.");
                            }
                            if (field.HasAttribute <UnsavedAttribute>())
                            {
                                throw new InvalidOperationException("Translated untranslatable field ([Unsaved] attribute) " + field.Name + " of type " + field.FieldType + " at path " + path + ". Translating this field will break the game.");
                            }
                            if (field.HasAttribute <TranslationCanChangeCountAttribute>())
                            {
                                flag = true;
                            }
                            if (defInjectionPathPartKind == DefInjectionPathPartKind.Field)
                            {
                                obj = field.GetValue(obj);
                            }
                            else
                            {
                                object       value2    = field.GetValue(obj);
                                PropertyInfo property2 = value2.GetType().GetProperty("Item");
                                if (property2 == null)
                                {
                                    throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property).");
                                }
                                int num3 = (int)value2.GetType().GetProperty("Count").GetValue(value2, null);
                                if (result < 0 || result >= num3)
                                {
                                    throw new InvalidOperationException("Index out of bounds (max index is " + (num3 - 1) + ")");
                                }
                                obj = property2.GetValue(value2, new object[1]
                                    {
                                        result
                                    });
                            }
                            break;
                        }

                        case DefInjectionPathPartKind.ListIndex:
                        case DefInjectionPathPartKind.ListHandle:
                        case DefInjectionPathPartKind.ListHandleWithIndex:
                        {
                            object       obj2     = obj;
                            PropertyInfo property = obj2.GetType().GetProperty("Item");
                            if (property == null)
                            {
                                throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property).");
                            }
                            bool flag2;
                            if (defInjectionPathPartKind == DefInjectionPathPartKind.ListHandle || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandleWithIndex)
                            {
                                result = TranslationHandleUtility.GetElementIndexByHandle(obj2, text, result);
                                defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex;
                                flag2 = true;
                            }
                            else
                            {
                                flag2 = false;
                            }
                            int num2 = (int)obj2.GetType().GetProperty("Count").GetValue(obj2, null);
                            if (result < 0 || result >= num2)
                            {
                                throw new InvalidOperationException("Index out of bounds (max index is " + (num2 - 1) + ")");
                            }
                            obj = property.GetValue(obj2, new object[1]
                                {
                                    result
                                });
                            if (flag2)
                            {
                                string[] array2 = normalizedPath.Split('.');
                                array2[num]    = result.ToString();
                                normalizedPath = string.Join(".", array2);
                            }
                            else
                            {
                                string bestHandleWithIndexForListElement = TranslationHandleUtility.GetBestHandleWithIndexForListElement(obj2, obj);
                                if (!bestHandleWithIndexForListElement.NullOrEmpty())
                                {
                                    string[] array3 = suggestedPath.Split('.');
                                    array3[num]   = bestHandleWithIndexForListElement;
                                    suggestedPath = string.Join(".", array3);
                                }
                            }
                            break;
                        }

                        default:
                            loadErrors.Add("Can't enter node " + text + " at path " + path + ", element kind is " + defInjectionPathPartKind + ". (" + fileSource + ")");
                            break;
                        }
                        list.RemoveAt(0);
                        num++;
                    }
                    bool flag3 = false;
                    foreach (KeyValuePair <string, DefInjection> injection in injections)
                    {
                        if (!(injection.Key == path) && injection.Value.injected && injection.Value.normalizedPath == normalizedPath)
                        {
                            string text2 = "Duplicate def-injected translation key. Both " + injection.Value.path + " and " + path + " refer to the same field (" + suggestedPath + ")";
                            if (injection.Value.path != injection.Value.nonBackCompatiblePath)
                            {
                                string text3 = text2;
                                text2 = text3 + " (" + injection.Value.nonBackCompatiblePath + " was auto-renamed to " + injection.Value.path + ")";
                            }
                            text2 = text2 + " (" + injection.Value.fileSource + ")";
                            loadErrors.Add(text2);
                            flag3 = true;
                            break;
                        }
                    }
                    bool result2 = false;
                    if (!flag3)
                    {
                        switch (defInjectionPathPartKind)
                        {
                        case DefInjectionPathPartKind.Field:
                        {
                            FieldInfo fieldNamed = GetFieldNamed(obj.GetType(), text);
                            if (fieldNamed == null)
                            {
                                throw new InvalidOperationException("Field " + text + " does not exist in type " + obj.GetType() + ".");
                            }
                            if (fieldNamed.HasAttribute <NoTranslateAttribute>())
                            {
                                loadErrors.Add("Translated untranslatable field " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + path + ". Translating this field will break the game. (" + fileSource + ")");
                            }
                            else if (fieldNamed.HasAttribute <UnsavedAttribute>())
                            {
                                loadErrors.Add("Translated untranslatable field (UnsavedAttribute) " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + path + ". Translating this field will break the game. (" + fileSource + ")");
                            }
                            else if (!isPlaceholder && fieldNamed.FieldType != ensureFieldType)
                            {
                                loadErrors.Add("Translated non-" + ensureFieldType + " field " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + path + ". Expected " + ensureFieldType + ". (" + fileSource + ")");
                            }
                            else if (!isPlaceholder && ensureFieldType != typeof(string) && !fieldNamed.HasAttribute <TranslationCanChangeCountAttribute>())
                            {
                                loadErrors.Add("Tried to translate field " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + path + ", but this field doesn't have [TranslationCanChangeCount] attribute so it doesn't allow this type of translation. (" + fileSource + ")");
                            }
                            else if (!isPlaceholder)
                            {
                                if (ensureFieldType == typeof(string))
                                {
                                    replacedString = (string)fieldNamed.GetValue(obj);
                                }
                                else
                                {
                                    replacedStringsList = (fieldNamed.GetValue(obj) as IEnumerable <string>);
                                }
                                fieldNamed.SetValue(obj, value);
                                result2 = true;
                            }
                            break;
                        }

                        case DefInjectionPathPartKind.ListIndex:
                        case DefInjectionPathPartKind.ListHandle:
                        case DefInjectionPathPartKind.ListHandleWithIndex:
                        {
                            object obj3 = obj;
                            if (obj3 == null)
                            {
                                throw new InvalidOperationException("Tried to use index on null list at " + path);
                            }
                            Type         type      = obj3.GetType();
                            PropertyInfo property3 = type.GetProperty("Count");
                            if (property3 == null)
                            {
                                throw new InvalidOperationException("Tried to use index on non-list (missing 'Count' property).");
                            }
                            if (defInjectionPathPartKind == DefInjectionPathPartKind.ListHandle || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandleWithIndex)
                            {
                                result = TranslationHandleUtility.GetElementIndexByHandle(obj3, text, result);
                                defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex;
                            }
                            int num4 = (int)property3.GetValue(obj3, null);
                            if (result >= num4)
                            {
                                throw new InvalidOperationException("Trying to translate " + defType + "." + path + " at index " + result + " but the list only has " + num4 + " entries (so max index is " + (num4 - 1).ToString() + ").");
                            }
                            PropertyInfo property4 = type.GetProperty("Item");
                            if (property4 == null)
                            {
                                throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property).");
                            }
                            Type propertyType = property4.PropertyType;
                            if (!isPlaceholder && propertyType != ensureFieldType)
                            {
                                loadErrors.Add("Translated non-" + ensureFieldType + " list item of type " + propertyType + " at path " + path + ". Expected " + ensureFieldType + ". (" + fileSource + ")");
                            }
                            else if (!isPlaceholder && ensureFieldType != typeof(string) && !flag)
                            {
                                loadErrors.Add("Tried to translate field of type " + propertyType + " at path " + path + ", but this field doesn't have [TranslationCanChangeCount] attribute so it doesn't allow this type of translation. (" + fileSource + ")");
                            }
                            else if (result < 0 || result >= (int)type.GetProperty("Count").GetValue(obj3, null))
                            {
                                loadErrors.Add("Index out of bounds (max index is " + ((int)type.GetProperty("Count").GetValue(obj3, null) - 1) + ")");
                            }
                            else if (!isPlaceholder)
                            {
                                replacedString = (string)property4.GetValue(obj3, new object[1]
                                    {
                                        result
                                    });
                                property4.SetValue(obj3, value, new object[1]
                                    {
                                        result
                                    });
                                result2 = true;
                            }
                            break;
                        }

                        default:
                            loadErrors.Add("Translated " + text + " at path " + path + " but it's not a field, it's " + defInjectionPathPartKind + ". (" + fileSource + ")");
                            break;
                        }
                    }
                    if (path != suggestedPath)
                    {
                        IList <string> list2 = value as IList <string>;
                        string         text4 = (list2 == null) ? value.ToString() : list2.ToStringSafeEnumerable();
                        loadSyntaxSuggestions.Add("Consider using " + suggestedPath + " instead of " + path + " for translation '" + text4 + "' (" + fileSource + ")");
                    }
                    return(result2);
                }
                catch (Exception ex)
                {
                    string text5 = "Couldn't inject " + path + " into " + defType + " (" + fileSource + "): " + ex.Message;
                    if (ex.InnerException != null)
                    {
                        text5 = text5 + " -> " + ex.InnerException.Message;
                    }
                    loadErrors.Add(text5);
                    return(false);
                }
            }
            if (errorOnDefNotFound)
            {
                loadErrors.Add("Found no " + defType + " named " + defName + " to match " + path + " (" + fileSource + ")");
            }
            return(false);
        }