do not handle blocked/muted characters
This commit is contained in:
58
MareSynchronos/Interop/BlockedCharacterHandler.cs
Normal file
58
MareSynchronos/Interop/BlockedCharacterHandler.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Dalamud.Plugin.Services;
|
||||
using Dalamud.Utility.Signatures;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI.Info;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MareSynchronos.Interop;
|
||||
|
||||
public unsafe class BlockedCharacterHandler
|
||||
{
|
||||
private readonly Dictionary<(ulong, ulong), bool> _blockedCharacterCache = new();
|
||||
|
||||
private enum BlockResultType
|
||||
{
|
||||
NotBlocked = 1,
|
||||
BlockedByAccountId = 2,
|
||||
BlockedByContentId = 3,
|
||||
}
|
||||
|
||||
[Signature("48 83 EC 48 F6 81 ?? ?? ?? ?? ?? 75 ?? 33 C0 48 83 C4 48")]
|
||||
private readonly GetBlockResultTypeDelegate? _getBlockResultType = null;
|
||||
private readonly ILogger<BlockedCharacterHandler> _logger;
|
||||
|
||||
private unsafe delegate BlockResultType GetBlockResultTypeDelegate(InfoProxyBlacklist* thisPtr, ulong accountId, ulong contentId);
|
||||
|
||||
public BlockedCharacterHandler(ILogger<BlockedCharacterHandler> logger, IGameInteropProvider gameInteropProvider)
|
||||
{
|
||||
gameInteropProvider.InitializeFromAttributes(this);
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private static ulong GetAccIdFromPlayerPointer(nint ptr)
|
||||
{
|
||||
if (ptr == nint.Zero) return 0;
|
||||
return ((BattleChara*)ptr)->Character.AccountId;
|
||||
}
|
||||
|
||||
private static ulong GetContentIdFromPlayerPointer(nint ptr)
|
||||
{
|
||||
if (ptr == nint.Zero) return 0;
|
||||
return ((BattleChara*)ptr)->Character.ContentId;
|
||||
}
|
||||
|
||||
public bool IsCharacterBlocked(nint ptr)
|
||||
{
|
||||
(ulong AccId, ulong ContentId) combined = (GetAccIdFromPlayerPointer(ptr), GetContentIdFromPlayerPointer(ptr));
|
||||
if (_blockedCharacterCache.TryGetValue(combined, out var isBlocked))
|
||||
return isBlocked;
|
||||
|
||||
if (_getBlockResultType == null)
|
||||
return _blockedCharacterCache[combined] = false;
|
||||
|
||||
var infoProxy = InfoProxyBlacklist.Instance();
|
||||
var blockStatus = _getBlockResultType(infoProxy, combined.AccId, combined.ContentId);
|
||||
_logger.LogTrace("CharaPtr {ptr} is BlockStatus: {status}", ptr, blockStatus);
|
||||
return _blockedCharacterCache[combined] = blockStatus != BlockResultType.NotBlocked;
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
public Plugin(IDalamudPluginInterface pluginInterface, ICommandManager commandManager, IDataManager gameData,
|
||||
IFramework framework, IObjectTable objectTable, IClientState clientState, ICondition condition, IChatGui chatGui,
|
||||
IGameGui gameGui, IDtrBar dtrBar, IPluginLog pluginLog, ITargetManager targetManager, INotificationManager notificationManager,
|
||||
ITextureProvider textureProvider, IContextMenu contextMenu)
|
||||
ITextureProvider textureProvider, IContextMenu contextMenu, IGameInteropProvider gameInteropProvider)
|
||||
{
|
||||
if (!Directory.Exists(pluginInterface.ConfigDirectory.FullName))
|
||||
Directory.CreateDirectory(pluginInterface.ConfigDirectory.FullName);
|
||||
@@ -110,6 +110,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
collection.AddSingleton<TagHandler>();
|
||||
collection.AddSingleton<IdDisplayHandler>();
|
||||
collection.AddSingleton<PlayerPerformanceService>();
|
||||
collection.AddSingleton((s) => new BlockedCharacterHandler(s.GetRequiredService<ILogger<BlockedCharacterHandler>>(), gameInteropProvider));
|
||||
collection.AddSingleton((s) => new IpcProvider(s.GetRequiredService<ILogger<IpcProvider>>(),
|
||||
pluginInterface,
|
||||
s.GetRequiredService<MareCharaFileManager>(), s.GetRequiredService<DalamudUtilService>(),
|
||||
@@ -119,7 +120,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
s.GetRequiredService<ILogger<EventAggregator>>(), s.GetRequiredService<MareMediator>()));
|
||||
collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService<ILogger<DalamudUtilService>>(),
|
||||
clientState, objectTable, framework, gameGui, condition, gameData, targetManager,
|
||||
s.GetRequiredService<MareMediator>(), s.GetRequiredService<PerformanceCollectorService>()));
|
||||
s.GetRequiredService<BlockedCharacterHandler>(), s.GetRequiredService<MareMediator>(), s.GetRequiredService<PerformanceCollectorService>()));
|
||||
collection.AddSingleton((s) => new DtrEntry(s.GetRequiredService<ILogger<DtrEntry>>(), dtrBar, s.GetRequiredService<MareConfigService>(),
|
||||
s.GetRequiredService<MareMediator>(), s.GetRequiredService<PairManager>(), s.GetRequiredService<ApiController>()));
|
||||
collection.AddSingleton(s => new PairManager(s.GetRequiredService<ILogger<PairManager>>(), s.GetRequiredService<PairFactory>(),
|
||||
|
||||
@@ -6,6 +6,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;
|
||||
@@ -23,6 +24,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 ILogger<DalamudUtilService> _logger;
|
||||
@@ -37,9 +39,10 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
private readonly List<string> _notUpdatedCharas = [];
|
||||
private bool _sentBetweenAreas = false;
|
||||
|
||||
|
||||
public DalamudUtilService(ILogger<DalamudUtilService> logger, IClientState clientState, IObjectTable objectTable, IFramework framework,
|
||||
IGameGui gameGui, ICondition condition, IDataManager gameData, ITargetManager targetManager,
|
||||
MareMediator mediator, PerformanceCollectorService performanceCollector)
|
||||
BlockedCharacterHandler blockedCharacterHandler, MareMediator mediator, PerformanceCollectorService performanceCollector)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientState = clientState;
|
||||
@@ -48,6 +51,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
_gameGui = gameGui;
|
||||
_condition = condition;
|
||||
_gameData = gameData;
|
||||
_blockedCharacterHandler = blockedCharacterHandler;
|
||||
Mediator = mediator;
|
||||
_performanceCollector = performanceCollector;
|
||||
WorldData = new(() =>
|
||||
@@ -457,6 +461,9 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
if (chara == null || chara.ObjectKind != Dalamud.Game.ClientState.Objects.Enums.ObjectKind.Player)
|
||||
continue;
|
||||
|
||||
if (_blockedCharacterHandler.IsCharacterBlocked(chara.Address))
|
||||
continue;
|
||||
|
||||
var charaName = ((GameObject*)chara.Address)->NameString;
|
||||
var hash = GetHashedAccIdFromPlayerPointer(chara.Address);
|
||||
if (!IsAnythingDrawing)
|
||||
|
||||
Reference in New Issue
Block a user