feat: start adding appearance obscurer

This commit is contained in:
Anna 2022-05-09 21:57:31 -04:00
parent 579fd63331
commit a3ae2629ef
11 changed files with 1018 additions and 773 deletions

View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Logging;
using Lumina.Excel.GeneratedSheets;
namespace NominaOcculta;
internal class AppearanceRepository {
private Plugin Plugin { get; }
private List<ENpcBase> Npcs { get; }
private int Salt { get; } = new Random().Next();
private static readonly string[] Exclude = {
"Thancred",
"Y'shtola",
"Alphinaud",
"Alisaie",
"Urianger",
"Tataru",
"Minfilia",
"Lyse",
"Yda",
"Papalymo",
"Krile",
"Ryne",
"Estinien",
"Nanamo Ul Namo",
"G'raha Tia",
"Raubahn",
"Cid",
"Biggs",
"Wedge",
"Haurchefant",
"Merlwyb",
"Kan-E-Senna",
"Yugiri",
"Aymeric",
"Lahabrea",
"Igeyorhm",
"Hildibrand",
"Godbert",
};
internal AppearanceRepository(Plugin plugin) {
this.Plugin = plugin;
var names = this.Plugin.DataManager.GetExcelSheet<ENpcResident>()!;
this.Npcs = this.Plugin.DataManager.GetExcelSheet<ENpcBase>()!
.Where(row => row.BodyType == 1)
.Where(row => row.ModelChara.Row == 0)
.Where(row => row.ModelBody != 0)
.Where(row => row.ModelLegs != 0)
.Where(row => !Exclude.Contains(names.GetRow(row.RowId)?.Singular.RawString))
.ToList();
PluginLog.Log($"npcs: {this.Npcs.Count}");
}
private int GetNpcIndex(uint objectId) {
return new Random((int) (objectId + this.Salt)).Next(0, this.Npcs.Count);
}
internal ENpcBase GetNpc(uint objectId) {
return this.Npcs[this.GetNpcIndex(objectId)];
}
}

View File

@ -1,8 +1,9 @@
using System;
using Dalamud.Game.Command;
namespace NominaOcculta {
internal class Commands : IDisposable {
namespace NominaOcculta;
internal class Commands : IDisposable {
private Plugin Plugin { get; }
internal Commands(Plugin plugin) {
@ -92,5 +93,4 @@ namespace NominaOcculta {
this.Plugin.SaveConfig();
}
}
}

View File

@ -1,9 +1,10 @@
using System;
using Dalamud.Configuration;
namespace NominaOcculta {
[Serializable]
internal class Configuration : IPluginConfiguration {
namespace NominaOcculta;
[Serializable]
internal class Configuration : IPluginConfiguration {
public int Version { get; set; } = 1;
public bool Enabled;
@ -13,5 +14,4 @@ namespace NominaOcculta {
public bool Party;
public bool Others;
public bool ExcludeFriends;
}
}

10
NominaOcculta/EquipData.cs Executable file
View File

@ -0,0 +1,10 @@
using System.Runtime.InteropServices;
namespace NominaOcculta;
[StructLayout(LayoutKind.Sequential)]
internal struct EquipData {
internal ushort Model;
internal byte Variant;
internal byte Dye;
}

View File

@ -2,17 +2,23 @@
using System.Runtime.InteropServices;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Hooking;
using Dalamud.Logging;
using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using Siggingway;
namespace NominaOcculta {
internal class GameFunctions : IDisposable {
namespace NominaOcculta;
internal class GameFunctions : IDisposable {
private static class Signatures {
internal const string GenerateName = "E8 ?? ?? ?? ?? 48 8D 8B ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 85 C0 74 1B 48 8D 8B ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8B 8B ?? ?? ?? ?? 48 8B D0 E8 ?? ?? ?? ?? 48 8B CB 48 8B 7C 24";
internal const string Utf8StringCtor = "E8 ?? ?? ?? ?? 44 2B F7";
internal const string Utf8StringDtor = "80 79 21 00 75 12";
internal const string AtkTextNodeSetText = "E8 ?? ?? ?? ?? 8D 4E 32";
internal const string LoadExd = "40 53 56 57 48 81 EC ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 ?? ?? ?? ?? 41 0F B6 D9";
internal const string CharacterInitialise = "48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC 30 48 8B F9 48 8B EA 48 81 C1 ?? ?? ?? ?? E8";
internal const string CharacterIsMount = "40 53 48 83 EC 20 48 8B 01 48 8B D9 FF 50 10 83 F8 08 75 08";
internal const string FlagSlotUpdate = "48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 8B DA 49 8B F0 48 8B F9 83 FA 0A";
}
#region Delegates
@ -29,6 +35,12 @@ namespace NominaOcculta {
private delegate IntPtr GetExcelModuleDelegate(IntPtr uiModule);
private delegate IntPtr CharacterIsMountDelegate(IntPtr actor);
private delegate char CharacterInitialiseDelegate(IntPtr actorPtr, IntPtr customizeDataPtr);
private delegate IntPtr FlagSlotUpdateDelegate(IntPtr actorPtr, uint slot, IntPtr equipData);
#endregion
#region Functions
@ -50,10 +62,31 @@ namespace NominaOcculta {
[Signature(Signatures.AtkTextNodeSetText, DetourName = nameof(AtkTextNodeSetTextDetour))]
private Hook<AtkTextNodeSetTextDelegate> AtkTextNodeSetTextHook { get; init; } = null!;
[Signature(Signatures.CharacterIsMount, DetourName = nameof(CharacterIsMountDetour))]
private Hook<CharacterIsMountDelegate> CharacterIsMountHook { get; init; } = null!;
[Signature(Signatures.CharacterInitialise, DetourName = nameof(CharacterInitialiseDetour))]
private Hook<CharacterInitialiseDelegate> CharacterInitializeHook { get; init; } = null!;
[Signature(Signatures.FlagSlotUpdate, DetourName = nameof(FlagSlotUpdateDetour))]
private Hook<FlagSlotUpdateDelegate> FlagSlotUpdateHook { get; init; } = null!;
#region Events
internal delegate void AtkTextNodeSetTextEventDelegate(IntPtr node, IntPtr text, ref SeString? overwrite);
internal event AtkTextNodeSetTextEventDelegate? AtkTextNodeSetText;
internal unsafe delegate void CharacterInitialiseEventDelegate(GameObject* gameObj, IntPtr humanPtr, IntPtr customiseDataPtr);
internal event CharacterInitialiseEventDelegate? CharacterInitialise;
internal unsafe delegate void FlagSlotUpdateEventDelegate(GameObject* gameObj, uint slot, EquipData* equipData);
internal event FlagSlotUpdateEventDelegate? FlagSlotUpdate;
#endregion
private Plugin Plugin { get; }
private IntPtr First { get; }
@ -62,9 +95,12 @@ namespace NominaOcculta {
internal GameFunctions(Plugin plugin) {
this.Plugin = plugin;
Siggingway.Siggingway.Initialise(this.Plugin.SigScanner, this);
SignatureHelper.Initialise(this);
this.AtkTextNodeSetTextHook.Enable();
this.CharacterInitializeHook.Enable();
this.CharacterIsMountHook.Enable();
this.FlagSlotUpdateHook.Enable();
this.First = Marshal.AllocHGlobal(128);
this.Last = Marshal.AllocHGlobal(128);
@ -79,6 +115,9 @@ namespace NominaOcculta {
Marshal.FreeHGlobal(this.Last);
Marshal.FreeHGlobal(this.First);
this.AtkTextNodeSetTextHook.Dispose();
this.CharacterInitializeHook.Dispose();
this.CharacterIsMountHook.Dispose();
this.FlagSlotUpdateHook.Dispose();
}
private unsafe void AtkTextNodeSetTextDetour(IntPtr node, IntPtr text) {
@ -96,6 +135,43 @@ namespace NominaOcculta {
this.AtkTextNodeSetTextHook.Original(node, text);
}
private IntPtr _lastActor = IntPtr.Zero;
private unsafe IntPtr CharacterIsMountDetour(IntPtr characterPtr) {
var chara = (GameObject*) characterPtr;
if (chara != null && chara->ObjectKind == (byte) ObjectKind.Pc) {
this._lastActor = characterPtr;
} else {
this._lastActor = IntPtr.Zero;
}
return this.CharacterIsMountHook.Original(characterPtr);
}
private unsafe char CharacterInitialiseDetour(IntPtr actorPtr, IntPtr customizeDataPtr) {
if (this._lastActor != IntPtr.Zero) {
try {
this.CharacterInitialise?.Invoke((GameObject*) this._lastActor, actorPtr, customizeDataPtr);
} catch (Exception e) {
PluginLog.LogError(e, "yeet");
}
}
return this.CharacterInitializeHook.Original(actorPtr, customizeDataPtr);
}
private unsafe IntPtr FlagSlotUpdateDetour(IntPtr actorPtr, uint slot, IntPtr equipDataPtr) {
if (this._lastActor != IntPtr.Zero) {
try {
this.FlagSlotUpdate?.Invoke((GameObject*) this._lastActor, slot, (EquipData*) equipDataPtr);
} catch (Exception e) {
PluginLog.LogError(e, "yeet2");
}
}
return this.FlagSlotUpdateHook.Original(actorPtr, slot, equipDataPtr);
}
public string? GenerateName(int race, int clan, int gender) {
if (this.InternalGenerateName(race, clan, gender, this.First, this.Last) == IntPtr.Zero) {
return null;
@ -121,5 +197,4 @@ namespace NominaOcculta {
this.LoadExd(excel, name, 0, 1);
}
}
}

View File

@ -5,8 +5,9 @@ using System.Linq;
using Dalamud.Game;
using Lumina.Excel.GeneratedSheets;
namespace NominaOcculta {
internal class NameRepository : IDisposable {
namespace NominaOcculta;
internal class NameRepository : IDisposable {
private Plugin Plugin { get; }
private Random Rng { get; } = new();
@ -156,5 +157,4 @@ namespace NominaOcculta {
internal void Reset() {
this.Replacements.Clear();
}
}
}

View File

@ -8,6 +8,8 @@
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup>
@ -42,10 +44,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DalamudLinter" Version="1.0.3"/>
<PackageReference Include="DalamudPackager" Version="2.1.5"/>
<PackageReference Include="Siggingway" Version="1.1.0"/>
<PackageReference Include="XivCommon" Version="4.0.0"/>
<PackageReference Include="DalamudLinter" Version="1.0.3" />
<PackageReference Include="DalamudPackager" Version="2.1.7" />
<PackageReference Include="XivCommon" Version="5.0.1-alpha.1" />
</ItemGroup>
</Project>

View File

@ -8,16 +8,19 @@ using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Logging;
using XivCommon.Functions.NamePlates;
using GameObject = FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject;
namespace NominaOcculta {
internal class Obscurer : IDisposable {
namespace NominaOcculta;
internal class Obscurer : IDisposable {
private Plugin Plugin { get; }
private Stopwatch UpdateTimer { get; } = new();
private IList<string> Friends { get; set; }
internal Obscurer(Plugin plugin) {
internal unsafe Obscurer(Plugin plugin) {
this.Plugin = plugin;
this.UpdateTimer.Start();
@ -28,14 +31,18 @@ namespace NominaOcculta {
this.Plugin.Framework.Update += this.OnFrameworkUpdate;
this.Plugin.Functions.AtkTextNodeSetText += this.OnAtkTextNodeSetText;
this.Plugin.Functions.CharacterInitialise += this.OnCharacterInitialise;
this.Plugin.Functions.FlagSlotUpdate += this.OnFlagSlotUpdate;
this.Plugin.Common.Functions.NamePlates.OnUpdate += this.OnNamePlateUpdate;
this.Plugin.ChatGui.ChatMessage += this.OnChatMessage;
}
public void Dispose() {
public unsafe void Dispose() {
this.Plugin.ChatGui.ChatMessage -= this.OnChatMessage;
this.Plugin.Common.Functions.NamePlates.OnUpdate -= this.OnNamePlateUpdate;
this.Plugin.Functions.AtkTextNodeSetText -= this.OnAtkTextNodeSetText;
this.Plugin.Functions.CharacterInitialise -= this.OnCharacterInitialise;
this.Plugin.Functions.FlagSlotUpdate -= this.OnFlagSlotUpdate;
this.Plugin.Framework.Update -= this.OnFrameworkUpdate;
}
@ -72,6 +79,83 @@ namespace NominaOcculta {
}
}
private unsafe void OnCharacterInitialise(GameObject* gameObj, IntPtr humanPtr, IntPtr customiseDataPtr) {
var npc = this.Plugin.AppearanceRepository.GetNpc(gameObj->ObjectID);
var customise = (byte*) customiseDataPtr;
customise[(int) CustomizeIndex.Race] = (byte) npc.Race.Row;
customise[(int) CustomizeIndex.Gender] = npc.Gender;
customise[(int) CustomizeIndex.ModelType] = npc.BodyType;
customise[(int) CustomizeIndex.Height] = npc.Height;
customise[(int) CustomizeIndex.Tribe] = (byte) npc.Tribe.Row;
customise[(int) CustomizeIndex.FaceType] = npc.Face;
customise[(int) CustomizeIndex.HairStyle] = npc.HairStyle;
customise[(int) CustomizeIndex.HasHighlights] = npc.HairHighlight;
customise[(int) CustomizeIndex.SkinColor] = npc.SkinColor;
customise[(int) CustomizeIndex.EyeColor] = npc.EyeColor;
customise[(int) CustomizeIndex.HairColor] = npc.HairColor;
customise[(int) CustomizeIndex.HairColor2] = npc.HairHighlightColor;
customise[(int) CustomizeIndex.FaceFeatures] = npc.FacialFeature;
customise[(int) CustomizeIndex.FaceFeaturesColor] = npc.FacialFeatureColor;
customise[(int) CustomizeIndex.Eyebrows] = npc.Eyebrows;
customise[(int) CustomizeIndex.EyeColor2] = npc.EyeHeterochromia;
customise[(int) CustomizeIndex.EyeShape] = npc.EyeShape;
customise[(int) CustomizeIndex.NoseShape] = npc.Nose;
customise[(int) CustomizeIndex.JawShape] = npc.Jaw;
customise[(int) CustomizeIndex.LipStyle] = npc.Mouth;
customise[(int) CustomizeIndex.LipColor] = npc.LipColor;
customise[(int) CustomizeIndex.RaceFeatureSize] = npc.BustOrTone1;
customise[(int) CustomizeIndex.RaceFeatureType] = npc.ExtraFeature1;
customise[(int) CustomizeIndex.BustSize] = npc.ExtraFeature2OrBust;
customise[(int) CustomizeIndex.Facepaint] = npc.FacePaint;
customise[(int) CustomizeIndex.FacepaintColor] = npc.FacePaintColor;
}
private enum PlateSlot : uint {
Head = 0,
Body = 1,
Hands = 2,
Legs = 3,
Feet = 4,
Ears = 5,
Neck = 6,
Wrists = 7,
RightRing = 8,
LeftRing = 9,
MainHand = 10,
OffHand = 11,
}
private unsafe void OnFlagSlotUpdate(GameObject* gameObj, uint slot, EquipData* equipData) {
if (equipData == null) {
return;
}
var npc = this.Plugin.AppearanceRepository.GetNpc(gameObj->ObjectID);
var itemSlot = (PlateSlot) slot;
var info = itemSlot switch {
PlateSlot.Head => (npc.ModelHead, npc.DyeHead.Row),
PlateSlot.Body => (npc.ModelBody, npc.DyeBody.Row),
PlateSlot.Hands => (npc.ModelHands, npc.DyeHands.Row),
PlateSlot.Legs => (npc.ModelLegs, npc.DyeLegs.Row),
PlateSlot.Feet => (npc.ModelFeet, npc.DyeFeet.Row),
PlateSlot.Ears => (npc.ModelEars, npc.DyeEars.Row),
PlateSlot.Neck => (npc.ModelNeck, npc.DyeNeck.Row),
PlateSlot.Wrists => (npc.ModelWrists, npc.DyeWrists.Row),
PlateSlot.RightRing => (npc.ModelRightRing, npc.DyeRightRing.Row),
PlateSlot.LeftRing => (npc.ModelLeftRing, npc.DyeLeftRing.Row),
_ => (uint.MaxValue, uint.MaxValue),
};
if (info.Item1 == uint.MaxValue) {
return;
}
equipData->Model = (ushort) (info.Item1 & 0xFFFF);
equipData->Variant = (byte) ((info.Item1 >> 16) & 0xFF);
equipData->Dye = (byte) info.Item2;
}
private void OnNamePlateUpdate(NamePlateUpdateEventArgs args) {
// only replace nameplates that have objects in the table
if (!this.Plugin.Config.Enabled || !this.Plugin.NameRepository.Initialised || args.ObjectId == 0xE0000000) {
@ -248,5 +332,4 @@ namespace NominaOcculta {
chara.Customize[(byte) CustomizeIndex.Gender]
);
}
}
}

View File

@ -11,8 +11,9 @@ using Dalamud.IoC;
using Dalamud.Plugin;
using XivCommon;
namespace NominaOcculta {
public class Plugin : IDalamudPlugin {
namespace NominaOcculta;
public class Plugin : IDalamudPlugin {
public string Name => "Nomina Occulta";
[PluginService]
@ -43,10 +44,10 @@ namespace NominaOcculta {
internal PartyList PartyList { get; private init; }
[PluginService]
internal ObjectTable ObjectTable { get; private init; }
internal TargetManager TargetManager { get; private init; }
[PluginService]
internal SigScanner SigScanner { get; private init; }
internal ObjectTable ObjectTable { get; private init; }
internal XivCommonBase Common { get; }
internal GameFunctions Functions { get; }
@ -54,6 +55,7 @@ namespace NominaOcculta {
internal Configuration Config { get; }
private Commands Commands { get; }
internal NameRepository NameRepository { get; }
internal AppearanceRepository AppearanceRepository { get; }
private Obscurer Obscurer { get; }
internal PluginUi Ui { get; }
@ -65,6 +67,7 @@ namespace NominaOcculta {
this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration();
this.Ui = new PluginUi(this);
this.NameRepository = new NameRepository(this);
this.AppearanceRepository = new AppearanceRepository(this);
this.Obscurer = new Obscurer(this);
this.Commands = new Commands(this);
}
@ -83,5 +86,4 @@ namespace NominaOcculta {
internal void SaveConfig() {
this.Interface.SavePluginConfig(this.Config);
}
}
}

View File

@ -1,9 +1,12 @@
using System;
using Dalamud.Game.ClientState.Keys;
using Dalamud.Logging;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
namespace NominaOcculta {
internal class PluginUi : IDisposable {
namespace NominaOcculta;
internal class PluginUi : IDisposable {
private Plugin Plugin { get; }
internal bool Visible;
@ -82,6 +85,12 @@ namespace NominaOcculta {
this.Plugin.Functions.LoadSheet(Util.SheetName);
}
if (this.Plugin.TargetManager.Target is {} target) {
var npc = this.Plugin.AppearanceRepository.GetNpc(target.ObjectId);
ImGui.TextUnformatted(npc.ToString());
ImGui.TextUnformatted(this.Plugin.DataManager.GetExcelSheet<ENpcResident>()!.GetRow(npc.RowId)!.Singular);
}
ImGui.Separator();
if (ImGui.TreeNode("Name queue")) {
@ -141,5 +150,4 @@ namespace NominaOcculta {
ImGui.TreePop();
}
}
}

View File

@ -3,8 +3,9 @@ using System.Collections.Generic;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
namespace NominaOcculta {
internal static class Util {
namespace NominaOcculta;
internal static class Util {
internal const string SheetName = "CharaMakeName";
internal static bool ContainsPlayerName(this SeString text, string name) {
@ -78,5 +79,4 @@ namespace NominaOcculta {
return bytes.ToArray();
}
}
}