Use refactored Penumbra options to allow for fixed designs on NPCs.

This commit is contained in:
Ottermandias 2021-10-10 15:55:27 +02:00
parent 9d5f811a44
commit 9dc1b92c9a
3 changed files with 14 additions and 51 deletions

View file

@ -43,11 +43,6 @@ namespace Glamourer.Gui
Dalamud.PluginInterface.UiBuilder.Draw += Draw;
Dalamud.PluginInterface.UiBuilder.OpenConfigUi += ToggleVisibility;
_characterConstructor = typeof(Character).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[]
{
typeof(IntPtr),
}, null)!;
_equipSlotNames = GetEquipSlotNames();
_stains = GameData.Stains(Dalamud.GameData);

View file

@ -11,6 +11,7 @@ using Glamourer.Customization;
using Glamourer.Designs;
using Glamourer.FileSystem;
using ImGuiNET;
using Penumbra.PlayerWatch;
namespace Glamourer.Gui
{
@ -22,7 +23,6 @@ namespace Glamourer.Gui
private const string DesignNamePopupLabel = "Save Design As...";
private const uint RedHeaderColor = 0xFF1818C0;
private const uint GreenHeaderColor = 0xFF18C018;
private readonly ConstructorInfo _characterConstructor;
private void DrawPlayerHeader()
{
@ -111,49 +111,16 @@ namespace Glamourer.Gui
Glamourer.Penumbra.UpdateCharacters(player, fallback);
}
private const int ModelTypeOffset = 0x01B4;
private static unsafe int ModelType(GameObject actor)
=> *(int*) (actor.Address + ModelTypeOffset);
private static unsafe void SetModelType(GameObject actor, int value)
=> *(int*) (actor.Address + ModelTypeOffset) = value;
private Character Character(IntPtr address)
=> (Character) _characterConstructor.Invoke(new object[]
{
address,
});
private Character? CreateCharacter(GameObject? actor)
{
if (actor == null)
return null;
return actor switch
{
PlayerCharacter p => p,
BattleChara b => b,
_ => actor.ObjectKind switch
{
ObjectKind.BattleNpc => Character(actor.Address),
ObjectKind.Companion => Character(actor.Address),
ObjectKind.EventNpc => Character(actor.Address),
_ => null,
},
};
}
private static Character? TransformToCustomizable(Character? actor)
{
if (actor == null)
return null;
if (ModelType(actor) == 0)
if (actor.ModelType() == 0)
return actor;
SetModelType(actor, 0);
actor.SetModelType(0);
CharacterCustomization.Default.Write(actor.Address);
return actor;
}
@ -163,7 +130,7 @@ namespace Glamourer.Gui
if (!ImGui.Button("Apply to Target"))
return;
var player = TransformToCustomizable(CreateCharacter(Dalamud.Targets.Target));
var player = TransformToCustomizable(CharacterFactory.Convert(Dalamud.Targets.Target));
if (player == null)
return;
@ -224,7 +191,7 @@ namespace Glamourer.Gui
DrawTargetPlayerButton();
}
var currentModel = ModelType(_player!);
var currentModel = _player!.ModelType();
using var raii = new ImGuiRaii();
if (!raii.Begin(() => ImGui.BeginCombo("Model Id", currentModel.ToString()), ImGui.EndCombo))
return;
@ -234,7 +201,7 @@ namespace Glamourer.Gui
if (!ImGui.Selectable($"{id:D6}##models", id == currentModel) || id == currentModel)
continue;
SetModelType(_player!, (int) id);
_player!.SetModelType((int) id);
Glamourer.Penumbra.UpdateCharacters(_player!);
}
}
@ -286,7 +253,7 @@ namespace Glamourer.Gui
return;
}
if (_player == null || ModelType(_player) == 0)
if (_player == null || _player.ModelType() == 0)
DrawPlayerPanel();
else
DrawMonsterPanel();

View file

@ -5,6 +5,7 @@ using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Interface;
using ImGuiNET;
using Penumbra.PlayerWatch;
namespace Glamourer.Gui
{
@ -43,7 +44,7 @@ namespace Glamourer.Gui
if (player.ObjectKind == ObjectKind.Player)
return num == 1 ? playerName : $"{playerName} #{num}";
if (ModelType(player) == 0)
if (player.ModelType() == 0)
return num == 1 ? $"{playerName} (NPC)" : $"{playerName} #{num} (NPC)";
return num == 1 ? $"{playerName} (Monster)" : $"{playerName} #{num} (Monster)";
@ -112,7 +113,7 @@ namespace Glamourer.Gui
else
{
if (ImGui.Button(FontAwesomeIcon.HandPointer.ToIconString(), buttonWidth))
select = CreateCharacter(Dalamud.Targets.Target);
select = CharacterFactory.Convert(Dalamud.Targets.Target);
}
raii.PopFonts();
@ -142,7 +143,7 @@ namespace Glamourer.Gui
_gPoseActors.Clear();
for (var i = GPoseObjectId; i < GPoseObjectId + 48; ++i)
{
var player = CreateCharacter(Dalamud.Objects[i]);
var player = CharacterFactory.Convert(Dalamud.Objects[i]);
if (player == null)
break;
@ -151,14 +152,14 @@ namespace Glamourer.Gui
for (var i = 0; i < GPoseObjectId; ++i)
{
var player = CreateCharacter(Dalamud.Objects[i])!;
var player = CharacterFactory.Convert(Dalamud.Objects[i])!;
if (player != null)
DrawPlayerSelectable(player);
}
for (var i = GPoseObjectId + 48; i < Dalamud.Objects.Length; ++i)
{
var player = CreateCharacter(Dalamud.Objects[i])!;
var player = CharacterFactory.Convert(Dalamud.Objects[i])!;
if (player != null)
DrawPlayerSelectable(player);
}