C++ Question

Posts 1–15 of 16 · Page 1 of 2
C++ Question
Well , aanthonyz gave me the code and evrything on making the Score appears on CMD , nice, i used that code and i changed to read an hp and mana address , its showing everything fine.

My question is , can i acctually make , force C++ to say something on an notepad or game ? like , on vb , that u make an autotyper to type whatever you want ?

i want to make somethigng like that, if my HP fall under 1000 , to the program or game or whatever , to force using an spell , like a macro or whatever u guys calls it .


so lets go review the question.

Review:

Make a " macro" that , when it read that my hp is less than 1000 hp , the program auto type the name of the cure spell , giving me more chance to live on the game , or , when im not paying attetion, like , going to pee or so , if someone go killing me , the program auto heal me .

is that posible on C++? cuz , i think on VB it is , but idk how to do on both.

Thank to you that reply and support me , happy hacking !!

"We all have an start , a begginer side , but sometime we all grow up and end up teaching the others."
Yes. It's very easy to do this. All you have to do is send command, or keystrokes to the target program.

Someone created a C++ Class to send keys as easily as those in VB or C# can: SendKeys in C++ - CodeProject

Also if you search you will find plenty of example in the annals of the C++ forum, using techniques such as: SendMessage to kybd_event
ok tyvm why06 , ill take a look at link , thanks for the reply and support! , ifi have problems ill post back here , ty!
Quote Originally Posted by wolfguardiann View Post
ok tyvm why06 , ill take a look at link , thanks for the reply and support! , ifi have problems ill post back here , ty!
That's great, all I ask is that you put in the effort to search for and attempt examples, if you have any problems then its fun to help out, else it becomes kind of a chore to repeat things to many different people, goodluck.
well , problems , can u give an example of this ? an quick example ? post all the codes here so i can examine , if im not abusinh too much , please.


i couldnt find a simple example , just make on that say hi on notepad , and then show me where i can change to make that on aan game
I am using this for my robot that I am making.

Code:
SetForegroundWindow(GetConsoleWindow()); //Sets the program as the main window. Used to set the window.
    keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0); //Simulate that you are pressing the ALT key
    keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0); //Simulate that you are pressing the ENTER key
    keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0); //Simulate that you are letting go of the ALT key
    keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0); //Simulate that you are letting go of the ENTER key
REMEMBER. ALWAYS LET GO OF THE BUTTON!!!
If you dont, your computer will assume you are pressing those buttons forever!


PRESS THANKS!!!!!


Quote Originally Posted by aanthonyz View Post
I am using this for my robot that I am making.

Code:
SetForegroundWindow(GetConsoleWindow()); //Sets the program as the main window. Used to set the window.
    keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0); //Simulate that you are pressing the ALT key
    keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0); //Simulate that you are pressing the ENTER key
    keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0); //Simulate that you are letting go of the ALT key
    keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0); //Simulate that you are letting go of the ENTER key
REMEMBER. ALWAYS LET GO OF THE BUTTON!!!
If you dont, your computer will assume you are pressing those buttons forever!


PRESS THANKS!!!!!



heres the code

Code:
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
     DWORD address =0x063FE94; // This is the address that we want to read from
     int value = 0; // This will store our value. In my case, its an integer, which is the timer
     DWORD address2=0x063FE78;
     int value2= 0;
     DWORD pid; //This will store our Process ID, used to read/write into the memory
     HWND hwnd; //Finally a handle to our window 
     
     hwnd = FindWindow(NULL,"TB"); //Finds the Window called "TB"
	if(!hwnd) //If none, display an error
	{
	cout <<"Window not found!\n";
	cin.get();
	}
	else
	{
    GetWindowThreadProcessId(hwnd,&pid); //Get the process id and place it in pid
    HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,pid); //Get permission to read
    cout << "ok , tentando Mostrar valores...\n";
        if(!phandle) //Once again, if it fails, tell us
		{
		cout <<"Could not get handle!\n";
		cin.get();
		}
       
        
		else
		{
        while(1)  //Forever, or until you force close the program
		{
		ReadProcessMemory(phandle,(void*)address,&value,sizeof(value),0); //Read what is in "address" and store it in "value", then what is the size of what we are going to read which is "value",and finally the number of bytes read, but I dont care about that so I put a 0, or NULL
		cout <<"HP:"<< value << "\n\n";  //Display it
		ReadProcessMemory(phandle,(void*)address2,&value2,sizeof(value2),0);
		cout <<"MP:"<<value2<<"\n\n";
		Sleep(5000); //I was reading the timer which increases every second, so I made my program go through that loop every second 
		
	
		
        }
		return 0;
		}
	}
}
i want the , when it reads the value of the address 1

ADDRESS 1 I MEAN VALUE

address1=value
address2=value2;;;

when it read the value 1 that is responsable for the hp , that it type the name of the cure spell , just like an macro or whatever .

i tryed to use the codes there , it worked but , idk where to put the text to send xD

can you modify the code there to make that ? if im not abusing too much?
There are two ways of doing it:

1: Change the memory itself (Easiest if game is unprotected)
Code:
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
     DWORD address =0x063FE94; // This is the address that we want to read from
     int change = 1000;
	 int value = 0; // This will store our value. In my case, its an integer, which is the timer
     DWORD address2=0x063FE78;
	 int change2 = 1000;
     int value2= 0;
     DWORD pid; //This will store our Process ID, used to read/write into the memory
     HWND hwnd; //Finally a handle to our window 
     
     hwnd = FindWindow(NULL,"TB"); //Finds the Window called "Minesweeper"
	if(!hwnd) //If none, display an error
	{
	cout <<"Janela nao encontrada!\n";
	cin.get();
	}
	else
	{
    GetWindowThreadProcessId(hwnd,&pid); //Get the process id and place it in pid
    HANDLE phandle = OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE,0,pid); //Get permission to read
    cout << "ok , tentando Mostrar valores...\n";
        if(!phandle) //Once again, if it fails, tell us
		{
		cout <<"Could not get handle!\n";
		cin.get();
		}
       
        
		else
		{
        while(1)  //Forever, or until you force close the program
		{
		ReadProcessMemory(phandle,(void*)address,&value,sizeof(value),0); //Read what is in "address" and store it in "value", then what is the size of what we are going to read which is "value",and finally the number of bytes read, but I dont care about that so I put a 0, or NULL
		cout <<"HP:"<< value << "\n\n";  //Display it
		ReadProcessMemory(phandle,(void*)address2,&value2,sizeof(value2),0);
		cout <<"MP:"<<value2<<"\n\n";
		if(value == 2)
		{
		WriteProcessMemory(phandle,(void*)address,&change,sizeof(change),0);
		}
		if(value2 == 2)
		{
		WriteProcessMemory(phandle,(void*)address,&change2,sizeof(change2),0);
		}
		Sleep(5000); //I was reading the timer which increases every second, so I made my program go through that loop every second 
		
	
		
        }
		return 0;
		}
	}
Change the red stuff with the number you want it to check for before it changes the value.

2: Key Command
Code:
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
     DWORD address =0x063FE94; // This is the address that we want to read from
     int change = 1000;
	 int value = 0; // This will store our value. In my case, its an integer, which is the timer
     DWORD address2=0x063FE78;
	 int change2 = 1000;
     int value2= 0;
     DWORD pid; //This will store our Process ID, used to read/write into the memory
     HWND hwnd; //Finally a handle to our window 
     
     hwnd = FindWindow(NULL,"TB"); //Finds the Window called "Minesweeper"
	if(!hwnd) //If none, display an error
	{
	cout <<"Janela nao encontrada!\n";
	cin.get();
	}
	else
	{
    GetWindowThreadProcessId(hwnd,&pid); //Get the process id and place it in pid
    HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,pid); //Get permission to read
    cout << "ok , tentando Mostrar valores...\n";
        if(!phandle) //Once again, if it fails, tell us
		{
		cout <<"Could not get handle!\n";
		cin.get();
		}
       
        
		else
		{
        while(1)  //Forever, or until you force close the program
		{
		ReadProcessMemory(phandle,(void*)address,&value,sizeof(value),0); //Read what is in "address" and store it in "value", then what is the size of what we are going to read which is "value",and finally the number of bytes read, but I dont care about that so I put a 0, or NULL
		cout <<"HP:"<< value << "\n\n";  //Display it
		ReadProcessMemory(phandle,(void*)address2,&value2,sizeof(value2),0);
		cout <<"MP:"<<value2<<"\n\n";
		if(value == 2)
		{
	keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0); 
    keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0); 
    keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0); 
    keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0); 
		}
		if(value2 == 2)
		{
	keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0); 
    keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0); 
    keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0); 
    keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0); 
		}
		Sleep(5000); //I was reading the timer which increases every second, so I made my program go through that loop every second 
		
	
		
        }
		return 0;
		}
	}
Change the red stuff, with the keys for your macro
which one you think its the best ? i tryed the key one ( cuz the first i didnt get what to do acctually)

onthe key method, i putted to F11 , but, it do anything, haha
Quote Originally Posted by wolfguardiann View Post
which one you think its the best ? i tryed the key one ( cuz the first i didnt get what to do acctually)

onthe key method, i putted to F11 , but, it do anything, haha
I forgot something. Tell me the name of the game.
Regnum online
Tibia;

read what i sent so ull get extra info. ;P
Replace the red stuff with the name of the game

Code:
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
     DWORD address =0x063FE94; // This is the address that we want to read from
     int change = 1000;
	 int value = 0; // This will store our value. In my case, its an integer, which is the timer
     DWORD address2=0x063FE78;
	 int change2 = 1000;
     int value2= 0;
     DWORD pid; //This will store our Process ID, used to read/write into the memory
     HWND hwnd; //Finally a handle to our window 
     
     hwnd = FindWindow(NULL,"TB"); //Finds the Window called "Minesweeper"
	if(!hwnd) //If none, display an error
	{
	cout <<"Janela nao encontrada!\n";
	cin.get();
	}
	else
	{
    GetWindowThreadProcessId(hwnd,&pid); //Get the process id and place it in pid
    HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,pid); //Get permission to read
    cout << "ok , tentando Mostrar valores...\n";
        if(!phandle) //Once again, if it fails, tell us
		{
		cout <<"Could not get handle!\n";
		cin.get();
		}
       
        
		else
		{
        while(1)  //Forever, or until you force close the program
		{
		ReadProcessMemory(phandle,(void*)address,&value,sizeof(value),0); //Read what is in "address" and store it in "value", then what is the size of what we are going to read which is "value",and finally the number of bytes read, but I dont care about that so I put a 0, or NULL
		cout <<"HP:"<< value << "\n\n";  //Display it
		ReadProcessMemory(phandle,(void*)address2,&value2,sizeof(value2),0);
		cout <<"MP:"<<value2<<"\n\n";
		if(value == 2)
		{
	SetForegroundWindow(hwnd); //Sets the window to the game
	keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), 0, 0); //Press F11
    keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), KEYEVENTF_KEYUP, 0); //Let go of F11
		}
		if(value2 == 2)
		{
	SetForegroundWindow(hwnd); //Sets the window to the game
	keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), 0, 0); //Press F11
    keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), KEYEVENTF_KEYUP, 0); //Let go of F11  
		}
		Sleep(5000); //I was reading the timer which increases every second, so I made my program go through that loop every second 
		
	
		
        }
		return 0;
		}
	}
This should be it...
Quote Originally Posted by aanthonyz View Post
Replace the red stuff with the name of the game

Code:
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
     DWORD address =0x063FE94; // This is the address that we want to read from
     int change = 1000;
	 int value = 0; // This will store our value. In my case, its an integer, which is the timer
     DWORD address2=0x063FE78;
	 int change2 = 1000;
     int value2= 0;
     DWORD pid; //This will store our Process ID, used to read/write into the memory
     HWND hwnd; //Finally a handle to our window 
     
     hwnd = FindWindow(NULL,"TB"); //Finds the Window called "Minesweeper"
	if(!hwnd) //If none, display an error
	{
	cout <<"Janela nao encontrada!\n";
	cin.get();
	}
	else
	{
    GetWindowThreadProcessId(hwnd,&pid); //Get the process id and place it in pid
    HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,pid); //Get permission to read
    cout << "ok , tentando Mostrar valores...\n";
        if(!phandle) //Once again, if it fails, tell us
		{
		cout <<"Could not get handle!\n";
		cin.get();
		}
       
        
		else
		{
        while(1)  //Forever, or until you force close the program
		{
		ReadProcessMemory(phandle,(void*)address,&value,sizeof(value),0); //Read what is in "address" and store it in "value", then what is the size of what we are going to read which is "value",and finally the number of bytes read, but I dont care about that so I put a 0, or NULL
		cout <<"HP:"<< value << "\n\n";  //Display it
		ReadProcessMemory(phandle,(void*)address2,&value2,sizeof(value2),0);
		cout <<"MP:"<<value2<<"\n\n";
		if(value == 2)
		{
	SetForegroundWindow(hwnd); //Sets the window to the game
	keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), 0, 0); //Press F11
    keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), KEYEVENTF_KEYUP, 0); //Let go of F11
		}
		if(value2 == 2)
		{
	SetForegroundWindow(hwnd); //Sets the window to the game
	keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), 0, 0); //Press F11
    keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), KEYEVENTF_KEYUP, 0); //Let go of F11  
		}
		Sleep(5000); //I was reading the timer which increases every second, so I made my program go through that loop every second 
		
	
		
        }
		return 0;
		}
	}
This should be it...
when i press F11 nothing happens , can this be done only by forcing the program to type something?


here i found this quick code

Code:
#include <windows.h>
#include <stdio.h>
int main()

{

 

char buffer[MAX_PATH];

char *message = "hello";

sprintf(buffer, "%s", message);

 

//GetWindowText(hwContact, szContact, 256);

//strcpy(&szContact[strlen(szContact)], " - Conversation");

 

//GetWindowText(hwMsg, szMsg, 256);

//strcpy(&szMsg[strlen(szMsg)], "");

 

HWND fcContact = FindWindow(NULL, "Untitled - Notepad");

 

ShowWindow(fcContact, SW_SHOWMAXIMIZED);

SetForegroundWindow(fcContact);

//FindWindowEx( hTray, NULL, "Button", NULL);

SendMessage(FindWindowEx(fcContact, NULL, "Edit", NULL), WM_SETTEXT, 0, (LPARAM)buffer);

 

system("pause");

}
so when its executed , it would say Hello

i want to the program force type the name of the spell , instead of Hello

i tryed to do this by changing the window name , and it didnt typed anything, this means the game cant type anything?
Waaaaiiiitttt!!!

What do you want exactly?

This basically presses a certain button when your health is 65:
Code:
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
     DWORD address =0x063FE94;
	 int value = 0;
     DWORD address2=0x063FE78;
     int value2= 0;
     DWORD pid;
     HWND hwnd;
     hwnd = FindWindow(NULL,"TB");
	if(!hwnd)
	{
	cout <<"Janela nao encontrada!\n";
	cin.get();
	}
	else
	{
    GetWindowThreadProcessId(hwnd,&pid);
    HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,pid); //Get permission to read
    cout << "ok , tentando Mostrar valores...\n";
        if(!phandle)
		{
		cout <<"Could not get handle!\n";
		cin.get();
		}
       
        
		else
		{
        while(1)
		{
		ReadProcessMemory(phandle,(void*)address,&value,sizeof(value),0);
		cout <<"HP:"<< value << "\n\n";  //Display it
		ReadProcessMemory(phandle,(void*)address2,&value2,sizeof(value2),0);
		cout <<"MP:"<<value2<<"\n\n";
		if(value == 65)
		{
	SetForegroundWindow(hwnd); //Sets the window to the game
	keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), 0, 0); //Press F11
    keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), KEYEVENTF_KEYUP, 0); //Let go of F11
		}
		if(value2 == 65)
		{
	SetForegroundWindow(hwnd); //Sets the window to the game
	keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), 0, 0); //Press F11
    keybd_event(VK_F11, MapVirtualKey(VK_F11, 0), KEYEVENTF_KEYUP, 0); //Let go of F11  
		}
		Sleep(5000);
		
	
		
        }
		return 0;
		}
	}
ohhhhhhhhhh i see , i did shit here , i accidentally pressed F on the codes, was giving error , haha, sorry aanthonyz , its working now , so , everytime when my health is 65 , like your example , the program will press F11 , like all onlnie gamehave an Hotkey method, instead of creating one, u just press the hotkey that in-game , is configured to do something , genious! , it worked!

thanks again for all your help , aanthonyz , thank you very much!!!

oh and , when that thing u said is going to start , pm me !! ill try me best to help!!
Posts 1–15 of 16 · Page 1 of 2

Post a Reply

Tags for this Thread

None

Talk with us