【发布时间】:2021-02-22 20:14:22
【问题描述】:
我正在尝试为一款不受欢迎的游戏作弊。每次游戏调用 WSASend 函数时,lpBuffers 变量中都会有 1 个一定长度的缓冲区。我需要这样做,以便在按住鼠标侧键的同时,将缓冲区写入某种数组。然后,当按钮被释放时,检查我的数组中是否有东西,如果有,则一个接一个地发送每个缓冲区。作弊的本质是在快速发送记录数据时,我的角色会突然从一个点移动到另一个点或非常快速地执行一些其他动作。我写了以下代码,但它不能正常工作。
std::vector<std::string> records;
WSABUF buffer;
/*
The WSASend function leads to __WSASend. The original WSASend function is in _WSASend.
*/
int WSAAPI __WSASend(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesSent, DWORD dwFlags, LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
if (GetAsyncKeyState(VK_XBUTTON1) < 0) // If the side mouse button is pressed when calling WSASend, write the buffer data to my array of strings
{
records.emplace_back(lpBuffers->buf);
/*
While the mouse button is held down, the game will think that the data was sent because * lpNumberOfBytesSent = lpBuffers-> len; This is necessary in order for the game to send new data.
*/
*lpNumberOfBytesSent = lpBuffers->len;
return 0;
}
/* I need to send data with a delay, but I cannot use the Sleep () function since WSASend and WSARecv are on the same thread. Since the game tries to send the same data if it just returns 0 (without setting * lpNumberOfBytesSent = lpBuffers-> len) I decided to take advantage of this. */
if (records.size() > 0)
{
buffer.buf = &records[0][0];
buffer.len = records[0].length();
_WSASend(s, &buffer, 1, 0, 0, 0, 0);
records.erase(records.begin());
/* No delay because I decided to check if it works at all. And as it turned out, it works, but very rarely. When the saved data was small - 50 to 50 that will go and everything will be ok, but when there is a lot, it always kicks from the server with a data read error. */
return 0; // I am returning 0 without setting * lpNumberOfBytesSent = lpBuffers-> len; so that the game calls the same function again with the same data to send next recorded buffer data
}
return _WSASend(s, lpBuffers, dwBufferCount, lpNumberOfBytesSent, dwFlags, lpOverlapped, lpCompletionRoutine); // When there is no data recorded
}
由于游戏双方都使用加密+计数器,因此以正确的顺序(先记录到最后)写入和发送数据非常重要。理论上,如果你写得正确并以正确的顺序发送它,然后让游戏继续发送它没有记录的数据,那么一切都会好起来的。但正如我所说,有时它适用于小数据,但不适用于大数据。我被服务器抛出读取错误。
【问题讨论】: