using System; using System.IO; using Dalamud.Configuration.Internal; using Dalamud.Game; using Dalamud.Game.Command; using Dalamud.Interface.Windowing; using Dalamud.Plugin; using Dalamud.Plugin.Services; using Dalamud.Utility; using Serilog; namespace Dalamud.CorePlugin { /// /// This class is a a plugin testbed for developing new Dalamud features with easy access to Dalamud itself. /// Be careful to not commit anything extra. /// /// /// ██████╗ ███████╗ █████╗ ██████╗ ████████╗██╗ ██╗██╗███████╗ /// ██╔══██╗██╔════╝██╔══██╗██╔══██╗ ╚══██╔══╝██║ ██║██║██╔════╝ /// ██████╔╝█████╗ ███████║██║ ██║ ██║ ███████║██║███████╗ /// ██╔══██╗██╔══╝ ██╔══██║██║ ██║ ██║ ██╔══██║██║╚════██║ /// ██║ ██║███████╗██║ ██║██████╔╝ ██║ ██║ ██║██║███████║ /// ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝ /// CorePlugin should not be used as a base for new plugins. Use this instead https://github.com/goatcorp/SamplePlugin. /// While it may have similarities, it is compiled with access to Dalamud internals, which may cause confusion when /// some things work and others don't in normal operations. /// public sealed class PluginImpl : IDalamudPlugin { #if !DEBUG /// /// Initializes a new instance of the class. /// /// Dalamud plugin interface. public PluginImpl(DalamudPluginInterface pluginInterface) { } /// public void Dispose() { } #else private readonly WindowSystem windowSystem = new("Dalamud.CorePlugin"); private Localization localization; private IPluginLog pluginLog; /// /// Initializes a new instance of the class. /// /// Dalamud plugin interface. /// Logging service. public PluginImpl(DalamudPluginInterface pluginInterface, IPluginLog log, ISigScanner scanner) { try { // this.InitLoc(); this.Interface = pluginInterface; this.pluginLog = log; this.windowSystem.AddWindow(new PluginWindow()); this.pluginLog.Information(scanner.ToString()); this.Interface.UiBuilder.Draw += this.OnDraw; this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi; this.Interface.UiBuilder.OpenMainUi += this.OnOpenMainUi; Service.Get().AddHandler("/coreplug", new(this.OnCommand) { HelpMessage = "Access the plugin." }); log.Information("CorePlugin ctor!"); } catch (Exception ex) { log.Error(ex, "kaboom"); } } /// /// Gets the plugin interface. /// internal DalamudPluginInterface Interface { get; private set; } /// public void Dispose() { Service.Get().RemoveHandler("/coreplug"); this.Interface.UiBuilder.Draw -= this.OnDraw; this.windowSystem.RemoveAllWindows(); this.Interface.ExplicitDispose(); } /// /// CheapLoc needs to be reinitialized here because it tracks the setup by assembly name. New assembly, new setup. /// public void InitLoc() { var dalamud = Service.Get(); var dalamudConfig = Service.Get(); this.localization = new Localization(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "loc", "dalamud"), "dalamud_"); if (!dalamudConfig.LanguageOverride.IsNullOrEmpty()) { this.localization.SetupWithLangCode(dalamudConfig.LanguageOverride); } else { this.localization.SetupWithUiCulture(); } } /// /// Draw the window system. /// private void OnDraw() { try { this.windowSystem.Draw(); } catch (Exception ex) { this.pluginLog.Error(ex, "Boom"); } } private void OnCommand(string command, string args) { this.pluginLog.Information("Command called!"); // this.window.IsOpen = true; } private void OnOpenConfigUi() { // this.window.IsOpen = true; } private void OnOpenMainUi() { Log.Verbose("Opened main UI"); } #endif } }