Skip to content

Commit

Permalink
Fixed inner Sets types not getting their arrays resized.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirsario committed Jul 7, 2020
1 parent 4bd11a4 commit 3f5f115
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 8 deletions.
3 changes: 2 additions & 1 deletion patches/tModLoader/Terraria/ModLoader/BuffLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Terraria.ID;
using Terraria.Localization;
using Terraria.GameContent;
using Terraria.ModLoader.Core;

namespace Terraria.ModLoader
{
Expand Down Expand Up @@ -82,7 +83,7 @@ internal static void ResizeArrays() {
Array.Resize(ref TextureAssets.Buff, nextBuff);

//Sets
typeof(BuffID.Sets).TypeInitializer.Invoke(null, null);
LoaderUtils.ReloadSets(typeof(BuffID.Sets));

//Etc
Array.Resize(ref Main.pvpBuff, nextBuff);
Expand Down
17 changes: 17 additions & 0 deletions patches/tModLoader/Terraria/ModLoader/Core/LoaderUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace Terraria.ModLoader.Core
{
internal static class LoaderUtils
{
public static void ReloadSets(Type setsType) {
setsType.TypeInitializer.Invoke(null, null);

foreach (var type in setsType.GetNestedTypes()) {
if (type.IsAbstract && type.IsSealed) { //IsStatic
type.TypeInitializer?.Invoke(null, null);
}
}
}
}
}
3 changes: 2 additions & 1 deletion patches/tModLoader/Terraria/ModLoader/ItemLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Terraria.GameContent;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader.Core;
using Terraria.ModLoader.IO;
using Terraria.UI;
using Terraria.Utilities;
Expand Down Expand Up @@ -87,7 +88,7 @@ internal static void ResizeArrays(bool unloading) {
Array.Resize(ref TextureAssets.ItemFlame, nextItem);

//Sets
typeof(ItemID.Sets).TypeInitializer.Invoke(null, null);
LoaderUtils.ReloadSets(typeof(ItemID.Sets));

//Etc
Array.Resize(ref Main.itemAnimations, nextItem);
Expand Down
3 changes: 2 additions & 1 deletion patches/tModLoader/Terraria/ModLoader/ModGore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using Terraria.GameContent;
using Terraria.ID;
using Terraria.ModLoader.Core;

namespace Terraria.ModLoader
{
Expand Down Expand Up @@ -44,7 +45,7 @@ internal static void ResizeAndFillArrays() {
Array.Resize(ref TextureAssets.Gore, nextGore);

//Sets
typeof(GoreID.Sets).TypeInitializer.Invoke(null, null);
LoaderUtils.ReloadSets(typeof(GoreID.Sets));
Array.Resize(ref ChildSafety.SafeGore, nextGore);

for (int k = GoreID.Count; k < nextGore; k++) {
Expand Down
3 changes: 2 additions & 1 deletion patches/tModLoader/Terraria/ModLoader/MountLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader.Core;

namespace Terraria.ModLoader
{
Expand Down Expand Up @@ -37,7 +38,7 @@ internal static int ReserveMountID() {

internal static void ResizeArrays() {
//Sets
typeof(MountID.Sets).TypeInitializer.Invoke(null, null);
LoaderUtils.ReloadSets(typeof(MountID.Sets));

//Etc
Array.Resize(ref Mount.mounts, MountCount);
Expand Down
3 changes: 2 additions & 1 deletion patches/tModLoader/Terraria/ModLoader/NPCLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Terraria.GameContent.UI;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader.Core;

namespace Terraria.ModLoader
{
Expand Down Expand Up @@ -104,7 +105,7 @@ internal static void ResizeArrays(bool unloading) {
Array.Resize(ref TextureAssets.Npc, nextNPC);

//Sets
typeof(NPCID.Sets).TypeInitializer.Invoke(null, null);
LoaderUtils.ReloadSets(typeof(NPCID.Sets));

//Etc
Array.Resize(ref Main.townNPCCanSpawn, nextNPC);
Expand Down
3 changes: 2 additions & 1 deletion patches/tModLoader/Terraria/ModLoader/ProjectileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Terraria.GameContent;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader.Core;

namespace Terraria.ModLoader
{
Expand Down Expand Up @@ -67,7 +68,7 @@ internal static void ResizeArrays() {
Array.Resize(ref TextureAssets.Projectile, nextProjectile);

//Sets
typeof(ProjectileID.Sets).TypeInitializer.Invoke(null, null);
LoaderUtils.ReloadSets(typeof(ProjectileID.Sets));

//Etc
Array.Resize(ref Main.projHostile, nextProjectile);
Expand Down
3 changes: 2 additions & 1 deletion patches/tModLoader/Terraria/ModLoader/TileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Terraria.Audio;
using Terraria.GameContent;
using Terraria.ID;
using Terraria.ModLoader.Core;
using Terraria.ObjectData;

namespace Terraria.ModLoader
Expand Down Expand Up @@ -123,7 +124,7 @@ internal static void ResizeArrays(bool unloading = false) {
Array.Resize(ref TextureAssets.HighlightMask, nextTile);

//Sets
typeof(TileID.Sets).TypeInitializer.Invoke(null, null);
LoaderUtils.ReloadSets(typeof(TileID.Sets));

//Etc
Array.Resize(ref Main.tileLighted, nextTile);
Expand Down
3 changes: 2 additions & 1 deletion patches/tModLoader/Terraria/ModLoader/WallLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Terraria.Audio;
using Terraria.GameContent;
using Terraria.ID;
using Terraria.ModLoader.Core;

namespace Terraria.ModLoader
{
Expand Down Expand Up @@ -70,7 +71,7 @@ internal static void ResizeArrays(bool unloading = false) {
Array.Resize(ref TextureAssets.Wall, nextWall);

//Sets
typeof(WallID.Sets).TypeInitializer.Invoke(null, null);
LoaderUtils.ReloadSets(typeof(WallID.Sets));

//Etc
Array.Resize(ref Main.wallHouse, nextWall);
Expand Down

0 comments on commit 3f5f115

Please sign in to comment.