Compare commits

..

2 commits

Author SHA1 Message Date
3a54a2781f
Bump version 2025-01-15 00:53:06 +01:00
27ec1f0e39
Add hotkey, fix unload race 2025-01-15 00:52:33 +01:00
6 changed files with 168 additions and 23 deletions

View file

@ -1,6 +1,9 @@
using Dalamud.Configuration; using Dalamud.Configuration;
using Dalamud.Game.ClientState.Keys;
using Dalamud.Plugin; using Dalamud.Plugin;
using System; using System;
using System.Collections.Generic;
using System.Reflection;
namespace CustomResolution; namespace CustomResolution;
@ -15,6 +18,9 @@ public class Configuration : IPluginConfiguration
public uint Width = 1024; public uint Width = 1024;
public uint Height = 1024; public uint Height = 1024;
public VirtualKey HotkeyKey = VirtualKey.NO_KEY;
public ModifierKey HotkeyModifier = ModifierKey.NONE;
public DXVKDWMHackMode DXVKDWMHackMode = DXVKDWMHackMode.Off; public DXVKDWMHackMode DXVKDWMHackMode = DXVKDWMHackMode.Off;
[NonSerialized] [NonSerialized]
@ -68,3 +74,52 @@ public static class DXVKDWMHackModeExt
_ => false _ => false
}; };
} }
public enum ModifierKey
{
NONE = 0,
CTRL = 1,
ALT = 2,
SHIFT = 4
}
public static class VirtualKeyExt
{
private static readonly Dictionary<VirtualKey, string> _strings = new();
static VirtualKeyExt()
{
foreach (var field in typeof(VirtualKey).GetFields(BindingFlags.Public | BindingFlags.Static))
{
var key = (VirtualKey) field.GetValue(null)!;
_strings[key] = key.GetFancyName();
}
}
public static string ToHumanNameString(this VirtualKey mode)
{
return _strings[mode];
}
public static string? ToHumanInfoString(this VirtualKey mode) => mode switch
{
_ => null
};
}
public static class ModifierKeyExt
{
public static string ToHumanNameString(this ModifierKey mode) => mode switch
{
ModifierKey.NONE => "None",
ModifierKey.CTRL => "Ctrl",
ModifierKey.ALT => "Alt",
ModifierKey.SHIFT => "Shift",
_ => mode.ToString(),
};
public static string? ToHumanInfoString(this ModifierKey mode) => mode switch
{
_ => null
};
}

View file

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Authors>0x0ade</Authors> <Authors>0x0ade</Authors>
<Company></Company> <Company></Company>
<Version>0.2.0.4</Version> <Version>0.2.1.0</Version>
<Description></Description> <Description></Description>
<Copyright></Copyright> <Copyright></Copyright>
<PackageProjectUrl></PackageProjectUrl> <PackageProjectUrl></PackageProjectUrl>

View file

@ -1,9 +1,12 @@
using Dalamud.IoC; using Dalamud.Game.ClientState.Keys;
using Dalamud.IoC;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel; using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel;
using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Common.Lua;
using FFXIVClientStructs.Interop; using FFXIVClientStructs.Interop;
using ImGuiNET;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -14,6 +17,8 @@ namespace CustomResolution;
public sealed unsafe class Plugin : IDalamudPlugin public sealed unsafe class Plugin : IDalamudPlugin
{ {
private object _disposeLock = new();
private readonly HRGN _invisibleRgn; private readonly HRGN _invisibleRgn;
private readonly List<Cmd> _cmds; private readonly List<Cmd> _cmds;
@ -68,12 +73,16 @@ public sealed unsafe class Plugin : IDalamudPlugin
public void Dispose() public void Dispose()
{ {
_tickCount = 0;
_unloading = true; _unloading = true;
lock (_disposeLock)
{
_tickCount = 0;
Service.Framework.Update -= OnFrameworkUpdate; Service.Framework.Update -= OnFrameworkUpdate;
Service.Framework.RunOnFrameworkThread(Update); Service.Framework.RunOnFrameworkThread(Update);
}
foreach (Cmd cmd in _cmds) foreach (Cmd cmd in _cmds)
{ {
@ -310,6 +319,25 @@ public sealed unsafe class Plugin : IDalamudPlugin
private void OnFrameworkUpdate(IFramework framework) private void OnFrameworkUpdate(IFramework framework)
{ {
lock (_disposeLock)
{
var io = ImGui.GetIO();
if (Service.Config.HotkeyKey != VirtualKey.NO_KEY &&
(ImGuiNative.igIsKeyPressed((ImGuiKey) Service.Config.HotkeyKey, 0) != 0 || Service.KeyState.GetRawValue(Service.Config.HotkeyKey) != 0) &&
(Service.Config.HotkeyModifier switch
{
ModifierKey.NONE => !io.KeyCtrl && !io.KeyAlt && !io.KeyShift,
ModifierKey.CTRL => io.KeyCtrl && !io.KeyAlt && !io.KeyShift,
ModifierKey.ALT => !io.KeyCtrl && io.KeyAlt && !io.KeyShift,
ModifierKey.SHIFT => !io.KeyCtrl && !io.KeyAlt && io.KeyShift,
_ => false,
}))
{
Service.Config.IsEnabled = !Service.Config.IsEnabled;
Service.Config.Save();
}
var dev = Device.Instance(); var dev = Device.Instance();
_currentHwnd = (HWND) (IntPtr) dev->hWnd; _currentHwnd = (HWND) (IntPtr) dev->hWnd;
@ -321,7 +349,7 @@ public sealed unsafe class Plugin : IDalamudPlugin
GetWindowRect(_currentHwnd, currentWindowRectPtr); GetWindowRect(_currentHwnd, currentWindowRectPtr);
} }
if (_tickCount++ >= 10) if (_tickCount++ >= 2)
{ {
_tickCount = 0; _tickCount = 0;
@ -331,3 +359,4 @@ public sealed unsafe class Plugin : IDalamudPlugin
_tickCount++; _tickCount++;
} }
} }
}

View file

@ -10,6 +10,7 @@ public sealed class PluginUI : IDisposable
internal PluginUI() internal PluginUI()
{ {
Service.PluginInterface.UiBuilder.DisableGposeUiHide = true;
Service.PluginInterface.UiBuilder.Draw += Draw; Service.PluginInterface.UiBuilder.Draw += Draw;
Service.PluginInterface.UiBuilder.OpenConfigUi += ShowConfigWindow; Service.PluginInterface.UiBuilder.OpenConfigUi += ShowConfigWindow;

View file

@ -38,6 +38,9 @@ public sealed class Service
[PluginService] [PluginService]
public static IChatGui ChatGui { get; private set; } = null!; public static IChatGui ChatGui { get; private set; } = null!;
[PluginService]
public static IKeyState KeyState { get; private set; } = null!;
public static void PrintChat(string msg) public static void PrintChat(string msg)
{ {
ChatGui.Print(new XivChatEntry ChatGui.Print(new XivChatEntry

View file

@ -1,16 +1,22 @@
using Dalamud.Interface.Windowing; using Dalamud.Game.ClientState.Keys;
using Dalamud.Interface.Windowing;
using ImGuiNET; using ImGuiNET;
using System; using System;
using System.Linq;
using System.Numerics; using System.Numerics;
namespace CustomResolution.Windows; namespace CustomResolution.Windows;
public class ConfigWindow : Window, IDisposable public class ConfigWindow : Window, IDisposable
{ {
private VirtualKey[] _validKeys = new VirtualKey[] { VirtualKey.NO_KEY }.Union(Service.KeyState.GetValidVirtualKeys()).ToArray();
private int[] _displayCurrentWH = new int[2]; private int[] _displayCurrentWH = new int[2];
private int[] _displayCurrentWindowWH = new int[2]; private int[] _displayCurrentWindowWH = new int[2];
private bool _configIsEnabled; private bool _configIsEnabled;
private VirtualKey _configHotkeyKey;
private ModifierKey _configHotkeyModifier;
private bool _configIsScale; private bool _configIsScale;
private float _configScale; private float _configScale;
private int[] _configWH = new int[2]; private int[] _configWH = new int[2];
@ -32,6 +38,8 @@ public class ConfigWindow : Window, IDisposable
var config = Service.Config; var config = Service.Config;
_configIsEnabled = config.IsEnabled; _configIsEnabled = config.IsEnabled;
_configHotkeyKey = config.HotkeyKey;
_configHotkeyModifier = config.HotkeyModifier;
_configIsScale = config.IsScale; _configIsScale = config.IsScale;
_configScale = config.Scale; _configScale = config.Scale;
_configWH[0] = (int) config.Width; _configWH[0] = (int) config.Width;
@ -44,6 +52,8 @@ public class ConfigWindow : Window, IDisposable
var config = Service.Config; var config = Service.Config;
config.IsEnabled = _configIsEnabled; config.IsEnabled = _configIsEnabled;
config.HotkeyKey = _configHotkeyKey;
config.HotkeyModifier = _configHotkeyModifier;
config.IsScale = _configIsScale; config.IsScale = _configIsScale;
config.Scale = _configScale; config.Scale = _configScale;
config.Width = (uint) _configWH[0]; config.Width = (uint) _configWH[0];
@ -70,6 +80,53 @@ public class ConfigWindow : Window, IDisposable
ImGui.Checkbox("Enabled", ref _configIsEnabled); ImGui.Checkbox("Enabled", ref _configIsEnabled);
ImGui.SameLine();
ImGui.Dummy(new Vector2(20, 0));
ImGui.SameLine();
ImGui.SetNextItemWidth(80);
if (ImGui.BeginCombo("##_configHotkeyModifier", _configHotkeyModifier.ToHumanNameString()))
{
foreach (var key in Enum.GetValues<ModifierKey>())
{
if (ImGui.Selectable(key.ToHumanNameString(), _configHotkeyModifier == key, ImGuiSelectableFlags.None))
{
_configHotkeyModifier = key;
}
if (ImGui.IsItemHovered() && key.ToHumanInfoString() is { } info)
{
ImGui.SetTooltip(info);
}
}
ImGui.EndCombo();
}
ImGui.SameLine();
ImGui.SetNextItemWidth(160);
if (ImGui.BeginCombo("##_configHotkeyKey", _configHotkeyKey.ToHumanNameString()))
{
foreach (var key in _validKeys)
{
if (ImGui.Selectable(key.ToHumanNameString(), _configHotkeyKey == key, ImGuiSelectableFlags.None))
{
_configHotkeyKey = key;
}
if (ImGui.IsItemHovered() && key.ToHumanInfoString() is { } info)
{
ImGui.SetTooltip(info);
}
}
ImGui.EndCombo();
}
ImGui.SameLine();
ImGui.Text("Hotkey");
if (!_configIsEnabled) if (!_configIsEnabled)
{ {
ImGui.BeginDisabled(); ImGui.BeginDisabled();