66 lines
2.3 KiB
C#
66 lines
2.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using Dalamud.Game.Command;
|
|
using Dalamud.Game.Gui;
|
|
using Dalamud.IoC;
|
|
using Dalamud.Plugin;
|
|
using IronPython.Hosting;
|
|
using Microsoft.Scripting.Hosting;
|
|
|
|
namespace DalamudPython {
|
|
public class Plugin : IDalamudPlugin {
|
|
public string Name => "DalamudPython";
|
|
|
|
[PluginService]
|
|
public DalamudPluginInterface Interface { get; private init; } = null!;
|
|
|
|
[PluginService]
|
|
internal ChatGui ChatGui { get; private init; } = null!;
|
|
|
|
[PluginService]
|
|
internal CommandManager CommandManager { get; private init; } = null!;
|
|
|
|
public ScriptEngine Engine { get; } = Python.CreateEngine();
|
|
|
|
private Commands Commands { get; }
|
|
|
|
public string ConfigDirectory => Path.Combine(new[] {
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"XIVLauncher",
|
|
"pluginConfigs",
|
|
this.Name,
|
|
});
|
|
|
|
public Plugin() {
|
|
// 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(this.GetType().Assembly);
|
|
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(DalamudPluginInterface)));
|
|
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(Lumina.GameData)));
|
|
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(Lumina.Excel.ExcelRow)));
|
|
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 (name, desc) in Commands.All) {
|
|
this.CommandManager.AddHandler(name, new CommandInfo(this.Commands.OnCommand) {
|
|
HelpMessage = desc,
|
|
});
|
|
}
|
|
|
|
Directory.CreateDirectory(this.ConfigDirectory);
|
|
}
|
|
|
|
public void Dispose() {
|
|
foreach (var name in Commands.All.Keys) {
|
|
this.CommandManager.RemoveHandler(name);
|
|
}
|
|
|
|
this.Engine.Runtime.Shutdown();
|
|
}
|
|
}
|
|
}
|