Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: better nameplate. but not perfect.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 23, 2024
1 parent 50e7433 commit 2dd43cd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
71 changes: 58 additions & 13 deletions FakeName/Hooker.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.Gui.NamePlate;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Hooking;
using Dalamud.Plugin.Services;
using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Info;
using Svg;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;
using System.Text;

Expand All @@ -26,32 +29,74 @@ public class Hooker
[Signature("E8 ?? ?? ?? ?? 8D 4E 32", DetourName = nameof(AtkTextNodeSetTextDetour))]
private Hook<AtkTextNodeSetTextDelegate>? AtkTextNodeSetTextHook { get; init; }

private delegate void SetNamePlateDelegate(IntPtr addon, bool isPrefixTitle,
bool displayTitle, IntPtr titlePtr, IntPtr namePtr, IntPtr fcNamePtr, IntPtr prefix, int iconId);

/// <summary>
/// https://github.com/shdwp/xivPartyIcons/blob/main/PartyIcons/Api/PluginAddressResolver.cs#L40
/// </summary>
[Signature("E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 48 8B 5C 24 ?? 45 38 BE", DetourName = nameof(SetNamePlateDetour))]
private Hook<SetNamePlateDelegate>? SetNamePlateHook { get; init; }

public static List<(string[], string)> Replacement { get; private set; } = [];

internal unsafe Hooker()
{
Service.Hook.InitializeFromAttributes(this);

AtkTextNodeSetTextHook?.Enable();
SetNamePlateHook?.Enable();

Service.NamePlate.OnNamePlateUpdate += NamePlate_OnNamePlateUpdate;

Service.Framework.Update += Framework_Update;
Service.ClientState.Login += ClientState_Login;
}

private void NamePlate_OnNamePlateUpdate(INamePlateUpdateContext context, IReadOnlyList<INamePlateUpdateHandler> handlers)
{
foreach (var handler in handlers)
{
switch (handler.NamePlateKind)
{
case NamePlateKind.PlayerCharacter:
var str = handler.Name?.TextValue;

if (!string.IsNullOrEmpty(str))
{
handler.Name = ReplaceNameplate(str);
}

var nameSe = handler.FreeCompanyTag.TextValue;
foreach ((var key, var value) in Service.Config.FCNameDict)
{
if (key != nameSe) continue;
handler.FreeCompanyTag = value;
break;
}
break;

case NamePlateKind.EventNpcCompanion:
str = handler.Title.ToString();
var start = str[0];
var end = str[^1];
handler.Title = start + ReplaceNameplate(str[1..^1]) + end;
break;
}
}
}

private static string ReplaceNameplate(string str)
{
if (Service.ClientState.LocalPlayer != null && GetNamesFull(Service.ClientState.LocalPlayer.Name.TextValue).Contains(str))
{
return Service.Config.FakeNameText;
}
else if (Service.Config.AllPlayerReplace)
{
return GetChangedName(str);
}
else
{
return str;
}
}

public unsafe void Dispose()
{
AtkTextNodeSetTextHook?.Dispose();
SetNamePlateHook?.Dispose();
Service.NamePlate.OnNamePlateUpdate -= NamePlate_OnNamePlateUpdate;

Service.Framework.Update -= Framework_Update;
Service.ClientState.Login -= ClientState_Login;
}
Expand Down Expand Up @@ -202,8 +247,8 @@ private unsafe void SetNamePlateDetour(IntPtr namePlateObjectPtr, bool isPrefixT
Service.Log.Error(ex, "Failed to change name plate");
}

SetNamePlateHook?.Original(namePlateObjectPtr, isPrefixTitle, displayTitle,
titlePtr, namePtr, fcNamePtr, prefix, iconId);
//SetNamePlateHook?.Original(namePlateObjectPtr, isPrefixTitle, displayTitle,
// titlePtr, namePtr, fcNamePtr, prefix, iconId);
}

private static string[] GetNamesFull(string name)
Expand Down
13 changes: 6 additions & 7 deletions FakeName/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
"XIVConfigUI.LocalString.CopyCommand": "Copy \"{0}\"",
"XIVConfigUI.LocalString.Localization": "Click to open the crowdin for modifying localization!",
"XIVConfigUI.LocalString.SourceCode": "Click to see the source code!",
"XIVConfigUI.Attributes.ConfigUnitType.None": "None",
"XIVConfigUI.Attributes.ConfigUnitType.Seconds": "Time Unit, in seconds.",
"XIVConfigUI.Attributes.ConfigUnitType.Degree": "Angle Unit, in degrees.",
"XIVConfigUI.Attributes.ConfigUnitType.Yalms": "Distance Unit, in yalms.",
"XIVConfigUI.Attributes.ConfigUnitType.Percent": "Ratio Unit, as percentage.",
"XIVConfigUI.Attributes.ConfigUnitType.Pixels": "Display Unit, in pixels.",
"XIVConfigUI.LocalString.Remove": "Remove",
"XIVConfigUI.LocalString.MoveUp": "Move Up",
"XIVConfigUI.LocalString.MoveDown": "Move Down",
"XIVConfigUI.LocalString.CopyToClipboard": "Copy to Clipboard",
"XIVConfigUI.LocalString.FromClipboard": "From Clipboard",
"XIVConfigUI.LocalString.List": "List",
"XIVConfigUI.LocalString.Nothing": "No items in Combo"
"XIVConfigUI.LocalString.Nothing": "No items in Combo",
"XIVConfigUI.Attributes.ConfigUnitType.Seconds": "Time Unit, in seconds.",
"XIVConfigUI.Attributes.ConfigUnitType.Degree": "Angle Unit, in degrees.",
"XIVConfigUI.Attributes.ConfigUnitType.Yalms": "Distance Unit, in yalms.",
"XIVConfigUI.Attributes.ConfigUnitType.Percent": "Ratio Unit, as percentage.",
"XIVConfigUI.Attributes.ConfigUnitType.Pixels": "Display Unit, in pixels."
}
3 changes: 3 additions & 0 deletions FakeName/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ internal class Service

[PluginService]
public static IPluginLog Log { get; private set; } = null!;

[PluginService]
public static INamePlateGui NamePlate { get; private set; } = null!;
}

0 comments on commit 2dd43cd

Please sign in to comment.