2022-04-16 00:30:46 +02:00
|
|
|
|
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
|
|
|
|
//
|
|
|
|
|
// Purpose: Defines the entry point for the application.
|
|
|
|
|
//
|
|
|
|
|
// $NoKeywords: $
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
#include "core/stdafx.h"
|
2023-03-18 21:42:30 +01:00
|
|
|
|
#include "core/logdef.h"
|
2023-01-31 22:13:40 +01:00
|
|
|
|
#include "tier0/crashhandler.h"
|
2022-04-16 00:30:46 +02:00
|
|
|
|
#include "tier0/commandline.h"
|
2022-08-20 03:15:51 +02:00
|
|
|
|
#include "tier1/strtools.h"
|
2022-04-16 00:30:46 +02:00
|
|
|
|
#include "launcher/launcher.h"
|
2023-05-13 18:07:05 +02:00
|
|
|
|
#include <eiface.h>
|
2022-04-16 00:30:46 +02:00
|
|
|
|
|
|
|
|
|
int LauncherMain(HINSTANCE hInstance)
|
|
|
|
|
{
|
2023-07-01 01:20:47 +02:00
|
|
|
|
// Flush buffers every 5 seconds for every logger.
|
|
|
|
|
// Has to be done here, don't move this to SpdLog
|
|
|
|
|
// init, as this could cause deadlocks on certain
|
|
|
|
|
// compilers (VS2017)!!!
|
|
|
|
|
spdlog::flush_every(std::chrono::seconds(5));
|
2023-03-18 21:42:30 +01:00
|
|
|
|
|
2022-04-16 00:30:46 +02:00
|
|
|
|
int results = v_LauncherMain(hInstance);
|
2023-08-21 19:12:29 +02:00
|
|
|
|
Msg(eDLL_T::NONE, "%s returned: %s\n", __FUNCTION__, ExitCodeToString(results));
|
2022-04-16 00:30:46 +02:00
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if !defined (GAMEDLL_S0) || !defined (GAMEDLL_S1)
|
|
|
|
|
// Remove all but the last -game parameter.
|
|
|
|
|
// This is for mods based off something other than Half-Life 2 (like HL2MP mods).
|
|
|
|
|
// The Steam UI does 'steam -applaunch 320 -game c:\steam\steamapps\sourcemods\modname', but applaunch inserts
|
2022-09-09 19:47:31 +02:00
|
|
|
|
// its own -game parameter, which would supersede the one we really want if we didn't intercede here.
|
2022-04-16 00:30:46 +02:00
|
|
|
|
void RemoveSpuriousGameParameters()
|
|
|
|
|
{
|
|
|
|
|
// Find the last -game parameter.
|
|
|
|
|
int nGameArgs = 0;
|
|
|
|
|
char lastGameArg[MAX_PATH];
|
|
|
|
|
for (int i = 0; i < CommandLine()->ParmCount() - 1; i++)
|
|
|
|
|
{
|
2022-08-20 03:15:51 +02:00
|
|
|
|
if (Q_stricmp(CommandLine()->GetParm(i), "-game") == 0)
|
2022-04-16 00:30:46 +02:00
|
|
|
|
{
|
2022-08-20 03:15:51 +02:00
|
|
|
|
Q_snprintf(lastGameArg, sizeof(lastGameArg), "\"%s\"", CommandLine()->GetParm(i + 1));
|
2022-04-16 00:30:46 +02:00
|
|
|
|
++nGameArgs;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We only care if > 1 was specified.
|
|
|
|
|
if (nGameArgs > 1)
|
|
|
|
|
{
|
|
|
|
|
CommandLine()->RemoveParm("-game");
|
|
|
|
|
CommandLine()->AppendParm("-game", lastGameArg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
const char* ExitCodeToString(int nCode)
|
|
|
|
|
{
|
|
|
|
|
switch (nCode)
|
|
|
|
|
{
|
|
|
|
|
case EXIT_SUCCESS:
|
|
|
|
|
return "EXIT_SUCCESS";
|
|
|
|
|
case EXIT_FAILURE:
|
2022-04-16 12:51:28 +02:00
|
|
|
|
return "EXIT_FAILURE";
|
2022-04-16 00:30:46 +02:00
|
|
|
|
default:
|
2022-12-28 21:44:51 +01:00
|
|
|
|
return "UNKNOWN_EXIT_CODE";
|
2022-04-16 00:30:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-28 21:44:51 +01:00
|
|
|
|
LONG WINAPI TopLevelExceptionFilter(EXCEPTION_POINTERS* pExceptionPointers)
|
|
|
|
|
{
|
|
|
|
|
// Don't run the unhandled exception filter from the
|
|
|
|
|
// game if we have a valid vectored exception filter.
|
2023-06-19 01:35:10 +02:00
|
|
|
|
if (g_CrashHandler)
|
2022-12-28 21:44:51 +01:00
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v_TopLevelExceptionFilter(pExceptionPointers);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-26 13:21:20 +01:00
|
|
|
|
void VLauncher::Detour(const bool bAttach) const
|
2022-04-16 00:30:46 +02:00
|
|
|
|
{
|
2023-11-26 13:21:20 +01:00
|
|
|
|
DetourSetup(&v_LauncherMain, &LauncherMain, bAttach);
|
|
|
|
|
DetourSetup(&v_TopLevelExceptionFilter, &TopLevelExceptionFilter, bAttach);
|
2022-04-19 00:00:45 +02:00
|
|
|
|
#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1)
|
2023-11-26 13:21:20 +01:00
|
|
|
|
DetourSetup(&v_RemoveSpuriousGameParameters, &RemoveSpuriousGameParameters, bAttach);
|
2022-04-16 00:30:46 +02:00
|
|
|
|
#endif
|
|
|
|
|
}
|