Skip to content

Commit

Permalink
safer name handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chirpxiv committed Jan 18, 2023
1 parent f10ebfa commit 616d95e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Ktisis/Data/Files/AnamCharaFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public enum SaveModes {
public float? HeightMultiplier { get; set; }

public void WriteToFile(Actor actor, SaveModes mode) {
Nickname = actor.Name;
Nickname = actor.GetName();
ModelType = actor.ModelId;
ObjectKind = (ObjectKind)actor.GameObject.ObjectKind;

Expand Down
6 changes: 4 additions & 2 deletions Ktisis/Interop/Hooks/GuiHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ internal unsafe static void UpdateTarName(IntPtr a1) {
var target = Ktisis.GPoseTarget;
if (target != null) {
var actor = (Actor*)Ktisis.GPoseTarget!.Address;
if (actor != null && actor->Model != null && actor->Name != null)
nameToDisplay = actor->Name!;
if (actor != null) {
var name = actor->GetName();
if (name != null) nameToDisplay = name;
}
}
}

Expand Down
11 changes: 9 additions & 2 deletions Ktisis/Structs/Actor/Actor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ public struct Actor {

[FieldOffset(0xC40)] public ActorGaze Gaze; // Update in ActorHooks.cs as well

public unsafe string? Name => Marshal.PtrToStringAnsi((IntPtr)GameObject.GetName());
public unsafe string? GetName() {
var ptr = GameObject.GetName();
return ptr == null ? null : Marshal.PtrToStringUTF8((IntPtr)ptr);
}

public string GetNameOr(string fallback) {
var name = GetName();
return ((ObjectKind)GameObject.ObjectKind == ObjectKind.Pc && !Ktisis.Configuration.DisplayCharName) || string.IsNullOrEmpty(name) ? fallback : name;
}

public string GetNameOr(string fallback) => ((ObjectKind)GameObject.ObjectKind == ObjectKind.Pc && !Ktisis.Configuration.DisplayCharName) || string.IsNullOrEmpty(Name)? fallback : Name;
public string GetNameOrId() => GetNameOr("Actor #" + ObjectID);

public unsafe IntPtr GetAddress() {
Expand Down

0 comments on commit 616d95e

Please sign in to comment.