2019-12-03 12:52:12 -05:00
|
|
|
// My own modified version of ColdClientLoader originally written by Rat431
|
2023-12-24 06:42:36 +02:00
|
|
|
// https://github.com/Rat431/ColdAPI_Steam/tree/master/src/ColdClientLoader
|
2019-12-03 12:52:12 -05:00
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
|
|
|
// Windows Header Files
|
|
|
|
#include <windows.h>
|
|
|
|
// C RunTime Header Files
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <tchar.h>
|
2020-07-06 11:27:05 -04:00
|
|
|
#include <stdio.h>
|
2019-12-03 12:52:12 -05:00
|
|
|
|
2021-04-29 18:53:13 -04:00
|
|
|
bool IsNotRelativePathOrRemoveFileName(WCHAR* output, bool Remove)
|
2019-12-03 12:52:12 -05:00
|
|
|
{
|
2021-04-29 18:53:13 -04:00
|
|
|
int LG = lstrlenW(output);
|
2019-12-03 12:52:12 -05:00
|
|
|
for (int i = LG; i > 0; i--) {
|
|
|
|
if (output[i] == '\\') {
|
|
|
|
if(Remove)
|
2021-04-29 18:53:13 -04:00
|
|
|
RtlFillMemory(&output[i], (LG - i) * sizeof(WCHAR), NULL);
|
2019-12-03 12:52:12 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
|
|
|
|
{
|
2021-04-29 18:53:13 -04:00
|
|
|
WCHAR CurrentDirectory[MAX_PATH] = { 0 };
|
|
|
|
WCHAR Client64Path[MAX_PATH] = { 0 };
|
|
|
|
WCHAR ClientPath[MAX_PATH] = { 0 };
|
|
|
|
WCHAR ExeFile[MAX_PATH] = { 0 };
|
|
|
|
WCHAR ExeRunDir[MAX_PATH] = { 0 };
|
|
|
|
WCHAR ExeCommandLine[4096] = { 0 };
|
|
|
|
WCHAR AppId[128] = { 0 };
|
|
|
|
|
2023-12-24 06:39:42 +02:00
|
|
|
STARTUPINFOW info = { 0 };
|
|
|
|
SecureZeroMemory(&info, sizeof(info));
|
|
|
|
info.cb = sizeof(info);
|
|
|
|
|
|
|
|
PROCESS_INFORMATION processInfo = { 0 };
|
|
|
|
SecureZeroMemory(&processInfo, sizeof(processInfo));
|
2019-12-03 12:52:12 -05:00
|
|
|
|
2021-04-29 18:53:13 -04:00
|
|
|
int Length = GetModuleFileNameW(GetModuleHandleW(NULL), CurrentDirectory, sizeof(CurrentDirectory)) + 1;
|
2019-12-03 12:52:12 -05:00
|
|
|
for (int i = Length; i > 0; i--) {
|
|
|
|
if (CurrentDirectory[i] == '\\') {
|
2021-04-29 18:53:13 -04:00
|
|
|
lstrcpyW(&CurrentDirectory[i + 1], L"ColdClientLoader.ini");
|
2019-12-03 12:52:12 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-12-24 06:41:34 +02:00
|
|
|
|
2021-04-29 18:53:13 -04:00
|
|
|
if (GetFileAttributesW(CurrentDirectory) == INVALID_FILE_ATTRIBUTES) {
|
2019-12-03 12:52:12 -05:00
|
|
|
MessageBoxA(NULL, "Couldn't find the configuration file(ColdClientLoader.ini).", "ColdClientLoader", MB_ICONERROR);
|
2023-12-24 06:41:34 +02:00
|
|
|
return 1;
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
|
|
|
|
2021-04-29 18:53:13 -04:00
|
|
|
GetPrivateProfileStringW(L"SteamClient", L"SteamClient64Dll", L"", Client64Path, MAX_PATH, CurrentDirectory);
|
|
|
|
GetPrivateProfileStringW(L"SteamClient", L"SteamClientDll", L"", ClientPath, MAX_PATH, CurrentDirectory);
|
|
|
|
GetPrivateProfileStringW(L"SteamClient", L"Exe", NULL, ExeFile, MAX_PATH, CurrentDirectory);
|
|
|
|
GetPrivateProfileStringW(L"SteamClient", L"ExeRunDir", NULL, ExeRunDir, MAX_PATH, CurrentDirectory);
|
|
|
|
GetPrivateProfileStringW(L"SteamClient", L"ExeCommandLine", NULL, ExeCommandLine, 4096, CurrentDirectory);
|
|
|
|
GetPrivateProfileStringW(L"SteamClient", L"AppId", NULL, AppId, sizeof(AppId), CurrentDirectory);
|
2019-12-03 12:52:12 -05:00
|
|
|
|
|
|
|
if (AppId[0]) {
|
2021-04-29 18:53:13 -04:00
|
|
|
SetEnvironmentVariableW(L"SteamAppId", AppId);
|
|
|
|
SetEnvironmentVariableW(L"SteamGameId", AppId);
|
2023-12-19 16:48:07 +02:00
|
|
|
SetEnvironmentVariableW(L"SteamOverlayGameId", AppId);
|
2021-04-29 18:53:13 -04:00
|
|
|
} else {
|
|
|
|
MessageBoxA(NULL, "You forgot to set the AppId.", "ColdClientLoader", MB_ICONERROR);
|
2023-12-24 06:41:34 +02:00
|
|
|
return 1;
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
|
|
|
|
2023-12-24 06:42:02 +02:00
|
|
|
WCHAR TMP[MAX_PATH] = { 0 };
|
2019-12-03 12:52:12 -05:00
|
|
|
if (!IsNotRelativePathOrRemoveFileName(Client64Path, false)) {
|
2021-04-29 18:53:13 -04:00
|
|
|
lstrcpyW(TMP, Client64Path);
|
2023-12-24 06:40:33 +02:00
|
|
|
SecureZeroMemory(Client64Path, sizeof(Client64Path));
|
2021-04-29 18:53:13 -04:00
|
|
|
GetFullPathNameW(TMP, MAX_PATH, Client64Path, NULL);
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
|
|
|
if (!IsNotRelativePathOrRemoveFileName(ClientPath, false)) {
|
2021-04-29 18:53:13 -04:00
|
|
|
lstrcpyW(TMP, ClientPath);
|
2023-12-24 06:40:33 +02:00
|
|
|
SecureZeroMemory(ClientPath, sizeof(ClientPath));
|
2021-04-29 18:53:13 -04:00
|
|
|
GetFullPathNameW(TMP, MAX_PATH, ClientPath, NULL);
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
|
|
|
if (!IsNotRelativePathOrRemoveFileName(ExeFile, false)) {
|
2021-04-29 18:53:13 -04:00
|
|
|
lstrcpyW(TMP, ExeFile);
|
2023-12-24 06:40:33 +02:00
|
|
|
SecureZeroMemory(ExeFile, sizeof(ExeFile));
|
2021-04-29 18:53:13 -04:00
|
|
|
GetFullPathNameW(TMP, MAX_PATH, ExeFile, NULL);
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
|
|
|
if (!IsNotRelativePathOrRemoveFileName(ExeRunDir, false)) {
|
2021-04-29 18:53:13 -04:00
|
|
|
lstrcpyW(TMP, ExeRunDir);
|
2023-12-24 06:40:33 +02:00
|
|
|
SecureZeroMemory(ExeRunDir, sizeof(ExeRunDir));
|
2021-04-29 18:53:13 -04:00
|
|
|
GetFullPathNameW(TMP, MAX_PATH, ExeRunDir, NULL);
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
|
|
|
|
2021-04-29 18:53:13 -04:00
|
|
|
if (GetFileAttributesW(Client64Path) == INVALID_FILE_ATTRIBUTES) {
|
2019-12-03 12:52:12 -05:00
|
|
|
MessageBoxA(NULL, "Couldn't find the requested SteamClient64Dll.", "ColdClientLoader", MB_ICONERROR);
|
2023-12-24 06:41:34 +02:00
|
|
|
return 1;
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
|
|
|
|
2021-04-29 18:53:13 -04:00
|
|
|
if (GetFileAttributesW(ClientPath) == INVALID_FILE_ATTRIBUTES) {
|
2019-12-03 12:52:12 -05:00
|
|
|
MessageBoxA(NULL, "Couldn't find the requested SteamClientDll.", "ColdClientLoader", MB_ICONERROR);
|
2023-12-24 06:41:34 +02:00
|
|
|
return 1;
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
|
|
|
|
2021-04-29 18:53:13 -04:00
|
|
|
if (GetFileAttributesW(ExeFile) == INVALID_FILE_ATTRIBUTES) {
|
2019-12-03 12:52:12 -05:00
|
|
|
MessageBoxA(NULL, "Couldn't find the requested Exe file.", "ColdClientLoader", MB_ICONERROR);
|
2023-12-24 06:41:34 +02:00
|
|
|
return 1;
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
|
|
|
|
2023-12-24 06:39:00 +02:00
|
|
|
WCHAR CommandLine[16384] = { 0 };
|
|
|
|
_snwprintf(CommandLine, _countof(CommandLine), L"\"%ls\" %ls %ls", ExeFile, ExeCommandLine, lpCmdLine);
|
2021-04-29 18:53:13 -04:00
|
|
|
if (!ExeFile[0] || !CreateProcessW(ExeFile, CommandLine, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, ExeRunDir, &info, &processInfo))
|
2019-12-03 12:52:12 -05:00
|
|
|
{
|
|
|
|
MessageBoxA(NULL, "Unable to load the requested EXE file.", "ColdClientLoader", MB_ICONERROR);
|
2023-12-24 06:41:34 +02:00
|
|
|
return 1;
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
2023-12-24 06:42:02 +02:00
|
|
|
|
|
|
|
HKEY Registrykey = { 0 };
|
2019-12-03 12:52:12 -05:00
|
|
|
// Declare some variables to be used for Steam registry.
|
|
|
|
DWORD UserId = 0x03100004771F810D & 0xffffffff;
|
|
|
|
DWORD ProcessID = GetCurrentProcessId();
|
|
|
|
|
2021-02-07 19:05:22 -05:00
|
|
|
bool orig_steam = false;
|
|
|
|
DWORD keyType = REG_SZ;
|
2021-04-29 18:53:13 -04:00
|
|
|
WCHAR OrgSteamCDir[MAX_PATH] = { 0 };
|
|
|
|
WCHAR OrgSteamCDir64[MAX_PATH] = { 0 };
|
2021-02-07 19:05:22 -05:00
|
|
|
DWORD Size1 = MAX_PATH;
|
|
|
|
DWORD Size2 = MAX_PATH;
|
2021-04-29 18:53:13 -04:00
|
|
|
if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Valve\\Steam\\ActiveProcess", 0, KEY_ALL_ACCESS, &Registrykey) == ERROR_SUCCESS)
|
2019-12-03 12:52:12 -05:00
|
|
|
{
|
2021-02-07 19:05:22 -05:00
|
|
|
orig_steam = true;
|
|
|
|
// Get original values to restore later.
|
2021-04-29 18:53:13 -04:00
|
|
|
RegQueryValueExW(Registrykey, L"SteamClientDll", 0, &keyType, (LPBYTE)& OrgSteamCDir, &Size1);
|
|
|
|
RegQueryValueExW(Registrykey, L"SteamClientDll64", 0, &keyType, (LPBYTE)& OrgSteamCDir64, &Size2);
|
2021-02-07 19:05:22 -05:00
|
|
|
} else {
|
2021-04-29 18:53:13 -04:00
|
|
|
if (RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\Valve\\Steam\\ActiveProcess", 0, 0, REG_OPTION_NON_VOLATILE,
|
2019-12-03 12:52:12 -05:00
|
|
|
KEY_ALL_ACCESS, NULL, &Registrykey, NULL) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
TerminateProcess(processInfo.hProcess, NULL);
|
2023-12-24 06:42:25 +02:00
|
|
|
MessageBoxA(NULL, "Unable to patch Steam process informations on the Windows registry.", "ColdClientLoader", MB_ICONERROR);
|
2023-12-24 06:41:34 +02:00
|
|
|
return 1;
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 19:05:22 -05:00
|
|
|
// Set values to Windows registry.
|
|
|
|
RegSetValueExA(Registrykey, "ActiveUser", NULL, REG_DWORD, (LPBYTE)& UserId, sizeof(DWORD));
|
|
|
|
RegSetValueExA(Registrykey, "pid", NULL, REG_DWORD, (LPBYTE)& ProcessID, sizeof(DWORD));
|
2019-12-03 12:52:12 -05:00
|
|
|
|
2021-02-07 19:05:22 -05:00
|
|
|
{
|
|
|
|
// Before saving to the registry check again if the path was valid and if the file exist
|
2021-04-29 18:53:13 -04:00
|
|
|
if (GetFileAttributesW(ClientPath) != INVALID_FILE_ATTRIBUTES) {
|
|
|
|
RegSetValueExW(Registrykey, L"SteamClientDll", NULL, REG_SZ, (LPBYTE)ClientPath, (DWORD)(lstrlenW(ClientPath) * sizeof(WCHAR)) + 1);
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|
2021-02-07 19:05:22 -05:00
|
|
|
else {
|
2021-04-29 18:53:13 -04:00
|
|
|
RegSetValueExW(Registrykey, L"SteamClientDll", NULL, REG_SZ, (LPBYTE)"", 0);
|
2021-02-07 19:05:22 -05:00
|
|
|
}
|
2021-04-29 18:53:13 -04:00
|
|
|
if (GetFileAttributesW(Client64Path) != INVALID_FILE_ATTRIBUTES) {
|
|
|
|
RegSetValueExW(Registrykey, L"SteamClientDll64", NULL, REG_SZ, (LPBYTE)Client64Path, (DWORD)(lstrlenW(Client64Path) * sizeof(WCHAR)) + 1);
|
2021-02-07 19:05:22 -05:00
|
|
|
}
|
|
|
|
else {
|
2021-04-29 18:53:13 -04:00
|
|
|
RegSetValueExW(Registrykey, L"SteamClientDll64", NULL, REG_SZ, (LPBYTE)"", 0);
|
2021-02-07 19:05:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
RegSetValueExA(Registrykey, "Universe", NULL, REG_SZ, (LPBYTE)"Public", (DWORD)lstrlenA("Public") + 1);
|
2019-12-03 12:52:12 -05:00
|
|
|
|
2021-02-07 19:05:22 -05:00
|
|
|
// Close the HKEY Handle.
|
|
|
|
RegCloseKey(Registrykey);
|
2019-12-03 12:52:12 -05:00
|
|
|
|
2021-02-07 19:05:22 -05:00
|
|
|
ResumeThread(processInfo.hThread);
|
|
|
|
WaitForSingleObject(processInfo.hThread, INFINITE);
|
|
|
|
CloseHandle(processInfo.hProcess);
|
|
|
|
CloseHandle(processInfo.hThread);
|
2019-12-03 12:52:12 -05:00
|
|
|
|
2021-02-07 19:05:22 -05:00
|
|
|
if (orig_steam) {
|
2021-04-29 18:53:13 -04:00
|
|
|
if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Valve\\Steam\\ActiveProcess", 0, KEY_ALL_ACCESS, &Registrykey) == ERROR_SUCCESS)
|
2019-12-03 12:52:12 -05:00
|
|
|
{
|
|
|
|
// Restore the values.
|
2021-04-29 18:53:13 -04:00
|
|
|
RegSetValueExW(Registrykey, L"SteamClientDll", NULL, REG_SZ, (LPBYTE)OrgSteamCDir, Size1);
|
|
|
|
RegSetValueExW(Registrykey, L"SteamClientDll64", NULL, REG_SZ, (LPBYTE)OrgSteamCDir64, Size2);
|
2019-12-03 12:52:12 -05:00
|
|
|
|
|
|
|
// Close the HKEY Handle.
|
|
|
|
RegCloseKey(Registrykey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 19:05:22 -05:00
|
|
|
return 0;
|
2019-12-03 12:52:12 -05:00
|
|
|
}
|