feat: add plugin API for interfaces

This commit is contained in:
goat 2020-01-12 16:00:31 +09:00
parent 099e0e107b
commit feb8edb6c9
5 changed files with 71 additions and 9 deletions

View file

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Target"> <PropertyGroup Label="Target">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<TargetFramework>net48</TargetFramework> <TargetFramework>net48</TargetFramework>
@ -23,7 +23,7 @@
<DocumentationFile></DocumentationFile> <DocumentationFile></DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="EasyHook" Version="2.7.7097" /> <PackageReference Include="EasyHook" Version="2.7.6270" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using Dalamud.DiscordBot; using Dalamud.DiscordBot;
using Dalamud.Game.Chat; using Dalamud.Game.Chat;
@ -34,6 +35,7 @@ namespace Dalamud.Injector {
process = Process.Start( process = Process.Start(
"C:\\Program Files (x86)\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\ffxiv_dx11.exe", "C:\\Program Files (x86)\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\ffxiv_dx11.exe",
"DEV.TestSID=0 DEV.UseSqPack=1 DEV.DataPathType=1 DEV.LobbyHost01=127.0.0.1 DEV.LobbyPort01=54994 DEV.LobbyHost02=127.0.0.1 DEV.LobbyPort02=54994 DEV.LobbyHost03=127.0.0.1 DEV.LobbyPort03=54994 DEV.LobbyHost04=127.0.0.1 DEV.LobbyPort04=54994 DEV.LobbyHost05=127.0.0.1 DEV.LobbyPort05=54994 DEV.LobbyHost06=127.0.0.1 DEV.LobbyPort06=54994 DEV.LobbyHost07=127.0.0.1 DEV.LobbyPort07=54994 DEV.LobbyHost08=127.0.0.1 DEV.LobbyPort08=54994 SYS.Region=0 language=1 version=1.0.0.0 DEV.MaxEntitledExpansionID=2 DEV.GMServerHost=127.0.0.1 DEV.GameQuitMessageBox=0"); "DEV.TestSID=0 DEV.UseSqPack=1 DEV.DataPathType=1 DEV.LobbyHost01=127.0.0.1 DEV.LobbyPort01=54994 DEV.LobbyHost02=127.0.0.1 DEV.LobbyPort02=54994 DEV.LobbyHost03=127.0.0.1 DEV.LobbyPort03=54994 DEV.LobbyHost04=127.0.0.1 DEV.LobbyPort04=54994 DEV.LobbyHost05=127.0.0.1 DEV.LobbyPort05=54994 DEV.LobbyHost06=127.0.0.1 DEV.LobbyPort06=54994 DEV.LobbyHost07=127.0.0.1 DEV.LobbyPort07=54994 DEV.LobbyHost08=127.0.0.1 DEV.LobbyPort08=54994 SYS.Region=0 language=1 version=1.0.0.0 DEV.MaxEntitledExpansionID=2 DEV.GMServerHost=127.0.0.1 DEV.GameQuitMessageBox=0");
Thread.Sleep(1000);
break; break;
default: default:
process = Process.GetProcessById(pid); process = Process.GetProcessById(pid);

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -18,6 +19,7 @@ using Dalamud.Game.Internal.Gui;
using Dalamud.Game.Network; using Dalamud.Game.Network;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Plugin; using Dalamud.Plugin;
using ImGuiNET;
using Serilog; using Serilog;
using XIVLauncher.Dalamud; using XIVLauncher.Dalamud;
@ -52,6 +54,8 @@ namespace Dalamud {
public readonly InterfaceManager InterfaceManager; public readonly InterfaceManager InterfaceManager;
private readonly string assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString();
public Dalamud(DalamudStartInfo info) { public Dalamud(DalamudStartInfo info) {
this.StartInfo = info; this.StartInfo = info;
this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath); this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath);
@ -85,7 +89,8 @@ namespace Dalamud {
this.WinSock2 = new WinSockHandlers(); this.WinSock2 = new WinSockHandlers();
this.InterfaceManager = new InterfaceManager(this.sigScanner); this.InterfaceManager = new InterfaceManager(this.sigScanner);
//this.InterfaceManager.Start(); this.InterfaceManager.ReadyToDraw += (sender, args) => this.InterfaceManager.OnBuildUi += BuildDalamudUi;
this.InterfaceManager.Enable();
try { try {
this.PluginManager.LoadPlugins(); this.PluginManager.LoadPlugins();
@ -96,6 +101,34 @@ namespace Dalamud {
} }
} }
private bool isImguiDrawDemoWindow = true;
private bool isImguiDrawWelcome = true;
private bool neverDrawWelcome = false;
private void BuildDalamudUi() {
if (this.isImguiDrawDemoWindow)
ImGui.ShowDemoWindow();
if (this.isImguiDrawWelcome) {
if (!ImGui.Begin("Welcome to XIVLauncher", ImGuiWindowFlags.Modal | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize))
{
// Early out if the window is collapsed, as an optimization.
ImGui.End();
} else {
ImGui.Text($"dalamud says hello. ({this.assemblyVersion})");
ImGui.Checkbox("Don't show this message again", ref this.neverDrawWelcome);
ImGui.Spacing();
if (ImGui.Button("Close")) {
this.isImguiDrawWelcome = false;
}
ImGui.End();
}
}
}
public void Start() { public void Start() {
Framework.Enable(); Framework.Enable();
@ -198,6 +231,11 @@ namespace Dalamud {
{ {
HelpMessage = "Notify when a roulette has a bonus you specified. Run without parameters for more info. Usage: /xlbonus <roulette name> <role name>" HelpMessage = "Notify when a roulette has a bonus you specified. Run without parameters for more info. Usage: /xlbonus <roulette name> <role name>"
}); });
CommandManager.AddHandler("/xlduidrawdemo", new CommandInfo(OnDebugDrawImGuiDemo) {
HelpMessage = "Open ImGUI demo window",
ShowInHelp = false
});
} }
private void OnUnloadCommand(string command, string arguments) { private void OnUnloadCommand(string command, string arguments) {
@ -483,6 +521,10 @@ namespace Dalamud {
"Possible values for role: tank, dps, healer, all, none/reset"); "Possible values for role: tank, dps, healer, all, none/reset");
} }
private void OnDebugDrawImGuiDemo(string command, string arguments) {
this.isImguiDrawDemoWindow = true;
}
private int RouletteSlugToKey(string slug) => slug.ToLower() switch { private int RouletteSlugToKey(string slug) => slug.ToLower() switch {
"leveling" => 1, "leveling" => 1,
"506070" => 2, "506070" => 2,

View file

@ -48,9 +48,19 @@ namespace Dalamud.Interface
private SwapChainAddressResolver Address { get; } private SwapChainAddressResolver Address { get; }
private RawDX11Scene scene; private RawDX11Scene scene;
/// <summary>
/// This event gets called when ImGUI is ready to draw your UI.
/// </summary>
public event RawDX11Scene.BuildUIDelegate OnBuildUi
{
add => this.scene.OnBuildUI += value;
remove => this.scene.OnBuildUI -= value;
}
public EventHandler ReadyToDraw;
public InterfaceManager(SigScanner scanner) public InterfaceManager(SigScanner scanner)
{ {
Address = new SwapChainAddressResolver(); Address = new SwapChainAddressResolver();
@ -63,7 +73,6 @@ namespace Dalamud.Interface
new Hook<PresentDelegate>(Address.Present, new Hook<PresentDelegate>(Address.Present,
new PresentDelegate(PresentDetour), new PresentDelegate(PresentDetour),
this); this);
Enable();
} }
public void Enable() public void Enable()
@ -96,7 +105,8 @@ namespace Dalamud.Interface
#else #else
this.scene = new RawDX11Scene(swapChain); this.scene = new RawDX11Scene(swapChain);
#endif #endif
this.scene.OnBuildUI += DrawUI; this.scene.OnBuildUI += HandleMouseUI;
this.ReadyToDraw?.Invoke(this, null);
} }
this.scene.Render(); this.scene.Render();
@ -104,7 +114,7 @@ namespace Dalamud.Interface
return this.presentHook.Original(swapChain, syncInterval, presentFlags); return this.presentHook.Original(swapChain, syncInterval, presentFlags);
} }
private void DrawUI() private void HandleMouseUI()
{ {
// this is more or less part of what reshade/etc do to avoid having to manually // this is more or less part of what reshade/etc do to avoid having to manually
// set the cursor inside the ui // set the cursor inside the ui
@ -112,8 +122,6 @@ namespace Dalamud.Interface
// the normal one from the game, and the one for ImGui // the normal one from the game, and the one for ImGui
// Doing this here because it's somewhat application-specific behavior // Doing this here because it's somewhat application-specific behavior
ImGui.GetIO().MouseDrawCursor = ImGui.GetIO().WantCaptureMouse; ImGui.GetIO().MouseDrawCursor = ImGui.GetIO().WantCaptureMouse;
ImGui.ShowDemoWindow();
} }
} }
} }

View file

@ -10,6 +10,7 @@ using Dalamud.Game.ClientState;
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Game.Internal; using Dalamud.Game.Internal;
using Dalamud.Game.Internal.Gui; using Dalamud.Game.Internal.Gui;
using Dalamud.Interface;
namespace Dalamud.Plugin namespace Dalamud.Plugin
{ {
@ -32,6 +33,11 @@ namespace Dalamud.Plugin
/// </summary> /// </summary>
public readonly Framework Framework; public readonly Framework Framework;
/// <summary>
/// The InterfaceManager object which allows you to draw UI into the game via ImGui draw calls.
/// </summary>
public readonly InterfaceManager Interface;
private readonly Dalamud dalamud; private readonly Dalamud dalamud;
private readonly string pluginName; private readonly string pluginName;
@ -43,6 +49,7 @@ namespace Dalamud.Plugin
this.CommandManager = dalamud.CommandManager; this.CommandManager = dalamud.CommandManager;
this.Framework = dalamud.Framework; this.Framework = dalamud.Framework;
this.ClientState = dalamud.ClientState; this.ClientState = dalamud.ClientState;
this.Interface = dalamud.InterfaceManager;
this.dalamud = dalamud; this.dalamud = dalamud;
this.pluginName = pluginName; this.pluginName = pluginName;
@ -61,6 +68,9 @@ namespace Dalamud.Plugin
return; return;
} }
if (currentConfig == null)
return;
this.dalamud.Configuration.PluginConfigurations.Add(this.pluginName, currentConfig); this.dalamud.Configuration.PluginConfigurations.Add(this.pluginName, currentConfig);
this.dalamud.Configuration.Save(this.dalamud.StartInfo.ConfigurationPath); this.dalamud.Configuration.Save(this.dalamud.StartInfo.ConfigurationPath);
} }