From 48ad5660d3d40ddd15aa2b61c52454392ea35869 Mon Sep 17 00:00:00 2001 From: Aireil <33433913+Aireil@users.noreply.github.com> Date: Thu, 29 Apr 2021 05:37:45 +0200 Subject: [PATCH 1/4] feat: toggle instead of open in system menu --- Dalamud/Game/Addon/DalamudSystemMenu.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dalamud/Game/Addon/DalamudSystemMenu.cs b/Dalamud/Game/Addon/DalamudSystemMenu.cs index 8d1d38a47..c6b0da8f3 100644 --- a/Dalamud/Game/Addon/DalamudSystemMenu.cs +++ b/Dalamud/Game/Addon/DalamudSystemMenu.cs @@ -140,11 +140,11 @@ namespace Dalamud.Game.Addon { if (commandId == 69420) { - this.dalamud.DalamudUi.OpenPluginInstaller(); + this.dalamud.DalamudUi.TogglePluginInstaller(); } else if (commandId == 69421) { - this.dalamud.DalamudUi.OpenSettings(); + this.dalamud.DalamudUi.ToggleSettings(); } else { From 82c1c48d408ac15288bd0897c30d8054a2c9fa75 Mon Sep 17 00:00:00 2001 From: Aireil <33433913+Aireil@users.noreply.github.com> Date: Thu, 29 Apr 2021 05:49:26 +0200 Subject: [PATCH 2/4] refractor: small code style update in DalamudSystemMenu.cs --- Dalamud/Game/Addon/DalamudSystemMenu.cs | 52 ++++++++++++------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/Dalamud/Game/Addon/DalamudSystemMenu.cs b/Dalamud/Game/Addon/DalamudSystemMenu.cs index c6b0da8f3..7f8590c1b 100644 --- a/Dalamud/Game/Addon/DalamudSystemMenu.cs +++ b/Dalamud/Game/Addon/DalamudSystemMenu.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; using System.Text; -using System.Threading.Tasks; + using CheapLoc; using Dalamud.Hooking; using FFXIVClientStructs.FFXIV.Component.GUI; @@ -16,9 +14,9 @@ namespace Dalamud.Game.Addon { private readonly Dalamud dalamud; - private delegate void AgentHudOpenSystemMenuProtoype(void* thisPtr, AtkValue* atkValueArgs, uint menuSize); + private delegate void AgentHudOpenSystemMenuPrototype(void* thisPtr, AtkValue* atkValueArgs, uint menuSize); - private Hook hookAgentHudOpenSystemMenu; + private Hook hookAgentHudOpenSystemMenu; private delegate void AtkValueChangeType(AtkValue* thisPtr, ValueType type); @@ -43,9 +41,9 @@ namespace Dalamud.Game.Addon var openSystemMenuAddress = this.dalamud.SigScanner.ScanText("E8 ?? ?? ?? ?? 32 C0 4C 8B AC 24 ?? ?? ?? ?? 48 8B 8D ?? ?? ?? ??"); - this.hookAgentHudOpenSystemMenu = new Hook( + this.hookAgentHudOpenSystemMenu = new Hook( openSystemMenuAddress, - new AgentHudOpenSystemMenuProtoype(this.AgentHudOpenSystemMenuDetour), + new AgentHudOpenSystemMenuPrototype(this.AgentHudOpenSystemMenuDetour), this); var atkValueChangeTypeAddress = @@ -57,10 +55,10 @@ namespace Dalamud.Game.Addon this.dalamud.SigScanner.ScanText("E8 ?? ?? ?? ?? 41 03 ED"); this.atkValueSetString = Marshal.GetDelegateForFunctionPointer(atkValueSetStringAddress); - var uiModuleRequestMainCommmandAddress = this.dalamud.SigScanner.ScanText( + var uiModuleRequestMainCommandAddress = this.dalamud.SigScanner.ScanText( "40 53 56 48 81 EC ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 ?? ?? ?? ?? 48 8B 01 8B DA 48 8B F1 FF 90 ?? ?? ?? ??"); this.hookUiModuleRequestMainCommand = new Hook( - uiModuleRequestMainCommmandAddress, + uiModuleRequestMainCommandAddress, new UiModuleRequestMainCommand(this.UiModuleRequestMainCommandDetour), this); } @@ -78,7 +76,7 @@ namespace Dalamud.Game.Addon // see if we can add 2 entries if (menuSize >= 0xD) { - hookAgentHudOpenSystemMenu.Original(thisPtr, atkValueArgs, menuSize); + this.hookAgentHudOpenSystemMenu.Original(thisPtr, atkValueArgs, menuSize); return; } @@ -88,10 +86,10 @@ namespace Dalamud.Game.Addon // reference the original function for more details :) // step 1) move all the current menu items down so we can put Dalamud at the top like it deserves - atkValueChangeType(&atkValueArgs[menuSize + 5], ValueType.Int); // currently this value has no type, set it to int - atkValueChangeType(&atkValueArgs[menuSize + 5 + 1], ValueType.Int); + this.atkValueChangeType(&atkValueArgs[menuSize + 5], ValueType.Int); // currently this value has no type, set it to int + this.atkValueChangeType(&atkValueArgs[menuSize + 5 + 1], ValueType.Int); - for (uint i = menuSize+2; i > 1; i--) + for (uint i = menuSize + 2; i > 1; i--) { var curEntry = &atkValueArgs[i + 5 - 2]; var nextEntry = &atkValueArgs[i + 5]; @@ -109,9 +107,9 @@ namespace Dalamud.Game.Addon // since the game first checks for strings in the AtkValue argument before pulling them from the exd, if we create strings we dont have to worry // about hooking the exd reader, thank god var firstStringEntry = &atkValueArgs[5 + 15]; - atkValueChangeType(firstStringEntry, ValueType.String); + this.atkValueChangeType(firstStringEntry, ValueType.String); var secondStringEntry = &atkValueArgs[6 + 15]; - atkValueChangeType(secondStringEntry, ValueType.String); + this.atkValueChangeType(secondStringEntry, ValueType.String); var strPlugins = Encoding.UTF8.GetBytes(Loc.Localize("SystemMenuPlugins", "Dalamud Plugins")); var strSettings = Encoding.UTF8.GetBytes(Loc.Localize("SystemMenuSettings", "Dalamud Settings")); @@ -121,13 +119,13 @@ namespace Dalamud.Game.Addon Marshal.Copy(strPlugins, 0, new IntPtr(bytes), strPlugins.Length); bytes[strPlugins.Length] = 0x0; - atkValueSetString(firstStringEntry, bytes); // this allocs the string properly using the game's allocators and copies it, so we dont have to worry about memory fuckups + this.atkValueSetString(firstStringEntry, bytes); // this allocs the string properly using the game's allocators and copies it, so we dont have to worry about memory fuckups var bytes2 = stackalloc byte[strSettings.Length + 1]; Marshal.Copy(strSettings, 0, new IntPtr(bytes2), strSettings.Length); bytes2[strSettings.Length] = 0x0; - atkValueSetString(secondStringEntry, bytes2); + this.atkValueSetString(secondStringEntry, bytes2); // open menu with new size var sizeEntry = &atkValueArgs[4]; @@ -138,17 +136,17 @@ namespace Dalamud.Game.Addon private void UiModuleRequestMainCommandDetour(void* thisPtr, int commandId) { - if (commandId == 69420) + switch (commandId) { - this.dalamud.DalamudUi.TogglePluginInstaller(); - } - else if (commandId == 69421) - { - this.dalamud.DalamudUi.ToggleSettings(); - } - else - { - this.hookUiModuleRequestMainCommand.Original(thisPtr, commandId); + case 69420: + this.dalamud.DalamudUi.TogglePluginInstaller(); + break; + case 69421: + this.dalamud.DalamudUi.ToggleSettings(); + break; + default: + this.hookUiModuleRequestMainCommand.Original(thisPtr, commandId); + break; } } From 8219e230eb9f8d751370801f6cc19e69dec2376b Mon Sep 17 00:00:00 2001 From: Aireil <33433913+Aireil@users.noreply.github.com> Date: Thu, 29 Apr 2021 06:21:03 +0200 Subject: [PATCH 3/4] fix: game crashing when plugin master is loading --- Dalamud/Plugin/PluginInstallerWindow.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Dalamud/Plugin/PluginInstallerWindow.cs b/Dalamud/Plugin/PluginInstallerWindow.cs index c117261fc..b0e0fe3f8 100644 --- a/Dalamud/Plugin/PluginInstallerWindow.cs +++ b/Dalamud/Plugin/PluginInstallerWindow.cs @@ -192,7 +192,8 @@ namespace Dalamud.Plugin } else { - if (ImGui.Button(Loc.Localize("InstallerUpdatePlugins", "Update plugins"))) + if (ImGui.Button(Loc.Localize("InstallerUpdatePlugins", "Update plugins")) && + this.dalamud.PluginRepository.State == PluginRepository.InitializationState.Success) { this.installStatus = PluginInstallStatus.InProgress; @@ -217,7 +218,8 @@ namespace Dalamud.Plugin this.errorModalDrawing = this.installStatus == PluginInstallStatus.Fail; this.errorModalOnNextFrame = this.installStatus == PluginInstallStatus.Fail; - this.dalamud.PluginRepository.PrintUpdatedPlugins(this.updatedPlugins, Loc.Localize("DalamudPluginUpdates", "Updates:")); + this.dalamud.PluginRepository.PrintUpdatedPlugins( + this.updatedPlugins, Loc.Localize("DalamudPluginUpdates", "Updates:")); this.RefetchPlugins(); }); @@ -305,8 +307,11 @@ namespace Dalamud.Plugin private void ResortPlugins() { + if (this.dalamud.PluginRepository.State != PluginRepository.InitializationState.Success) + return; + var availableDefs = this.dalamud.PluginRepository.PluginMaster.Where( - x => this.pluginListInstalled.All(y => x.InternalName != y.InternalName)) + x => this.pluginListInstalled.All(y => x.InternalName != y.InternalName)) .GroupBy(x => new { x.InternalName, x.AssemblyVersion }) .Select(y => y.First()).ToList(); From 6bea0ab38a76368a9963af15bd3d5528ba685381 Mon Sep 17 00:00:00 2001 From: Aireil <33433913+Aireil@users.noreply.github.com> Date: Thu, 29 Apr 2021 09:00:00 +0200 Subject: [PATCH 4/4] fix: raw plugins not loading without config file --- Dalamud/Plugin/PluginManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dalamud/Plugin/PluginManager.cs b/Dalamud/Plugin/PluginManager.cs index ffc9715ea..4d625d86a 100644 --- a/Dalamud/Plugin/PluginManager.cs +++ b/Dalamud/Plugin/PluginManager.cs @@ -149,7 +149,7 @@ namespace Dalamud.Plugin return prio2.CompareTo(prio1); }); - this.deferredPlugins = pluginDefs.Where(x => x.definition?.LoadPriority <= 0); + this.deferredPlugins = pluginDefs.Where(x => x.definition == null || x.definition.LoadPriority <= 0); // Pass preloaded definitions for "synchronous load" plugins to LoadPluginFromAssembly, because we already loaded them anyways foreach (var (dllFile, definition, isRaw) in pluginDefs.Where(x => x.definition?.LoadPriority > 0))