ExpandedSearchInfo/ExpandedSearchInfo/GameFunctions.cs

48 lines
1.7 KiB
C#
Raw 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;
2021-08-24 05:43:09 +00:00
using Dalamud.Logging;
2021-02-18 20:20:40 +00:00
namespace ExpandedSearchInfo {
public class GameFunctions : IDisposable {
private Plugin Plugin { get; }
private delegate byte SearchInfoDownloadedDelegate(IntPtr data, IntPtr a2, IntPtr searchInfoPtr, IntPtr a4);
private readonly Hook<SearchInfoDownloadedDelegate>? _searchInfoDownloadedHook;
2021-08-24 05:43:09 +00:00
internal delegate void ReceiveSearchInfoEventDelegate(uint objectId, SeString info);
2021-02-18 20:20:40 +00:00
internal event ReceiveSearchInfoEventDelegate? ReceiveSearchInfo;
internal GameFunctions(Plugin plugin) {
this.Plugin = plugin;
2021-08-24 05:43:09 +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 = new Hook<SearchInfoDownloadedDelegate>(sidPtr, this.SearchInfoDownloaded);
2021-02-18 20:20:40 +00:00
this._searchInfoDownloadedHook.Enable();
}
public void Dispose() {
this._searchInfoDownloadedHook?.Dispose();
}
2021-08-24 05:43:09 +00:00
private unsafe byte SearchInfoDownloaded(IntPtr data, IntPtr a2, IntPtr searchInfoPtr, IntPtr a4) {
2021-02-18 20:20:40 +00:00
var result = this._searchInfoDownloadedHook!.Original(data, a2, searchInfoPtr, a4);
try {
2021-04-14 22:21:59 +00:00
// Updated: 4.5
2021-08-24 05:43:09 +00:00
var actorId = *(uint*) (data + 48);
2021-02-18 20:20:40 +00:00
2021-08-29 17:08:40 +00:00
var searchInfo = Util.ReadRawSeString(searchInfoPtr);
2021-02-18 20:20:40 +00:00
this.ReceiveSearchInfo?.Invoke(actorId, searchInfo);
} catch (Exception ex) {
PluginLog.LogError($"Error in SearchInfoDownloaded hook\n{ex}");
}
return result;
}
}
2021-04-11 12:27:32 +00:00
}