using System; using Dalamud.Extensions.MicrosoftLogging; using Dalamud.Game; using Dalamud.Game.ClientState.Objects; using Dalamud.Interface.Windowing; using Dalamud.Plugin; using Dalamud.Plugin.Services; using LLib; using LLib.Gear; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Questionable.Controller; using Questionable.Controller.CombatModules; using Questionable.Controller.GameUi; using Questionable.Controller.NavigationOverrides; using Questionable.Controller.Steps; using Questionable.Controller.Steps.Common; using Questionable.Controller.Steps.Gathering; using Questionable.Controller.Steps.Interactions; using Questionable.Controller.Steps.Movement; using Questionable.Controller.Steps.Shared; using Questionable.Controller.Utils; using Questionable.Data; using Questionable.External; using Questionable.Functions; using Questionable.Validation; using Questionable.Validation.Validators; using Questionable.Windows; using Questionable.Windows.ConfigComponents; using Questionable.Windows.JournalComponents; using Questionable.Windows.QuestComponents; using Questionable.Windows.Utils; namespace Questionable; public sealed class QuestionablePlugin : IDalamudPlugin, IDisposable { private readonly ServiceProvider? _serviceProvider; public QuestionablePlugin(IDalamudPluginInterface pluginInterface, IClientState clientState, ITargetManager targetManager, IFramework framework, IGameGui gameGui, IDataManager dataManager, ISigScanner sigScanner, IObjectTable objectTable, IPluginLog pluginLog, ICondition condition, IChatGui chatGui, ICommandManager commandManager, IAddonLifecycle addonLifecycle, IKeyState keyState, IContextMenu contextMenu, IToastGui toastGui, IGameInteropProvider gameInteropProvider, IAetheryteList aetheryteList) { ArgumentNullException.ThrowIfNull(pluginInterface, "pluginInterface"); ArgumentNullException.ThrowIfNull(chatGui, "chatGui"); try { ServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddLogging(delegate(ILoggingBuilder builder) { builder.SetMinimumLevel(LogLevel.Trace).ClearProviders().AddDalamudLogger(pluginLog, delegate(string t) { int num = t.LastIndexOf('.') + 1; return t.Substring(num, t.Length - num); }); }); ((IServiceCollection)serviceCollection).AddSingleton((IDalamudPlugin)this); serviceCollection.AddSingleton(pluginInterface); serviceCollection.AddSingleton(clientState); serviceCollection.AddSingleton(targetManager); serviceCollection.AddSingleton(framework); serviceCollection.AddSingleton(gameGui); serviceCollection.AddSingleton(dataManager); serviceCollection.AddSingleton(sigScanner); serviceCollection.AddSingleton(objectTable); serviceCollection.AddSingleton(pluginLog); serviceCollection.AddSingleton(condition); serviceCollection.AddSingleton(chatGui); serviceCollection.AddSingleton(commandManager); serviceCollection.AddSingleton(addonLifecycle); serviceCollection.AddSingleton(keyState); serviceCollection.AddSingleton(contextMenu); serviceCollection.AddSingleton(toastGui); serviceCollection.AddSingleton(gameInteropProvider); serviceCollection.AddSingleton(aetheryteList); serviceCollection.AddSingleton(new WindowSystem("Questionable")); serviceCollection.AddSingleton(((Configuration)pluginInterface.GetPluginConfig()) ?? new Configuration()); AddBasicFunctionsAndData(serviceCollection); AddTaskFactories(serviceCollection); AddControllers(serviceCollection); AddWindows(serviceCollection); AddQuestValidators(serviceCollection); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); _serviceProvider = serviceCollection.BuildServiceProvider(); Initialize(_serviceProvider); } catch (Exception) { chatGui.PrintError("Unable to load plugin, check /xllog for details", "Questionable"); throw; } } private static void AddBasicFunctionsAndData(ServiceCollection serviceCollection) { serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); } private static void AddTaskFactories(ServiceCollection serviceCollection) { serviceCollection.AddTaskFactory(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactory(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactory(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactory(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactory(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactoryAndExecutor(); serviceCollection.AddTaskFactory(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskFactory(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddTaskExecutor(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); } private static void AddControllers(ServiceCollection serviceCollection) { serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); } private static void AddWindows(ServiceCollection serviceCollection) { serviceCollection.AddSingleton(); serviceCollection.AddTransient(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); } private static void AddQuestValidators(ServiceCollection serviceCollection) { serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); ((IServiceCollection)serviceCollection).AddSingleton((Func)((IServiceProvider sp) => sp.GetRequiredService())); } private static void Initialize(IServiceProvider serviceProvider) { serviceProvider.GetRequiredService().Reload(); serviceProvider.GetRequiredService().Reload(); serviceProvider.GetRequiredService().Reload(); serviceProvider.GetRequiredService(); serviceProvider.GetRequiredService(); serviceProvider.GetRequiredService(); serviceProvider.GetRequiredService(); serviceProvider.GetRequiredService(); serviceProvider.GetRequiredService(); serviceProvider.GetRequiredService(); serviceProvider.GetRequiredService(); serviceProvider.GetRequiredService(); } public void Dispose() { _serviceProvider?.Dispose(); } }