public static void UpdateItem(Item item) { if (fa.dontConnectSteam) { return; } if (!SteamManager.Initialized) { return; } //whats the next step for this item? //no reference? Ask steam for one, and return out if (!item.hasRef && !item.waitingForRef) { item.waitingForRef = true; RawFuncs.Print("1. Requesting: " + item.leaderboard); SteamAPICall_t hSteamAPICall = SteamUserStats.FindLeaderboard(item.leaderboard); m_findResult.Set(hSteamAPICall, OnFindLeaderboardResult); return; } //does it have a reference? if (item.hasRef && !item.waitingForUpload) { item.waitingForUpload = true; RawFuncs.Print("3. uploading score(" + item.score + ") to steam leaderboard(" + item.leaderboard + ")"); SteamAPICall_t hSteamAPICall = SteamUserStats.UploadLeaderboardScore(item.steamRef, s_leaderboardMethod, item.score, null, 0); m_uploadResult.Set(hSteamAPICall, OnLeaderboardUploadResult); } }
public static void Init() { RawFuncs.Print("Steam init! TestVer: 003"); SteamStatsAndAchievements.WhatsMySteamName(); leaderboardLabels = new string[totalNumOfLeaderboards]; leaderboardTypes = new FreshLevels.Type[totalNumOfLeaderboards]; queue = new List <Item>(); for (int i = 0; i < totalNumOfLeaderboards; i++) { leaderboardTypes[i] = FreshLevels.IndexForLevelLeaderboard(i); bool syncThis = true; if (PlayerPrefs.HasKey("Syncd_" + leaderboardTypes[i])) { int result = 0; result = PlayerPrefs.GetInt("Syncd_" + leaderboardTypes[i], 0); if (result == 1) { syncThis = false; } } if (syncThis) { float pb = PlayerPrefs.GetFloat("LevelTime_" + leaderboardTypes[i], -1); AddToQueue(FreshLevels.IndexForLevelLeaderboard(i), pb); RawFuncs.Print("" + leaderboardTypes[i] + ": " + pb + ", added to queue"); } } }
static private void OnLeaderboardUploadResult(LeaderboardScoreUploaded_t pCallback, bool failure) { RawFuncs.Print("4. STEAM LEADERBOARDS: failure - " + failure + " Completed - " + pCallback.m_bSuccess + " NewScore: " + pCallback.m_nGlobalRankNew + " Score " + pCallback.m_nScore + " HasChanged - " + pCallback.m_bScoreChanged); for (int i = 0; i < queue.Count; i++) { if (queue[i].open) { if (queue[i].waitingForUpload) { if (!failure) { queue[i].finished = true; queue[i].open = false; RawFuncs.Print("5. Success!"); PlayerPrefs.SetInt("Syncd_" + queue[i].type, 1); PlayerPrefs.Save(); } else { queue[i].finished = false; queue[i].waitingForUpload = false; //try again RawFuncs.Print("5b. Trying again..."); } } return; } } }
static private void OnFindLeaderboardResult(LeaderboardFindResult_t pCallback, bool failure) { RawFuncs.Print("2. " + Time.time + " STEAM LEADERBOARDS: Found - " + pCallback.m_bLeaderboardFound + " leaderboardID - " + pCallback.m_hSteamLeaderboard.m_SteamLeaderboard); for (int i = 0; i < queue.Count; i++) { if (queue[i].open) { if (queue[i].waitingForRef && !queue[i].hasRef) { queue[i].hasRef = true; queue[i].steamRef = pCallback.m_hSteamLeaderboard; } else { //the open one isn't waiting/already has a ref, which means it's probably the wrong one? //shoulnd't ever get here, but probably the packet got lost, then showed up later? //just ignore this result //(possibly kill this one, and add to it's timespent, as it might be better to move on?) } return; } } return; //RawFuncs.Print("" + Time.time + " STEAM LEADERBOARDS: Found - " + pCallback.m_bLeaderboardFound + " leaderboardID - " + pCallback.m_hSteamLeaderboard.m_SteamLeaderboard); //leaderboardSteamRefs[requestIndex] = pCallback.m_hSteamLeaderboard; //leaderboardFound[requestIndex] = true; //requestIndex++; //waiting = false; }
public static void WhatsMySteamName() { if (fa.dontConnectSteam) { return; } if (SteamManager.Initialized) { //Debug.Log("Name: " + SteamFriends.GetPersonaName()); RawFuncs.Print("Name: " + SteamFriends.GetPersonaName()); } }
public static void UpdateQueue() { if (fa.dontConnectSteam) { return; } if (!SteamManager.Initialized) { return; } //loop through, find the open one, update that. for (int i = 0; i < queue.Count; i++) { if (queue[i].open && !queue[i].finished) { queue[i].timespent += queueDelay; if (queue[i].timespent > queueGiveup) { //giving up RawFuncs.Print("Giving up on " + queue[i].leaderboard); queue[i].open = false; } else { UpdateItem(queue[i]); } return; } } //if it didn't find one, open one for (int i = 0; i < queue.Count; i++) { if (!queue[i].finished && queue[i].timespent < queueGiveup) //if I haven't already spent enough time attempting this one { RawFuncs.Print("Opening new item for " + queue[i].leaderboard); queue[i].open = true; return; } } }
private void Awake() { // Only one instance of SteamManager at a time! if (s_instance != null) { Destroy(gameObject); return; } s_instance = this; if (s_EverInialized) { // This is almost always an error. // The most common case where this happens is the SteamManager getting desstroyed via Application.Quit() and having some code in some OnDestroy which gets called afterwards, creating a new SteamManager. throw new System.Exception("Tried to Initialize the SteamAPI twice in one session!"); } // We want our SteamManager Instance to persist across scenes. DontDestroyOnLoad(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); RawFuncs.Print("[Steamworks.NET] Packsize Test returned false, the wrong version of Steamworks.NET is being run in this platform."); } 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); RawFuncs.Print("[Steamworks.NET] DllCheck Test returned false, One or more of the Steamworks binaries seems to be the wrong version."); } try { // If Steam is not running or the game wasn't started through Steam, SteamAPI_RestartAppIfNecessary starts the // Steam client and also launches this game again if the User owns it. This can act as a rudimentary form of DRM. // Once you get a Steam AppID assigned by Valve, you need to replace AppId_t.Invalid with it and // remove steam_appid.txt from the game depot. eg: "(AppId_t)480" or "new AppId_t(480)". // See the Valve documentation for more information: https://partner.steamgames.com/documentation/drm#FAQ if (SteamAPI.RestartAppIfNecessary(AppId_t.Invalid)) { Application.Quit(); return; } } catch (System.DllNotFoundException e) { // We catch this exception here, as it will be the first occurence of it. 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" + e, this); RawFuncs.Print("[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" + e); Application.Quit(); return; } // Initialize the SteamAPI, if Init() returns false this can happen for many reasons. // Some examples include: // Steam Client is not running. // Launching from outside of steam without a steam_appid.txt file in place. // Running under a different OS User or Access level (for example running "as administrator") // Valve's documentation for this is located here: // https://partner.steamgames.com/documentation/getting_started // https://partner.steamgames.com/documentation/example // Under: Common Build Problems // https://partner.steamgames.com/documentation/bootstrap_stats // At the very bottom // If you're running into Init issues try running DbgView prior to launching to get the internal output from Steam. // http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx m_bInitialized = SteamAPI.Init(); if (!m_bInitialized) { Debug.Log("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.", this); RawFuncs.Print("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information."); return; } s_EverInialized = true; }