58 lines
2.2 KiB
C#
58 lines
2.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using Dalamud.Game.Command;
|
|
using Dalamud.Plugin;
|
|
using IronPython.Hosting;
|
|
using Microsoft.Scripting.Hosting;
|
|
|
|
namespace DalamudPython {
|
|
public class Plugin : IDalamudPlugin {
|
|
public string Name => "DalamudPython";
|
|
|
|
public DalamudPluginInterface Interface { get; private set; } = null!;
|
|
|
|
public ScriptEngine Engine { get; } = Python.CreateEngine();
|
|
|
|
private Commands Commands { get; set; } = null!;
|
|
|
|
public string ConfigDirectory => Path.Combine(new[] {
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"XIVLauncher",
|
|
"pluginConfigs",
|
|
this.Name,
|
|
});
|
|
|
|
public void Initialize(DalamudPluginInterface pluginInterface) {
|
|
this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface));
|
|
|
|
// set a global variable for the plugin interface
|
|
this.Engine.Runtime.Globals.SetVariable("interface", this.Interface);
|
|
// load Dalamud, Lumina, and ImGuiNET
|
|
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(DalamudPluginInterface)));
|
|
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(Lumina.Lumina)));
|
|
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(Lumina.Excel.IExcelRow)));
|
|
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(Lumina.Excel.GeneratedSheets.Achievement)));
|
|
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(ImGuiNET.ImGui)));
|
|
|
|
this.Commands = new Commands(this);
|
|
|
|
foreach (var command in Commands.All) {
|
|
this.Interface.CommandManager.AddHandler(command.Key, new CommandInfo(this.Commands.OnCommand) {
|
|
HelpMessage = command.Value,
|
|
});
|
|
}
|
|
|
|
Directory.CreateDirectory(this.ConfigDirectory);
|
|
}
|
|
|
|
public void Dispose() {
|
|
foreach (var name in Commands.All.Keys) {
|
|
this.Interface.CommandManager.RemoveHandler(name);
|
|
}
|
|
|
|
this.Engine.Runtime.Shutdown();
|
|
}
|
|
}
|
|
}
|