static bool Prefix(CatalogBehaviour __instance, ref Dictionary <Modification, ModMetaData> ___modifications, ref Dictionary <SpawnableAsset, Action <GameObject> > ___modActionByAsset, ref List <SpawnableAsset> ___spawnables) { Console.WriteLine("Populate patch triggered"); List <SpawnableAsset> spawnables = Resources.LoadAll <SpawnableAsset>("SpawnableAssets").ToList(); foreach (Mod mod in Main.mods) { foreach (SpawnableAsset s in mod.loadedSpawnables) { foreach (Category c in __instance.Catalog.Categories) { if (c.name == s.Category.name) { s.Category = c; } } Debug.Log($"Adding {s.name} under {s.Category.name}"); } spawnables.AddRange(mod.loadedSpawnables); } __instance.Catalog.Items = spawnables.ToArray(); ___spawnables = new List <SpawnableAsset>(__instance.Catalog.Items); ___modActionByAsset.Clear(); ___modifications.Clear(); __instance.BackgroundScripts.Clear(); MethodInfo RegisterModifications = __instance.GetType().GetMethod("RegisterModifications", BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo ApplyModifications = __instance.GetType().GetMethod("ApplyModifications", BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo InstantiateBackgroundScripts = __instance.GetType().GetMethod("InstantiateBackgroundScripts", BindingFlags.NonPublic | BindingFlags.Instance); RegisterModifications.Invoke(__instance, new object[] { }); ApplyModifications.Invoke(__instance, new object[] { }); InstantiateBackgroundScripts.Invoke(__instance, new object[] { }); return(false); }
static bool Prefix(CatalogBehaviour __instance, ref List <SpawnableAsset> ___spawnables) { Console.WriteLine("Populate patch triggered"); List <SpawnableAsset> spawnables = Resources.LoadAll <SpawnableAsset>("SpawnableAssets").ToList(); foreach (Mod mod in Main.mods) { foreach (SpawnableAsset s in mod.loadedSpawnables) { bool hasChanged = false; foreach (Category c in __instance.Catalog.Categories) { if (c.name == s.Category.name) { s.Category = c; hasChanged = true; } } if (!hasChanged) { List <Category> newL = __instance.Catalog.Categories.ToList(); newL.Add(s.Category); __instance.Catalog.Categories = newL.ToArray(); } Debug.Log($"Adding {s.name} under {s.Category.name}"); } Debug.Log(1); spawnables.AddRange(mod.loadedSpawnables); } Debug.Log(2); __instance.Catalog.Items = spawnables.ToArray(); Debug.Log(3); ___spawnables = new List <SpawnableAsset>(__instance.Catalog.Items); Debug.Log(4); (__instance.GetType()?.GetField("modActionByAsset", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance) as Dictionary <SpawnableAsset, Action <GameObject> >)?.Clear(); Debug.Log(5); MethodInfo ApplyModifications = __instance.GetType().GetMethod("ApplyModifications", BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo InstantiateBackgroundScripts = __instance.GetType().GetMethod("InstantiateBackgroundScripts", BindingFlags.NonPublic | BindingFlags.Instance); __instance.GetType().Assembly.GetType("ModificationManager").GetMethod("InvokeMain", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { }); ApplyModifications.Invoke(__instance, new object[] { }); InstantiateBackgroundScripts.Invoke(__instance, new object[] { }); return(false); }
/// <summary> /// Use this method to create your own category. /// </summary> /// <param name="name">New category name</param> /// <param name="description">Description of the new category</param> /// <param name="icon">New category icon</param> public static void Create(string name, string description, Sprite icon) { CatalogBehaviour manager = UnityEngine.Object.FindObjectOfType <CatalogBehaviour>(); if (manager.Catalog.Categories.FirstOrDefault((Category c) => c.name == name) == null) { Category category = ScriptableObject.CreateInstance <Category>(); category.name = name; category.Description = description; category.Icon = icon; Category[] NewCategories = new Category[manager.Catalog.Categories.Length + 1]; Category[] categories = manager.Catalog.Categories; for (int i = 0; i < categories.Length; i++) { NewCategories[i] = categories[i]; } NewCategories[NewCategories.Length - 1] = category; manager.Catalog.Categories = NewCategories; } }