From c8a895b49f4e0c140899464d6447d4febd6a37cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 21 Oct 2026 02:51:43 +0300 Subject: [PATCH 1/6] Fix Lua panels being destroyed after their Lua state closes --- Game.Client/GarrysMod/GModBase.cs | 18 +++--------------- Game.MenuSystem/MenuSystem.cs | 9 ++++++--- Source.GUI.Controls/Panel.cs | 6 ------ 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/Game.Client/GarrysMod/GModBase.cs b/Game.Client/GarrysMod/GModBase.cs index 5f7fa4286..8fd48c0e5 100644 --- a/Game.Client/GarrysMod/GModBase.cs +++ b/Game.Client/GarrysMod/GModBase.cs @@ -68,28 +68,16 @@ public class GModBase : Panel static void DestroyPanel(ref Panel? panel) { if (panel == null) return; - panel.SetParent(null); - panel.SetVisible(false); - panel.MarkForDeletion(); + panel.DeletePanel(); panel = null; } public static void Shutdown() { - Panel clientDll = (Panel)enginevgui.GetPanel(VGuiPanelType.ClientDll); - for (int i = 0; i < clientDll.GetChildCount(); i++) - clientDll.GetChild(i).ClearLuaReferencesRecursive(); - if (HudGMod.g_HudGMod != null) { - for (int i = 0; i < HudGMod.g_HudGMod.GetChildCount(); i++) { - HudGMod.g_HudGMod.GetChild(i).MarkForDeletion(); - HudGMod.g_HudGMod.GetChild(i).ClearLuaReferencesRecursive(); - } + while (HudGMod.g_HudGMod.GetChildCount() > 0) + HudGMod.g_HudGMod.GetChild(0).DeletePanel(); } - MouseInput?.ClearLuaReferencesRecursive(); - BasePanel?.ClearLuaReferencesRecursive(); - ParentToHUDPanel?.ClearLuaReferencesRecursive(); - DestroyPanel(ref MouseInput); DestroyPanel(ref BasePanel); DestroyPanel(ref ParentToHUDPanel); diff --git a/Game.MenuSystem/MenuSystem.cs b/Game.MenuSystem/MenuSystem.cs index b80e70afd..ab1345334 100644 --- a/Game.MenuSystem/MenuSystem.cs +++ b/Game.MenuSystem/MenuSystem.cs @@ -39,9 +39,9 @@ public int Init(IServiceProvider services, IGet get, IGarrysMod gmod, GlobalVars public void Shutdown() { filesystem.Addons().SetDownloadNotify(null); - CloseLua(); DestroyLoadingPanel(); DestroyMenuPanels(); + CloseLua(); } public void SetupNetworkString(INetworkStringTableContainer networkStringTableContainer) => networkstringtable = networkStringTableContainer; @@ -108,12 +108,15 @@ void CloseLua() { return; LuaStarts++; + g_LuaID++; get.LuaShared()!.UnMountLua("LuaMenu"); get.LuaShared()!.CloseLuaInterface(g_Lua); g_Lua = null; } public void StartLua() { + DestroyLoadingPanel(); + DestroyMenuPanels(); CloseLua(); MenuPanels.CreateMenuPanels(); @@ -158,7 +161,7 @@ static void DestroyLoadingPanel() { return; MenuPanels.g_hLoadingPanel.SetParent((Panel?)null); - MenuPanels.g_hLoadingPanel.MarkForDeletion(); + MenuPanels.g_hLoadingPanel.DeletePanel(); MenuPanels.g_hLoadingPanel = null; } @@ -167,7 +170,7 @@ static void DestroyMenuPanels() { if (MenuPanels.g_hMenuPanel != null) { MenuPanels.g_hMenuPanel.SetParent((Panel?)null); - MenuPanels.g_hMenuPanel.MarkForDeletion(); + MenuPanels.g_hMenuPanel.DeletePanel(); MenuPanels.g_hMenuPanel = null; } diff --git a/Source.GUI.Controls/Panel.cs b/Source.GUI.Controls/Panel.cs index ad7ce2316..cf05ad99b 100644 --- a/Source.GUI.Controls/Panel.cs +++ b/Source.GUI.Controls/Panel.cs @@ -1526,12 +1526,6 @@ public void ClearLuaReferences() { LuaObject?.UnReference(); LuaObject = null; } - - public virtual void ClearLuaReferencesRecursive() { - ClearLuaReferences(); - for (int i = 0; i < GetChildCount(); i++) - GetChild(i).ClearLuaReferencesRecursive(); - } #endif public virtual bool HasLuaTable() => LuaTable != null; From b10d2af23c8998d825d04de92ad98e3c1ecf109c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 21 Oct 2026 03:07:19 +0300 Subject: [PATCH 2/6] Fix local player staying set after the entity is released --- Game.Client/C_BasePlayer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Game.Client/C_BasePlayer.cs b/Game.Client/C_BasePlayer.cs index a43df8961..4fa44cba0 100644 --- a/Game.Client/C_BasePlayer.cs +++ b/Game.Client/C_BasePlayer.cs @@ -541,11 +541,11 @@ public C_CommandContext GetCommandContext() { return CommandContext; } - public override void Dispose() { - base.Dispose(); + public override void Term() { if (this == localPlayer) { localPlayer = null; } + base.Term(); } public float GetStepSize() => Local.StepSize; From 3ce3d8876f385ca6265a8ec18d09e3613cddb170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 21 Oct 2026 03:21:56 +0300 Subject: [PATCH 3/6] Kill client Lua on level shutdown like GMod --- Game.Client/HLClient.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Game.Client/HLClient.cs b/Game.Client/HLClient.cs index eed5f9b60..55654efdd 100644 --- a/Game.Client/HLClient.cs +++ b/Game.Client/HLClient.cs @@ -551,7 +551,9 @@ public void LevelShutdown() { // gHUD.LevelShutdown(); - // todo +#if GMOD_DLL + Game.Client.GarrysMod.GarrysMod.Lua.Kill(); +#endif } public LookupProxyInterfaceFn GetMaterialProxyInterfaceFn() { From c25b54f48ef52d009d35800b2038afdd38a8f8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 21 Oct 2026 03:26:41 +0300 Subject: [PATCH 4/6] Port HUD level shutdown --- Game.Client/HLClient.cs | 2 +- Game.Client/HUD/Hud.cs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Game.Client/HLClient.cs b/Game.Client/HLClient.cs index 55654efdd..bfecb02f1 100644 --- a/Game.Client/HLClient.cs +++ b/Game.Client/HLClient.cs @@ -549,7 +549,7 @@ public void LevelShutdown() { // StopAllRumbleEffects(); - // gHUD.LevelShutdown(); + gHUD.LevelShutdown(); #if GMOD_DLL Game.Client.GarrysMod.GarrysMod.Lua.Kill(); diff --git a/Game.Client/HUD/Hud.cs b/Game.Client/HUD/Hud.cs index 075264ef1..f142e37ca 100644 --- a/Game.Client/HUD/Hud.cs +++ b/Game.Client/HUD/Hud.cs @@ -216,6 +216,11 @@ public void VidInit() { ResetHUD(); } + public void LevelShutdown() { + foreach (var element in HudList) + element.LevelShutdown(); + } + public void InitColors(IScheme scheme) { ClrNormal = scheme.GetColor("Normal", new(255, 208, 64, 255)); ClrCaution = scheme.GetColor("Caution", new(255, 48, 0, 255)); From 265e5b242591ff9f4af4e6b61d9d6feff695f55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 21 Oct 2026 03:31:17 +0300 Subject: [PATCH 5/6] Fix removed search paths staying in the search order --- Source.Filesystem/SearchPathIDCollection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source.Filesystem/SearchPathIDCollection.cs b/Source.Filesystem/SearchPathIDCollection.cs index cfa33c4e5..03dca6d27 100644 --- a/Source.Filesystem/SearchPathIDCollection.cs +++ b/Source.Filesystem/SearchPathIDCollection.cs @@ -27,9 +27,9 @@ public bool OpenOrCreateCollection(in ReadOnlySpan pathID, out SearchPathC return true; } - public bool Remove(in ReadOnlySpan pathID) { - ulong hashID = pathID.Hash(); + public bool Remove(in ReadOnlySpan pathID) => Remove(pathID.Hash()); + public new bool Remove(ulong hashID) { base.Remove(hashID); searchPathNames.Remove(hashID); return pathOrder.Remove(hashID); From a2071e302f5799e21e4e0600b3ce98188783a552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 21 Oct 2026 03:36:52 +0300 Subject: [PATCH 6/6] Fix Steam game server not shutting down on level end --- Source.Engine/Server/SteamAuth.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source.Engine/Server/SteamAuth.cs b/Source.Engine/Server/SteamAuth.cs index dcc3805f4..174e70eb5 100644 --- a/Source.Engine/Server/SteamAuth.cs +++ b/Source.Engine/Server/SteamAuth.cs @@ -453,6 +453,8 @@ public void Shutdown() { if (!BIsActive()) return; + Steamworks.GameServer.Shutdown(); + HasActivePlayers = false; LogOnResult = false; SteamIDGS = CSteamID.NotInitYetGS;