r5sdk/r5dev/tier0/commandline.cpp
Kawe Mazidjatari edc52ad669 IDetour: remove extraneous pointer assignments
Originally, we store the search results in a CMemory instance which we then assign to the actual function pointer. CMemory is just a pointer class; we can assign the results directly to the actual function pointer. This commit reduces a lot of code verbosity, and also reduced roughly 2KiB worth of static pointers in the resulting executable. This commit also officially deprecates the support for any GameDLL's below S3 (Season 3), since it makes more sense to port the assets from earlier/later games back to the version this SDK supports.
2024-04-05 17:19:32 +02:00

96 lines
2.5 KiB
C++

//=============================================================================//
//
// Purpose: Command line utilities
//
//=============================================================================//
#include "tier0/commandline.h"
bool g_bCommandLineCreated = false;
//-----------------------------------------------------------------------------
// Purpose: Create a command line from the passed in string
// Note that if you pass in a @filename, then the routine will read settings
// from a file instead of the command line
//-----------------------------------------------------------------------------
void CCommandLine::StaticCreateCmdLine(CCommandLine* thisptr, const char* pszCommandLine)
{
// The SDK creates the cmdline instead, when loaded. We hook this
// function, and skip the actual creation of subsequent calls.
// This is required as otherwise our own appended parameters will
// get lost when the game recreates it in 'LauncherMain'.
if (!g_bCommandLineCreated)
{
CCommandLine__CreateCmdLine(thisptr, pszCommandLine);
}
}
//-----------------------------------------------------------------------------
// Purpose: parses a text file and appends its parameters/values
//-----------------------------------------------------------------------------
void CCommandLine::AppendParametersFromFile(const char* const pszConfig)
{
char szTextBuf[2048];
FILE* pFile = fopen(pszConfig, "r");
if (!pFile)
{
// Try the 'PLATFORM' folder.
snprintf(szTextBuf, sizeof(szTextBuf), "platform/%s", pszConfig);
pFile = fopen(szTextBuf, "r");
if (!pFile)
{
printf("%s: '%s' does not exist!\n",
__FUNCTION__, pszConfig);
return;
}
}
while (fgets(szTextBuf, sizeof(szTextBuf), pFile))
{
// Trim newlines...
size_t nLen = strlen(szTextBuf);
if (nLen > 0 && szTextBuf[nLen - 1] == '\n')
{
szTextBuf[--nLen] = '\0';
}
char* const pSpacePos = strchr(szTextBuf, ' ');
const char* pArgValue = "";
if (pSpacePos)
{
// Skip space and move to value.
*pSpacePos = '\0';
char* pArg = pSpacePos + 1;
// Trim the quotes around the value.
if (*pArg == '\"')
{
pArg++;
char* const pEndQuote = strchr(pArg, '\"');
if (pEndQuote)
{
*pEndQuote = '\0';
}
}
pArgValue = pArg;
}
AppendParm(szTextBuf, pArgValue);
}
fclose(pFile);
}
///////////////////////////////////////////////////////////////////////////////
CCommandLine* g_pCmdLine = nullptr;
void VCommandLine::Detour(const bool bAttach) const
{
DetourSetup(&CCommandLine__CreateCmdLine, &CCommandLine::StaticCreateCmdLine, bAttach);
}