Exemplo n.º 1
0
        public SteamworksPlugin(uint appId, int callbackFrequencyMs = 2000)
        {
            if (_init)
            {
                throw new Exception("Only one Steamworks Plugin can be active.");
            }

            _init = true;
            AppId = appId;

            _callbackRunner = new Every(callbackFrequencyMs, () => { SteamNative.RunCallbacks(); });

            LoadNative();
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            LoadFunctions();

            if (Engine.Configuration.DebugMode)
            {
                // If in debug mode, create app id file if missing.
                if (!File.Exists("steam_appid.txt"))
                {
                    File.WriteAllText("steam_appid.txt", AppId.ToString());
                }
            }
            else
            {
                // If not in debug mode, delete app id file.
                if (File.Exists("steam_appid.txt"))
                {
                    File.Delete("steam_appid.txt");
                }
            }

            Engine.Log.Info($"Initializing Steam plugin - app id is {AppId}", LOG_SOURCE);

            // Check if we should restart.
            bool necessary = SteamNative.RestartAppIfNecessary(AppId);

            if (necessary)
            {
                Engine.Log.Warning("Steam API said we should restart.", LOG_SOURCE);
                Engine.Quit();
            }

            bool steamOpen = SteamNative.IsSteamRunning();

            if (!steamOpen)
            {
                Engine.Log.Warning("Steam is not running.", LOG_SOURCE);
                Engine.Quit();
            }

            try
            {
                bool initialized = SteamNative.Init();
                if (!initialized)
                {
                    Engine.Log.Warning("Steam didn't initialize.", LOG_SOURCE);
                    Engine.Quit();
                }
            }
            catch (Exception ex)
            {
                Engine.Log.Error($"Error while initializing Steam - {ex}.", LOG_SOURCE);
                Engine.Quit();
            }

            // Initialize Steam modules.
            _steamClient    = SteamNative.GetSteamClient();
            _steamPipe      = SteamNative.GetSteamPipe();
            _steamUser      = SteamNative.GetSteamUser();
            _steamUtils     = SteamNative.GetSteamUtils(_steamClient, _steamPipe, Constants.STEAMUTILS_INTERFACE_VERSION);
            _steamUserStats = SteamNative.GetSteamUserStats(_steamClient, _steamUser, _steamPipe, Constants.STEAMUSERSTATS_INTERFACE_VERSION);

            // Attach warning callback.
            SteamNative.SetWarningMessageHook(_steamUtils, _warningHook);

            bool statsReceived = SteamNative.RequestStats(_steamUserStats);

            if (!statsReceived)
            {
                Engine.Log.Warning("User is not logged in to Steam.", LOG_SOURCE);
            }

            SteamNative.RunCallbacks();
            Engine.CoroutineManager.StartCoroutine(UpdateRoutine());
        }