refactor: ScanTextSafe -> TryScanText

This commit is contained in:
Anna 2021-04-24 13:13:09 -04:00
parent 60983f04be
commit 230aa3f1b3
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
7 changed files with 10 additions and 10 deletions

View File

@ -43,7 +43,7 @@ namespace XivCommon.Functions {
this.SeStringManager = seStringManager; this.SeStringManager = seStringManager;
this.HookEnabled = hook; this.HookEnabled = hook;
if (scanner.ScanTextSafe(Signatures.AddBattleTalk, out var addBattleTalkPtr, "battle talk")) { if (scanner.TryScanText(Signatures.AddBattleTalk, out var addBattleTalkPtr, "battle talk")) {
this.AddBattleTalk = Marshal.GetDelegateForFunctionPointer<AddBattleTalkDelegate>(addBattleTalkPtr); this.AddBattleTalk = Marshal.GetDelegateForFunctionPointer<AddBattleTalkDelegate>(addBattleTalkPtr);
if (this.HookEnabled) { if (this.HookEnabled) {

View File

@ -22,7 +22,7 @@ namespace XivCommon.Functions {
internal Chat(GameFunctions functions, SigScanner scanner) { internal Chat(GameFunctions functions, SigScanner scanner) {
this.Functions = functions; this.Functions = functions;
if (scanner.ScanTextSafe(Signatures.SendChat, out var processChatBoxPtr, "chat sending")) { if (scanner.TryScanText(Signatures.SendChat, out var processChatBoxPtr, "chat sending")) {
this.ProcessChatBox = Marshal.GetDelegateForFunctionPointer<ProcessChatBoxDelegate>(processChatBoxPtr); this.ProcessChatBox = Marshal.GetDelegateForFunctionPointer<ProcessChatBoxDelegate>(processChatBoxPtr);
} }
} }

View File

@ -65,12 +65,12 @@ namespace XivCommon.Functions {
return; return;
} }
if (scanner.ScanTextSafe(Signatures.ChatBubbleOpen, out var openPtr, "chat bubbles open")) { if (scanner.TryScanText(Signatures.ChatBubbleOpen, out var openPtr, "chat bubbles open")) {
this.OpenChatBubbleHook = new Hook<OpenChatBubbleDelegate>(openPtr, new OpenChatBubbleDelegate(this.OpenChatBubbleDetour)); this.OpenChatBubbleHook = new Hook<OpenChatBubbleDelegate>(openPtr, new OpenChatBubbleDelegate(this.OpenChatBubbleDetour));
this.OpenChatBubbleHook.Enable(); this.OpenChatBubbleHook.Enable();
} }
if (scanner.ScanTextSafe(Signatures.ChatBubbleUpdate, out var updatePtr, "chat bubbles update")) { if (scanner.TryScanText(Signatures.ChatBubbleUpdate, out var updatePtr, "chat bubbles update")) {
unsafe { unsafe {
this.UpdateChatBubbleHook = new Hook<UpdateChatBubbleDelegate>(updatePtr + 9, new UpdateChatBubbleDelegate(this.UpdateChatBubbleDetour)); this.UpdateChatBubbleHook = new Hook<UpdateChatBubbleDelegate>(updatePtr + 9, new UpdateChatBubbleDelegate(this.UpdateChatBubbleDetour));
} }

View File

@ -25,7 +25,7 @@ namespace XivCommon.Functions {
this.Functions = functions; this.Functions = functions;
// got this by checking what accesses rciData below // got this by checking what accesses rciData below
if (scanner.ScanTextSafe(Signatures.RequestCharacterInfo, out var rciPtr, "Examine")) { if (scanner.TryScanText(Signatures.RequestCharacterInfo, out var rciPtr, "Examine")) {
this.RequestCharacterInfo = Marshal.GetDelegateForFunctionPointer<RequestCharInfoDelegate>(rciPtr); this.RequestCharacterInfo = Marshal.GetDelegateForFunctionPointer<RequestCharInfoDelegate>(rciPtr);
} }
} }

View File

@ -53,7 +53,7 @@ namespace XivCommon.Functions {
this.ListingsEnabled = hooks.HasFlag(Hooks.PartyFinderListings); this.ListingsEnabled = hooks.HasFlag(Hooks.PartyFinderListings);
this.JoinsEnabled = hooks.HasFlag(Hooks.PartyFinderJoins); this.JoinsEnabled = hooks.HasFlag(Hooks.PartyFinderJoins);
if (scanner.ScanTextSafe(Signatures.RequestListings, out var requestPfPtr, "Party Finder listings")) { if (scanner.TryScanText(Signatures.RequestListings, out var requestPfPtr, "Party Finder listings")) {
this.RequestPartyFinderListings = Marshal.GetDelegateForFunctionPointer<RequestPartyFinderListingsDelegate>(requestPfPtr); this.RequestPartyFinderListings = Marshal.GetDelegateForFunctionPointer<RequestPartyFinderListingsDelegate>(requestPfPtr);
if (this.ListingsEnabled) { if (this.ListingsEnabled) {
@ -63,7 +63,7 @@ namespace XivCommon.Functions {
} }
if (this.JoinsEnabled) { if (this.JoinsEnabled) {
if (scanner.ScanTextSafe(Signatures.JoinCrossParty, out var joinPtr, "Party Finder joins")) { if (scanner.TryScanText(Signatures.JoinCrossParty, out var joinPtr, "Party Finder joins")) {
this.JoinPfHook = new Hook<JoinPfDelegate>(joinPtr, new JoinPfDelegate(this.JoinPfDetour)); this.JoinPfHook = new Hook<JoinPfDelegate>(joinPtr, new JoinPfDelegate(this.JoinPfDetour));
this.JoinPfHook.Enable(); this.JoinPfHook.Enable();

View File

@ -48,7 +48,7 @@ namespace XivCommon.Functions {
internal Talk(SigScanner scanner, SeStringManager manager, bool hooksEnabled) { internal Talk(SigScanner scanner, SeStringManager manager, bool hooksEnabled) {
this.SeStringManager = manager; this.SeStringManager = manager;
if (scanner.ScanTextSafe(Signatures.SetAtkValue, out var setAtkPtr, "Talk - set atk value")) { if (scanner.TryScanText(Signatures.SetAtkValue, out var setAtkPtr, "Talk - set atk value")) {
this.SetAtkValueString = Marshal.GetDelegateForFunctionPointer<SetAtkValueStringDelegate>(setAtkPtr); this.SetAtkValueString = Marshal.GetDelegateForFunctionPointer<SetAtkValueStringDelegate>(setAtkPtr);
} else { } else {
return; return;
@ -58,7 +58,7 @@ namespace XivCommon.Functions {
return; return;
} }
if (scanner.ScanTextSafe(Signatures.ShowMessageBox, out var showMessageBoxPtr, "Talk")) { if (scanner.TryScanText(Signatures.ShowMessageBox, out var showMessageBoxPtr, "Talk")) {
this.AddonTalkV45Hook = new Hook<AddonTalkV45Delegate>(showMessageBoxPtr, new AddonTalkV45Delegate(this.AddonTalkV45Detour)); this.AddonTalkV45Hook = new Hook<AddonTalkV45Delegate>(showMessageBoxPtr, new AddonTalkV45Delegate(this.AddonTalkV45Detour));
this.AddonTalkV45Hook.Enable(); this.AddonTalkV45Hook.Enable();
} }

View File

@ -13,7 +13,7 @@ namespace XivCommon {
/// <param name="result">pointer where signature was found or <see cref="IntPtr.Zero"/> if not found</param> /// <param name="result">pointer where signature was found or <see cref="IntPtr.Zero"/> if not found</param>
/// <param name="name">name of this signature - if specified, a warning will be printed if the signature could not be found</param> /// <param name="name">name of this signature - if specified, a warning will be printed if the signature could not be found</param>
/// <returns>true if signature was found</returns> /// <returns>true if signature was found</returns>
internal static bool ScanTextSafe(this SigScanner scanner, string sig, out IntPtr result, string? name = null) { internal static bool TryScanText(this SigScanner scanner, string sig, out IntPtr result, string? name = null) {
result = IntPtr.Zero; result = IntPtr.Zero;
try { try {
result = scanner.ScanText(sig); result = scanner.ScanText(sig);