该程序在开始时确实可以工作,但是在几次循环后就出错了
我在使用 ReadProcessMemory 时遇到问题。它在我的程序开始时工作并读取大字符串,但它会停止正确更新值。例如,它将保留先前的字符串并在程序的其余部分中保留该字符串,或者在我关闭程序之前,字符串中将完全没有任何内容。这在前两次有效后随机发生。基本地址包含游戏中通过悬停效果的项目的一串文本。然而,readprocessmemory 似乎在几次后停止工作,我仔细检查了该地址是否仍在通过作弊引擎更新正确的值,但它没有在程序中正确更新。我知道代码写得不好,我应该使用向量等......
问题发生在这里:
while(temp.size() < 150 ){
do{
// memset(&buffer[0], 0, sizeof(buffer));
ReadProcessMemory(hProcHandle, (LPCVOID)myaddr, &buffer, sizeof(buffer), NULL);
temp = std::string((char*)buffer);
}
while(temp == previous);
std:: cout << temp.size() << std::endl;
}
上面的代码以前不是循环,我尝试再次调用它,直到它有新值或不为空,但是一旦程序停止使用坏值,无论我调用它多少次,它都会停留在循环中,但同样作弊引擎中的地址正在同时更新,我已经仔细检查过。此循环中的主要问题是 readprocessmemory 继续具有与先前调用相同的值并保持这种状态直到关闭程序。在游戏运行的同时,地址也在游戏中更新。
#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <vector>
DWORD ariaBase = 0x400000 + 0x009B5A20;
std::string teatime[] = {" + 5 E"," + 6 Acc"," + 5 Acc"," + 6 Acc"," + 5 Acc"," + 7 Crit"," + 6 Damage"," + 5 Damage"," + 4 Damage"," + 3 Crit"};
unsigned char* buffer[800] = {0};
std::string temp = "";
std::string previous = "";
int myaddr = 0;
bool match[5];
DWORD aOffset[] = {0x724, 0x37C, 0x0, 0xAC, 0x50};
int count = 0;
std::vector<std::string> stats;
bool statsFound = false;
void WriteToMemory(HANDLE hProcHandle){
stats.clear();
temp = "";
while(temp.size() < 150 ){
do{
// memset(&buffer[0], 0, sizeof(buffer));
ReadProcessMemory(hProcHandle, (LPCVOID)myaddr, &buffer, sizeof(buffer), NULL);
temp = std::string((char*)buffer);
}
while(temp == previous);
std:: cout << temp.size() << std::endl;
}
previous = temp;
std::replace( temp.begin(), temp.end(),(char)'\\', '*');
stats = findStats(temp);
//for( std::vector<std::string>::const_iterator i = stats.begin(); i != stats.end(); ++i)std::cout << *i << ' ' << std::endl;
}
int main(){
...code...
...code...
...code...
...code...
while(statsFound == false){
round++;
checkItem();
Sleep(2000);
WriteToMemory(hProcHandle);
std::cout << round << std::endl;
for( std::vector<std::string>::const_iterator i = stats.begin(); i != stats.end(); ++i)std::cout << *i << ' ' << std::endl;
for(int i = 0; i < stats.size();i++){
for(int j = 0; j < 10;j++){
if(("Identified Attribute:" + teatime[j]) == stats[i])match[i] = true;
}
}
count = 0;
for(int i = 0; i < stats.size();i++){
if(match[i] != true)statsFound = false;
else count++;
if(count == stats.size())statsFound = true;
}
match[0] = false;
match[1] = false;
match[2] = false;
match[3] = false;
if(statsFound == false)MouseStart();
}
...code...
...code...
...code...
}