Target player improvements / crash fix
This commit is contained in:
@@ -46,7 +46,7 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
|
|
||||||
public Plugin(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IDataManager gameData,
|
public Plugin(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IDataManager gameData,
|
||||||
IFramework framework, IObjectTable objectTable, IClientState clientState, ICondition condition, IChatGui chatGui,
|
IFramework framework, IObjectTable objectTable, IClientState clientState, ICondition condition, IChatGui chatGui,
|
||||||
IGameGui gameGui, IDtrBar dtrBar, IPluginLog pluginLog, ITargetManager targetManager)
|
IGameGui gameGui, IDtrBar dtrBar, IToastGui toastGui, IPluginLog pluginLog, ITargetManager targetManager)
|
||||||
{
|
{
|
||||||
Plugin.Self = this;
|
Plugin.Self = this;
|
||||||
_hostBuilderRunTask = new HostBuilder()
|
_hostBuilderRunTask = new HostBuilder()
|
||||||
@@ -88,7 +88,7 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
collection.AddSingleton<UidDisplayHandler>();
|
collection.AddSingleton<UidDisplayHandler>();
|
||||||
collection.AddSingleton((s) => new DalamudContextMenu(pluginInterface));
|
collection.AddSingleton((s) => new DalamudContextMenu(pluginInterface));
|
||||||
collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService<ILogger<DalamudUtilService>>(),
|
collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService<ILogger<DalamudUtilService>>(),
|
||||||
clientState, objectTable, framework, gameGui, condition, gameData, targetManager,
|
clientState, objectTable, framework, gameGui, toastGui, condition, gameData, targetManager,
|
||||||
s.GetRequiredService<MareMediator>(), s.GetRequiredService<PerformanceCollectorService>()));
|
s.GetRequiredService<MareMediator>(), s.GetRequiredService<PerformanceCollectorService>()));
|
||||||
collection.AddSingleton((s) => new DtrEntry(s.GetRequiredService<ILogger<DtrEntry>>(), dtrBar, s.GetRequiredService<MareConfigService>(),
|
collection.AddSingleton((s) => new DtrEntry(s.GetRequiredService<ILogger<DtrEntry>>(), dtrBar, s.GetRequiredService<MareConfigService>(),
|
||||||
s.GetRequiredService<MareMediator>(), s.GetRequiredService<PairManager>(), s.GetRequiredService<ApiController>()));
|
s.GetRequiredService<MareMediator>(), s.GetRequiredService<PairManager>(), s.GetRequiredService<ApiController>()));
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
|||||||
private readonly ICondition _condition;
|
private readonly ICondition _condition;
|
||||||
private readonly IFramework _framework;
|
private readonly IFramework _framework;
|
||||||
private readonly IGameGui _gameGui;
|
private readonly IGameGui _gameGui;
|
||||||
|
private readonly IToastGui _toastGui;
|
||||||
private readonly ILogger<DalamudUtilService> _logger;
|
private readonly ILogger<DalamudUtilService> _logger;
|
||||||
private readonly IObjectTable _objectTable;
|
private readonly IObjectTable _objectTable;
|
||||||
private readonly PerformanceCollectorService _performanceCollector;
|
private readonly PerformanceCollectorService _performanceCollector;
|
||||||
@@ -44,7 +45,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
|||||||
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, ICondition condition, IDataManager gameData, ITargetManager targetManager,
|
IGameGui gameGui, IToastGui toastGui,ICondition condition, IDataManager gameData, ITargetManager targetManager,
|
||||||
MareMediator mediator, PerformanceCollectorService performanceCollector)
|
MareMediator mediator, PerformanceCollectorService performanceCollector)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@@ -52,6 +53,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
|||||||
_objectTable = objectTable;
|
_objectTable = objectTable;
|
||||||
_framework = framework;
|
_framework = framework;
|
||||||
_gameGui = gameGui;
|
_gameGui = gameGui;
|
||||||
|
_toastGui = toastGui;
|
||||||
_condition = condition;
|
_condition = condition;
|
||||||
Mediator = mediator;
|
Mediator = mediator;
|
||||||
_performanceCollector = performanceCollector;
|
_performanceCollector = performanceCollector;
|
||||||
@@ -64,13 +66,17 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
|||||||
mediator.Subscribe<TargetPairMessage>(this, async (msg) =>
|
mediator.Subscribe<TargetPairMessage>(this, async (msg) =>
|
||||||
{
|
{
|
||||||
if (clientState.IsPvP) return;
|
if (clientState.IsPvP) return;
|
||||||
var name = msg.Pair.PlayerName;
|
var ident = msg.Pair.GetPlayerNameHash();
|
||||||
if (string.IsNullOrEmpty(name)) return;
|
|
||||||
var addr = _playerCharas.FirstOrDefault(f => string.Equals(f.Value.Name, name, StringComparison.Ordinal)).Value.Address;
|
|
||||||
if (addr == nint.Zero) return;
|
|
||||||
await RunOnFrameworkThread(() =>
|
await RunOnFrameworkThread(() =>
|
||||||
{
|
{
|
||||||
targetManager.Target = CreateGameObject(addr);
|
var addr = GetPlayerCharacterFromCachedTableByIdent(ident);
|
||||||
|
var pc = GetPlayerCharacter();
|
||||||
|
var gobj = CreateGameObject(addr);
|
||||||
|
// Any further than roughly 55y is out of range for targetting
|
||||||
|
if (gobj != null && Vector3.Distance(pc.Position, gobj.Position) < 55.0f)
|
||||||
|
targetManager.Target = gobj;
|
||||||
|
else
|
||||||
|
_toastGui.ShowError("Player out of range.");
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -458,17 +464,19 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
|||||||
}
|
}
|
||||||
|
|
||||||
IsAnythingDrawing = false;
|
IsAnythingDrawing = false;
|
||||||
_playerCharas.Clear();
|
|
||||||
|
var playerCharaList = new Dictionary<string, (string Name, nint Address)>(StringComparer.Ordinal);
|
||||||
_performanceCollector.LogPerformance(this, "ObjTableToCharas",
|
_performanceCollector.LogPerformance(this, "ObjTableToCharas",
|
||||||
() => {
|
() => {
|
||||||
foreach (var p in _objectTable.OfType<PlayerCharacter>().Where(o => o.ObjectIndex < 200))
|
foreach (var p in _objectTable.OfType<PlayerCharacter>().Where(o => o.ObjectIndex < 200))
|
||||||
{
|
{
|
||||||
CheckCharacterForDrawing(p);
|
CheckCharacterForDrawing(p);
|
||||||
var info = GetPlayerInfo(p);
|
var info = GetPlayerInfo(p);
|
||||||
_playerCharas.Add(info.Hash, (info.Name, p.Address));
|
playerCharaList.Add(info.Hash, (info.Name, p.Address));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
_playerCharas = playerCharaList;
|
||||||
|
|
||||||
if (!IsAnythingDrawing && !string.IsNullOrEmpty(_lastGlobalBlockPlayer))
|
if (!IsAnythingDrawing && !string.IsNullOrEmpty(_lastGlobalBlockPlayer))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -302,6 +302,14 @@ public class DrawGroupPair : DrawPairBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
|
if (_pair.IsVisible)
|
||||||
|
{
|
||||||
|
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.Eye, "Target player"))
|
||||||
|
{
|
||||||
|
_mediator.Publish(new TargetPairMessage(_pair));
|
||||||
|
ImGui.CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!_pair.IsPaused)
|
if (!_pair.IsPaused)
|
||||||
{
|
{
|
||||||
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.User, "Open Profile"))
|
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.User, "Open Profile"))
|
||||||
|
|||||||
@@ -193,6 +193,14 @@ public class DrawUserPair : DrawPairBase
|
|||||||
|
|
||||||
private void DrawPairedClientMenu(Pair entry)
|
private void DrawPairedClientMenu(Pair entry)
|
||||||
{
|
{
|
||||||
|
if (entry.IsVisible)
|
||||||
|
{
|
||||||
|
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.Eye, "Target player"))
|
||||||
|
{
|
||||||
|
_mediator.Publish(new TargetPairMessage(entry));
|
||||||
|
ImGui.CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!entry.IsPaused)
|
if (!entry.IsPaused)
|
||||||
{
|
{
|
||||||
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.User, "Open Profile"))
|
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.User, "Open Profile"))
|
||||||
|
|||||||
Reference in New Issue
Block a user