Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++ Errors] I am trying to write a trainer please help me.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Tue Sep 16, 2008 6:44 pm    Post subject: [C++ Errors] I am trying to write a trainer please help me. Reply with quote

I keep getting errors ... can someone help me? I am new to
C++. I know Delphi better but C++ seems popular also so
I'm trying it.

I can't tell but it could be my compiler...
and if you see any comments that are
wrong feel free to explain.

Code:
// --- Made by inoobzx of CEF ---

// --------------------------------------------------

#include <windows.h> // Commonly used functions.
#include <stdio.h> // ???. Note: Not sure if used...
#include <iostream> // Used in consoles.

// --------------------------------------------------

using namespace std;

// --------------------------------------------------

unsigned FindPatternProcess(char* szPattern, const char* szMask, unsigned min, unsigned max);
unsigned FindPattern(String szAOB, int Offset, bool Pointer);

// --------------------------------------------------

unsigned FindPatternProcess(char* szPattern, const char* szMask, unsigned min, unsigned max)
{
   char* bBuffer = 0;
   int iLength = (int)strlen( szMask );
   char* bPattern = new char[ iLength+1 ];
   for( int x = 0; x <= iLength; x++ ){
      bPattern[x] = szPattern[x];
   }

   for( unsigned i=min; i<max; i++ ){
      if( MaskCheck( (char*)&bBuffer[i], bPattern, szMask ) ){
         delete[] bPattern;
         return i;
      }
   }

   delete[] bPattern;
   return 0;
}

unsigned FindPattern(String szAOB, int Offset, bool Pointer)
{
   String szTemp = StringReplace(szAOB, " ", "",TReplaceFlags() << rfReplaceAll);
   int len = szTemp.Length();
   char* szBuffer = new char[len];
   char* szMask = new char[len];
   int j = 0;
   for (int pos = 1; pos <= len; pos += 2, j++) {
      if ( szTemp.SubString(pos,1) == '?') {
         szBuffer[j] = 0;
         szMask[j] = '?';
      } else {
         String szByte = "0x"+szTemp.SubString(pos,2);
         szBuffer[j] = (unsigned char)szByte.ToInt();
         szMask[j] = 'x';
      }
   }
   unsigned returnval = FindPatternProcess(szBuffer,szMask,0x00400000,0x00800000)+Offset;
   if (returnval != 0) {
      if (Pointer) {
         returnval = *(unsigned*)returnval;
      }
   }
   String szOutput;
   szOutput.sprintf("%x", returnval);
   OutputDebugString(szOutput.c_str());
   return returnval; // Return the address.
}

// --------------------------------------------------

void MainThread()
{
    AllocConsole();
    SetConsoleTitle("Dynamic GMS Trainer v.1.0"); // Changes the console title.
    // cout << "                            " << endl; // 28 characters.
    cout << "[--------------------------]" << endl;
    cout << " Dynamic GMS Trainer v.1.0  " << endl;
    cout << " Made by inoobzx of CEF     " << endl;
    cout << "[--------------------------]" << endl;
    cout << " Hotkeys:                   " << endl;
    cout << " F1 = CRC Bypass            " << endl;
    cout << " F2 = Damage Control        " << endl;
    cout << " F3 = Exit                  " << endl;
    cout << "[--------------------------]" << endl;
   
    // --------------------------------------------------
   
    BOOL Exit = false;
    int Damage_Control_Address = FindPattern("F069F840A1E6C5C7F2D7", 0, false);
    int Damage_Control_Bytes_On = 0x0000F0F0;
    int Damage_Control_Bytes_Off = 0xF069F840;
   
    // --------------------------------------------------
   
    while (Exit = false)
    {
        if(GetAsyncKeyState(VK_F1)) // If F1 is pressed:
        {
            cout << " Sorry Not Avaible Yet      " << endl;
            /*
            Note: Add Later
            */   
        }
        else if(GetAsyncKeyState(VK_F2)) // If F2 is pressed:
        {
            if(Damage_Control = false)
            {
                cout << " [Enabled] Damage Control   " << endl;
                Sleep(100);
                *(WORD*)Damage_Control_Address = Damage_Control_Bytes_On // Turns hack on.                   
            }
            else
            {
                cout << " [Disabled] Damage Control  " << endl;
                Sleep(100);
                *(WORD*)Damage_Control_Address = Damage_Control_Bytes_Off; // Turns hack off.   
            }
        }
        else if(GetAsyncKeyState(VK_F3)) // If F3 is pressed.
        {
            Exit = true;     
        }
        Sleep(50);
    }
    cout << "Exiting";
    Sleep(500);
    cout << ".";
    Sleep(500);
    cout << ".";
    Sleep(500);
    cout << "." << endl;
    cout << "Have a nice day!            " << endl;
}

// --------------------------------------------------

BOOL APIENTRY DllMain(HMODULE hModule, DWORD call, LPVOID lpReserved) // DLL Main.
{
    if(call == DLL_PROCESS_ATTACH) { // If DLL is attatched to the process.
        DisableThreadLibraryCalls(hModule); // Disables [DLL_THREAD_ATTACH] and [DLL_THREAD_DETACH].
      CreateThread(0, 0, (LPTHREAD_START_ROUTINE)MainThread, hModule, 0, 0); // Creates the MainThread in the process...
    } else if (call == DLL_PROCESS_DETACH) { // If DLL is detached from the process.
        // VirtualFree(CRC, 0x400000, MEM_DECOMMIT); // Deallocate CRC Bypass (use later).
    }
    return TRUE;
}

// --------------------------------------------------

/*

Reference:

*(BYTE*)0x00400000 = 0x90; // Changes an address opcode to a nop (no operation). 
*(WORD*)0x00400000 = 0x9090; // Changes an address opcode to 2 nops (no operations).
*(DWORD*)0x00400000 = 0x90909090; // Changes an address opcode to 4 nops (no operations).

LPVOID CRC; // Sets the ??? variable CRC.
CRC = VirtualAlloc(NULL, 0x00400000, MEM_COMMIT, PAGE_EXECUTE_READWRITE); // Allocate a codecave in the process and assign it to CRC 
VirtualFree(CRC, 0x400000, MEM_DECOMMIT); // Deallocate the CRC codecave in the processes memory.

void _declspec(naked) ASMScript() // A codecave
{
   _asm
   {
      // Blah Blah Blah ... ASM stuff.
   }
}

*/


PS: If the errors are obvious please don't flame.
>.<
Back to top
View user's profile Send private message
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Tue Sep 16, 2008 7:01 pm    Post subject: Reply with quote

Code:

unsigned FindPatternProcess(char* szPattern, const char* szMask, unsigned min, unsigned max)
{
   char* bBuffer = 0;
   int iLength = (int)strlen( szMask );
   char* bPattern = new char[ iLength+1 ];
   for( int x = 0; x <= iLength; x++ ){
      bPattern[x] = szPattern[x];
   }

   for( unsigned i=min; i<max; i++ ){
      if( MaskCheck( (char*)&bBuffer[i], bPattern, szMask ) ){
         delete[] bPattern;
         return i;
      }
   }

   delete[] bPattern;
   return 0;
}

unsigned FindPattern(String szAOB, int Offset, bool Pointer)
{
   String szTemp = StringReplace(szAOB, " ", "",TReplaceFlags() << rfReplaceAll);
   int len = szTemp.Length();
   char* szBuffer = new char[len];
   char* szMask = new char[len];
   int j = 0;
   for (int pos = 1; pos <= len; pos += 2, j++) {
      if ( szTemp.SubString(pos,1) == '?') {
         szBuffer[j] = 0;
         szMask[j] = '?';
      } else {
         String szByte = "0x"+szTemp.SubString(pos,2);
         szBuffer[j] = (unsigned char)szByte.ToInt();
         szMask[j] = 'x';
      }
   }
   unsigned returnval = FindPatternProcess(szBuffer,szMask,0x00400000,0x00800000)+Offset;
   if (returnval != 0) {
      if (Pointer) {
         returnval = *(unsigned*)returnval;
      }
   }
   String szOutput;
   szOutput.sprintf("%x", returnval);
   OutputDebugString(szOutput.c_str());
   return returnval; // Return the address.
}

I can swear i saw this code somewhere...

What about if you post the errors you get?

1) change
Code:
while (Exit = false)

to
Code:
while (Exit == false


2)To start off. You dont have a Damage_Control var.
and if you had it...
change:
Code:
if(Damage_Control = false)

to
Code:
if(Damage_Control == false)


3) Why are you doing this?
Code:

cout << "Exiting";
    Sleep(500);
    cout << ".";
    Sleep(500);
    cout << ".";
    Sleep(500);
    cout << "." << endl;

Its useless make it looks like it loading. You are just wasting time.

4)
Code:
*(WORD*)Damage_Control_Address = Damage_Control_Bytes_On // Turns hack on.

and

*(WORD*)Damage_Control_Address = Damage_Control_Bytes_Off; // Turns hack off.


You know you are writing just 2 bytes right...?
You sayd the value was an int. int is 4 bytes.
Try using DWORD.

_________________
Gone
Back to top
View user's profile Send private message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Tue Sep 16, 2008 7:12 pm    Post subject: Reply with quote

You saw this code in KiPE for getting addresses from AOBs...
and here are the errors:

Dang I have to attach it...

Edit: thx for helpin me i'm a noob at c++

But i thought word = 4 bytes lol

my mom is goin to kill me i will go on tomorrow
Back to top
View user's profile Send private message
Henley
Grandmaster Cheater
Reputation: 0

Joined: 03 Oct 2006
Posts: 671

PostPosted: Tue Sep 16, 2008 7:20 pm    Post subject: Reply with quote

i tried cout with allocconsole before and it didnt work for me.. maybe that could be some errors

dunno though, i might have done something different
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Tue Sep 16, 2008 7:29 pm    Post subject: Reply with quote

WriteConsole/WriteFile for AllocConsole.
_________________
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Tue Sep 16, 2008 7:58 pm    Post subject: Reply with quote

sponge wrote:
WriteConsole/WriteFile for AllocConsole.

Redirecting the I/O is better Smile
Back to top
View user's profile Send private message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Wed Sep 17, 2008 4:43 am    Post subject: Reply with quote

Ok thx I will try when I can...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites