commit a9d939973808fb177230ba1705b4aefd89390b55 Author: Anna Clemens Date: Sat Aug 1 03:43:23 2020 -0400 chore: initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..03b3248 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,203 @@ +# Remove the line below if you want to inherit .editorconfig settings from higher directories +root = true + +# C# files +[*.{cs,json}] + +#### Core EditorConfig Options #### + +# Indentation and spacing +indent_size = 4 +indent_style = space +tab_width = 4 + +# New line preferences +end_of_line = lf +insert_final_newline = true + +[*.cs] + +#### .NET Coding Conventions #### + +# Organize usings +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = false +file_header_template = unset + +# this. and Me. preferences +dotnet_style_qualification_for_event = true:silent +dotnet_style_qualification_for_field = true:silent +dotnet_style_qualification_for_method = true:silent +dotnet_style_qualification_for_property = true:silent + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:silent +dotnet_style_predefined_type_for_member_access = true:silent + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent + +# Expression-level preferences +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_object_initializer = true:suggestion +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion + +# Field preferences +dotnet_style_readonly_field = true:suggestion + +# Parameter preferences +dotnet_code_quality_unused_parameters = all:suggestion + +#### C# Coding Conventions #### + +# var preferences +csharp_style_var_elsewhere = false:silent +csharp_style_var_for_built_in_types = false:silent +csharp_style_var_when_type_is_apparent = false:silent + +# Expression-bodied members +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent + +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_prefer_switch_expression = true:suggestion + +# Null-checking preferences +csharp_style_conditional_delegate_call = true:suggestion + +# Modifier preferences +csharp_prefer_static_local_function = true:suggestion +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent + +# Code-block preferences +csharp_prefer_braces = true:silent +csharp_prefer_simple_using_statement = true:suggestion + +# Expression-level preferences +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_pattern_local_over_anonymous_function = true:suggestion +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_range_operator = true:suggestion +csharp_style_throw_expression = true:suggestion +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +csharp_style_unused_value_expression_statement_preference = discard_variable:silent + +# 'using' directive preferences +csharp_using_directive_placement = outside_namespace:silent + +#### C# Formatting Rules #### + +# New line preferences +csharp_new_line_before_catch = false +csharp_new_line_before_else = false +csharp_new_line_before_finally = false +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = none +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcadb2c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ee5385 --- /dev/null +++ b/.gitignore @@ -0,0 +1,362 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd diff --git a/Globetrotter.sln b/Globetrotter.sln new file mode 100644 index 0000000..97ce04d --- /dev/null +++ b/Globetrotter.sln @@ -0,0 +1,30 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30320.27 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Globetrotter", "Globetrotter\Globetrotter.csproj", "{F7501CB3-7970-4E81-9ACE-C285C76FDCCC}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{08E68022-CEA3-43CC-982D-EAFFE60A7F10}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F7501CB3-7970-4E81-9ACE-C285C76FDCCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7501CB3-7970-4E81-9ACE-C285C76FDCCC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7501CB3-7970-4E81-9ACE-C285C76FDCCC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7501CB3-7970-4E81-9ACE-C285C76FDCCC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A35004C3-29D3-4EB3-A37D-978B8C2B7020} + EndGlobalSection +EndGlobal diff --git a/Globetrotter/Configuration.cs b/Globetrotter/Configuration.cs new file mode 100644 index 0000000..6eb0306 --- /dev/null +++ b/Globetrotter/Configuration.cs @@ -0,0 +1,23 @@ +using Dalamud.Configuration; +using Dalamud.Plugin; +using System; + +namespace Globetrotter { + [Serializable] + class Configuration : IPluginConfiguration { + private DalamudPluginInterface pi; + + public int Version { get; set; } = 1; + + public bool ShowOnHover { get; set; } = true; + public bool ShowOnOpen { get; set; } = true; + + public void Initialize(DalamudPluginInterface pi) { + this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null"); + } + + public void Save() { + this.pi.SavePluginConfig(this); + } + } +} diff --git a/Globetrotter/GlobalSuppressions.cs b/Globetrotter/GlobalSuppressions.cs new file mode 100644 index 0000000..e4b4d97 --- /dev/null +++ b/Globetrotter/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// 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 new file mode 100644 index 0000000..c1d94a7 --- /dev/null +++ b/Globetrotter/Globetrotter.csproj @@ -0,0 +1,100 @@ + + + + + + + + + + Debug + AnyCPU + {F7501CB3-7970-4E81-9ACE-C285C76FDCCC} + Library + Properties + Globetrotter + Globetrotter + v4.8 + 512 + true + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + $(AppData)\XIVLauncher\addon\Hooks\Dalamud.dll + + + $(AppData)\XIVLauncher\addon\Hooks\ImGui.NET.dll + + + $(AppData)\XIVLauncher\addon\Hooks\ImGuiScene.dll + + + False + $(AppData)\XIVLauncher\addon\Hooks\Lumina.dll + + + $(AppData)\XIVLauncher\addon\Hooks\Lumina.Generated.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + \ No newline at end of file diff --git a/Globetrotter/Globetrotter.json b/Globetrotter/Globetrotter.json new file mode 100644 index 0000000..5e2f959 --- /dev/null +++ b/Globetrotter/Globetrotter.json @@ -0,0 +1,10 @@ +{ + "Author": "ascclemens", + "Name": "Globetrotter", + "Description": "Automatically shows where treasure maps are located. /pglobetrogger /tmap", + "InternalName": "Globetrotter", + "AssemblyVersion": "1.0.0", + "RepoUrl": "https://sr.ht/~jkcclemens/Globetrotter", + "ApplicableVersion": "any", + "DalamudApiLevel": 1 +} diff --git a/Globetrotter/GlobetrotterPlugin.cs b/Globetrotter/GlobetrotterPlugin.cs new file mode 100644 index 0000000..626fa44 --- /dev/null +++ b/Globetrotter/GlobetrotterPlugin.cs @@ -0,0 +1,79 @@ +using Dalamud.Game.Command; +using Dalamud.Plugin; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Globetrotter { + public class GlobetrotterPlugin : IDalamudPlugin { + private bool disposedValue; + + public string Name => "Globetrotter"; + + private DalamudPluginInterface pi; + private Configuration config; + private PluginUI ui; + private TreasureMaps maps; + + 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.ui = new PluginUI(this.pi, 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.Framework.Network.OnNetworkMessage += this.maps.OnNetwork; + 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" + }); + } + + private void OnConfigCommand(string command, string args) { + this.ui.OpenSettings(null, null); + } + + private void OnCommand(string command, string args) { + 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.pi.Framework.Network.OnNetworkMessage -= this.maps.OnNetwork; + 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; + } + } + + // // 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); + // } + + public void Dispose() { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + } +} diff --git a/Globetrotter/PluginUI.cs b/Globetrotter/PluginUI.cs new file mode 100644 index 0000000..7ebe962 --- /dev/null +++ b/Globetrotter/PluginUI.cs @@ -0,0 +1,53 @@ +using Dalamud.Plugin; +using ImGuiNET; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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/Properties/AssemblyInfo.cs b/Globetrotter/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..29f601d --- /dev/null +++ b/Globetrotter/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Globetrotter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Globetrotter")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f7501cb3-7970-4e81-9ace-c285c76fdccc")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0")] +[assembly: AssemblyFileVersion("1.0.0")] diff --git a/Globetrotter/TreasureMaps.cs b/Globetrotter/TreasureMaps.cs new file mode 100644 index 0000000..100be40 --- /dev/null +++ b/Globetrotter/TreasureMaps.cs @@ -0,0 +1,166 @@ +using Dalamud.Game.Chat.SeStringHandling.Payloads; +using Dalamud.Game.Internal.Network; +using Dalamud.Plugin; +using Lumina.Excel.GeneratedSheets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace Globetrotter { + class TreasureMaps { + private static readonly Dictionary MAP_TO_ROW = new Dictionary { + [2_001_087] = 1, + [2_001_088] = 2, + [2_001_089] = 3, + [2_001_090] = 4, + [2_001_091] = 5, + // missing 6, 7, 8 + [2_001_762] = 9, + [2_001_763] = 10, + [2_001_764] = 11, + [2_002_209] = 12, + [2_002_210] = 13, + // missing 14, 15, 16 + [2_002_663] = 17, + [2_002_664] = 18, + }; + + private readonly DalamudPluginInterface pi; + private readonly Configuration config; + private TreasureMapPacket lastMap; + + 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"); + } + + public void OnHover(object sender, ulong id) { + if (!this.config.ShowOnHover || this.lastMap == null || this.lastMap.EventItemId != id) { + return; + } + + this.OpenMapLocation(); + } + + public void OnNetwork(IntPtr dataPtr, ushort opCode, uint sourceActorId, uint targetActorId, NetworkMessageDirection direction) { + if (direction != NetworkMessageDirection.ZoneDown) { + return; + } + + TreasureMapPacket packet = ParsePacket(dataPtr, opCode); + if (packet == null) { + return; + } + + this.lastMap = packet; + + if (this.config.ShowOnOpen && packet.JustOpened) { + // this does not work because the offset in memory is not yet updated with the thing + this.OpenMapLocation(); + } + } + + public void OpenMapLocation() { + TreasureMapPacket packet = this.lastMap; + + if (packet == null) { + return; + } + + if (!MAP_TO_ROW.TryGetValue(packet.EventItemId, out uint rowId)) { + return; + } + + TreasureSpot spot = this.pi.Data.GetExcelSheet().GetRow(rowId, packet.SubRowId); + if (spot == 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; + + // TODO: can probably fix this up to be nicer after Dalamud releases a new version and fixes the big with MapLinkPayload + + float x = ToMapCoordinate(loc.X, map.SizeFactor); + float y = ToMapCoordinate(loc.Z, map.SizeFactor); + MapLinkPayload mapLink = new MapLinkPayload( + terr.RowId, + map.RowId, + ConvertMapCoordinateToRawPosition(x, map.SizeFactor), + ConvertMapCoordinateToRawPosition(y, map.SizeFactor) + ); + + // fix bug in Dalamud + mapLink.GetType().GetField("DataResolver", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(mapLink, this.pi.Data); + + this.pi.Framework.Gui.OpenMapWithMapLink(mapLink); + } + + public static TreasureMapPacket ParsePacket(IntPtr dataPtr, ushort opCode) { + if (opCode != 0x165) { + return null; + } + + uint category = (uint)Marshal.ReadByte(dataPtr); + if (category != 0x54) { + return null; + } + + dataPtr += 4; // skip padding + uint param1 = (uint)Marshal.ReadInt32(dataPtr); + dataPtr += 4; + uint param2 = (uint)Marshal.ReadInt32(dataPtr); + dataPtr += 4; + uint param3 = (uint)Marshal.ReadInt32(dataPtr); + + uint eventItemId = param1; + uint subRowId = param2; + bool justOpened = param3 == 1; + + return new TreasureMapPacket(eventItemId, subRowId, justOpened); + } + + private static int ConvertMapCoordinateToRawPosition(float pos, float scale) { + var c = scale / 100.0f; + + var scaledPos = ((((pos - 1.0f) * c / 41.0f) * 2048.0f) - 1024.0f) / c; + scaledPos *= 1000.0f; + + return (int)scaledPos; + } + private static float ToMapCoordinate(float val, float scale) { + var c = scale / 100f; + + val *= c; + return ((41f / c) * ((val + 1024f) / 2048f)) + 1; + } + } + + class TreasureMapPacket { + public uint EventItemId { get; private set; } + public uint SubRowId { get; private set; } + public bool JustOpened { get; private set; } + + public TreasureMapPacket(uint eventItemId, uint subRowId, bool justOpened) { + this.EventItemId = eventItemId; + this.SubRowId = subRowId; + this.JustOpened = justOpened; + } + } +} diff --git a/Globetrotter/packages.config b/Globetrotter/packages.config new file mode 100644 index 0000000..b8ca95a --- /dev/null +++ b/Globetrotter/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file