2021-12-25 22:36:38 +01:00
# include "core/stdafx.h"
2022-05-23 19:14:12 +02:00
# include "basepanel.h"
2022-05-24 02:23:37 +02:00
# include "sdklauncher_const.h"
# include "sdklauncher.h"
2022-05-23 19:14:12 +02:00
# include <objidl.h>
# include "gdiplus.h"
# include "shellapi.h"
2022-05-26 22:04:50 +02:00
///////////////////////////////////////////////////////////////////////////////
// Purpose: initializes the user interface
///////////////////////////////////////////////////////////////////////////////
void CLauncher : : InitSurface ( )
{
Forms : : Application : : EnableVisualStyles ( ) ;
UIX : : UIXTheme : : InitializeRenderer ( new Themes : : KoreTheme ( ) ) ;
g_pLauncher - > m_pSurface = new CUIBaseSurface ( ) ;
Forms : : Application : : Run ( g_pLauncher - > m_pSurface ) ;
UIX : : UIXTheme : : ShutdownRenderer ( ) ;
}
///////////////////////////////////////////////////////////////////////////////
// Purpose: initializes the console (release builds only)
///////////////////////////////////////////////////////////////////////////////
void CLauncher : : InitConsole ( )
{
AllocConsole ( ) ;
freopen ( " conin$ " , " r " , stdin ) ;
freopen ( " conout$ " , " w " , stdout ) ;
freopen ( " conout$ " , " w " , stderr ) ;
}
///////////////////////////////////////////////////////////////////////////////
// Purpose: initializes the logger
///////////////////////////////////////////////////////////////////////////////
void CLauncher : : InitLogger ( )
{
wconsole - > set_pattern ( " [%^%l%$] %v " ) ;
wconsole - > set_level ( spdlog : : level : : trace ) ;
spdlog : : set_default_logger ( wconsole ) ; // Set as default.
}
///////////////////////////////////////////////////////////////////////////////
// Purpose: handles user input pre-init
// Input : argc -
// *argv -
// Output : exit_code (-1 if EP should continue to HandleInput)
///////////////////////////////////////////////////////////////////////////////
int CLauncher : : HandleCmdLine ( int argc , char * argv [ ] )
{
for ( int i = 1 ; i < __argc ; + + i )
{
std : : string arg = __argv [ i ] ;
if ( ( arg = = " -debug " ) | | ( arg = = " -dbg " ) )
{
if ( g_pLauncher - > Setup ( eLaunchMode : : LM_HOST_DEBUG , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
if ( ( arg = = " -release " ) | | ( arg = = " -rel " ) )
{
if ( g_pLauncher - > Setup ( eLaunchMode : : LM_HOST , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
if ( ( arg = = " -dedicated_dev " ) | | ( arg = = " -dedid " ) )
{
if ( g_pLauncher - > Setup ( eLaunchMode : : LM_SERVER_DEBUG , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
if ( ( arg = = " -dedicated " ) | | ( arg = = " -dedi " ) )
{
if ( g_pLauncher - > Setup ( eLaunchMode : : LM_SERVER , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
if ( ( arg = = " -client_dev " ) | | ( arg = = " -cld " ) )
{
if ( g_pLauncher - > Setup ( eLaunchMode : : LM_CLIENT_DEBUG , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
if ( ( arg = = " -client " ) | | ( arg = = " -cl " ) )
{
if ( g_pLauncher - > Setup ( eLaunchMode : : LM_CLIENT , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
}
return - 1 ;
}
///////////////////////////////////////////////////////////////////////////////
// Purpose: handles user input post-init
// Output : exit_code
///////////////////////////////////////////////////////////////////////////////
int CLauncher : : HandleInput ( )
{
std : : cout < < " ---------------------------------------------------------------------------------------------------------------------- " < < std : : endl ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : warn , " If a DEBUG option has been choosen as launch parameter, do not broadcast servers to the Server Browser! \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : warn , " All FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY ConVar's/ConCommand's will be enabled. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : warn , " Connected clients will be able to set and execute anything flagged FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY. \n " ) ;
std : : cout < < " ---------------------------------------------------------------------------------------------------------------------- " < < std : : endl ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : warn , " Use DEBUG HOST [0] for research and development purposes. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : warn , " Use RELEASE HOST [1] for playing the game and creating servers. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : warn , " Use DEBUG SERVER [2] for research and development purposes. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : warn , " Use RELEASE SERVER [3] for running and hosting dedicated servers. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : warn , " Use DEBUG CLIENT [4] for research and development purposes. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : warn , " Use RELEASE CLIENT [5] for running client only builds against remote servers. \n " ) ;
std : : cout < < " ---------------------------------------------------------------------------------------------------------------------- " < < std : : endl ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : info , " Enter '0' for 'DEBUG HOST'. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : info , " Enter '1' for 'RELEASE HOST'. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : info , " Enter '2' for 'DEBUG SERVER'. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : info , " Enter '3' for 'RELEASE SERVER'. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : info , " Enter '4' for 'DEBUG CLIENT'. \n " ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : info , " Enter '5' for 'RELEASE CLIENT'. \n " ) ;
std : : cout < < " ---------------------------------------------------------------------------------------------------------------------- " < < std : : endl ;
std : : cout < < " User input: " ;
std : : string input = std : : string ( ) ;
if ( std : : cin > > input )
{
try
{
eLaunchMode mode = static_cast < eLaunchMode > ( std : : stoi ( input ) ) ;
switch ( mode )
{
case eLaunchMode : : LM_HOST_DEBUG :
{
if ( g_pLauncher - > Setup ( mode , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
case eLaunchMode : : LM_HOST :
{
if ( g_pLauncher - > Setup ( mode , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
case eLaunchMode : : LM_SERVER_DEBUG :
{
if ( g_pLauncher - > Setup ( mode , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
2022-05-23 19:14:12 +02:00
2022-05-26 22:04:50 +02:00
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
case eLaunchMode : : LM_SERVER :
{
if ( g_pLauncher - > Setup ( mode , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
case eLaunchMode : : LM_CLIENT_DEBUG :
{
if ( g_pLauncher - > Setup ( mode , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
case eLaunchMode : : LM_CLIENT :
{
if ( g_pLauncher - > Setup ( mode , eLaunchState : : LS_CHEATS ) )
{
if ( g_pLauncher - > Launch ( ) )
{
Sleep ( 2000 ) ;
return EXIT_SUCCESS ;
}
}
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
default :
{
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : err , " Invalid mode (range 0-5). \n " ) ;
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
}
}
catch ( std : : exception & e )
{
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : err , " SDK Launcher only takes numerical input. Error: {:s}. \n " , e . what ( ) ) ;
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
}
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : err , " SDK Launcher requires numerical input. \n " ) ;
2021-08-01 02:25:29 -07:00
2022-05-26 22:04:50 +02:00
Sleep ( 2000 ) ;
return EXIT_FAILURE ;
}
2022-05-24 02:23:37 +02:00
2022-05-26 22:04:50 +02:00
///////////////////////////////////////////////////////////////////////////////
// Purpose: setup for game dll's and configurations
// Input : lMode -
// lState -
// Output : true on success, false otherwise
///////////////////////////////////////////////////////////////////////////////
2022-05-23 19:14:12 +02:00
bool CLauncher : : Setup ( eLaunchMode lMode , eLaunchState lState )
2021-04-13 04:45:22 -07:00
{
2021-06-17 17:07:26 -07:00
///////////////////////////////////////////////////////////////////////////
2022-04-16 00:30:46 +02:00
std : : string svCmdLineArgs = std : : string ( ) ;
2021-04-13 04:45:22 -07:00
2021-08-30 16:39:56 +02:00
///////////////////////////////////////////////////////////////////////////
2021-08-01 02:25:29 -07:00
switch ( lMode )
2021-04-13 05:05:29 -07:00
{
2022-05-24 02:23:37 +02:00
case eLaunchMode : : LM_HOST_DEBUG :
2022-05-23 19:14:12 +02:00
{
fs : : path cfgPath = fs : : current_path ( ) / = " platform \\ cfg \\ startup_debug.cfg " ;
std : : ifstream cfgFile ( cfgPath ) ;
if ( cfgFile . good ( ) & & cfgFile )
2021-04-25 14:36:55 -07:00
{
2022-05-23 19:14:12 +02:00
std : : stringstream ss ;
ss < < cfgFile . rdbuf ( ) ;
svCmdLineArgs = ss . str ( ) + " -launcher " ;
2021-08-01 02:25:29 -07:00
}
2022-05-23 19:14:12 +02:00
else
2021-08-01 02:25:29 -07:00
{
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : err , " File 'platform \\ cfg \\ startup_debug.cfg' does not exist! \n " ) ;
2022-05-23 19:14:12 +02:00
return false ;
}
2021-08-01 02:25:29 -07:00
2022-05-23 19:14:12 +02:00
m_svWorkerDll = m_svCurrentDir + " \\ gamesdk.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex.exe " + svCmdLineArgs ;
2021-08-30 16:39:56 +02:00
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHING GAME [DEBUG] *** \n " ) ;
2022-05-23 19:14:12 +02:00
break ;
}
2022-05-24 02:23:37 +02:00
case eLaunchMode : : LM_HOST :
2022-05-23 19:14:12 +02:00
{
fs : : path cfgPath = fs : : current_path ( ) / = " platform \\ cfg \\ startup_retail.cfg " ;
std : : ifstream cfgFile ( cfgPath ) ;
if ( cfgFile . good ( ) & & cfgFile )
{
std : : stringstream ss ;
ss < < cfgFile . rdbuf ( ) ;
svCmdLineArgs = ss . str ( ) + " -launcher " ;
2021-08-01 02:25:29 -07:00
}
2022-05-23 19:14:12 +02:00
else
2021-08-01 02:25:29 -07:00
{
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : err , " File 'platform \\ cfg \\ startup_retail.cfg' does not exist! \n " ) ;
2022-05-23 19:14:12 +02:00
return false ;
}
2021-08-01 02:25:29 -07:00
2022-05-23 19:14:12 +02:00
m_svWorkerDll = m_svCurrentDir + " \\ gamesdk.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex.exe " + svCmdLineArgs ;
2021-08-30 16:39:56 +02:00
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHING GAME [RELEASE] *** \n " ) ;
2022-05-23 19:14:12 +02:00
break ;
}
2022-05-24 02:23:37 +02:00
case eLaunchMode : : LM_SERVER_DEBUG :
2022-05-23 19:14:12 +02:00
{
fs : : path cfgPath = fs : : current_path ( ) / = " platform \\ cfg \\ startup_dedi_debug.cfg " ;
std : : ifstream cfgFile ( cfgPath ) ;
if ( cfgFile . good ( ) & & cfgFile )
{
std : : stringstream ss ;
ss < < cfgFile . rdbuf ( ) ;
svCmdLineArgs = ss . str ( ) + " -launcher " ;
2022-01-16 12:48:56 +01:00
}
2022-05-23 19:14:12 +02:00
else
2022-01-16 12:48:56 +01:00
{
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : err , " File 'platform \\ cfg \\ startup_dedi_debug.cfg' does not exist! \n " ) ;
2022-05-23 19:14:12 +02:00
return false ;
}
2022-01-16 12:48:56 +01:00
2022-05-23 19:14:12 +02:00
m_svWorkerDll = m_svCurrentDir + " \\ dedicated.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex_ds.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex_ds.exe " + svCmdLineArgs ;
2022-01-16 12:48:56 +01:00
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHING DEDICATED [DEBUG] *** \n " ) ;
2022-05-23 19:14:12 +02:00
break ;
}
2022-05-24 02:23:37 +02:00
case eLaunchMode : : LM_SERVER :
2022-05-23 19:14:12 +02:00
{
fs : : path cfgPath = fs : : current_path ( ) / = " platform \\ cfg \\ startup_dedi_retail.cfg " ;
std : : ifstream cfgFile ( cfgPath ) ;
if ( cfgFile . good ( ) & & cfgFile )
{
std : : stringstream ss ;
ss < < cfgFile . rdbuf ( ) ;
svCmdLineArgs = ss . str ( ) ; + " -launcher " ;
2021-08-01 02:25:29 -07:00
}
2022-05-23 19:14:12 +02:00
else
2021-08-01 02:25:29 -07:00
{
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : err , " File 'platform \\ cfg \\ startup_dedi_retail.cfg' does not exist! \n " ) ;
2021-08-01 02:25:29 -07:00
return false ;
2021-04-25 14:36:55 -07:00
}
2022-05-23 19:14:12 +02:00
m_svWorkerDll = m_svCurrentDir + " \\ dedicated.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex_ds.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex_ds.exe " + svCmdLineArgs ;
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHING DEDICATED [RELEASE] *** \n " ) ;
break ;
}
case eLaunchMode : : LM_CLIENT_DEBUG :
{
fs : : path cfgPath = fs : : current_path ( ) / = " platform \\ cfg \\ startup_client_debug.cfg " ;
std : : ifstream cfgFile ( cfgPath ) ;
if ( cfgFile . good ( ) & & cfgFile )
{
std : : stringstream ss ;
ss < < cfgFile . rdbuf ( ) ;
svCmdLineArgs = ss . str ( ) ; + " -launcher " ;
}
else
{
AddLog ( spdlog : : level : : level_enum : : err , " File 'platform \\ cfg \\ startup_client_debug.cfg' does not exist! \n " ) ;
return false ;
}
m_svWorkerDll = m_svCurrentDir + " \\ bin \\ client.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex.exe " + svCmdLineArgs ;
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHING CLIENT [DEBUG] *** \n " ) ;
break ;
}
case eLaunchMode : : LM_CLIENT :
{
fs : : path cfgPath = fs : : current_path ( ) / = " platform \\ cfg \\ startup_client_retail.cfg " ;
std : : ifstream cfgFile ( cfgPath ) ;
if ( cfgFile . good ( ) & & cfgFile )
{
std : : stringstream ss ;
ss < < cfgFile . rdbuf ( ) ;
svCmdLineArgs = ss . str ( ) ; + " -launcher " ;
}
else
{
AddLog ( spdlog : : level : : level_enum : : err , " File 'platform \\ cfg \\ startup_client_retail.cfg' does not exist! \n " ) ;
return false ;
}
m_svWorkerDll = m_svCurrentDir + " \\ bin \\ client.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex.exe " + svCmdLineArgs ;
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHING CLIENT [RELEASE] *** \n " ) ;
2022-05-23 19:14:12 +02:00
break ;
}
default :
{
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : err , " *** NO LAUNCH MODE SPECIFIED *** \n " ) ;
2022-05-23 19:14:12 +02:00
return false ;
}
2021-04-13 05:05:29 -07:00
}
2021-06-17 17:07:26 -07:00
///////////////////////////////////////////////////////////////////////////
2022-05-26 22:04:50 +02:00
// Print the file paths and arguments.
2022-01-16 12:48:56 +01:00
std : : cout < < " ---------------------------------------------------------------------------------------------------------------------- " < < std : : endl ;
2022-05-26 22:04:50 +02:00
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : debug , " - CWD: {:s} \n " , m_svCurrentDir ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : debug , " - EXE: {:s} \n " , m_svGameExe ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : debug , " - DLL: {:s} \n " , m_svWorkerDll ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : debug , " - CLI: {:s} \n " , svCmdLineArgs ) ;
2022-01-16 12:48:56 +01:00
std : : cout < < " ---------------------------------------------------------------------------------------------------------------------- " < < std : : endl ;
2021-04-13 04:45:22 -07:00
2022-05-23 19:14:12 +02:00
return true ;
}
2022-05-26 22:04:50 +02:00
///////////////////////////////////////////////////////////////////////////////
// Purpose: setup for game dll's and configurations
// Input : lMode -
// &svCommandLine -
// Output : true on success, false otherwise
///////////////////////////////////////////////////////////////////////////////
2022-05-24 02:23:37 +02:00
bool CLauncher : : Setup ( eLaunchMode lMode , const string & svCommandLine )
{
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
switch ( lMode )
{
case eLaunchMode : : LM_HOST_DEBUG :
{
m_svWorkerDll = m_svCurrentDir + " \\ gamesdk.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex.exe " + svCommandLine ;
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHER SETUP FOR HOST [DEBUG] *** \n " ) ;
2022-05-24 02:23:37 +02:00
break ;
}
case eLaunchMode : : LM_HOST :
{
m_svWorkerDll = m_svCurrentDir + " \\ gamesdk.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex.exe " + svCommandLine ;
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHER SETUP FOR HOST [RELEASE] *** \n " ) ;
2022-05-24 02:23:37 +02:00
break ;
}
case eLaunchMode : : LM_SERVER_DEBUG :
{
m_svWorkerDll = m_svCurrentDir + " \\ dedicated.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex_ds.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex_ds.exe " + svCommandLine ;
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHER SETUP FOR DEDICATED [DEBUG] *** \n " ) ;
2022-05-24 02:23:37 +02:00
break ;
}
case eLaunchMode : : LM_SERVER :
{
m_svWorkerDll = m_svCurrentDir + " \\ dedicated.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex_ds.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex_ds.exe " + svCommandLine ;
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHER SETUP FOR DEDICATED [RELEASE] *** \n " ) ;
break ;
}
case eLaunchMode : : LM_CLIENT_DEBUG :
{
m_svWorkerDll = m_svCurrentDir + " \\ bin \\ client.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex.exe " + svCommandLine ;
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHER SETUP FOR CLIENT [DEBUG] *** \n " ) ;
break ;
}
case eLaunchMode : : LM_CLIENT :
{
m_svWorkerDll = m_svCurrentDir + " \\ bin \\ client.dll " ;
m_svGameExe = m_svCurrentDir + " \\ r5apex.exe " ;
m_svCmdLine = m_svCurrentDir + " \\ r5apex.exe " + svCommandLine ;
AddLog ( spdlog : : level : : level_enum : : info , " *** LAUNCHER SETUP FOR CLIENT [RELEASE] *** \n " ) ;
2022-05-24 02:23:37 +02:00
break ;
}
default :
{
2022-05-26 22:04:50 +02:00
AddLog ( spdlog : : level : : level_enum : : err , " *** INVALID LAUNCH MODE SPECIFIED *** \n " ) ;
2022-05-24 02:23:37 +02:00
return false ;
}
}
///////////////////////////////////////////////////////////////////////////
// Print the file paths and arguments.
std : : cout < < " ---------------------------------------------------------------------------------------------------------------------- " < < std : : endl ;
2022-05-26 22:04:50 +02:00
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : debug , " - CWD: {:s} \n " , m_svCurrentDir ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : debug , " - EXE: {:s} \n " , m_svGameExe ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : debug , " - DLL: {:s} \n " , m_svWorkerDll ) ;
g_pLauncher - > AddLog ( spdlog : : level : : level_enum : : debug , " - CLI: {:s} \n " , svCommandLine ) ;
2022-05-24 02:23:37 +02:00
std : : cout < < " ---------------------------------------------------------------------------------------------------------------------- " < < std : : endl ;
return true ;
}
2022-05-26 22:04:50 +02:00
///////////////////////////////////////////////////////////////////////////////
// Purpose: launhes the game with results from the setup
// Output : true on success, false otherwise
///////////////////////////////////////////////////////////////////////////////
bool CLauncher : : Launch ( ) const
2022-05-23 19:14:12 +02:00
{
2021-06-17 17:07:26 -07:00
///////////////////////////////////////////////////////////////////////////
2021-04-13 04:45:22 -07:00
// Build our list of dlls to inject.
LPCSTR DllsToInject [ 1 ] =
{
2022-05-23 19:14:12 +02:00
m_svWorkerDll . c_str ( )
2021-04-13 04:45:22 -07:00
} ;
2022-03-04 16:06:36 +01:00
STARTUPINFOA StartupInfo = { 0 } ;
2021-08-30 16:39:56 +02:00
PROCESS_INFORMATION ProcInfo = { 0 } ;
// Initialize startup info struct.
2022-03-04 16:06:36 +01:00
StartupInfo . cb = sizeof ( STARTUPINFOA ) ;
2021-08-30 16:39:56 +02:00
2021-06-17 17:07:26 -07:00
///////////////////////////////////////////////////////////////////////////
2021-04-13 04:45:22 -07:00
// Create the game process in a suspended state with our dll.
2021-08-30 16:39:56 +02:00
BOOL result = DetourCreateProcessWithDllsA
(
2022-05-23 19:14:12 +02:00
m_svGameExe . c_str ( ) , // lpApplicationName
( LPSTR ) m_svCmdLine . c_str ( ) , // lpCommandLine
2021-08-30 16:39:56 +02:00
NULL , // lpProcessAttributes
NULL , // lpThreadAttributes
FALSE , // bInheritHandles
CREATE_SUSPENDED , // dwCreationFlags
NULL , // lpEnvironment
2022-05-23 19:14:12 +02:00
m_svCurrentDir . c_str ( ) , // lpCurrentDirectory
2021-08-30 16:39:56 +02:00
& StartupInfo , // lpStartupInfo
& ProcInfo , // lpProcessInformation
sizeof ( DllsToInject ) / sizeof ( LPCSTR ) , // nDlls
DllsToInject , // rlpDlls
NULL // pfCreateProcessA
2021-04-13 04:45:22 -07:00
) ;
2021-06-17 17:07:26 -07:00
///////////////////////////////////////////////////////////////////////////
// Failed to create the process.
2021-04-13 04:45:22 -07:00
if ( ! result )
{
PrintLastError ( ) ;
return false ;
}
2021-06-17 17:07:26 -07:00
///////////////////////////////////////////////////////////////////////////
2021-04-13 04:45:22 -07:00
// Resume the process.
ResumeThread ( ProcInfo . hThread ) ;
2021-06-17 17:07:26 -07:00
///////////////////////////////////////////////////////////////////////////
2021-04-13 04:45:22 -07:00
// Close the process and thread handles.
CloseHandle ( ProcInfo . hProcess ) ;
CloseHandle ( ProcInfo . hThread ) ;
return true ;
}
2021-06-17 17:07:26 -07:00
///////////////////////////////////////////////////////////////////////////////
2021-06-28 15:51:32 -07:00
// Entrypoint.
2021-07-12 08:47:54 -07:00
///////////////////////////////////////////////////////////////////////////////
2021-04-13 04:45:22 -07:00
int main ( int argc , char * argv [ ] , char * envp [ ] )
{
2022-05-26 22:04:50 +02:00
g_pLauncher - > InitLogger ( ) ;
if ( __argc < 2 )
2021-08-01 02:25:29 -07:00
{
2022-05-26 22:04:50 +02:00
FreeConsole ( ) ;
g_pLauncher - > InitSurface ( ) ;
2022-05-23 19:14:12 +02:00
}
else
2021-08-19 15:26:44 +02:00
{
2022-05-26 22:04:50 +02:00
int results = g_pLauncher - > HandleCmdLine ( __argc , __argv ) ;
if ( results ! = - 1 )
return results ;
2021-08-19 15:26:44 +02:00
2022-05-26 22:04:50 +02:00
return g_pLauncher - > HandleInput ( ) ;
2022-05-23 19:14:12 +02:00
}
return EXIT_SUCCESS ;
2021-12-25 22:36:38 +01:00
}