Skip to content

Commit

Permalink
Update Util.ShowStruct() (#2104)
Browse files Browse the repository at this point in the history
- Now prints field offsets, if/when they are defined.
- Fixed a bug wherein Boolean fields were being printed with incorrect values (now tries reading the value as a byte, which seems to do the trick)
  • Loading branch information
ItsBexy authored Nov 19, 2024
1 parent 2f50276 commit 192dc9c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Dalamud/Utility/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,8 @@ private static void ShowStructInternal(object obj, ulong addr, bool autoExpand =
.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance))
{
var fixedBuffer = (FixedBufferAttribute)f.GetCustomAttribute(typeof(FixedBufferAttribute));
var offset = (FieldOffsetAttribute)f.GetCustomAttribute(typeof(FieldOffsetAttribute));

if (fixedBuffer != null)
{
ImGui.Text($"fixed");
Expand All @@ -1212,6 +1214,11 @@ private static void ShowStructInternal(object obj, ulong addr, bool autoExpand =
}
else
{
if (offset != null)
{
ImGui.TextDisabled($"[0x{offset.Value:X}]");
ImGui.SameLine();
}
ImGui.TextColored(new Vector4(0.2f, 0.9f, 0.9f, 1), $"{f.FieldType.Name}");
}

Expand All @@ -1224,6 +1231,8 @@ private static void ShowStructInternal(object obj, ulong addr, bool autoExpand =
{
if (f.FieldType.IsGenericType && (f.FieldType.IsByRef || f.FieldType.IsByRefLike))
ImGui.Text("Cannot preview ref typed fields."); // object never contains ref struct
else if (f.FieldType == typeof(bool) && offset != null)
ShowValue(addr, pathList, f.FieldType, Marshal.ReadByte((nint)addr + offset.Value) > 0, hideAddress);
else
ShowValue(addr, pathList, f.FieldType, f.GetValue(obj), hideAddress);
}
Expand Down

0 comments on commit 192dc9c

Please sign in to comment.