chore: initial commit

This commit is contained in:
Anna 2021-06-02 21:09:49 -04:00
commit 8654578777
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
10 changed files with 807 additions and 0 deletions

365
.gitignore vendored Normal file
View File

@ -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

16
TheGreatSeparator.sln Executable file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheGreatSeparator", "TheGreatSeparator\TheGreatSeparator.csproj", "{74A81195-9EEA-4C75-94BD-5B9A5D1D2BB9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{74A81195-9EEA-4C75-94BD-5B9A5D1D2BB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74A81195-9EEA-4C75-94BD-5B9A5D1D2BB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74A81195-9EEA-4C75-94BD-5B9A5D1D2BB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74A81195-9EEA-4C75-94BD-5B9A5D1D2BB9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

24
TheGreatSeparator/Commands.cs Executable file
View File

@ -0,0 +1,24 @@
using System;
using Dalamud.Game.Command;
namespace TheGreatSeparator {
public class Commands : IDisposable {
private TheGreatSeparator Plugin { get; }
internal Commands(TheGreatSeparator plugin) {
this.Plugin = plugin;
this.Plugin.Interface.CommandManager.AddHandler("/tgs", new CommandInfo(this.OnCommand) {
HelpMessage = "Open The Great Separator",
});
}
public void Dispose() {
this.Plugin.Interface.CommandManager.RemoveHandler("/tgs");
}
private void OnCommand(string command, string args) {
this.Plugin.Ui.Toggle();
}
}
}

View File

@ -0,0 +1,24 @@
using Dalamud.Configuration;
using Dalamud.Plugin;
namespace TheGreatSeparator {
public class Configuration : IPluginConfiguration {
private DalamudPluginInterface Interface { get; set; } = null!;
public int Version { get; set; } = 1;
public bool FlyText = true;
public bool AbilityCost;
public bool AbilityTooltip;
public bool PartyList = true;
public char? CustomSeparator;
internal void Initialise(DalamudPluginInterface @interface) {
this.Interface = @interface;
}
internal void Save() {
this.Interface.SavePluginConfig(this);
}
}
}

27
TheGreatSeparator/Extensions.cs Executable file
View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using Dalamud.Game;
namespace TheGreatSeparator {
internal static class Extensions {
internal static bool TryScanText(this SigScanner scanner, string sig, out IntPtr result) {
result = IntPtr.Zero;
try {
result = scanner.ScanText(sig);
return true;
} catch (KeyNotFoundException) {
return false;
}
}
internal static bool TryGetStaticAddressFromSig(this SigScanner scanner, string sig, out IntPtr result) {
result = IntPtr.Zero;
try {
result = scanner.GetStaticAddressFromSig(sig);
return true;
} catch (KeyNotFoundException) {
return false;
}
}
}
}

17
TheGreatSeparator/Plugin.cs Executable file
View File

@ -0,0 +1,17 @@
using Dalamud.Plugin;
namespace TheGreatSeparator {
public class Plugin : IDalamudPlugin {
public string Name => "The Great Separator";
private TheGreatSeparator? Separator { get; set; }
public void Initialize(DalamudPluginInterface pluginInterface) {
this.Separator = new TheGreatSeparator(pluginInterface);
}
public void Dispose() {
this.Separator?.Dispose();
}
}
}

57
TheGreatSeparator/PluginUi.cs Executable file
View File

@ -0,0 +1,57 @@
using System;
using ImGuiNET;
namespace TheGreatSeparator {
internal class PluginUi : IDisposable {
private TheGreatSeparator Plugin { get; }
private bool _showWindow;
internal PluginUi(TheGreatSeparator plugin) {
this.Plugin = plugin;
this.Plugin.Interface.UiBuilder.OnBuildUi += this.Draw;
this.Plugin.Interface.UiBuilder.OnOpenConfigUi += this.Toggle;
}
public void Dispose() {
this.Plugin.Interface.UiBuilder.OnOpenConfigUi -= this.Toggle;
this.Plugin.Interface.UiBuilder.OnBuildUi -= this.Draw;
}
internal void Toggle(object? sender = null, object? args = null) {
this._showWindow = !this._showWindow;
}
private void Draw() {
if (!this._showWindow) {
return;
}
if (!ImGui.Begin("The Great Separator", ref this._showWindow)) {
ImGui.End();
return;
}
var save = false;
save |= ImGui.Checkbox("Add separators to damage/healing numbers", ref this.Plugin.Config.FlyText);
save |= ImGui.Checkbox("Add separators to party list HP", ref this.Plugin.Config.PartyList);
save |= ImGui.Checkbox("Add separators to ability costs on hotbars", ref this.Plugin.Config.AbilityCost);
save |= ImGui.Checkbox("Add separators to ability costs in tooltips", ref this.Plugin.Config.AbilityTooltip);
var custom = this.Plugin.Config.CustomSeparator?.ToString() ?? string.Empty;
if (ImGui.InputText("Custom separator", ref custom, 1)) {
save = true;
this.Plugin.Config.CustomSeparator = string.IsNullOrEmpty(custom) ? null : custom[0];
this.Plugin.SetSeparator(this.Plugin.Config.CustomSeparator);
}
if (save) {
this.Plugin.Config.Save();
this.Plugin.ConfigureInstructions();
}
ImGui.End();
}
}
}

View File

@ -0,0 +1,238 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Dalamud;
using Dalamud.Hooking;
using Dalamud.Plugin;
using FFXIVClientStructs.FFXIV.Component.GUI;
namespace TheGreatSeparator {
public class TheGreatSeparator : IDisposable {
private static class Signatures {
internal const string ShowFlyText = "E8 ?? ?? ?? ?? FF C7 41 D1 C7";
internal const string SprintfNumber = "48 83 EC 28 44 8B C9";
internal const string FlyTextStringify = "45 33 C0 C6 44 24 ?? ?? 41 8B D6 E8 ?? ?? ?? ??";
internal const string HotbarManaStringify = "45 33 C0 48 8B CE C6 44 24 ?? ?? 42 8B 14 38 E8 ?? ?? ?? ??";
internal const string PartyListStringify = "45 33 C0 C6 44 24 ?? ?? 8B D5 E8 ?? ?? ?? ?? EB";
internal const string Separator = "44 0F B6 05 ?? ?? ?? ?? 45 84 C0 74 36 F6 87 ?? ?? ?? ?? ??";
}
private static readonly byte[] ThirdArgOne = {
0x41, 0xB0, 0x01,
};
private delegate void ShowFlyTextDelegate(IntPtr addon, uint actorIndex, uint messageMax, IntPtr numbers, int offsetNum, int offsetNumMax, IntPtr strings, int offsetStr, int offsetStrMax, int a10);
private Hook<ShowFlyTextDelegate>? ShowFlyTextHook { get; }
private delegate IntPtr SprintfNumberDelegate(uint number);
private Hook<SprintfNumberDelegate>? SprintfNumberHook { get; }
internal DalamudPluginInterface Interface { get; }
internal Configuration Config { get; }
internal PluginUi Ui { get; }
private Commands Commands { get; }
private Dictionary<IntPtr, byte[]> OldBytes { get; } = new();
private byte OriginalSeparator { get; }
private IntPtr SeparatorPtr { get; } = IntPtr.Zero;
internal TheGreatSeparator(DalamudPluginInterface @interface) {
this.Interface = @interface;
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
this.Config.Initialise(this.Interface);
this.ConfigureInstructions();
this.Ui = new PluginUi(this);
this.Commands = new Commands(this);
if (this.Interface.TargetModuleScanner.TryScanText(Signatures.ShowFlyText, out var showFlyPtr)) {
this.ShowFlyTextHook = new Hook<ShowFlyTextDelegate>(showFlyPtr + 9, new ShowFlyTextDelegate(this.ShowFlyTextDetour));
this.ShowFlyTextHook.Enable();
}
if (this.Interface.TargetModuleScanner.TryScanText(Signatures.SprintfNumber, out var sprintfPtr)) {
this.SprintfNumberHook = new Hook<SprintfNumberDelegate>(sprintfPtr, new SprintfNumberDelegate(this.SprintfNumberDetour));
this.SprintfNumberHook.Enable();
}
if (this.Interface.TargetModuleScanner.TryGetStaticAddressFromSig(Signatures.Separator, out var separatorPtr)) {
this.SeparatorPtr = separatorPtr;
this.OriginalSeparator = Marshal.ReadByte(this.SeparatorPtr);
}
this.SetSeparator(this.Config.CustomSeparator);
}
public void Dispose() {
this.SprintfNumberHook?.Dispose();
this.ShowFlyTextHook?.Dispose();
this.RestoreAllBytes();
this.Commands.Dispose();
this.Ui.Dispose();
if (this.SeparatorPtr != IntPtr.Zero && this.OriginalSeparator != 0) {
Marshal.WriteByte(this.SeparatorPtr, this.OriginalSeparator);
}
}
internal void SetSeparator(char? sep) {
if (this.SeparatorPtr == IntPtr.Zero) {
return;
}
var separator = (byte?) sep ?? this.OriginalSeparator;
if (separator == 0) {
separator = (byte) ',';
}
Marshal.WriteByte(this.SeparatorPtr, separator);
}
internal void ConfigureInstructions() {
this.ConfigureInstruction(Signatures.FlyTextStringify, this.Config.FlyText);
this.ConfigureInstruction(Signatures.HotbarManaStringify, this.Config.AbilityCost);
this.ConfigureInstruction(Signatures.PartyListStringify, this.Config.PartyList);
}
private void ConfigureInstruction(string sig, bool enabled) {
if (!this.Interface.TargetModuleScanner.TryScanText(sig, out var ptr)) {
return;
}
if (enabled) {
this.ReplaceBytes(ptr);
} else {
this.RestoreBytes(ptr);
}
}
private void ReplaceBytes(IntPtr ptr) {
if (this.OldBytes.ContainsKey(ptr)) {
return;
}
SafeMemory.ReadBytes(ptr, ThirdArgOne.Length, out var oldBytes);
SafeMemory.WriteBytes(ptr, ThirdArgOne);
this.OldBytes[ptr] = oldBytes;
}
private void RestoreBytes(IntPtr ptr) {
if (!this.OldBytes.TryGetValue(ptr, out var oldBytes)) {
return;
}
SafeMemory.WriteBytes(ptr, oldBytes);
this.OldBytes.Remove(ptr);
}
private void RestoreAllBytes() {
foreach (var ptr in this.OldBytes.Keys.ToList()) {
this.RestoreBytes(ptr);
}
}
private unsafe IntPtr SprintfNumberDetour(uint number) {
var ret = (byte*) this.SprintfNumberHook!.Original(number);
if (!this.Config.AbilityTooltip) {
goto Return;
}
var nfi = (NumberFormatInfo) NumberFormatInfo.CurrentInfo.Clone();
if (this.Config.CustomSeparator != null) {
nfi.NumberGroupSeparator = this.Config.CustomSeparator.ToString();
}
var str = number.ToString("N0", nfi);
var strBytes = Encoding.UTF8.GetBytes(str);
fixed (byte* bytesPtr = strBytes) {
Buffer.MemoryCopy(bytesPtr, ret, 0x40, strBytes.Length);
}
*(ret + strBytes.Length) = 0;
Return:
return (IntPtr) ret;
}
private unsafe void ShowFlyTextDetour(IntPtr addon, uint actorIndex, uint messageMax, IntPtr numbers, int offsetNum, int offsetNumMax, IntPtr strings, int offsetStr, int offsetStrMax, int a10) {
this.ShowFlyTextHook!.Original(addon, actorIndex, messageMax, numbers, offsetNum, offsetNumMax, strings, offsetStr, offsetStrMax, a10);
if (!this.Config.FlyText) {
return;
}
static void Action(IntPtr ptr) {
// only check text nodes
var node = (AtkResNode*) ptr;
if (node->Type != NodeType.Text) {
return;
}
var text = (AtkTextNode*) node;
var font = (text->AlignmentFontType & 0xF0) >> 4;
// only touch text nodes with a font above four and less than eight
if (font is not (> 4 and < 8)) {
return;
}
// only touch text nodes with a string starting with a digit
var stringPtr = text->NodeText.StringPtr;
if (stringPtr == null || !char.IsDigit((char) *stringPtr)) {
return;
}
// set the font type of the node to 4 for non-number support
text->AlignmentFontType = (byte) ((text->AlignmentFontType & 0xF) | (4 << 4));
}
var unit = (AtkUnitBase*) addon;
if (unit->RootNode != null) {
this.TraverseNodes(unit->RootNode, Action);
}
for (var i = 0; i < unit->UldManager.NodeListCount; i++) {
var node = unit->UldManager.NodeList[i];
this.TraverseNodes(node, Action);
}
}
private unsafe void TraverseNodes(AtkResNode* node, Action<IntPtr> action, bool siblings = true) {
if (node == null) {
return;
}
action((IntPtr) node);
if ((int) node->Type < 1000) {
this.TraverseNodes(node->ChildNode, action);
} else {
var comp = (AtkComponentNode*) node;
for (var i = 0; i < comp->Component->UldManager.NodeListCount; i++) {
this.TraverseNodes(comp->Component->UldManager.NodeList[i], action);
}
}
if (!siblings) {
return;
}
var prev = node;
while ((prev = prev->PrevSiblingNode) != null) {
this.TraverseNodes(prev, action, false);
}
var next = node;
while ((next = next->NextSiblingNode) != null) {
this.TraverseNodes(next, action, false);
}
}
}
}

View File

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<Version>1.2.0</Version>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dalamud">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Dalamud.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="FFXIVClientStructs">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\FFXIVClientStructs.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGui.NET">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\ImGui.NET.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGuiScene">
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\ImGuiScene.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="1.2.1"/>
</ItemGroup>
</Project>

View File

@ -0,0 +1,9 @@
name: The Great Separator
author: ascclemens
description: |-
Add separators to various numbers.
- Damage/healing numbers (not DoTs or other players' numbers)
- Party list HP
- Ability costs on hotbars
- Ability costs in tooltips