From d9ea9e0aebabc4e4e8f7dd0763a2a5d04b11bbd8 Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 1 Sep 2020 20:21:43 -0400 Subject: [PATCH] chore: initial commit --- .editorconfig | 203 +++++++++++++++ .gitattributes | 1 + .gitignore | 362 ++++++++++++++++++++++++++ GoodMemory.sln | 30 +++ GoodMemory/ActionType.cs | 30 +++ GoodMemory/GameFunctions.cs | 65 +++++ GoodMemory/GoodMemory.csproj | 62 +++++ GoodMemory/GoodMemory.json | 10 + GoodMemory/Plugin.cs | 162 ++++++++++++ GoodMemory/Properties/AssemblyInfo.cs | 38 +++ 10 files changed, 963 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 GoodMemory.sln create mode 100644 GoodMemory/ActionType.cs create mode 100644 GoodMemory/GameFunctions.cs create mode 100644 GoodMemory/GoodMemory.csproj create mode 100644 GoodMemory/GoodMemory.json create mode 100644 GoodMemory/Plugin.cs create mode 100644 GoodMemory/Properties/AssemblyInfo.cs 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/GoodMemory.sln b/GoodMemory.sln new file mode 100644 index 0000000..17f3dee --- /dev/null +++ b/GoodMemory.sln @@ -0,0 +1,30 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30406.217 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoodMemory", "GoodMemory\GoodMemory.csproj", "{2B53DAAE-5F20-4EAF-8BC5-97FCE68C1738}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B68CFC57-5F01-4F16-86FA-82306CCE695F}" + 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 + {2B53DAAE-5F20-4EAF-8BC5-97FCE68C1738}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B53DAAE-5F20-4EAF-8BC5-97FCE68C1738}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B53DAAE-5F20-4EAF-8BC5-97FCE68C1738}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B53DAAE-5F20-4EAF-8BC5-97FCE68C1738}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1579EFBA-835F-428B-9FC6-BAD6FC361610} + EndGlobalSection +EndGlobal diff --git a/GoodMemory/ActionType.cs b/GoodMemory/ActionType.cs new file mode 100644 index 0000000..1d60d67 --- /dev/null +++ b/GoodMemory/ActionType.cs @@ -0,0 +1,30 @@ +using Lumina.Excel.GeneratedSheets; +using System; +using System.Linq; + +namespace GoodMemory { + public static class ActionTypeExt { + private static readonly ActionType[] VALID = (ActionType[])Enum.GetValues(typeof(ActionType)); + + public static bool IsValidAction(ItemAction action) { + if (action == null || action.RowId == 0) { + return false; + } + + ActionType type = (ActionType)action.Type; + return VALID.Contains(type); + } + } + + public enum ActionType : ushort { + Minions = 853, // minions + Bardings = 1_013, // bardings + Mounts = 1_322, // mounts + CrafterBooks = 2_136, // crafter books + Miscellaneous = 2_633, // riding maps, blu totems, emotes/dances + Cards = 3_357, // cards + GathererBooks = 4_107, // gatherer books + OrchestrionRolls = 5_845, // orchestrion rolls + FashionAccessories = 20_086, // fashion accessories + } +} diff --git a/GoodMemory/GameFunctions.cs b/GoodMemory/GameFunctions.cs new file mode 100644 index 0000000..2905129 --- /dev/null +++ b/GoodMemory/GameFunctions.cs @@ -0,0 +1,65 @@ +using Lumina.Excel.GeneratedSheets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace GoodMemory { + public class GameFunctions { + private readonly Plugin plugin; + + private delegate byte HasItemActionUnlockedDelegate(long itemActionId); + private readonly HasItemActionUnlockedDelegate hasItemActionUnlocked; + + private delegate byte HasCardDelegate(IntPtr localPlayer, ushort cardId); + private readonly HasCardDelegate hasCard; + + private readonly IntPtr cardStaticAddr; + + public GameFunctions(Plugin plugin) { + this.plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "Plugin cannot be null"); + + IntPtr hasIAUnlockedPtr = plugin.Interface.TargetModuleScanner.ScanText("48 83 EC 28 E8 ?? ?? ?? ?? 48 85 C0 0F 84 ?? ?? ?? ??"); + IntPtr hasCardPtr = plugin.Interface.TargetModuleScanner.ScanText("40 53 48 83 EC 20 48 8B D9 66 85 D2 74 ??"); + this.cardStaticAddr = plugin.Interface.TargetModuleScanner.GetStaticAddressFromSig("48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 84 C0 74 ?? 48 8B 53 ?? 48 8D 4B ?? 48 83 C2 0C 48 8D 14 ?? E8 ?? ?? ?? ?? 40 FE C7 40 3A FD 72 ?? 48 8B 5C 24 ??"); + + if (hasIAUnlockedPtr == IntPtr.Zero || hasCardPtr == IntPtr.Zero || this.cardStaticAddr == IntPtr.Zero) { + throw new ApplicationException("Could not get pointers for game functions"); + } + + this.hasItemActionUnlocked = Marshal.GetDelegateForFunctionPointer(hasIAUnlockedPtr); + this.hasCard = Marshal.GetDelegateForFunctionPointer(hasCardPtr); + } + + public bool HasAcquired(Item item) { + ItemAction action = item.ItemAction.Value; + + if (action == null) { + return false; + } + + ActionType type = (ActionType)action.Type; + + if (type == ActionType.Cards) { + uint cardId = item.AdditionalData; + TripleTriadCard card = this.plugin.Interface.Data.GetExcelSheet().GetRow(cardId); + if (card == null) { + return false; + } + return this.HasCard((ushort)card.RowId); + } + + return this.HasItemActionUnlocked(action.RowId); + } + + private bool HasItemActionUnlocked(long itemActionId) { + return this.hasItemActionUnlocked(itemActionId) == 1; + } + + private bool HasCard(ushort cardId) { + return this.hasCard(this.cardStaticAddr, cardId) == 1; + } + } +} diff --git a/GoodMemory/GoodMemory.csproj b/GoodMemory/GoodMemory.csproj new file mode 100644 index 0000000..379558c --- /dev/null +++ b/GoodMemory/GoodMemory.csproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + {2B53DAAE-5F20-4EAF-8BC5-97FCE68C1738} + Library + Properties + GoodMemory + GoodMemory + 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\Lumina.dll + + + $(AppData)\XIVLauncher\addon\Hooks\Lumina.Generated.dll + + + + + + + + + + + + + + + + + + + + + diff --git a/GoodMemory/GoodMemory.json b/GoodMemory/GoodMemory.json new file mode 100644 index 0000000..0caa724 --- /dev/null +++ b/GoodMemory/GoodMemory.json @@ -0,0 +1,10 @@ +{ + "Author": "ascclemens", + "Name": "Good Memory", + "Description": "Adds an indicator in item tooltips to show whether you have acquired that item.", + "InternalName": "GoodMemory", + "AssemblyVersion": "1.0.0", + "RepoUrl": "https://sr.ht/~jkcclemens/GoodMemory", + "ApplicableVersion": "any", + "DalamudApiLevel": 1 +} diff --git a/GoodMemory/Plugin.cs b/GoodMemory/Plugin.cs new file mode 100644 index 0000000..4957af9 --- /dev/null +++ b/GoodMemory/Plugin.cs @@ -0,0 +1,162 @@ +using Dalamud.Hooking; +using Dalamud.Plugin; +using Lumina.Excel.GeneratedSheets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace GoodMemory { + public class Plugin : IDalamudPlugin { + private bool disposedValue; + + public string Name => "Good Memory"; + + public DalamudPluginInterface Interface { get; private set; } + private GameFunctions Functions { get; set; } + private readonly IntPtr alloc = Marshal.AllocHGlobal(4096); + private Hook tooltipHook; + + private delegate IntPtr TooltipDelegate(IntPtr a1, IntPtr a2, IntPtr a3); + + public void Initialize(DalamudPluginInterface pluginInterface) { + this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface cannot be null"); + this.Functions = new GameFunctions(this); + this.SetUpHook(); + } + + protected virtual void Dispose(bool disposing) { + if (!this.disposedValue) { + if (disposing) { + this.tooltipHook?.Dispose(); + Marshal.FreeHGlobal(this.alloc); + } + + this.disposedValue = true; + } + } + + public void Dispose() { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + private void SetUpHook() { + IntPtr tooltipPtr = this.Interface.TargetModuleScanner.ScanText("48 89 5C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 48 83 EC 50 48 8B 42 ??"); + if (tooltipPtr == IntPtr.Zero) { + throw new ApplicationException("Could not set up tooltip hook because of null pointer"); + } + this.tooltipHook = new Hook(tooltipPtr, new TooltipDelegate(this.OnTooltip)); + this.tooltipHook.Enable(); + } + + private IntPtr OnTooltip(IntPtr a1, IntPtr a2, IntPtr a3) { + IntPtr v3 = Marshal.ReadIntPtr(a2 + 32); + uint v9 = (uint)Marshal.ReadInt32(v3 + 16); + + if ((v9 & 2) == 0) { + goto Return; + } + + ulong itemId = this.Interface.Framework.Gui.HoveredItem; + if (itemId > 2_000_000) { + goto Return; + } else if (itemId > 1_000_000) { + itemId -= 1_000_000; + } + + Item item = this.Interface.Data.GetExcelSheet().GetRow((uint)itemId); + + if (item == null) { + goto Return; + } + + // get the pointer to the text + IntPtr startPtr = Marshal.ReadIntPtr(a3 + 32) + 104; + // get the text pointer + IntPtr start = Marshal.ReadIntPtr(startPtr); + + // work around function being called twice + if (start == this.alloc) { + goto Return; + } + + string overwrite; + + // Faded Copies + if (item.FilterGroup == 12 && item.ItemUICategory.Value?.RowId == 94 && item.LevelItem.Value?.RowId == 1) { + Item[] recipeResults = this.Interface.Data.GetExcelSheet() + .Where(recipe => recipe.UnkStruct5.Any(ritem => ritem.ItemIngredient == item.RowId)) + .Select(recipe => recipe.ItemResult.Value) + .Where(result => result != null) + .ToArray(); + + overwrite = ReadString(start); + + foreach (Item result in recipeResults) { + ItemAction resultAction = result.ItemAction.Value; + if (!ActionTypeExt.IsValidAction(resultAction)) { + continue; + } + + this.AppendIfAcquired(ref overwrite, result, true); + } + } else { + ItemAction action = item.ItemAction?.Value; + + if (!ActionTypeExt.IsValidAction(action)) { + goto Return; + } + + // get the text + overwrite = ReadString(start); + + // generate our replacement text + this.AppendIfAcquired(ref overwrite, item); + } + + // write our replacement text into our own managed memory (4096 bytes) + WriteString(this.alloc, overwrite, true); + + // overwrite the original pointer with our own + Marshal.WriteIntPtr(startPtr, this.alloc); + + Return: + return this.tooltipHook.Original(a1, a2, a3); + } + + private void AppendIfAcquired(ref string txt, Item item, bool useItem = false) { + string has = this.Functions.HasAcquired(item) ? "Yes" : "No"; + if (useItem) { + txt = $"{txt}\nAcquired ({item.Name}): {has}"; + } else { + txt = $"{txt}\nAcquired: {has}"; + } + } + + private static string ReadString(IntPtr ptr) { + int offset = 0; + List stringBytes = new List(); + while (true) { + byte b = Marshal.ReadByte(ptr + offset); + if (b == 0) { + break; + } + stringBytes.Add(b); + offset += 1; + } + return Encoding.UTF8.GetString(stringBytes.ToArray()); + } + + private static void WriteString(IntPtr dst, string s, bool finalise = false) { + byte[] bytes = Encoding.UTF8.GetBytes(s); + Marshal.Copy(bytes, 0, dst, bytes.Length); + if (finalise) { + Marshal.WriteByte(dst + bytes.Length, 0); + } + } + } +} diff --git a/GoodMemory/Properties/AssemblyInfo.cs b/GoodMemory/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..dfd2919 --- /dev/null +++ b/GoodMemory/Properties/AssemblyInfo.cs @@ -0,0 +1,38 @@ +using System.Resources; +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("GoodMemory")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GoodMemory")] +[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("2b53daae-5f20-4eaf-8bc5-97fce68c1738")] + +// 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")] +[assembly: NeutralResourcesLanguage("en-GB")]