From f16dbe6dd65ca60a3c13bb0fb3bca09d7ce3ac92 Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Sun, 30 Mar 2025 17:48:49 +0200 Subject: [PATCH] fix some exceptions when playerchara is null --- MareSynchronos/Services/DalamudUtilService.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MareSynchronos/Services/DalamudUtilService.cs b/MareSynchronos/Services/DalamudUtilService.cs index 599acc2..4d05f4f 100644 --- a/MareSynchronos/Services/DalamudUtilService.cs +++ b/MareSynchronos/Services/DalamudUtilService.cs @@ -48,6 +48,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber private bool _sentBetweenAreas = false; private readonly Dictionary _aidCache = []; private readonly Lazy _aid; + private int _aidCounter = 0; public DalamudUtilService(ILogger logger, IClientState clientState, IObjectTable objectTable, IFramework framework, IGameGui gameGui, ICondition condition, IDataManager gameData, ITargetManager targetManager, IGameConfig gameConfig, ISigScanner sigScanner, @@ -302,11 +303,13 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber private unsafe string GetHashedAccIdFromPlayerPointer(nint ptr) { - if (ptr == nint.Zero) return string.Empty; + if (ptr == nint.Zero) return "UNK" + _aidCounter++; var aid = ((BattleChara*)ptr)->Character.AccountId; if (!_aidCache.TryGetValue(aid, out string? hash)) { - _aidCache[aid] = hash = unchecked((uint)(((((BattleChara*)GetPlayerCharacter().Address)->Character.AccountId ^ aid) >> 31) ^ _aid.Value)).ToString().GetHash256(); + 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; }