Fix visor service with umbrella on.

This commit is contained in:
Ottermandias 2024-04-05 14:42:23 +02:00
parent 7091fdd808
commit 10e508b4e7

View file

@ -43,21 +43,22 @@ public class VisorService : IDisposable
return true; return true;
} }
private delegate void UpdateVisorDelegateInternal(nint humanPtr, ushort modelId, bool on); private delegate void UpdateVisorDelegateInternal(nint humanPtr, ushort modelId, byte on);
private readonly Hook<UpdateVisorDelegateInternal> _setupVisorHook; private readonly Hook<UpdateVisorDelegateInternal> _setupVisorHook;
private void SetupVisorDetour(nint human, ushort modelId, bool on) private void SetupVisorDetour(nint human, ushort modelId, byte value)
{ {
var originalOn = on; var originalOn = value != 0;
var on = originalOn;
// Invoke an event that can change the requested value // Invoke an event that can change the requested value
// and also control whether the function should be called at all. // and also control whether the function should be called at all.
Event.Invoke(human, false, ref on); Event.Invoke(human, false, ref on);
Glamourer.Log.Excessive( Glamourer.Log.Verbose(
$"[SetVisorState] Invoked from game on 0x{human:X} switching to {on} (original {originalOn})."); $"[SetVisorState] Invoked from game on 0x{human:X} switching to {on} (original {originalOn} from {value} with {modelId}).");
SetupVisorDetour((Model)human, modelId, on); SetupVisorDetour(human, modelId, on);
} }
/// <summary> /// <summary>
@ -69,6 +70,6 @@ public class VisorService : IDisposable
private unsafe void SetupVisorDetour(Model human, ushort modelId, bool on) private unsafe void SetupVisorDetour(Model human, ushort modelId, bool on)
{ {
human.AsCharacterBase->VisorToggled = on; human.AsCharacterBase->VisorToggled = on;
_setupVisorHook.Original(human.Address, modelId, on); _setupVisorHook.Original(human.Address, modelId, on ? (byte)1 : (byte)0);
} }
} }