From 28c09a4407d2b3cf8ea17e9521b2d7914dc90fbc Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sat, 6 Dec 2025 09:20:12 +0900 Subject: [PATCH] Removed Usage for GetLoadableTypes in Attributes Loader --- NPCs/CalamityNetImportantNPC.cs | 17 +++++------------ NPCs/CalamityPierceResistance.cs | 28 ++++++++++------------------ 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/NPCs/CalamityNetImportantNPC.cs b/NPCs/CalamityNetImportantNPC.cs index 2fe29b4d5e..21c6bb5a98 100644 --- a/NPCs/CalamityNetImportantNPC.cs +++ b/NPCs/CalamityNetImportantNPC.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; using Terraria; using Terraria.ID; using Terraria.ModLoader; -using Terraria.ModLoader.Core; namespace CalamityMod.NPCs { @@ -40,24 +38,19 @@ namespace CalamityMod.NPCs uniqueNetOffsetID++; #endregion Vanilla Enemies - var types = AssemblyManager.GetLoadableTypes(CalamityMod.Instance.Code) - .Where(type => !type.IsAbstract && type.IsSubclassOf(typeof(ModNPC))); - - // Caching this for better performance - var npcTypeMethod = typeof(ModContent).GetMethod(nameof(ModContent.NPCType)); + var npcs = ModContent.GetContent(); var netOffsetTable = new Dictionary(); - foreach (var type in types) + foreach (var npc in npcs) { try { + var type = npc.GetType(); var longDistSync = type.GetCustomAttribute(); if (longDistSync == null) continue; - var npcTypeActualMethod = npcTypeMethod.MakeGenericMethod(typeArguments: type); - - int npcType = (int)npcTypeActualMethod.Invoke(null, null); + int npcType = npc.Type; int netOffset = uniqueNetOffsetID; Type typeToCheck = longDistSync.SyncWith ?? type; @@ -75,7 +68,7 @@ namespace CalamityMod.NPCs } catch (Exception e) { - CalamityMod.Log.Error($"Exception thrown while evaluating type \"{type.Name}\": {e}"); + CalamityMod.Log.Error($"Exception thrown while evaluating type \"{npc.FullName}\": {e}"); } } diff --git a/NPCs/CalamityPierceResistance.cs b/NPCs/CalamityPierceResistance.cs index 54e0c047f9..d9c715a9dd 100644 --- a/NPCs/CalamityPierceResistance.cs +++ b/NPCs/CalamityPierceResistance.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; using CalamityMod.Balancing; using CalamityMod.Items.Accessories; @@ -8,7 +7,6 @@ using CalamityMod.Systems.Collections; using Terraria; using Terraria.ID; using Terraria.ModLoader; -using Terraria.ModLoader.Core; using static Terraria.ModLoader.ModContent; namespace CalamityMod.NPCs @@ -75,20 +73,17 @@ namespace CalamityMod.NPCs singleHitboxExemptProjectiles[ProjectileID.ToxicCloud2] = true; singleHitboxExemptProjectiles[ProjectileID.ToxicCloud3] = true; - var projectileTypes = AssemblyManager.GetLoadableTypes(CalamityMod.Instance.Code) - .Where(type => !type.IsAbstract && type.IsSubclassOf(typeof(ModProjectile))); - - foreach (var type in projectileTypes) + var projectiles = GetContent(); + foreach (var projectile in projectiles) { try { + var type = projectile.GetType(); var pierceResistException = type.GetCustomAttribute(); if (pierceResistException == null) continue; - var projectileTypeMethod = typeof(ModContent).GetMethod(nameof(ModContent.ProjectileType)); - var projectileTypeActualMethod = projectileTypeMethod.MakeGenericMethod(type); - int projectileType = (int)projectileTypeActualMethod.Invoke(null, null); + int projectileType = projectile.Type; if (pierceResistException.OnlyForSingleHitbox) { @@ -102,24 +97,21 @@ namespace CalamityMod.NPCs } catch (Exception e) { - CalamityMod.Log.Error($"Exception thrown while evaluating type \"{type.Name}\": {e}"); + CalamityMod.Log.Error($"Exception thrown while evaluating type \"{projectile.FullName}\": {e}"); } } - var npcTypes = AssemblyManager.GetLoadableTypes(CalamityMod.Instance.Code) - .Where(type => !type.IsAbstract && type.IsSubclassOf(typeof(ModNPC))); - - foreach (var type in npcTypes) + var npcs = GetContent(); + foreach (var npc in npcs) { try { + var type = npc.GetType(); var hasPierceResist = type.GetCustomAttribute(); if (hasPierceResist == null) continue; - var npcTypeMethod = typeof(ModContent).GetMethod(nameof(ModContent.NPCType)); - var npcTypeActualMethod = npcTypeMethod.MakeGenericMethod(type); - int npcType = (int)npcTypeActualMethod.Invoke(null, null); + int npcType = npc.Type; pierceResistNPC.Add(npcType); if (hasPierceResist.SingleHitbox) @@ -127,7 +119,7 @@ namespace CalamityMod.NPCs } catch (Exception e) { - CalamityMod.Log.Error($"Exception thrown while evaluating type \"{type.Name}\": {e}"); + CalamityMod.Log.Error($"Exception thrown while evaluating type \"{npc.FullName}\": {e}"); } } }