【发布时间】:2014-11-29 15:19:10
【问题描述】:
我试图在游戏进程中读取一些地址,然后与一个整数进行比较。
我的代码如下:
BOOL SCMemoryCheat::CheckDKHack()
{
int *DkAddr1 = (int*)0x87016C + 0x11E4; // Pointer DK 1
memcpy(DKBytesValues1, DkAddr1, 16);
int *DkAddr2 = (int*)0x87016C + 0x1224; // Pointer DK 2
memcpy(DKBytesValues2, DkAddr2, 16);
if ( DKBytesValues1[0] == DKBytesValues1[1]
&& DKBytesValues1[1] == DKBytesValues1[2]
&& DKBytesValues1[2] == DKBytesValues1[3]
&& DKBytesValues1[3] == DKBytesValues1[4]
&& DKBytesValues1[4] == DKBytesValues1[5]
&& DKBytesValues1[0] == 0x00)
{
// DK Detected
return TRUE;
}
}
bool StartSCMemoryCheats()
{
SCMemoryCheat* SCMemC = new SCMemoryCheat;
while (TRUE)
{
int *ChannelIDAddr = (int*)0x8915AF;
int *p = (int*)255;
if (ChannelIDAddr == p)
{
if (SCMemC->CheckDKHack)
{
delete[] SCMemC;
break;
}
}
ExitProcess(0);
}
}
和班级:
class SCMemoryCheat
{
unsigned char *DKBytesValues1 = new unsigned char[16];
unsigned char *DKBytesValues2 = new unsigned char[16];
unsigned char *XFS = new unsigned char[4];
public:
SCMemoryCheat();
virtual ~SCMemoryCheat();
BOOL CheckDKHack();
};
bool StartSCMemoryCheats() 用线程调用,这样:
DWORD dwSMCThreadId = 0;
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartSCMemoryCheats,(LPVOID) NULL, 0, &dwSMCThreadId);
它可以编译,但不工作,并且进程在 +/- 30% 的 CPU 使用情况下被冻结。
我该如何进行这种比较?
编辑
修复了一些问题
但现在这个条件总是返回 TRUE,并且值为 255。
**volatile int *ChannelIDAddr = (int*)0x8915AF;
// Check world list
if (*ChannelIDAddr != 255)
{
// ALWAYS TRUE
}**
提前致谢。
【问题讨论】:
-
while循环只是比较指针,而不是间接通过它们。您还应该声明值volatile,因此编译器不会对其进行优化。 -
那么我怎样才能得到指针的值(1字节),然后和一个整数值比较呢?
-
给定一个指针
p,*p得到它指向的值。 -
您要与哪个整数进行比较?
int *p = (int *)255声明指向内存位置 255 的指针,而不是整数 255。
标签: c++ pointers integer compare