Prevent vanilla tooltip for event item and implement #28

This commit is contained in:
Infi
2024-04-30 03:49:53 +02:00
parent 695fd997d7
commit a74cdcb899
11 changed files with 110 additions and 40 deletions
+27 -18
View File
@@ -24,7 +24,7 @@ internal unsafe class GameFunctions : IDisposable
#region Functions
[Signature("E8 ?? ?? ?? ?? 84 C0 74 0D B0 02", Fallibility = Fallibility.Fallible)]
private readonly delegate* unmanaged<IntPtr, byte> IsMentorNative = null!;
private readonly delegate* unmanaged<nint, byte> IsMentorNative = null!;
[Signature("48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 E8 ?? ?? ?? ?? 48 8B 8B ?? ?? ?? ?? 48 85 C9", Fallibility = Fallibility.Fallible)]
private readonly delegate* unmanaged<AgentInterface*, ulong, byte> OpenPartyFinderNative = null!;
@@ -37,7 +37,7 @@ internal unsafe class GameFunctions : IDisposable
#endregion
#region Hooks
private delegate IntPtr ResolveTextCommandPlaceholderDelegate(IntPtr a1, byte* placeholderText, byte a3, byte a4);
private delegate nint ResolveTextCommandPlaceholderDelegate(nint a1, byte* placeholderText, byte a3, byte a4);
[Signature(Signatures.ResolveTextCommandPlaceholder, DetourName = nameof(ResolveTextCommandPlaceholderDetour))]
private Hook<ResolveTextCommandPlaceholderDelegate>? ResolveTextCommandPlaceholderHook { get; init; }
@@ -48,7 +48,7 @@ internal unsafe class GameFunctions : IDisposable
private readonly byte? CurrentChatEntryOffset;
[Signature(Signatures.IsMentorA1, ScanType = ScanType.StaticAddress)]
private readonly IntPtr? IsMentorA1;
private readonly nint? IsMentorA1;
#pragma warning restore 0649
private Plugin Plugin { get; }
@@ -77,7 +77,7 @@ internal unsafe class GameFunctions : IDisposable
Marshal.FreeHGlobal(PlaceholderNamePtr);
}
internal IntPtr GetInfoProxyByIndex(uint idx)
internal nint GetInfoProxyByIndex(uint idx)
{
var infoModule = InfoModule.Instance();
if (infoModule == null)
@@ -91,7 +91,7 @@ internal unsafe class GameFunctions : IDisposable
if (CurrentChatEntryOffset == null)
return null;
var log = (IntPtr) Framework.Instance()->GetUiModule()->GetRaptureLogModule();
var log = (nint) Framework.Instance()->GetUiModule()->GetRaptureLogModule();
return *(uint*) (log + CurrentChatEntryOffset.Value);
}
@@ -120,8 +120,8 @@ internal unsafe class GameFunctions : IDisposable
{
var unitManager = AtkStage.GetSingleton()->RaptureAtkUnitManager;
var addon = (IntPtr) unitManager->GetAddonByName(name);
if (addon == IntPtr.Zero)
var addon = (nint) unitManager->GetAddonByName(name);
if (addon == nint.Zero)
return;
var flags = (uint*) (addon + 0x180);
@@ -143,8 +143,8 @@ internal unsafe class GameFunctions : IDisposable
{
var unitManager = AtkStage.GetSingleton()->RaptureAtkUnitManager;
var addon = (IntPtr) unitManager->GetAddonByName(name);
if (addon == IntPtr.Zero)
var addon = (nint) unitManager->GetAddonByName(name);
if (addon == nint.Zero)
return false;
var flags = (uint*) (addon + 0x180);
@@ -161,8 +161,7 @@ internal unsafe class GameFunctions : IDisposable
if (agent == null || addon == null)
return;
var agentPtr = (IntPtr) agent;
var agentPtr = (nint) agent;
// addresses mentioned here are 6.11
// see the call near the end of AgentItemDetail.Update
// offsets valid as of 6.11
@@ -177,6 +176,8 @@ internal unsafe class GameFunctions : IDisposable
*(uint*) (agentPtr + 0x120) = 0;
// A558A5: skips a check to do with inventory
*(byte*) (agentPtr + 0x128) &= 0xEF;
// Is also set to the ID of the item when in chat
*(uint*) (agentPtr + 0x138) = id;
// A54B3F: when set to 1, lets everything continue (one frame)
*(byte*) (agentPtr + 0x14A) = 1;
// A54B59: skips early return
@@ -186,9 +187,9 @@ internal unsafe class GameFunctions : IDisposable
agent->AddonId = addon->ID;
// vcall from E8 ?? ?? ?? ?? 0F B7 C0 48 83 C4 60 (FF 50 28 48 8B D3 48 8B CF)
var vf5 = (delegate* unmanaged<AtkUnitBase*, byte, uint, void>*) ((IntPtr) addon->VTable + 40);
var vf5 = (delegate* unmanaged<AtkUnitBase*, byte, uint, void>*) ((nint) addon->VTable + 40);
// EA8BED: lets vf5 actually run
*(byte*) ((IntPtr) atkStage + 0x2B4) |= 2;
*(byte*) ((nint) atkStage + 0x2B4) |= 2;
(*vf5)(addon, 0, 15);
}
@@ -201,7 +202,15 @@ internal unsafe class GameFunctions : IDisposable
var agent = Framework.Instance()->GetUiModule()->GetAgentModule()->GetAgentByInternalId(AgentId.ItemDetail);
if (agent != null)
{
Plugin.Log.Information("close and clean was called");
agent->Hide();
// The game sets them to 0 whenever tooltips aren't hovered anymore
var agentPtr = (nint)agent;
*(uint*) (agentPtr + 0x138) = 0;
*(uint*) (agentPtr + 0x13C) = 0;
}
}
internal static void OpenPartyFinder()
@@ -219,7 +228,7 @@ internal unsafe class GameFunctions : IDisposable
else
{
// 6.05: 8443DD
if (*(uint*) ((IntPtr) lfg + 0x2C20) > 0)
if (*(uint*) ((nint) lfg + 0x2C20) > 0)
lfg->Hide();
else
lfg->Show();
@@ -228,7 +237,7 @@ internal unsafe class GameFunctions : IDisposable
internal bool IsMentor()
{
if (IsMentorNative == null || IsMentorA1 == null || IsMentorA1.Value == IntPtr.Zero)
if (IsMentorNative == null || IsMentorA1 == null || IsMentorA1.Value == nint.Zero)
return false;
return IsMentorNative(IsMentorA1.Value) > 0;
@@ -286,16 +295,16 @@ internal unsafe class GameFunctions : IDisposable
vf0(agent, &result, &value, 0, 0);
}
private readonly IntPtr PlaceholderNamePtr = Marshal.AllocHGlobal(128);
private readonly nint PlaceholderNamePtr = Marshal.AllocHGlobal(128);
private readonly string Placeholder = $"<{Guid.NewGuid():N}>";
private string? ReplacementName;
private IntPtr ResolveTextCommandPlaceholderDetour(IntPtr a1, byte* placeholderText, byte a3, byte a4)
private nint ResolveTextCommandPlaceholderDetour(nint a1, byte* placeholderText, byte a3, byte a4)
{
if (ReplacementName == null)
goto Original;
var placeholder = MemoryHelper.ReadStringNullTerminated((IntPtr) placeholderText);
var placeholder = MemoryHelper.ReadStringNullTerminated((nint) placeholderText);
if (placeholder != Placeholder)
goto Original;