• You've discovered RedGuides 📕 an EverQuest multi-boxing community 🛡️🧙🗡️. We want you to play several EQ characters at once, come join us and say hello! 👋
  • IS THIS SITE UGLY? Change the look. To dismiss this notice, click the X --->

DoCrack question (1 Viewer)

Rellik

New member
Joined
Feb 13, 2005
RedCents
40¢
I tried opening the link in the acrobat guide for EQ Underground but it said my security settings would not allow that file type to be opened. I fiddled with it for a while but could never get it to work.

Am I missing something with Acrobat?

I also searched on these forums and found a post requesting a clean copy of mq2docrack. A poster replied with the cpp and xml changes. I copied the cpp and made the xml changes and added the xml windows, then tried to compile the cpp but got an error-
MQ2Docrack.cpp(55) : fatal error c1083: Cannot open include file: 'ByteHandler.h' : No such file or directory.
I created a blank bytehandler.h and then had a problem with it wanting mq2docrack.h
I found mq2docrack.h on the f-h forums and included it, and still could not get it to compile correctly.
I've searched here and the f-h forums but can't seem to find my problem.

I'm sure I'm just doing something stupid, but any help would be appreciated.
 
no, you weren't doing anything stupid, if i missed any more files, please reply here again
bytehandler.h
Rich (BB code):
struct Bytes { 
   vector<BYTE> Normal; 
   vector<BYTE> Crack; 
   DWORD EQADDR; 
}; 

list<Bytes> ByteList; 


class CByteHandler 
{ 
   CHAR szErrorBuffer[MAX_STRING]; 
   CHAR szUnSpacedNormal[MAX_STRING]; 
   CHAR szUnSpacedCrack[MAX_STRING]; 
   CHAR szSpacedNormal[MAX_STRING]; 
   CHAR szSpacedCrack[MAX_STRING]; 
   PCHAR space(PCHAR szSrc, PCHAR szDest); 
   PCHAR unSpace(PCHAR szSrc, PCHAR szDest); 
   void ByteError(PCHAR szFormat, ...); 
   void szStringToVBYTE(PCHAR szString, bool normal); 
   bool bWriteErrors; 
public: 

   Bytes ByteStruct; 
   int NormalByte, CrackByte; 
   bool ProceedWithCrack(bool WriteErrors); 
   bool bProceedWithCrack; 
   CByteHandler(PCHAR szNormal, PCHAR szCrack); 
   CByteHandler(const CByteHandler &ob); 
   ~CByteHandler(); 
}; 



void CByteHandler::ByteError(PCHAR szFormat,...) 
{ 
   bProceedWithCrack = false; 
    va_list vaList; 
    va_start( vaList, szFormat ); 
    vsprintf(szErrorBuffer,szFormat, vaList); 
   if (bWriteErrors) 
      WriteChatColor(szErrorBuffer,CONCOLOR_RED); 
   //FatalError 
   DebugSpewAlways("MQ2DoCrack::ByteError(%s)",szErrorBuffer); 
    

} 

bool CByteHandler::ProceedWithCrack(bool WriteErrors) 
{ 
   bWriteErrors = WriteErrors; 
   if ((strlen(szUnSpacedCrack)%2)) 
      ByteError("Crack Error: Crack information %s is not of an evenly divisable length",szSpacedCrack); 

   if ((strlen(szUnSpacedNormal)%2)) 
      ByteError("Crack Error: Normal information %s is not of an evenly divisable length",szSpacedNormal); 

   if (!strcmp(szUnSpacedNormal,szUnSpacedCrack)) 
      ByteError("Crack Error: Crack and Normal information (%s) are the same",szUnSpacedCrack); 

    
   for (int x=0;x<strlen(szUnSpacedNormal);x++) 
   { 
      if (!isxdigit(szUnSpacedNormal[x])) 
         ByteError("Crack Error: Normal contains non hexadecimal numbers characters in it (%c)",szUnSpacedNormal[x]); 
   } 

   for (x=0;x<strlen(szUnSpacedCrack);x++) 
   { 
      if (!isxdigit(szUnSpacedCrack[x])) 
         ByteError("Crack Error: Crack contains non hexadecimal numbers characters in it (%c)",szUnSpacedCrack[x]); 
   } 

   if (NormalByte != CrackByte) 
      ByteError("Crack Error: Normal/Crack size mismatch: %d/%d bytes",NormalByte,CrackByte); 
   if (!bProceedWithCrack) 
   { 
         ByteError("Normal %s Crack %s",szSpacedNormal,szSpacedCrack); 
         return 0; 
   } 
   else 
      return 1; 
} 

CByteHandler::CByteHandler(PCHAR szNormal, PCHAR szCrack) 
{ 
   bWriteErrors = false;    
   bProceedWithCrack = true; 
   unSpace(szNormal,szUnSpacedNormal); 
   unSpace(szCrack,szUnSpacedCrack); 
   space(szNormal,szSpacedNormal); 
   space(szCrack,szSpacedCrack); 

   NormalByte = ((strlen(szUnSpacedNormal)/2)+(strlen(szUnSpacedNormal)%2)); 
   CrackByte = ((strlen(szUnSpacedCrack)/2)+(strlen(szUnSpacedCrack)%2)); 

   szStringToVBYTE(szUnSpacedNormal,1); 
   szStringToVBYTE(szUnSpacedCrack,0); 

   for (int iByte = 0; iByte+1 < CrackByte; iByte++) 
      if (ByteStruct.Crack[iByte] == ByteStruct.Normal[iByte]) 
         DebugSpewAlways("MQ2DoCrack::CByteHandler::CByteHandler(Crack and Normal at array location %d are the same (0x%x))",(iByte+1),ByteStruct.Normal[iByte]); 
} 

void CByteHandler::szStringToVBYTE(PCHAR szString, bool normal) 
{ 
   char szByte[MAX_STRING] = {0}; 
   DWORD dwPos = 0, dwEnd = strlen(szString); 
    
   while (dwPos < dwEnd) { 
      strcpy(szByte,&szString[dwPos]); 
      szByte[2] = '\0'; 
      if (normal) 
         ByteStruct.Normal.push_back((BYTE)strtoul(szByte, NULL, 16)); 
      else 
         ByteStruct.Crack.push_back((BYTE)strtoul(szByte, NULL, 16)); 
      dwPos = dwPos+2; 
   } 

   return; 
} 

CByteHandler::~CByteHandler() 
{ 
   ByteStruct.Normal.clear(); 
   ByteStruct.Crack.clear(); 
} 

CByteHandler::CByteHandler(const CByteHandler &ob) 
{ 
   ByteStruct.Crack = ob.ByteStruct.Crack; 
   ByteStruct.Normal = ob.ByteStruct.Normal; 
} 

PCHAR CByteHandler::space(PCHAR szSrc, PCHAR szDest) 
{ 
   char *pBuffer=(char*)malloc(MAX_STRING); 
   unSpace(szSrc,pBuffer); 
   char spaceBuffer[MAX_STRING] = {0}; 
   ZeroMemory(szDest,MAX_STRING); 
   for (int h = 0; h<=strlen(szSrc); h=h+2) 
   { 
      ZeroMemory(spaceBuffer,MAX_STRING); 
      for (int o=0;o<2;o++) 
         spaceBuffer[o] = pBuffer[h+o]; 
      if (h>=strlen(szSrc)) break; 
      strcat(spaceBuffer," "); 
      strcat(szDest,spaceBuffer); 
   } 
   free(pBuffer); 
   return szDest; 
} 


PCHAR CByteHandler::unSpace(PCHAR szSrc, PCHAR szDest) 
{ 
    
   char *pBuffer; 
   char spaceBuffer[MAX_STRING] = {0}; 
   ZeroMemory(szDest,MAX_STRING); 
   pBuffer = szSrc; 
   for (int h = 0; h<=strlen(szSrc); h++) 
   { 
      ZeroMemory(spaceBuffer,MAX_STRING); 
      if (szSrc[h] != ' ') //need to put an null term check here? 
      { 
         spaceBuffer[0]=szSrc[h]; 
         strcat(szDest,spaceBuffer); 
      } 
   } 
   return szDest; 
}
 
Last edited:
mq2docrackwnd.h
Rich (BB code):
class CDoCrackWnd; 
void CreateDoCrackWindow(); 
void DestroyDoCrackWindow(); 
void ReadWindowINI(PCSIDLWND pWindow); 
void WriteWindowINI(PCSIDLWND pWindow); 
void DoCrackWndCommand(PSPAWNINFO pChar, PCHAR szLine); 
void GetCrackStat(PCHAR szCrackName); 

// CDoCrackWnd window class 
class CDoCrackWnd : public CCustomWnd 
{ 
public: 
   CListWnd *CrackList; 
   CButtonWnd *LoadButton; 

   CDoCrackWnd():CCustomWnd("DoCrackWnd") 
   { 
      CrackList = (CListWnd*)GetChildItem("DC_CrackList"); 
      LoadButton = (CButtonWnd*)GetChildItem("DC_LoadButton"); 
      SetWndNotification(CDoCrackWnd); 
      LoadList(); 
   } 

   ~CDoCrackWnd() 
   { 
   } 

   int WndNotification(CXWnd *pWnd, unsigned int Message, void *unknown) 
   { 
      CHAR szTemp[MAX_STRING]={0}, szBuffer[MAX_STRING]={0}; 

      if (pWnd==(CXWnd*)LoadButton) { 
         if (Message==XWM_LCLICK) { 
            //WriteChatColor("CDoCrackWnd::Button01 LCLICK", USERCOLOR_DEFAULT); 
            this->LoadList(); 
         } else { 
            //DebugSpew("Button01 message %Xh / %d",Message,Message); 
         } 
      } 
      if (pWnd==(CXWnd*)CrackList) { 
         if (Message==XWM_LCLICK) { 
         sprintf(szTemp,"/docrack %s on", GetListItem(szBuffer, (DWORD)(CrackList->GetCurSel()) ) ); 
            //DebugSpewAlways("CDoCrackWnd::CrackList LCLICK Command '%s'", szTemp); 
            DoCommand(NULL, szTemp); 
         } 
         if (Message==XWM_RCLICK) { 
         sprintf(szTemp,"/docrack %s off", GetListItem(szBuffer, (DWORD)(CrackList->GetCurSel()) ) ); 
            //DebugSpewAlways("CDoCrackWnd::CrackList LCLICK Command '%s'", szTemp); 
            DoCommand(NULL, szTemp); 
            LoadList(); 

         } 
         if (Message==XWM_LMOUSEUP) { 
            LoadList();  //refresh status colors after crack select 
         } 
      } 
      return CSidlScreenWnd::WndNotification(pWnd,Message,unknown); 
   }; 

   void LoadList() 
   { 
      char szBuffer[MAX_STRING], szSection[MAX_STRING], szCrackName[MAX_STRING]; 
      int i, prev=0, curListIndex=0; 
      DWORD crack_color; 

      CrackList->DeleteAll(); 

      //DebugSpewAlways("CDoCrackWnd::LoadList(): Get sections list"); 
      GetPrivateProfileString(NULL,NULL,NULL,szBuffer,MAX_STRING,INIFileName); 

      for (i=0; ((szBuffer != 0) || (szBuffer[i+1] != 0)); i++) { 
         //DebugSpewAlways("LoadList(): cycledsectionbuffer byte %d", i); 

         szSection[i-prev] = szBuffer; 
         if ( szBuffer==0 ) { 
               //DebugSpewAlways("LoadList(): found section %s", szSection); 
               strcpy(szCrackName, szSection); 
               crack_color = GetCrackStatusColor(szCrackName); 

               //DebugSpewAlways("LoadList(): CrackList->AddString(text='%s',crack_color=0x%X)", szCrackName, crack_color); 
               CrackList->AddString(CXStr(szCrackName), crack_color, 0, 0); 

               curListIndex++; 
               prev=i+1; 
            } 
      } 
   } 

   PCHAR GetListItem(PCHAR szFoundName, DWORD dwIndex) 
   { 
      char szBuffer[MAX_STRING], szSection[MAX_STRING]; 
      sprintf(szFoundName, "GetListItem_ERROR"); 
      int i, prev=0; 
      DWORD curListIndex=0; 

      //DebugSpewAlways("CDoCrackWnd::GetListItem(%d): Get sections list", dwIndex); 
      GetPrivateProfileString(NULL,NULL,NULL,szBuffer,MAX_STRING,INIFileName); 

      for (i=0; ((szBuffer != 0) || (szBuffer[i+1] != 0)); i++) { 
         //DebugSpewAlways("GetListItem(): cycledsectionbuffer byte %d", i); 

         szSection[i-prev] = szBuffer; 
         if ( szBuffer==0 ) { 
               if ( curListIndex == dwIndex ) { 
                  strcpy(szFoundName, szSection); 
                  break; 
               } 
               curListIndex++; 
               prev=i+1; 
            } 
      } 
      //DebugSpewAlways("GetListItem():Return %s", szFoundName); 
      return szFoundName; 
   } 
   DWORD GetCrackStatusColor(PCHAR szCrackName) 
   { 
      CHAR szAddr[MAX_STRING] = {0}; 
      CHAR szIniKey[MAX_STRING] = {0}; 
      CHAR szCrack[MAX_STRING] = {0}; 
      CHAR szNormal[MAX_STRING] = {0}; 
      CHAR szBuffer[MAX_STRING] = {0}; 
      CHAR szTextBuffer[MAX_STRING] = {0}; 
      DWORD dwAddr; 
      int iChange = 0, iByte, iCrackSize; 
      BYTE byCrack[20]; 
      BYTE byNormal[20]; 
      DWORD crack_color; 

      while(1) 
      { 
         sprintf(szAddr,"Address%d",iChange); 
         GetPrivateProfileString(szCrackName,szAddr,"NULL",szBuffer,MAX_STRING,INIFileName); 

         if (!strcmp(szBuffer,"NULL")) 
         { 
            if ( iChange==0 ) 
            { 
               sprintf(szTextBuffer,"GetCrackStatusColor(): no match for '%s'", szCrackName ); 
               crack_color = ConColorToARGB(CONCOLOR_RED);  //data error 
            } 
            break; 
         } 

         //converts string address to hex 
         dwAddr = strtoul(szBuffer,NULL,16); 

         sprintf(szIniKey,"Crack%d",iChange); 
         GetPrivateProfileString(szCrackName,szIniKey,"NULL",szCrack,MAX_STRING,INIFileName); 
         if (!strcmp(szCrack,"NULL")) 
         { 
            DebugSpewAlways("[%s] Crack error, no associated crack value set with address: 0x%x", szCrackName, dwAddr); 
            crack_color = ConColorToARGB(CONCOLOR_RED);  //data error 
            break; 
         } 
         sprintf(szIniKey,"Normal%d",iChange); 
         GetPrivateProfileString(szCrackName,szIniKey,"NULL",szNormal,MAX_STRING,INIFileName); 
         if (!strcmp(szNormal,"NULL")) 
         { 
            DebugSpewAlways(szTextBuffer,"[%s] Crack error, no associated normal value set with address: 0x%x", szCrackName, dwAddr); 
            crack_color = ConColorToARGB(CONCOLOR_RED);  //data error 
            break; 
         } 

         // convert crack string into actual bytes 
         char *pTempPos, *pCurPos = szCrack; 
         char *pEndCrack = szCrack + strlen(szCrack); 
         iByte = 0; 
         while (pCurPos < pEndCrack) 
         { 
            byCrack[iByte] = (unsigned char)strtol(pCurPos, &pTempPos, 16); 
            iByte++; 
            if (iByte > 20 ) 
            { 
               DebugSpewAlways(szTextBuffer, "[%s] Crack Error: Crack too big.", szCrackName); 
               crack_color = ConColorToARGB(CONCOLOR_RED);  //data error 
            } 
            pCurPos = pTempPos+1; 
         } 
         iCrackSize = iByte; 

         // convert normal string into actual bytes 
         pCurPos = szNormal; 
         pEndCrack = szNormal + strlen(szNormal); 
         iByte = 0; 
         while (pCurPos < pEndCrack) 
         { 
            byNormal[iByte] = (unsigned char)strtol(pCurPos, &pTempPos, 16); 
            iByte++; 
            pCurPos = pTempPos+1; 
         } 

         if (iByte != iCrackSize) 
         { 
            DebugSpewAlways("[%s] Crack error, crack mismatch crack size: %u  normal size: %u", szCrackName, iCrackSize, iByte); 
            crack_color = ConColorToARGB(CONCOLOR_RED);  //data error 
         } 

         // look for the first byte that is different in the crack from the normal 
         // should be the 1st byte for gods sake :) 
         for (iByte = 0; iByte < iCrackSize; iByte++) 
         { 
            if (byCrack[iByte] != byNormal[iByte]) 
            break; 
         } 
         if (iByte == iCrackSize) 
         { 
            DebugSpewAlways("[%s] Crack Error: no difference between the crack and normal bytes.", szCrackName); 
            crack_color = ConColorToARGB(CONCOLOR_RED);  //data error 
         } 

         if (*(((LPBYTE)dwAddr)+iByte) == byCrack[iByte]) 
         { 
            crack_color = ConColorToARGB(CONCOLOR_GREEN);  //on 
         } 
         else if (*(((LPBYTE)dwAddr)+iByte) == byNormal[iByte]) 
         { 
            crack_color = ConColorToARGB(CONCOLOR_BLUE);  //off 
         } 
         else 
         { 
            //problem 
            DebugSpewAlways("[%s] Crack warning! No match at addr: 0x%X  [%X/%X]", szCrackName, dwAddr, byNormal[iByte], byCrack[iByte]); 
            crack_color = ConColorToARGB(CONCOLOR_YELLOW);  //mismatch/warning 
         } 
         iChange++; 
      } 

      return crack_color; 
   } 
}; 
CDoCrackWnd *MyWnd = 0; 


// API are here just to show you where the stuff goes to tie it all together 


PLUGIN_API VOID OnZoned(VOID) 
{ 
   //if you use map enabling in this callback... do it before you call LoadList! 
   if ( gGameState==GAMESTATE_INGAME && MyWnd ) { 
      MyWnd->LoadList();    //can't load UI element lists if SetGameState hasn't loaded them yet 
   } 
} 

// *************************************** 
// DoCrackWnd UI stuff 
// *************************************** 

PLUGIN_API VOID OnCleanUI(VOID) 
{ 
   DebugSpewAlways("MQ2DoCrack::OnCleanUI()"); 
   DestroyDoCrackWindow(); 
} 

PLUGIN_API VOID OnReloadUI(VOID) 
{ 
   DebugSpewAlways("MQ2DoCrack::OnReloadUI()"); 
   CreateDoCrackWindow(); 
} 


CHAR szSettingINISection[MAX_STRING] = {0}; 
void ReadWindowINI(PCSIDLWND pWindow) 
{ 
   //DebugSpewAlways("MQ2DoCrack::ReadWindowINI()"); 
   CHAR Buffer[MAX_STRING] = {0}; 
   sprintf(szSettingINISection,"Settings",((PCHARINFO)pCharData)->Server,((PCHARINFO)pCharData)->Name); 
   pWindow->Location.top      = GetPrivateProfileInt(szSettingINISection,"Top",      401,INIFileName); 
   pWindow->Location.bottom   = GetPrivateProfileInt(szSettingINISection,"Bottom",   723,INIFileName); 
   pWindow->Location.left      = GetPrivateProfileInt(szSettingINISection,"Left",      290,INIFileName); 
   pWindow->Location.right    = GetPrivateProfileInt(szSettingINISection,"Right",      437,INIFileName); 
   pWindow->Locked             = GetPrivateProfileInt(szSettingINISection,"Locked",         0,INIFileName); 
   pWindow->Fades             = GetPrivateProfileInt(szSettingINISection,"Fades",         1,INIFileName); 
   pWindow->TimeMouseOver       = GetPrivateProfileInt(szSettingINISection,"Delay",         2000,INIFileName); 
   pWindow->FadeDuration       = GetPrivateProfileInt(szSettingINISection,"Duration",      500,INIFileName); 
   pWindow->Alpha            = GetPrivateProfileInt(szSettingINISection,"Alpha",         255,INIFileName); 
   pWindow->FadeToAlpha      = GetPrivateProfileInt(szSettingINISection,"FadeToAlpha",   255,INIFileName); 
   pWindow->BGType            = GetPrivateProfileInt(szSettingINISection,"BGType",         1,INIFileName); 
   pWindow->BGColor.R         = GetPrivateProfileInt(szSettingINISection,"BGTint.red",      255,INIFileName); 
   pWindow->BGColor.G         = GetPrivateProfileInt(szSettingINISection,"BGTint.green",   255,INIFileName); 
   pWindow->BGColor.B         = GetPrivateProfileInt(szSettingINISection,"BGTint.blue",   255,INIFileName); 

   GetPrivateProfileString(szSettingINISection,"WindowTitle","MQ2DoCrack",Buffer,MAX_STRING,INIFileName); 
   SetCXStr(&pWindow->WindowText,Buffer); 
} 

void WriteWindowINI(PCSIDLWND pWindow) 
{ 
   //DebugSpewAlways("MQ2DoCrack::WriteWindowINI()"); 
   CHAR szTemp[MAX_STRING] = {0}; 
   if (pWindow->Minimized) 
   { 
      WritePrivateProfileString(szSettingINISection,"Top",      itoa(pWindow->OldLocation.top,      szTemp,10),INIFileName); 
      WritePrivateProfileString(szSettingINISection,"Bottom",   itoa(pWindow->OldLocation.bottom,   szTemp,10),INIFileName); 
      WritePrivateProfileString(szSettingINISection,"Left",   itoa(pWindow->OldLocation.left,      szTemp,10),INIFileName); 
      WritePrivateProfileString(szSettingINISection,"Right",   itoa(pWindow->OldLocation.right,   szTemp,10),INIFileName); 
   } 
   else 
   { 
      WritePrivateProfileString(szSettingINISection,"Top",      itoa(pWindow->Location.top,         szTemp,10),INIFileName); 
      WritePrivateProfileString(szSettingINISection,"Bottom",   itoa(pWindow->Location.bottom,      szTemp,10),INIFileName); 
      WritePrivateProfileString(szSettingINISection,"Left",   itoa(pWindow->Location.left,      szTemp,10),INIFileName); 
      WritePrivateProfileString(szSettingINISection,"Right",   itoa(pWindow->Location.right,      szTemp,10),INIFileName); 
   } 
   WritePrivateProfileString(szSettingINISection,"Locked",      itoa(pWindow->Locked,         szTemp,10),INIFileName); 

   GetCXStr(pWindow->WindowText,szTemp); 
   WritePrivateProfileString(szSettingINISection,"WindowTitle",                              szTemp,INIFileName); 

   WritePrivateProfileString(szSettingINISection,"Fades",      itoa(pWindow->Fades,            szTemp,10),INIFileName); 
   WritePrivateProfileString(szSettingINISection,"Delay",      itoa(pWindow->MouseOver,         szTemp,10),INIFileName); 
   WritePrivateProfileString(szSettingINISection,"Duration",   itoa(pWindow->FadeDuration,         szTemp,10),INIFileName); 
   WritePrivateProfileString(szSettingINISection,"Alpha",      itoa(pWindow->Alpha,            szTemp,10),INIFileName); 
   WritePrivateProfileString(szSettingINISection,"FadeToAlpha",   itoa(pWindow->FadeToAlpha,         szTemp,10),INIFileName); 
   WritePrivateProfileString(szSettingINISection,"BGType",      itoa(pWindow->BGType,            szTemp,10),INIFileName); 
   WritePrivateProfileString(szSettingINISection,"BGTint.red",   itoa(pWindow->BGColor.R,         szTemp,10),INIFileName); 
   WritePrivateProfileString(szSettingINISection,"BGTint.green",   itoa(pWindow->BGColor.G,      szTemp,10),INIFileName); 
   WritePrivateProfileString(szSettingINISection,"BGTint.blue",   itoa(pWindow->BGColor.B,         szTemp,10),INIFileName); 
} 

void CreateDoCrackWindow() 
{ 
   //DebugSpewAlways("MQ2DoCrack::CreateDoCrackWindow()"); 
   if (MyWnd)  return; 

   if (pSidlMgr->FindScreenPieceTemplate("DoCrackWnd")) { 
      MyWnd = new CDoCrackWnd(); 
      ReadWindowINI((PCSIDLWND)MyWnd); 
      WriteWindowINI((PCSIDLWND)MyWnd); 
   } 
} 

void DestroyDoCrackWindow() 
{ 
   //DebugSpewAlways("MQ2DoCrack::DestroyDoCrackWindow()"); 
   if (MyWnd) 
   { 
      WriteWindowINI((PCSIDLWND)MyWnd); 
      delete MyWnd; 
      MyWnd=0; 
   } 
} 

// *************************************************************************** 
// Function:      DoCrackWndCommand 
// Description:   How we hide/show our docrack window 
// *************************************************************************** 
VOID DoCrackWndCommand(PSPAWNINFO pChar, PCHAR szLine) 
{ 
   if (!MyWnd) { 
      WriteChatColor("/docrackwnd: window init problem",USERCOLOR_DEFAULT); 
      return; 
   } 
    
   if (szLine[0]==0) { 
      WriteChatColor("/docrackwnd: show|hide|load",USERCOLOR_DEFAULT); 
      ((CXWnd*)MyWnd)->Show(1,1); 
      return; 
   } 

   if ( strstr(szLine, "off") || strstr(szLine, "hide") ) { 
      ((CXWnd*)MyWnd)->Show(0,0); 
   } else if ( strstr(szLine, "load") ) { 
      WriteChatColor("/docrackwnd: Reload Cracklist Display",USERCOLOR_DEFAULT); 
      MyWnd->LoadList(); 
      ((CXWnd*)MyWnd)->Show(1,1); 
   } else { 
      ((CXWnd*)MyWnd)->Show(1,1); 
   } 
}

mq2docrack.h
Rich (BB code):
BOOL bInitialized = false; 
void DoCrackHandler(PSPAWNINFO pChar, PCHAR szLine); 
void ShowMemHandler(PSPAWNINFO pChar, PCHAR szLine); 
void DoOffsetHandler(PSPAWNINFO pChar, PCHAR szLine); 

class CDoCrack 
{ 
   typedef char dateString[MAX_STRING]; 


   CHAR szAddr[MAX_STRING]; 
   CHAR szIniKey[MAX_STRING]; 
   CHAR szCrack[MAX_STRING]; 
   CHAR szNormal[MAX_STRING]; 
   CHAR szBuffer[MAX_STRING]; 
   CHAR szTextBuffer[MAX_STRING]; 
   CHAR szAddresses[MAX_STRING]; 
   CHAR szCrackName[MAX_STRING]; 
   CHAR szDescription[MAX_STRING]; 
   CHAR szVersion[MAX_STRING]; 

   DWORD dwAddr; 

   DWORD GetCrackStatus(PCHAR szCrackName); //true if cracked, false if normal or error 
   BOOL DateCheck(PCHAR szApp); 
   VOID Offset(DWORD Address, vector<BYTE> NewData, BOOL Reverse=1); 
   //void LoadOffsets(PCHAR szCrackName); 
   //void WriteOffsets(void); 
public: 
   VOID InitializeCracks(VOID); 
   VOID DoOffset        (PCHAR szLine); 
   VOID DoCrack        (PCHAR szLine); 
   VOID ShowMemory        (PCHAR szLine); 
} DoCrackClass; 


VOID CDoCrack::DoCrack(PCHAR szLine) 
{      
   int iChange = 0, i = 0;//, end; 

   // Parse out the crack name from the command line. 
   GetArg(szCrackName,szLine,1); 

   // If no crack was specified then print the usage string. 
   if( szLine[0]==0 
      || (!strstr(szLine,"list") && !strstr(szLine,"status") 
      && !strstr(szLine,"on") && !strstr(szLine,"off"))) 
   { 
            SyntaxError("Syntax: /docrack <crackname> [on|off|status]"); 
         SyntaxError("Syntax: /docrack list"); 
      return; 
   } 

   // If they want a list of cracks then print it out. 
   // Otherwise preform the requested task. 
   if (!strcmp(szCrackName,"list")) {        
      // Load up the list of cracks available in it .ini file. 
      GetPrivateProfileString(NULL,NULL,NULL,szBuffer,MAX_STRING,INIFileName); 
      CHAR* szCracks = 0; 

      // Print out the crack names one by one. 
      WriteChatColor("Available cracks:",USERCOLOR_DEFAULT); 

      szCracks = szBuffer; 
      for (i=0; i==0 || (szBuffer[i-1]!=0 || szBuffer!=0) ; i++) { 

         if ( szBuffer==0 ) { 
          CHAR szTemp[MAX_STRING] = {0}; 
          sprintf(szTemp, "\t\t%s", szCracks); 
          if( int status = (GetCrackStatus(szCracks) == CRACKSTATUS_ON )){ 
             strcat(szTemp, " on"); 
             WriteChatColor(szTemp, CONCOLOR_GREEN); 
          } else if (status == CRACKSTATUS_OFF){ 
             strcat(szTemp, " off"); 
             WriteChatColor(szTemp, CONCOLOR_BLUE); 
          } else if (status == CRACKSTATUS_ERROR){ 
             strcat(szTemp, " error"); 
             WriteChatColor(szTemp, CONCOLOR_BLUE); 
          } 

            // Set the name pointer to the next position after the null character. 
            szCracks = &szBuffer[i+1]; 
         } 
      } 

      return; 
   } 

   GetPrivateProfileString(szCrackName,NULL,"NULL",szBuffer,MAX_STRING,INIFileName); 
   if (!strcmp(szBuffer,"NULL")) 
   { 
      sprintf(szTextBuffer,"No Ini key found for %s, aborting",szCrackName); 
      WriteChatColor(szTextBuffer,CONCOLOR_RED); 
      return; 
   } 
        
   // Make sure the entry in the .ini file is recent. 
   if (!DateCheck(szCrackName)){ 
      WriteChatColor("Date discrepency found, not changing memory"); 
      return; 
   } 
   // Loop through the crack and perform the required action. 
   while(1){ 
       
      sprintf(szAddr,"Address%d",iChange); 
      GetPrivateProfileString(szCrackName,szAddr,"NULL",szBuffer,MAX_STRING,INIFileName); 
       
      if (!strcmp(szBuffer,"NULL")) break; 

      //converts string address to hex 
      dwAddr = strtoul(szBuffer,NULL,16); 

      sprintf(szIniKey,"Crack%d",iChange); 
      GetPrivateProfileString(szCrackName,szIniKey,"NULL",szCrack,MAX_STRING,INIFileName); 
      if (!strcmp(szCrack,"NULL")) { 
         sprintf(szTextBuffer,"Crack error, no associated crack value set with address: 0x%x", dwAddr); 
         WriteChatColor(szTextBuffer ,USERCOLOR_DEFAULT); 
         break; 
      } 
      sprintf(szIniKey,"Normal%d",iChange); 
      GetPrivateProfileString(szCrackName,szIniKey,"NULL",szNormal,MAX_STRING,INIFileName); 
      if (!strcmp(szNormal,"NULL")) { 
         sprintf(szTextBuffer,"Crack error, no associated normal value set with address: 0x%x", dwAddr); 
         WriteChatColor(szTextBuffer ,USERCOLOR_DEFAULT); 
         break; 
      } 
      CByteHandler CBHDoCrack(szNormal,szCrack); 
      if (!CBHDoCrack.ProceedWithCrack(true)) 
      { 
         ByteList.clear(); 
         return; 
      } 

      CBHDoCrack.ByteStruct.EQADDR = dwAddr; 
      ByteList.push_back(CBHDoCrack.ByteStruct); 
      iChange++; 
   } 
    

//feed offsets to write function              
      list<Bytes>::iterator p = ByteList.begin(); 
      // Modify the memory depending on what we need to do. 
       
      if( strstr(szLine,"off") ){ 
         while (p!=ByteList.end()) 
         { 
             
            Offset(p->EQADDR, p->Normal, FALSE); 
            RemoveDetour(p->EQADDR); 
            p++; 
         } 
      } else if( strstr(szLine,"on") ){ 
         // Set the memory to the cracked state. 
         while (p!=ByteList.end()) 
         { 
            AddDetour(p->EQADDR); 
            Offset(p->EQADDR, p->Crack, FALSE); 
            p++; 
         } 
      } 
      ByteList.clear(); 
//end write start information print    

   // Print out what we've done. 
   if( !strstr(szLine, "silent") ) { 
      int GCS = GetCrackStatus(szCrackName); 
      if (GCS==CRACKSTATUS_ON) 
      { 
         GetPrivateProfileString(szCrackName,"Description","NULL",szDescription,MAX_STRING,INIFileName); 
         sprintf(szTextBuffer,"%s: on", szCrackName); 
         WriteChatColor(szTextBuffer, CONCOLOR_GREEN); 
         if (strcmp(szDescription,"NULL")) 
         { 
            sprintf(szTextBuffer,"[%s] %s",szCrackName,szDescription); 
            WriteChatColor(szTextBuffer); 
         } 
      } 
      else if (GCS==CRACKSTATUS_OFF) 
      { 
         sprintf(szTextBuffer,"%s: off", szCrackName); 
         WriteChatColor(szTextBuffer,CONCOLOR_BLUE); 
      } 
      else if (GCS==CRACKSTATUS_ERROR) 
      { 
         sprintf(szTextBuffer,"%s: error!", szCrackName); 
         WriteChatColor(szTextBuffer,CONCOLOR_RED); 
      }        
   } 
   return; 
} 



VOID CDoCrack::Offset(DWORD Address, vector<BYTE> VData, BOOL Reverse) 
{ 
   ZeroMemory(szTextBuffer,MAX_STRING); 
   DWORD i, j, Length = VData.size(); 
   BYTE *NewData = new BYTE [Length]; 
   for (DWORD a = 0;a<Length;a++) 
      NewData[a] = VData[a]; 
    
   DWORD oldperm=0, tmp; 
   if (Reverse && Length>1) 
   { 
      BYTE *szReverse = new BYTE [Length]; 
      for (i = 0, j=Length-1; i < Length; i++,j--) 
      { 
         szReverse=NewData[j]; 
      } 
      memcpy(NewData,szReverse,Length); 
      delete szReverse; 
   } 
   for (DWORD x=0;x<Length;x++) 
   { 
      sprintf(szBuffer,"%x ",NewData[x]); 
      strcat(szTextBuffer,szBuffer); 
   } 
   DebugSpewAlways("MQ2DoCrack::Offset(0x%x,%s)",Address,szTextBuffer); 
    
   FlushInstructionCache(GetCurrentProcess(),(LPCVOID)Address, Length); 
   VirtualProtectEx(GetCurrentProcess(), (LPVOID)Address, Length,PAGE_EXECUTE_READWRITE, &oldperm); 
   WriteProcessMemory( 
      GetCurrentProcess(), 
      (LPVOID)Address, 
      (LPVOID)NewData, 
      Length, 
      NULL); 
   VirtualProtectEx(GetCurrentProcess(), (LPVOID)Address, Length, oldperm, &tmp); 
    
   delete [] NewData; 
} 


VOID CDoCrack::DoOffset(PCHAR szLine) 
{ 
   if (!szLine[0]) 
   { 
      SyntaxError("Syntax: /dooffset <address> <1 byte of memory|...>"); 
      return; 
   } 
   vector<BYTE> crack; 

   GetArg(szBuffer,szLine,1); 
   DWORD dwAddr = strtoul(szBuffer,NULL,16); 
   if (!dwAddr) 
      return; 

   char *pLine; 
   pLine = &szLine[strlen(szBuffer)]; 
   char *p2, *ptr = pLine; 
   char *end = pLine + strlen(pLine); 

   sprintf(szBuffer,"Command was %X %s",dwAddr,pLine); 
   WriteChatColor(szBuffer,USERCOLOR_DEFAULT); 
    
   AddDetour(dwAddr); 

   while (ptr<end) { 
      crack.push_back((unsigned char)strtol(ptr, &p2, 16)); 
      ptr = p2+1; 
   } 
    
   Offset(dwAddr,crack,FALSE); 
   /*for (int j=0;j<crack.size();j++) 
   { 
      sprintf(szBuffer,"dwAddr: %x with an existing value of %x, cracking with value: %x",(dwAddr+j),*(((LPBYTE)dwAddr)+j),crack[j]); 
      WriteChatColor(szBuffer,USERCOLOR_DEFAULT); 
      Offset((dwAddr+j),crack,1,FALSE); 
   } */ 
} 



BOOL CDoCrack::DateCheck(PCHAR szApp) 
{ 
   dateString szClient[3]; 
   dateString szCrack[3]; 
    
   CHAR szCrackDate[MAX_STRING] = {0}; 

   int d=0; 
   PCHAR szMonth[] = { 
      "Jan",   //0 
      "Feb",   //1 
      "Mar",   //2 
      "Apr",   //3 
      "May",   //4 
      "Jun",   //5 
      "Jul",   //6 
      "Aug",   //7 
      "Sep",   //8 
      "Oct",   //9 
      "Nov",   //10 
      "Dec"    //11 
   }; 


   GetPrivateProfileString(szApp,"Version","NULL",szCrackDate,MAX_STRING,INIFileName); 
   if (!strcmp(szCrackDate,"NULL")) 
   { 
      DebugSpewAlways("MQ2DoCrack::DateCheck(No version key found, going ahead with crack)"); 
      return 1; 
   } 


   //allocate client date information 
   for (int i=0;i<=2;i++) 
   { 
      GetArg(szBuffer,__ExpectedVersionDate,(i+1)); 
      strcpy(szClient,szBuffer); 
   } 

   //turn client month in to numeric form 
   for (i=1;i<12;i++) 
   { 
      if (!strcmp(szClient[0],szMonth)) 
         d=i++; 
   } 
   if (d==0) return 0; 

   //allocate crack date information 
   for ( i=0;i<=2;i++) 
   { 
      GetArg(szBuffer,szCrackDate,(i+1),1,0,0,'.'); 
      strcpy(szCrack,szBuffer); 
   } 
    
   //compare dates 
   if (atoi(szClient[2])<=atoi(szCrack[0])) 
      if (d<=atoi(szCrack[1])) 
         if (atoi(szClient[1])<=atoi(szCrack[2])) 
            return 1; 
         else return 0; 
      else return 0; 
   else return 0; 
    
} 


VOID CDoCrack::ShowMemory(PCHAR szLine) 
{ 
   if (!szLine[0]) 
   { 
      SyntaxError("Syntax: /showmem <address> <bytes of memory to show>"); 
      return; 
   } 
   int i = 0; 
   GetArg(szAddr,szLine,1); 
   DWORD dwAddr = strtoul(szAddr,NULL,16); 
   if (!dwAddr) 
      return; 
   GetArg(szBuffer,szLine,2); 
    
   if (!(i = atoi(szBuffer))) 
      i=1; 
   for (int j = 0;i>j;j++) 
   { 
      sprintf(szBuffer,"%x ",*(((LPBYTE)dwAddr)+j)); 
      strcat(szTextBuffer,szBuffer); 
   } 
   sprintf(szBuffer,"Memory at %x:",dwAddr); 
   WriteChatColor(szBuffer); 
   WriteChatColor(szTextBuffer); 
   return; 
    

} 

DWORD CDoCrack::GetCrackStatus(PCHAR szCrackName) { 

   int iChange = 0; 
   bool bError = false; 

   while(1) 
   { 
      sprintf(szAddr,"Address%d",iChange); 
      GetPrivateProfileString(szCrackName,szAddr,"NULL",szBuffer,MAX_STRING,INIFileName); 

      if (!strcmp(szBuffer,"NULL")) { 
         if ( iChange==0 ) 
            DebugSpewAlways("MQ2Docrack::GetCrackStatus(No Address key found for %s)",szCrackName); 
         // Return error. 
         return CRACKSTATUS_ERROR; 
      } 
       
      //converts string address to hex 
      dwAddr = strtoul(szBuffer,NULL,16); 
       
      sprintf(szIniKey,"Crack%d",iChange); 
      GetPrivateProfileString(szCrackName,szIniKey,"NULL",szCrack,MAX_STRING,INIFileName); 
      if (!strcmp(szCrack,"NULL")) { 
         DebugSpewAlways("MQ2Docrack::GetCrackStatus([%s] Crack error, no associated crack value set with address: 0x%x)", szCrackName, dwAddr);     
         // Return null. 
         return CRACKSTATUS_ERROR; 
      } 
      sprintf(szIniKey,"Normal%d",iChange); 
      GetPrivateProfileString(szCrackName,szIniKey,"NULL",szNormal,MAX_STRING,INIFileName); 
      if (!strcmp(szNormal,"NULL")) { 
         DebugSpewAlways(szTextBuffer,"MQ2Docrack::GetCrackStatus([%s] Crack error, no associated normal value set with address: 0x%x)", szCrackName, dwAddr); 
         // Return null. 
         return CRACKSTATUS_ERROR; 
      } 
       
      CByteHandler GCS(szNormal, szCrack); 
      if (GCS.ProceedWithCrack(false)) 
         bError = false; 

      for (int iByte = 0;iByte<GCS.NormalByte;iByte++) 
      { 
         if (bError) 
            return CRACKSTATUS_ERROR; 
         else if (*(((LPBYTE)dwAddr)+iByte) == GCS.ByteStruct.Crack[iByte]) 
            return CRACKSTATUS_ON; 
         else if (*(((LPBYTE)dwAddr)+iByte) == GCS.ByteStruct.Normal[iByte]) 
            return CRACKSTATUS_OFF; 
         else 
         {   //problem 
            DebugSpewAlways("MQ2Docrack::GetCrackStatus([%s] Crack warning! No match at addr: 0x%X  [%X/%X])", szCrackName, dwAddr, GCS.ByteStruct.Normal[iByte], GCS.ByteStruct.Crack[iByte]); 
            return CRACKSTATUS_ERROR; 
         } 
      } 
      iChange++; 
   } 
   return 0; 
} 




void CDoCrack::InitializeCracks(void) 
{ 

   if (gGameState==GAMESTATE_INGAME) { 

      bInitialized = true; 

      char szDefaultSetting[MAX_STRING]; 
      char* szSection=0; 
      int i, prev=0, curListIndex=0; 

      // Load the list of cracks from the .ini file. 
      GetPrivateProfileString(NULL,NULL,NULL,szBuffer,MAX_STRING,INIFileName); 

      // Cycle through each of the cracks and set the default value. 
      sprintf(szIniKey,"DefaultSetting"); 
      szSection = szBuffer; 
      for (i=0; i==0 || (szBuffer[i-1]!=0 || szBuffer!=0) ; i++) { 
        
         // If we've reached the end of the section name then process it. 
         if ( szBuffer==0 ) { 

            // Look up the default setting for this entry. 
            GetPrivateProfileString(szSection,szIniKey,"NULL",szDefaultSetting,MAX_STRING,INIFileName);            

            if( strstr(szDefaultSetting, "on") ){ 
               sprintf(szTextBuffer, "%s on silent", szSection); 
               DoCrack(szTextBuffer); 
            } 

            if( strstr(szDefaultSetting, "off") ){ 
               sprintf(szTextBuffer, "%s off silent", szSection); 
               DoCrack(szTextBuffer); 
            } 

            szSection = &szBuffer[i+1]; 
         } 
      } 
   } 

   return; 
} 

 
DoCrack question

Users who are viewing this thread

Back
Top