mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Implement DI for scratchpad
This commit is contained in:
parent
c864cae087
commit
506731d7fe
4 changed files with 135 additions and 31 deletions
|
|
@ -4,7 +4,6 @@ using System.Linq;
|
||||||
|
|
||||||
using Dalamud.IoC.Internal;
|
using Dalamud.IoC.Internal;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using ImGuiNET;
|
|
||||||
using Microsoft.CodeAnalysis.CSharp.Scripting;
|
using Microsoft.CodeAnalysis.CSharp.Scripting;
|
||||||
using Microsoft.CodeAnalysis.Scripting;
|
using Microsoft.CodeAnalysis.Scripting;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
@ -60,21 +59,46 @@ namespace Dalamud.Interface.Internal.Scratchpad
|
||||||
var code = doc.IsMacro ? this.MacroProcessor.Process(doc.Content) : doc.Content;
|
var code = doc.IsMacro ? this.MacroProcessor.Process(doc.Content) : doc.Content;
|
||||||
|
|
||||||
var options = ScriptOptions.Default
|
var options = ScriptOptions.Default
|
||||||
.AddReferences(typeof(ImGui).Assembly)
|
// Dalamud
|
||||||
.AddReferences(typeof(Dalamud).Assembly)
|
.AddReferences(typeof(Dalamud).Assembly)
|
||||||
.AddReferences(typeof(FFXIVClientStructs.Resolver).Assembly) // FFXIVClientStructs
|
// ImGui
|
||||||
.AddReferences(typeof(Lumina.GameData).Assembly) // Lumina
|
.AddReferences(typeof(ImGuiNET.ImGui).Assembly)
|
||||||
.AddReferences(typeof(Lumina.Excel.GeneratedSheets.TerritoryType).Assembly) // Lumina.Excel
|
// ImGuiScene
|
||||||
// .WithReferences(MetadataReference.CreateFromFile(typeof(ScratchExecutionManager).Assembly.Location))
|
.AddReferences(typeof(ImGuiScene.RawDX11Scene).Assembly)
|
||||||
.AddImports("System")
|
// FFXIVClientStructs
|
||||||
.AddImports("System.IO")
|
.AddReferences(typeof(FFXIVClientStructs.Resolver).Assembly)
|
||||||
.AddImports("System.Reflection")
|
// Lumina
|
||||||
.AddImports("System.Runtime.InteropServices")
|
.AddReferences(typeof(Lumina.GameData).Assembly)
|
||||||
.AddImports("Dalamud")
|
// Lumina.Excel
|
||||||
.AddImports("Dalamud.Plugin")
|
.AddReferences(typeof(Lumina.Excel.GeneratedSheets.TerritoryType).Assembly)
|
||||||
.AddImports("Dalamud.Game.Command")
|
.AddImports("System")
|
||||||
.AddImports("Dalamud.Hooking")
|
.AddImports("System.IO")
|
||||||
.AddImports("ImGuiNET");
|
.AddImports("System.Reflection")
|
||||||
|
.AddImports("System.Runtime.InteropServices")
|
||||||
|
.AddImports("Dalamud")
|
||||||
|
.AddImports("Dalamud.Data")
|
||||||
|
.AddImports("Dalamud.Game")
|
||||||
|
.AddImports("Dalamud.Game.ClientState")
|
||||||
|
.AddImports("Dalamud.Game.ClientState.Buddy")
|
||||||
|
.AddImports("Dalamud.Game.ClientState.Conditions")
|
||||||
|
.AddImports("Dalamud.Game.ClientState.Fates")
|
||||||
|
.AddImports("Dalamud.Game.ClientState.JobGauge")
|
||||||
|
.AddImports("Dalamud.Game.ClientState.Keys")
|
||||||
|
.AddImports("Dalamud.Game.ClientState.Objects")
|
||||||
|
.AddImports("Dalamud.Game.ClientState.Party")
|
||||||
|
.AddImports("Dalamud.Game.Command")
|
||||||
|
.AddImports("Dalamud.Game.Gui")
|
||||||
|
.AddImports("Dalamud.Game.Gui.FlyText")
|
||||||
|
.AddImports("Dalamud.Game.Gui.PartyFinder")
|
||||||
|
.AddImports("Dalamud.Game.Gui.Toast")
|
||||||
|
.AddImports("Dalamud.Hooking")
|
||||||
|
.AddImports("Dalamud.Game.Libc")
|
||||||
|
.AddImports("Dalamud.Game.Network")
|
||||||
|
.AddImports("Dalamud.Game.Text.SeStringHandling")
|
||||||
|
.AddImports("Dalamud.Logging")
|
||||||
|
.AddImports("Dalamud.Plugin")
|
||||||
|
.AddImports("Dalamud.Utility")
|
||||||
|
.AddImports("ImGuiNET");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,83 @@ namespace Dalamud.Interface.Internal.Scratchpad
|
||||||
public class ScratchPlugin : IDalamudPlugin {
|
public class ScratchPlugin : IDalamudPlugin {
|
||||||
|
|
||||||
public string Name => ""ScratchPlugin"";
|
public string Name => ""ScratchPlugin"";
|
||||||
private DalamudPluginInterface pi;
|
|
||||||
|
private readonly DalamudPluginInterface pi;
|
||||||
|
private readonly BuddyList buddies;
|
||||||
|
private readonly ChatGui chat;
|
||||||
|
private readonly ChatHandlers chatHandlers;
|
||||||
|
private readonly ClientState clientState;
|
||||||
|
private readonly CommandManager commands;
|
||||||
|
private readonly Condition condition;
|
||||||
|
private readonly DataManager data;
|
||||||
|
private readonly FateTable fates;
|
||||||
|
private readonly FlyTextGui flyText;
|
||||||
|
private readonly Framework framework;
|
||||||
|
private readonly GameGui gameGui;
|
||||||
|
private readonly GameNetwork gameNetwork;
|
||||||
|
private readonly JobGauges gauges;
|
||||||
|
private readonly KeyState keyState;
|
||||||
|
private readonly LibcFunction libc;
|
||||||
|
private readonly ObjectTable objects;
|
||||||
|
private readonly PartyFinderGui pfGui;
|
||||||
|
private readonly PartyList party;
|
||||||
|
private readonly SeStringManager seStringManager;
|
||||||
|
private readonly SigScanner sigScanner;
|
||||||
|
private readonly TargetManager targets;
|
||||||
|
private readonly ToastGui toasts;
|
||||||
|
|
||||||
{SETUPBODY}
|
{SETUPBODY}
|
||||||
|
|
||||||
public ScratchPlugin(DalamudPluginInterface pluginInterface)
|
public ScratchPlugin(
|
||||||
|
DalamudPluginInterface pluginInterface,
|
||||||
|
BuddyList buddies,
|
||||||
|
ChatGui chat,
|
||||||
|
ChatHandlers chatHandlers,
|
||||||
|
ClientState clientState,
|
||||||
|
CommandManager commands,
|
||||||
|
Condition condition,
|
||||||
|
DataManager data,
|
||||||
|
FateTable fates,
|
||||||
|
FlyTextGui flyText,
|
||||||
|
Framework framework,
|
||||||
|
GameGui gameGui,
|
||||||
|
GameNetwork gameNetwork,
|
||||||
|
JobGauges gauges,
|
||||||
|
KeyState keyState,
|
||||||
|
LibcFunction libcFunction,
|
||||||
|
ObjectTable objects,
|
||||||
|
PartyFinderGui pfGui,
|
||||||
|
PartyList party,
|
||||||
|
SeStringManager seStringManager,
|
||||||
|
SigScanner sigScanner,
|
||||||
|
TargetManager targets,
|
||||||
|
ToastGui toasts)
|
||||||
{
|
{
|
||||||
this.pi = pluginInterface;
|
this.pi = pluginInterface;
|
||||||
|
|
||||||
|
this.buddies = buddies;
|
||||||
|
this.chat = chat;
|
||||||
|
this.chatHandlers = chatHandlers;
|
||||||
|
this.clientState = clientState;
|
||||||
|
this.commands = commands;
|
||||||
|
this.condition = condition;
|
||||||
|
this.data = data;
|
||||||
|
this.fates = fates;
|
||||||
|
this.flyText = flyText;
|
||||||
|
this.framework = framework;
|
||||||
|
this.gameGui = gameGui;
|
||||||
|
this.gameNetwork = gameNetwork;
|
||||||
|
this.gauges = gauges;
|
||||||
|
this.keyState = keyState;
|
||||||
|
this.libc = libcFunction;
|
||||||
|
this.objects = objects;
|
||||||
|
this.pfGui = pfGui;
|
||||||
|
this.party = party;
|
||||||
|
this.seStringManager = seStringManager;
|
||||||
|
this.sigScanner = sigScanner;
|
||||||
|
this.targets = targets;
|
||||||
|
this.toasts = toasts;
|
||||||
|
|
||||||
this.pi.UiBuilder.Draw += DrawUI;
|
this.pi.UiBuilder.Draw += DrawUI;
|
||||||
|
|
||||||
{INITBODY}
|
{INITBODY}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Dalamud.IoC.Internal
|
||||||
var ctor = this.FindApplicableCtor(objectType, scopedObjects);
|
var ctor = this.FindApplicableCtor(objectType, scopedObjects);
|
||||||
if (ctor == null)
|
if (ctor == null)
|
||||||
{
|
{
|
||||||
Log.Error("Failed to create {TypeName}, unable to find any services to satisfy the dependencies in the ctor", objectType.FullName);
|
Log.Error("Failed to create {TypeName}, unable to find one or more services to satisfy the dependencies in the ctor", objectType.FullName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ namespace Dalamud.IoC.Internal
|
||||||
|
|
||||||
if (service == null)
|
if (service == null)
|
||||||
{
|
{
|
||||||
Log.Error("Requested service type {TypeName} could not be satisfied", p.parameterType.FullName);
|
Log.Error("Requested service type {TypeName} was not available (null)", p.parameterType.FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
|
@ -142,20 +142,35 @@ namespace Dalamud.IoC.Internal
|
||||||
// get a list of all the available types: scoped and singleton
|
// get a list of all the available types: scoped and singleton
|
||||||
var types = scopedObjects
|
var types = scopedObjects
|
||||||
.Select(o => o.GetType())
|
.Select(o => o.GetType())
|
||||||
.Union(this.instances.Keys);
|
.Union(this.instances.Keys)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
var ctors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
|
var ctors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
|
||||||
foreach (var ctor in ctors)
|
foreach (var ctor in ctors)
|
||||||
{
|
{
|
||||||
var parameters = ctor.GetParameters();
|
if (this.ValidateCtor(ctor, types))
|
||||||
|
{
|
||||||
var success = parameters.All(p => types.Contains(p.ParameterType));
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
return ctor;
|
return ctor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool ValidateCtor(ConstructorInfo ctor, Type[] types)
|
||||||
|
{
|
||||||
|
var parameters = ctor.GetParameters();
|
||||||
|
foreach (var parameter in parameters)
|
||||||
|
{
|
||||||
|
var contains = types.Contains(parameter.ParameterType);
|
||||||
|
if (!contains)
|
||||||
|
{
|
||||||
|
Log.Error("Failed to validate {TypeName}, unable to find any services that satisfy the type", parameter.ParameterType.FullName);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Dynamic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -8,9 +7,6 @@ using System.Reflection;
|
||||||
using Dalamud.Configuration;
|
using Dalamud.Configuration;
|
||||||
using Dalamud.Configuration.Internal;
|
using Dalamud.Configuration.Internal;
|
||||||
using Dalamud.Data;
|
using Dalamud.Data;
|
||||||
using Dalamud.Game;
|
|
||||||
using Dalamud.Game.ClientState;
|
|
||||||
using Dalamud.Game.Command;
|
|
||||||
using Dalamud.Game.Gui;
|
using Dalamud.Game.Gui;
|
||||||
using Dalamud.Game.Text;
|
using Dalamud.Game.Text;
|
||||||
using Dalamud.Game.Text.Sanitizer;
|
using Dalamud.Game.Text.Sanitizer;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue