Skip to content

Commit

Permalink
Only show items with an existing draw object
Browse files Browse the repository at this point in the history
  • Loading branch information
PassiveModding committed Oct 27, 2023
1 parent 9336b58 commit 64a8bc3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Meddle/Meddle.Plugin/UI/ResourceTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ private void DrawObjectPicker()
.Where(x =>
x.ObjectKind is ObjectKind.Player or ObjectKind.BattleNpc or ObjectKind.Retainer or ObjectKind.EventNpc
or ObjectKind.Companion
).ToArray();
)
.Where(x => CharacterUtility.HasDrawObject(x.ObjectIndex, Service.ObjectTable))
.ToArray();
if (objects.Length == 0)
{
ImGui.Text("No game objects found");
Expand All @@ -152,7 +154,15 @@ or ObjectKind.Companion
}
}

var names = objects.Select(x => $"{x.Name} - {x.ObjectKind}").ToArray();
var names = objects.Select(x =>
{
var name = x.Name?.ToString();
if (string.IsNullOrEmpty(name))
{
name = x.ObjectIndex.ToString();
}
return $"{name} - {x.ObjectKind}";
}).ToArray();

if (selected == -1 && names.Length > 0)
{
Expand Down
20 changes: 20 additions & 0 deletions Meddle/Meddle.Xande/Utility/CharacterUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ public static class CharacterUtility
return orderedPaths.FirstOrDefault() ?? suspectedPath;
}

public static unsafe bool HasDrawObject(ushort gameObjectId, IObjectTable objectTable)
{
var characters = objectTable.OfType<Character>();

var match = characters.FirstOrDefault(x => x.ObjectIndex == gameObjectId);
if (match == null || !match.IsValid())
{
return false;
}

var gameObject = (GameObject*) match.Address;
var drawObject = gameObject->GetDrawObject();
if (drawObject == null)
{
return false;
}

return true;
}

public static unsafe Models.Character? GetCharacterInfo(ushort gameObjectId, IObjectTable objectTable, LuminaManager lumina)
{
var characters = objectTable.OfType<Character>();
Expand Down

0 comments on commit 64a8bc3

Please sign in to comment.