do not handle blocked/muted characters

simplify get ids

potentially fix invalid chara state

partial 514d254

skip erroneous blockstatus
This commit is contained in:
Stanley Dimant
2024-10-29 21:38:19 +01:00
committed by Loporrit
parent 289f776223
commit 9fd3647f02
3 changed files with 54 additions and 1 deletions

View 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;
}
}

View File

@@ -111,6 +111,7 @@ public sealed class Plugin : IDalamudPlugin
collection.AddSingleton<FileCompactor>(); collection.AddSingleton<FileCompactor>();
collection.AddSingleton<TagHandler>(); collection.AddSingleton<TagHandler>();
collection.AddSingleton<UidDisplayHandler>(); collection.AddSingleton<UidDisplayHandler>();
collection.AddSingleton<BlockedCharacterHandler>();
collection.AddSingleton<IpcProvider>(); collection.AddSingleton<IpcProvider>();
collection.AddSingleton<PluginWatcherService>(); collection.AddSingleton<PluginWatcherService>();
collection.AddSingleton<PlayerPerformanceService>(); collection.AddSingleton<PlayerPerformanceService>();

View File

@@ -5,6 +5,7 @@ using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Client.Game.Character; using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Game.Control; using FFXIVClientStructs.FFXIV.Client.Game.Control;
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene; using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using MareSynchronos.Interop;
using MareSynchronos.PlayerData.Handlers; using MareSynchronos.PlayerData.Handlers;
using MareSynchronos.Services.Mediator; using MareSynchronos.Services.Mediator;
using MareSynchronos.Utils; using MareSynchronos.Utils;
@@ -37,6 +38,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
private readonly IClientState _clientState; private readonly IClientState _clientState;
private readonly ICondition _condition; private readonly ICondition _condition;
private readonly IDataManager _gameData; private readonly IDataManager _gameData;
private readonly BlockedCharacterHandler _blockedCharacterHandler;
private readonly IFramework _framework; private readonly IFramework _framework;
private readonly IGameGui _gameGui; private readonly IGameGui _gameGui;
private readonly IToastGui _toastGui; private readonly IToastGui _toastGui;
@@ -53,9 +55,10 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
private bool _sentBetweenAreas = false; private bool _sentBetweenAreas = false;
private static readonly Dictionary<uint, PlayerInfo> _playerInfoCache = new(); private static readonly Dictionary<uint, PlayerInfo> _playerInfoCache = new();
public DalamudUtilService(ILogger<DalamudUtilService> logger, IClientState clientState, IObjectTable objectTable, IFramework framework, public DalamudUtilService(ILogger<DalamudUtilService> logger, IClientState clientState, IObjectTable objectTable, IFramework framework,
IGameGui gameGui, IToastGui toastGui,ICondition condition, IDataManager gameData, ITargetManager targetManager, IGameGui gameGui, IToastGui toastGui,ICondition condition, IDataManager gameData, ITargetManager targetManager,
MareMediator mediator, PerformanceCollectorService performanceCollector) BlockedCharacterHandler blockedCharacterHandler, MareMediator mediator, PerformanceCollectorService performanceCollector)
{ {
_logger = logger; _logger = logger;
_clientState = clientState; _clientState = clientState;
@@ -65,6 +68,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
_toastGui = toastGui; _toastGui = toastGui;
_condition = condition; _condition = condition;
_gameData = gameData; _gameData = gameData;
_blockedCharacterHandler = blockedCharacterHandler;
Mediator = mediator; Mediator = mediator;
_performanceCollector = performanceCollector; _performanceCollector = performanceCollector;
WorldData = new(() => WorldData = new(() =>
@@ -501,6 +505,12 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
if (chara == null || chara.ObjectKind != Dalamud.Game.ClientState.Objects.Enums.ObjectKind.Player) if (chara == null || chara.ObjectKind != Dalamud.Game.ClientState.Objects.Enums.ObjectKind.Player)
continue; 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); var info = GetPlayerInfo(chara);
if (!IsAnythingDrawing) if (!IsAnythingDrawing)