From 9ac1f5cdb4a7b2aa1a73cb1546e29281f61fdca6 Mon Sep 17 00:00:00 2001 From: Kaz Wolfe Date: Fri, 15 Nov 2024 08:18:39 -0800 Subject: [PATCH] Revert OnLogin event to only fire when LocalPlayer is present --- Dalamud/Game/ClientState/ClientState.cs | 35 ++++++++++++++----------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Dalamud/Game/ClientState/ClientState.cs b/Dalamud/Game/ClientState/ClientState.cs index 364466cce..5f22eb54b 100644 --- a/Dalamud/Game/ClientState/ClientState.cs +++ b/Dalamud/Game/ClientState/ClientState.cs @@ -38,11 +38,16 @@ internal sealed class ClientState : IInternalDisposableService, IClientState private readonly ClientStateAddressResolver address; private readonly Hook setupTerritoryTypeHook; private readonly Hook uiModuleHandlePacketHook; - private readonly Hook processPacketPlayerSetupHook; private readonly Hook onLogoutHook; + [ServiceManager.ServiceDependency] + private readonly Framework framework = Service.Get(); + [ServiceManager.ServiceDependency] private readonly NetworkHandlers networkHandlers = Service.Get(); + + private bool lastConditionNone = true; + [ServiceManager.ServiceConstructor] private unsafe ClientState(TargetSigScanner sigScanner, Dalamud dalamud, GameLifecycle lifecycle) @@ -60,14 +65,13 @@ internal sealed class ClientState : IInternalDisposableService, IClientState this.setupTerritoryTypeHook = Hook.FromAddress(setTerritoryTypeAddr, this.SetupTerritoryTypeDetour); this.uiModuleHandlePacketHook = Hook.FromAddress((nint)UIModule.StaticVirtualTablePointer->HandlePacket, this.UIModuleHandlePacketDetour); - this.processPacketPlayerSetupHook = Hook.FromAddress(this.address.ProcessPacketPlayerSetup, this.ProcessPacketPlayerSetupDetour); this.onLogoutHook = Hook.FromAddress((nint)LogoutCallbackInterface.StaticVirtualTablePointer->OnLogout, this.OnLogoutDetour); + this.framework.Update += this.FrameworkOnOnUpdateEvent; this.networkHandlers.CfPop += this.NetworkHandlersOnCfPop; this.setupTerritoryTypeHook.Enable(); this.uiModuleHandlePacketHook.Enable(); - this.processPacketPlayerSetupHook.Enable(); this.onLogoutHook.Enable(); } @@ -171,8 +175,9 @@ internal sealed class ClientState : IInternalDisposableService, IClientState { this.setupTerritoryTypeHook.Dispose(); this.uiModuleHandlePacketHook.Dispose(); - this.processPacketPlayerSetupHook.Dispose(); this.onLogoutHook.Dispose(); + + this.framework.Update -= this.FrameworkOnOnUpdateEvent; this.networkHandlers.CfPop -= this.NetworkHandlersOnCfPop; } @@ -255,24 +260,24 @@ internal sealed class ClientState : IInternalDisposableService, IClientState } } - private unsafe void ProcessPacketPlayerSetupDetour(nint a1, nint packet) + private void FrameworkOnOnUpdateEvent(IFramework framework1) { - // Call original first, so everything is set up. - this.processPacketPlayerSetupHook.Original(a1, packet); - + var condition = Service.GetNullable(); var gameGui = Service.GetNullable(); + var data = Service.GetNullable(); - try + if (condition == null || gameGui == null || data == null) + return; + + if (condition.Any() && this.lastConditionNone && this.LocalPlayer != null) { - Log.Debug("Login"); + Log.Debug("Is login"); + this.lastConditionNone = false; this.Login?.InvokeSafely(); - gameGui?.ResetUiHideState(); + gameGui.ResetUiHideState(); + this.lifecycle.ResetLogout(); } - catch (Exception ex) - { - Log.Error(ex, "Exception during ProcessPacketPlayerSetupDetour"); - } } private unsafe void OnLogoutDetour(LogoutCallbackInterface* thisPtr, LogoutCallbackInterface.LogoutParams* logoutParams)