Skip to content

Commit

Permalink
refactor: update highlight color handling and configuration types
Browse files Browse the repository at this point in the history
  • Loading branch information
meoiswa committed Jan 13, 2025
1 parent 6e3eedb commit 958e848
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 deletions.
30 changes: 6 additions & 24 deletions MagitekStratagem/MagitekStratagemPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.IO;
using Dalamud.Game.Command;
using Dalamud.Game.Command;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Newtonsoft.Json;
Expand All @@ -10,14 +8,13 @@
using ImGuiNET;
using Dalamud.Hooking;
using FFXIVClientStructs.FFXIV.Client.Game.Control;
using System.Linq;
using System.Collections.Generic;
using Dalamud.Plugin.Services;
using System.Text.RegularExpressions;
using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.UI;
using Dalamud.Game.ClientState.Conditions;
using Microsoft.AspNetCore.SignalR.Client;
using FFXIVClientStructs.FFXIV.Client.Game.Object;

namespace MagitekStratagemPlugin
{
Expand All @@ -44,10 +41,6 @@ public sealed unsafe class MagitekStratagemPlugin : IDalamudPlugin
public bool ErrorNoTobii { get; private set; } = false;
public bool ErrorNoEyeware { get; private set; } = false;

[Signature("E8 ?? ?? ?? FF 48 8D 8B ?? ?? 00 00 40 0F B6 D6 E8 ?? ?? ?? ?? 40 84 FF")]
private readonly delegate* unmanaged<IntPtr, byte, void> HighlightGameObjectWithColorDelegate = null;


[Signature("E8 ?? ?? ?? ?? 84 C0 44 8B C3")]
private readonly delegate* unmanaged<InputManager*, int, bool> IsInputPressed = null;

Expand Down Expand Up @@ -257,7 +250,7 @@ private void UpdateSelectedTracker()
SignalRService.StartTracking(ActiveTracker);
}
}
}
}

private void EnableHook<T>(Hook<T>? hook, string hookName) where T : Delegate
{
Expand Down Expand Up @@ -305,17 +298,6 @@ private bool WatchingAnyCutscene()
Service.Condition[ConditionFlag.WatchingCutscene78];
}

private void HighlightGameObjectWithColor(IntPtr gameObject, byte color)
{
if (HighlightGameObjectWithColorDelegate == null || WatchingAnyCutscene())
{
return;
}

HighlightGameObjectWithColorDelegate(gameObject, color);

}

public void SaveConfiguration()
{
var configJson = JsonConvert.SerializeObject(Configuration, Formatting.Indented);
Expand Down Expand Up @@ -544,17 +526,17 @@ private void UpdateHighlight()
{
if (lastHighlight != null && ClosestMatch != lastHighlight)
{
HighlightGameObjectWithColor(lastHighlight.Address, 0);
((GameObjectStruct*)lastHighlight.Address)->Highlight(0);
}

HighlightGameObjectWithColor(ClosestMatch.Address, IsRaycasted ? (byte)Configuration.HighlightColor : (byte)Configuration.ProximityColor);
((GameObjectStruct*)ClosestMatch.Address)->Highlight(IsRaycasted ? Configuration.HighlightColor : Configuration.ProximityColor);
LastHighlighted = ClosestMatch;
}
else
{
if (lastHighlight != null)
{
HighlightGameObjectWithColor(lastHighlight.Address, 0);
((GameObjectStruct*)lastHighlight.Address)->Highlight(0);
LastHighlighted = null;
}
}
Expand Down
15 changes: 7 additions & 8 deletions MagitekStratagem/MagitekStratagemUI.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Dalamud.Interface.Windowing;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using ImGuiNET;
using System;
using System.Linq;
using System.Numerics;

namespace MagitekStratagemPlugin
Expand Down Expand Up @@ -331,11 +330,11 @@ private void DrawOverlayCheckbox()
private void DrawProximityColorCombo()
{
ImGui.Text("Highlight color for proximity target");
var proximityColor = plugin.Configuration.ProximityColor;
if (ImGui.Combo("##color", ref proximityColor, "None\0Red\0Green\0Blue\0Yellow\0Orange\0Magenta\0Black\0"))
var proximityColor = (int)plugin.Configuration.ProximityColor;
if (ImGui.Combo("##color", ref proximityColor, "None\0Red\0Green\0Blue\0Yellow\0Orange\0Magenta\0"))
{
proximityColor = ClampColorValue(proximityColor);
plugin.Configuration.ProximityColor = proximityColor;
plugin.Configuration.ProximityColor = (ObjectHighlightColor)proximityColor;
plugin.Configuration.Save();
}
}
Expand All @@ -348,11 +347,11 @@ private void DrawHighlightColorCombo()
}

ImGui.Text("Highlight color for raycasted target");
var highlightColor = plugin.Configuration.HighlightColor;
if (ImGui.Combo("##gazecolor", ref highlightColor, "None\0Red\0Green\0Blue\0Yellow\0Orange\0Magenta\0Black\0"))
var highlightColor = (int)plugin.Configuration.HighlightColor;
if (ImGui.Combo("##gazecolor", ref highlightColor, "None\0Red\0Green\0Blue\0Yellow\0Orange\0Magenta\0"))
{
highlightColor = ClampColorValue(highlightColor);
plugin.Configuration.HighlightColor = highlightColor;
plugin.Configuration.HighlightColor = (ObjectHighlightColor)highlightColor;
plugin.Configuration.Save();
}

Expand Down
8 changes: 3 additions & 5 deletions MagitekStratagem/configuration/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Dalamud.Configuration;
using Dalamud.Plugin;
using System;
using System.Collections.Generic;
using FFXIVClientStructs.FFXIV.Client.Game.Object;

namespace MagitekStratagemPlugin
{
Expand All @@ -14,8 +12,8 @@ public class Configuration : IPluginConfiguration

public bool IsVisible { get; set; } = false;

public int HighlightColor { get; set; } = 2;
public int ProximityColor { get; set; } = 5;
public ObjectHighlightColor HighlightColor { get; set; } = ObjectHighlightColor.Green;
public ObjectHighlightColor ProximityColor { get; set; } = ObjectHighlightColor.Orange;

public bool OverlayEnabled { get; set; } = false;

Expand Down

0 comments on commit 958e848

Please sign in to comment.