Skip to content

Commit

Permalink
Player name override option
Browse files Browse the repository at this point in the history
  • Loading branch information
PassiveModding committed Jul 27, 2024
1 parent 7a38ab3 commit 895fd71
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions Meddle/Meddle.Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class Configuration : IPluginConfiguration

public bool ShowAdvanced { get; set; }
public bool OpenOnLoad { get; set; }
public string PlayerNameOverride { get; set; } = string.Empty;

public int Version { get; set; } = 1;

Expand Down
9 changes: 6 additions & 3 deletions Meddle/Meddle.Plugin/UI/CharacterTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public unsafe class CharacterTab : ITab
private readonly ILogger<CharacterTab> log;
private readonly IObjectTable objectTable;
private readonly ParseUtil parseUtil;
private readonly Configuration config;
private readonly PluginState pluginState;

private readonly Dictionary<string, TextureImage> textureCache = new();
Expand All @@ -50,12 +51,14 @@ public CharacterTab(
ExportUtil exportUtil,
IDataManager dataManager,
ITextureProvider textureProvider,
ParseUtil parseUtil)
ParseUtil parseUtil,
Configuration config)
{
this.log = log;
this.pluginState = pluginState;
this.exportUtil = exportUtil;
this.parseUtil = parseUtil;
this.config = config;
this.exportUtil.OnLogEvent += HandleLogEvent;
this.parseUtil.OnLogEvent += HandleLogEvent;
this.objectTable = objectTable;
Expand Down Expand Up @@ -143,14 +146,14 @@ private void DrawObjectPicker()
SelectedCharacter ??= objects.FirstOrDefault() ?? clientState.LocalPlayer;

ImGui.Text("Select Character");
var preview = SelectedCharacter != null ? clientState.GetCharacterDisplayText(SelectedCharacter) : "None";
var preview = SelectedCharacter != null ? clientState.GetCharacterDisplayText(SelectedCharacter, config.PlayerNameOverride) : "None";
using (var combo = ImRaii.Combo("##Character", preview))
{
if (combo)
{
foreach (var character in objects)
{
if (ImGui.Selectable(clientState.GetCharacterDisplayText(character)))
if (ImGui.Selectable(clientState.GetCharacterDisplayText(character, config.PlayerNameOverride)))
{
SelectedCharacter = character;
}
Expand Down
7 changes: 7 additions & 0 deletions Meddle/Meddle.Plugin/UI/OptionsTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,12 @@ public void Draw()
config.OpenOnLoad = openOnLoad;
config.Save();
}

var playerNameOverride = config.PlayerNameOverride;
if (ImGui.InputText("Player Name Override", ref playerNameOverride, 64))
{
config.PlayerNameOverride = playerNameOverride;
config.Save();
}
}
}
7 changes: 4 additions & 3 deletions Meddle/Meddle.Plugin/Utils/ObjectUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static Vector3 GetDistanceToLocalPlayer(this IClientState clientState, IG
return new Vector3(obj.YalmDistanceX, 0, obj.YalmDistanceZ);
}

public static unsafe string GetCharacterDisplayText(this IClientState clientState, IGameObject obj)
public static unsafe string GetCharacterDisplayText(this IClientState clientState, IGameObject obj, string overrideName = "")
{
var drawObject = ((GameObject*)obj.Address)->DrawObject;
if (drawObject == null)
Expand All @@ -60,8 +60,9 @@ public static unsafe string GetCharacterDisplayText(this IClientState clientStat
return "Invalid Character";

var modelType = ((CharacterBase*)drawObject)->GetModelType();


var name = string.IsNullOrWhiteSpace(overrideName) ? obj.Name.TextValue : overrideName;
return
$"[{obj.Address:X8}:{obj.GameObjectId:X}][{obj.ObjectKind}][{modelType}] - {(string.IsNullOrWhiteSpace(obj.Name.TextValue) ? "Unnamed" : obj.Name.TextValue)} - {clientState.GetDistanceToLocalPlayer(obj).Length():0.00}y";
$"[{obj.Address:X8}:{obj.GameObjectId:X}][{obj.ObjectKind}][{modelType}] - {(string.IsNullOrWhiteSpace(name) ? "Unnamed" : name)} - {clientState.GetDistanceToLocalPlayer(obj).Length():0.00}y";
}
}

0 comments on commit 895fd71

Please sign in to comment.