82 lines
2.8 KiB
C#
82 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Terraria;
|
|
using Terraria.ModLoader;
|
|
using Emiliasmod.Content.Items.Ammo;
|
|
using Emiliasmod.Content.Items.Accessories;
|
|
using Emiliasmod.Content.Items.Weapon;
|
|
using Emiliasmod.Content.Projectiles;
|
|
|
|
// Please read https://github.com/tModLoader/tModLoader/wiki/Basic-tModLoader-Modding-Guide#mod-skeleton-contents for more information about the various files in a mod.
|
|
namespace Emiliasmod
|
|
{
|
|
public static class InternalLoader {
|
|
public static void Load(Mod mod) {
|
|
var types = mod.Code.GetTypes();
|
|
|
|
foreach (Type type in types) {
|
|
// 1. Must be a class and not abstract
|
|
// 2. Must implement ILoadable (this covers ModItem, ModNPC, ModSystem, etc.)
|
|
// 3. Optional: Check if it has the [Autoload(false)] attribute to confirm it's your target
|
|
// !type.IsAbstract is the key here to skip BaseWing itself
|
|
if (!type.IsAbstract && typeof(ILoadable).IsAssignableFrom(type)) {
|
|
var instance = (ILoadable)Activator.CreateInstance(type);
|
|
mod.AddContent(instance);
|
|
}
|
|
}
|
|
}
|
|
public static void Unload(Mod mod) {
|
|
// Manual cleanup for statics if necessary
|
|
// 1. Clear custom lists/dictionaries
|
|
// hitTargets.Clear();
|
|
|
|
// 2. Nullify static references to textures/assets
|
|
// MyBaseClass.CustomShader = null;
|
|
|
|
// 3. Use Reflection to nullify all statics in a specific namespace (Extreme approach)
|
|
// Only do this if you have hundreds of static fields and want to be "lazy" but safe.
|
|
var types = mod.Code.GetTypes();
|
|
foreach (var type in types) {
|
|
// Look for any static fields that are classes (not value types)
|
|
var staticFields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
|
foreach (var field in staticFields) {
|
|
if (!field.FieldType.IsValueType) {
|
|
field.SetValue(null, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class Emiliasmod : Mod
|
|
{
|
|
public const string AssetPath = $"{nameof(Emiliasmod)}/Assets/";
|
|
//public override bool IsLoadingEnabled(Mod tModLoader) => true;
|
|
//need to load all of the mods here
|
|
//Terraria.ModLoader.VanillaDamageClass;
|
|
public override void Load() {
|
|
//InternalLoader.Load(this);
|
|
////Spacesuit spacesuit = new Spacesuit(Spacesui);
|
|
//// Manual registration happens here
|
|
AddContent<VacuumTube>();
|
|
AddContent<QuantumVacuumTube>();
|
|
AddContent<SpaceBlaster>();
|
|
AddContent<SpaceBlasterProjectile>();
|
|
AddContent<Spacesuit>();
|
|
AddContent<Spacesurf>();
|
|
AddContent<EmiliasWand>();
|
|
AddContent<EmiliasWandProjectile>();
|
|
}
|
|
|
|
public override void Unload() {
|
|
//InternalLoader.Unload(this);
|
|
// Clear caches, static references, or arrays
|
|
}
|
|
}
|
|
}
|