From f687852879f5accc14f1c7486623d3bbaf1187a1 Mon Sep 17 00:00:00 2001 From: Haselnussbomber Date: Fri, 15 Aug 2025 18:19:21 +0200 Subject: [PATCH] Set ClientState.TerritoryType on load (#2366) * Set TerritoryType on load * Do not fire TerritoryChanged event on load --- Dalamud/Game/ClientState/ClientState.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Dalamud/Game/ClientState/ClientState.cs b/Dalamud/Game/ClientState/ClientState.cs index 4c32873c6..13b75bda0 100644 --- a/Dalamud/Game/ClientState/ClientState.cs +++ b/Dalamud/Game/ClientState/ClientState.cs @@ -72,6 +72,8 @@ internal sealed class ClientState : IInternalDisposableService, IClientState this.setupTerritoryTypeHook.Enable(); this.uiModuleHandlePacketHook.Enable(); this.onLogoutHook.Enable(); + + this.framework.RunOnTick(this.Setup); } private unsafe delegate void ProcessPacketPlayerSetupDelegate(nint a1, nint packet); @@ -180,8 +182,22 @@ internal sealed class ClientState : IInternalDisposableService, IClientState this.networkHandlers.CfPop -= this.NetworkHandlersOnCfPop; } + private unsafe void Setup() + { + this.TerritoryType = (ushort)GameMain.Instance()->CurrentTerritoryTypeId; + } + private unsafe void SetupTerritoryTypeDetour(EventFramework* eventFramework, ushort territoryType) { + this.SetTerritoryType(territoryType); + this.setupTerritoryTypeHook.Original(eventFramework, territoryType); + } + + private unsafe void SetTerritoryType(ushort territoryType) + { + if (this.TerritoryType == territoryType) + return; + Log.Debug("TerritoryType changed: {0}", territoryType); this.TerritoryType = territoryType; @@ -207,8 +223,6 @@ internal sealed class ClientState : IInternalDisposableService, IClientState } } } - - this.setupTerritoryTypeHook.Original(eventFramework, territoryType); } private unsafe void UIModuleHandlePacketDetour(