142 lines
3.0 KiB
C#
142 lines
3.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Steamworks;
|
|
using UnityEngine;
|
|
|
|
[DisallowMultipleComponent]
|
|
public class SteamManager : MonoBehaviour
|
|
{
|
|
private static SteamManager s_instance;
|
|
|
|
private static bool s_EverInialized;
|
|
|
|
private bool m_bInitialized;
|
|
|
|
private SteamAPIWarningMessageHook_t m_SteamAPIWarningMessageHook;
|
|
|
|
public static bool hasSteamAppIdFile;
|
|
|
|
public static bool hasProblemWithLeaderboards;
|
|
|
|
public ulong gameId = 468920uL;
|
|
|
|
public ulong gameIdVR = 1024010uL;
|
|
|
|
public static SteamManager Instance
|
|
{
|
|
get
|
|
{
|
|
if (s_instance == null)
|
|
{
|
|
return new GameObject("SteamManager").AddComponent<SteamManager>();
|
|
}
|
|
return s_instance;
|
|
}
|
|
}
|
|
|
|
public static bool Initialized
|
|
{
|
|
get
|
|
{
|
|
return Instance.m_bInitialized;
|
|
}
|
|
}
|
|
|
|
private static void SteamAPIDebugTextHook(int nSeverity, StringBuilder pchDebugText)
|
|
{
|
|
Debug.LogWarning(pchDebugText);
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (s_instance != null)
|
|
{
|
|
UnityEngine.Object.Destroy(base.gameObject);
|
|
return;
|
|
}
|
|
s_instance = this;
|
|
if (!File.Exists(Path.Combine(Application.dataPath, "../666_steam_appid_Hubert.txt")))
|
|
{
|
|
hasSteamAppIdFile = File.Exists(Path.Combine(Application.dataPath, "../steam_appid.txt"));
|
|
}
|
|
if (s_EverInialized)
|
|
{
|
|
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((AppId_t)(uint)gameId))
|
|
{
|
|
Application.Quit();
|
|
return;
|
|
}
|
|
}
|
|
catch (DllNotFoundException ex)
|
|
{
|
|
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" + ex, this);
|
|
Application.Quit();
|
|
return;
|
|
}
|
|
m_bInitialized = SteamAPI.Init();
|
|
if (!m_bInitialized)
|
|
{
|
|
Debug.LogError("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.", this);
|
|
}
|
|
else
|
|
{
|
|
s_EverInialized = true;
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (m_bInitialized && (bool)GlobalSettings.Instance)
|
|
{
|
|
GlobalSettings.Instance.CheckBetaAccount();
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (s_instance == null)
|
|
{
|
|
s_instance = this;
|
|
}
|
|
if (m_bInitialized && m_SteamAPIWarningMessageHook == null)
|
|
{
|
|
m_SteamAPIWarningMessageHook = SteamAPIDebugTextHook;
|
|
SteamClient.SetWarningMessageHook(m_SteamAPIWarningMessageHook);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (!(s_instance != this))
|
|
{
|
|
s_instance = null;
|
|
if (m_bInitialized)
|
|
{
|
|
SteamAPI.Shutdown();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (m_bInitialized)
|
|
{
|
|
SteamAPI.RunCallbacks();
|
|
}
|
|
}
|
|
}
|