Cleanup steamclient loader a bit.

merge-requests/38/merge
Mr_Goldberg 2021-02-07 19:05:22 -05:00
parent 5f8a454e3f
commit 69d5facf4f
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
1 changed files with 46 additions and 85 deletions

View File

@ -45,7 +45,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
} }
if (GetFileAttributesA(CurrentDirectory) == INVALID_FILE_ATTRIBUTES) { if (GetFileAttributesA(CurrentDirectory) == INVALID_FILE_ATTRIBUTES) {
MessageBoxA(NULL, "Couldn't find the configuration file(ColdClientLoader.ini).", "ColdClientLoader", MB_ICONERROR); MessageBoxA(NULL, "Couldn't find the configuration file(ColdClientLoader.ini).", "ColdClientLoader", MB_ICONERROR);
ExitProcess(NULL); return 0;
} }
GetPrivateProfileStringA("SteamClient", "SteamClient64Dll", "", Client64Path, MAX_PATH, CurrentDirectory); GetPrivateProfileStringA("SteamClient", "SteamClient64Dll", "", Client64Path, MAX_PATH, CurrentDirectory);
@ -60,27 +60,23 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
SetEnvironmentVariableA("SteamGameId", AppId); SetEnvironmentVariableA("SteamGameId", AppId);
} }
CHAR TMP[MAX_PATH] = { 0 }; CHAR TMP[MAX_PATH] = {};
if (!IsNotRelativePathOrRemoveFileName(Client64Path, false)) { if (!IsNotRelativePathOrRemoveFileName(Client64Path, false)) {
ZeroMemory(TMP, sizeof(TMP));
lstrcpyA(TMP, Client64Path); lstrcpyA(TMP, Client64Path);
ZeroMemory(Client64Path, sizeof(Client64Path)); ZeroMemory(Client64Path, sizeof(Client64Path));
GetFullPathNameA(TMP, MAX_PATH, Client64Path, NULL); GetFullPathNameA(TMP, MAX_PATH, Client64Path, NULL);
} }
if (!IsNotRelativePathOrRemoveFileName(ClientPath, false)) { if (!IsNotRelativePathOrRemoveFileName(ClientPath, false)) {
ZeroMemory(TMP, sizeof(TMP));
lstrcpyA(TMP, ClientPath); lstrcpyA(TMP, ClientPath);
ZeroMemory(ClientPath, sizeof(ClientPath)); ZeroMemory(ClientPath, sizeof(ClientPath));
GetFullPathNameA(TMP, MAX_PATH, ClientPath, NULL); GetFullPathNameA(TMP, MAX_PATH, ClientPath, NULL);
} }
if (!IsNotRelativePathOrRemoveFileName(ExeFile, false)) { if (!IsNotRelativePathOrRemoveFileName(ExeFile, false)) {
ZeroMemory(TMP, sizeof(TMP));
lstrcpyA(TMP, ExeFile); lstrcpyA(TMP, ExeFile);
ZeroMemory(ExeFile, sizeof(ExeFile)); ZeroMemory(ExeFile, sizeof(ExeFile));
GetFullPathNameA(TMP, MAX_PATH, ExeFile, NULL); GetFullPathNameA(TMP, MAX_PATH, ExeFile, NULL);
} }
if (!IsNotRelativePathOrRemoveFileName(ExeRunDir, false)) { if (!IsNotRelativePathOrRemoveFileName(ExeRunDir, false)) {
ZeroMemory(TMP, sizeof(TMP));
lstrcpyA(TMP, ExeRunDir); lstrcpyA(TMP, ExeRunDir);
ZeroMemory(ExeRunDir, sizeof(ExeRunDir)); ZeroMemory(ExeRunDir, sizeof(ExeRunDir));
GetFullPathNameA(TMP, MAX_PATH, ExeRunDir, NULL); GetFullPathNameA(TMP, MAX_PATH, ExeRunDir, NULL);
@ -88,17 +84,17 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
if (GetFileAttributesA(Client64Path) == INVALID_FILE_ATTRIBUTES) { if (GetFileAttributesA(Client64Path) == INVALID_FILE_ATTRIBUTES) {
MessageBoxA(NULL, "Couldn't find the requested SteamClient64Dll.", "ColdClientLoader", MB_ICONERROR); MessageBoxA(NULL, "Couldn't find the requested SteamClient64Dll.", "ColdClientLoader", MB_ICONERROR);
ExitProcess(NULL); return 0;
} }
if (GetFileAttributesA(ClientPath) == INVALID_FILE_ATTRIBUTES) { if (GetFileAttributesA(ClientPath) == INVALID_FILE_ATTRIBUTES) {
MessageBoxA(NULL, "Couldn't find the requested SteamClientDll.", "ColdClientLoader", MB_ICONERROR); MessageBoxA(NULL, "Couldn't find the requested SteamClientDll.", "ColdClientLoader", MB_ICONERROR);
ExitProcess(NULL); return 0;
} }
if (GetFileAttributesA(ExeFile) == INVALID_FILE_ATTRIBUTES) { if (GetFileAttributesA(ExeFile) == INVALID_FILE_ATTRIBUTES) {
MessageBoxA(NULL, "Couldn't find the requested Exe file.", "ColdClientLoader", MB_ICONERROR); MessageBoxA(NULL, "Couldn't find the requested Exe file.", "ColdClientLoader", MB_ICONERROR);
ExitProcess(NULL); return 0;
} }
CHAR CommandLine[8192]; CHAR CommandLine[8192];
@ -106,73 +102,39 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
if (!ExeFile[0] || !CreateProcessA(ExeFile, CommandLine, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, ExeRunDir, &info, &processInfo)) if (!ExeFile[0] || !CreateProcessA(ExeFile, CommandLine, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, ExeRunDir, &info, &processInfo))
{ {
MessageBoxA(NULL, "Unable to load the requested EXE file.", "ColdClientLoader", MB_ICONERROR); MessageBoxA(NULL, "Unable to load the requested EXE file.", "ColdClientLoader", MB_ICONERROR);
ExitProcess(NULL); return 0;
} }
HKEY Registrykey; HKEY Registrykey;
// Declare some variables to be used for Steam registry. // Declare some variables to be used for Steam registry.
DWORD UserId = 0x03100004771F810D & 0xffffffff; DWORD UserId = 0x03100004771F810D & 0xffffffff;
DWORD ProcessID = GetCurrentProcessId(); DWORD ProcessID = GetCurrentProcessId();
if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Valve\\Steam\\ActiveProcess", 0, KEY_ALL_ACCESS, &Registrykey) != ERROR_SUCCESS) bool orig_steam = false;
{
if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Valve\\Steam\\ActiveProcess", 0, 0, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &Registrykey, NULL) != ERROR_SUCCESS)
{
MessageBoxA(NULL, "Unable to patch Steam process informations on the Windows registry.", "ColdClientLoader", MB_ICONERROR);
TerminateProcess(processInfo.hProcess, NULL);
ExitProcess(NULL);
}
else
{
// 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));
{
// Before saving to the registry check again if the path was valid and if the file exist
if (GetFileAttributesA(ClientPath) != INVALID_FILE_ATTRIBUTES) {
RegSetValueExA(Registrykey, "SteamClientDll", NULL, REG_SZ, (LPBYTE)ClientPath, (DWORD)lstrlenA(ClientPath) + 1);
}
else {
RegSetValueExA(Registrykey, "SteamClientDll", NULL, REG_SZ, (LPBYTE)"", 0);
}
if (GetFileAttributesA(Client64Path) != INVALID_FILE_ATTRIBUTES) {
RegSetValueExA(Registrykey, "SteamClientDll64", NULL, REG_SZ, (LPBYTE)Client64Path, (DWORD)lstrlenA(Client64Path) + 1);
}
else {
RegSetValueExA(Registrykey, "SteamClientDll64", NULL, REG_SZ, (LPBYTE)"", 0);
}
}
RegSetValueExA(Registrykey, "Universe", NULL, REG_SZ, (LPBYTE)"Public", (DWORD)lstrlenA("Public") + 1);
// Close the HKEY Handle.
RegCloseKey(Registrykey);
ResumeThread(processInfo.hThread);
WaitForSingleObject(processInfo.hThread, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
ExitProcess(NULL);
}
}
else
{
DWORD keyType = REG_SZ; DWORD keyType = REG_SZ;
CHAR OrgSteamCDir[MAX_PATH] = { 0 }; CHAR OrgSteamCDir[MAX_PATH] = { 0 };
CHAR OrgSteamCDir64[MAX_PATH] = { 0 }; CHAR OrgSteamCDir64[MAX_PATH] = { 0 };
DWORD Size1 = MAX_PATH; DWORD Size1 = MAX_PATH;
DWORD Size2 = MAX_PATH; DWORD Size2 = MAX_PATH;
if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Valve\\Steam\\ActiveProcess", 0, KEY_ALL_ACCESS, &Registrykey) == ERROR_SUCCESS)
{
orig_steam = true;
// Get original values to restore later. // Get original values to restore later.
RegQueryValueExA(Registrykey, "SteamClientDll", 0, &keyType, (LPBYTE)& OrgSteamCDir, &Size1); RegQueryValueExA(Registrykey, "SteamClientDll", 0, &keyType, (LPBYTE)& OrgSteamCDir, &Size1);
RegQueryValueExA(Registrykey, "SteamClientDll64", 0, &keyType, (LPBYTE)& OrgSteamCDir64, &Size2); RegQueryValueExA(Registrykey, "SteamClientDll64", 0, &keyType, (LPBYTE)& OrgSteamCDir64, &Size2);
} else {
if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Valve\\Steam\\ActiveProcess", 0, 0, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &Registrykey, NULL) != ERROR_SUCCESS)
{
MessageBoxA(NULL, "Unable to patch Steam process informations on the Windows registry.", "ColdClientLoader", MB_ICONERROR);
TerminateProcess(processInfo.hProcess, NULL);
return 0;
}
}
// Set values to Windows registry. // Set values to Windows registry.
RegSetValueExA(Registrykey, "ActiveUser", NULL, REG_DWORD, (LPBYTE)& UserId, sizeof(DWORD)); RegSetValueExA(Registrykey, "ActiveUser", NULL, REG_DWORD, (LPBYTE)& UserId, sizeof(DWORD));
RegSetValueExA(Registrykey, "pid", NULL, REG_DWORD, (LPBYTE)& ProcessID, sizeof(DWORD)); RegSetValueExA(Registrykey, "pid", NULL, REG_DWORD, (LPBYTE)& ProcessID, sizeof(DWORD));
{ {
// Before saving to the registry check again if the path was valid and if the file exist // Before saving to the registry check again if the path was valid and if the file exist
if (GetFileAttributesA(ClientPath) != INVALID_FILE_ATTRIBUTES) { if (GetFileAttributesA(ClientPath) != INVALID_FILE_ATTRIBUTES) {
@ -198,6 +160,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread); CloseHandle(processInfo.hThread);
if (orig_steam) {
if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Valve\\Steam\\ActiveProcess", 0, KEY_ALL_ACCESS, &Registrykey) == ERROR_SUCCESS) if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Valve\\Steam\\ActiveProcess", 0, KEY_ALL_ACCESS, &Registrykey) == ERROR_SUCCESS)
{ {
// Restore the values. // Restore the values.
@ -207,9 +170,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
// Close the HKEY Handle. // Close the HKEY Handle.
RegCloseKey(Registrykey); RegCloseKey(Registrykey);
} }
ExitProcess(NULL);
} }
return 0;
return 1;
} }