diff --git a/Facepunch.Steamworks/SteamClient.cs b/Facepunch.Steamworks/SteamClient.cs index 6369c4c..be83d68 100644 --- a/Facepunch.Steamworks/SteamClient.cs +++ b/Facepunch.Steamworks/SteamClient.cs @@ -79,13 +79,23 @@ internal static async void RunCallbacksAsync() public static void Shutdown() { - Event.DisposeAllClient(); - - initialized = false; + if ( !IsValid ) return; SteamInput.Shutdown(); + Cleanup(); + + SteamAPI.Shutdown(); + } + + internal static void Cleanup() + { + initialized = false; + + Event.DisposeAllClient(); ShutdownInterfaces(); + + SteamInput.Shutdown(); SteamApps.Shutdown(); SteamUtils.Shutdown(); SteamParental.Shutdown(); @@ -101,10 +111,7 @@ public static void Shutdown() SteamParties.Shutdown(); SteamNetworkingUtils.Shutdown(); SteamNetworkingSockets.Shutdown(); - ServerList.Base.Shutdown(); - - SteamAPI.Shutdown(); } internal static void RegisterCallback( IntPtr intPtr, int callbackId ) @@ -114,6 +121,8 @@ internal static void RegisterCallback( IntPtr intPtr, int callbackId ) public static void RunCallbacks() { + if ( !IsValid ) return; + try { SteamAPI.RunCallbacks(); diff --git a/Facepunch.Steamworks/SteamInput.cs b/Facepunch.Steamworks/SteamInput.cs index fa5ae92..af3c485 100644 --- a/Facepunch.Steamworks/SteamInput.cs +++ b/Facepunch.Steamworks/SteamInput.cs @@ -24,7 +24,11 @@ internal static ISteamInput Internal internal static void Shutdown() { - _internal?.DoShutdown(); + if ( _internal != null && _internal.IsValid ) + { + _internal.DoShutdown(); + } + _internal = null; } diff --git a/Facepunch.Steamworks/SteamUtils.cs b/Facepunch.Steamworks/SteamUtils.cs index 2cbf2ef..04dbe65 100644 --- a/Facepunch.Steamworks/SteamUtils.cs +++ b/Facepunch.Steamworks/SteamUtils.cs @@ -36,10 +36,17 @@ internal static void InstallEvents() { IPCountry_t.Install( x => OnIpCountryChanged?.Invoke() ); LowBatteryPower_t.Install( x => OnLowBatteryPower?.Invoke( x.MinutesBatteryLeft ) ); - SteamShutdown_t.Install( x => OnSteamShutdown?.Invoke() ); + SteamShutdown_t.Install( x => SteamClosed() ); GamepadTextInputDismissed_t.Install( x => OnGamepadTextInputDismissed?.Invoke( x.Submitted ) ); } + private static void SteamClosed() + { + SteamClient.Cleanup(); + + OnSteamShutdown?.Invoke(); + } + /// /// The country of the user changed /// diff --git a/Facepunch.Steamworks/Utility/Platform.cs b/Facepunch.Steamworks/Utility/Platform.cs index 42749af..1145021 100644 --- a/Facepunch.Steamworks/Utility/Platform.cs +++ b/Facepunch.Steamworks/Utility/Platform.cs @@ -34,7 +34,7 @@ internal static class Platform public static int MemoryOffset( int memLocation ) { -#if PLATFORM_WIN64 || PLATFORM_POSIX64 +#if PLATFORM_64 return memLocation; #else return memLocation / 2; diff --git a/Facepunch.Steamworks/Utility/SteamInterface.cs b/Facepunch.Steamworks/Utility/SteamInterface.cs index e983cde..d9d10ba 100644 --- a/Facepunch.Steamworks/Utility/SteamInterface.cs +++ b/Facepunch.Steamworks/Utility/SteamInterface.cs @@ -15,6 +15,7 @@ internal abstract class SteamInterface public IntPtr VTable; public virtual string InterfaceName => null; + public bool IsValid => Self != IntPtr.Zero && VTable != IntPtr.Zero; public void Init() {