commit d3ee9cc07c35596b79f97bdc7110b2a9adfcb277 Author: Anna Clemens Date: Tue Apr 6 04:41:38 2021 -0400 chore: initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1db30bf --- /dev/null +++ b/.gitignore @@ -0,0 +1,365 @@ +## 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 + +# Packaging +pack/ + +# 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/XivCommon.sln b/XivCommon.sln new file mode 100755 index 0000000..8b22c09 --- /dev/null +++ b/XivCommon.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XivCommon", "XivCommon\XivCommon.csproj", "{83659925-02EA-468D-9C61-DFA657BD27CF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {83659925-02EA-468D-9C61-DFA657BD27CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {83659925-02EA-468D-9C61-DFA657BD27CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83659925-02EA-468D-9C61-DFA657BD27CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {83659925-02EA-468D-9C61-DFA657BD27CF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/XivCommon/Functions/Chat.cs b/XivCommon/Functions/Chat.cs new file mode 100755 index 0000000..bc6b945 --- /dev/null +++ b/XivCommon/Functions/Chat.cs @@ -0,0 +1,66 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; +using System.Text; +using Dalamud.Game; + +namespace XivCommon.Functions { + public class Chat { + private GameFunctions Functions { get; } + + private delegate void ProcessChatBoxDelegate(IntPtr uiModule, IntPtr message, IntPtr unused, byte a4); + + private ProcessChatBoxDelegate ProcessChatBox { get; } + + internal Chat(GameFunctions functions, SigScanner scanner) { + this.Functions = functions; + + var processChatBoxPtr = scanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 45 84 C9"); + this.ProcessChatBox = Marshal.GetDelegateForFunctionPointer(processChatBoxPtr); + } + + public void SendMessage(string message) { + var uiModule = this.Functions.GetUiModule(); + + using var payload = new ChatPayload(message); + var mem1 = Marshal.AllocHGlobal(400); + Marshal.StructureToPtr(payload, mem1, false); + + this.ProcessChatBox(uiModule, mem1, IntPtr.Zero, 0); + + Marshal.FreeHGlobal(mem1); + } + + [StructLayout(LayoutKind.Explicit)] + [SuppressMessage("ReSharper", "PrivateFieldCanBeConvertedToLocalVariable")] + private readonly struct ChatPayload : IDisposable { + [FieldOffset(0)] + private readonly IntPtr textPtr; + + [FieldOffset(16)] + private readonly ulong textLen; + + [FieldOffset(8)] + private readonly ulong unk1; + + [FieldOffset(24)] + private readonly ulong unk2; + + internal ChatPayload(string text) { + var stringBytes = Encoding.UTF8.GetBytes(text); + this.textPtr = Marshal.AllocHGlobal(stringBytes.Length + 30); + Marshal.Copy(stringBytes, 0, this.textPtr, stringBytes.Length); + Marshal.WriteByte(this.textPtr + stringBytes.Length, 0); + + this.textLen = (ulong) (stringBytes.Length + 1); + + this.unk1 = 64; + this.unk2 = 0; + } + + public void Dispose() { + Marshal.FreeHGlobal(this.textPtr); + } + } + } +} diff --git a/XivCommon/Functions/PartyFinder.cs b/XivCommon/Functions/PartyFinder.cs new file mode 100755 index 0000000..7c34bb2 --- /dev/null +++ b/XivCommon/Functions/PartyFinder.cs @@ -0,0 +1,45 @@ +using System; +using System.Runtime.InteropServices; +using Dalamud.Game; +using Dalamud.Game.Internal.Gui; +using Dalamud.Hooking; + +namespace XivCommon.Functions { + public class PartyFinder : IDisposable { + private delegate byte RequestPartyFinderListingsDelegate(IntPtr agent, byte categoryIdx); + + private RequestPartyFinderListingsDelegate RequestPartyFinderListings { get; } + private Hook RequestPfListingsHook { get; } + + private IntPtr PartyFinderAgent { get; set; } = IntPtr.Zero; + + internal PartyFinder(SigScanner scanner) { + var requestPfPtr = scanner.ScanText("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 40 0F 10 81 ?? ?? ?? ??"); + + this.RequestPartyFinderListings = Marshal.GetDelegateForFunctionPointer(requestPfPtr); + this.RequestPfListingsHook = new Hook(requestPfPtr, new RequestPartyFinderListingsDelegate(this.OnRequestPartyFinderListings)); + this.RequestPfListingsHook.Enable(); + } + + public void Dispose() { + this.RequestPfListingsHook.Dispose(); + } + + private byte OnRequestPartyFinderListings(IntPtr agent, byte categoryIdx) { + this.PartyFinderAgent = agent; + return this.RequestPfListingsHook.Original(agent, categoryIdx); + } + + public void RefreshListings() { + // Updated 5.41 + const int categoryOffset = 10_655; + + if (this.PartyFinderAgent == IntPtr.Zero) { + return; + } + + var categoryIdx = Marshal.ReadByte(this.PartyFinderAgent + categoryOffset); + this.RequestPartyFinderListings(this.PartyFinderAgent, categoryIdx); + } + } +} diff --git a/XivCommon/Functions/Toast.cs b/XivCommon/Functions/Toast.cs new file mode 100755 index 0000000..e30aa65 --- /dev/null +++ b/XivCommon/Functions/Toast.cs @@ -0,0 +1,40 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; +using Dalamud.Game; +using Dalamud.Game.Text.SeStringHandling; + +namespace XivCommon.Functions { + public class Toast { + private GameFunctions Functions { get; } + + private delegate IntPtr ShowToastDelegate(IntPtr manager, IntPtr text, int layer, byte bool1, byte bool2, int logMessageId); + + private ShowToastDelegate ShowToast { get; } + + internal Toast(GameFunctions functions, SigScanner scanner) { + this.Functions = functions; + + var showToast = scanner.ScanText("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC 30 83 3D ?? ?? ?? ?? ??"); + this.ShowToast = Marshal.GetDelegateForFunctionPointer(showToast); + } + + public void Show(string message) { + this.Show(Encoding.UTF8.GetBytes(message)); + } + + public void Show(SeString message) { + this.Show(message.Encode()); + } + + private void Show(byte[] bytes) { + var manager = this.Functions.GetUiModule(); + + unsafe { + fixed (byte* ptr = bytes) { + this.ShowToast(manager, (IntPtr) ptr, 5, 0, 1, 0); + } + } + } + } +} diff --git a/XivCommon/GameFunctions.cs b/XivCommon/GameFunctions.cs new file mode 100755 index 0000000..e599f3a --- /dev/null +++ b/XivCommon/GameFunctions.cs @@ -0,0 +1,37 @@ +using System; +using System.Runtime.InteropServices; +using Dalamud.Game; +using XivCommon.Functions; + +namespace XivCommon { + public class GameFunctions : IDisposable { + private IntPtr UiModulePtr { get; } + + private delegate IntPtr GetUiModuleDelegate(IntPtr basePtr); + + private GetUiModuleDelegate InternalGetUiModule { get; } + + public Toast Toast { get; } + public Chat Chat { get; } + public PartyFinder PartyFinder { get; } + + internal GameFunctions(SigScanner scanner) { + this.UiModulePtr = scanner.GetStaticAddressFromSig("48 8B 0D ?? ?? ?? ?? 48 8D 54 24 ?? 48 83 C1 10 E8 ?? ?? ?? ??"); + + var getUiModulePtr = scanner.ScanText("E8 ?? ?? ?? ?? 83 3B 01"); + this.InternalGetUiModule = Marshal.GetDelegateForFunctionPointer(getUiModulePtr); + + this.Toast = new Toast(this, scanner); + this.Chat = new Chat(this, scanner); + this.PartyFinder = new PartyFinder(scanner); + } + + public void Dispose() { + this.PartyFinder.Dispose(); + } + + public IntPtr GetUiModule() { + return this.InternalGetUiModule(Marshal.ReadIntPtr(this.UiModulePtr)); + } + } +} diff --git a/XivCommon/XivCommon.csproj b/XivCommon/XivCommon.csproj new file mode 100755 index 0000000..1bf0e59 --- /dev/null +++ b/XivCommon/XivCommon.csproj @@ -0,0 +1,17 @@ + + + + net48 + latest + true + enable + + + + + $(AppData)\XIVLauncher\addon\Hooks\dev\Dalamud.dll + False + + + + diff --git a/XivCommon/XivCommonBase.cs b/XivCommon/XivCommonBase.cs new file mode 100755 index 0000000..0d75641 --- /dev/null +++ b/XivCommon/XivCommonBase.cs @@ -0,0 +1,16 @@ +using System; +using Dalamud.Game; + +namespace XivCommon { + public class XivCommonBase : IDisposable { + public GameFunctions Functions { get; } + + public XivCommonBase(SigScanner scanner) { + this.Functions = new GameFunctions(scanner); + } + + public void Dispose() { + this.Functions.Dispose(); + } + } +}