我做了.dll,我注入了游戏。它按下alt + s后运行像素检测,但游戏滞后。有没有可能解决它?
它会检测到红色,按下鼠标3并在游戏中拍摄但速度太慢且游戏滞后。
我试图删除Sleep(),但它更多。有什么建议吗?
#include <windows.h>
#include <gdiplus.h>
const int SX = GetSystemMetrics(SM_CXSCREEN);
const int SY = GetSystemMetrics(SM_CYSCREEN);
const int SCREEN_X = (SX/2);
const int SCREEN_Y = (SY/2);
const COLORREF red=RGB(255, 0, 0);
const int Sound[]={SND_ALIAS_SYSTEMASTERISK,SND_ALIAS_SYSTEMEXCLAMATION};
const int State[]={MOUSEEVENTF_MIDDLEDOWN,MOUSEEVENTF_MIDDLEUP};
bool PixelCheck(HDC hdc)
{
time_t stop=GetTickCount()+50;
bool result=false;
while(GetTickCount()<stop) if(GetPixel(hdc,SCREEN_X,SCREEN_Y) == red) result=true;
Sleep(1);
return result;
}
DWORD WINAPI ThreadFunction(PVOID pvParam)
{
HDC hdc=GetDC(0);
bool shotbot=false,isdown=false;
INPUT ip;
ip.type=INPUT_MOUSE;
ip.mi.dx=0;
ip.mi.dy=0;
ip.mi.dwExtraInfo=0;
while(true)
{
if(GetAsyncKeyState(0xA4) && GetAsyncKeyState(0x53))
{
shotbot=!shotbot;
PlaySound((LPCSTR)Sound[shotbot],NULL,SND_ALIAS_ID);
}
Sleep(1);
if((shotbot&&PixelCheck(hdc))||isdown)
{
ip.mi.dwFlags=State[isdown];
SendInput(1,&ip,sizeof(INPUT));
isdown=!isdown;
}
}
ReleaseDC(0, hdc);
return 0;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
if(fdwReason==DLL_PROCESS_ATTACH) SetThreadPriority(CreateThread(0,0,ThreadFunction,0,0,NULL),THREAD_PRIORITY_NORMAL);
return TRUE;
}
答案 0 :(得分:4)
除了呼叫GetPixel()
50毫秒之外,你什么都不做。那是50毫秒的滞后。你有什么期望?
删除Sleep
通话只会意味着您更频繁地延迟,并且每次仍然持续50毫秒。这也是预期的。
答案 1 :(得分:1)
有些观点:
1)你的while循环很紧凑且占用大量CPU资源。如果您有支持它的CPU,请将__mm_pause内在函数放在那里(::YieldProcessor()
)或尝试::SwitchToThread()
2)GetPixel
非常慢IIRC,可能有更快的方法从HBITMAP