diff --git a/CalamityMod.cs b/CalamityMod.cs index e74cd3ca63..34a6b578ad 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -383,7 +383,6 @@ namespace CalamityMod return Color.Lerp(player.hairColor, new Color(186, 85, 211), stealthInterpolant); })); - PopupGUIManager.LoadGUIs(); InvasionProgressUIManager.LoadGUIs(); } #endregion diff --git a/Cooldowns/CooldownRegistry.cs b/Cooldowns/CooldownRegistry.cs index 28504bc654..53822657c1 100644 --- a/Cooldowns/CooldownRegistry.cs +++ b/Cooldowns/CooldownRegistry.cs @@ -23,9 +23,6 @@ namespace CalamityMod.Cooldowns registry = new Cooldown[defaultSize]; nameToNetID = new Dictionary(defaultSize); - // TODO -- CooldownHandlers should be ILoadable in 1.4 - RegisterModCooldowns(CalamityMod.Instance); - #region Unused manual registration left here as backup // Vanilla cooldowns represented by the interface //var potionSickness = Register(PotionSickness.ID); @@ -63,26 +60,29 @@ namespace CalamityMod.Cooldowns #endregion } - public static void RegisterModCooldowns(Mod mod) + public static void RegisterModCooldowns() { Type baseHandlerType = typeof(CooldownHandler); - foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code)) + foreach (Mod mod in ModLoader.Mods) { - if (type.IsSubclassOf(baseHandlerType) && !type.IsAbstract && type != baseHandlerType) + foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code)) { - //Get the static property ID of the handler - string handlerID = (string)type.GetProperty("ID").GetValue(null); + if (type.IsSubclassOf(baseHandlerType) && !type.IsAbstract && type != baseHandlerType) + { + //Get the static property ID of the handler + string handlerID = (string)type.GetProperty("ID").GetValue(null); - //If for whatever reason the ID is not set, create an ID from the mod and handler name - if (handlerID == null) - handlerID = mod.Name + "_" + type.Name; + //If for whatever reason the ID is not set, create an ID from the mod and handler name + if (handlerID == null) + handlerID = mod.Name + "_" + type.Name; - //Use reflection to call the method. You can't use the type as the generic type argument of register here - MethodInfo methodInfo = typeof(CooldownRegistry).GetMethod("Register", BindingFlags.Public | BindingFlags.Static); - Type[] genericArguments = new Type[] { type }; + //Use reflection to call the method. You can't use the type as the generic type argument of register here + MethodInfo methodInfo = typeof(CooldownRegistry).GetMethod("Register", BindingFlags.Public | BindingFlags.Static); + Type[] genericArguments = new Type[] { type }; - MethodInfo genericRegister = methodInfo.MakeGenericMethod(genericArguments); - genericRegister.Invoke(null, new object[] { handlerID }); + MethodInfo genericRegister = methodInfo.MakeGenericMethod(genericArguments); + genericRegister.Invoke(null, new object[] { handlerID }); + } } } } diff --git a/ModSupport/ModCalls.cs b/ModSupport/ModCalls.cs index 344095e943..9810684f24 100644 --- a/ModSupport/ModCalls.cs +++ b/ModSupport/ModCalls.cs @@ -1981,20 +1981,6 @@ namespace CalamityMod BossRushEvent.BossDeathEffects[npcType5] = deathEffect; return null; - case "LoadParticleInstances": - if (args.Length != 2 || !(args[1] is Mod)) - return new ArgumentNullException("ERROR: Must specify a Mod instance to load particles from."); - - GeneralParticleHandler.LoadModParticleInstances(args[1] as Mod); - return null; - - case "RegisterModCooldowns": - if (args.Length != 2 || !(args[1] is Mod)) - return new ArgumentNullException("ERROR: Must specify a Mod instance to register cooldowns from."); - - CooldownRegistry.RegisterModCooldowns(args[1] as Mod); - return null; - case "GetSummonerNerfDisabledByItem": if (args.Length != 2 || !isValidItemArg(args[1])) return new ArgumentException("ERROR: Must specify a valid item to check status of."); diff --git a/ModSupport/WeakReferenceSupport.cs b/ModSupport/WeakReferenceSupport.cs index 1327f31e92..1ab51722af 100644 --- a/ModSupport/WeakReferenceSupport.cs +++ b/ModSupport/WeakReferenceSupport.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using CalamityMod.Buffs.Summon; +using CalamityMod.Cooldowns; using CalamityMod.Events; using CalamityMod.Items; using CalamityMod.Items.Armor.Vanity; @@ -55,9 +56,11 @@ using CalamityMod.NPCs.SunkenSea; using CalamityMod.NPCs.SupremeCalamitas; using CalamityMod.NPCs.TownNPCs; using CalamityMod.NPCs.Yharon; +using CalamityMod.Particles; using CalamityMod.Projectiles.DraedonsArsenal; using CalamityMod.Projectiles.Summon; using CalamityMod.Projectiles.Summon.Umbrella; +using CalamityMod.UI; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -188,6 +191,13 @@ namespace CalamityMod FargosSupport(); DialogueTweakSupport(); SummonersAssociationSupport(); + // done here to assure that all other mods have already loaded so that Calamity can automatically grab any of these types they may have + if (!Main.dedServ) + { + GeneralParticleHandler.LoadModParticleInstances(); + CooldownRegistry.RegisterModCooldowns(); + PopupGUIManager.LoadGUIs(); + } } #region WikiThis diff --git a/Particles/GeneralParticleHandler.cs b/Particles/GeneralParticleHandler.cs index 6c340cebe1..85bfb1c6c4 100644 --- a/Particles/GeneralParticleHandler.cs +++ b/Particles/GeneralParticleHandler.cs @@ -26,23 +26,26 @@ namespace CalamityMod.Particles private static List batchedNonPremultipliedParticles; private static List batchedAdditiveBlendParticles; - public static void LoadModParticleInstances(Mod mod) + public static void LoadModParticleInstances() { Type baseParticleType = typeof(Particle); - foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code)) + foreach (Mod mod in ModLoader.Mods) { - if (type.IsSubclassOf(baseParticleType) && !type.IsAbstract && type != baseParticleType) + foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code)) { - int ID = particleTypes.Count; //Get the ID of the particle - particleTypes[type] = ID; + if (type.IsSubclassOf(baseParticleType) && !type.IsAbstract && type != baseParticleType) + { + int ID = particleTypes.Count; //Get the ID of the particle + particleTypes[type] = ID; - Particle instance = (Particle)FormatterServices.GetUninitializedObject(type); - particleInstances.Add(instance); + Particle instance = (Particle)FormatterServices.GetUninitializedObject(type); + particleInstances.Add(instance); - string texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name; - if (instance.Texture != "") - texturePath = instance.Texture; - particleTextures[ID] = ModContent.Request(texturePath, AssetRequestMode.ImmediateLoad).Value; + string texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name; + if (instance.Texture != "") + texturePath = instance.Texture; + particleTextures[ID] = ModContent.Request(texturePath, AssetRequestMode.ImmediateLoad).Value; + } } } } @@ -58,8 +61,6 @@ namespace CalamityMod.Particles batchedAlphaBlendParticles = new List(); batchedNonPremultipliedParticles = new List(); batchedAdditiveBlendParticles = new List(); - - LoadModParticleInstances(CalamityMod.Instance); } internal static void Unload() diff --git a/UI/PopupGUIManager.cs b/UI/PopupGUIManager.cs index 61c72bbf6e..40b47cb197 100644 --- a/UI/PopupGUIManager.cs +++ b/UI/PopupGUIManager.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; using System.Linq; using Terraria; +using Terraria.ModLoader; +using Terraria.ModLoader.Core; namespace CalamityMod.UI { @@ -58,13 +60,16 @@ namespace CalamityMod.UI public static void LoadGUIs() { // Look through every type in the mod, and check if it's derived from PopupGUI. If it is, create a copy and save it in the static list. - foreach (Type type in typeof(CalamityMod).Assembly.GetTypes()) + foreach (Mod mod in ModLoader.Mods) { - // Don't load abstract classes since they cannot have instances. - if (type.IsAbstract) - continue; - if (type.IsSubclassOf(typeof(PopupGUI))) - gUIs.Add(Activator.CreateInstance(type) as PopupGUI); + foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code)) + { + // Don't load abstract classes since they cannot have instances. + if (type.IsAbstract) + continue; + if (type.IsSubclassOf(typeof(PopupGUI))) + gUIs.Add(Activator.CreateInstance(type) as PopupGUI); + } } } public static void UnloadGUIs() => gUIs.Clear();