From 8375abd6cbfa52b223ed0936642f2afa28efb787 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Thu, 4 Apr 2024 14:01:58 +0200 Subject: [PATCH] Maybe fix visor state issue. --- Glamourer/Events/VisorStateChanged.cs | 2 +- Glamourer/Interop/MetaService.cs | 2 +- Glamourer/Interop/VisorService.cs | 2 +- Glamourer/State/StateListener.cs | 9 ++++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Glamourer/Events/VisorStateChanged.cs b/Glamourer/Events/VisorStateChanged.cs index 8e70002..d2d3a6c 100644 --- a/Glamourer/Events/VisorStateChanged.cs +++ b/Glamourer/Events/VisorStateChanged.cs @@ -12,7 +12,7 @@ namespace Glamourer.Events; /// /// public sealed class VisorStateChanged() - : EventWrapperRef2(nameof(VisorStateChanged)) + : EventWrapperRef3(nameof(VisorStateChanged)) { public enum Priority { diff --git a/Glamourer/Interop/MetaService.cs b/Glamourer/Interop/MetaService.cs index a862e59..1bc7a32 100644 --- a/Glamourer/Interop/MetaService.cs +++ b/Glamourer/Interop/MetaService.cs @@ -93,7 +93,7 @@ public unsafe class MetaService : IDisposable private void ToggleVisorDetour(DrawDataContainer* drawData, bool value) { Actor actor = drawData->Parent; - _visorEvent.Invoke(actor.Model, ref value); + _visorEvent.Invoke(actor.Model, true, ref value); Glamourer.Log.Verbose($"[MetaService] Toggle Visor triggered with 0x{(nint)drawData:X} {value} for {actor.Utf8Name}."); _toggleVisorHook.Original(drawData, value); } diff --git a/Glamourer/Interop/VisorService.cs b/Glamourer/Interop/VisorService.cs index 4232446..4487ef8 100644 --- a/Glamourer/Interop/VisorService.cs +++ b/Glamourer/Interop/VisorService.cs @@ -52,7 +52,7 @@ public class VisorService : IDisposable var originalOn = on; // Invoke an event that can change the requested value // and also control whether the function should be called at all. - Event.Invoke(human, ref on); + Event.Invoke(human, false, ref on); Glamourer.Log.Excessive( $"[SetVisorState] Invoked from game on 0x{human:X} switching to {on} (original {originalOn})."); diff --git a/Glamourer/State/StateListener.cs b/Glamourer/State/StateListener.cs index ff227a8..7a30108 100644 --- a/Glamourer/State/StateListener.cs +++ b/Glamourer/State/StateListener.cs @@ -568,7 +568,7 @@ public class StateListener : IDisposable } /// Handle visor state changes made by the game. - private void OnVisorChange(Model model, ref bool value) + private unsafe void OnVisorChange(Model model, bool game, ref bool value) { // Skip updates when in customize update. if (ChangeCustomizeService.InUpdate.InMethod) @@ -578,6 +578,13 @@ public class StateListener : IDisposable // We do not need to handle fixed designs, // since a fixed design would already have established state-tracking. var actor = _penumbra.GameObjectFromDrawObject(model); + + // Only actually change anything if the actor state changed, + // when equipping headgear the method is called with the current draw object state, + // which corrupts Glamourer's assumed game state otherwise. + if (!game && actor.AsCharacter->DrawData.IsVisorToggled != value) + return; + if (_condition[ConditionFlag.CreatingCharacter] && actor.Index >= ObjectIndex.CutsceneStart) return;