public static void ParseAllRecipes() { if (References.ALL_RECIPES is Dictionary <string, Recipe> recipes) { foreach (Recipe recipe in recipes.Values) { int id = recipe.RecipeID; if (id == 0) { if (int.TryParse(recipe.name.Substring(0, 3), out int id2)) { id = id2; } } var key = id.ToString(); if (ListManager.Recipes.ContainsKey(key)) { SL.LogWarning("Recipe list already contains ID " + key + ", skipping this recipe: " + recipe.name); continue; } var recipeHolder = ParseRecipe(recipe, id); string dir = Serializer.Folders.Recipes; string saveName = recipeHolder.Name + " (" + recipeHolder.RecipeID + ")"; ListManager.Recipes.Add(key, recipeHolder); Serializer.SaveToXml(dir, saveName, recipeHolder); } } }
public static void Postfix(Item __instance, ref string ___m_toLogString) { ___m_toLogString = Serializer.ReplaceInvalidChars(___m_toLogString); if (!SL.PacksLoaded) { return; } if (SL_Item.s_initCallbacks.TryGetValue(__instance.ItemID, out List <Action <Item> > invocationList)) { foreach (var listener in invocationList) { try { listener.Invoke(__instance); } catch (Exception e) { SL.LogWarning($"Exception invoking callback for Item.Start() on {__instance.Name}"); SL.LogInnerException(e); } } } }
/// <summary> /// Helper to manually save a PlayerSaveExtension of type T to the given character UID folder. /// </summary> /// <typeparam name="T">The type of extension you want to save.</typeparam> /// <param name="characterUID">The character UID you want to save to</param> /// <param name="extension">The extension data to save</param> public static void TrySaveExtension <T>(string characterUID, T extension) where T : PlayerSaveExtension { try { if (extension == null) { throw new ArgumentNullException("extension"); } if (string.IsNullOrEmpty(characterUID)) { throw new ArgumentNullException("characterUID"); } var filePath = GetSaveFilePath <T>(characterUID); if (File.Exists(filePath)) { File.Delete(filePath); } var serializer = Serializer.GetXmlSerializer(typeof(T)); using (var file = File.Create(filePath)) { serializer.Serialize(file, extension); } } catch (Exception ex) { SL.LogWarning($"Exception saving save extension '{typeof(T).FullName}' for character '{characterUID}'"); SL.Log(ex.ToString()); } }
public static void Dump() { SL.LogWarning("[Dataminer] Starting full dump!"); // setup tags for (int i = 1; i < 500; i++) { if (TagSourceManager.Instance.GetTag(i.ToString()) is Tag tag) { ListManager.AddTagSource(tag, null); } } DM_Item.ParseAllItems(); DM_StatusEffect.ParseAllEffects(); DM_Recipe.ParseAllRecipes(); DM_EnchantmentRecipe.ParseAllRecipes(); SL.LogWarning("Saving early lists..."); ListManager.SaveEarlyLists(); SL.LogWarning("Finished prefab dumping."); }
public static List <ContentTemplate> SolveDependencies(List <ContentTemplate> allTemplates) { if (allTemplates == null || !allTemplates.Any()) { return(allTemplates); } List <ContentTemplate> sorted; // Check if there are any actual dependencies var dependencies = allTemplates.Where(it => !it.DoesTargetExist).ToList(); if (dependencies.Any()) { // Toplogical sort dependencies and full list. if (!TopologicalSort(allTemplates, dependencies, out List <ContentTemplate> resolved)) { // sort returning false means some templates weren't resolved. // these will still exist in the "dependencies" list. foreach (var template in dependencies) { SL.LogWarning("A template targeting ID '" + template.TargetID + "' could not be resolved! This may be a circular dependency."); } } sorted = resolved; } else { sorted = allTemplates; // we had no dependencies } return(sorted); }
/// <summary> /// Pass a Game Class type (eg, Item) and get the corresponding Dataminer class (eg, DM_Item). /// </summary> /// <param name="_gameType">Eg, typeof(Item)</param> /// <param name="logging">If you want to log debug messages.</param> public static Type GetDMType(Type _gameType, bool logging = true) { var name = $"Dataminer.DM_{_gameType.Name}"; if (!m_typeCache.ContainsKey(name)) { Type t = null; try { t = DM_Assembly.GetType(name); if (t == null) { throw new Exception("Null"); } m_typeCache.Add(name, t); } catch (Exception e) { if (logging) { SL.LogWarning($"Could not get DM_Assembly Type '{name}'"); SL.LogWarning(e.Message); SL.LogWarning(e.StackTrace); } } return(t); } else { return(m_typeCache[name]); } }
// ~~~~~~~~~ Core internal ~~~~~~~~~ internal static void OnSaveInstanceSave(SaveInstance __instance) { try { if (__instance.CharSave == null || string.IsNullOrEmpty(__instance.CharSave.CharacterUID)) { return; } var charUID = __instance.CharSave.CharacterUID; bool isHost = !PhotonNetwork.isNonMasterClientInRoom && !(bool)At.GetField(NetworkLevelLoader.Instance, "m_saveOnHostLost") && CharacterManager.Instance?.GetWorldHostCharacter()?.UID == charUID; // Save internal stuff for the host if (isHost) { SLCharacterSaveManager.SaveCharacters(); SLItemSpawnSaveManager.SaveItemSpawns(); } // Save custom extensions from other mods PlayerSaveExtension.SaveAllExtensions(CharacterManager.Instance.GetCharacter(charUID), isHost); } catch (Exception ex) { SL.LogWarning("Exception on SaveInstance.Save!"); SL.LogInnerException(ex); } }
internal void RemoveEntry(int index) { if (RefIList.IsFixedSize) { if (this.FallbackType.IsArray) { var array = Value as Array; Resize(ref array, RefIList.Count - 1, index); Value = array; RefIList = Value as IList; } else { SL.LogWarning("Cannot remove from this type: " + FallbackType.GetType()); return; } } else { RefIList.RemoveAt(index); } ApplyFromRefIList(); }
public static DM_Item ParseItemToTemplate(Item item) { if (item == null) { return(null); } //SL.Log("Parsing item to template: " + item.Name); var type = Serializer.GetBestDMType(item.GetType()); DM_Item holder; try { holder = (DM_Item)Activator.CreateInstance(type); } catch (InvalidCastException) { if (type == null) { SL.LogWarning("type is null"); } else { SL.LogWarning("Exception casting '" + type.FullName + "' to DM_Item?"); } return(null); } holder.SerializeItem(item, holder); return(holder); }
private void LoadTexture(SLPack pack, Dictionary <string, object> dict, string dirPath, string texFile, bool addGlobal) { var texture = pack.LoadTexture2D(dirPath, texFile, false, false); var name = Path.GetFileNameWithoutExtension(texFile); // add to the Texture2D dict for this pack if (pack.Texture2D.ContainsKey(name)) { SL.LogWarning("Trying to load two textures with the same name into the same SLPack: " + name); return; } pack.Texture2D.Add(name, texture); dict.Add(Path.Combine(dirPath, texFile), texture); if (addGlobal) { // add to the global Tex replacements dict if (CustomTextures.Textures.ContainsKey(name)) { SL.Log("Custom Texture2Ds: A Texture already exists in the global list called " + name + "! Overwriting with this one..."); CustomTextures.Textures[name] = texture; } else { CustomTextures.Textures.Add(name, texture); } } }
public override Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload) { var dir = pack.GetPathForCategory <PackBundleCategory>(); if (!Directory.Exists(dir)) { return(null); } foreach (var bundlePath in Directory.GetFiles(dir)) { try { SL.Log("Loading Pack AssetBundle: " + bundlePath); var assetbundle = AssetBundle.LoadFromFile(bundlePath); var bundlePack = new SLPackBundle(Path.GetFileName(bundlePath), pack, assetbundle); pack.PackBundles.Add(bundlePack.Name, bundlePack); s_loadedBundles.Add(bundlePath, bundlePack); //SL.Log($"Added bundle '{bundlePack.Name}' to pack '{pack.Name}' (Bundle count: {pack.PackBundles.Count})"); } catch (Exception ex) { SL.LogWarning("Exception loading Pack Bundle: " + bundlePath); SL.LogInnerException(ex); } } return(null); }
private IEnumerator WaitForSceneReady() { while (!NetworkLevelLoader.Instance.IsOverallLoadingDone || !NetworkLevelLoader.Instance.AllPlayerDoneLoading) { yield return(null); } try { foreach (var deployable in ItemManager.Instance.WorldItems.Values.Where(x => x.GetExtension("Deployable") != null)) { var comp = deployable.GetComponent <Deployable>(); if (comp.IsDeployed && comp.PackedStateItemPrefab == null) { AddDestroyInteraction(comp); } } } catch (Exception ex) { SL.LogWarning("Exception applying Dismantler interactions"); SL.LogInnerException(ex); } }
/// <summary> /// Helper to manually try to load the saved data for an extension of type T, with the given character UID. /// </summary> /// <typeparam name="T">The type of PlayerSaveExtension you're looking for</typeparam> /// <param name="characterUID">The saved character's UID</param> /// <returns>The loaded extension data, if found, otherwise null.</returns> public static T TryLoadExtension <T>(string characterUID) where T : PlayerSaveExtension { try { if (string.IsNullOrEmpty(characterUID)) { throw new ArgumentNullException("characterUID"); } var filePath = GetSaveFilePath <T>(characterUID); T ret = null; if (File.Exists(filePath)) { var serializer = Serializer.GetXmlSerializer(typeof(T)); using (var file = File.OpenRead(filePath)) { ret = (T)serializer.Deserialize(file); } } else { SL.LogWarning("No extension data found at '" + filePath + "'"); } return(ret); } catch (Exception ex) { SL.LogWarning($"Exception loading save extension '{typeof(T).FullName}' for character '{characterUID}'"); SL.Log(ex.ToString()); return(null); } }
private void Load() { if (RefPack == null) { SL.LogWarning("Error - RefPack is null on TemplateInspector.Load!"); return; } var directory = RefPack.GetPathForCategory(Template.PackCategory.GetType()); if (Template.TemplateAllowedInSubfolder && !string.IsNullOrEmpty(this.Template.SerializedSubfolderName)) { directory += $@"\{this.Template.SerializedSubfolderName}"; } var path = directory + "\\" + Template.SerializedFilename + ".xml"; if (!File.Exists(path)) { SL.LogWarning("No file exists at " + path); return; } if (Serializer.LoadFromXml(path) is ContentTemplate loadedData) { var loadedType = loadedData.GetType(); SL.Log("Loaded xml, loaded type is " + loadedType); if (loadedType != m_targetType) ChangeType(loadedType); CopyValuesFrom(loadedData); } UpdateFullPathText(); }
public static void Prefix(Building __instance) { if (!StoreManager.Instance.IsDlcInstalled(OTWStoreAPI.DLCs.DLC2) || !BuildingHelperMod.Instance.settings.AutoFinishBuildings || PhotonNetwork.isNonMasterClientInRoom) { return; } int sanity = 5; while (sanity >= 0 && __instance.CurrentPhase.ConstructionType == Building.ConstructionPhase.Type.WIP) { int cur = (int)At.GetField(__instance, "m_currentBasicPhaseIndex"); if (cur < 0) { cur = 0; } else { cur++; } At.SetField(__instance, "m_currentBasicPhaseIndex", cur); sanity--; } if (sanity < 0) { SL.LogWarning("Did more than 6 loops trying to auto-finish building, something went wrong!"); } At.SetField(__instance, "m_remainingConstructionTime", 0f); }
public static void CheckTypeCache() { //SL.Log("Getting implementations of SLPackCategory in all assemblies..."); var allTypes = At.GetImplementationsOf(typeof(SLPackCategory)); if (allTypes.Count == s_lastTypeCount) { return; } s_lastTypeCount = allTypes.Count; var list = new List <SLPackCategory>(); //var lateList = new List<SLPackCategory>(); foreach (var type in allTypes) { try { SLPackCategory ctg; if (s_slPackCategories != null && s_slPackCategories.ContainsKey(type)) { ctg = s_slPackCategories[type]; } else { ctg = (SLPackCategory)At.TryCreateDefault(type); } if (ctg != null) { list.Add(ctg); //if (ctg.HasLateContent) // lateList.Add(ctg); } else { SL.Log("SLPack categories internal: could not create instance of type '" + type.FullName + "'"); } } catch (Exception ex) { SL.LogWarning("Exception checking SLPackCategory '" + type.FullName + "'"); SL.LogInnerException(ex); } } s_slPackCategories = new Dictionary <Type, SLPackCategory>(); foreach (var instance in list.OrderBy(it => it.LoadOrder)) { s_slPackCategories.Add(instance.GetType(), instance); } //s_slPackLateCategories = new Dictionary<Type, SLPackCategory>(); //if (lateList.Any()) // foreach (var instance in lateList.OrderBy(it => it.LoadOrder)) // s_slPackLateCategories.Add(instance.GetType(), instance); }
public string GetCurrentLocation(Vector3 _pos) { if (!SceneManagerHelper.ActiveSceneName.ToLower().Contains("dungeonssmall")) { return(SceneHelper.SceneBuildNames[SceneManagerHelper.ActiveSceneName]); } else { string closestRegion = ""; float lowest = float.MaxValue; Dictionary <string, Vector3> dict = null; switch (GetCurrentRegion()) { case "Chersonese": dict = SceneHelper.ChersoneseDungeons; break; case "Enmerkar Forest": dict = SceneHelper.EnmerkarDungeons; break; case "Hallowed Marsh": dict = SceneHelper.MarshDungeons; break; case "Abrassar": dict = SceneHelper.AbrassarDungeons; break; case "Antique Plateau": dict = SceneHelper.AntiqueDungeons; break; case "Caldera": dict = SceneHelper.CalderaDungeons; break; default: break; } if (dict != null) { foreach (KeyValuePair <string, Vector3> entry in dict) { if (Vector3.Distance(_pos, entry.Value) < lowest) { lowest = Vector3.Distance(_pos, entry.Value); closestRegion = entry.Key; } } return(closestRegion); } else { SL.LogWarning("Could not get region!"); return(SceneManagerHelper.ActiveSceneName); } } }
private void DeserializePack(SLPack pack, List <ContentTemplate> list) { try { var dict = new Dictionary <string, object>(); var dirPath = pack.GetPathForCategory(this.GetType()); if (!pack.DirectoryExists(dirPath)) { return; } // load root directory templates foreach (var filepath in pack.GetFiles(dirPath, ".xml")) { DeserializeTemplate(dirPath, filepath); } // load one-subfolder templates foreach (var subDir in pack.GetDirectories(dirPath)) { foreach (var filepath in pack.GetFiles(subDir, ".xml")) { DeserializeTemplate(subDir, filepath, subDir); } } AddToSLPackDictionary(pack, dict); void DeserializeTemplate(string directory, string filepath, string subfolder = null) { //SL.Log($@"Deserializing template from '{directory}\{filepath}'"); var template = pack.ReadXmlDocument <T>(directory, Path.GetFileName(filepath)); dict.Add(filepath, template); list.Add(template); template.SerializedSLPackName = pack.Name; template.SerializedFilename = Path.GetFileNameWithoutExtension(filepath); if (!string.IsNullOrEmpty(subfolder)) { template.SerializedSubfolderName = Path.GetFileName(subfolder); } } } catch (Exception ex) { SL.LogWarning("Exception loading " + this.FolderName + " from '" + pack.Name + "'"); SL.LogInnerException(ex); } }
public static void Postfix(Character _character) { try { PlayerSaveExtension.LoadExtensions(_character); } catch (Exception ex) { SL.LogWarning("Exception on loading SL PlayerSaveExtensions!"); SL.LogInnerException(ex); } }
public override void ApplyToComponent <T>(T component) { var tag = CustomTags.GetTag(ImmunityTag, false); if (tag == Tag.None) { SL.LogWarning($"{this.GetType().Name}: Could not find a tag with the name '{ImmunityTag}'!"); return; } At.SetField(component as AddStatusImmunity, "m_statusImmunity", new TagSourceSelector(tag)); }
private static void LoadPackCategory(List <SLPack> packs, SLPackCategory ctg, bool firstSetup) { try { ctg.InternalLoad(packs, !firstSetup); } catch (Exception ex) { SL.LogWarning($"Exception loading {ctg.FolderName}!"); SL.LogInnerException(ex); } }
private static void InvokeLateApplyListener(Action <object[]> listener, params object[] args) { try { listener.Invoke(args); } catch (Exception ex) { SL.LogWarning("Exception invoking OnLateApply listener!"); SL.LogInnerException(ex); } }
internal void SaveDataFromCharacter(Character character, bool isWorldHost) { try { Save(character, isWorldHost); } catch (Exception ex) { SL.LogWarning("Exception saving data from character: " + this.ToString()); SL.LogInnerException(ex); } }
internal void OnApplyClicked() { try { Value = ParseMethod.Invoke(null, new object[] { m_valueInput.text }); Owner.SetValue(); RefreshUIForValue(); } catch (Exception e) { SL.LogWarning($"Could not parse input! {e.GetType()}: {e.Message}"); } }
protected internal override void InternalLoad(List <SLPack> packs, bool isHotReload) { if (AllCurrentTemplates.Count > 0) { AllCurrentTemplates.Clear(); } var list = new List <ContentTemplate>(); // Load SL packs first foreach (var pack in packs) { DeserializePack(pack, list); if (pack.PackBundles != null && pack.PackBundles.Count > 0) { foreach (var bundle in pack.PackBundles.Values) { DeserializePack(bundle, list); } } } // Load CSharp templates if (CSharpTemplates != null && CSharpTemplates.Any()) { SL.Log(CSharpTemplates.Count + " registered C# templates found..."); list.AddRange(CSharpTemplates); } list = TemplateDependancySolver.SolveDependencies(list); foreach (var template in list) { try { ApplyTemplate(template); Internal_AllCurrentTemplates.Add(template); } catch (Exception ex) { SL.LogWarning("Exception applying template!"); SL.LogInnerException(ex); } } return; }
private IEnumerator DelayedLoadCoroutine(Character character, bool isWorldHost) { yield return(new WaitForSeconds(1.0f)); try { ApplyLoadedSave(character, isWorldHost); } catch (Exception ex) { SL.LogWarning("Exception loading save data onto character: " + this.ToString()); SL.LogInnerException(ex); } }
public static Exception Finalizer(MapDisplay __instance, Exception __exception) { var self = __instance; try { if (!(self.CurrentMapScene.MarkerOffset == Vector2.zero) || !(self.CurrentMapScene.MarkerScale == Vector2.zero)) { // update EnemyMarker positions for (int i = 0; i < EnemyMarkers.Count; i++) { if (!EnemyMarkers[i]) { continue; } EnemyMarkers[i].CalculateMapPosition(MapDisplay.Instance.CurrentMapScene, i, MapDisplay.Instance.m_zoomLevelSmooth * 1.0351562f); EnemyMarkers[i].m_adjustedMapPosition = EnemyMarkers[i].MapPosition; } } // update enemy marker texts for (int i = 0; i < m_enemyTexts.Count; i++) { if (i < EnemyMarkers.Count && EnemyMarkers[i]) { if (!m_enemyTexts[i].gameObject.activeSelf) { m_enemyTexts[i].SetActive(true); } m_enemyTexts[i].UpdateDisplay(EnemyMarkers[i]); } else { if (m_enemyTexts[i].gameObject.activeSelf) { m_enemyTexts[i].SetActive(false); } } } } catch (Exception ex) { SL.LogWarning($"Exception updating enemy marker positions: {ex}"); } return(null); }
public SLPackArchive(string name, ZipArchive archive) { this.Name = name; this.RefZipArchive = archive; if (SL.s_embeddedArchivePacks.ContainsKey(Name)) { SL.LogWarning("Two embedded SLPackArchives with duplicate name: " + Name + ", not loading!"); return; } SL.s_embeddedArchivePacks.Add(Name, this); CachePaths(); }
public void CreateTag() { if (CustomTags.GetTag(this.TagName, false) != Tag.None) { SL.LogWarning($"Creating Tag '{this.TagName}', but it already exists!"); return; } ; var tag = CustomTags.CreateTag(TagName); if (!string.IsNullOrEmpty(this.OptionalTagUID)) { At.SetField(tag, "m_uid", new UID(this.OptionalTagUID)); } }
public static void ParseAllItems() { //int[] IDsToSaveIcons = new int[] //{ // 2150140, // 2150150, // 2150160, // 2150165, // 2150170, // 2150175, // 2150180, // 2150185, //}; if (References.RPM_ITEM_PREFABS is Dictionary <string, Item> ItemPrefabs) { foreach (Item item in ItemPrefabs.Values) { try { var safename = Serializer.SafeName(item.Name); //if (IDsToSaveIcons.Contains(item.ItemID)) // CustomTextures.SaveIconAsPNG(item.ItemIcon, "ItemIcons", safename); //if (item.DLCID == OTWStoreAPI.DLCs.DLC2 && item.ItemIcon && !item.HasDefaultIcon) //{ // CustomTextures.SaveIconAsPNG(item.ItemIcon, "ItemIcons", safename); //} //SL.Log("Parsing " + item.Name + ", typeof: " + item.GetType()); // Parse the item. This will recursively dive. var itemHolder = ParseItemToTemplate(item); ListManager.Items.Add(item.ItemID.ToString(), itemHolder); string dir = GetFullSaveDir(item, itemHolder); Serializer.SaveToXml(dir, safename + " (" + item.gameObject.name + ")", itemHolder); } catch (Exception e) { SL.LogWarning(e.ToString()); } } } }