152 lines
5.5 KiB
C#
152 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using CalamityMod.FluidSimulation;
|
|
using CalamityMod.Items;
|
|
using CalamityMod.Particles;
|
|
using CalamityMod.Projectiles;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.ModLoader;
|
|
using Terraria.ModLoader.Config;
|
|
|
|
[assembly: InternalsVisibleTo("CalTestHelpers")]
|
|
[assembly: InternalsVisibleTo("InfernumMode")]
|
|
namespace CalamityMod
|
|
{
|
|
public class CalamityMod : Mod
|
|
{
|
|
#region External Flags
|
|
// External flag to disable non-Revengeance boss AI edits
|
|
// This can be edited by other mods using reflection to prevent compatibility issues
|
|
public static bool ExternalFlag_DisableNonRevBossAI = false;
|
|
|
|
// External flag to disable Defense Damage
|
|
// This can be edited by other mods using reflection if desired
|
|
// Note that this flag trumps Bloodflare Core and will stop that accessory from working properly.
|
|
// There is also a means to disable defense damage on a per-player basis.
|
|
public static bool ExternalFlag_DisableDefenseDamage = false;
|
|
#endregion
|
|
|
|
internal static CalamityMod Instance => _Instance ??= ModContent.GetInstance<CalamityMod>();
|
|
private static CalamityMod _Instance;
|
|
|
|
#region Load
|
|
public override void Load()
|
|
{
|
|
// Initialize the EnemyStats struct as early as it is safe to do so
|
|
NPCStats.Load();
|
|
|
|
// Initialize Calamity Balance, since it is tightly coupled with the remaining systems
|
|
CalamityGlobalItem.LoadTweaks();
|
|
CalamityGlobalProjectile.LoadTweaks();
|
|
|
|
if (!Main.dedServ)
|
|
{
|
|
// This must be done separately from immediate loading, as loading is now multithreaded.
|
|
// However, render targets and certain other graphical objects can only be created on the main thread.
|
|
Main.QueueMainThreadAction(() => Main.OnPreDraw += PrepareRenderTargets);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Unload
|
|
public override void Unload()
|
|
{
|
|
NPCStats.Unload();
|
|
CalamityGlobalItem.UnloadTweaks();
|
|
CalamityGlobalProjectile.UnloadTweaks();
|
|
|
|
Main.QueueMainThreadAction(() =>
|
|
{
|
|
Main.OnPreDraw -= PrepareRenderTargets;
|
|
});
|
|
|
|
_Instance = null;
|
|
base.Unload();
|
|
}
|
|
#endregion
|
|
|
|
#region Render Target Management
|
|
|
|
public static void PrepareRenderTargets(GameTime gameTime)
|
|
{
|
|
DeathAshParticle.PrepareRenderTargets();
|
|
FluidFieldManager.Update();
|
|
}
|
|
#endregion Render Target Management
|
|
|
|
#region Force ModConfig save (Reflection)
|
|
internal static void SaveConfig(CalamityClientConfig cfg)
|
|
{
|
|
// There is no current way to manually save a mod configuration file in tModLoader.
|
|
// The method which saves mod config files is private in ConfigManager, so reflection is used to invoke it.
|
|
try
|
|
{
|
|
MethodInfo saveMethodInfo = typeof(ConfigManager).GetMethod("Save", BindingFlags.Static | BindingFlags.NonPublic);
|
|
if (saveMethodInfo is not null)
|
|
saveMethodInfo.Invoke(null, new object[] { cfg });
|
|
else
|
|
Instance.Logger.Error("TML ConfigManager.Save reflection failed. Method signature has changed. Notify Calamity Devs if you see this in your log.");
|
|
}
|
|
catch
|
|
{
|
|
Instance.Logger.Error("An error occurred while manually saving Calamity mod configuration. This may be due to a complex mod conflict. It is safe to ignore this error.");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Music
|
|
|
|
// This function returns an available Calamity Music Mod track, or null if the Calamity Music Mod is not available.
|
|
public int? GetMusicFromMusicMod(string songFilename) => ExternalMods.MusicAvailable ? MusicLoader.GetMusicSlot(ExternalMods.musicMod, "Sounds/Music/" + songFilename) : null;
|
|
|
|
// This function returns an available VCMM track, or null if VCMM is not available.
|
|
// Unlike the main Music Mod, VCMM is hierarchical.
|
|
public int? GetMusicFromVCMM(string songPath) => ExternalMods.VCMMAvailable ? MusicLoader.GetMusicSlot(ExternalMods.vcmm, "Assets/" + songPath) : null;
|
|
|
|
#endregion
|
|
|
|
#region Mod Support
|
|
public override object Call(params object[] args) => ModCalls.Call(args);
|
|
#endregion
|
|
|
|
#region Seasons
|
|
public static Season CurrentSeason
|
|
{
|
|
get
|
|
{
|
|
DateTime date = DateTime.Now;
|
|
int day = date.DayOfYear - Convert.ToInt32(DateTime.IsLeapYear(date.Year) && date.DayOfYear > 59);
|
|
|
|
if (day < 80 || day >= 355)
|
|
{
|
|
return Season.Winter;
|
|
}
|
|
|
|
else if (day >= 80 && day < 172)
|
|
{
|
|
return Season.Spring;
|
|
}
|
|
|
|
else if (day >= 172 && day < 266)
|
|
{
|
|
return Season.Summer;
|
|
}
|
|
|
|
else
|
|
{
|
|
return Season.Fall;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Netcode
|
|
public override void HandlePacket(BinaryReader reader, int whoAmI) => CalamityNetcode.HandlePacket(this, reader, whoAmI);
|
|
#endregion
|
|
}
|
|
}
|