mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: add plugin API for interfaces
This commit is contained in:
parent
099e0e107b
commit
feb8edb6c9
5 changed files with 71 additions and 9 deletions
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup Label="Target">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
<DocumentationFile></DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EasyHook" Version="2.7.7097" />
|
||||
<PackageReference Include="EasyHook" Version="2.7.6270" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using Dalamud.DiscordBot;
|
||||
using Dalamud.Game.Chat;
|
||||
|
|
@ -34,6 +35,7 @@ namespace Dalamud.Injector {
|
|||
process = Process.Start(
|
||||
"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");
|
||||
Thread.Sleep(1000);
|
||||
break;
|
||||
default:
|
||||
process = Process.GetProcessById(pid);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -18,6 +19,7 @@ using Dalamud.Game.Internal.Gui;
|
|||
using Dalamud.Game.Network;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Plugin;
|
||||
using ImGuiNET;
|
||||
using Serilog;
|
||||
using XIVLauncher.Dalamud;
|
||||
|
||||
|
|
@ -52,6 +54,8 @@ namespace Dalamud {
|
|||
|
||||
public readonly InterfaceManager InterfaceManager;
|
||||
|
||||
private readonly string assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString();
|
||||
|
||||
public Dalamud(DalamudStartInfo info) {
|
||||
this.StartInfo = info;
|
||||
this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath);
|
||||
|
|
@ -85,7 +89,8 @@ namespace Dalamud {
|
|||
this.WinSock2 = new WinSockHandlers();
|
||||
|
||||
this.InterfaceManager = new InterfaceManager(this.sigScanner);
|
||||
//this.InterfaceManager.Start();
|
||||
this.InterfaceManager.ReadyToDraw += (sender, args) => this.InterfaceManager.OnBuildUi += BuildDalamudUi;
|
||||
this.InterfaceManager.Enable();
|
||||
|
||||
try {
|
||||
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() {
|
||||
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>"
|
||||
});
|
||||
|
||||
CommandManager.AddHandler("/xlduidrawdemo", new CommandInfo(OnDebugDrawImGuiDemo) {
|
||||
HelpMessage = "Open ImGUI demo window",
|
||||
ShowInHelp = false
|
||||
});
|
||||
}
|
||||
|
||||
private void OnUnloadCommand(string command, string arguments) {
|
||||
|
|
@ -483,6 +521,10 @@ namespace Dalamud {
|
|||
"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 {
|
||||
"leveling" => 1,
|
||||
"506070" => 2,
|
||||
|
|
|
|||
|
|
@ -48,9 +48,19 @@ namespace Dalamud.Interface
|
|||
|
||||
private SwapChainAddressResolver Address { get; }
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
Address = new SwapChainAddressResolver();
|
||||
|
|
@ -63,7 +73,6 @@ namespace Dalamud.Interface
|
|||
new Hook<PresentDelegate>(Address.Present,
|
||||
new PresentDelegate(PresentDetour),
|
||||
this);
|
||||
Enable();
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
|
|
@ -96,7 +105,8 @@ namespace Dalamud.Interface
|
|||
#else
|
||||
this.scene = new RawDX11Scene(swapChain);
|
||||
#endif
|
||||
this.scene.OnBuildUI += DrawUI;
|
||||
this.scene.OnBuildUI += HandleMouseUI;
|
||||
this.ReadyToDraw?.Invoke(this, null);
|
||||
}
|
||||
|
||||
this.scene.Render();
|
||||
|
|
@ -104,7 +114,7 @@ namespace Dalamud.Interface
|
|||
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
|
||||
// set the cursor inside the ui
|
||||
|
|
@ -112,8 +122,6 @@ namespace Dalamud.Interface
|
|||
// the normal one from the game, and the one for ImGui
|
||||
// Doing this here because it's somewhat application-specific behavior
|
||||
ImGui.GetIO().MouseDrawCursor = ImGui.GetIO().WantCaptureMouse;
|
||||
|
||||
ImGui.ShowDemoWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using Dalamud.Game.ClientState;
|
|||
using Dalamud.Game.Command;
|
||||
using Dalamud.Game.Internal;
|
||||
using Dalamud.Game.Internal.Gui;
|
||||
using Dalamud.Interface;
|
||||
|
||||
namespace Dalamud.Plugin
|
||||
{
|
||||
|
|
@ -32,6 +33,11 @@ namespace Dalamud.Plugin
|
|||
/// </summary>
|
||||
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 string pluginName;
|
||||
|
||||
|
|
@ -43,6 +49,7 @@ namespace Dalamud.Plugin
|
|||
this.CommandManager = dalamud.CommandManager;
|
||||
this.Framework = dalamud.Framework;
|
||||
this.ClientState = dalamud.ClientState;
|
||||
this.Interface = dalamud.InterfaceManager;
|
||||
|
||||
this.dalamud = dalamud;
|
||||
this.pluginName = pluginName;
|
||||
|
|
@ -61,6 +68,9 @@ namespace Dalamud.Plugin
|
|||
return;
|
||||
}
|
||||
|
||||
if (currentConfig == null)
|
||||
return;
|
||||
|
||||
this.dalamud.Configuration.PluginConfigurations.Add(this.pluginName, currentConfig);
|
||||
this.dalamud.Configuration.Save(this.dalamud.StartInfo.ConfigurationPath);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue