5

我制作了要注入游戏的 .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;
}
4

2 回答 2

4

You're doing nothing but call GetPixel() for 50 milliseconds. That's a 50 millisecond lag right there. What did you expect?

Removing the Sleep call just means you lag more often, and each time still for 50 milliseconds. That too is expected.

于 2012-12-03T15:44:25.103 回答
1

几点:

1)您的 while 循环很紧凑且占用大量 CPU。如果您有支持它的 CPU,请将 __mm_pause 内在函数放在那里(::YieldProcessor())或尝试::SwitchToThread()

2)GetPixel非常慢的 IIRC,可能有一种更快的方法可以从HBITMAP

于 2012-12-03T15:45:42.150 回答