Handle steam shutdown nicer

This commit is contained in:
Garry Newman 2019-07-02 14:12:55 +01:00
parent 38b1ed5f88
commit c6c73a36e9
5 changed files with 30 additions and 9 deletions

View File

@ -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();

View File

@ -24,7 +24,11 @@ internal static ISteamInput Internal
internal static void Shutdown()
{
_internal?.DoShutdown();
if ( _internal != null && _internal.IsValid )
{
_internal.DoShutdown();
}
_internal = null;
}

View File

@ -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();
}
/// <summary>
/// The country of the user changed
/// </summary>

View File

@ -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;

View File

@ -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()
{