public static void LoadCache() { if (cacheLoaded) { return; } var savePathDir = GetCachePath(); if (!File.Exists(savePathDir)) { SaveCache(); return; } var allText = File.ReadAllLines(savePathDir); foreach (var line in allText) { var techTypeName = line.Split(':')[0]; var techTypeIndex = line.Split(':')[1]; var cache = new TechTypeCache() { Name = techTypeName, Index = int.Parse(techTypeIndex) }; cacheList.Add(cache); } Logger.Log("Loaded TechTypeCache!"); cacheLoaded = true; }
public static TechType AddTechType(string name, string languageName, string languageTooltip, bool unlockOnGameStart) { var cache = GetCacheForTechTypeName(name); if (cache == null) { cache = new TechTypeCache() { Name = name, Index = GetNextFreeIndex() }; } if (MultipleCachesUsingSameIndex(cache.Index)) { cache.Index = GetNextFreeIndex(); } var techType = (TechType)cache.Index; customTechTypes.Add(techType, cache); LanguagePatcher.customLines.Add(name, languageName); LanguagePatcher.customLines.Add("Tooltip_" + name, languageTooltip); var valueToString = CachedEnumString_valueToString.GetValue(TooltipFactory.techTypeTooltipStrings) as Dictionary <TechType, string>; valueToString[techType] = "Tooltip_" + name; var techTypeExtensions = typeof(TechTypeExtensions); var traverse = Traverse.Create(techTypeExtensions); var stringsNormal = traverse.Field("stringsNormal").GetValue <Dictionary <TechType, string> >(); var stringsLowercase = traverse.Field("stringsLowercase").GetValue <Dictionary <TechType, string> >(); var techTypesNormal = traverse.Field("techTypesNormal").GetValue <Dictionary <string, TechType> >(); var techTypesIgnoreCase = traverse.Field("techTypesIgnoreCase").GetValue <Dictionary <string, TechType> >(); var techTypeKeys = traverse.Field("techTypeKeys").GetValue <Dictionary <TechType, string> >(); var keyTechTypes = traverse.Field("keyTechTypes").GetValue <Dictionary <string, TechType> >(); stringsNormal[techType] = name; stringsLowercase[techType] = name.ToLowerInvariant(); techTypesNormal[name] = techType; techTypesIgnoreCase[name] = techType; string key3 = ((int)techType).ToString(); techTypeKeys[techType] = key3; keyTechTypes[key3] = techType; if (unlockOnGameStart) { KnownTechPatcher.unlockedAtStart.Add(techType); } CallerName = CallerName ?? Assembly.GetCallingAssembly().GetName().Name; Logger.Log("Successfully added Tech Type: \"{0}\" to Index: \"{1}\" for mod \"{2}\"", name, cache.Index, CallerName); CallerName = null; SaveCache(); return(techType); }