Workaround for direct chat not triggering on special keys

This commit is contained in:
Infi
2024-04-15 23:33:50 +02:00
parent 78e8f763e0
commit 230e63033d
3 changed files with 433 additions and 400 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.21.0</Version>
<Version>1.21.1</Version>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
+28 -41
View File
@@ -1,4 +1,5 @@
using System.Numerics;
using System.Text;
using ChatTwo.Code;
using ChatTwo.GameFunctions.Types;
using ChatTwo.Util;
@@ -16,11 +17,13 @@ using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
using FFXIVClientStructs.FFXIV.Client.UI.Shell;
using FFXIVClientStructs.FFXIV.Component.GUI;
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
namespace ChatTwo.GameFunctions;
internal sealed unsafe class Chat : IDisposable {
internal sealed unsafe class Chat : IDisposable
{
// Functions
[Signature("E8 ?? ?? ?? ?? 0F B7 44 37 ??", Fallibility = Fallibility.Fallible)]
@@ -351,39 +354,6 @@ internal sealed unsafe class Chat : IDisposable {
["CMD_BEGINNER_ALWAYS"] = new(InputChannel.NoviceNetwork, true),
};
private bool _inputFocused;
private int _graceFrames;
private void CheckFocus()
{
void Decrement()
{
if (_graceFrames > 0)
_graceFrames -= 1;
else
_inputFocused = false;
}
// 6.08: CB8F27
var isTextInputActivePtr = *(bool**) ((IntPtr) AtkStage.GetSingleton() + 0x28) + 0x188E;
if (isTextInputActivePtr == null)
{
Decrement();
return;
}
if (*isTextInputActivePtr)
{
_inputFocused = true;
_graceFrames = 60;
}
else
{
Decrement();
}
}
private void UpdateKeybinds()
{
foreach (var name in KeybindsToIntercept.Keys)
@@ -398,8 +368,6 @@ internal sealed unsafe class Chat : IDisposable {
private void InterceptKeybinds(IFramework framework1)
{
// CheckFocus();
// Refresh current keybinds every 5s
if (LastRefresh + 5 * 1000 < Environment.TickCount64)
{
@@ -407,8 +375,6 @@ internal sealed unsafe class Chat : IDisposable {
LastRefresh = Environment.TickCount64;
}
// if (_inputFocused)
// return;
var modifierState = (ModifierFlag) 0;
foreach (var modifier in Enum.GetValues<ModifierFlag>())
@@ -484,15 +450,37 @@ internal sealed unsafe class Chat : IDisposable {
if (eventId != 0x31 || value == null || value->UInt is not (0x05 or 0x0C))
return ChatLogRefreshHook!.Original(log, eventId, value);
string? input = null;
if (Plugin.GameConfig.TryGet(UiControlOption.DirectChat, out bool option) && option)
{
if (CurrentCharacter != null)
{
// FIXME: this whole system sucks
var c = *CurrentCharacter;
// FIXME v2: I hate everything about this, but it works
Plugin.Framework.RunOnTick(() =>
{
string? input = null;
var utf8Bytes = MemoryHelper.ReadRaw((nint) CurrentCharacter, 2);
var chars = Encoding.UTF8.GetString(utf8Bytes).ToCharArray();
if (chars.Length == 0)
return;
var c = chars[0];
if (c != '\0' && !char.IsControl(c))
input = c.ToString();
try
{
var args = new ChatActivatedArgs(new ChannelSwitchInfo(null)) {
Input = input,
};
Activated?.Invoke(args);
}
catch (Exception ex)
{
Plugin.Log.Error(ex, "Error in chat Activated event");
}
});
}
}
@@ -510,7 +498,6 @@ internal sealed unsafe class Chat : IDisposable {
{
var args = new ChatActivatedArgs(new ChannelSwitchInfo(null)) {
AddIfNotPresent = addIfNotPresent,
Input = input,
};
Activated?.Invoke(args);
}
File diff suppressed because it is too large Load Diff