Magic the magic happen

This commit is contained in:
Raymond Lynch 2021-07-11 16:32:29 -04:00
parent 84769ae5b7
commit 658eedca37
188 changed files with 10329 additions and 3549 deletions

View file

@ -1,10 +1,10 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Configuration;
using Dalamud.Configuration.Internal;
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Game.Addon;
@ -13,17 +13,24 @@ using Dalamud.Game.Command;
using Dalamud.Game.Internal;
using Dalamud.Game.Network;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Interface;
using Dalamud.Plugin;
using Dalamud.Hooking.Internal;
using Dalamud.Interface.Internal;
using Dalamud.Memory;
using Dalamud.Plugin.Internal;
using Serilog;
using Serilog.Core;
#if DEBUG
// This allows for rapid prototyping of Dalamud modules with access to internal objects.
[assembly: InternalsVisibleTo("Dalamud.CorePlugin")]
#endif
namespace Dalamud
{
/// <summary>
/// The main Dalamud class containing all subsystems.
/// </summary>
public sealed class Dalamud : IDisposable
internal sealed class Dalamud : IDisposable
{
#region Internals
@ -31,8 +38,6 @@ namespace Dalamud
private readonly ManualResetEvent finishUnloadSignal;
private readonly string baseDirectory;
private bool hasDisposedPlugins = false;
#endregion
@ -46,11 +51,14 @@ namespace Dalamud
/// <param name="configuration">The Dalamud configuration.</param>
public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch, ManualResetEvent finishSignal, DalamudConfiguration configuration)
{
#if DEBUG
Instance = this;
#endif
this.StartInfo = info;
this.LogLevelSwitch = loggingLevelSwitch;
this.Configuration = configuration;
this.baseDirectory = info.WorkingDirectory;
// this.baseDirectory = info.WorkingDirectory;
this.unloadSignal = new ManualResetEvent(false);
this.unloadSignal.Reset();
@ -59,6 +67,13 @@ namespace Dalamud
this.finishUnloadSignal.Reset();
}
#if DEBUG
/// <summary>
/// Gets the Dalamud singleton instance.
/// </summary>
internal static Dalamud Instance { get; private set; }
#endif
#region Native Game Subsystems
/// <summary>
@ -76,6 +91,11 @@ namespace Dalamud
/// </summary>
internal WinSockHandlers WinSock2 { get; private set; }
/// <summary>
/// Gets Hook management subsystem.
/// </summary>
internal HookManager HookManager { get; private set; }
/// <summary>
/// Gets ImGui Interface subsystem.
/// </summary>
@ -95,11 +115,6 @@ namespace Dalamud
/// </summary>
internal PluginManager PluginManager { get; private set; }
/// <summary>
/// Gets Plugin Repository subsystem.
/// </summary>
internal PluginRepository PluginRepository { get; private set; }
/// <summary>
/// Gets Data provider subsystem.
/// </summary>
@ -205,6 +220,7 @@ namespace Dalamud
// Initialize the process information.
this.TargetModule = Process.GetCurrentProcess().MainModule;
this.SigScanner = new SigScanner(this.TargetModule, true);
this.HookManager = new HookManager(this);
// Initialize game subsystem
this.Framework = new Framework(this.SigScanner, this);
@ -289,6 +305,7 @@ namespace Dalamud
Log.Information("[T2] Data OK!");
this.SeStringManager = new SeStringManager(this.Data);
MemoryHelper.Initialize(this); // For SeString handling
Log.Information("[T2] SeString OK!");
@ -327,28 +344,18 @@ namespace Dalamud
{
Log.Information("[T3] START!");
this.PluginRepository =
new PluginRepository(this, this.StartInfo.PluginDirectory, this.StartInfo.GameVersion);
Log.Information("[T3] PREPO OK!");
if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false"))
{
try
{
this.PluginRepository.CleanupPlugins();
Log.Information("[T3] PRC OK!");
this.PluginManager = new PluginManager(
this,
this.StartInfo.PluginDirectory,
this.StartInfo.DefaultPluginDirectory);
this.PluginManager.LoadSynchronousPlugins();
Task.Run(() => this.PluginManager.LoadDeferredPlugins());
this.PluginManager = new PluginManager(this);
Log.Information("[T3] PM OK!");
this.PluginManager.CleanupPlugins();
Log.Information("[T3] PMC OK!");
this.PluginManager.LoadAllPlugins();
Log.Information("[T3] PML OK!");
}
catch (Exception ex)
{
@ -357,8 +364,6 @@ namespace Dalamud
}
this.DalamudUi = new DalamudInterface(this);
this.InterfaceManager.OnDraw += this.DalamudUi.Draw;
Log.Information("[T3] DUI OK!");
Troubleshooting.LogTroubleshooting(this, this.InterfaceManager != null);
@ -410,16 +415,9 @@ namespace Dalamud
// use any resources that it freed in its own Dispose method
this.InterfaceManager?.Dispose();
try
{
this.PluginManager.UnloadPlugins();
}
catch (Exception ex)
{
Log.Error(ex, "Plugin unload failed.");
}
this.DalamudUi?.Dispose();
this.PluginManager?.Dispose();
}
/// <summary>
@ -436,20 +434,23 @@ namespace Dalamud
}
this.Framework?.Dispose();
this.ClientState?.Dispose();
this.unloadSignal?.Dispose();
this.WinSock2?.Dispose();
this.SigScanner?.Dispose();
this.Data?.Dispose();
this.AntiDebug?.Dispose();
this.SystemMenu?.Dispose();
this.HookManager?.Dispose();
this.SigScanner?.Dispose();
Log.Debug("Dalamud::Dispose() OK!");
}
catch (Exception ex)