ExpandedSearchInfo/ExpandedSearchInfo/GameFunctions.cs

47 lines
1.6 KiB
C#
Raw Permalink Normal View History

2021-02-18 20:20:40 +00:00
using System;
2021-04-11 12:27:32 +00:00
using Dalamud.Game.Text.SeStringHandling;
2021-02-18 20:20:40 +00:00
using Dalamud.Hooking;
2023-09-29 01:09:50 +00:00
namespace ExpandedSearchInfo;
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
public class GameFunctions : IDisposable {
private Plugin Plugin { get; }
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
private delegate byte SearchInfoDownloadedDelegate(IntPtr data, IntPtr a2, IntPtr searchInfoPtr, IntPtr a4);
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
private readonly Hook<SearchInfoDownloadedDelegate>? _searchInfoDownloadedHook;
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
internal delegate void ReceiveSearchInfoEventDelegate(uint objectId, SeString info);
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
internal event ReceiveSearchInfoEventDelegate? ReceiveSearchInfo;
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
internal GameFunctions(Plugin plugin) {
this.Plugin = plugin;
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
var sidPtr = this.Plugin.SigScanner.ScanText("48 89 5C 24 ?? 48 89 6C 24 ?? 56 48 83 EC 20 49 8B E8 8B DA");
this._searchInfoDownloadedHook = this.Plugin.GameInteropProvider.HookFromAddress<SearchInfoDownloadedDelegate>(sidPtr, this.SearchInfoDownloaded);
this._searchInfoDownloadedHook.Enable();
}
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
public void Dispose() {
this._searchInfoDownloadedHook?.Dispose();
}
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
private unsafe byte SearchInfoDownloaded(IntPtr data, IntPtr a2, IntPtr searchInfoPtr, IntPtr a4) {
var result = this._searchInfoDownloadedHook!.Original(data, a2, searchInfoPtr, a4);
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
try {
// Updated: 4.5
var actorId = *(uint*) (data + 48);
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
var searchInfo = Util.ReadRawSeString(searchInfoPtr);
2021-02-18 20:20:40 +00:00
2023-09-29 01:09:50 +00:00
this.ReceiveSearchInfo?.Invoke(actorId, searchInfo);
} catch (Exception ex) {
Plugin.Log.Error(ex, "Error in SearchInfoDownloaded hook");
2021-02-18 20:20:40 +00:00
}
2023-09-29 01:09:50 +00:00
return result;
2021-02-18 20:20:40 +00:00
}
2021-04-11 12:27:32 +00:00
}