Its obvious why it crash, it reach invalid pointer because aIndex goes over the limit of AddTab. If you define AddTab likeyou will not be able to access AddTab[256] because its not allocated in declaration. By the way I have no idea why would you delete the line you marked. And this line
Code:
AddTab = (AddObj*)malloc(OBJ_MAX * sizeof(AddObj));
you need to free the memory used for allocating AddTab once you're done with it else there will be what's called memory leak. A global preallocated instance of AddTab would be better.
.h
Code:
struct PMSG_ACTION
{
PBMSG_HEAD h;
BYTE Dir; // 3
BYTE ActionNumber; // 4
BYTE iTargetIndexH; // 5
BYTE iTargetIndexL; // 6
};
struct AddObj
{
int AnimTick;
int AnimCnt;
};
#define off_LogAddTD 0x0635992C
#define off_objtable 0x0660F078
#define off_CGActionRecv 0x0044A760
#define OBJ_MAX 4000
void CGActionRecv(PMSG_ACTION * lpMsg, int aIndex);
.cpp
Code:
AddObj AddTab[OBJ_MAX];
void CGActionRecv(PMSG_ACTION * lpMsg, int aIndex)
{
DWORD dwObj = off_objtable;
if (aIndex > OBJ_MAX) return;
if (AddTab[aIndex].AnimTick == 0)
{
AddTab[aIndex].AnimTick = GetTickCount();
AddTab[aIndex].AnimCnt = 0;
CloseClient(aIndex);
}
else
{
int tick = GetTickCount();
if (tick - AddTab[aIndex].AnimTick >= 1000)
{
AddTab[aIndex].AnimTick = tick;
AddTab[aIndex].AnimCnt = 0;
CloseClient(aIndex);
}
else
{
AddTab[aIndex].AnimCnt += 1;
if (AddTab[aIndex].AnimCnt >= 10)
{
Log.Add("[ANTI-HACK][MoveProto][%s][%s] Too many actions (DC Hack).", (LPVOID)(dwObj + 0x68), (LPVOID)(dwObj + 0x73));
AddTab[aIndex].AnimTick = 0;
AddTab[aIndex].AnimCnt = 0;
CloseClient(aIndex);
return;
}
}
}
CGActionRecvFunc(lpMsg, aIndex); // pCGActionRecvFunc CGActionRecvFunc = (pCGActionRecvFunc) 0x044A760;
}
Somewhere before starting using the AddTab clean it like
Code:
memset(&AddTab, 0x00, sizeof(AddTab));