diff options
Diffstat (limited to 'Client/Assembly-CSharp/SteamManager.cs')
-rw-r--r-- | Client/Assembly-CSharp/SteamManager.cs | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/SteamManager.cs b/Client/Assembly-CSharp/SteamManager.cs new file mode 100644 index 0000000..ce42f18 --- /dev/null +++ b/Client/Assembly-CSharp/SteamManager.cs @@ -0,0 +1,131 @@ +using System; +using System.Text; +using Steamworks; +using UnityEngine; + +[DisallowMultipleComponent] +public class SteamManager : MonoBehaviour +{ + private static SteamManager Instance + { + get + { + if (SteamManager.s_instance == null) + { + return new GameObject("SteamManager").AddComponent<SteamManager>(); + } + return SteamManager.s_instance; + } + } + + public static bool Initialized + { + get + { + return SteamManager.Instance.m_bInitialized; + } + } + + private static SteamManager s_instance; + + private static bool s_EverInitialized; + + private bool m_bInitialized; + + private SteamAPIWarningMessageHook_t m_SteamAPIWarningMessageHook; + + private static void SteamAPIDebugTextHook(int nSeverity, StringBuilder pchDebugText) + { + Debug.LogWarning(pchDebugText); + } + + private void Awake() + { + if (SteamManager.s_instance != null) + { + UnityEngine.Object.Destroy(base.gameObject); + return; + } + SteamManager.s_instance = this; + if (SteamManager.s_EverInitialized) + { + throw new Exception("Tried to Initialize the SteamAPI twice in one session!"); + } + UnityEngine.Object.DontDestroyOnLoad(base.gameObject); + if (!Packsize.Test()) + { + Debug.LogError("[Steamworks.NET] Packsize Test returned false, the wrong version of Steamworks.NET is being run in this platform.", this); + } + if (!DllCheck.Test()) + { + Debug.LogError("[Steamworks.NET] DllCheck Test returned false, One or more of the Steamworks binaries seems to be the wrong version.", this); + } + try + { + if (SteamAPI.RestartAppIfNecessary(new AppId_t(945360U))) + { + Application.Quit(); + return; + } + } + catch (DllNotFoundException arg) + { + Debug.LogError("[Steamworks.NET] Could not load [lib]steam_api.dll/so/dylib. It's likely not in the correct location. Refer to the README for more details.\n" + arg, this); + Application.Quit(); + return; + } + this.m_bInitialized = SteamAPI.Init(); + if (!this.m_bInitialized) + { + Debug.LogError("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.", this); + return; + } + SteamManager.s_EverInitialized = true; + } + + private void OnEnable() + { + if (SteamManager.s_instance == null) + { + SteamManager.s_instance = this; + } + if (!this.m_bInitialized) + { + return; + } + if (this.m_SteamAPIWarningMessageHook == null) + { + this.m_SteamAPIWarningMessageHook = new SteamAPIWarningMessageHook_t(SteamManager.SteamAPIDebugTextHook); + SteamClient.SetWarningMessageHook(this.m_SteamAPIWarningMessageHook); + } + } + + private void OnDestroy() + { + if (SteamManager.s_instance != this) + { + return; + } + SteamManager.s_instance = null; + if (!this.m_bInitialized) + { + return; + } + SteamAPI.Shutdown(); + } + + [ContextMenu("Shutdown")] + private void DoShutdown() + { + SteamAPI.Shutdown(); + } + + private void Update() + { + if (!this.m_bInitialized) + { + return; + } + SteamAPI.RunCallbacks(); + } +} |