-
Contributor
[2.4.3][C++][Injection] Injecting a c++ dll cause lagging the client.
I have such a weird behavior.
When i inject any c++ code in the tbc(2.4.3) client - it starts chopping/lagging the video.
Remarks:
1. When the video settings details are on max - the more the chopping is noticeable (only happens on 2.4.3 and c++ dll injection).
2. It only happens on the 2.4.3 client. The 1.12.1 and 3.3.5a are never concerned.
3. The .net clr injection is working fine too and never cause problems neither.
I googled and i tried, tried and googled again, but since I'm still a beginner, i need your help guys.
Here is my injected code that causes lag on the 2.4.3 client:
Code:
#ifndef WIN32
#define WIN32
#endif
#include <WinSock2.h>
HINSTANCE instanceDLL = nullptr;
void MainThread()
{
while (!GetAsyncKeyState(VK_NUMPAD7)) {}
FreeLibraryAndExitThread((HMODULE)instanceDLL, 0);
return;
}
BOOL APIENTRY DllMain(HINSTANCE instDLL, DWORD reason, LPVOID /* reserved */)
{
if (reason == DLL_PROCESS_ATTACH)
{
instanceDLL = instDLL;
DisableThreadLibraryCalls(instDLL);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&MainThread, NULL, 0, NULL);
}
else if (reason == DLL_PROCESS_DETACH) {}
return TRUE;
}
Thanks in advance!
-
Active Member
while (!GetAsyncKeyState(VK_NUMPAD7)) {}
-
Originally Posted by
tutrakan
I have such a weird behavior.
When i inject any c++ code in the tbc(2.4.3) client - it starts chopping/lagging the video.
Remarks:
1. When the video settings details are on max - the more the chopping is noticeable (only happens on 2.4.3 and c++ dll injection).
2. It only happens on the 2.4.3 client. The 1.12.1 and 3.3.5a are never concerned.
3. The .net clr injection is working fine too and never cause problems neither.
I googled and i tried, tried and googled again, but since I'm still a beginner, i need your help guys.
Here is my injected code that causes lag on the 2.4.3 client:
Code:
#ifndef WIN32
#define WIN32
#endif
#include <WinSock2.h>
HINSTANCE instanceDLL = nullptr;
void MainThread()
{
while (!GetAsyncKeyState(VK_NUMPAD7)) {}
FreeLibraryAndExitThread((HMODULE)instanceDLL, 0);
return;
}
BOOL APIENTRY DllMain(HINSTANCE instDLL, DWORD reason, LPVOID /* reserved */)
{
if (reason == DLL_PROCESS_ATTACH)
{
instanceDLL = instDLL;
DisableThreadLibraryCalls(instDLL);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&MainThread, NULL, 0, NULL);
}
else if (reason == DLL_PROCESS_DETACH) {}
return TRUE;
}
Thanks in advance!
The only explanation I can think for this is that the affinity of the newly created thread places it on the same CPU as the main thread, and given that you never sleep your newly created thread, it uses up 100% available CPU.
Try changing the loop in 'MainThread' to something like this:
Code:
while (!GetAsyncKeyState(VK_NUMPAD7)) { std::this_thread::sleep_for(std::chrono::milliseconds(250)); }
-
Post Thanks / Like - 2 Thanks
tutrakan,
Jansi (2 members gave Thanks to namreeb for this useful post)
-
Contributor
Well, thank you a lot!
I was about to get crazy wondering why the heck this happens only in c++ and only on 2.4.3.
But the true is that I still look at it as a "black box" and I'm missing the logic.
Thanks Namreeb.
Edit:
I just found another TBC anomaly - When I inject my c# dll and do the same graphics I do on the other clients, the video is lagging again.
The remedy I found, is to check "Vertical Sync" in the video options, thus way the fps don't goes up to 1000, but max 250.
Last edited by tutrakan; 04-14-2017 at 10:25 PM.