fix: censor abbreviated player names in screenshot mode
Best effort.
This commit is contained in:
@@ -3,6 +3,7 @@ using ChatTwo.Code;
|
||||
using ChatTwo.GameFunctions.Types;
|
||||
using ChatTwo.Resources;
|
||||
using ChatTwo.Util;
|
||||
using Dalamud.Game.Config;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Hooking;
|
||||
using Dalamud.Memory;
|
||||
@@ -57,6 +58,17 @@ internal sealed unsafe class Chat : IDisposable
|
||||
internal bool UsesTellTempChannel { get; set; }
|
||||
internal InputChannel? PreviousChannel { get; private set; }
|
||||
|
||||
private enum PlayerNameDisplayType : uint
|
||||
{
|
||||
FullName = 0,
|
||||
SurnameAbbreviated = 1,
|
||||
ForenameAbbreviated = 2,
|
||||
Initials = 3
|
||||
}
|
||||
|
||||
private long LastPlayerNameDisplayTypeRefresh;
|
||||
private PlayerNameDisplayType CurrentPlayerNameDisplayType = PlayerNameDisplayType.FullName;
|
||||
|
||||
internal Chat(Plugin plugin)
|
||||
{
|
||||
Plugin = plugin;
|
||||
@@ -444,4 +456,38 @@ internal sealed unsafe class Chat : IDisposable
|
||||
|
||||
return wasValid;
|
||||
}
|
||||
|
||||
private PlayerNameDisplayType GetNameDisplayType()
|
||||
{
|
||||
var ok = Plugin.GameConfig.TryGet(UiConfigOption.LogNameType, out uint type);
|
||||
if (!ok || !Enum.IsDefined(typeof(PlayerNameDisplayType), type))
|
||||
return PlayerNameDisplayType.FullName;
|
||||
return (PlayerNameDisplayType) type;
|
||||
}
|
||||
|
||||
internal string AbbreviatePlayerName(string playerName)
|
||||
{
|
||||
if (LastPlayerNameDisplayTypeRefresh + 5 * 1000 < Environment.TickCount64)
|
||||
{
|
||||
LastPlayerNameDisplayTypeRefresh = Environment.TickCount64;
|
||||
CurrentPlayerNameDisplayType = GetNameDisplayType();
|
||||
}
|
||||
|
||||
if (CurrentPlayerNameDisplayType == PlayerNameDisplayType.FullName)
|
||||
return playerName;
|
||||
|
||||
var split = playerName.Split(' ');
|
||||
if (split.Length != 2)
|
||||
return playerName;
|
||||
return CurrentPlayerNameDisplayType switch
|
||||
{
|
||||
PlayerNameDisplayType.SurnameAbbreviated =>
|
||||
$"{split.First()} {split.Last().FirstOrDefault('A')}.",
|
||||
PlayerNameDisplayType.ForenameAbbreviated =>
|
||||
$"{split.First().FirstOrDefault('A')}. {split.Last()}",
|
||||
PlayerNameDisplayType.Initials =>
|
||||
$"{split.First().FirstOrDefault('A')}. {split.Last().FirstOrDefault('A')}.",
|
||||
_ => playerName
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user