do not handle blocked/muted characters
simplify get ids potentially fix invalid chara state partial 514d254 skip erroneous blockstatus
This commit is contained in:
42
MareSynchronos/Interop/BlockedCharacterHandler.cs
Normal file
42
MareSynchronos/Interop/BlockedCharacterHandler.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Dalamud.Plugin.Services;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI.Info;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MareSynchronos.Interop;
|
||||
|
||||
public unsafe class BlockedCharacterHandler
|
||||
{
|
||||
private sealed record CharaData(ulong AccId, ulong ContentId);
|
||||
private readonly Dictionary<CharaData, bool> _blockedCharacterCache = new();
|
||||
|
||||
private readonly ILogger<BlockedCharacterHandler> _logger;
|
||||
|
||||
public BlockedCharacterHandler(ILogger<BlockedCharacterHandler> logger, IGameInteropProvider gameInteropProvider)
|
||||
{
|
||||
gameInteropProvider.InitializeFromAttributes(this);
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private static CharaData GetIdsFromPlayerPointer(nint ptr)
|
||||
{
|
||||
if (ptr == nint.Zero) return new(0, 0);
|
||||
var castChar = ((BattleChara*)ptr);
|
||||
return new(castChar->Character.AccountId, castChar->Character.ContentId);
|
||||
}
|
||||
|
||||
public bool IsCharacterBlocked(nint ptr, out bool firstTime)
|
||||
{
|
||||
firstTime = false;
|
||||
var combined = GetIdsFromPlayerPointer(ptr);
|
||||
if (_blockedCharacterCache.TryGetValue(combined, out var isBlocked))
|
||||
return isBlocked;
|
||||
|
||||
firstTime = true;
|
||||
var blockStatus = InfoProxyBlacklist.Instance()->GetBlockResultType(combined.AccId, combined.ContentId);
|
||||
_logger.LogTrace("CharaPtr {ptr} is BlockStatus: {status}", ptr, blockStatus);
|
||||
if ((int)blockStatus == 0)
|
||||
return false;
|
||||
return _blockedCharacterCache[combined] = blockStatus != InfoProxyBlacklist.BlockResultType.NotBlocked;
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
collection.AddSingleton<FileCompactor>();
|
||||
collection.AddSingleton<TagHandler>();
|
||||
collection.AddSingleton<UidDisplayHandler>();
|
||||
collection.AddSingleton<BlockedCharacterHandler>();
|
||||
collection.AddSingleton<IpcProvider>();
|
||||
collection.AddSingleton<PluginWatcherService>();
|
||||
collection.AddSingleton<PlayerPerformanceService>();
|
||||
|
||||
@@ -5,6 +5,7 @@ using Dalamud.Utility;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.Control;
|
||||
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
|
||||
using MareSynchronos.Interop;
|
||||
using MareSynchronos.PlayerData.Handlers;
|
||||
using MareSynchronos.Services.Mediator;
|
||||
using MareSynchronos.Utils;
|
||||
@@ -37,6 +38,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
private readonly IClientState _clientState;
|
||||
private readonly ICondition _condition;
|
||||
private readonly IDataManager _gameData;
|
||||
private readonly BlockedCharacterHandler _blockedCharacterHandler;
|
||||
private readonly IFramework _framework;
|
||||
private readonly IGameGui _gameGui;
|
||||
private readonly IToastGui _toastGui;
|
||||
@@ -53,9 +55,10 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
private bool _sentBetweenAreas = false;
|
||||
private static readonly Dictionary<uint, PlayerInfo> _playerInfoCache = new();
|
||||
|
||||
|
||||
public DalamudUtilService(ILogger<DalamudUtilService> logger, IClientState clientState, IObjectTable objectTable, IFramework framework,
|
||||
IGameGui gameGui, IToastGui toastGui,ICondition condition, IDataManager gameData, ITargetManager targetManager,
|
||||
MareMediator mediator, PerformanceCollectorService performanceCollector)
|
||||
BlockedCharacterHandler blockedCharacterHandler, MareMediator mediator, PerformanceCollectorService performanceCollector)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientState = clientState;
|
||||
@@ -65,6 +68,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
_toastGui = toastGui;
|
||||
_condition = condition;
|
||||
_gameData = gameData;
|
||||
_blockedCharacterHandler = blockedCharacterHandler;
|
||||
Mediator = mediator;
|
||||
_performanceCollector = performanceCollector;
|
||||
WorldData = new(() =>
|
||||
@@ -501,6 +505,12 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
if (chara == null || chara.ObjectKind != Dalamud.Game.ClientState.Objects.Enums.ObjectKind.Player)
|
||||
continue;
|
||||
|
||||
if (_blockedCharacterHandler.IsCharacterBlocked(chara.Address, out bool firstTime) && firstTime)
|
||||
{
|
||||
_logger.LogTrace("Skipping character {addr}, blocked/muted", chara.Address.ToString("X"));
|
||||
continue;
|
||||
}
|
||||
|
||||
var info = GetPlayerInfo(chara);
|
||||
|
||||
if (!IsAnythingDrawing)
|
||||
|
||||
Reference in New Issue
Block a user