🐛 Fix invalid mem addresses after zone change

This commit is contained in:
Liza 2023-02-26 00:27:49 +01:00
parent acec50fd3d
commit d6e46c24bb
Signed by: liza
GPG Key ID: 7199F8D727D55F67

View File

@ -15,7 +15,6 @@ namespace RetainerTrack.Handlers
private readonly GameGui _gameGui; private readonly GameGui _gameGui;
private readonly PersistenceContext _persistenceContext; private readonly PersistenceContext _persistenceContext;
private AddonItemSearchResult* _itemSearchResultAddon;
private Hook<Draw>? _drawHook; private Hook<Draw>? _drawHook;
private delegate void Draw(AtkUnitBase* addon); private delegate void Draw(AtkUnitBase* addon);
@ -30,19 +29,20 @@ namespace RetainerTrack.Handlers
_framework = framework; _framework = framework;
_gameGui = gameGui; _gameGui = gameGui;
_persistenceContext = persistenceContext; _persistenceContext = persistenceContext;
;
_framework.Update += FrameworkUpdate; _framework.Update += FrameworkUpdate;
} }
private AddonItemSearchResult* ItemSearchResult => (AddonItemSearchResult*)_gameGui.GetAddonByName("ItemSearchResult");
private void FrameworkUpdate(Framework framework) private void FrameworkUpdate(Framework framework)
{ {
_itemSearchResultAddon = (AddonItemSearchResult*)_gameGui.GetAddonByName("ItemSearchResult"); var addon = ItemSearchResult;
if (_itemSearchResultAddon == null) if (addon == null)
return; return;
_drawHook ??= Hook<Draw>.FromAddress( _drawHook ??= Hook<Draw>.FromAddress(
new nint(_itemSearchResultAddon->AtkUnitBase.AtkEventListener.vfunc[42]), new nint(addon->AtkUnitBase.AtkEventListener.vfunc[42]),
AddonDraw); AddonDraw);
_drawHook.Enable(); _drawHook.Enable();
_framework.Update -= FrameworkUpdate; _framework.Update -= FrameworkUpdate;
@ -58,10 +58,11 @@ namespace RetainerTrack.Handlers
{ {
try try
{ {
if (_itemSearchResultAddon == null || !_itemSearchResultAddon->AtkUnitBase.IsVisible) var addon = ItemSearchResult;
if (addon == null || !addon->AtkUnitBase.IsVisible)
return; return;
var results = _itemSearchResultAddon->Results; var results = addon->Results;
if (results == null) if (results == null)
return; return;