refactor: move to net5

This commit is contained in:
Anna 2021-08-22 21:48:54 -04:00
parent e4ac1e9428
commit bc4ef260fa
6 changed files with 166 additions and 56 deletions

View File

@ -2,9 +2,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.2.0</Version>
<TargetFramework>net48</TargetFramework>
<TargetFramework>net5-windows</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dalamud">
@ -29,6 +30,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="1.2.1"/>
<PackageReference Include="DalamudPackager" Version="2.0.0"/>
</ItemGroup>
</Project>

View File

@ -1,5 +1,9 @@
author: ascclemens
name: Globetrotter
punchline: Automatically shows where treasure maps are located.
description: |-
Automatically shows where treasure maps are located.
Icon: Map by Adrien Coquet from the Noun Project
repo_url: https://git.sr.ht/~jkcclemens/Globetrotter
icon_url: https://annaclemens.io/assets/plugins/icons/globetrotter.png

View File

@ -1,44 +1,63 @@
using Dalamud.Game.Command;
using Dalamud.Plugin;
using System;
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Game.Gui;
namespace Globetrotter {
// ReSharper disable once ClassNeverInstantiated.Global
public class GlobetrotterPlugin : IDalamudPlugin {
private bool _disposedValue;
public string Name => "Globetrotter";
private DalamudPluginInterface _pi = null!;
private Configuration _config = null!;
private PluginUi _ui = null!;
private TreasureMaps _maps = null!;
private DalamudPluginInterface Interface { get; }
private CommandManager CommandManager { get; }
internal DataManager DataManager { get; }
internal GameGui GameGui { get; }
internal SigScanner SigScanner { get; }
public void Initialize(DalamudPluginInterface pluginInterface) {
this._pi = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface cannot be null");
internal Configuration Config { get; }
private PluginUi Ui { get; }
private TreasureMaps Maps { get; }
this._config = this._pi.GetPluginConfig() as Configuration ?? new Configuration();
this._config.Initialize(this._pi);
public GlobetrotterPlugin(
DalamudPluginInterface pluginInterface,
CommandManager commandManager,
DataManager dataManager,
GameGui gameGui,
SigScanner scanner
) {
this.Interface = pluginInterface;
this.CommandManager = commandManager;
this.DataManager = dataManager;
this.GameGui = gameGui;
this.SigScanner = scanner;
this._ui = new PluginUi(this._config);
this._maps = new TreasureMaps(this._pi, this._config);
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
this.Config.Initialize(this.Interface);
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) {
this.Ui = new PluginUi(this);
this.Maps = new TreasureMaps(this);
this.Interface.UiBuilder.Draw += this.Ui.Draw;
this.Interface.UiBuilder.OpenConfigUi += this.Ui.OpenSettings;
this.GameGui.HoveredItemChanged += this.Maps.OnHover;
this.CommandManager.AddHandler("/pglobetrotter", new CommandInfo(this.OnConfigCommand) {
HelpMessage = "Show the Globetrotter config",
});
this._pi.CommandManager.AddHandler("/tmap", new CommandInfo(this.OnCommand) {
this.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) {
@ -47,12 +66,12 @@ namespace Globetrotter {
}
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.Interface.UiBuilder.Draw -= this.Ui.Draw;
this.Interface.UiBuilder.OpenConfigUi -= this.Ui.OpenSettings;
this.GameGui.HoveredItemChanged -= this.Maps.OnHover;
this.Maps.Dispose();
this.CommandManager.RemoveHandler("/pglobetrotter");
this.CommandManager.RemoveHandler("/tmap");
}
this._disposedValue = true;

View File

@ -4,7 +4,7 @@ using System.Numerics;
namespace Globetrotter {
internal class PluginUi {
private Configuration Config { get; }
private GlobetrotterPlugin Plugin { get; }
private bool _displaySettings;
@ -13,11 +13,11 @@ namespace Globetrotter {
set => this._displaySettings = value;
}
public PluginUi(Configuration config) {
this.Config = config ?? throw new ArgumentNullException(nameof(config), "Configuration cannot be null");
public PluginUi(GlobetrotterPlugin plugin) {
this.Plugin = plugin;
}
public void OpenSettings(object sender, EventArgs e) {
public void OpenSettings(object? sender, EventArgs? e) {
this.DisplaySettings = true;
}
@ -37,26 +37,26 @@ namespace Globetrotter {
ImGui.Separator();
var showOnDecipher = this.Config.ShowOnDecipher;
var showOnDecipher = this.Plugin.Config.ShowOnDecipher;
if (HelpCheckbox("Show on decipher", "Open the map with a flag set after deciphering a map.", ref showOnDecipher)) {
this.Config.ShowOnDecipher = showOnDecipher;
this.Config.Save();
this.Plugin.Config.ShowOnDecipher = showOnDecipher;
this.Plugin.Config.Save();
}
ImGui.Separator();
var showOnOpen = this.Config.ShowOnOpen;
var showOnOpen = this.Plugin.Config.ShowOnOpen;
if (HelpCheckbox("Show on open", "Open the map with a flag set instead of the normal treasure map window.", ref showOnOpen)) {
this.Config.ShowOnOpen = showOnOpen;
this.Config.Save();
this.Plugin.Config.ShowOnOpen = showOnOpen;
this.Plugin.Config.Save();
}
ImGui.Separator();
var showOnHover = this.Config.ShowOnHover;
var showOnHover = this.Plugin.Config.ShowOnHover;
if (HelpCheckbox("Show on hover", "Open the map with a flag set when hovering over a deciphered map.", ref showOnHover)) {
this.Config.ShowOnHover = showOnHover;
this.Config.Save();
this.Plugin.Config.ShowOnHover = showOnHover;
this.Plugin.Config.Save();
}
ImGui.End();

View File

@ -1,11 +1,11 @@
using Dalamud.Hooking;
using Dalamud.Plugin;
using Lumina.Excel.GeneratedSheets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Logging;
namespace Globetrotter {
internal sealed class TreasureMaps : IDisposable {
@ -21,7 +21,7 @@ namespace Globetrotter {
var mapToRow = new Dictionary<uint, uint>();
foreach (var rank in this.Interface.Data.GetExcelSheet<TreasureHuntRank>()) {
foreach (var rank in this.Plugin.DataManager.GetExcelSheet<TreasureHuntRank>()) {
var unopened = rank.ItemName.Value;
if (unopened == null) {
continue;
@ -48,8 +48,7 @@ namespace Globetrotter {
}
}
private DalamudPluginInterface Interface { get; }
private Configuration Config { get; }
private GlobetrotterPlugin Plugin { get; }
private TreasureMapPacket? _lastMap;
private delegate char HandleActorControlSelfDelegate(long a1, long a2, IntPtr dataPtr);
@ -59,16 +58,15 @@ namespace Globetrotter {
private readonly Hook<HandleActorControlSelfDelegate> _acsHook;
private readonly Hook<ShowTreasureMapDelegate> _showMapHook;
public TreasureMaps(DalamudPluginInterface pi, Configuration config) {
this.Interface = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null");
this.Config = config ?? throw new ArgumentNullException(nameof(config), "Configuration cannot be null");
public TreasureMaps(GlobetrotterPlugin plugin) {
this.Plugin = plugin;
var acsPtr = 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");
this._acsHook = new Hook<HandleActorControlSelfDelegate>(acsPtr, new HandleActorControlSelfDelegate(this.OnACS));
var acsPtr = this.Plugin.SigScanner.ScanText("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 30 48 8B D9 49 8B F8 41 0F B7 08");
this._acsHook = new Hook<HandleActorControlSelfDelegate>(acsPtr, this.OnACS);
this._acsHook.Enable();
var showMapPtr = this.Interface.TargetModuleScanner.ScanText("E8 ?? ?? ?? ?? 40 84 FF 0F 85 ?? ?? ?? ?? 48 8B 0D ?? ?? ?? ??");
this._showMapHook = new Hook<ShowTreasureMapDelegate>(showMapPtr, new ShowTreasureMapDelegate(this.OnShowMap));
var showMapPtr = this.Plugin.SigScanner.ScanText("E8 ?? ?? ?? ?? 40 84 FF 0F 85 ?? ?? ?? ?? 48 8B 0D ?? ?? ?? ??");
this._showMapHook = new Hook<ShowTreasureMapDelegate>(showMapPtr, this.OnShowMap);
this._showMapHook.Enable();
}
@ -77,8 +75,8 @@ namespace Globetrotter {
this._showMapHook.Dispose();
}
public void OnHover(object sender, ulong id) {
if (!this.Config.ShowOnHover || this._lastMap == null || this._lastMap.EventItemId != id) {
public void OnHover(object? sender, ulong id) {
if (!this.Plugin.Config.ShowOnHover || this._lastMap == null || this._lastMap.EventItemId != id) {
return;
}
@ -107,7 +105,7 @@ namespace Globetrotter {
}
}
if (!this.Config.ShowOnOpen && (!this.Config.ShowOnDecipher || this._lastMap?.JustOpened != true)) {
if (!this.Plugin.Config.ShowOnOpen && (!this.Plugin.Config.ShowOnDecipher || this._lastMap?.JustOpened != true)) {
return true;
}
@ -145,7 +143,7 @@ namespace Globetrotter {
return;
}
var spot = this.Interface.Data.GetExcelSheet<TreasureSpot>().GetRow(rowId, packet.SubRowId);
var spot = this.Plugin.DataManager.GetExcelSheet<TreasureSpot>().GetRow(rowId, packet.SubRowId);
var loc = spot?.Location?.Value;
var map = loc?.Map?.Value;
@ -155,17 +153,16 @@ namespace Globetrotter {
return;
}
var x = ToMapCoordinate(loc.X, map.SizeFactor);
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.Interface.Framework.Gui.OpenMapWithMapLink(mapLink);
this.Plugin.GameGui.OpenMapWithMapLink(mapLink);
if (this._lastMap != null) {
this._lastMap.JustOpened = false;

89
icon.svg Executable file
View File

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
version="1.1"
x="0px"
y="0px"
viewBox="0 0 96.988243 96.988243"
xml:space="preserve"
id="svg16"
sodipodi:docname="icon.svg"
width="96.988243"
height="96.988243"
inkscape:version="1.1 (c68e22c387, 2021-05-23)"
inkscape:export-filename="C:\Users\Anna\Desktop\globetrotter.png"
inkscape:export-xdpi="506.45239"
inkscape:export-ydpi="506.45239"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/"><defs
id="defs20" /><sodipodi:namedview
id="namedview18"
pagecolor="#505050"
bordercolor="#ffffff"
borderopacity="1"
inkscape:pageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="1"
showgrid="false"
inkscape:zoom="6.656"
inkscape:cx="47.325721"
inkscape:cy="48.602764"
inkscape:window-width="1920"
inkscape:window-height="1017"
inkscape:window-x="1592"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" /><g
inkscape:groupmode="layer"
id="layer4"
inkscape:label="Layer 3"
transform="translate(-2.4844592,-1.9624853)"><path
style="stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal"
d="m 96.778582,92.850725 -9,-39.499998 c -0.5,-1.9 -2.1,-3.2 -4.1,-3.2 h -1.7 c 3.3,-6.4 6.9,-13.6 8.3,-16.3 3,-6.1 3,-13.100003 0,-19.200003 -5.3,-10.4999991 -18.1,-14.70000014 -28.600004,-9.3999991 -5,2.5 -8.799999,6.9999991 -10.599999,12.3999991 -1.8,5.400003 -1.400001,11.300003 1.099999,16.200003 l 8.3,16.3 H 18.278579 c -2,0 -3.6,1.3 -4.1,3.2 L 5.1785793,92.850725 c -0.3,1.2 0,2.5 0.8,3.5 0.8,1 2,1.6 3.2000015,1.6 H 92.678582 c 1.3,0 2.5,-0.6 3.3,-1.6 0.8,-1 1.1,-2.3 0.8,-3.5 z"
id="path6213" /></g><g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Layer 2"
transform="translate(-2.4844592,-1.9624853)"><path
style="fill:#ff0000;fill-opacity:1;stroke-width:1.20192"
d="M 70.326551,7.4888413 C 62.323404,7.6120356 55.28287,14.53903 54.598538,22.437538 c -0.356358,3.373799 0.211396,6.882245 1.924919,9.838181 4.563672,9.189854 9.221731,18.336026 13.918416,27.456575 0.244313,0.651344 1.184417,0.724893 1.380333,-0.0021 C 76.78798,50.528997 81.514069,41.197887 86.168075,31.835465 89.271028,26.162545 88.443422,18.730141 84.336173,13.769594 80.997409,9.5890461 75.66845,7.2087454 70.326551,7.4888413 Z M 71.271129,16.4346 c 4.405487,-0.20231 8.432838,3.820159 8.224781,8.229183 0.208443,4.429935 -3.963755,8.549621 -8.399661,8.167085 -4.288632,0.194829 -8.257222,-3.897161 -8.007646,-8.196429 -0.257095,-4.38939 3.819375,-8.396067 8.182526,-8.199839 z"
id="path4279" /><path
style="fill:#008000;fill-opacity:1;stroke-width:1.20192"
d="m 22.140469,54.63938 c -1.177417,0.08873 -2.424591,-0.180161 -3.556472,0.142024 -0.911614,3.148664 -1.496045,6.423647 -2.281367,9.62107 -2.1779,9.490382 -4.321902,18.988986 -6.5285291,28.472497 0.09207,1.090943 1.5598101,0.455563 2.2890881,0.617351 4.535184,-0.06061 9.100517,0.02907 13.616881,-0.125772 0.772682,-0.605819 1.006555,-1.774142 1.574983,-2.591405 4.917545,-9.238693 9.924422,-18.431477 14.747957,-27.719075 0.109023,-0.887154 -1.102954,-0.94273 -1.632689,-1.363021 -4.977308,-2.41006 -9.981123,-4.798394 -15.021399,-7.054843 -1.069484,3.92e-4 -2.138969,7.83e-4 -3.208453,0.0012 z"
id="path4854" /><path
style="fill:#005eff;fill-opacity:1;stroke-width:1.20192"
d="m 46.161031,64.726907 c -0.877056,0.331724 -0.998175,1.52976 -1.539589,2.224641 -4.589496,8.546428 -9.221785,17.074155 -13.713625,25.67048 -0.08576,1.022767 1.288883,0.764493 1.931704,0.837473 6.431696,0.07067 12.864196,0.01227 19.296205,0.02406 1.350131,-0.853478 2.372268,-2.213363 3.594327,-3.264577 4.741099,-4.620153 9.618544,-9.110335 14.202703,-13.886008 0.360105,-0.912352 -1.000392,-1.046988 -1.54757,-1.428834 -7.090726,-3.334484 -14.122473,-6.80372 -21.294542,-9.959797 -0.298382,-0.106197 -0.606041,-0.241176 -0.929613,-0.217438 z"
id="path5006" /><path
style="fill:#008000;fill-opacity:1;stroke-width:1.20192"
d="m 74.265666,78.099768 c -5.038591,4.848139 -10.115402,9.656645 -15.116765,14.543093 -0.524351,1.084901 1.073639,0.866269 1.703409,0.855959 10.277284,0 20.554567,2e-6 30.831851,0 1.017659,-0.357639 0.08345,-1.620554 0.0821,-2.36921 -0.469972,-1.878701 -0.809682,-3.81727 -1.377894,-5.654225 -1.176079,-0.856439 -2.688394,-1.306242 -3.991175,-2.00928 -3.912114,-1.803367 -7.786529,-3.755674 -11.722244,-5.465923 -0.162203,-0.04091 -0.283226,-0.004 -0.409284,0.09959 z"
id="path4930" /><path
style="fill:#c87137;fill-opacity:1;stroke-width:1.20192"
d="m 79.628836,54.643195 c -0.883599,0.413627 -0.983358,1.657269 -1.543158,2.409248 -1.20675,2.116659 -2.019876,4.467514 -3.642482,6.30176 -2.014543,1.810692 -5.665224,1.465114 -7.074502,-0.942231 -1.561947,-2.423864 -2.63243,-5.12061 -4.083534,-7.59189 -0.893003,-0.413686 -2.04628,-0.05597 -3.036746,-0.175811 -7.624097,0.02882 -15.254301,-0.07363 -22.874685,0.07668 -0.87517,0.499434 0.139511,1.184769 0.717887,1.32205 16.692357,7.886326 33.34517,15.859971 50.124692,23.559459 0.701525,0.351807 0.998021,-0.574495 0.701023,-1.091002 -1.707542,-7.839417 -3.542613,-15.652168 -5.302722,-23.475648 -0.565376,-0.647558 -1.606153,-0.278916 -2.370688,-0.394768 -0.538361,7.16e-4 -1.076722,0.0014 -1.615085,0.0021 z"
id="path5230" /></g><g
inkscape:groupmode="layer"
id="layer1"
inkscape:label="Layer 1"
transform="translate(-2.4844592,-1.9624853)"><switch
id="switch10"
transform="translate(0.97858271,0.45072486)"
style="stroke:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;paint-order:normal"><foreignObject
requiredExtensions="http://ns.adobe.com/AdobeIllustrator/10.0/"
x="0"
y="0"
width="1"
height="1" /><g
i:extraneous="self"
id="g8"
style="stroke:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;paint-order:normal"><g
id="g6"
style="stroke:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;paint-order:normal"><path
d="m 95.8,92.4 -9,-39.5 C 86.3,51 84.7,49.7 82.7,49.7 H 81 c 3.3,-6.4 6.9,-13.6 8.3,-16.3 3,-6.1 3,-13.1 0,-19.2 C 84,3.7 71.2,-0.5 60.7,4.8 c -5,2.5 -8.8,7 -10.6,12.4 -1.8,5.4 -1.4,11.3 1.1,16.2 l 8.3,16.3 H 17.3 c -2,0 -3.6,1.3 -4.1,3.2 l -9,39.5 c -0.3,1.2 0,2.5 0.8,3.5 0.8,1 2,1.6 3.2,1.6 h 83.5 c 1.3,0 2.5,-0.6 3.3,-1.6 0.8,-1 1.1,-2.3 0.8,-3.5 z M 54.7,18.7 c 1.4,-4.2 4.3,-7.6 8.1,-9.6 2.4,-1.2 4.9,-1.7 7.4,-1.7 6,0 11.8,3.3 14.7,9 2.4,4.7 2.4,10 0,14.8 -2.7,5.4 -14.4,28.1 -14.4,28.1 0,0 0,0 0,0 0,0.1 -0.1,0.2 -0.3,0.2 -0.2,0 -0.3,-0.1 -0.3,-0.2 L 55.6,31.2 C 53.7,27.5 53.4,22.9 54.7,18.7 Z m 7.3,35.9 3.6,7 c 0.9,1.8 2.7,2.9 4.7,2.9 0,0 0,0 0,0 2,0 3.8,-1.1 4.7,-2.9 0.1,-0.2 1.6,-3.1 3.6,-7 h 3.6 L 87.8,79.1 35.9,54.6 Z m -52.8,38 8.7,-38 h 6.5 l 16.4,7.7 -16.2,30.3 z m 20.9,0 15.1,-28.2 23.7,11.2 -17.7,17 z m 28.2,0 15.3,-14.7 15.5,7.3 1.7,7.4 z"
id="path2"
style="stroke:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;paint-order:normal" /><circle
cx="70.300003"
cy="24.200001"
id="ellipse4"
r="8.6999998"
style="stroke:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;paint-order:normal" /></g></g></switch></g></svg>

After

Width:  |  Height:  |  Size: 7.6 KiB