Skip to content

Commit 2182828

Browse files
committed
Fixed CPU consumption
1 parent 86ec4d3 commit 2182828

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

RawInput2/main.cpp

+20-16
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,10 @@ float m_flMouseSampleTime;
3535

3636
void Error(char* text)
3737
{
38-
MessageBox(0, text, "ERROR", 16);
38+
MessageBoxA(0, text, "ERROR", 16);
3939
ExitProcess(0);
4040
}
4141

42-
void UpdateConsole()
43-
{
44-
system("cls");
45-
printf("Set \"m_rawinput 2\" in game for it to take effect.\n");
46-
printf("Use DELETE button to unhook and shutdown RawInput2.\n");
47-
}
48-
4942
bool GetRawMouseAccumulators(int& accumX, int& accumY, double frame_split)
5043
{
5144
static int* m_mouseRawAccumX = (int*)((uintptr_t)g_InputSystem + 0x119C);
@@ -203,7 +196,15 @@ void __fastcall Hooked_IN_SetSampleTime(void* thisptr, void* edx, float frametim
203196
oIn_SetSampleTime(thisptr, frametime);
204197
}
205198

206-
DWORD InjectionEntryPoint()
199+
BOOL IsProcessRunning(DWORD processID)
200+
{
201+
HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, processID);
202+
DWORD ret = WaitForSingleObject(process, 0);
203+
CloseHandle(process);
204+
return ret == WAIT_TIMEOUT;
205+
}
206+
207+
DWORD InjectionEntryPoint(DWORD processID)
207208
{
208209
LoadLibraryA("VCRUNTIME140.dll");
209210

@@ -221,7 +222,7 @@ DWORD InjectionEntryPoint()
221222
ConMsg = (ConMsgFn)(uintptr_t)GetProcAddress((HMODULE)tier, "?ConMsg@@YAXPBDZZ");
222223
Plat_FloatTime = (Plat_FloatTimeFn)(uintptr_t)GetProcAddress((HMODULE)tier, "Plat_FloatTime");
223224

224-
//ConMsg("Plat_FloatTime: %.5f\n", plat_floattime());
225+
//ConMsg("Plat_FloatTime: %.5f\n", Plat_FloatTime());
225226

226227
DetourTransactionBegin();
227228
DetourUpdateThread(GetCurrentThread());
@@ -232,9 +233,10 @@ DWORD InjectionEntryPoint()
232233
DetourAttach(&(PVOID&)oIn_SetSampleTime, Hooked_IN_SetSampleTime);
233234
DetourTransactionCommit();
234235

235-
while (!(GetAsyncKeyState(VK_DELETE) & 0x8000))
236+
while (IsProcessRunning(processID))
237+
//while(FindWindowA(NULL, "CS:S RawInput2") != 0)
236238
{
237-
Sleep(100);
239+
Sleep(1000);
238240
}
239241

240242
DetourTransactionBegin();
@@ -251,7 +253,7 @@ DWORD InjectionEntryPoint()
251253
}
252254

253255
//Credits: https://www.ired.team/offensive-security/code-injection-process-injection/pe-injection-executing-pes-inside-remote-processes
254-
void PEInjector(DWORD processID, DWORD Func())
256+
void PEInjector(DWORD processID, DWORD Func(DWORD))
255257
{
256258
// Get current image's base address
257259
PVOID imageBase = GetModuleHandle(NULL);
@@ -297,7 +299,7 @@ void PEInjector(DWORD processID, DWORD Func())
297299
WriteProcessMemory(targetProcess, targetImage, localImage, ntHeader->OptionalHeader.SizeOfImage, NULL);
298300

299301
// Start the injected PE inside the target process
300-
CreateRemoteThread(targetProcess, NULL, 0, (LPTHREAD_START_ROUTINE)((DWORD_PTR)Func + deltaImageBase), NULL, 0, NULL);
302+
CreateRemoteThread(targetProcess, NULL, 0, (LPTHREAD_START_ROUTINE)((DWORD_PTR)Func + deltaImageBase), (LPVOID)GetCurrentProcessId(), 0, NULL);
301303
}
302304

303305
//Сredits: https://github.com/alkatrazbhop/BunnyhopAPE
@@ -333,10 +335,12 @@ int main()
333335
if (!strstr(cmdLine, " -insecure"))
334336
Error("-insecure key is missing!");
335337

336-
UpdateConsole();
338+
system("cls");
339+
printf("Set \"m_rawinput 2\" in game for it to take effect.\n");
337340

338341
PEInjector(processID, InjectionEntryPoint);
339342

340-
while (!(GetAsyncKeyState(VK_DELETE) & 0x8000)) {}
343+
344+
while (_getch() != VK_RETURN) {}
341345
return false;
342346
}

0 commit comments

Comments
 (0)