Exemplo n.º 1
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*/
	}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
//=========================================================
//=========================================================
void C_GameInstructor::FireGameEvent( IGameEvent *event )
{
	VPROF_BUDGET( "C_GameInstructor::FireGameEvent", "GameInstructor" );
	const char *name = event->GetName();
 
	if ( Q_strcmp( name, "gameinstructor_draw" ) == 0 )
	{
		if ( m_bNoDraw )
		{
			if ( gameinstructor_verbose.GetInt() > 0 )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Set to draw...\n" );
			}
 
			m_bNoDraw = false;
		}
	}
	else if ( Q_strcmp( name, "gameinstructor_nodraw" ) == 0 )
	{
		if ( !m_bNoDraw )
		{
			if ( gameinstructor_verbose.GetInt() > 0 )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Set to not draw...\n" );
			}
 
			m_bNoDraw = true;
			StopAllLessons();
		}
	}
	else if ( Q_strcmp( name, "round_end" ) == 0 )
	{
		if ( gameinstructor_verbose.GetInt() > 0 )
		{
			ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " );
			ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Round ended...\n" );
		}
 
		CloseAllOpenOpportunities();
 
		if ( IsPC() )
		{
			// Good place to backup our counts
			WriteSaveData();
		}
	}
	else if ( Q_strcmp( name, "round_start" ) == 0 )
	{
		if ( gameinstructor_verbose.GetInt() > 0 )
		{
			ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " );
			ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Round started...\n" );
		}
 
		CloseAllOpenOpportunities();
 
		EvaluateLessonsForGameRules();
	}
	else if ( Q_strcmp( name, "player_death" ) == 0 )
	{
		#if !defined(NO_STEAM) && defined(USE_CEG)
				Steamworks_TestSecret(); 
				Steamworks_SelfCheck(); 
		#endif
 
		C_BasePlayer *pLocalPlayer = GetLocalPlayer();
 
		if ( pLocalPlayer && pLocalPlayer == UTIL_PlayerByUserId( event->GetInt( "userid" ) ) )
		{
			if ( gameinstructor_verbose.GetInt() > 0 )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Local player died...\n" );
			}
 
			for ( int i = m_OpenOpportunities.Count() - 1; i >= 0; --i )
			{
				CBaseLesson *pLesson		= m_OpenOpportunities[ i ];
				CBaseLesson *pRootLesson	= pLesson->GetRoot();
 
				if ( !pRootLesson->CanOpenWhenDead() )
					CloseOpportunity( pLesson );
			}
		}
	}
	else if ( Q_strcmp( name, "player_team" ) == 0 )
	{
		C_BasePlayer *pLocalPlayer = GetLocalPlayer();
 
		if ( pLocalPlayer && pLocalPlayer == UTIL_PlayerByUserId( event->GetInt( "userid" ) ) && 
			 ( event->GetInt( "team" ) != event->GetInt( "oldteam" ) || event->GetBool( "disconnect" ) ) )
		{
			if ( gameinstructor_verbose.GetInt() > 0 )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Local player changed team (or disconnected)...\n" );
			}
 
			CloseAllOpenOpportunities();
		}
 
		EvaluateLessonsForGameRules();
	}
	else if ( Q_strcmp( name, "player_disconnect" ) == 0 )
	{
		C_BasePlayer *pLocalPlayer = GetLocalPlayer();
		if ( pLocalPlayer && pLocalPlayer == UTIL_PlayerByUserId( event->GetInt( "userid" ) ) )
		{
			if ( gameinstructor_verbose.GetInt() > 0 )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Local player disconnected...\n" );
			}
 
			CloseAllOpenOpportunities();
		}
	}
	else if ( Q_strcmp( name, "map_transition" ) == 0 )
	{
		if ( gameinstructor_verbose.GetInt() > 0 )
		{
			ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " );
			ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "Map transition...\n" );
		}
 
		CloseAllOpenOpportunities();
 
		if ( m_bNoDraw )
		{
			if ( gameinstructor_verbose.GetInt() > 0 )
			{
				ConColorMsg( Color( 255, 128, 64, 255 ), "[INSTRUCTOR]: " );
				ConColorMsg( Color( 64, 128, 255, 255 ), "Set to draw...\n" );
			}
 
			m_bNoDraw = false;
		}
 
		if ( IsPC() )
		{
			// Good place to backup our counts
			WriteSaveData();
		}
	}
	else if ( Q_strcmp( name, "game_newmap" ) == 0 )
	{
		if ( gameinstructor_verbose.GetInt() > 0 )
		{
			ConColorMsg( CBaseLesson::m_rgbaVerboseHeader, "[INSTRUCTOR]: " );
			ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "New map...\n" );
		}
 
		CloseAllOpenOpportunities();
 
		if ( m_bNoDraw )
		{
			if ( gameinstructor_verbose.GetInt() > 0 )
			{
				ConColorMsg( Color( 255, 128, 64, 255 ), "[INSTRUCTOR]: " );
				ConColorMsg( Color( 64, 128, 255, 255 ), "Set to draw...\n" );
			}
 
			m_bNoDraw = false;
		}
 
		if ( IsPC() )
		{
			// Good place to backup our counts
			WriteSaveData();
		}
	}
 
	else if ( Q_strcmp( name, "set_instructor_group_enabled" ) == 0 )
	{
		const char *pszGroup	= event->GetString( "group" );
		bool bEnabled			= event->GetInt( "enabled" ) != 0;
 
		if ( pszGroup && pszGroup[0] )
			SetLessonGroupEnabled(pszGroup, bEnabled);
	}
}