Fix issues with Visor and Aesthetician

This commit is contained in:
Ottermandias 2023-08-30 18:04:28 +02:00
parent 937e385cbc
commit 5417013bc3
3 changed files with 23 additions and 55 deletions

View file

@ -1,46 +0,0 @@
using Glamourer.Customization;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs;
namespace Glamourer.Designs;
public interface IDesign
{
public uint GetModelId();
public bool SetModelId(uint modelId);
public EquipItem GetEquipItem(EquipSlot slot);
public bool SetEquipItem(EquipItem item);
public StainId GetStain(EquipSlot slot);
public bool SetStain(EquipSlot slot, StainId stain);
public CustomizeValue GetCustomizeValue(CustomizeIndex type);
public bool SetCustomizeValue(CustomizeIndex type);
public bool DoApplyEquip(EquipSlot slot);
public bool DoApplyStain(EquipSlot slot);
public bool DoApplyCustomize(CustomizeIndex index);
public bool SetApplyEquip(EquipSlot slot, bool value);
public bool SetApplyStain(EquipSlot slot, bool value);
public bool SetApplyCustomize(CustomizeIndex slot, bool value);
public bool IsWet();
public bool SetIsWet(bool value);
public bool IsHatVisible();
public bool DoApplyHatVisible();
public bool SetHatVisible(bool value);
public bool SetApplyHatVisible(bool value);
public bool IsVisorToggled();
public bool DoApplyVisorToggle();
public bool SetVisorToggle(bool value);
public bool SetApplyVisorToggle(bool value);
public bool IsWeaponVisible();
public bool DoApplyWeaponVisible();
public bool SetWeaponVisible(bool value);
public bool SetApplyWeaponVisible(bool value);
}

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
using Dalamud.Hooking; using Dalamud.Hooking;
using Dalamud.Utility.Signatures; using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene; using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
@ -19,6 +20,9 @@ public unsafe class ChangeCustomizeService : EventWrapper<Action<Model, Ref<Cust
{ {
private readonly PenumbraReloaded _penumbraReloaded; private readonly PenumbraReloaded _penumbraReloaded;
/// <summary> Check whether we in a manual customize update, in which case we need to not toggle certain flags. </summary>
public static readonly ThreadLocal<bool> InUpdate = new(() => false);
public enum Priority public enum Priority
{ {
/// <seealso cref="State.StateListener.OnCustomizeChange"/> /// <seealso cref="State.StateListener.OnCustomizeChange"/>
@ -62,9 +66,12 @@ public unsafe class ChangeCustomizeService : EventWrapper<Action<Model, Ref<Cust
{ {
if (!model.IsHuman) if (!model.IsHuman)
return false; return false;
Glamourer.Log.Verbose($"[ChangeCustomize] Invoked on 0x{model.Address:X} with {customize}."); Glamourer.Log.Verbose($"[ChangeCustomize] Invoked on 0x{model.Address:X} with {customize}.");
return _changeCustomizeHook.Original(model.AsHuman, customize.Data, 1); InUpdate.Value = true;
var ret = _changeCustomizeHook.Original(model.AsHuman, customize.Data, 1);
InUpdate.Value = false;
return ret;
} }
public bool UpdateCustomize(Actor actor, CustomizeData customize) public bool UpdateCustomize(Actor actor, CustomizeData customize)

View file

@ -160,10 +160,13 @@ public class StateListener : IDisposable
private unsafe void OnCustomizeChange(Model model, Ref<Customize> customize) private unsafe void OnCustomizeChange(Model model, Ref<Customize> customize)
{ {
if (_condition[ConditionFlag.CreatingCharacter] || !model.IsHuman) if (!model.IsHuman)
return; return;
var actor = _penumbra.GameObjectFromDrawObject(model); var actor = _penumbra.GameObjectFromDrawObject(model);
if (_condition[ConditionFlag.CreatingCharacter] && actor.Index >= ObjectIndex.CutsceneStart)
return;
if (!actor.Identifier(_actors.AwaitedService, out var identifier) if (!actor.Identifier(_actors.AwaitedService, out var identifier)
|| !_manager.TryGetValue(identifier, out var state)) || !_manager.TryGetValue(identifier, out var state))
return; return;
@ -218,10 +221,10 @@ public class StateListener : IDisposable
/// </summary> /// </summary>
private void OnSlotUpdating(Model model, EquipSlot slot, Ref<CharacterArmor> armor, Ref<ulong> returnValue) private void OnSlotUpdating(Model model, EquipSlot slot, Ref<CharacterArmor> armor, Ref<ulong> returnValue)
{ {
if (_condition[ConditionFlag.CreatingCharacter]) var actor = _penumbra.GameObjectFromDrawObject(model);
if (_condition[ConditionFlag.CreatingCharacter] && actor.Index >= ObjectIndex.CutsceneStart)
return; return;
var actor = _penumbra.GameObjectFromDrawObject(model);
if (actor.Identifier(_actors.AwaitedService, out var identifier) if (actor.Identifier(_actors.AwaitedService, out var identifier)
&& _manager.TryGetValue(identifier, out var state)) && _manager.TryGetValue(identifier, out var state))
HandleEquipSlot(actor, state, slot, ref armor.Value); HandleEquipSlot(actor, state, slot, ref armor.Value);
@ -274,7 +277,7 @@ public class StateListener : IDisposable
/// </summary> /// </summary>
private void OnWeaponLoading(Actor actor, EquipSlot slot, Ref<CharacterWeapon> weapon) private void OnWeaponLoading(Actor actor, EquipSlot slot, Ref<CharacterWeapon> weapon)
{ {
if (_condition[ConditionFlag.CreatingCharacter]) if (_condition[ConditionFlag.CreatingCharacter] && actor.Index >= ObjectIndex.CutsceneStart)
return; return;
// Fist weapon gauntlet hack. // Fist weapon gauntlet hack.
@ -466,13 +469,17 @@ public class StateListener : IDisposable
/// <summary> Handle visor state changes made by the game. </summary> /// <summary> Handle visor state changes made by the game. </summary>
private void OnVisorChange(Model model, Ref<bool> value) private void OnVisorChange(Model model, Ref<bool> value)
{ {
if (_condition[ConditionFlag.CreatingCharacter]) // Skip updates when in customize update.
if (ChangeCustomizeService.InUpdate.IsValueCreated && ChangeCustomizeService.InUpdate.Value)
return; return;
// Find appropriate actor and state. // Find appropriate actor and state.
// We do not need to handle fixed designs, // We do not need to handle fixed designs,
// since a fixed design would already have established state-tracking. // since a fixed design would already have established state-tracking.
var actor = _penumbra.GameObjectFromDrawObject(model); var actor = _penumbra.GameObjectFromDrawObject(model);
if (_condition[ConditionFlag.CreatingCharacter] && actor.Index >= ObjectIndex.CutsceneStart)
return;
if (!actor.Identifier(_actors.AwaitedService, out var identifier)) if (!actor.Identifier(_actors.AwaitedService, out var identifier))
return; return;
@ -499,7 +506,7 @@ public class StateListener : IDisposable
/// <summary> Handle Hat Visibility changes. These act on the game object. </summary> /// <summary> Handle Hat Visibility changes. These act on the game object. </summary>
private void OnHeadGearVisibilityChange(Actor actor, Ref<bool> value) private void OnHeadGearVisibilityChange(Actor actor, Ref<bool> value)
{ {
if (_condition[ConditionFlag.CreatingCharacter]) if (_condition[ConditionFlag.CreatingCharacter] && actor.Index >= ObjectIndex.CutsceneStart)
return; return;
// Find appropriate state. // Find appropriate state.
@ -532,7 +539,7 @@ public class StateListener : IDisposable
/// <summary> Handle Weapon Visibility changes. These act on the game object. </summary> /// <summary> Handle Weapon Visibility changes. These act on the game object. </summary>
private void OnWeaponVisibilityChange(Actor actor, Ref<bool> value) private void OnWeaponVisibilityChange(Actor actor, Ref<bool> value)
{ {
if (_condition[ConditionFlag.CreatingCharacter]) if (_condition[ConditionFlag.CreatingCharacter] && actor.Index >= ObjectIndex.CutsceneStart)
return; return;
// Find appropriate state. // Find appropriate state.