Skip to content

Commit 8c2dce2

Browse files
committed
Enhance the injector.
1 parent b7d57f9 commit 8c2dce2

4 files changed

Lines changed: 70 additions & 69 deletions

File tree

WinSplitPlusApp/Version.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#define PROD_NAME "WinSplitPlus (32-bit)"
99
#endif
1010

11-
#define VER_FILEVERSION 1,2,0,0
12-
#define VER_FILEVERSION_STR "1.2.0.0\0"
11+
#define VER_FILEVERSION 1,3,5,0
12+
#define VER_FILEVERSION_STR "1.3.5.0\0"
1313

14-
#define VER_PRODUCTVERSION 1,2,0,0
15-
#define VER_PRODUCTVERSION_STR "1.2.0.0\0"
14+
#define VER_PRODUCTVERSION 1,3,5,0
15+
#define VER_PRODUCTVERSION_STR "1.3.5.0\0"
1616

1717
VS_VERSION_INFO VERSIONINFO
1818
FILEVERSION VER_FILEVERSION

WinSplitPlusApp/main.cpp

Lines changed: 44 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ void print_usage() {
3131
<< L" -A Enable ANSI hooks (e.g. RegisterClassA).\n"
3232
<< L" -W Enable Unicode hooks (e.g. RegisterClassW).\n"
3333
<< L" -Std Enable Standard hooks (e.g. RegisterClass).\n"
34-
<< L" -Ex Enable Extended hooks (e.g. RegisterClassEx).\n\n"
34+
<< L" -Ex Enable Extended hooks (e.g. RegisterClassEx).\n"
3535
<< L" -IgnoreWinClass <Name> Ignore specific Class Name (partial match).\n"
36-
<< L" -IgnoreWinName <Name> Ignore specific Window Name (partial match).\n"
36+
<< L" -IgnoreWinName <Name> Ignore specific Window Name (partial match).\n\n"
3737
<< L" (If no filters are provided, ALL are enabled by default.)\n\n";
3838
}
3939

@@ -218,10 +218,7 @@ int wmain(int argc, wchar_t* argv[])
218218
WCHAR exePath[MAX_PATH];
219219
GetModuleFileName(NULL, exePath, MAX_PATH);
220220
std::wstring exeDir = exePath;
221-
size_t lastSlash = exeDir.find_last_of(L"\\/");
222-
if (lastSlash != std::wstring::npos) {
223-
exeDir = exeDir.substr(0, lastSlash);
224-
}
221+
exeDir = exeDir.substr(0, exeDir.find_last_of(L"\\/"));
225222

226223
std::wstring coreDllName;
227224

@@ -244,96 +241,85 @@ int wmain(int argc, wchar_t* argv[])
244241

245242
// Plugin DLLs
246243
std::vector<std::wstring> pluginDlls;
247-
std::wstring pluginsDir = exeDir + L"\\plugins\\";
248-
std::wstring searchPath = pluginsDir + L"*.dll";
244+
std::wstring searchPath = exeDir + L"\\plugins\\*.dll";
249245
WIN32_FIND_DATA wfd;
250246
HANDLE hFind = FindFirstFile(searchPath.c_str(), &wfd);
251247

252248
if (hFind != INVALID_HANDLE_VALUE) {
253249
do {
254250
std::wstring filename = wfd.cFileName;
255251
std::wstring lowerName = to_lower(filename);
256-
if (lowerName.length() >= 4 &&
257-
lowerName.substr(lowerName.length() - 4) == L".dll")
258-
{
259-
pluginDlls.push_back(pluginsDir + filename);
260-
}
261-
else
262-
{
263-
//std::wcout << L"Skipping invalid match: " << filename << std::endl;
264-
}
265-
252+
if (lowerName.length() >= 4 && lowerName.substr(lowerName.length() - 4) == L".dll")
253+
pluginDlls.push_back(exeDir + L"\\plugins\\" + filename);
266254
} while (FindNextFile(hFind, &wfd));
267255
FindClose(hFind);
268256
}
269-
else {
270-
std::wcout << L"No plugins found in " << pluginsDir << std::endl;
271-
}
272257

273258
// Launch Process
274259
PROCESS_INFORMATION pi = {};
275260
STARTUPINFOW si = {};
276261
si.cb = sizeof(si);
277-
278262
std::wstring fullCommandLine = L"\"" + gamePath + L"\" " + gameArgs;
279263

280264
std::wcout << L"Launching game suspended: " << gamePath << std::endl;
281-
282-
if (!CreateProcess(
283-
NULL,
284-
const_cast<wchar_t*>(fullCommandLine.c_str()), // Command line
285-
NULL,
286-
NULL,
287-
FALSE,
288-
CREATE_SUSPENDED,
289-
NULL,
290-
NULL,
291-
&si, // StartupInfo
292-
&pi // ProcessInfo
293-
)) {
294-
std::wcerr << L"Failed to create process: " << GetLastError() << std::endl;
295-
Sleep(7000);
265+
if (!CreateProcess(NULL, const_cast<wchar_t*>(fullCommandLine.c_str()), NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi)) {
266+
std::wcerr << L"Failed to create process." << std::endl;
296267
return 1;
297268
}
298269

299-
DWORD processId = pi.dwProcessId;
270+
std::wcout << L"Resuming process..." << std::endl;
271+
ResumeThread(pi.hThread);
300272

273+
std::wcout << L"Attempting to catch process..." << std::endl;
301274

302-
std::wcout << L"Injecting Core DLL via EasyHook..." << std::endl;
303-
NTSTATUS nt = RhInjectLibrary(
304-
processId,
305-
0,
306-
EASYHOOK_INJECT_DEFAULT,
275+
NTSTATUS nt = -1;
276+
int attempts = 0;
277+
const int MAX_ATTEMPTS = 50;
278+
279+
while (attempts < MAX_ATTEMPTS) {
280+
nt = RhInjectLibrary(
281+
pi.dwProcessId,
282+
0,
283+
EASYHOOK_INJECT_DEFAULT,
307284
#if defined(_WIN64)
308-
NULL, const_cast<wchar_t*>(coreDllPath.c_str()),
285+
NULL, const_cast<wchar_t*>(coreDllPath.c_str()),
309286
#else
310-
const_cast<wchar_t*>(coreDllPath.c_str()), NULL,
287+
const_cast<wchar_t*>(coreDllPath.c_str()), NULL,
311288
#endif
312-
& injectionInfo, sizeof(InjectionInfo)
313-
);
289+
& injectionInfo, sizeof(InjectionInfo)
290+
);
291+
292+
if (nt == 0) {
293+
std::wcout << L"Injection Successful on attempt " << (attempts + 1) << std::endl;
294+
break;
295+
}
296+
else {
297+
attempts++;
298+
Sleep(10);
299+
}
300+
}
314301

315302
if (nt != 0) {
316-
std::wcerr << L"Failed to inject Core DLL: " << RtlGetLastErrorString() << std::endl;
317-
std::wcerr << L"Terminating..." << std::endl;
318-
TerminateProcess(pi.hProcess, 1);
303+
std::wcerr << L"CRITICAL FAILURE: Could not inject after " << MAX_ATTEMPTS << " attempts." << std::endl;
304+
std::wcerr << L"Last Error: " << RtlGetLastErrorString() << std::endl;
305+
// TerminateProcess(pi.hProcess, 1);
319306
return 1;
320307
}
321308

322-
if (!pluginDlls.empty())
323-
{
324-
std::wcout << L"Injecting " << pluginDlls.size() << L" plugins via LoadLibrary..." << std::endl;
309+
std::wcout << L"Waiting for hooks to settle..." << std::endl;
310+
Sleep(2000);
311+
312+
if (!pluginDlls.empty()) {
313+
std::wcout << L"Injecting plugins..." << std::endl;
325314
for (const auto& dllPath : pluginDlls) {
326315
InjectStandardDLL(pi.hProcess, dllPath);
316+
Sleep(200);
327317
}
328318
}
329319

330-
std::wcout << L"Resuming game process..." << std::endl;
331-
ResumeThread(pi.hThread);
332-
333320
CloseHandle(pi.hProcess);
334321
CloseHandle(pi.hThread);
335322

336-
std::wcout << L"Success. Launcher exiting." << std::endl;
337-
323+
std::wcout << L"Success." << std::endl;
338324
return 0;
339325
}

WinSplitPlusIJ/Version.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#define PROD_NAME "WinSplitPlusIJ (32-bit)"
99
#endif
1010

11-
#define VER_FILEVERSION 1,3,0,0
12-
#define VER_FILEVERSION_STR "1.3.0.0\0"
11+
#define VER_FILEVERSION 1,3,3,0
12+
#define VER_FILEVERSION_STR "1.3.3.0\0"
1313

14-
#define VER_PRODUCTVERSION 1,3,0,0
15-
#define VER_PRODUCTVERSION_STR "1.3.0.0\0"
14+
#define VER_PRODUCTVERSION 1,3,3,0
15+
#define VER_PRODUCTVERSION_STR "1.3.3.0\0"
1616

1717
VS_VERSION_INFO VERSIONINFO
1818
FILEVERSION VER_FILEVERSION

WinSplitPlusIJ/WinSplitPlusIJ.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,22 @@ bool IgnoreClassA(LPCSTR lpClassName)
7171
// Internal helpers
7272
if (strstr(lpClassName, "Overlay") != NULL) return true;
7373
if (strstr(lpClassName, "MSXML") != NULL) return true;
74-
if (strstr(lpClassName, "DirectInput") != NULL) return true;
74+
if (strstr(lpClassName, "DIEmWin") != NULL) return true;
7575
if (strstr(lpClassName, "DirectSound") != NULL) return true;
7676
if (strstr(lpClassName, "Direct3D") != NULL) return true;
7777
if (strstr(lpClassName, "DirectDraw") != NULL) return true;
78+
if (strstr(lpClassName, "RawInput") != NULL) return true;
79+
80+
// SDL
81+
if (strstr(lpClassName, "SDL_app") != NULL) return true;
82+
if (strstr(lpClassName, "SDL_HIDAPI_DEVICE_DETECTION") != NULL) return true;
83+
if (strstr(lpClassName, "SDLHelperWindowInputCatcher") != NULL) return true;
84+
if (strstr(lpClassName, "Message") != NULL) return true;
7885

7986
// System
8087
if (strstr(lpClassName, "IME") != NULL) return true;
8188
if (strstr(lpClassName, "MSCTF") != NULL) return true;
82-
89+
if (strstr(lpClassName, "MSCTFIME UI") != NULL) return true;
8390
return false;
8491
}
8592

@@ -124,14 +131,22 @@ bool IgnoreClassW(LPCWSTR lpClassName)
124131
// Internal helpers
125132
if (wcsstr(lpClassName, L"Overlay") != NULL) return true;
126133
if (wcsstr(lpClassName, L"MSXML") != NULL) return true;
127-
if (wcsstr(lpClassName, L"DirectInput") != NULL) return true;
134+
if (wcsstr(lpClassName, L"DIEmWin") != NULL) return true;
128135
if (wcsstr(lpClassName, L"DirectSound") != NULL) return true;
129136
if (wcsstr(lpClassName, L"Direct3D") != NULL) return true;
130137
if (wcsstr(lpClassName, L"DirectDraw") != NULL) return true;
138+
if (wcsstr(lpClassName, L"RawInput") != NULL) return true;
139+
140+
// SDL
141+
if (wcsstr(lpClassName, L"SDL_app") != NULL) return true;
142+
if (wcsstr(lpClassName, L"SDL_HIDAPI_DEVICE_DETECTION") != NULL) return true;
143+
if (wcsstr(lpClassName, L"SDLHelperWindowInputCatcher") != NULL) return true;
144+
if (wcsstr(lpClassName, L"Message") != NULL) return true;
131145

132146
// System
133147
if (wcsstr(lpClassName, L"IME") != NULL) return true;
134148
if (wcsstr(lpClassName, L"MSCTF") != NULL) return true;
149+
if (wcsstr(lpClassName, L"MSCTFIME UI") != NULL) return true;
135150

136151
return false;
137152
}

0 commit comments

Comments
 (0)