Target player improvements / crash fix

This commit is contained in:
Loporrit
2023-12-12 10:30:39 +00:00
parent ec951a8976
commit 14f0b10244
4 changed files with 34 additions and 10 deletions

View File

@@ -46,7 +46,7 @@ public sealed class Plugin : IDalamudPlugin
public Plugin(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IDataManager gameData,
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;
_hostBuilderRunTask = new HostBuilder()
@@ -88,7 +88,7 @@ public sealed class Plugin : IDalamudPlugin
collection.AddSingleton<UidDisplayHandler>();
collection.AddSingleton((s) => new DalamudContextMenu(pluginInterface));
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>()));
collection.AddSingleton((s) => new DtrEntry(s.GetRequiredService<ILogger<DtrEntry>>(), dtrBar, s.GetRequiredService<MareConfigService>(),
s.GetRequiredService<MareMediator>(), s.GetRequiredService<PairManager>(), s.GetRequiredService<ApiController>()));

View File

@@ -31,6 +31,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
private readonly ICondition _condition;
private readonly IFramework _framework;
private readonly IGameGui _gameGui;
private readonly IToastGui _toastGui;
private readonly ILogger<DalamudUtilService> _logger;
private readonly IObjectTable _objectTable;
private readonly PerformanceCollectorService _performanceCollector;
@@ -44,7 +45,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
private static readonly Dictionary<uint, PlayerInfo> _playerInfoCache = new();
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)
{
_logger = logger;
@@ -52,6 +53,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
_objectTable = objectTable;
_framework = framework;
_gameGui = gameGui;
_toastGui = toastGui;
_condition = condition;
Mediator = mediator;
_performanceCollector = performanceCollector;
@@ -64,13 +66,17 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
mediator.Subscribe<TargetPairMessage>(this, async (msg) =>
{
if (clientState.IsPvP) return;
var name = msg.Pair.PlayerName;
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;
var ident = msg.Pair.GetPlayerNameHash();
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);
});
}
@@ -458,17 +464,19 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
}
IsAnythingDrawing = false;
_playerCharas.Clear();
var playerCharaList = new Dictionary<string, (string Name, nint Address)>(StringComparer.Ordinal);
_performanceCollector.LogPerformance(this, "ObjTableToCharas",
() => {
foreach (var p in _objectTable.OfType<PlayerCharacter>().Where(o => o.ObjectIndex < 200))
{
CheckCharacterForDrawing(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))
{

View File

@@ -302,6 +302,14 @@ public class DrawGroupPair : DrawPairBase
}
ImGui.Separator();
if (_pair.IsVisible)
{
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.Eye, "Target player"))
{
_mediator.Publish(new TargetPairMessage(_pair));
ImGui.CloseCurrentPopup();
}
}
if (!_pair.IsPaused)
{
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.User, "Open Profile"))

View File

@@ -193,6 +193,14 @@ public class DrawUserPair : DrawPairBase
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 (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.User, "Open Profile"))