fix some exceptions when playerchara is null
This commit is contained in:
@@ -48,6 +48,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
|||||||
private bool _sentBetweenAreas = false;
|
private bool _sentBetweenAreas = false;
|
||||||
private readonly Dictionary<ulong, string> _aidCache = [];
|
private readonly Dictionary<ulong, string> _aidCache = [];
|
||||||
private readonly Lazy<uint> _aid;
|
private readonly Lazy<uint> _aid;
|
||||||
|
private int _aidCounter = 0;
|
||||||
|
|
||||||
public DalamudUtilService(ILogger<DalamudUtilService> logger, IClientState clientState, IObjectTable objectTable, IFramework framework,
|
public DalamudUtilService(ILogger<DalamudUtilService> 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, ISigScanner sigScanner,
|
||||||
@@ -302,11 +303,13 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
|||||||
|
|
||||||
private unsafe string GetHashedAccIdFromPlayerPointer(nint ptr)
|
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;
|
var aid = ((BattleChara*)ptr)->Character.AccountId;
|
||||||
if (!_aidCache.TryGetValue(aid, out string? hash))
|
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;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user