diff --git a/Configuration.cs b/Configuration.cs index b800c48..9fa59be 100644 --- a/Configuration.cs +++ b/Configuration.cs @@ -28,6 +28,7 @@ public class Configuration : IPluginConfiguration { """; public GamepadButtons GamepadKeybind = GamepadButtons.L1 | GamepadButtons.Start; + public bool DisableNativeScreenshots = true; private int _templateHashCode; private Template? _template; diff --git a/GameFunctions.cs b/GameFunctions.cs new file mode 100644 index 0000000..e42a02f --- /dev/null +++ b/GameFunctions.cs @@ -0,0 +1,32 @@ +using Dalamud.Hooking; +using Dalamud.Utility.Signatures; + +namespace Screenie; + +internal unsafe class GameFunctions : IDisposable { + private Plugin Plugin { get; } + + private delegate byte TakeScreenshotDelegate(nint a1, nint a2, nint a3); + + [Signature("E8 ?? ?? ?? ?? 84 C0 75 22 F3 0F 10 05", DetourName = nameof(TakeScreenshotDetour))] + private Hook _takeScreenshotHook; + + internal GameFunctions(Plugin plugin) { + this.Plugin = plugin; + this.Plugin.GameInteropProvider.InitializeFromAttributes(this); + + this._takeScreenshotHook!.Enable(); + } + + public void Dispose() { + this._takeScreenshotHook.Dispose(); + } + + private byte TakeScreenshotDetour(nint a1, nint a2, nint a3) { + if (this.Plugin.Config.DisableNativeScreenshots) { + return 0; + } + + return this._takeScreenshotHook.Original(a1, a2, a3); + } +} diff --git a/Plugin.cs b/Plugin.cs index b9c99dd..9ac9f87 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -43,6 +43,9 @@ public sealed class Plugin : IDalamudPlugin { [PluginService] internal IGameGui GameGui { get; init; } + [PluginService] + internal IGameInteropProvider GameInteropProvider { get; init; } + [PluginService] internal IGamepadState GamepadState { get; init; } @@ -50,6 +53,7 @@ public sealed class Plugin : IDalamudPlugin { internal IObjectTable ObjectTable { get; init; } internal Configuration Config { get; } + internal GameFunctions GameFunctions { get; } internal PenumbraIpc Penumbra { get; } internal Database Database { get; } internal LinkHandlers LinkHandlers { get; } @@ -60,6 +64,7 @@ public sealed class Plugin : IDalamudPlugin { #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public Plugin() { this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration(); + this.GameFunctions = new GameFunctions(this); this.Penumbra = new PenumbraIpc(this); this.Database = new Database(this); this.LinkHandlers = new LinkHandlers(this); @@ -79,6 +84,7 @@ public sealed class Plugin : IDalamudPlugin { this.LinkHandlers.Dispose(); this.Database.Dispose(); // this.Penumbra.Dispose(); + this.GameFunctions.Dispose(); } internal void SaveConfig() { diff --git a/Ui/Tabs/SettingsTab.cs b/Ui/Tabs/SettingsTab.cs index 58be717..9194950 100644 --- a/Ui/Tabs/SettingsTab.cs +++ b/Ui/Tabs/SettingsTab.cs @@ -124,6 +124,8 @@ internal class SettingsTab : ITab { } } + anyChanged |= ImGui.Checkbox("Disable vanilla in-game screenshots", ref this.Plugin.Config.DisableNativeScreenshots); + if (anyChanged) { this.Plugin.SaveConfig(); }