diff --git a/Game.Client/C_BasePlayer.cs b/Game.Client/C_BasePlayer.cs index a43df896..4fa44cba 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; diff --git a/Game.Client/GarrysMod/GModBase.cs b/Game.Client/GarrysMod/GModBase.cs index 5f7fa428..8fd48c0e 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.Client/HLClient.cs b/Game.Client/HLClient.cs index eed5f9b6..bfecb02f 100644 --- a/Game.Client/HLClient.cs +++ b/Game.Client/HLClient.cs @@ -549,9 +549,11 @@ public void LevelShutdown() { // StopAllRumbleEffects(); - // gHUD.LevelShutdown(); + gHUD.LevelShutdown(); - // todo +#if GMOD_DLL + Game.Client.GarrysMod.GarrysMod.Lua.Kill(); +#endif } public LookupProxyInterfaceFn GetMaterialProxyInterfaceFn() { diff --git a/Game.Client/HUD/Hud.cs b/Game.Client/HUD/Hud.cs index 075264ef..f142e37c 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)); diff --git a/Game.MenuSystem/MenuSystem.cs b/Game.MenuSystem/MenuSystem.cs index b80e70af..ab134533 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.Engine/Server/SteamAuth.cs b/Source.Engine/Server/SteamAuth.cs index dcc3805f..174e70eb 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; diff --git a/Source.Filesystem/SearchPathIDCollection.cs b/Source.Filesystem/SearchPathIDCollection.cs index cfa33c4e..03dca6d2 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); diff --git a/Source.GUI.Controls/Panel.cs b/Source.GUI.Controls/Panel.cs index ad7ce231..cf05ad99 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;