diff --git a/Globetrotter.sln b/Globetrotter.sln old mode 100755 new mode 100644 diff --git a/Globetrotter/Configuration.cs b/Globetrotter/Configuration.cs index 6eb0306..bf7ad04 100644 --- a/Globetrotter/Configuration.cs +++ b/Globetrotter/Configuration.cs @@ -4,8 +4,8 @@ using System; namespace Globetrotter { [Serializable] - class Configuration : IPluginConfiguration { - private DalamudPluginInterface pi; + internal class Configuration : IPluginConfiguration { + private DalamudPluginInterface _pi; public int Version { get; set; } = 1; @@ -13,11 +13,11 @@ namespace Globetrotter { public bool ShowOnOpen { get; set; } = true; public void Initialize(DalamudPluginInterface pi) { - this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null"); + this._pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null"); } public void Save() { - this.pi.SavePluginConfig(this); + this._pi.SavePluginConfig(this); } } } diff --git a/Globetrotter/DalamudPackager.targets b/Globetrotter/DalamudPackager.targets old mode 100755 new mode 100644 index 5e1a68b..bb2ca49 --- a/Globetrotter/DalamudPackager.targets +++ b/Globetrotter/DalamudPackager.targets @@ -5,7 +5,7 @@ ProjectDir="$(ProjectDir)" OutputPath="$(OutputPath)" AssemblyName="$(AssemblyName)" - VersionCompenents="3" + VersionComponents="3" MakeZip="true"/> diff --git a/Globetrotter/GlobalSuppressions.cs b/Globetrotter/GlobalSuppressions.cs deleted file mode 100644 index e4b4d97..0000000 --- a/Globetrotter/GlobalSuppressions.cs +++ /dev/null @@ -1,8 +0,0 @@ -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. - -using System.Diagnostics.CodeAnalysis; - -[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "", Scope = "module")] diff --git a/Globetrotter/Globetrotter.csproj b/Globetrotter/Globetrotter.csproj old mode 100755 new mode 100644 index 8844623..b0e1257 --- a/Globetrotter/Globetrotter.csproj +++ b/Globetrotter/Globetrotter.csproj @@ -1,27 +1,28 @@  - - 1.1.2 - net48 - - - - $(AppData)\XIVLauncher\addon\Hooks\Dalamud.dll - - - $(AppData)\XIVLauncher\addon\Hooks\ImGui.NET.dll - - - $(AppData)\XIVLauncher\addon\Hooks\ImGuiScene.dll - - - $(AppData)\XIVLauncher\addon\Hooks\Lumina.dll - - - $(AppData)\XIVLauncher\addon\Hooks\Lumina.Excel.dll - - - - - + + 1.1.2 + net48 + latest + + + + $(AppData)\XIVLauncher\addon\Hooks\dev\Dalamud.dll + + + $(AppData)\XIVLauncher\addon\Hooks\dev\ImGui.NET.dll + + + $(AppData)\XIVLauncher\addon\Hooks\dev\ImGuiScene.dll + + + $(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.dll + + + $(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll + + + + + \ No newline at end of file diff --git a/Globetrotter/Globetrotter.yaml b/Globetrotter/Globetrotter.yaml old mode 100755 new mode 100644 diff --git a/Globetrotter/GlobetrotterPlugin.cs b/Globetrotter/GlobetrotterPlugin.cs index 0b157d2..1d2c1ff 100644 --- a/Globetrotter/GlobetrotterPlugin.cs +++ b/Globetrotter/GlobetrotterPlugin.cs @@ -4,70 +4,63 @@ using System; namespace Globetrotter { public class GlobetrotterPlugin : IDalamudPlugin { - private bool disposedValue; + private bool _disposedValue; public string Name => "Globetrotter"; - private DalamudPluginInterface pi; - private Configuration config; - private PluginUI ui; - private TreasureMaps maps; + private DalamudPluginInterface _pi = null!; + private Configuration _config = null!; + private PluginUi _ui = null!; + private TreasureMaps _maps = null!; public void Initialize(DalamudPluginInterface pluginInterface) { - this.pi = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface cannot be null"); - - this.config = this.pi.GetPluginConfig() as Configuration ?? new Configuration(); - this.config.Initialize(this.pi); + this._pi = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface cannot be null"); - this.ui = new PluginUI(this.pi, this.config); - this.maps = new TreasureMaps(this.pi, this.config); + this._config = this._pi.GetPluginConfig() as Configuration ?? new Configuration(); + this._config.Initialize(this._pi); - this.pi.UiBuilder.OnBuildUi += this.ui.Draw; - this.pi.UiBuilder.OnOpenConfigUi += this.ui.OpenSettings; - this.pi.Framework.Gui.HoveredItemChanged += this.maps.OnHover; - this.pi.CommandManager.AddHandler("/pglobetrotter", new CommandInfo(this.OnConfigCommand) { - HelpMessage = "Show the Globetrotter config" + this._ui = new PluginUi(this._config); + this._maps = new TreasureMaps(this._pi, this._config); + + this._pi.UiBuilder.OnBuildUi += this._ui.Draw; + this._pi.UiBuilder.OnOpenConfigUi += this._ui.OpenSettings; + this._pi.Framework.Gui.HoveredItemChanged += this._maps.OnHover; + this._pi.CommandManager.AddHandler("/pglobetrotter", new CommandInfo(this.OnConfigCommand) { + HelpMessage = "Show the Globetrotter config", }); - this.pi.CommandManager.AddHandler("/tmap", new CommandInfo(this.OnCommand) { - HelpMessage = "Open the map and place a flag at the location of your current treasure map" + this._pi.CommandManager.AddHandler("/tmap", new CommandInfo(this.OnCommand) { + HelpMessage = "Open the map and place a flag at the location of your current treasure map", }); } private void OnConfigCommand(string command, string args) { - this.ui.OpenSettings(null, null); + this._ui.OpenSettings(null, null); } private void OnCommand(string command, string args) { - this.maps.OpenMapLocation(); + this._maps.OpenMapLocation(); } protected virtual void Dispose(bool disposing) { - if (!disposedValue) { - if (disposing) { - this.pi.UiBuilder.OnBuildUi -= this.ui.Draw; - this.pi.UiBuilder.OnOpenConfigUi -= this.ui.OpenSettings; - this.pi.Framework.Gui.HoveredItemChanged -= this.maps.OnHover; - this.maps.Dispose(); - this.pi.CommandManager.RemoveHandler("/pglobetrotter"); - this.pi.CommandManager.RemoveHandler("/tmap"); - } - - // TODO: free unmanaged resources (unmanaged objects) and override finalizer - // TODO: set large fields to null - disposedValue = true; + if (this._disposedValue) { + return; } - } - // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources - // ~GlobetrotterPlugin() - // { - // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - // Dispose(disposing: false); - // } + if (disposing) { + this._pi.UiBuilder.OnBuildUi -= this._ui.Draw; + this._pi.UiBuilder.OnOpenConfigUi -= this._ui.OpenSettings; + this._pi.Framework.Gui.HoveredItemChanged -= this._maps.OnHover; + this._maps.Dispose(); + this._pi.CommandManager.RemoveHandler("/pglobetrotter"); + this._pi.CommandManager.RemoveHandler("/tmap"); + } + + this._disposedValue = true; + } public void Dispose() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); + this.Dispose(true); GC.SuppressFinalize(this); } } diff --git a/Globetrotter/PluginUI.cs b/Globetrotter/PluginUI.cs deleted file mode 100644 index 14454c2..0000000 --- a/Globetrotter/PluginUI.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Dalamud.Plugin; -using ImGuiNET; -using System; - -namespace Globetrotter { - class PluginUI { - private readonly DalamudPluginInterface pi; - private readonly Configuration config; - - private bool _displaySettings = false; - internal bool DisplaySettings { get => this._displaySettings; private set => this._displaySettings = value; } - - public PluginUI(DalamudPluginInterface pi, Configuration config) { - this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null"); - this.config = config ?? throw new ArgumentNullException(nameof(config), "Configuration cannot be null"); - } - - public void OpenSettings(object sender, EventArgs e) { - this.DisplaySettings = true; - } - - public void Draw() { - if (!this.DisplaySettings) { - return; - } - - if (ImGui.Begin("Globetrotter settings", ref this._displaySettings)) { - ImGui.Text("Use /tmap to open your current treasure map."); - ImGui.Text("If you have a map and this plugin isn't working, change zone."); - - ImGui.Separator(); - - bool showOnHover = this.config.ShowOnHover; - if (ImGui.Checkbox("Show on hover", ref showOnHover)) { - this.config.ShowOnHover = showOnHover; - this.config.Save(); - } - - bool showOnOpen = this.config.ShowOnOpen; - if (ImGui.Checkbox("Show on open", ref showOnOpen)) { - this.config.ShowOnOpen = showOnOpen; - this.config.Save(); - } - - ImGui.End(); - } - } - } -} diff --git a/Globetrotter/PluginUi.cs b/Globetrotter/PluginUi.cs new file mode 100644 index 0000000..ef60727 --- /dev/null +++ b/Globetrotter/PluginUi.cs @@ -0,0 +1,52 @@ +using ImGuiNET; +using System; + +namespace Globetrotter { + internal class PluginUi { + private Configuration Config { get; } + + private bool _displaySettings; + + private bool DisplaySettings { + get => this._displaySettings; + set => this._displaySettings = value; + } + + public PluginUi(Configuration config) { + this.Config = config ?? throw new ArgumentNullException(nameof(config), "Configuration cannot be null"); + } + + public void OpenSettings(object sender, EventArgs e) { + this.DisplaySettings = true; + } + + public void Draw() { + if (!this.DisplaySettings) { + return; + } + + if (!ImGui.Begin("Globetrotter settings", ref this._displaySettings)) { + return; + } + + ImGui.TextUnformatted("Use /tmap to open your current treasure map."); + ImGui.TextUnformatted("If you have a map and this plugin isn't working, change zone."); + + ImGui.Separator(); + + var showOnHover = this.Config.ShowOnHover; + if (ImGui.Checkbox("Show on hover", ref showOnHover)) { + this.Config.ShowOnHover = showOnHover; + this.Config.Save(); + } + + var showOnOpen = this.Config.ShowOnOpen; + if (ImGui.Checkbox("Show on open", ref showOnOpen)) { + this.Config.ShowOnOpen = showOnOpen; + this.Config.Save(); + } + + ImGui.End(); + } + } +} diff --git a/Globetrotter/TreasureMaps.cs b/Globetrotter/TreasureMaps.cs index 83e7504..deedb23 100644 --- a/Globetrotter/TreasureMaps.cs +++ b/Globetrotter/TreasureMaps.cs @@ -7,20 +7,21 @@ using System.Collections.Generic; using System.Runtime.InteropServices; namespace Globetrotter { - class TreasureMaps : IDisposable { - private const uint TREASURE_MAPS = 0x54; + internal sealed class TreasureMaps : IDisposable { + private const uint TreasureMapsCode = 0x54; private static Dictionary _mapToRow; + private Dictionary MapToRow { get { if (_mapToRow != null) { return _mapToRow; } - Dictionary mapToRow = new Dictionary(); + var mapToRow = new Dictionary(); - foreach (TreasureHuntRank rank in this.pi.Data.GetExcelSheet()) { - Item unopened = rank.ItemName.Value; + foreach (var rank in this.Interface.Data.GetExcelSheet()) { + var unopened = rank.ItemName.Value; if (unopened == null) { continue; } @@ -32,6 +33,7 @@ namespace Globetrotter { } catch (NullReferenceException) { opened = null; } + if (opened == null) { continue; } @@ -45,30 +47,30 @@ namespace Globetrotter { } } - private readonly DalamudPluginInterface pi; - private readonly Configuration config; - private TreasureMapPacket lastMap; - private bool disposedValue; + private DalamudPluginInterface Interface { get; } + private Configuration Config { get; } + private TreasureMapPacket _lastMap; private delegate char HandleActorControlSelfDelegate(long a1, long a2, IntPtr dataPtr); - private readonly Hook acsHook; + + private readonly Hook _acsHook; public TreasureMaps(DalamudPluginInterface pi, Configuration config) { - this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null"); - this.config = config ?? throw new ArgumentNullException(nameof(config), "Configuration cannot be null"); + this.Interface = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null"); + this.Config = config ?? throw new ArgumentNullException(nameof(config), "Configuration cannot be null"); - IntPtr delegatePtr = this.pi.TargetModuleScanner.ScanText("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 30 48 8B D9 49 8B F8 41 0F B7 08"); + var delegatePtr = this.Interface.TargetModuleScanner.ScanText("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 30 48 8B D9 49 8B F8 41 0F B7 08"); if (delegatePtr == IntPtr.Zero) { PluginLog.Log("Unable to detect treasure maps because could not find ACS handler delegate"); return; } - this.acsHook = new Hook(delegatePtr, new HandleActorControlSelfDelegate(this.OnACS)); - this.acsHook.Enable(); + this._acsHook = new Hook(delegatePtr, new HandleActorControlSelfDelegate(this.OnACS)); + this._acsHook.Enable(); } public void OnHover(object sender, ulong id) { - if (!this.config.ShowOnHover || this.lastMap == null || this.lastMap.EventItemId != id) { + if (!this.Config.ShowOnHover || this._lastMap == null || this._lastMap.EventItemId != id) { return; } @@ -76,81 +78,71 @@ namespace Globetrotter { } private char OnACS(long a1, long a2, IntPtr dataPtr) { - TreasureMapPacket packet = ParsePacket(dataPtr); + var packet = ParsePacket(dataPtr); if (packet == null) { - return this.acsHook.Original(a1, a2, dataPtr); + return this._acsHook.Original(a1, a2, dataPtr); } - this.lastMap = packet; + this._lastMap = packet; - if (this.config.ShowOnOpen && packet.JustOpened) { + if (this.Config.ShowOnOpen && packet.JustOpened) { // this does not work because the offset in memory is not yet updated with the thing this.OpenMapLocation(); } - return this.acsHook.Original(a1, a2, dataPtr); + return this._acsHook.Original(a1, a2, dataPtr); } public void OpenMapLocation() { - TreasureMapPacket packet = this.lastMap; + var packet = this._lastMap; if (packet == null) { return; } - if (!this.MapToRow.TryGetValue(packet.EventItemId, out uint rowId)) { + if (!this.MapToRow.TryGetValue(packet.EventItemId, out var rowId)) { return; } - TreasureSpot spot = this.pi.Data.GetExcelSheet().GetRow(rowId, packet.SubRowId); - if (spot == null) { + var spot = this.Interface.Data.GetExcelSheet().GetRow(rowId, packet.SubRowId); + + var loc = spot?.Location?.Value; + var map = loc?.Map?.Value; + var terr = map?.TerritoryType?.Value; + + if (terr == null) { return; } - if (spot.Location.Value == null) { - return; - } - Level loc = spot.Location.Value; - - if (loc.Map.Value == null) { - return; - } - Map map = loc.Map.Value; - - if (map.TerritoryType.Value == null) { - return; - } - TerritoryType terr = map.TerritoryType.Value; - - float x = ToMapCoordinate(loc.X, map.SizeFactor); - float y = ToMapCoordinate(loc.Z, map.SizeFactor); - MapLinkPayload mapLink = new MapLinkPayload( - this.pi.Data, + var x = ToMapCoordinate(loc.X, map.SizeFactor); + var y = ToMapCoordinate(loc.Z, map.SizeFactor); + var mapLink = new MapLinkPayload( + this.Interface.Data, terr.RowId, map.RowId, ConvertMapCoordinateToRawPosition(x, map.SizeFactor), ConvertMapCoordinateToRawPosition(y, map.SizeFactor) ); - this.pi.Framework.Gui.OpenMapWithMapLink(mapLink); + this.Interface.Framework.Gui.OpenMapWithMapLink(mapLink); } - public static TreasureMapPacket ParsePacket(IntPtr dataPtr) { + private static TreasureMapPacket ParsePacket(IntPtr dataPtr) { uint category = Marshal.ReadByte(dataPtr); - if (category != TREASURE_MAPS) { + if (category != TreasureMapsCode) { return null; } dataPtr += 4; // skip padding - uint param1 = (uint)Marshal.ReadInt32(dataPtr); + var param1 = (uint) Marshal.ReadInt32(dataPtr); dataPtr += 4; - uint param2 = (uint)Marshal.ReadInt32(dataPtr); + var param2 = (uint) Marshal.ReadInt32(dataPtr); dataPtr += 4; - uint param3 = (uint)Marshal.ReadInt32(dataPtr); + var param3 = (uint) Marshal.ReadInt32(dataPtr); - uint eventItemId = param1; - uint subRowId = param2; - bool justOpened = param3 == 1; + var eventItemId = param1; + var subRowId = param2; + var justOpened = param3 == 1; return new TreasureMapPacket(eventItemId, subRowId, justOpened); } @@ -161,8 +153,9 @@ namespace Globetrotter { var scaledPos = (((pos - 1.0f) * c / 41.0f * 2048.0f) - 1024.0f) / c; scaledPos *= 1000.0f; - return (int)scaledPos; + return (int) scaledPos; } + private static float ToMapCoordinate(float val, float scale) { var c = scale / 100f; @@ -170,27 +163,15 @@ namespace Globetrotter { return (41f / c * ((val + 1024f) / 2048f)) + 1; } - protected virtual void Dispose(bool disposing) { - if (!disposedValue) { - if (disposing) { - this.acsHook?.Dispose(); - } - - disposedValue = true; - } - } - public void Dispose() { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); - GC.SuppressFinalize(this); + this._acsHook?.Dispose(); } } - class TreasureMapPacket { - public uint EventItemId { get; private set; } - public uint SubRowId { get; private set; } - public bool JustOpened { get; private set; } + internal class TreasureMapPacket { + public uint EventItemId { get; } + public uint SubRowId { get; } + public bool JustOpened { get; } public TreasureMapPacket(uint eventItemId, uint subRowId, bool justOpened) { this.EventItemId = eventItemId;