コード例 #1
0
 public Dialog_DebugOutputMenu()
 {
     forcePause = true;
     foreach (Type item in GenTypes.AllTypesWithAttribute <HasDebugOutputAttribute>())
     {
         MethodInfo[] methods = item.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
         foreach (MethodInfo mi in methods)
         {
             if (mi.TryGetAttribute(out DebugOutputAttribute _))
             {
                 string label  = GenText.SplitCamelCase(mi.Name);
                 Action action = delegate
                 {
                     mi.Invoke(null, null);
                 };
                 CategoryAttribute customAttribute2 = null;
                 string            category         = (!mi.TryGetAttribute(out customAttribute2)) ? "General" : customAttribute2.name;
                 debugOutputs.Add(new DebugOutputOption
                 {
                     label    = label,
                     category = category,
                     action   = action
                 });
             }
         }
     }
     debugOutputs = (from r in debugOutputs
                     orderby r.category, r.label
                     select r).ToList();
 }
コード例 #2
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);
            }
        }
コード例 #3
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);
        }
コード例 #4
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));
        }
        public static void CallAll()
        {
            IEnumerable <Type> enumerable = GenTypes.AllTypesWithAttribute <StaticConstructorOnStartup>();

            foreach (Type item in enumerable)
            {
                RuntimeHelpers.RunClassConstructor(item.TypeHandle);
            }
            StaticConstructorOnStartupUtility.coreStaticAssetsLoaded = true;
        }
コード例 #6
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);
        }
 public static void CallAll()
 {
     foreach (Type item in GenTypes.AllTypesWithAttribute <StaticConstructorOnStartup>())
     {
         try
         {
             RuntimeHelpers.RunClassConstructor(item.TypeHandle);
         }
         catch (Exception ex)
         {
             Log.Error(string.Concat("Error in static constructor of ", item, ": ", ex));
         }
     }
     coreStaticAssetsLoaded = true;
 }
コード例 #8
0
        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));
        }
コード例 #9
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);
            }
        }
コード例 #10
0
        public static Type GetTypeInAnyAssembly(string typeName)
        {
            Type typeInAnyAssemblyRaw = GenTypes.GetTypeInAnyAssemblyRaw(typeName);

            if (typeInAnyAssemblyRaw != null)
            {
                return(typeInAnyAssemblyRaw);
            }
            for (int i = 0; i < GenTypes.IgnoredNamespaceNames.Count; i++)
            {
                string typeName2 = GenTypes.IgnoredNamespaceNames[i] + "." + typeName;
                typeInAnyAssemblyRaw = GenTypes.GetTypeInAnyAssemblyRaw(typeName2);
                if (typeInAnyAssemblyRaw != null)
                {
                    return(typeInAnyAssemblyRaw);
                }
            }
            return(null);
        }
コード例 #11
0
ファイル: DirectXmlLoader.cs プロジェクト: potsh/RimWorld
        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);
        }
コード例 #12
0
 public Dialog_DebugOutputMenu()
 {
     this.forcePause = true;
     foreach (Type current in GenTypes.AllTypesWithAttribute <HasDebugOutputAttribute>())
     {
         MethodInfo[] methods = current.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
         for (int i = 0; i < methods.Length; i++)
         {
             MethodInfo           mi = methods[i];
             DebugOutputAttribute debugOutputAttribute;
             if (mi.TryGetAttribute(out debugOutputAttribute))
             {
                 string label  = GenText.SplitCamelCase(mi.Name);
                 Action action = delegate
                 {
                     mi.Invoke(null, null);
                 };
                 CategoryAttribute categoryAttribute = null;
                 string            category;
                 if (mi.TryGetAttribute(out categoryAttribute))
                 {
                     category = categoryAttribute.name;
                 }
                 else
                 {
                     category = "General";
                 }
                 this.debugOutputs.Add(new Dialog_DebugOutputMenu.DebugOutputOption
                 {
                     label    = label,
                     category = category,
                     action   = action
                 });
             }
         }
     }
     this.debugOutputs = (from r in this.debugOutputs
                          orderby r.category, r.label
                          select r).ToList <Dialog_DebugOutputMenu.DebugOutputOption>();
 }
コード例 #13
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));
 }
コード例 #14
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));
 }
コード例 #15
0
        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);
        }
コード例 #16
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);
            }
        }
コード例 #17
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;
     }
 }
コード例 #18
0
ファイル: ParseHelper.cs プロジェクト: potsh/RimWorld
 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;
     }
 }
コード例 #19
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();
     }
 }
コード例 #20
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();
     }
 }
コード例 #21
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();
     }
 }
コード例 #22
0
ファイル: DirectXmlSaver.cs プロジェクト: potsh/RimWorld
        public static XElement XElementFromObject(object obj, Type expectedType, string nodeName, FieldInfo owningField = null, bool saveDefsAsRefs = false)
        {
            DefaultValueAttribute customAttribute;

            if (owningField != null && owningField.TryGetAttribute(out customAttribute) && customAttribute.ObjIsDefault(obj))
            {
                return(null);
            }
            if (obj == null)
            {
                XElement xElement = new XElement(nodeName);
                xElement.SetAttributeValue("IsNull", "True");
                return(xElement);
            }
            Type     type      = obj.GetType();
            XElement xElement2 = new XElement(nodeName);

            if (IsSimpleTextType(type))
            {
                xElement2.Add(new XText(obj.ToString()));
            }
            else if (saveDefsAsRefs && typeof(Def).IsAssignableFrom(type))
            {
                string defName = ((Def)obj).defName;
                xElement2.Add(new XText(defName));
            }
            else
            {
                if (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(List <>))
                {
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <, >))
                    {
                        Type        expectedType2 = type.GetGenericArguments()[0];
                        Type        expectedType3 = type.GetGenericArguments()[1];
                        IEnumerator enumerator    = (obj as IEnumerable).GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                object   current   = enumerator.Current;
                                object   value     = current.GetType().GetProperty("Key").GetValue(current, null);
                                object   value2    = current.GetType().GetProperty("Value").GetValue(current, null);
                                XElement xElement3 = new XElement("li");
                                xElement3.Add(XElementFromObject(value, expectedType2, "key", null, saveDefsAsRefs: true));
                                xElement3.Add(XElementFromObject(value2, expectedType3, "value", null, saveDefsAsRefs: true));
                                xElement2.Add(xElement3);
                            }
                            return(xElement2);
                        }
                        finally
                        {
                            IDisposable disposable;
                            if ((disposable = (enumerator as IDisposable)) != null)
                            {
                                disposable.Dispose();
                            }
                        }
                    }
                    if (type != expectedType)
                    {
                        XAttribute content = new XAttribute("Class", GenTypes.GetTypeNameWithoutIgnoredNamespaces(obj.GetType()));
                        xElement2.Add(content);
                    }
                    {
                        foreach (FieldInfo item in from f in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                 orderby f.MetadataToken
                                 select f)
                        {
                            try
                            {
                                XElement xElement4 = XElementFromField(item, obj);
                                if (xElement4 != null)
                                {
                                    xElement2.Add(xElement4);
                                }
                            }
                            catch
                            {
                                throw;
                            }
                        }
                        return(xElement2);
                    }
                }
                Type expectedType4 = type.GetGenericArguments()[0];
                int  num           = (int)type.GetProperty("Count").GetValue(obj, null);
                for (int i = 0; i < num; i++)
                {
                    object[] index = new object[1]
                    {
                        i
                    };
                    object value3   = type.GetProperty("Item").GetValue(obj, index);
                    XNode  content2 = XElementFromObject(value3, expectedType4, "li", null, saveDefsAsRefs: true);
                    xElement2.Add(content2);
                }
            }
            return(xElement2);
        }
コード例 #23
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()*/;
        }
コード例 #24
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();
 }
コード例 #25
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);
        }
コード例 #26
0
 public static void Look <T>(ref T target, bool saveDestroyedThings, string label, params object[] ctorArgs)
 {
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         Thing thing = target as Thing;
         if (thing != null && thing.Destroyed)
         {
             if (!saveDestroyedThings)
             {
                 Log.Warning(string.Concat(new object[]
                 {
                     "Deep-saving destroyed thing ",
                     thing,
                     " with saveDestroyedThings==false. label=",
                     label
                 }), false);
             }
             else if (thing.Discarded)
             {
                 Log.Warning(string.Concat(new object[]
                 {
                     "Deep-saving discarded thing ",
                     thing,
                     ". This mode means that the thing is no longer managed by anything in the code and should not be deep-saved anywhere. (even with saveDestroyedThings==true) , label=",
                     label
                 }), false);
             }
         }
         IExposable exposable = target as IExposable;
         if (target != null && exposable == null)
         {
             Log.Error(string.Concat(new object[]
             {
                 "Cannot use LookDeep to save non-IExposable non-null ",
                 label,
                 " of type ",
                 typeof(T)
             }), false);
             return;
         }
         if (target == null)
         {
             if (Scribe.EnterNode(label))
             {
                 try
                 {
                     Scribe.saver.WriteAttribute("IsNull", "True");
                 }
                 finally
                 {
                     Scribe.ExitNode();
                 }
             }
         }
         else if (Scribe.EnterNode(label))
         {
             try
             {
                 if (target.GetType() != typeof(T) || typeof(T).IsGenericTypeDefinition)
                 {
                     Scribe.saver.WriteAttribute("Class", GenTypes.GetTypeNameWithoutIgnoredNamespaces(target.GetType()));
                 }
                 exposable.ExposeData();
             }
             catch (OutOfMemoryException)
             {
                 throw;
             }
             catch (Exception ex)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Exception while saving ",
                     exposable.ToStringSafe <IExposable>(),
                     ": ",
                     ex
                 }), false);
             }
             finally
             {
                 Scribe.ExitNode();
             }
         }
         Scribe.saver.loadIDsErrorsChecker.RegisterDeepSaved(target, label);
     }
     else if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         try
         {
             target = ScribeExtractor.SaveableFromNode <T>(Scribe.loader.curXmlParent[label], ctorArgs);
         }
         catch (Exception ex2)
         {
             Log.Error(string.Concat(new object[]
             {
                 "Exception while loading ",
                 Scribe.loader.curXmlParent[label].ToStringSafe <XmlElement>(),
                 ": ",
                 ex2
             }), false);
             target = default(T);
         }
     }
 }
コード例 #27
0
 private static void ForEachPossibleDefInjectionInDefRecursive(object obj, string curNormalizedPath, string curSuggestedPath, HashSet <object> visited, bool translationAllowed, Def def, PossibleDefInjectionTraverser action)
 {
     if (obj == null || (!obj.GetType().IsValueType&& visited.Contains(obj)))
     {
         return;
     }
     visited.Add(obj);
     foreach (FieldInfo item in FieldsInDeterministicOrder(obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)))
     {
         object value = item.GetValue(obj);
         bool   flag  = translationAllowed && !item.HasAttribute <NoTranslateAttribute>() && !item.HasAttribute <UnsavedAttribute>();
         if (value is Def)
         {
             continue;
         }
         if (typeof(string).IsAssignableFrom(item.FieldType))
         {
             string currentValue  = (string)value;
             string text          = curNormalizedPath + "." + item.Name;
             string suggestedPath = curSuggestedPath + "." + item.Name;
             if (TKeySystem.TrySuggestTKeyPath(text, out var tKeyPath))
             {
                 suggestedPath = tKeyPath;
             }
             action(suggestedPath, text, isCollection: false, currentValue, null, flag, fullListTranslationAllowed: false, item, def);
         }
         else if (value is IEnumerable <string> )
         {
             IEnumerable <string> currentValueCollection = (IEnumerable <string>)value;
             bool   flag2          = item.HasAttribute <TranslationCanChangeCountAttribute>();
             string text2          = curNormalizedPath + "." + item.Name;
             string suggestedPath2 = curSuggestedPath + "." + item.Name;
             if (TKeySystem.TrySuggestTKeyPath(text2, out var tKeyPath2))
             {
                 suggestedPath2 = tKeyPath2;
             }
             action(suggestedPath2, text2, isCollection: true, null, currentValueCollection, flag, flag && flag2, item, def);
         }
         else if (value is IEnumerable)
         {
             IEnumerable enumerable = (IEnumerable)value;
             int         num        = 0;
             foreach (object item2 in enumerable)
             {
                 if (item2 != null && !(item2 is Def) && GenTypes.IsCustomType(item2.GetType()))
                 {
                     string text3 = TranslationHandleUtility.GetBestHandleWithIndexForListElement(enumerable, item2);
                     if (text3.NullOrEmpty())
                     {
                         text3 = num.ToString();
                     }
                     string curNormalizedPath2 = curNormalizedPath + "." + item.Name + "." + num;
                     string curSuggestedPath2  = curSuggestedPath + "." + item.Name + "." + text3;
                     ForEachPossibleDefInjectionInDefRecursive(item2, curNormalizedPath2, curSuggestedPath2, visited, flag, def, action);
                 }
                 num++;
             }
         }
         else if (value != null && GenTypes.IsCustomType(value.GetType()))
         {
             string curNormalizedPath3 = curNormalizedPath + "." + item.Name;
             string curSuggestedPath3  = curSuggestedPath + "." + item.Name;
             ForEachPossibleDefInjectionInDefRecursive(value, curNormalizedPath3, curSuggestedPath3, visited, flag, def, action);
         }
     }
 }
コード例 #28
0
 private static void ForEachPossibleDefInjectionInDefRecursive(object obj, string curNormalizedPath, string curSuggestedPath, HashSet <object> visited, bool translationAllowed, Def def, DefInjectionUtility.PossibleDefInjectionTraverser action)
 {
     if (obj == null)
     {
         return;
     }
     if (visited.Contains(obj))
     {
         return;
     }
     visited.Add(obj);
     foreach (FieldInfo fieldInfo in DefInjectionUtility.FieldsInDeterministicOrder(obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)))
     {
         object value = fieldInfo.GetValue(obj);
         bool   flag  = translationAllowed && !fieldInfo.HasAttribute <NoTranslateAttribute>() && !fieldInfo.HasAttribute <UnsavedAttribute>();
         if (!(value is Def))
         {
             if (typeof(string).IsAssignableFrom(fieldInfo.FieldType))
             {
                 string currentValue   = (string)value;
                 string normalizedPath = curNormalizedPath + "." + fieldInfo.Name;
                 string suggestedPath  = curSuggestedPath + "." + fieldInfo.Name;
                 action(suggestedPath, normalizedPath, false, currentValue, null, flag, false, fieldInfo, def);
             }
             else if (value is IEnumerable <string> )
             {
                 IEnumerable <string> currentValueCollection = (IEnumerable <string>)value;
                 bool   flag2           = fieldInfo.HasAttribute <TranslationCanChangeCountAttribute>();
                 string normalizedPath2 = curNormalizedPath + "." + fieldInfo.Name;
                 string suggestedPath2  = curSuggestedPath + "." + fieldInfo.Name;
                 action(suggestedPath2, normalizedPath2, true, null, currentValueCollection, flag, flag && flag2, fieldInfo, def);
             }
             else if (value is IEnumerable)
             {
                 IEnumerable enumerable  = (IEnumerable)value;
                 int         num         = 0;
                 IEnumerator enumerator2 = enumerable.GetEnumerator();
                 try
                 {
                     while (enumerator2.MoveNext())
                     {
                         object obj2 = enumerator2.Current;
                         if (obj2 != null && !(obj2 is Def) && GenTypes.IsCustomType(obj2.GetType()))
                         {
                             string text = TranslationHandleUtility.GetBestHandleWithIndexForListElement(enumerable, obj2);
                             if (text.NullOrEmpty())
                             {
                                 text = num.ToString();
                             }
                             string curNormalizedPath2 = string.Concat(new object[]
                             {
                                 curNormalizedPath,
                                 ".",
                                 fieldInfo.Name,
                                 ".",
                                 num
                             });
                             string curSuggestedPath2 = string.Concat(new string[]
                             {
                                 curSuggestedPath,
                                 ".",
                                 fieldInfo.Name,
                                 ".",
                                 text
                             });
                             DefInjectionUtility.ForEachPossibleDefInjectionInDefRecursive(obj2, curNormalizedPath2, curSuggestedPath2, visited, flag, def, action);
                         }
                         num++;
                     }
                 }
                 finally
                 {
                     IDisposable disposable;
                     if ((disposable = (enumerator2 as IDisposable)) != null)
                     {
                         disposable.Dispose();
                     }
                 }
             }
             else if (value != null && GenTypes.IsCustomType(value.GetType()))
             {
                 string curNormalizedPath3 = curNormalizedPath + "." + fieldInfo.Name;
                 string curSuggestedPath3  = curSuggestedPath + "." + fieldInfo.Name;
                 DefInjectionUtility.ForEachPossibleDefInjectionInDefRecursive(value, curNormalizedPath3, curSuggestedPath3, visited, flag, def, action);
             }
         }
     }
 }