Code

//God Mode
 }else if(stricmp(lpcLine, "!god") == 0){
  bRet = false;
  if(ADDR_GODMODE[0] != 0x90){
  BYTE godmode[] = {0x90, 0x90};
  EnableHack((BYTE*)ADDR_GODMODE, godmode, 2);
  Echo("GodMode On");
 }
  else{
  BYTE godmode[] = {0x7B, 0x05};
  EnableHack((BYTE*)ADDR_GODMODE, godmode, 2);
  Echo("GodMode Off");
 }

Error

error C2109: subscript requires array or pointer type

Dani AI

Generated

Brief diagnosis and fix

The toggle logic is checking the address value instead of the byte stored at that address. As noted earlier by , the original compiler error came from using [] on something that wasn't a pointer; replacing that with a numeric literal (e.g. 0x00481692) fixed the compile error but introduced the logic bug: the address constant will never equal 0x90, so the "On" branch always runs. Read the byte at the target address and compare that byte instead of comparing the address itself.

Example patterns (do not copy forum code exactly):

/* in-process memory check */
BYTE current = *reinterpret_cast<BYTE*>(addr);
if (current != 0x90) {
    // apply patch (turn on)
} else {
    // restore original bytes (turn off)
}
/* cross-process memory check */
BYTE current = 0;
SIZE_T got = 0;
ReadProcessMemory(hProcess, (LPCVOID)addr, &current, 1, &got);
if (got == 1 && current != 0x90) {
    // apply patch via WriteProcessMemory / VirtualProtectEx
}

Practical tips: verify EnableHack actually writes the expected bytes and returns success; consider comparing both bytes you write with memcmp rather than a single opcode byte; use VirtualProtect(Ex) when changing code pages; prefer module+offset or signature scanning over hard-coded addresses because offsets change with patches; or keep an explicit boolean state for the toggle to avoid relying on in-memory heuristics. was right to ask for the full function earlier — if problems persist, post the function and any return codes from your memory-write helper.

Recommended Answers

All 5 Replies

The compilers I use will take you to the potential culprit line. If yours does too then telling us which line is pointed to gives us, and you too, an idea of where to start. Since:

BYTE godmode[] = {0x90, 0x90};

and this:

BYTE godmode[] = {0x7B, 0x05};

are both local array declarations, then I must assume from the code posted that the culprit may be this:


ADDR_GODMODE[0]

If ADDR_GODMODE isn't an array or a pointer or a vector or a map then the use of subscript operator [] is illegal unless you have overloaded the [] operator for whatever type ADDR_GODMODE is. However, since ADDR_GODMODE isn't declared in the code snippet posted I have no idea what type it is.

ADDR_GODMODE = the address im changing with

BYTE godmode[] = {0x90, 0x90};

and this:

BYTE godmode[] = {0x7B, 0x05};

Please post entire function and complete error message including line number -- we still have no clude how ADDR_GODMODE is declared or what line number that error occurred.

NVM I Fixed It ;)

apart from when i activate it it works but when i type !god again to de-activate it, it just says GodMode On.... and dosent de-activate it

//God Mode
}else if(stricmp(lpcLine, "!god") == 0){
bRet = false;
if(0x00481692 != 0x90){
BYTE godmode[] = {0x90, 0x90};
EnableHack((BYTE*)ADDR_GODMODE, godmode, 2);
Echo("GodMode On");
}
else{
BYTE godmode[] = {0x7B, 0x05};
EnableHack((BYTE*)ADDR_GODMODE, godmode, 2);
Echo("GodMode Off");
}

stricmp() will return zero if the two strings are equal from a case insensitive point of view. Therefore if you compare the input line, which I presume is lpcLine with !god using stricmp() and the result equals zero then lpcLine is !god and you would presumably output GodModeOff rather than GodModeOn using the Echo() statement, though I have no idea what Echo() really does.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.