2021-04-13 04:45:22 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <detours.h>
|
|
|
|
|
2021-06-17 17:07:26 -07:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* _main.cpp
|
|
|
|
*-----------------------------------------------------------------------------*/
|
|
|
|
|
2021-04-13 04:45:22 -07:00
|
|
|
void PrintLastError()
|
|
|
|
{
|
2021-06-17 17:07:26 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2021-06-28 15:51:32 -07:00
|
|
|
// Get the error message, if any.
|
2021-04-13 04:45:22 -07:00
|
|
|
DWORD errorMessageID = ::GetLastError();
|
|
|
|
if (errorMessageID == 0)
|
2021-04-25 14:36:55 -07:00
|
|
|
{
|
2021-04-13 04:45:22 -07:00
|
|
|
return;
|
2021-04-25 14:36:55 -07:00
|
|
|
}
|
2021-04-13 04:45:22 -07:00
|
|
|
|
|
|
|
LPSTR messageBuffer = nullptr;
|
|
|
|
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
|
|
|
|
|
|
|
|
printf("ERROR: %s\n", messageBuffer);
|
|
|
|
LocalFree(messageBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LaunchR5Apex()
|
|
|
|
{
|
2021-04-13 05:05:29 -07:00
|
|
|
FILE* sLaunchParams;
|
2021-04-25 14:36:55 -07:00
|
|
|
CHAR sArgumentBuffer[1024] = { 0 };
|
2021-04-13 05:05:29 -07:00
|
|
|
CHAR sCommandDirectory[MAX_PATH];
|
|
|
|
LPSTR sCommandLine = sCommandDirectory;
|
|
|
|
|
2021-06-17 17:07:26 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2021-04-25 14:36:55 -07:00
|
|
|
// '+exec autoexec -dev -fnf -noplatform'
|
2021-06-08 10:54:49 -07:00
|
|
|
fopen_s(&sLaunchParams, "platform\\cfg\\startup_debug.cfg", "r");
|
2021-04-13 05:05:29 -07:00
|
|
|
|
2021-04-13 04:45:22 -07:00
|
|
|
BOOL result;
|
|
|
|
|
|
|
|
CHAR sDevDll[MAX_PATH];
|
|
|
|
CHAR sGameExe[MAX_PATH];
|
|
|
|
CHAR sGameDirectory[MAX_PATH];
|
|
|
|
|
|
|
|
STARTUPINFO StartupInfo = { 0 };
|
|
|
|
PROCESS_INFORMATION ProcInfo = { 0 };
|
|
|
|
|
2021-06-17 17:07:26 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2021-04-13 04:45:22 -07:00
|
|
|
// Initialize the startup info structure.
|
|
|
|
StartupInfo.cb = sizeof(STARTUPINFO);
|
|
|
|
|
2021-06-17 17:07:26 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2021-04-13 05:05:29 -07:00
|
|
|
// Load command line arguments from a file on the disk.
|
|
|
|
if (sLaunchParams)
|
|
|
|
{
|
2021-06-16 17:03:02 -07:00
|
|
|
while (fread(sArgumentBuffer, sizeof(sArgumentBuffer), 1, sLaunchParams) != NULL)
|
2021-04-25 14:36:55 -07:00
|
|
|
{
|
2021-04-13 05:05:29 -07:00
|
|
|
fclose(sLaunchParams);
|
2021-04-25 14:36:55 -07:00
|
|
|
}
|
2021-04-13 05:05:29 -07:00
|
|
|
}
|
|
|
|
|
2021-06-17 17:07:26 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2021-04-13 04:45:22 -07:00
|
|
|
// Format the file paths for the game exe and dll.
|
|
|
|
GetCurrentDirectory(MAX_PATH, sGameDirectory);
|
|
|
|
snprintf(sGameExe, sizeof(sGameExe), "%s\\r5apex.exe", sGameDirectory);
|
2021-06-17 17:07:26 -07:00
|
|
|
snprintf(sDevDll, sizeof(sDevDll), "%s\\r5detours.dll", sGameDirectory);
|
2021-04-16 11:06:20 -07:00
|
|
|
snprintf(sCommandLine, sizeof(sCommandDirectory), "%s\\r5apex.exe %s", sGameDirectory, sArgumentBuffer);
|
2021-04-13 04:45:22 -07:00
|
|
|
|
|
|
|
printf("Launching Apex Dev...\n");
|
|
|
|
printf(" - CWD: %s\n", sGameDirectory);
|
|
|
|
printf(" - EXE: %s\n", sGameExe);
|
|
|
|
printf(" - DLL: %s\n", sDevDll);
|
|
|
|
printf(" - CLI: %s\n", sCommandLine);
|
|
|
|
|
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] =
|
|
|
|
{
|
|
|
|
sDevDll
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
result = DetourCreateProcessWithDllsA(
|
|
|
|
sGameExe, // lpApplicationName
|
|
|
|
sCommandLine, // lpCommandLine
|
|
|
|
NULL, // lpProcessAttributes
|
|
|
|
NULL, // lpThreadAttributes
|
|
|
|
FALSE, // bInheritHandles
|
|
|
|
CREATE_SUSPENDED, // dwCreationFlags
|
|
|
|
NULL, // lpEnvironment
|
|
|
|
sGameDirectory, // lpCurrentDirectory
|
|
|
|
&StartupInfo, // lpStartupInfo
|
|
|
|
&ProcInfo, // lpProcessInformation
|
|
|
|
1, // nDlls
|
|
|
|
DllsToInject, // rlpDlls
|
|
|
|
NULL // pfCreateProcessA
|
|
|
|
);
|
|
|
|
|
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[])
|
|
|
|
{
|
|
|
|
LaunchR5Apex();
|
2021-04-16 14:12:39 +02:00
|
|
|
Sleep(1000);
|
2021-04-13 04:45:22 -07:00
|
|
|
return 0;
|
2021-06-17 17:07:26 -07:00
|
|
|
}
|