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); } } }
private bool SetDefFieldAtPath(Type defType, string path, object value, Type ensureFieldType, bool errorOnDefNotFound, string fileSource, bool isPlaceholder, out string normalizedPath, out string suggestedPath, out string replacedString, out IEnumerable <string> replacedStringsList) { replacedString = null; replacedStringsList = null; string b = path; string text = path; bool flag = TKeySystem.TryGetNormalizedPath(path, out normalizedPath); if (flag) { text = text + " (" + normalizedPath + ")"; suggestedPath = path; path = normalizedPath; } else { normalizedPath = path; suggestedPath = path; } string defName = path.Split('.')[0]; defName = BackCompatibility.BackCompatibleDefName(defType, defName, forDefInjections: true); if (GenDefDatabase.GetDefSilentFail(defType, defName, specialCaseForSoundDefs: false) == null) { if (errorOnDefNotFound) { loadErrors.Add("Found no " + defType + " named " + defName + " to match " + text + " (" + fileSource + ")"); } return(false); } bool flag2 = false; int num = 0; List <object> list = new List <object>(); try { List <string> list2 = path.Split('.').ToList(); object obj = GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), defType, "GetNamedSilentFail", list2[0]); if (obj == null) { throw new InvalidOperationException("Def named " + list2[0] + " not found."); } num++; string text2; int result; DefInjectionPathPartKind defInjectionPathPartKind; while (true) { text2 = list2[num]; list.Add(obj); result = -1; if (int.TryParse(text2, out result)) { defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex; } else if (GetFieldNamed(obj.GetType(), text2) != null) { defInjectionPathPartKind = DefInjectionPathPartKind.Field; } else if (obj.GetType().GetProperty("Count") != null) { if (text2.Contains('-')) { defInjectionPathPartKind = DefInjectionPathPartKind.ListHandleWithIndex; string[] array = text2.Split('-'); text2 = array[0]; result = ParseHelper.FromString <int>(array[1]); } else { defInjectionPathPartKind = DefInjectionPathPartKind.ListHandle; } } else { defInjectionPathPartKind = DefInjectionPathPartKind.Field; } if (num == list2.Count - 1) { break; } switch (defInjectionPathPartKind) { case DefInjectionPathPartKind.Field: { FieldInfo field = obj.GetType().GetField(text2, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { throw new InvalidOperationException("Field or TKey " + text2 + " does not exist."); } if (field.HasAttribute <NoTranslateAttribute>()) { throw new InvalidOperationException("Translated untranslatable field " + field.Name + " of type " + field.FieldType + " at path " + text + ". Translating this field will break the game."); } if (field.HasAttribute <UnsavedAttribute>()) { throw new InvalidOperationException("Translated untranslatable field ([Unsaved] attribute) " + field.Name + " of type " + field.FieldType + " at path " + text + ". Translating this field will break the game."); } if (field.HasAttribute <TranslationCanChangeCountAttribute>()) { flag2 = true; } if (defInjectionPathPartKind == DefInjectionPathPartKind.Field) { obj = field.GetValue(obj); } else { object value2 = field.GetValue(obj); PropertyInfo property2 = value2.GetType().GetProperty("Item"); if (property2 == null) { throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property)."); } int num3 = (int)value2.GetType().GetProperty("Count").GetValue(value2, null); if (result < 0 || result >= num3) { throw new InvalidOperationException("Index out of bounds (max index is " + (num3 - 1) + ")"); } obj = property2.GetValue(value2, new object[1] { result }); } break; } case DefInjectionPathPartKind.ListIndex: case DefInjectionPathPartKind.ListHandle: case DefInjectionPathPartKind.ListHandleWithIndex: { object obj2 = obj; PropertyInfo property = obj2.GetType().GetProperty("Item"); if (property == null) { throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property)."); } bool flag3; if (defInjectionPathPartKind == DefInjectionPathPartKind.ListHandle || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandleWithIndex) { result = TranslationHandleUtility.GetElementIndexByHandle(obj2, text2, result); defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex; flag3 = true; } else { flag3 = false; } int num2 = (int)obj2.GetType().GetProperty("Count").GetValue(obj2, null); if (result < 0 || result >= num2) { throw new InvalidOperationException("Index out of bounds (max index is " + (num2 - 1) + ")"); } obj = property.GetValue(obj2, new object[1] { result }); if (flag3) { string[] array2 = normalizedPath.Split('.'); array2[num] = result.ToString(); normalizedPath = string.Join(".", array2); } else if (!flag) { string bestHandleWithIndexForListElement = TranslationHandleUtility.GetBestHandleWithIndexForListElement(obj2, obj); if (!bestHandleWithIndexForListElement.NullOrEmpty()) { string[] array3 = suggestedPath.Split('.'); array3[num] = bestHandleWithIndexForListElement; suggestedPath = string.Join(".", array3); } } break; } default: loadErrors.Add("Can't enter node " + text2 + " at path " + text + ", element kind is " + defInjectionPathPartKind + ". (" + fileSource + ")"); break; } num++; } bool flag4 = false; foreach (KeyValuePair <string, DefInjection> injection in injections) { if (!(injection.Key == b) && injection.Value.injected && injection.Value.normalizedPath == normalizedPath) { string text3 = "Duplicate def-injected translation key. Both " + injection.Value.path + " and " + text + " refer to the same field (" + suggestedPath + ")"; if (injection.Value.path != injection.Value.nonBackCompatiblePath) { text3 = text3 + " (" + injection.Value.nonBackCompatiblePath + " was auto-renamed to " + injection.Value.path + ")"; } text3 = text3 + " (" + injection.Value.fileSource + ")"; loadErrors.Add(text3); flag4 = true; break; } } bool result2 = false; if (!flag4) { switch (defInjectionPathPartKind) { case DefInjectionPathPartKind.Field: { FieldInfo fieldNamed = GetFieldNamed(obj.GetType(), text2); if (fieldNamed == null) { throw new InvalidOperationException("Field " + text2 + " does not exist in type " + obj.GetType() + "."); } if (fieldNamed.HasAttribute <NoTranslateAttribute>()) { loadErrors.Add("Translated untranslatable field " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + text + ". Translating this field will break the game. (" + fileSource + ")"); } else if (fieldNamed.HasAttribute <UnsavedAttribute>()) { loadErrors.Add("Translated untranslatable field (UnsavedAttribute) " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + text + ". Translating this field will break the game. (" + fileSource + ")"); } else if (!isPlaceholder && fieldNamed.FieldType != ensureFieldType) { loadErrors.Add("Translated non-" + ensureFieldType + " field " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + text + ". Expected " + ensureFieldType + ". (" + fileSource + ")"); } else if (!isPlaceholder && ensureFieldType != typeof(string) && !fieldNamed.HasAttribute <TranslationCanChangeCountAttribute>()) { loadErrors.Add("Tried to translate field " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + text + ", but this field doesn't have [TranslationCanChangeCount] attribute so it doesn't allow this type of translation. (" + fileSource + ")"); } else if (!isPlaceholder) { if (ensureFieldType == typeof(string)) { replacedString = (string)fieldNamed.GetValue(obj); } else { replacedStringsList = (fieldNamed.GetValue(obj) as IEnumerable <string>); } fieldNamed.SetValue(obj, value); result2 = true; } break; } case DefInjectionPathPartKind.ListIndex: case DefInjectionPathPartKind.ListHandle: case DefInjectionPathPartKind.ListHandleWithIndex: { object obj3 = obj; if (obj3 == null) { throw new InvalidOperationException("Tried to use index on null list at " + text); } Type type = obj3.GetType(); PropertyInfo property3 = type.GetProperty("Count"); if (property3 == null) { throw new InvalidOperationException("Tried to use index on non-list (missing 'Count' property)."); } if (defInjectionPathPartKind == DefInjectionPathPartKind.ListHandle || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandleWithIndex) { result = TranslationHandleUtility.GetElementIndexByHandle(obj3, text2, result); defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex; } int num4 = (int)property3.GetValue(obj3, null); if (result >= num4) { throw new InvalidOperationException("Trying to translate " + defType + "." + text + " at index " + result + " but the list only has " + num4 + " entries (so max index is " + (num4 - 1).ToString() + ")."); } PropertyInfo property4 = type.GetProperty("Item"); if (property4 == null) { throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property)."); } Type propertyType = property4.PropertyType; if (!isPlaceholder && propertyType != ensureFieldType) { loadErrors.Add("Translated non-" + ensureFieldType + " list item of type " + propertyType + " at path " + text + ". Expected " + ensureFieldType + ". (" + fileSource + ")"); } else if (!isPlaceholder && ensureFieldType != typeof(string) && !flag2) { loadErrors.Add("Tried to translate field of type " + propertyType + " at path " + text + ", but this field doesn't have [TranslationCanChangeCount] attribute so it doesn't allow this type of translation. (" + fileSource + ")"); } else if (result < 0 || result >= (int)type.GetProperty("Count").GetValue(obj3, null)) { loadErrors.Add("Index out of bounds (max index is " + ((int)type.GetProperty("Count").GetValue(obj3, null) - 1) + ")"); } else if (!isPlaceholder) { replacedString = (string)property4.GetValue(obj3, new object[1] { result }); property4.SetValue(obj3, value, new object[1] { result }); result2 = true; } break; } default: loadErrors.Add("Translated " + text2 + " at path " + text + " but it's not a field, it's " + defInjectionPathPartKind + ". (" + fileSource + ")"); break; } } for (int num5 = list.Count - 1; num5 > 0; num5--) { if (list[num5].GetType().IsValueType&& !list[num5].GetType().IsPrimitive) { FieldInfo fieldNamed2 = GetFieldNamed(list[num5 - 1].GetType(), list2[num5]); if (fieldNamed2 != null) { fieldNamed2.SetValue(list[num5 - 1], list[num5]); } } } string tKeyPath; if (flag) { path = suggestedPath; } else if (TKeySystem.TrySuggestTKeyPath(path, out tKeyPath)) { suggestedPath = tKeyPath; } if (path != suggestedPath) { IList <string> list3 = value as IList <string>; string text4 = (list3 == null) ? value.ToString() : list3.ToStringSafeEnumerable(); loadSyntaxSuggestions.Add("Consider using " + suggestedPath + " instead of " + text + " for translation '" + text4 + "' (" + fileSource + ")"); } return(result2); } catch (Exception ex) { string text5 = "Couldn't inject " + text + " into " + defType + " (" + fileSource + "): " + ex.Message; if (ex.InnerException != null) { text5 = text5 + " -> " + ex.InnerException.Message; } loadErrors.Add(text5); return(false); } }
private static void CleanupDefInjectionsForDefType(Type defType, string defInjectionsFolderPath, ModMetaData mod) { List <KeyValuePair <string, DefInjectionPackage.DefInjection> > list = (from x in LanguageDatabase.activeLanguage.defInjections.Where((DefInjectionPackage x) => x.defType == defType).SelectMany((DefInjectionPackage x) => x.injections) where !x.Value.isPlaceholder && x.Value.ModifiesDefFromModOrNullCore(mod, defType) select x).ToList(); Dictionary <string, DefInjectionPackage.DefInjection> dictionary = new Dictionary <string, DefInjectionPackage.DefInjection>(); foreach (KeyValuePair <string, DefInjectionPackage.DefInjection> item2 in list) { if (!dictionary.ContainsKey(item2.Value.normalizedPath)) { dictionary.Add(item2.Value.normalizedPath, item2.Value); } } List <PossibleDefInjection> possibleDefInjections = new List <PossibleDefInjection>(); DefInjectionUtility.ForEachPossibleDefInjection(defType, delegate(string suggestedPath, string normalizedPath, bool isCollection, string str, IEnumerable <string> collection, bool translationAllowed, bool fullListTranslationAllowed, FieldInfo fieldInfo, Def def) { if (translationAllowed) { PossibleDefInjection item = new PossibleDefInjection { suggestedPath = suggestedPath, normalizedPath = normalizedPath, isCollection = isCollection, fullListTranslationAllowed = fullListTranslationAllowed, curValue = str, curValueCollection = collection, fieldInfo = fieldInfo, def = def }; possibleDefInjections.Add(item); } }, mod); if (!possibleDefInjections.Any() && !list.Any()) { return; } List <KeyValuePair <string, DefInjectionPackage.DefInjection> > source = list.Where((KeyValuePair <string, DefInjectionPackage.DefInjection> x) => !x.Value.injected).ToList(); foreach (string fileName in possibleDefInjections.Select((PossibleDefInjection x) => GetSourceFile(x.def)).Concat(source.Select((KeyValuePair <string, DefInjectionPackage.DefInjection> x) => x.Value.fileSource)).Distinct()) { try { XDocument xDocument = new XDocument(); bool flag = false; try { XElement xElement = new XElement("LanguageData"); xDocument.Add(xElement); xElement.Add(new XComment("NEWLINE")); List <PossibleDefInjection> source2 = possibleDefInjections.Where((PossibleDefInjection x) => GetSourceFile(x.def) == fileName).ToList(); List <KeyValuePair <string, DefInjectionPackage.DefInjection> > source3 = source.Where((KeyValuePair <string, DefInjectionPackage.DefInjection> x) => x.Value.fileSource == fileName).ToList(); foreach (string defName in from x in source2.Select((PossibleDefInjection x) => x.def.defName).Concat(source3.Select((KeyValuePair <string, DefInjectionPackage.DefInjection> x) => x.Value.DefName)).Distinct() orderby x select x) { try { IEnumerable <PossibleDefInjection> enumerable = source2.Where((PossibleDefInjection x) => x.def.defName == defName); IEnumerable <KeyValuePair <string, DefInjectionPackage.DefInjection> > enumerable2 = source3.Where((KeyValuePair <string, DefInjectionPackage.DefInjection> x) => x.Value.DefName == defName); if (enumerable.Any()) { bool flag2 = false; foreach (PossibleDefInjection item3 in enumerable) { if (item3.isCollection) { IEnumerable <string> englishList = GetEnglishList(item3.normalizedPath, item3.curValueCollection, dictionary); bool flag3 = false; if (englishList != null) { int num = 0; foreach (string item4 in englishList) { _ = item4; if (dictionary.ContainsKey(item3.normalizedPath + "." + num)) { flag3 = true; break; } num++; } } if (flag3 || !item3.fullListTranslationAllowed) { if (englishList == null) { continue; } int num2 = -1; foreach (string item5 in englishList) { num2++; string text = item3.normalizedPath + "." + num2; string suggestedPath2 = item3.suggestedPath + "." + num2; if (TKeySystem.TrySuggestTKeyPath(text, out var tKeyPath)) { suggestedPath2 = tKeyPath; } if (!dictionary.TryGetValue(text, out var value)) { value = null; } if (value == null && !DefInjectionUtility.ShouldCheckMissingInjection(item5, item3.fieldInfo, item3.def)) { continue; } flag2 = true; flag = true; try { if (!item5.NullOrEmpty()) { xElement.Add(new XComment(SanitizeXComment(" EN: " + item5.Replace("\n", "\\n") + " "))); } } catch (Exception ex) { Log.Error("Could not add comment node in " + fileName + ": " + ex); } xElement.Add(GetDefInjectableFieldNode(suggestedPath2, value)); } continue; } bool flag4 = false; if (englishList != null) { foreach (string item6 in englishList) { if (DefInjectionUtility.ShouldCheckMissingInjection(item6, item3.fieldInfo, item3.def)) { flag4 = true; break; } } } if (!dictionary.TryGetValue(item3.normalizedPath, out var value2)) { value2 = null; } if (value2 == null && !flag4) { continue; } flag2 = true; flag = true; try { string text2 = ListToLiNodesString(englishList); if (!text2.NullOrEmpty()) { xElement.Add(new XComment(SanitizeXComment(" EN:\n" + text2.Indented() + "\n "))); } } catch (Exception ex2) { Log.Error("Could not add comment node in " + fileName + ": " + ex2); } xElement.Add(GetDefInjectableFieldNode(item3.suggestedPath, value2)); continue; } if (!dictionary.TryGetValue(item3.normalizedPath, out var value3)) { value3 = null; } string text3 = ((value3 != null && value3.injected) ? value3.replacedString : item3.curValue); if (value3 == null && !DefInjectionUtility.ShouldCheckMissingInjection(text3, item3.fieldInfo, item3.def)) { continue; } flag2 = true; flag = true; try { if (!text3.NullOrEmpty()) { xElement.Add(new XComment(SanitizeXComment(" EN: " + text3.Replace("\n", "\\n") + " "))); } } catch (Exception ex3) { Log.Error("Could not add comment node in " + fileName + ": " + ex3); } xElement.Add(GetDefInjectableFieldNode(item3.suggestedPath, value3)); } if (flag2) { xElement.Add(new XComment("NEWLINE")); } } if (!enumerable2.Any()) { continue; } flag = true; xElement.Add(new XComment(" UNUSED ")); foreach (KeyValuePair <string, DefInjectionPackage.DefInjection> item7 in enumerable2) { xElement.Add(GetDefInjectableFieldNode(item7.Value.path, item7.Value)); } xElement.Add(new XComment("NEWLINE")); } catch (Exception ex4) { Log.Error("Could not process def-injections for def " + defName + ": " + ex4); } } } finally { if (flag) { string text4 = Path.Combine(defInjectionsFolderPath, defType.Name); Directory.CreateDirectory(text4); SaveXMLDocumentWithProcessedNewlineTags(xDocument, Path.Combine(text4, fileName)); } } } catch (Exception ex5) { Log.Error("Could not process def-injections for file " + fileName + ": " + ex5); } } }
private static void DoPlayLoad() { DeepProfiler.Start("GraphicDatabase.Clear()"); try { GraphicDatabase.Clear(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Load all active mods."); try { LoadedModManager.LoadAllActiveMods(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Load language metadata."); try { LanguageDatabase.InitAllMetadata(); } finally { DeepProfiler.End(); } LongEventHandler.SetCurrentEventText("LoadingDefs".Translate()); DeepProfiler.Start("Copy all Defs from mods to global databases."); try { foreach (Type item in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "AddAllInMods"); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between non-implied Defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind defs (early)."); try { DefOfHelper.RebindAllDefOfs(earlyTryMode: true); } finally { DeepProfiler.End(); } DeepProfiler.Start("TKeySystem.BuildMappings()"); try { TKeySystem.BuildMappings(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Inject selected language data into game data (early pass)."); try { LanguageDatabase.activeLanguage.InjectIntoData_BeforeImpliedDefs(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (pre-resolve)."); try { DefGenerator.GenerateImpliedDefs_PreResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between Defs made by the implied defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors); } finally { DirectXmlCrossRefLoader.Clear(); DeepProfiler.End(); } DeepProfiler.Start("Rebind DefOfs (final)."); try { DefOfHelper.RebindAllDefOfs(earlyTryMode: false); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations (pre-resolve)."); try { PlayerKnowledgeDatabase.ReloadAndRebind(); LessonAutoActivator.Reset(); CostListCalculator.Reset(); Pawn.ResetStaticData(); PawnApparelGenerator.Reset(); RestUtility.Reset(); ThoughtUtility.Reset(); ThinkTreeKeyAssigner.Reset(); ThingCategoryNodeDatabase.FinalizeInit(); TrainableUtility.Reset(); HaulAIUtility.Reset(); GenConstruct.Reset(); MedicalCareUtility.Reset(); InspectPaneUtility.Reset(); GraphicDatabaseHeadRecords.Reset(); DateReadout.Reset(); ResearchProjectDef.GenerateNonOverlappingCoordinates(); BaseGen.Reset(); ResourceCounter.ResetDefs(); ApparelProperties.ResetStaticData(); WildPlantSpawner.ResetStaticData(); PawnGenerator.Reset(); TunnelHiveSpawner.ResetStaticData(); Hive.ResetStaticData(); ExpectationsUtility.Reset(); WealthWatcher.ResetStaticData(); SkillUI.Reset(); QuestNode_GetThingPlayerCanProduce.ResetStaticData(); Pawn_PsychicEntropyTracker.ResetStaticData(); ColoredText.ResetStaticData(); QuestNode_GetRandomNegativeGameCondition.ResetStaticData(); RoyalTitleUtility.ResetStaticData(); RewardsGenerator.ResetStaticData(); WorkGiver_FillFermentingBarrel.ResetStaticData(); WorkGiver_DoBill.ResetStaticData(); WorkGiver_InteractAnimal.ResetStaticData(); WorkGiver_Warden_DoExecution.ResetStaticData(); WorkGiver_GrowerSow.ResetStaticData(); WorkGiver_Miner.ResetStaticData(); WorkGiver_FixBrokenDownBuilding.ResetStaticData(); WorkGiver_ConstructDeliverResources.ResetStaticData(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve references."); try { DeepProfiler.Start("ThingCategoryDef resolver"); try { DefDatabase <ThingCategoryDef> .ResolveAllReferences(); } finally { DeepProfiler.End(); } DeepProfiler.Start("RecipeDef resolver"); try { DeepProfiler.enabled = false; DefDatabase <RecipeDef> .ResolveAllReferences(onlyExactlyMyType : true, parallel : true); DeepProfiler.enabled = true; } finally { DeepProfiler.End(); } DeepProfiler.Start("Static resolver calls"); try { foreach (Type item2 in typeof(Def).AllSubclasses()) { if (!(item2 == typeof(ThingDef)) && !(item2 == typeof(ThingCategoryDef)) && !(item2 == typeof(RecipeDef))) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true, false); } } } finally { DeepProfiler.End(); } DeepProfiler.Start("ThingDef resolver"); try { DefDatabase <ThingDef> .ResolveAllReferences(); } finally { DeepProfiler.End(); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (post-resolve)."); try { DefGenerator.GenerateImpliedDefs_PostResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations (post-resolve)."); try { PawnWeaponGenerator.Reset(); BuildingProperties.FinalizeInit(); ThingSetMakerUtility.Reset(); } finally { DeepProfiler.End(); } if (Prefs.DevMode) { DeepProfiler.Start("Error check all defs."); try { foreach (Type item3 in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item3, "ErrorCheckAllDefs"); } } finally { DeepProfiler.End(); } } LongEventHandler.SetCurrentEventText("Initializing".Translate()); DeepProfiler.Start("Load keyboard preferences."); try { KeyPrefs.Init(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Short hash giving."); try { ShortHashGiver.GiveAllShortHashes(); } finally { DeepProfiler.End(); } LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Load backstories."); try { BackstoryDatabase.ReloadAllBackstories(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Inject selected language data into game data."); try { LanguageDatabase.activeLanguage.InjectIntoData_AfterImpliedDefs(); GenLabel.ClearCache(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Static constructor calls"); try { StaticConstructorOnStartupUtility.CallAll(); if (Prefs.DevMode) { StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes(); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Garbage Collection"); try { AbstractFilesystem.ClearAllCache(); GC.Collect(int.MaxValue, GCCollectionMode.Forced); } finally { DeepProfiler.End(); } }); }
public static void LoadAllActiveMods() { DeepProfiler.Start("XmlInheritance.Clear()"); try { XmlInheritance.Clear(); } finally { DeepProfiler.End(); } DeepProfiler.Start("InitializeMods()"); try { InitializeMods(); } finally { DeepProfiler.End(); } DeepProfiler.Start("LoadModContent()"); try { LoadModContent(); } finally { DeepProfiler.End(); } DeepProfiler.Start("CreateModClasses()"); try { CreateModClasses(); } finally { DeepProfiler.End(); } List <LoadableXmlAsset> xmls = null; DeepProfiler.Start("LoadModXML()"); try { xmls = LoadModXML(); } finally { DeepProfiler.End(); } Dictionary <XmlNode, LoadableXmlAsset> assetlookup = new Dictionary <XmlNode, LoadableXmlAsset>(); XmlDocument xmlDocument = null; DeepProfiler.Start("CombineIntoUnifiedXML()"); try { xmlDocument = CombineIntoUnifiedXML(xmls, assetlookup); } finally { DeepProfiler.End(); } TKeySystem.Clear(); DeepProfiler.Start("TKeySystem.Parse()"); try { TKeySystem.Parse(xmlDocument); } finally { DeepProfiler.End(); } DeepProfiler.Start("ApplyPatches()"); try { ApplyPatches(xmlDocument, assetlookup); } finally { DeepProfiler.End(); } DeepProfiler.Start("ParseAndProcessXML()"); try { ParseAndProcessXML(xmlDocument, assetlookup); } finally { DeepProfiler.End(); } DeepProfiler.Start("ClearCachedPatches()"); try { ClearCachedPatches(); } finally { DeepProfiler.End(); } DeepProfiler.Start("XmlInheritance.Clear()"); try { XmlInheritance.Clear(); } finally { DeepProfiler.End(); } }