int SteamGlobal::init() { #if defined(CHOWDREN_FORCE_STEAM_OPEN) && defined(CHOWDREN_STEAM_APPID) if (SteamAPI_RestartAppIfNecessary(CHOWDREN_STEAM_APPID)) { return EXIT_FAILURE; } #endif initialized = SteamAPI_Init(); if (!initialized) { std::cout << "Could not initialize Steam API" << std::endl; #ifdef CHOWDREN_FORCE_STEAM_OPEN SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Steam error", "Could not initialize Steam API. " "Please make sure you are logged in to Steam " "before opening the game.", NULL); return EXIT_FAILURE; #endif return 0; } std::cout << "Initialized Steam API" << std::endl; bool debug_achievements = getenv("CHOWDREN_DEBUG_ACHIEVEMENTS") != NULL; if (debug_achievements) { if (!SteamUserStats()->ResetAllStats(true)) std::cout << "Could not reset stats" << std::endl; } if (!SteamUserStats()->RequestCurrentStats()) std::cout << "Could not request Steam stats" << std::endl; #ifdef CHOWDREN_STEAM_APPID ISteamApps * ownapp = SteamApps(); if (!ownapp->BIsSubscribedApp(CHOWDREN_STEAM_APPID)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Steam error", "Please purchase the Steam version of the " "game if you want to play it on Steam.", NULL); return EXIT_FAILURE; } #endif steam_language = SteamApps()->GetCurrentGameLanguage(); if (steam_language.empty()) steam_language = "english"; steam_language[0] = toupper(steam_language[0]); std::cout << "Detected Steam language: " << steam_language << std::endl; return 0; }
bool SteamObject::has_app(int app) { #ifdef CHOWDREN_ENABLE_STEAM if (!global_steam_obj.initialized) return false; return SteamApps()->BIsSubscribedApp(app); #else return false; #endif }
bool SteamObject::is_activated() { #ifdef CHOWDREN_ENABLE_STEAM if (!global_steam_obj.initialized) #ifdef CHOWDREN_FORCE_STEAM_OPEN return false; #else return true; #endif SteamUserStats()->RequestCurrentStats(); ISteamApps * ownapp = SteamApps(); return ownapp->BIsSubscribedApp(CHOWDREN_STEAM_APPID); #else return true; #endif }
int SteamClient::getSteamVRBuildID() { if (initialized) { static const int MAX_PATH_SIZE = 512; static const int STEAMVR_APPID = 250820; char rawPath[MAX_PATH_SIZE]; SteamApps()->GetAppInstallDir(STEAMVR_APPID, rawPath, MAX_PATH_SIZE); QString path(rawPath); path += "\\bin\\version.txt"; qDebug() << "SteamVR version file path:" << path; QFile file(path); if (file.open(QIODevice::ReadOnly)) { QString buildIDString = file.readLine(); bool ok = false; int buildID = buildIDString.toInt(&ok); if (ok) { return buildID; } } } return 0; }
//----------------------------------------------------------------------------- // Purpose: interface to app data //----------------------------------------------------------------------------- DLL(ISteamApps*) BS_SteamApps() { return SteamApps(); }
SW_PY bool IsDlcInstalled(int32 value) { return SteamApps()->BIsDlcInstalled(value); }
// Steam Apps SW_PY int GetDlcCount(){ return SteamApps()->GetDLCCount(); }
bool FOnlineSubsystemSteam::InitSteamworksClient(bool bRelaunchInSteam, int32 SteamAppId) { bSteamworksClientInitialized = false; // If the game was not launched from within Steam, but is supposed to, trigger a Steam launch and exit if (bRelaunchInSteam && SteamAppId != 0 && SteamAPI_RestartAppIfNecessary(SteamAppId)) { if (FPlatformProperties::IsGameOnly() || FPlatformProperties::IsServerOnly()) { UE_LOG_ONLINE(Log, TEXT("Game restarting within Steam client, exiting")); FPlatformMisc::RequestExit(false); } return bSteamworksClientInitialized; } // Otherwise initialize as normal else { // Steamworks needs to initialize as close to start as possible, so it can hook its overlay into Direct3D, etc. bSteamworksClientInitialized = (SteamAPI_Init() ? true : false); // Test all the Steam interfaces #define GET_STEAMWORKS_INTERFACE(Interface) \ if (Interface() == nullptr) \ { \ UE_LOG_ONLINE(Warning, TEXT("Steamworks: %s() failed!"), TEXT(#Interface)); \ bSteamworksClientInitialized = false; \ } \ // GSteamUtils GET_STEAMWORKS_INTERFACE(SteamUtils); // GSteamUser GET_STEAMWORKS_INTERFACE(SteamUser); // GSteamFriends GET_STEAMWORKS_INTERFACE(SteamFriends); // GSteamRemoteStorage GET_STEAMWORKS_INTERFACE(SteamRemoteStorage); // GSteamUserStats GET_STEAMWORKS_INTERFACE(SteamUserStats); // GSteamMatchmakingServers GET_STEAMWORKS_INTERFACE(SteamMatchmakingServers); // GSteamApps GET_STEAMWORKS_INTERFACE(SteamApps); // GSteamNetworking GET_STEAMWORKS_INTERFACE(SteamNetworking); // GSteamMatchmaking GET_STEAMWORKS_INTERFACE(SteamMatchmaking); #undef GET_STEAMWORKS_INTERFACE } if (bSteamworksClientInitialized) { bool bIsSubscribed = true; if (FPlatformProperties::IsGameOnly() || FPlatformProperties::IsServerOnly()) { bIsSubscribed = SteamApps()->BIsSubscribed(); } // Make sure the Steam user has valid access to the game if (bIsSubscribed) { UE_LOG_ONLINE(Log, TEXT("Steam User is subscribed %i"), bSteamworksClientInitialized); if (SteamUtils()) { SteamAppID = SteamUtils()->GetAppID(); SteamUtils()->SetWarningMessageHook(SteamworksWarningMessageHook); } } else { UE_LOG_ONLINE(Error, TEXT("Steam User is NOT subscribed, exiting.")); bSteamworksClientInitialized = false; FPlatformMisc::RequestExit(false); } } UE_LOG_ONLINE(Log, TEXT("[AppId: %d] Client API initialized %i"), GetSteamAppId(), bSteamworksClientInitialized); return bSteamworksClientInitialized; }