From 5b31d47d484b84162a82a507054704e4989a0160 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 13 Jan 2022 03:08:04 -0500 Subject: [PATCH] feat: add mentor check --- ChatTwo/ChatTwo.csproj | 2 +- ChatTwo/GameFunctions.cs | 63 ++++++++++++++++++++++++--------------- ChatTwo/PayloadHandler.cs | 2 +- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/ChatTwo/ChatTwo.csproj b/ChatTwo/ChatTwo.csproj index 513fb89..006ae98 100755 --- a/ChatTwo/ChatTwo.csproj +++ b/ChatTwo/ChatTwo.csproj @@ -48,7 +48,7 @@ - + diff --git a/ChatTwo/GameFunctions.cs b/ChatTwo/GameFunctions.cs index 0314940..3ec2827 100755 --- a/ChatTwo/GameFunctions.cs +++ b/ChatTwo/GameFunctions.cs @@ -20,47 +20,51 @@ internal unsafe class GameFunctions : IDisposable { private static class Signatures { internal const string ChatLogRefresh = "40 53 56 57 48 81 EC ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 ?? ?? ?? ?? 49 8B F0 8B FA"; internal const string ChangeChannelName = "E8 ?? ?? ?? ?? BA ?? ?? ?? ?? 48 8D 4D B0 48 8B F8 E8 ?? ?? ?? ?? 41 8B D6"; + internal const string IsMentorA1 = "48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 84 C0 74 71 0F B6 86"; internal const string CurrentChatEntryOffset = "8B 77 ?? 8D 46 01 89 47 14 81 FE ?? ?? ?? ?? 72 03 FF 47"; } #region Functions - [Signature("E8 ?? ?? ?? ?? 0F B7 44 37 ??")] - private readonly delegate* unmanaged _changeChatChannel; + [Signature("E8 ?? ?? ?? ?? 0F B7 44 37 ??", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _changeChatChannel = null!; - [Signature("4C 8B 81 ?? ?? ?? ?? 4D 85 C0 74 17")] - private readonly delegate* unmanaged _getContentIdForChatEntry; + [Signature("4C 8B 81 ?? ?? ?? ?? 4D 85 C0 74 17", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _getContentIdForChatEntry = null!; - [Signature("E8 ?? ?? ?? ?? 8B FD 8B CD")] - private readonly delegate* unmanaged _indexer; + [Signature("E8 ?? ?? ?? ?? 8B FD 8B CD", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _indexer = null!; - [Signature("E8 ?? ?? ?? ?? 33 C0 EB 51")] - private readonly delegate* unmanaged _inviteToParty; + [Signature("E8 ?? ?? ?? ?? 33 C0 EB 51", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _inviteToParty = null!; - [Signature(("E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 48 8B CB E8 ?? ?? ?? ?? 45 33 C9"))] - private readonly delegate* unmanaged _inviteToNoviceNetwork; + [Signature(("E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 48 8B CB E8 ?? ?? ?? ?? 45 33 C9"), Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _inviteToNoviceNetwork = null!; - [Signature("40 53 48 83 EC 20 48 8B D9 48 8B 49 10 48 8B 01 FF 90 ?? ?? ?? ?? 48 8B 48 48")] - private readonly delegate* unmanaged _friendRequestBool; + [Signature("40 53 48 83 EC 20 48 8B D9 48 8B 49 10 48 8B 01 FF 90 ?? ?? ?? ?? 48 8B 48 48", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _friendRequestBool = null!; - [Signature("E8 ?? ?? ?? ?? EB 35 BA")] - private readonly delegate* unmanaged _tryOn; + [Signature("E8 ?? ?? ?? ?? EB 35 BA", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _tryOn = null!; - [Signature("E8 ?? ?? ?? ?? EB 7B 49 8B 06")] - private readonly delegate* unmanaged _linkItem; + [Signature("E8 ?? ?? ?? ?? EB 7B 49 8B 06", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _linkItem = null!; - [Signature("E8 ?? ?? ?? ?? EB 3F 83 F8 FE")] - private readonly delegate* unmanaged _itemComparison; + [Signature("E8 ?? ?? ?? ?? EB 3F 83 F8 FE", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _itemComparison = null!; - [Signature("E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 41 B4 01")] - private readonly delegate* unmanaged _searchForRecipesUsingItem; + [Signature("E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 41 B4 01", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _searchForRecipesUsingItem = null!; - [Signature("E8 ?? ?? ?? ?? EB 45 45 33 C9")] - private readonly delegate* unmanaged _searchForItem; + [Signature("E8 ?? ?? ?? ?? EB 45 45 33 C9", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _searchForItem = null!; - [Signature("E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 48 8B CB E8 ?? ?? ?? ?? 84 C0 74 3A")] - private readonly delegate* unmanaged _agentContextYesNo; + [Signature("E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 48 8B CB E8 ?? ?? ?? ?? 84 C0 74 3A", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _agentContextYesNo = null!; + + [Signature("E8 ?? ?? ?? ?? 84 C0 74 0D B0 02", Fallibility = Fallibility.Fallible)] + private readonly delegate* unmanaged _isMentor = null!; #endregion @@ -81,6 +85,9 @@ internal unsafe class GameFunctions : IDisposable { [Signature(Signatures.CurrentChatEntryOffset, Offset = 2)] private readonly byte? _currentChatEntryOffset; + [Signature(Signatures.IsMentorA1, ScanType = ScanType.StaticAddress)] + private readonly IntPtr? _isMentorA1; + internal const int HqItemOffset = 1_000_000; private Plugin Plugin { get; } @@ -439,4 +446,12 @@ internal unsafe class GameFunctions : IDisposable { } } } + + internal bool IsMentor() { + if (this._isMentor == null || this._isMentorA1 == null || this._isMentorA1.Value == IntPtr.Zero) { + return false; + } + + return this._isMentor(this._isMentorA1.Value) > 0; + } } diff --git a/ChatTwo/PayloadHandler.cs b/ChatTwo/PayloadHandler.cs index 083e19e..2c19613 100755 --- a/ChatTwo/PayloadHandler.cs +++ b/ChatTwo/PayloadHandler.cs @@ -294,7 +294,7 @@ internal sealed class PayloadHandler { this.Ui.Plugin.Functions.SendFriendRequest(player.PlayerName, (ushort) player.World.RowId); } - if (ImGui.Selectable("Invite to Novice Network")) { + if (this.Ui.Plugin.Functions.IsMentor() && ImGui.Selectable("Invite to Novice Network")) { // FIXME: only show if character is mentor and target is sprout/returner this.Ui.Plugin.Functions.InviteToNoviceNetwork(player.PlayerName, (ushort) player.World.RowId); }