Skip to content

Commit

Permalink
Maybe fix visor state issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Apr 4, 2024
1 parent 3d42188 commit 8375abd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Glamourer/Events/VisorStateChanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Glamourer.Events;
/// </list>
/// </summary>
public sealed class VisorStateChanged()
: EventWrapperRef2<Model, bool, VisorStateChanged.Priority>(nameof(VisorStateChanged))
: EventWrapperRef3<Model, bool, bool, VisorStateChanged.Priority>(nameof(VisorStateChanged))
{
public enum Priority
{
Expand Down
2 changes: 1 addition & 1 deletion Glamourer/Interop/MetaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void HideWeaponsDetour(DrawDataContainer* drawData, bool value)
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);
}
Expand Down
2 changes: 1 addition & 1 deletion Glamourer/Interop/VisorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void SetupVisorDetour(nint human, ushort modelId, bool on)
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}).");
Expand Down
9 changes: 8 additions & 1 deletion Glamourer/State/StateListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ private unsafe UpdateState UpdateBaseData(Actor actor, ActorState state, Customi
}

/// <summary> Handle visor state changes made by the game. </summary>
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)
Expand All @@ -578,6 +578,13 @@ private void OnVisorChange(Model model, ref bool value)
// 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;

Expand Down

0 comments on commit 8375abd

Please sign in to comment.