Switch to CS for one function hook

This commit is contained in:
Infi
2024-05-02 04:47:06 +02:00
parent 7bd5f0302b
commit 0a6c611e73
2 changed files with 20 additions and 26 deletions
+20 -25
View File
@@ -32,9 +32,6 @@ internal sealed unsafe class Chat : IDisposable
[Signature("48 89 5C 24 ?? 55 56 57 48 81 EC ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 ?? ?? ?? ?? 48 8B 02", Fallibility = Fallibility.Fallible)] [Signature("48 89 5C 24 ?? 55 56 57 48 81 EC ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 ?? ?? ?? ?? 48 8B 02", Fallibility = Fallibility.Fallible)]
private readonly delegate* unmanaged<RaptureShellModule*, Utf8String*, Utf8String*, ushort, ulong, ushort, byte, bool> SetChannelTargetTell = null!; private readonly delegate* unmanaged<RaptureShellModule*, Utf8String*, Utf8String*, ushort, ulong, ushort, byte, bool> SetChannelTargetTell = null!;
[Signature("4C 8B 81 ?? ?? ?? ?? 4D 85 C0 74 17", Fallibility = Fallibility.Fallible)]
private readonly delegate* unmanaged<RaptureLogModule*, uint, ulong> GetContentIdForChatEntry = null!;
[Signature("E8 ?? ?? ?? ?? 48 8D 4D A0 8B F8")] [Signature("E8 ?? ?? ?? ?? 48 8D 4D A0 8B F8")]
private readonly delegate* unmanaged<IntPtr, Utf8String*, IntPtr, uint> GetKeybindNative = null!; private readonly delegate* unmanaged<IntPtr, Utf8String*, IntPtr, uint> GetKeybindNative = null!;
@@ -71,10 +68,6 @@ internal sealed unsafe class Chat : IDisposable
[Signature("E8 ?? ?? ?? ?? EB 0A 48 8D 4C 24 ?? E8 ?? ?? ?? ?? 48 8D 8D")] [Signature("E8 ?? ?? ?? ?? EB 0A 48 8D 4C 24 ?? E8 ?? ?? ?? ?? 48 8D 8D")]
private readonly delegate* unmanaged<Utf8String*, int, IntPtr, void> SanitiseString = null!; private readonly delegate* unmanaged<Utf8String*, int, IntPtr, void> SanitiseString = null!;
// Currently Unused
[Signature("E8 ?? ?? ?? ?? 48 3B F0 74 35")]
private readonly delegate* unmanaged<AtkStage*, IntPtr> GetFocus = null!;
// Hooks // Hooks
private delegate byte ChatLogRefreshDelegate(IntPtr log, ushort eventId, AtkValue* value); private delegate byte ChatLogRefreshDelegate(IntPtr log, ushort eventId, AtkValue* value);
@@ -181,7 +174,8 @@ internal sealed unsafe class Chat : IDisposable
Login(); Login();
} }
public void Dispose() { public void Dispose()
{
Plugin.ClientState.Login -= Login; Plugin.ClientState.Login -= Login;
Plugin.Framework.Update -= InterceptKeybinds; Plugin.Framework.Update -= InterceptKeybinds;
@@ -194,26 +188,25 @@ internal sealed unsafe class Chat : IDisposable
Activated = null; Activated = null;
} }
internal string? GetLinkshellName(uint idx) { internal string? GetLinkshellName(uint idx)
if (LinkshellInfoProxyIdx is not { } proxyIdx) { {
if (LinkshellInfoProxyIdx is not { } proxyIdx)
return null; return null;
}
var infoProxy = Plugin.Functions.GetInfoProxyByIndex(proxyIdx); var infoProxy = Plugin.Functions.GetInfoProxyByIndex(proxyIdx);
if (infoProxy == IntPtr.Zero) { if (infoProxy == IntPtr.Zero)
return null; return null;
}
var lsInfo = GetLinkshellInfo(infoProxy, idx); var lsInfo = GetLinkshellInfo(infoProxy, idx);
if (lsInfo == null) { if (lsInfo == null)
return null; return null;
}
var utf = GetLinkshellNameNative(infoProxy, *lsInfo); var utf = GetLinkshellNameNative(infoProxy, *lsInfo);
return utf == null ? null : MemoryHelper.ReadStringNullTerminated((IntPtr) utf); return utf == null ? null : MemoryHelper.ReadStringNullTerminated((IntPtr) utf);
} }
internal string? GetCrossLinkshellName(uint idx) { internal string? GetCrossLinkshellName(uint idx)
{
if (CrossLinkshellInfoProxyIdx is not { } proxyIdx) if (CrossLinkshellInfoProxyIdx is not { } proxyIdx)
return null; return null;
@@ -239,7 +232,8 @@ internal sealed unsafe class Chat : IDisposable
internal ulong RotateCrossLinkshellHistory(RotateMode mode) => RotateLinkshellHistoryInternal(RotateCrossLinkshellHistoryNative, mode); internal ulong RotateCrossLinkshellHistory(RotateMode mode) => RotateLinkshellHistoryInternal(RotateCrossLinkshellHistoryNative, mode);
private static ulong RotateLinkshellHistoryInternal(delegate* unmanaged<UIModule*, int, ulong> func, RotateMode mode) { private static ulong RotateLinkshellHistoryInternal(delegate* unmanaged<UIModule*, int, ulong> func, RotateMode mode)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse // ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (func == null) if (func == null)
return 0; return 0;
@@ -258,7 +252,8 @@ internal sealed unsafe class Chat : IDisposable
// This function looks up a channel's user-defined colour. // This function looks up a channel's user-defined colour.
// //
// If this function would ever return 0, it returns null instead. // If this function would ever return 0, it returns null instead.
internal uint? GetChannelColour(ChatType type) { internal uint? GetChannelColour(ChatType type)
{
if (GetColourInfo == null || ColourLookup == IntPtr.Zero) if (GetColourInfo == null || ColourLookup == IntPtr.Zero)
return null; return null;
@@ -269,7 +264,8 @@ internal sealed unsafe class Chat : IDisposable
var parent = new ChatCode((ushort) type).Parent(); var parent = new ChatCode((ushort) type).Parent();
switch (parent) { switch (parent)
{
case ChatType.Debug: case ChatType.Debug:
case ChatType.Urgent: case ChatType.Urgent:
case ChatType.Notice: case ChatType.Notice:
@@ -291,7 +287,8 @@ internal sealed unsafe class Chat : IDisposable
private readonly Dictionary<string, Keybind> _keybinds = new(); private readonly Dictionary<string, Keybind> _keybinds = new();
internal IReadOnlyDictionary<string, Keybind> Keybinds => _keybinds; internal IReadOnlyDictionary<string, Keybind> Keybinds => _keybinds;
internal static readonly IReadOnlyDictionary<string, ChannelSwitchInfo> KeybindsToIntercept = new Dictionary<string, ChannelSwitchInfo> { internal static readonly IReadOnlyDictionary<string, ChannelSwitchInfo> KeybindsToIntercept = new Dictionary<string, ChannelSwitchInfo>
{
["CMD_CHAT"] = new(null), ["CMD_CHAT"] = new(null),
["CMD_COMMAND"] = new(null, text: "/"), ["CMD_COMMAND"] = new(null, text: "/"),
["CMD_REPLY"] = new(InputChannel.Tell, rotate: RotateMode.Forward), ["CMD_REPLY"] = new(InputChannel.Tell, rotate: RotateMode.Forward),
@@ -450,7 +447,8 @@ internal sealed unsafe class Chat : IDisposable
} }
} }
private void Login() { private void Login()
{
if (ChangeChannelNameHook == null) if (ChangeChannelNameHook == null)
return; return;
@@ -630,10 +628,7 @@ internal sealed unsafe class Chat : IDisposable
internal ulong? GetContentIdForEntry(uint index) internal ulong? GetContentIdForEntry(uint index)
{ {
if (GetContentIdForChatEntry == null) return Framework.Instance()->GetUiModule()->GetRaptureLogModule()->GetContentIdForLogMessage((int) index);
return null;
return GetContentIdForChatEntry(Framework.Instance()->GetUiModule()->GetRaptureLogModule(), index);
} }
internal void SetChannel(InputChannel channel, string? tellTarget = null) internal void SetChannel(InputChannel channel, string? tellTarget = null)
-1
View File
@@ -86,7 +86,6 @@ internal class MessageManager : IDisposable
Store.UpsertMessage(message); Store.UpsertMessage(message);
var currentMatches = currentTab?.Matches(message) ?? false; var currentMatches = currentTab?.Matches(message) ?? false;
foreach (var tab in Plugin.Config.Tabs) foreach (var tab in Plugin.Config.Tabs)
{ {
var unread = !(tab.UnreadMode == UnreadMode.Unseen && currentTab != tab && currentMatches); var unread = !(tab.UnreadMode == UnreadMode.Unseen && currentTab != tab && currentMatches);