Пример #1
0
int32 UAdvancedFriendsLibrary::GetFriendSteamLevel(APlayerController *PlayerController, const FBPUniqueNetId UniqueNetId)
{

	if (!PlayerController)
	{
		UE_LOG(AdvancedFriendsLog, Warning, TEXT("IsAFriend Had a bad Player Controller!"));
		return 0;
	}

	if (!UniqueNetId.IsValid() || !UniqueNetId.UniqueNetId->IsValid())
	{
		UE_LOG(AdvancedFriendsLog, Warning, TEXT("IsAFriend Had a bad UniqueNetId!"));
		return 0;
	}

	if (SteamAPI_Init())
	{
		uint64 id = *((uint64*)UniqueNetId.UniqueNetId->GetBytes());

		return SteamFriends()->GetFriendSteamLevel(id);
	}

	return 0;


}
Пример #2
0
bool CSteamCtx::Connect (CString *retsError)

//  Connect
//
//  Connect to Steam.

    {
    if (m_bConnected)
        return true;

	//	Boot up steam

	if (!SteamAPI_Init())
		{
        if (retsError) *retsError = CONSTLIT("Unable to initialize Steam API.");
		m_bConnected = false;
		return false;
		}

    //  We're enabled

	m_sUsername = CString(CString::csUTF8, SteamFriends()->GetPersonaName());
    m_bConnected = true;
    return true;
    }
Пример #3
0
/* <ed99c> ../engine/sv_steam3.cpp:827 */
void CSteam3Client::InitClient()
{
    if (m_bLoggedOn)
        return;

    m_bLoggedOn = true;
    _unlink("steam_appid.txt");
    if (!getenv("SteamAppId"))
    {
        int nAppID = GetGameAppID();
        if (nAppID > 0)
        {
            FILE* f = fopen("steam_appid.txt", "w+");
            if (f)
            {
                fprintf(f, "%d\n", nAppID);
                fclose(f);
            }
        }
    }

    if (!SteamAPI_Init())
        Sys_Error("Failed to initalize authentication interface. Exiting...\n");

    m_bLogOnResult = false;
}
Пример #4
0
	bool SteamAPI::Init()
	{
		bool result = SteamAPI_Init();

		if (result)
			_instance = gcnew SteamAPI();
		return result;
	}
Пример #5
0
static PyObject *steam_init(PyObject *self, PyObject *args) {
	bool success = SteamAPI_Init();
	if (success) {
		Py_RETURN_NONE;
	}
	else {
		PyErr_SetString(SteamInitError, "Steam initialization failed!  Either Steam is not running or steam_appid.txt is not in your root folder.");
		Py_RETURN_NONE;
	};
};
Пример #6
0
void init_steamworks()
{
	// Initialize Steam
	bool bRet = SteamAPI_Init();
	// Create the SteamAchievements object if Steam was successfully initialized
	if (bRet)
	{
		g_SteamAchievements = new CSteamAchievements(g_Achievements, NUM_ACHIEVEMENTS);
	}
}
Пример #7
0
//-----------------------------------------------------------------------------
// Purpose: Initialize the steam3 connection
//-----------------------------------------------------------------------------
void CSteam3Client::Activate()
{
	if ( m_bActive )
		return;

	m_bActive = true;
	m_bGSSecure = false;

#if !defined( NO_STEAM )
	SteamAPI_Init(); // ignore failure, that will fall out later when they don't get a valid logon cookie
#endif
}
Пример #8
0
bool TPortal_Startup()
{
	bool bOkay = SteamAPI_Init();

	if (!bOkay)
		return false;

	// 127.0.0.1 = 2130706433
	SteamUser()->InitiateGameConnection( NULL, 0, k_steamIDNonSteamGS, 2130706433, 30203, false );
	SteamUtils()->SetOverlayNotificationPosition( k_EPositionBottomLeft );

	return true;
}
Пример #9
0
int Steam::init()
{
	//printf("Godot steam init\n");
	isInitSuccess = SteamAPI_Init();
	int err = FAILED;
	if (isInitSuccess)
		{ err = OK; }
	
	if ( !SteamAPI_IsSteamRunning() )
		{ err = ERR_NO_CLIENT; }
	else if ( !SteamUser()->BLoggedOn() )
		{ err = ERR_NO_CONNECTION; }
	
	return err;
}
Пример #10
0
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;
}
Пример #11
0
// ====================================================================================================================================================================================================
// Load game achievements
void hedGameAchievements::LoadAchievements()                                                 
{
	FILE* file;
	int   i;
	
	file = fopen(sysGetAppDataPath("achievements.dat"),"rt");
	
	// Create new achievements file, if it doesn't exist
	if(file == NULL)
	{
		for(i = 0; i < HED_ACHIEVEMENT_COUNT; i++)
        {
            achievementValue[i]  = 0;
			achievementStatus[i] = 0;
        }
        SaveAchievements();
		return;
	}

	// Load achievements
	for(i = 0; i < HED_ACHIEVEMENT_COUNT; i++)
    {
		fscanf(file,"%d\n",&achievementStatus[i]);
		fscanf(file,"%d\n",&achievementValue[i]);
    }
	fclose(file);

    // STEAM achievements
#if defined(BUILD_STEAM)
    if(SteamAPI_Init())
    //{
        //sysLogPrint("hedGameAchievements::LoadAchievements() - SteamAPI_Init() returned OK.");
        g_SteamAchievements = new CSteamAchievements(g_Achievements, 7);
		g_SteamLeaderboards = new CSteamLeaderboards();
		g_SteamLeaderboards->FindLeaderboard("Hacker Evolution Duality highscores");

		g_SteamStats = new CSteamStats(g_Stats, 1);
    //}
    //else
    //    sysLogPrint("hedGameAchievements::LoadAchievements() - SteamAPI_Init() failed.");
#endif
}
Пример #12
0
bool UAdvancedFriendsLibrary::RequestSteamFriendInfo(APlayerController *PlayerController, const FBPUniqueNetId UniqueNetId)
{
	if (!PlayerController)
	{
		UE_LOG(AdvancedFriendsLog, Warning, TEXT("IsAFriend Had a bad Player Controller!"));
		return false;
	}

	if (!UniqueNetId.IsValid() || !UniqueNetId.UniqueNetId->IsValid())
	{
		UE_LOG(AdvancedFriendsLog, Warning, TEXT("IsAFriend Had a bad UniqueNetId!"));
		return false;
	}

	if (SteamAPI_Init())
	{
		uint64 id = *((uint64*)UniqueNetId.UniqueNetId->GetBytes());

		return !SteamFriends()->RequestUserInformation(id, false);
	}

	return false;
}
Пример #13
0
static int RealMain( const char *pchCmdLine, HINSTANCE hInstance, int nCmdShow )
{

    if ( SteamAPI_RestartAppIfNecessary( k_uAppIdInvalid ) )
    {
        // if Steam is not running or the game wasn't started through Steam, SteamAPI_RestartAppIfNecessary starts the
        // local Steam client and also launches this game again.

        // Once you get a public Steam AppID assigned for this game, you need to replace k_uAppIdInvalid with it and
        // removed steam_appid.txt from the game depot.

        return EXIT_FAILURE;
    }


    // Init Steam CEG
    if ( !Steamworks_InitCEGLibrary() )
    {
        OutputDebugString( "Steamworks_InitCEGLibrary() failed\n" );
        Alert( "Fatal Error", "Steam must be running to play this game (InitDrmLibrary() failed).\n" );
        return EXIT_FAILURE;
    }

    // Initialize SteamAPI, if this fails we bail out since we depend on Steam for lots of stuff.
    // You don't necessarily have to though if you write your code to check whether all the Steam
    // interfaces are NULL before using them and provide alternate paths when they are unavailable.
    //
    // This will also load the in-game steam overlay dll into your process.  That dll is normally
    // injected by steam when it launches games, but by calling this you cause it to always load,
    // even when not launched via steam.
    if ( !SteamAPI_Init() )
    {
        OutputDebugString( "SteamAPI_Init() failed\n" );
        Alert( "Fatal Error", "Steam must be running to play this game (SteamAPI_Init() failed).\n" );
        return EXIT_FAILURE;
    }

    // set our debug handler
    SteamClient()->SetWarningMessageHook( &SteamAPIDebugTextHook );

    // Tell Steam where it's overlay should show notification dialogs, this can be top right, top left,
    // bottom right, bottom left. The default position is the bottom left if you don't call this.
    // Generally you should use the default and not call this as users will be most comfortable with
    // the default position.  The API is provided in case the bottom right creates a serious conflict
    // with important UI in your game.
    SteamUtils()->SetOverlayNotificationPosition( k_EPositionTopRight );

    // Ensure that the user has logged into Steam. This will always return true if the game is launched
    // from Steam, but if Steam is at the login prompt when you run your game from the debugger, it
    // will return false.
    if ( !SteamUser()->BLoggedOn() )
    {
        OutputDebugString( "Steam user is not logged in\n" );
        Alert( "Fatal Error", "Steam user must be logged in to play this game (SteamUser()->BLoggedOn() returned false).\n" );
        return EXIT_FAILURE;
    }

    // We are going to use the controller interface, initialize it, which is a seperate step as it
    // create a new thread in the game proc and we don't want to force that on games that don't
    // have native Steam controller implementations

    char rgchCWD[1024];
    _getcwd( rgchCWD, sizeof( rgchCWD ) );

    char rgchFullPath[1024];
#if defined(_WIN32)
    _snprintf( rgchFullPath, sizeof( rgchFullPath ), "%s\\%s", rgchCWD, "controller.vdf" );
#elif defined(OSX)
    // hack for now, because we do not have utility functions available for finding the resource path
    // alternatively we could disable the SteamController init on OS X
    _snprintf( rgchFullPath, sizeof( rgchFullPath ), "%s/steamworksexample.app/Contents/Resources/%s", rgchCWD, "controller.vdf" );
#else
    _snprintf( rgchFullPath, sizeof( rgchFullPath ), "%s/%s", rgchCWD, "controller.vdf" );
#endif
    if( !SteamController()->Init( rgchFullPath ) )
    {
        OutputDebugString( "SteamController()->Init() failed\n" );
        Alert( "Fatal Error", "Steam Controller Init failed. Is controller.vdf in the current working directory?\n" );
        return EXIT_FAILURE;
    }

    bool bUseVR = SteamUtils()->IsSteamRunningInVR();
    const char *pchServerAddress, *pchLobbyID;
    ParseCommandLine( pchCmdLine, &pchServerAddress, &pchLobbyID, &bUseVR );

    // do a DRM self check
    Steamworks_SelfCheck();

    // init VR before we make the window

    // Construct a new instance of the game engine
    // bugbug jmccaskey - make screen resolution dynamic, maybe take it on command line?
    IGameEngine *pGameEngine =
#if defined(_WIN32)
        new CGameEngineWin32( hInstance, nCmdShow, 1024, 768, bUseVR );
#elif defined(OSX)
        CreateGameEngineOSX();
#elif defined(SDL)
        CreateGameEngineSDL( bUseVR );
#else
#error	Need CreateGameEngine()
#endif

    // This call will block and run until the game exits
    RunGameLoop( pGameEngine, pchServerAddress, pchLobbyID );

    // Shutdown the SteamAPI
    SteamController()->Shutdown();
    SteamAPI_Shutdown();

    // Shutdown Steam CEG
    Steamworks_TermCEGLibrary();

    // exit
    return EXIT_SUCCESS;
}
	FSteamController(const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler)
		: MessageHandler(InMessageHandler)
	{
		// Attempt to load the Steam Library
		if (!LoadSteamModule())
		{
			return;
		}

		// Initialize the API, so we can start calling SteamController functions
		bool bAPIInitialized = SteamAPI_Init();

			// [RCL] 2015-01-23 FIXME: move to some other code than constructor so we can handle failures more gracefully
		if (bAPIInitialized && (SteamController() != nullptr))
		{
			FString PluginsDir = FPaths::EnginePluginsDir();
			FString ContentDir = FPaths::Combine(*PluginsDir, TEXT("Runtime"), TEXT("Steam"), TEXT("SteamController"), TEXT("Content"));
			FString VdfPath = FPaths::ConvertRelativePathToFull(FPaths::Combine(*ContentDir, TEXT("Controller.vdf")));

			bool bInited = SteamController()->Init(TCHAR_TO_ANSI(*VdfPath));
			UE_LOG(LogSteamController, Log, TEXT("SteamController %s initialized with vdf file '%s'."), bInited ? TEXT("could not be") : TEXT("has been"), *VdfPath);

			// [RCL] 2014-05-05 FIXME: disable when could not init?
			if (bInited)
			{
				FMemory::Memzero(ControllerStates, sizeof(ControllerStates));
			}
		}
		else
		{
			UE_LOG(LogSteamController, Log, TEXT("SteamController is not available"));
		}

		InitialButtonRepeatDelay = 0.2f;
		ButtonRepeatDelay = 0.1f;

		// set up mapping
		Buttons[0] = FGamepadKeyNames::FaceButtonBottom;
		Buttons[1] = FGamepadKeyNames::FaceButtonRight;
		Buttons[2] = FGamepadKeyNames::FaceButtonLeft;
		Buttons[3] = FGamepadKeyNames::FaceButtonTop;
		Buttons[4] = FGamepadKeyNames::LeftShoulder;
		Buttons[5] = FGamepadKeyNames::RightShoulder;
		Buttons[6] = FGamepadKeyNames::SpecialRight;
		Buttons[7] = FGamepadKeyNames::SpecialLeft;
		Buttons[8] = FGamepadKeyNames::LeftThumb;
		Buttons[9] = FGamepadKeyNames::RightThumb;
		Buttons[10] = FGamepadKeyNames::LeftTriggerThreshold;
		Buttons[11] = FGamepadKeyNames::RightTriggerThreshold;
		Buttons[12] = SteamControllerKeyNames::Touch0;
		Buttons[13] = SteamControllerKeyNames::Touch1;
		Buttons[14] = SteamControllerKeyNames::Touch2;
		Buttons[15] = SteamControllerKeyNames::Touch3;
		Buttons[16] = FGamepadKeyNames::LeftStickUp;
		Buttons[17] = FGamepadKeyNames::LeftStickDown;
		Buttons[18] = FGamepadKeyNames::LeftStickLeft;
		Buttons[19] = FGamepadKeyNames::LeftStickRight;
		Buttons[20] = FGamepadKeyNames::RightStickUp;
		Buttons[21] = FGamepadKeyNames::RightStickDown;
		Buttons[22] = FGamepadKeyNames::RightStickLeft;
		Buttons[23] = FGamepadKeyNames::RightStickRight;
		Buttons[24] = SteamControllerKeyNames::BackLeft;
		Buttons[25] = SteamControllerKeyNames::BackLeft;
	}
Пример #15
0
SB_API bool S_CALLTYPE Init() {
	return SteamAPI_Init();
}
Пример #16
0
SB_API bool S_CALLTYPE Init(SteamPS3Params_t *pParams) {
	return SteamAPI_Init(pParams);
}
Пример #17
0
int main(int argc, char *argv[]) {
    if (argc != 2) {
        std::cerr << "Usage: ./broiler dir_with_replays" << std::endl;
        return 1;
    }
    std::string directory(argv[1]);

    // init steam
    if (SteamAPI_RestartAppIfNecessary(k_uAppIdInvalid))
        return 1;
    if (!SteamAPI_Init()) {
        Error("Fatal Error", "Steam must be running (SteamAPI_Init() failed).\n");
        return 1;
    }
    if (!SteamUser()->BLoggedOn()) {
        Error("Fatal Error",
              "Steam user must be logged in (SteamUser()->BLoggedOn() returned false).\n");
        return 1;
    }

    bool running = true;
    auto cbthread = std::thread([&running]() {
        while (running) {
            try {
                std::this_thread::sleep_for(std::chrono::milliseconds(50));
                Steam_RunCallbacks(GetHSteamPipe(), false);
            } catch (BoilerException &e) {
                Error("Fatal Error", e.what());
                exit(1);
            }
        };
    });

    int res = 0;

    try {
        // make sure we are connected to the gc
        CSGOClient::GetInstance()->WaitForGcConnect();

        // refresh match list
        CSGOMatchList refresher;
        refresher.RefreshWait();
        std::vector<CDataGCCStrike15_v2_MatchInfo> matches = refresher.Matches();
        for (auto &match : matches) {
            CMsgGCCStrike15_v2_MatchmakingServerRoundStats* rs = getLegacyRoundStats(match);
            if (!rs) {
                std::cerr << "Cannot get info for match" << std::endl;
                continue;
            }
            std::string dotDemFile = directory + "/" + dotDem(match, *rs);
            std::string dotDemDotInfoFile = dotDemFile + ".info";
            std::string link = rs->map();

            if (!file_exists(dotDemDotInfoFile)) {
                rs->clear_map();
                std::cerr << "Creating " << dotDemDotInfoFile << std::endl;
                std::ofstream myfile;
                myfile.open(dotDemDotInfoFile, std::ios::binary);
                if (!match.SerializeToOstream(&myfile))
                    Error("Error", std::string("Cannot serialize to file ") + dotDemDotInfoFile);
                myfile.close();
            }

            if (!file_exists(dotDemFile))
                std::cout << link << std::endl;
        }
    } catch (BoilerException &e) {
        Error("Fatal error", e.what());
        res = 1;
    }

    // shutdown
    running = false;
    cbthread.join();
    CSGOClient::Destroy();

    SteamAPI_Shutdown();
    return res;
}
Пример #18
0
UTexture2D * UAdvancedFriendsLibrary::GetSteamFriendAvatar(APlayerController *PlayerController, const FBPUniqueNetId UniqueNetId, SteamAvatarSize AvatarSize)
{
	if (!PlayerController)
	{
		UE_LOG(AdvancedFriendsLog, Warning, TEXT("IsAFriend Had a bad Player Controller!"));
		return nullptr;
	}

	if (!UniqueNetId.IsValid() || !UniqueNetId.UniqueNetId->IsValid())
	{
		UE_LOG(AdvancedFriendsLog, Warning, TEXT("IsAFriend Had a bad UniqueNetId!"));
		return nullptr;
	}

	uint32 Width = 0;
	uint32 Height = 0;

	if (SteamAPI_Init())
	{
		//Getting the PictureID from the SteamAPI and getting the Size with the ID
		//virtual bool RequestUserInformation( CSteamID steamIDUser, bool bRequireNameOnly ) = 0;

		
		uint64 id = *((uint64*)UniqueNetId.UniqueNetId->GetBytes());
		int Picture = 0;
		
		switch(AvatarSize)
		{
		case SteamAvatarSize::SteamAvatar_Small: Picture = SteamFriends()->GetSmallFriendAvatar(id); break;
		case SteamAvatarSize::SteamAvatar_Medium: Picture = SteamFriends()->GetMediumFriendAvatar(id); break;
		case SteamAvatarSize::SteamAvatar_Large: Picture = SteamFriends()->GetLargeFriendAvatar(id); break;
		default: break;
		}

		if (Picture == -1)
			return NULL;

		SteamUtils()->GetImageSize(Picture, &Width, &Height);

		// STOLEN FROM ANSWERHUB :p

		if (Width > 0 && Height > 0)
		{
			//Creating the buffer "oAvatarRGBA" and then filling it with the RGBA Stream from the Steam Avatar
			uint8 *oAvatarRGBA = new uint8[Width * Height * 4];


			//Filling the buffer with the RGBA Stream from the Steam Avatar and creating a UTextur2D to parse the RGBA Steam in
			SteamUtils()->GetImageRGBA(Picture, (uint8*)oAvatarRGBA, 4 * Height * Width * sizeof(char));


			// Removed as I changed the image bit code to be RGB
			/*
			//Swap R and B channels because for some reason the games whack
			for (uint32 i = 0; i < (Width * Height * 4); i += 4)
			{
				uint8 Temp = oAvatarRGBA[i + 0];
				oAvatarRGBA[i + 0] = oAvatarRGBA[i + 2];
				oAvatarRGBA[i + 2] = Temp;
			}*/

			UTexture2D* Avatar = UTexture2D::CreateTransient(Width, Height, PF_R8G8B8A8);

			uint8* MipData = (uint8*)Avatar->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
			FMemory::Memcpy(MipData, (void*)oAvatarRGBA, Height * Width * 4);
			Avatar->PlatformData->Mips[0].BulkData.Unlock();

			// Original implementation was missing this!!
			// the hell man......
			delete[] oAvatarRGBA;

			//Setting some Parameters for the Texture and finally returning it
			Avatar->PlatformData->NumSlices = 1;
			Avatar->NeverStream = true;
			//Avatar->CompressionSettings = TC_EditorIcon;

			Avatar->UpdateResource();

			return Avatar;
		}
		else
		{
			UE_LOG(AdvancedFriendsLog, Warning, TEXT("Bad Height / Width with steam avatar!"));
		}

		return nullptr;
	}

	UE_LOG(AdvancedFriendsLog, Warning, TEXT("STEAM Couldn't be verified as initialized"));
	return nullptr;
}
Пример #19
0
bool SteamVR::Init()
{
  if (SteamAPI_RestartAppIfNecessary(k_uAppIdInvalid))
  {
    // if Steam is not running or the game wasn't started through Steam, SteamAPI_RestartAppIfNecessary starts the 
    // local Steam client and also launches this game again.

    // Once you get a public Steam AppID assigned for this game, you need to replace k_uAppIdInvalid with it and
    // removed steam_appid.txt from the game depot.
    return false;
  }

  if (!SteamAPI_Init())
  {
    Log("SteamAPI_Init() failed\n");
    return false;
  }

  // set our debug handler
  //SteamClient()->SetWarningMessageHook(&SteamAPIDebugTextHook);

  // Ensure that the user has logged into Steam. This will always return true if the game is launched
  // from Steam, but if Steam is at the login prompt when you run your game from the debugger, it
  // will return false.
  if (!SteamUser()->BLoggedOn())
  {
    Log("Steam user is not logged in\n");
    Log("Steam user must be logged in to play this game (SteamUser()->BLoggedOn() returned false).\n");
    return false;
  }

  // Initialize steam controller if connected
  char rgchCWD[1024];
  _getcwd(rgchCWD, sizeof(rgchCWD));

  char rgchFullPath[1024];
  _snprintf(rgchFullPath, sizeof(rgchFullPath), "%s\\%s", rgchCWD, "controller.vdf");

  if (!SteamController()->Init(rgchFullPath))
  {
    Log("SteamController()->Init() failed\n");
    Log("Steam Controller Init failed. Is controller.vdf in the current working directory?\n");
    return false;
  }

  // Need to run from Steam UI to work I think
  bool UseVR = SteamUtils()->IsSteamRunningInVR();
  // Set UseVR to true for testing
  UseVR = true;

  // Init VR
  if (!UseVR)
  {
    mVRHmd = NULL;
  }
  else
  {
    vr::HmdError error;
    mVRHmd = vr::VR_Init(&error);
    if (!mVRHmd)
    {
      Log("Failed to initialize VR.");
      Log("Game will run without VR.");
      return false;
    }
  }

  Log("SteamVR Initialized");
  return true;
}
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;
}
Пример #21
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	//
	// Console window is required for the program to automatically close when the user quits Steam
	//
	if(AllocConsole())
	{
		FILE* stream = nullptr;
		freopen_s(&stream, "CONOUT$", "w", stdout);
		freopen_s(&stream, "CONOUT$", "w", stderr);
		freopen_s(&stream, "CONIN$", "r", stdin);

		printf("SteamMusicKeys\n\n");
	}

	printf("Searching for Steam...	");
	bool SteamAPI_SteamIsRunning = SteamAPI_IsSteamRunning();

	for(int i = 0; i < STEAMAPI_STEAMISRUNNING_RETRY_COUNT; i++)
	{
		if(SteamAPI_SteamIsRunning = SteamAPI_IsSteamRunning())
		{
			printf("Found!\n");
			break;
		}
		Sleep(STEAMAPI_STEAMISRUNNING_RETRY_DELAY);
	}

	if(!SteamAPI_SteamIsRunning)
	{
		printf("Not Found!\n");
		MessageBox(0,L"ERROR: Could not initialize SteamAPI (Steam is not running)", 0, 0);
		FreeConsole();
		return 1;
	}

	printf("Initializing SteamAPI...\n");
	if(!SteamAPI_Init())
	{
		MessageBox(0, L"ERROR: Could not initialize SteamAPI", 0, 0);
		FreeConsole();
		return 2;
	}

	printf("Initializing Steam Music...\n");
	if(!(IMus = SteamMusic()))
	{
		MessageBox(0, L"ERROR: Could not initialize Steam Music", 0, 0);
		SteamAPI_Shutdown();
		FreeConsole();
		return 3;
	}

	printf("Creating dummy window...\n");
	HWND hWnd = SMK_CreateDummyWindow(hInstance, L"SteamMusicKeys");
	if(!hWnd)
	{
		MessageBox(0, L"ERROR: Could not create dummy window", 0, 0);
		SteamAPI_Shutdown();
		FreeConsole();
		return 4;
	}

	printf("Registering hotkeys...\n");
	SMK_RegisterHotkeys(hWnd);
	printf("Hiding console...\n");
	ShowWindow (GetConsoleWindow(), SW_HIDE);
	SMK_MessageLoop();

	printf("Showing console...\n");
	ShowWindow (GetConsoleWindow(), SW_SHOW);
	printf("Freeing Hotkeys...\n");
	SMK_UnregisterHotkeys(hWnd);
	printf("Freeing SteamAPI\n");
	SteamAPI_Shutdown();
	printf("Freeing Console\n");
	FreeConsole();
	return 0;
}
Пример #22
0
bool SteamClient::init() {
    if (SteamAPI_IsSteamRunning() && !initialized) {
        initialized = SteamAPI_Init();
    }
    return initialized;
}
Пример #23
0
// init and start wrapper
bool System_InitWrapper()
{
	//pLog = new Log("debug.log");
	LogToFile("System_InitWrapper");
	return SteamAPI_Init();
};
Пример #24
0
// Steamworks functions
//-----------------------------------------------
SW_PY bool SteamInit(void) {
	return SteamAPI_Init();
}
Пример #25
0
	void init(const std::vector<AchievementInfo>& achievementInfos) //const char *pchCmdLine, HINSTANCE hInstance, int nCmdShow)
	{
		g_AchievementInfosCopy = achievementInfos;
		for (size_t i = 0; i < achievementInfos.size(); ++i)
		{
			Achievement_t achievementData;
			achievementData.m_eAchievementID = i;
			achievementData.m_pchAchievementID = g_AchievementInfosCopy[i].id.c_str();
			strncpy(achievementData.m_rgchName, g_AchievementInfosCopy[i].name.c_str(), 128);
			strncpy(achievementData.m_rgchDescription, g_AchievementInfosCopy[i].description.c_str(), 128);
			achievementData.m_bAchieved = false;
			achievementData.m_iIconImage = 0;
			g_Achievements.push_back(achievementData);
		}

		if (SteamAPI_RestartAppIfNecessary(k_uAppIdInvalid))
		{
			// if Steam is not running or the game wasn't started through Steam, SteamAPI_RestartAppIfNecessary starts the
			// local Steam client and also launches this game again.

			// Once you get a public Steam AppID assigned for this game, you need to replace k_uAppIdInvalid with it and
			// removed steam_appid.txt from the game depot.

			AssertMessage(false, "SteamAPI_RestartAppIfNecessary failed");
		}

		// Init Steam CEG
		if (!Steamworks_InitCEGLibrary())
		{
			Utils::sleepMs(1000);
			if (!Steamworks_InitCEGLibrary()) // try twice - it may be a glitch in the network?
			{
				AssertMessage(false, "Steam must be running to play this game (InitDrmLibrary() failed).");
			}
		}

		// Initialize SteamAPI, if this fails we bail out since we depend on Steam for lots of stuff.
		// You don't necessarily have to though if you write your code to check whether all the Steam
		// interfaces are NULL before using them and provide alternate paths when they are unavailable.
		//
		// This will also load the in-game steam overlay dll into your process.  That dll is normally
		// injected by steam when it launches games, but by calling this you cause it to always load,
		// even when not launched via steam.
		if (!SteamAPI_Init())
		{
			Utils::sleepMs(1000);
			if (!SteamAPI_Init())
			{
				AssertMessage(false, "Steam must be running to play this game (SteamAPI_Init() failed).\n");
			}
		}

		// Create the SteamAchievements object if Steam was successfully initialized
		g_SteamAchievements = new CSteamAchievements(&g_Achievements[0], g_Achievements.size());


		bool res = g_SteamAchievements->RequestStats();
		if (!res)
		{
			Utils::sleepMs(1000);
			res = g_SteamAchievements->RequestStats();
			if (!res)
			{
				AssertMessage(false, "Could not get stats from Steam.\nPlease check that your Internet connection is working correctly and that Steam is up.\n");
			}
		}


		// set our debug handler
		SteamClient()->SetWarningMessageHook(&SteamAPIDebugTextHook);

		// Tell Steam where it's overlay should show notification dialogs, this can be top right, top left,
		// bottom right, bottom left. The default position is the bottom left if you don't call this.
		// Generally you should use the default and not call this as users will be most comfortable with
		// the default position.  The API is provided in case the bottom right creates a serious conflict
		// with important UI in your game.
		SteamUtils()->SetOverlayNotificationPosition(k_EPositionTopRight);

		// Ensure that the user has logged into Steam. This will always return true if the game is launched
		// from Steam, but if Steam is at the login prompt when you run your game from the debugger, it
		// will return false.
		if (!SteamUser()->BLoggedOn())
		{
			Utils::sleepMs(1000);
			if (!SteamUser()->BLoggedOn())
			{
				AssertMessage(false, "Steam user must be logged in to play this game (SteamUser()->BLoggedOn() returned false).\n");
			}
		}

		// We are going to use the controller interface, initialize it, which is a seperate step as it
		// create a new thread in the game proc and we don't want to force that on games that don't
		// have native Steam controller implementations

#ifdef USES_LINUX
		std::string rgchCWDstr = Utils::convertWStringToString(Utils::getCurrentDirectoryUnicode(), true);
		const char* rgchCWD = rgchCWDstr.c_str();
#else
		char rgchCWD[1024];
		_getcwd( rgchCWD, sizeof( rgchCWD ) );
#endif

		char rgchFullPath[1024];
#if defined(_WIN32)
		_snprintf(rgchFullPath, sizeof(rgchFullPath), "%s\\%s", rgchCWD, "controller.vdf");//.c_str()
#elif defined(OSX)
		// hack for now, because we do not have utility functions available for finding the resource path
		// alternatively we could disable the SteamController init on OS X
		_snprintf(rgchFullPath, sizeof(rgchFullPath), "%s/steamworksexample.app/Contents/Resources/%s", rgchCWD, "controller.vdf");
#else
		_snprintf(rgchFullPath, sizeof(rgchFullPath), "%s/%s", rgchCWD, "controller.vdf");
#endif
		if (!SteamController()->Init(rgchFullPath))
		{
			AssertMessage(false, "Steam Controller Init failed. Is controller.vdf in the current working directory?\n");
		}

		/*bool bUseVR = SteamUtils()->IsSteamRunningInVR();
		const char *pchServerAddress, *pchLobbyID;
		ParseCommandLine(pchCmdLine, &pchServerAddress, &pchLobbyID, &bUseVR);*/

		// do a DRM self check
		Steamworks_SelfCheck();

		// init VR before we make the window

		// Construct a new instance of the game engine
		// bugbug jmccaskey - make screen resolution dynamic, maybe take it on command line?
		/*IGameEngine *pGameEngine =
#if defined(_WIN32)
			new CGameEngineWin32(hInstance, nCmdShow, 1024, 768, bUseVR);
#elif defined(OSX)
			CreateGameEngineOSX();
#elif defined(SDL)
			CreateGameEngineSDL(bUseVR);
#else
#error	Need CreateGameEngine()
#endif*/
	}