diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index 4f06f0a..182c2a6 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -133,7 +133,7 @@ public sealed class Plugin : IDalamudPlugin collection.AddSingleton((s) => new EventAggregator(pluginInterface.ConfigDirectory.FullName, s.GetRequiredService>(), s.GetRequiredService())); collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService>(), - clientState, objectTable, framework, gameGui, condition, gameData, targetManager, gameConfig, sigScanner, + clientState, objectTable, framework, gameGui, condition, gameData, targetManager, gameConfig, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); collection.AddSingleton((s) => new DtrEntry(s.GetRequiredService>(), dtrBar, s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService(), s.GetRequiredService())); diff --git a/MareSynchronos/Services/DalamudUtilService.cs b/MareSynchronos/Services/DalamudUtilService.cs index f39946d..bdbb846 100644 --- a/MareSynchronos/Services/DalamudUtilService.cs +++ b/MareSynchronos/Services/DalamudUtilService.cs @@ -37,7 +37,6 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber private readonly IGameGui _gameGui; private readonly ILogger _logger; private readonly IObjectTable _objectTable; - private readonly ISigScanner _sigScanner; private readonly PerformanceCollectorService _performanceCollector; private uint? _classJobId = 0; private DateTime _delayedFrameworkUpdateCheck = DateTime.UtcNow; @@ -47,12 +46,10 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber private readonly Dictionary _playerCharas = new(StringComparer.Ordinal); private readonly List _notUpdatedCharas = []; private bool _sentBetweenAreas = false; - private readonly Dictionary _aidCache = []; - private Lazy _aid; - private int _aidCounter = 0; + private Lazy _cid; public DalamudUtilService(ILogger logger, IClientState clientState, IObjectTable objectTable, IFramework framework, - IGameGui gameGui, ICondition condition, IDataManager gameData, ITargetManager targetManager, IGameConfig gameConfig, ISigScanner sigScanner, + IGameGui gameGui, ICondition condition, IDataManager gameData, ITargetManager targetManager, IGameConfig gameConfig, BlockedCharacterHandler blockedCharacterHandler, MareMediator mediator, PerformanceCollectorService performanceCollector) { _logger = logger; @@ -65,7 +62,6 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber _gameConfig = gameConfig; _blockedCharacterHandler = blockedCharacterHandler; Mediator = mediator; - _sigScanner = sigScanner; _performanceCollector = performanceCollector; WorldData = new(() => { @@ -128,19 +124,10 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber }).ConfigureAwait(false); }); IsWine = Util.IsWine(); - _aid = RebuildAid(); + _cid = RebuildCID(); } - private Lazy RebuildAid() { - return new(() => - { - unsafe - { - var address = _sigScanner.GetStaticAddressFromSig("48 8B 0D ?? ?? ?? ?? 4C 8B CA"); - return (uint)(address != nint.Zero ? (*(ulong**)address)[1] : 0u); - } - }); - } + private Lazy RebuildCID() => new(GetCID); public bool IsWine { get; init; } @@ -312,20 +299,12 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber public async Task GetPlayerNameHashedAsync() { - return await RunOnFrameworkThread(() => _aid.Value.ToString().GetHash256()).ConfigureAwait(false); + return await RunOnFrameworkThread(() => _cid.Value.ToString().GetHash256()).ConfigureAwait(false); } - private unsafe string GetHashedAccIdFromPlayerPointer(nint ptr) + private unsafe static string GetHashedCIDFromPlayerPointer(nint ptr) { - if (ptr == nint.Zero) return "UNK" + _aidCounter++; - var aid = ((BattleChara*)ptr)->Character.AccountId; - if (!_aidCache.TryGetValue(aid, out string? hash)) - { - var player = GetPlayerCharacter(); - if (player == null) return "UNK" + _aidCounter++; - _aidCache[aid] = hash = unchecked((uint)(((((BattleChara*)player.Address)->Character.AccountId ^ aid) >> 31) ^ _aid.Value)).ToString().GetHash256(); - } - return hash; + return ((BattleChara*)ptr)->Character.ContentId.ToString().GetHash256(); } public IntPtr GetPlayerPtr() @@ -646,7 +625,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber } var charaName = ((GameObject*)chara.Address)->NameString; - var hash = GetHashedAccIdFromPlayerPointer(chara.Address); + var hash = GetHashedCIDFromPlayerPointer(chara.Address); if (!IsAnythingDrawing) CheckCharacterForDrawing(chara.Address, charaName); _notUpdatedCharas.Remove(hash); @@ -762,7 +741,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber _logger.LogDebug("Logged in"); IsLoggedIn = true; _lastZone = _clientState.TerritoryType; - _aid = RebuildAid(); + _cid = RebuildCID(); Mediator.Publish(new DalamudLoginMessage()); } else if (localPlayer == null && IsLoggedIn)