Ejemplo n.º 1
0
        public static void BuildMappings()
        {
            Dictionary <string, string> tmpTranslationKeyToTKey = new Dictionary <string, string>();

            foreach (TKeyRef key in keys)
            {
                string normalizedTranslationKey = GetNormalizedTranslationKey(key);
                if (tKeyToNormalizedTranslationKey.TryGetValue(key.tKeyPath, out string value))
                {
                    loadErrors.Add("Duplicate TKey: " + key.tKeyPath + " -> NEW=" + normalizedTranslationKey + " | OLD" + value + " - Ignoring old");
                }
                else
                {
                    tKeyToNormalizedTranslationKey.Add(key.tKeyPath, normalizedTranslationKey);
                    tmpTranslationKeyToTKey.Add(normalizedTranslationKey, key.tKeyPath);
                }
            }
            foreach (string item in keys.Select((TKeyRef k) => k.defTypeName).Distinct())
            {
                DefInjectionUtility.ForEachPossibleDefInjection(GenTypes.GetTypeInAnyAssembly(item), delegate(string suggestedPath, string normalizedPath, bool isCollection, string currentValue, IEnumerable <string> currentValueCollection, bool translationAllowed, bool fullListTranslationAllowed, FieldInfo fieldInfo, Def def)
                {
                    if (translationAllowed && !TryGetNormalizedPath(suggestedPath, out string _) && TrySuggestTKeyPath(normalizedPath, out string tKeyPath, tmpTranslationKeyToTKey))
                    {
                        tmpTranslationKeyToTKey.Add(suggestedPath, tKeyPath);
                    }
                });
            }
            foreach (KeyValuePair <string, string> item2 in tmpTranslationKeyToTKey)
            {
                translationKeyToTKey.Add(item2.Key, item2.Value);
            }
        }
Ejemplo n.º 2
0
        public static Def DefFromNode(XmlNode node, LoadableXmlAsset loadingAsset)
        {
            Def result;

            if (node.NodeType != XmlNodeType.Element)
            {
                result = null;
            }
            else
            {
                XmlAttribute xmlAttribute = node.Attributes["Abstract"];
                if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true")
                {
                    result = null;
                }
                else
                {
                    Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(node.Name);
                    if (typeInAnyAssembly == null)
                    {
                        result = null;
                    }
                    else if (!typeof(Def).IsAssignableFrom(typeInAnyAssembly))
                    {
                        result = null;
                    }
                    else
                    {
                        MethodInfo method     = typeof(DirectXmlToObject).GetMethod("ObjectFromXml");
                        MethodInfo methodInfo = method.MakeGenericMethod(new Type[]
                        {
                            typeInAnyAssembly
                        });
                        Def def = null;
                        try
                        {
                            def = (Def)methodInfo.Invoke(null, new object[]
                            {
                                node,
                                true
                            });
                        }
                        catch (Exception ex)
                        {
                            Log.Error(string.Concat(new object[]
                            {
                                "Exception loading def from file ",
                                (loadingAsset == null) ? "(unknown)" : loadingAsset.name,
                                ": ",
                                ex
                            }), false);
                        }
                        result = def;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static Action ParseAction(string str)
        {
            string[]   array      = str.Split('.');
            string     methodName = array[array.Length - 1];
            string     typeName   = (array.Length != 3) ? array[0] : (array[0] + "." + array[1]);
            MethodInfo method     = GenTypes.GetTypeInAnyAssembly(typeName).GetMethods().First((MethodInfo m) => m.Name == methodName);

            return((Action)Delegate.CreateDelegate(typeof(Action), method));
        }
Ejemplo n.º 4
0
        public static Type ParseType(string str)
        {
            if (str == "null" || str == "Null")
            {
                return(null);
            }
            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);

            if (typeInAnyAssembly == null)
            {
                Log.Error("Could not find a type named " + str);
            }
            return(typeInAnyAssembly);
        }
        private static Type ClassTypeOf <T>(XmlNode xmlRoot)
        {
            XmlAttribute xmlAttribute = xmlRoot.Attributes["Class"];

            if (xmlAttribute != null)
            {
                Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(xmlAttribute.Value, typeof(T).Namespace);
                if (typeInAnyAssembly == null)
                {
                    Log.Error("Could not find type named " + xmlAttribute.Value + " from node " + xmlRoot.OuterXml);
                    return(typeof(T));
                }
                return(typeInAnyAssembly);
            }
            return(typeof(T));
        }
Ejemplo n.º 6
0
        public void LoadDataFromXmlCustom(XmlNode xmlRoot)
        {
            if (xmlRoot.ChildNodes.Count != 1)
            {
                Log.Error("Misconfigured DefHyperlink: " + xmlRoot.OuterXml);
                return;
            }
            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(xmlRoot.Name);

            if (typeInAnyAssembly == null)
            {
                Log.Error("Misconfigured DefHyperlink. Could not find def of type " + xmlRoot.Name);
            }
            else
            {
                DirectXmlCrossRefLoader.RegisterObjectWantsCrossRef(this, "def", xmlRoot.FirstChild.Value, null, typeInAnyAssembly);
            }
        }
Ejemplo n.º 7
0
        public static Def DefFromNode(XmlNode node, LoadableXmlAsset loadingAsset)
        {
            if (node.NodeType != XmlNodeType.Element)
            {
                return(null);
            }
            XmlAttribute xmlAttribute = node.Attributes["Abstract"];

            if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true")
            {
                return(null);
            }
            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(node.Name);

            if (typeInAnyAssembly == null)
            {
                return(null);
            }
            if (typeof(Def).IsAssignableFrom(typeInAnyAssembly))
            {
                MethodInfo method     = typeof(DirectXmlToObject).GetMethod("ObjectFromXml");
                MethodInfo methodInfo = method.MakeGenericMethod(typeInAnyAssembly);
                Def        result     = null;
                try
                {
                    result = (Def)methodInfo.Invoke(null, new object[2]
                    {
                        node,
                        true
                    });
                    return(result);
                }
                catch (Exception ex)
                {
                    Log.Error("Exception loading def from file " + ((loadingAsset == null) ? "(unknown)" : loadingAsset.name) + ": " + ex);
                    return(result);
                }
            }
            return(null);
        }
Ejemplo n.º 8
0
 public static Type GetBackCompatibleType(Type baseType, string providedClassName, XmlNode node)
 {
     if (baseType == typeof(WorldObject))
     {
         if (providedClassName == "RimWorld.Planet.WorldObject" && node["def"] != null && node["def"].InnerText == "JourneyDestination")
         {
             return(WorldObjectDefOf.EscapeShip.worldObjectClass);
         }
     }
     else if (baseType == typeof(Thing))
     {
         if (providedClassName == "Building_PoisonShipPart" && node["def"] != null && node["def"].InnerText == "CrashedPoisonShipPart")
         {
             return(ThingDefOf.CrashedPoisonShipPart.thingClass);
         }
         if (providedClassName == "Building_PsychicEmanator" && node["def"] != null && node["def"].InnerText == "CrashedPsychicEmanatorShipPart")
         {
             return(ThingDefOf.CrashedPsychicEmanatorShipPart.thingClass);
         }
     }
     return(GenTypes.GetTypeInAnyAssembly(providedClassName));
 }
Ejemplo n.º 9
0
 public static Type GetBackCompatibleType(Type baseType, string providedClassName, XmlNode node)
 {
     for (int i = 0; i < conversionChain.Count; i++)
     {
         if (conversionChain[i].AppliesToLoadedGameVersion())
         {
             try
             {
                 Type backCompatibleType = conversionChain[i].GetBackCompatibleType(baseType, providedClassName, node);
                 if (backCompatibleType != null)
                 {
                     return(backCompatibleType);
                 }
             }
             catch (Exception ex)
             {
                 Log.Error("Error in GetBackCompatibleType of " + conversionChain[i].GetType() + "\n" + ex);
             }
         }
     }
     return(GenTypes.GetTypeInAnyAssembly(providedClassName));
 }
Ejemplo n.º 10
0
        public static Def DefFromNode(XmlNode node, LoadableXmlAsset loadingAsset)
        {
            if (node.NodeType != XmlNodeType.Element)
            {
                return(null);
            }
            XmlAttribute xmlAttribute = node.Attributes["Abstract"];

            if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true")
            {
                return(null);
            }
            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(node.Name);

            if (typeInAnyAssembly == null)
            {
                return(null);
            }
            if (!typeof(Def).IsAssignableFrom(typeInAnyAssembly))
            {
                return(null);
            }
            Func <XmlNode, bool, object> objectFromXmlMethod = DirectXmlToObject.GetObjectFromXmlMethod(typeInAnyAssembly);
            Def result = null;

            try
            {
                result = (Def)objectFromXmlMethod(node, arg2: true);
                return(result);
            }
            catch (Exception ex)
            {
                Log.Error("Exception loading def from file " + ((loadingAsset != null) ? loadingAsset.name : "(unknown)") + ": " + ex);
                return(result);
            }
        }
        private static Type ClassTypeOf <T>(XmlNode xmlRoot)
        {
            XmlAttribute xmlAttribute = xmlRoot.Attributes["Class"];
            Type         result;

            if (xmlAttribute != null)
            {
                Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(xmlAttribute.Value);
                if (typeInAnyAssembly == null)
                {
                    Log.Error("Could not find type named " + xmlAttribute.Value + " from node " + xmlRoot.OuterXml, false);
                    result = typeof(T);
                }
                else
                {
                    result = typeInAnyAssembly;
                }
            }
            else
            {
                result = typeof(T);
            }
            return(result);
        }
Ejemplo n.º 12
0
 public void LoadData()
 {
     if (dataIsLoaded)
     {
         return;
     }
     dataIsLoaded = true;
     DeepProfiler.Start("Loading language data: " + folderName);
     try
     {
         tmpAlreadyLoadedFiles.Clear();
         foreach (Tuple <VirtualDirectory, ModContentPack, string> allDirectory in AllDirectories)
         {
             Tuple <VirtualDirectory, ModContentPack, string> localDirectory = allDirectory;
             if (!tmpAlreadyLoadedFiles.ContainsKey(localDirectory.Item2))
             {
                 tmpAlreadyLoadedFiles[localDirectory.Item2] = new HashSet <string>();
             }
             LongEventHandler.ExecuteWhenFinished(delegate
             {
                 if (icon == BaseContent.BadTex)
                 {
                     VirtualFile file = localDirectory.Item1.GetFile("LangIcon.png");
                     if (file.Exists)
                     {
                         icon = ModContentLoader <Texture2D> .LoadItem(file).contentItem;
                     }
                 }
             });
             VirtualDirectory directory = localDirectory.Item1.GetDirectory("CodeLinked");
             if (directory.Exists)
             {
                 loadErrors.Add("Translations aren't called CodeLinked any more. Please rename to Keyed: " + directory);
             }
             else
             {
                 directory = localDirectory.Item1.GetDirectory("Keyed");
             }
             if (directory.Exists)
             {
                 foreach (VirtualFile file2 in directory.GetFiles("*.xml", SearchOption.AllDirectories))
                 {
                     if (TryRegisterFileIfNew(localDirectory, file2.FullPath))
                     {
                         LoadFromFile_Keyed(file2);
                     }
                 }
             }
             VirtualDirectory directory2 = localDirectory.Item1.GetDirectory("DefLinked");
             if (directory2.Exists)
             {
                 loadErrors.Add("Translations aren't called DefLinked any more. Please rename to DefInjected: " + directory2);
             }
             else
             {
                 directory2 = localDirectory.Item1.GetDirectory("DefInjected");
             }
             if (directory2.Exists)
             {
                 foreach (VirtualDirectory directory4 in directory2.GetDirectories("*", SearchOption.TopDirectoryOnly))
                 {
                     string name = directory4.Name;
                     Type   typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name);
                     if (typeInAnyAssembly == null && name.Length > 3)
                     {
                         typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name.Substring(0, name.Length - 1));
                     }
                     if (typeInAnyAssembly == null)
                     {
                         loadErrors.Add(string.Concat("Error loading language from ", allDirectory, ": dir ", directory4.Name, " doesn't correspond to any def type. Skipping..."));
                         continue;
                     }
                     foreach (VirtualFile file3 in directory4.GetFiles("*.xml", SearchOption.AllDirectories))
                     {
                         if (TryRegisterFileIfNew(localDirectory, file3.FullPath))
                         {
                             LoadFromFile_DefInject(file3, typeInAnyAssembly);
                         }
                     }
                 }
             }
             EnsureAllDefTypesHaveDefInjectionPackage();
             VirtualDirectory directory3 = localDirectory.Item1.GetDirectory("Strings");
             if (directory3.Exists)
             {
                 foreach (VirtualDirectory directory5 in directory3.GetDirectories("*", SearchOption.TopDirectoryOnly))
                 {
                     foreach (VirtualFile file4 in directory5.GetFiles("*.txt", SearchOption.AllDirectories))
                     {
                         if (TryRegisterFileIfNew(localDirectory, file4.FullPath))
                         {
                             LoadFromFile_Strings(file4, directory3);
                         }
                     }
                 }
             }
             wordInfo.LoadFrom(localDirectory, this);
         }
     }
     catch (Exception arg)
     {
         Log.Error("Exception loading language data. Rethrowing. Exception: " + arg);
         throw;
     }
     finally
     {
         DeepProfiler.End();
     }
 }
Ejemplo n.º 13
0
 public static IEnumerable <Def> AllDefsFromAsset(LoadableXmlAsset asset)
 {
     if (DirectXmlLoader.loadingAsset != null)
     {
         Log.Error(string.Concat(new object[]
         {
             "Tried to load ",
             asset,
             " while loading ",
             DirectXmlLoader.loadingAsset,
             ". This will corrupt the internal state of DataLoader."
         }));
     }
     if (asset.xmlDoc != null)
     {
         DirectXmlLoader.loadingAsset = asset;
         XmlNodeList assetNodes = asset.xmlDoc.DocumentElement.ChildNodes;
         bool        gotData    = false;
         foreach (XmlNode node in assetNodes)
         {
             if (node.NodeType == XmlNodeType.Element)
             {
                 XmlAttribute abstractAtt = node.Attributes["Abstract"];
                 if (abstractAtt != null && abstractAtt.Value.ToLower() == "true")
                 {
                     gotData = true;
                 }
                 else
                 {
                     Type defType = GenTypes.GetTypeInAnyAssembly(node.Name);
                     if (defType != null)
                     {
                         if (typeof(Def).IsAssignableFrom(defType))
                         {
                             MethodInfo method = typeof(DirectXmlToObject).GetMethod("ObjectFromXml");
                             MethodInfo gen    = method.MakeGenericMethod(new Type[]
                             {
                                 defType
                             });
                             Def def = null;
                             try
                             {
                                 def = (Def)gen.Invoke(null, new object[]
                                 {
                                     node,
                                     true
                                 });
                                 gotData = true;
                             }
                             catch (Exception ex)
                             {
                                 Log.Error(string.Concat(new object[]
                                 {
                                     "Exception loading def from file ",
                                     asset.name,
                                     ": ",
                                     ex
                                 }));
                             }
                             if (def != null)
                             {
                                 yield return(def);
                             }
                         }
                     }
                 }
             }
         }
         if (!gotData)
         {
             Log.Error("Found no usable data when trying to get defs from file " + asset.name);
         }
         DirectXmlLoader.loadingAsset = null;
     }
 }
Ejemplo n.º 14
0
 public static object FromString(string str, Type itemType)
 {
     try
     {
         itemType = (Nullable.GetUnderlyingType(itemType) ?? itemType);
         if (itemType == typeof(string))
         {
             str = str.Replace("\\n", "\n");
             return(str);
         }
         if (itemType == typeof(int))
         {
             return(ParseIntPermissive(str));
         }
         if (itemType == typeof(float))
         {
             return(float.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(bool))
         {
             return(bool.Parse(str));
         }
         if (itemType == typeof(long))
         {
             return(long.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(double))
         {
             return(double.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(sbyte))
         {
             return(sbyte.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType.IsEnum)
         {
             try
             {
                 object obj = BackCompatibility.BackCompatibleEnum(itemType, str);
                 if (obj != null)
                 {
                     return(obj);
                 }
                 return(Enum.Parse(itemType, str));
             }
             catch (ArgumentException innerException)
             {
                 string str2 = "'" + str + "' is not a valid value for " + itemType + ". Valid values are: \n";
                 str2 += GenText.StringFromEnumerable(Enum.GetValues(itemType));
                 ArgumentException ex = new ArgumentException(str2, innerException);
                 throw ex;
             }
         }
         if (itemType == typeof(Type))
         {
             if (str == "null" || str == "Null")
             {
                 return(null);
             }
             Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);
             if (typeInAnyAssembly == null)
             {
                 Log.Error("Could not find a type named " + str);
             }
             return(typeInAnyAssembly);
         }
         if (itemType == typeof(Action))
         {
             string[] array      = str.Split('.');
             string   methodName = array[array.Length - 1];
             string   empty      = string.Empty;
             empty = ((array.Length != 3) ? array[0] : (array[0] + "." + array[1]));
             Type       typeInAnyAssembly2 = GenTypes.GetTypeInAnyAssembly(empty);
             MethodInfo method             = typeInAnyAssembly2.GetMethods().First((MethodInfo m) => m.Name == methodName);
             return((Action)Delegate.CreateDelegate(typeof(Action), method));
         }
         if (itemType == typeof(Vector3))
         {
             return(FromStringVector3(str));
         }
         if (itemType == typeof(Vector2))
         {
             return(FromStringVector2(str));
         }
         if (itemType == typeof(Rect))
         {
             return(FromStringRect(str));
         }
         if (itemType == typeof(Color))
         {
             str = str.TrimStart('(', 'R', 'G', 'B', 'A');
             str = str.TrimEnd(')');
             string[] array2 = str.Split(',');
             float    num    = (float)FromString(array2[0], typeof(float));
             float    num2   = (float)FromString(array2[1], typeof(float));
             float    num3   = (float)FromString(array2[2], typeof(float));
             bool     flag   = num > 1f || num3 > 1f || num2 > 1f;
             float    num4   = (float)((!flag) ? 1 : 255);
             if (array2.Length == 4)
             {
                 num4 = (float)FromString(array2[3], typeof(float));
             }
             Color color = default(Color);
             if (!flag)
             {
                 color.r = num;
                 color.g = num2;
                 color.b = num3;
                 color.a = num4;
             }
             else
             {
                 color = GenColor.FromBytes(Mathf.RoundToInt(num), Mathf.RoundToInt(num2), Mathf.RoundToInt(num3), Mathf.RoundToInt(num4));
             }
             return(color);
         }
         if (itemType == typeof(PublishedFileId_t))
         {
             return(new PublishedFileId_t(ulong.Parse(str)));
         }
         if (itemType == typeof(IntVec2))
         {
             return(IntVec2.FromString(str));
         }
         if (itemType == typeof(IntVec3))
         {
             return(IntVec3.FromString(str));
         }
         if (itemType == typeof(Rot4))
         {
             return(Rot4.FromString(str));
         }
         if (itemType == typeof(CellRect))
         {
             return(CellRect.FromString(str));
         }
         if (itemType != typeof(CurvePoint))
         {
             if (itemType == typeof(NameTriple))
             {
                 NameTriple nameTriple = NameTriple.FromString(str);
                 nameTriple.ResolveMissingPieces();
             }
             else
             {
                 if (itemType == typeof(FloatRange))
                 {
                     return(FloatRange.FromString(str));
                 }
                 if (itemType == typeof(IntRange))
                 {
                     return(IntRange.FromString(str));
                 }
                 if (itemType == typeof(QualityRange))
                 {
                     return(QualityRange.FromString(str));
                 }
                 if (itemType == typeof(ColorInt))
                 {
                     str = str.TrimStart('(', 'R', 'G', 'B', 'A');
                     str = str.TrimEnd(')');
                     string[] array3   = str.Split(',');
                     ColorInt colorInt = new ColorInt(255, 255, 255, 255);
                     colorInt.r = (int)FromString(array3[0], typeof(int));
                     colorInt.g = (int)FromString(array3[1], typeof(int));
                     colorInt.b = (int)FromString(array3[2], typeof(int));
                     if (array3.Length == 4)
                     {
                         colorInt.a = (int)FromString(array3[3], typeof(int));
                     }
                     else
                     {
                         colorInt.a = 255;
                     }
                     return(colorInt);
                 }
             }
             throw new ArgumentException("Trying to parse to unknown data type " + itemType.Name + ". Content is '" + str + "'.");
         }
         return(CurvePoint.FromString(str));
     }
     catch (Exception innerException2)
     {
         ArgumentException ex2 = new ArgumentException("Exception parsing " + itemType + " from \"" + str + "\"", innerException2);
         throw ex2;
     }
 }
Ejemplo n.º 15
0
 public void LoadData()
 {
     if (this.dataIsLoaded)
     {
         return;
     }
     this.dataIsLoaded = true;
     DeepProfiler.Start("Loading language data: " + this.folderName);
     try
     {
         foreach (string current in this.FolderPaths)
         {
             string localFolderPath = current;
             LongEventHandler.ExecuteWhenFinished(delegate
             {
                 if (this.icon == BaseContent.BadTex)
                 {
                     FileInfo fileInfo = new FileInfo(Path.Combine(localFolderPath.ToString(), "LangIcon.png"));
                     if (fileInfo.Exists)
                     {
                         this.icon = ModContentLoader <Texture2D> .LoadItem(fileInfo.FullName, null).contentItem;
                     }
                 }
             });
             DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(current.ToString(), "CodeLinked"));
             if (directoryInfo.Exists)
             {
                 this.loadErrors.Add("Translations aren't called CodeLinked any more. Please rename to Keyed: " + directoryInfo);
             }
             else
             {
                 directoryInfo = new DirectoryInfo(Path.Combine(current.ToString(), "Keyed"));
             }
             if (directoryInfo.Exists)
             {
                 FileInfo[] files = directoryInfo.GetFiles("*.xml", SearchOption.AllDirectories);
                 for (int i = 0; i < files.Length; i++)
                 {
                     FileInfo file = files[i];
                     this.LoadFromFile_Keyed(file);
                 }
             }
             DirectoryInfo directoryInfo2 = new DirectoryInfo(Path.Combine(current.ToString(), "DefLinked"));
             if (directoryInfo2.Exists)
             {
                 this.loadErrors.Add("Translations aren't called DefLinked any more. Please rename to DefInjected: " + directoryInfo2);
             }
             else
             {
                 directoryInfo2 = new DirectoryInfo(Path.Combine(current.ToString(), "DefInjected"));
             }
             if (directoryInfo2.Exists)
             {
                 DirectoryInfo[] directories = directoryInfo2.GetDirectories("*", SearchOption.TopDirectoryOnly);
                 for (int j = 0; j < directories.Length; j++)
                 {
                     DirectoryInfo directoryInfo3    = directories[j];
                     string        name              = directoryInfo3.Name;
                     Type          typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name);
                     if (typeInAnyAssembly == null && name.Length > 3)
                     {
                         typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name.Substring(0, name.Length - 1));
                     }
                     if (typeInAnyAssembly == null)
                     {
                         this.loadErrors.Add(string.Concat(new string[]
                         {
                             "Error loading language from ",
                             current,
                             ": dir ",
                             directoryInfo3.Name,
                             " doesn't correspond to any def type. Skipping..."
                         }));
                     }
                     else
                     {
                         FileInfo[] files2 = directoryInfo3.GetFiles("*.xml", SearchOption.AllDirectories);
                         for (int k = 0; k < files2.Length; k++)
                         {
                             FileInfo file2 = files2[k];
                             this.LoadFromFile_DefInject(file2, typeInAnyAssembly);
                         }
                     }
                 }
             }
             this.EnsureAllDefTypesHaveDefInjectionPackage();
             DirectoryInfo directoryInfo4 = new DirectoryInfo(Path.Combine(current.ToString(), "Strings"));
             if (directoryInfo4.Exists)
             {
                 DirectoryInfo[] directories2 = directoryInfo4.GetDirectories("*", SearchOption.TopDirectoryOnly);
                 for (int l = 0; l < directories2.Length; l++)
                 {
                     DirectoryInfo directoryInfo5 = directories2[l];
                     FileInfo[]    files3         = directoryInfo5.GetFiles("*.txt", SearchOption.AllDirectories);
                     for (int m = 0; m < files3.Length; m++)
                     {
                         FileInfo file3 = files3[m];
                         this.LoadFromFile_Strings(file3, directoryInfo4);
                     }
                 }
             }
             this.wordInfo.LoadFrom(current);
         }
     }
     catch (Exception arg)
     {
         Log.Error("Exception loading language data. Rethrowing. Exception: " + arg, false);
         throw;
     }
     finally
     {
         DeepProfiler.End();
     }
 }
Ejemplo n.º 16
0
 public void LoadData()
 {
     if (!this.dataIsLoaded)
     {
         this.dataIsLoaded = true;
         DeepProfiler.Start("Loading language data: " + this.folderName);
         foreach (string folderPath in this.FolderPaths)
         {
             string localFolderPath = folderPath;
             LongEventHandler.ExecuteWhenFinished(delegate
             {
                 if ((UnityEngine.Object) this.icon == (UnityEngine.Object)BaseContent.BadTex)
                 {
                     FileInfo fileInfo = new FileInfo(Path.Combine(localFolderPath.ToString(), "LangIcon.png"));
                     if (fileInfo.Exists)
                     {
                         this.icon = ModContentLoader <Texture2D> .LoadItem(fileInfo.FullName, null).contentItem;
                     }
                 }
             });
             DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(folderPath.ToString(), "CodeLinked"));
             if (directoryInfo.Exists)
             {
                 Log.Warning("Translations aren't called CodeLinked any more. Please rename to Keyed: " + directoryInfo);
             }
             else
             {
                 directoryInfo = new DirectoryInfo(Path.Combine(folderPath.ToString(), "Keyed"));
             }
             if (directoryInfo.Exists)
             {
                 FileInfo[] files = directoryInfo.GetFiles("*.xml", SearchOption.AllDirectories);
                 foreach (FileInfo file in files)
                 {
                     this.LoadFromFile_Keyed(file);
                 }
             }
             DirectoryInfo directoryInfo2 = new DirectoryInfo(Path.Combine(folderPath.ToString(), "DefLinked"));
             if (directoryInfo2.Exists)
             {
                 Log.Warning("Translations aren't called DefLinked any more. Please rename to DefInjected: " + directoryInfo2);
             }
             else
             {
                 directoryInfo2 = new DirectoryInfo(Path.Combine(folderPath.ToString(), "DefInjected"));
             }
             if (directoryInfo2.Exists)
             {
                 DirectoryInfo[] directories = directoryInfo2.GetDirectories("*", SearchOption.TopDirectoryOnly);
                 foreach (DirectoryInfo directoryInfo3 in directories)
                 {
                     string name = directoryInfo3.Name;
                     Type   typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name);
                     if (typeInAnyAssembly == null && name.Length > 3)
                     {
                         typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name.Substring(0, name.Length - 1));
                     }
                     if (typeInAnyAssembly == null)
                     {
                         Log.Warning("Error loading language from " + folderPath + ": dir " + directoryInfo3.Name + " doesn't correspond to any def type. Skipping...");
                     }
                     else
                     {
                         FileInfo[] files2 = directoryInfo3.GetFiles("*.xml", SearchOption.AllDirectories);
                         foreach (FileInfo file2 in files2)
                         {
                             this.LoadFromFile_DefInject(file2, typeInAnyAssembly);
                         }
                     }
                 }
             }
             DirectoryInfo directoryInfo4 = new DirectoryInfo(Path.Combine(folderPath.ToString(), "Strings"));
             if (directoryInfo4.Exists)
             {
                 DirectoryInfo[] directories2 = directoryInfo4.GetDirectories("*", SearchOption.TopDirectoryOnly);
                 foreach (DirectoryInfo directoryInfo5 in directories2)
                 {
                     FileInfo[] files3 = directoryInfo5.GetFiles("*.txt", SearchOption.AllDirectories);
                     foreach (FileInfo file3 in files3)
                     {
                         this.LoadFromFile_Strings(file3, directoryInfo4);
                     }
                 }
             }
         }
         DeepProfiler.End();
     }
 }
Ejemplo n.º 17
0
        public static IEnumerable <Def> AllDefsFromAsset(LoadableXmlAsset asset)
        {
            if (DirectXmlLoader.loadingAsset != null)
            {
                Log.Error("Tried to load " + asset + " while loading " + DirectXmlLoader.loadingAsset + ". This will corrupt the internal state of DataLoader.");
            }
            if (asset.xmlDoc != null)
            {
                DirectXmlLoader.loadingAsset = asset;
                XmlNodeList assetNodes = asset.xmlDoc.DocumentElement.ChildNodes;
                bool        gotData    = false;
                IEnumerator enumerator = assetNodes.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        XmlNode node = (XmlNode)enumerator.Current;
                        if (node.NodeType == XmlNodeType.Element)
                        {
                            XmlAttribute abstractAtt = node.Attributes["Abstract"];
                            if (abstractAtt != null && abstractAtt.Value.ToLower() == "true")
                            {
                                gotData = true;
                            }
                            else
                            {
                                Type defType = GenTypes.GetTypeInAnyAssembly(node.Name);
                                if (defType != null && typeof(Def).IsAssignableFrom(defType))
                                {
                                    MethodInfo method = typeof(DirectXmlToObject).GetMethod("ObjectFromXml");
                                    MethodInfo gen    = method.MakeGenericMethod(defType);
                                    Def        def    = null;
                                    try
                                    {
                                        def = (Def)gen.Invoke(null, new object[2]
                                        {
                                            node,
                                            true
                                        });
                                        gotData = true;
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error("Exception loading def from file " + asset.name + ": " + ex);
                                    }
                                    if (def != null)
                                    {
                                        yield return(def);

                                        /*Error: Unable to find new state assignment for yield return*/;
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    IDisposable disposable;
                    IDisposable disposable2 = disposable = (enumerator as IDisposable);
                    if (disposable != null)
                    {
                        disposable2.Dispose();
                    }
                }
                if (!gotData)
                {
                    Log.Error("Found no usable data when trying to get defs from file " + asset.name);
                }
                DirectXmlLoader.loadingAsset = null;
            }
            yield break;
IL_02e2:
            /*Error near IL_02e3: Unexpected return in MoveNext()*/;
        }
Ejemplo n.º 18
0
        public static object FromString(string str, Type itemType)
        {
            object result;

            try
            {
                itemType = (Nullable.GetUnderlyingType(itemType) ?? itemType);
                if (itemType == typeof(string))
                {
                    str    = str.Replace("\\n", "\n");
                    result = str;
                }
                else if (itemType == typeof(int))
                {
                    result = int.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(float))
                {
                    result = float.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(bool))
                {
                    result = bool.Parse(str);
                }
                else if (itemType == typeof(long))
                {
                    result = long.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(double))
                {
                    result = double.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(sbyte))
                {
                    result = sbyte.Parse(str, CultureInfo.InvariantCulture);
                }
                else
                {
                    if (itemType.IsEnum)
                    {
                        try
                        {
                            result = Enum.Parse(itemType, str);
                            return(result);
                        }
                        catch (ArgumentException innerException)
                        {
                            string text = string.Concat(new object[]
                            {
                                "'",
                                str,
                                "' is not a valid value for ",
                                itemType,
                                ". Valid values are: \n"
                            });
                            text += GenText.StringFromEnumerable(Enum.GetValues(itemType));
                            ArgumentException ex = new ArgumentException(text, innerException);
                            throw ex;
                        }
                    }
                    if (itemType == typeof(Type))
                    {
                        if (str == "null" || str == "Null")
                        {
                            result = null;
                        }
                        else
                        {
                            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);
                            if (typeInAnyAssembly == null)
                            {
                                Log.Error("Could not find a type named " + str);
                            }
                            result = typeInAnyAssembly;
                        }
                    }
                    else if (itemType == typeof(Action))
                    {
                        string[] array = str.Split(new char[]
                        {
                            '.'
                        });
                        string methodName = array[array.Length - 1];
                        string typeName   = string.Empty;
                        if (array.Length == 3)
                        {
                            typeName = array[0] + "." + array[1];
                        }
                        else
                        {
                            typeName = array[0];
                        }
                        Type       typeInAnyAssembly2 = GenTypes.GetTypeInAnyAssembly(typeName);
                        MethodInfo method             = typeInAnyAssembly2.GetMethods().First((MethodInfo m) => m.Name == methodName);
                        result = (Action)Delegate.CreateDelegate(typeof(Action), method);
                    }
                    else if (itemType == typeof(Vector3))
                    {
                        result = ParseHelper.FromStringVector3(str);
                    }
                    else if (itemType == typeof(Vector2))
                    {
                        result = ParseHelper.FromStringVector2(str);
                    }
                    else if (itemType == typeof(Rect))
                    {
                        result = ParseHelper.FromStringRect(str);
                    }
                    else if (itemType == typeof(Color))
                    {
                        str = str.TrimStart(new char[]
                        {
                            '(',
                            'R',
                            'G',
                            'B',
                            'A'
                        });
                        str = str.TrimEnd(new char[]
                        {
                            ')'
                        });
                        string[] array2 = str.Split(new char[]
                        {
                            ','
                        });
                        float num  = (float)ParseHelper.FromString(array2[0], typeof(float));
                        float num2 = (float)ParseHelper.FromString(array2[1], typeof(float));
                        float num3 = (float)ParseHelper.FromString(array2[2], typeof(float));
                        bool  flag = num > 1f || num3 > 1f || num2 > 1f;
                        float num4 = (float)((!flag) ? 1 : 255);
                        if (array2.Length == 4)
                        {
                            num4 = (float)ParseHelper.FromString(array2[3], typeof(float));
                        }
                        Color color;
                        if (!flag)
                        {
                            color.r = num;
                            color.g = num2;
                            color.b = num3;
                            color.a = num4;
                        }
                        else
                        {
                            color = GenColor.FromBytes(Mathf.RoundToInt(num), Mathf.RoundToInt(num2), Mathf.RoundToInt(num3), Mathf.RoundToInt(num4));
                        }
                        result = color;
                    }
                    else if (itemType == typeof(PublishedFileId_t))
                    {
                        result = new PublishedFileId_t(ulong.Parse(str));
                    }
                    else if (itemType == typeof(IntVec2))
                    {
                        result = IntVec2.FromString(str);
                    }
                    else if (itemType == typeof(IntVec3))
                    {
                        result = IntVec3.FromString(str);
                    }
                    else if (itemType == typeof(Rot4))
                    {
                        result = Rot4.FromString(str);
                    }
                    else if (itemType == typeof(CellRect))
                    {
                        result = CellRect.FromString(str);
                    }
                    else
                    {
                        if (itemType != typeof(CurvePoint))
                        {
                            if (itemType == typeof(NameTriple))
                            {
                                NameTriple nameTriple = NameTriple.FromString(str);
                                nameTriple.ResolveMissingPieces(null);
                            }
                            else
                            {
                                if (itemType == typeof(FloatRange))
                                {
                                    result = FloatRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(IntRange))
                                {
                                    result = IntRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(QualityRange))
                                {
                                    result = QualityRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(ColorInt))
                                {
                                    str = str.TrimStart(new char[]
                                    {
                                        '(',
                                        'R',
                                        'G',
                                        'B',
                                        'A'
                                    });
                                    str = str.TrimEnd(new char[]
                                    {
                                        ')'
                                    });
                                    string[] array3 = str.Split(new char[]
                                    {
                                        ','
                                    });
                                    ColorInt colorInt = new ColorInt(255, 255, 255, 255);
                                    colorInt.r = (int)ParseHelper.FromString(array3[0], typeof(int));
                                    colorInt.g = (int)ParseHelper.FromString(array3[1], typeof(int));
                                    colorInt.b = (int)ParseHelper.FromString(array3[2], typeof(int));
                                    if (array3.Length == 4)
                                    {
                                        colorInt.a = (int)ParseHelper.FromString(array3[3], typeof(int));
                                    }
                                    else
                                    {
                                        colorInt.a = 255;
                                    }
                                    result = colorInt;
                                    return(result);
                                }
                            }
                            throw new ArgumentException(string.Concat(new string[]
                            {
                                "Trying to parse to unknown data type ",
                                itemType.Name,
                                ". Content is '",
                                str,
                                "'."
                            }));
                        }
                        result = CurvePoint.FromString(str);
                    }
                }
            }
            catch (Exception innerException2)
            {
                ArgumentException ex2 = new ArgumentException(string.Concat(new object[]
                {
                    "Exception parsing ",
                    itemType,
                    " from \"",
                    str,
                    "\""
                }), innerException2);
                throw ex2;
            }
            return(result);
        }
Ejemplo n.º 19
0
 public void LoadData()
 {
     if (this.dataIsLoaded)
     {
         return;
     }
     this.dataIsLoaded = true;
     DeepProfiler.Start("Loading language data: " + this.folderName);
     foreach (string text in this.FolderPaths)
     {
         string localFolderPath = text;
         LongEventHandler.ExecuteWhenFinished(delegate
         {
             if (this.icon == BaseContent.BadTex)
             {
                 FileInfo fileInfo = new FileInfo(Path.Combine(localFolderPath.ToString(), "LangIcon.png"));
                 if (fileInfo.Exists)
                 {
                     this.icon = ModContentLoader <Texture2D> .LoadItem(fileInfo.FullName, null).contentItem;
                 }
             }
         });
         DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(text.ToString(), "CodeLinked"));
         if (directoryInfo.Exists)
         {
             this.loadErrors.Add("Translations aren't called CodeLinked any more. Please rename to Keyed: " + directoryInfo);
         }
         else
         {
             directoryInfo = new DirectoryInfo(Path.Combine(text.ToString(), "Keyed"));
         }
         if (directoryInfo.Exists)
         {
             foreach (FileInfo file in directoryInfo.GetFiles("*.xml", SearchOption.AllDirectories))
             {
                 this.LoadFromFile_Keyed(file);
             }
         }
         DirectoryInfo directoryInfo2 = new DirectoryInfo(Path.Combine(text.ToString(), "DefLinked"));
         if (directoryInfo2.Exists)
         {
             this.loadErrors.Add("Translations aren't called DefLinked any more. Please rename to DefInjected: " + directoryInfo2);
         }
         else
         {
             directoryInfo2 = new DirectoryInfo(Path.Combine(text.ToString(), "DefInjected"));
         }
         if (directoryInfo2.Exists)
         {
             foreach (DirectoryInfo directoryInfo3 in directoryInfo2.GetDirectories("*", SearchOption.TopDirectoryOnly))
             {
                 string name = directoryInfo3.Name;
                 Type   typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name);
                 if (typeInAnyAssembly == null && name.Length > 3)
                 {
                     typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name.Substring(0, name.Length - 1));
                 }
                 if (typeInAnyAssembly == null)
                 {
                     this.loadErrors.Add(string.Concat(new string[]
                     {
                         "Error loading language from ",
                         text,
                         ": dir ",
                         directoryInfo3.Name,
                         " doesn't correspond to any def type. Skipping..."
                     }));
                 }
                 else
                 {
                     foreach (FileInfo file2 in directoryInfo3.GetFiles("*.xml", SearchOption.AllDirectories))
                     {
                         this.LoadFromFile_DefInject(file2, typeInAnyAssembly);
                     }
                 }
             }
         }
         this.EnsureAllDefTypesHaveDefInjectionPackage();
         DirectoryInfo directoryInfo4 = new DirectoryInfo(Path.Combine(text.ToString(), "Strings"));
         if (directoryInfo4.Exists)
         {
             foreach (DirectoryInfo directoryInfo5 in directoryInfo4.GetDirectories("*", SearchOption.TopDirectoryOnly))
             {
                 foreach (FileInfo file3 in directoryInfo5.GetFiles("*.txt", SearchOption.AllDirectories))
                 {
                     this.LoadFromFile_Strings(file3, directoryInfo4);
                 }
             }
         }
     }
     DeepProfiler.End();
 }