anyone interested in the bots i have written? here is a hero trainer written in c++. it has 2 modes fame(items) and exp (monsters). its a buggy alpha version. and it should compile without the icons.rc file, but i dunno... im pretty sure this version isnt threaded so dont expect to be able to use the computer for anything else while this code runs. it controls the mouse.
#include <radc++.h>
#include <string.h>
//Human Interface Imitator
#ifndef MOUSEEVENTF_RIGHTCLICK
#define MOUSEEVENTF_RIGHTCLICK 6591
#endif
#ifndef MOUSEEVENTF_LEFTCLICK
#define MOUSEEVENTF_LEFTCLICK 6590
#endif
/****lazy coding****/
HWND heroesofgaia = NULL;
HWND bot=NULL;
Form form1("HoG Hero Trainer (alpha) - by satanicgrrl",240,250,335,370,RCP_POPUP_NR );
void SendKey(HWND hwnd, char ch) {
PostMessage(hwnd, WM_KEYDOWN, VkKeyScan(ch), NULL);
}
void SendKeys(HWND hwnd, char *str) {
while (*str) SendKey(hwnd, *str++);
}
void SendClick(int clickType, int dX, int dY){
if (clickType == MOUSEEVENTF_RIGHTCLICK) {
mouse_event(MOUSEEVENTF_RIGHTDOWN, dX, dY, NULL, GetMessageExtraInfo());
mouse_event(MOUSEEVENTF_RIGHTUP, dX, dY, NULL, GetMessageExtraInfo());
}else if (clickType == MOUSEEVENTF_LEFTCLICK) {
mouse_event(MOUSEEVENTF_LEFTDOWN, dX, dY, NULL, GetMessageExtraInfo());
mouse_event(MOUSEEVENTF_LEFTUP, dX, dY, NULL, GetMessageExtraInfo());
}
}
BOOL CALLBACK SearchProc(HWND hWnd, LPARAM lParam) {
int nLen = GetWindowTextLength(hWnd);
LPSTR lpszTitle = new CHAR[nLen + 1];
GetWindowText(hWnd, lpszTitle, nLen);
//cout << "Looking at window: " << lpszTitle << endl;
if(strstr(lpszTitle, "Play Heroes of Gaia, a free online game on Kongregate")){
heroesofgaia=hWnd;
//keybd_event(VK_LCONTROL, 0x1d,0 , 0); //ctrl Press
//keybd_event(VkKeyScan('M'), 0x14,0 , 0); // 'T' Press
//keybd_event(VkKeyScan('M'), 0x94, KEYEVENTF_KEYUP, 0); // 'T' Release
//keybd_event(VK_LCONTROL, 0x9d, KEYEVENTF_KEYUP, 0); // Ctrl Release
//Sleep(1000);
delete lpszTitle;
return TRUE;
}
delete lpszTitle;
return TRUE;
}
/*****END OF H.I.D.I.******/
/**********FUNCTIONS*********/
void togglerunning(int);
void togglestatus();
void gethogcoords();
void getarenacoords();
int checkforred(int x,int y);
int npadstart();
void dokeys();
void arenaRun();
void updatetimer();
int pixeltest(HWND hWnd);
int herocheck();
void closearenamessages();
/*************/
/******TIMER****/
static int hhs=0;
static int mms=0;
static int sss=10;
int hh=hhs;
int mm=mms;
int ss=sss;
String timer1 = "Timer1";
String timer2 = "herocheck timer";
/************/
int hider=0;
int running=0;
int idle=0;
int dispclosemsg=0;
int maxlevel=0;
int mode=0; //0=XP 1=fame 2=daily task monster 3=daily task item
PopUpMenu popup;
MenuItem __EXIT,i2,n,daily,fame,xp;
/****stuff for step 1*/
ImageBox s1ibox(AUTO_ID,0, 10, 0, 100, 28, form1);//2nd arg : 0 = no image by default
Button Button1("Step 1: click this button, then place mouse in upper left corner of HoG (inside blue line) and press ENTER", AUTO_ID, 10, 30, 100, 100, form1);
Label hcoords("HoG window Coords:", AUTO_ID, 10, 131, 100, 20, form1);
ReadOnlyBox coords("",AUTO_ID, 10, 145, 100, 20, form1);
/****stuff for step 2*/
ImageBox s2ibox(AUTO_ID, 0, 115, 0, 100, 28, form1);//2nd arg : 0 = no image by default
Button Button2("STEP 2: click this button", AUTO_ID, 115, 30, 100, 100, form1);
Label acoordslr("Mouse Coords (rel):", AUTO_ID, 115, 131, 100, 20, form1);
ReadOnlyBox acoordsr("",AUTO_ID, 115, 145, 100, 20, form1);
Label acoordsla("Mouse Coords (abs):", AUTO_ID, 115, 165, 100, 20, form1);
ReadOnlyBox acoordsa("",AUTO_ID, 115, 175, 100, 20, form1);
/****stuff for step 3*/
ImageBox s3ibox(AUTO_ID, 0, 10, 166, 100, 28, form1);//2nd arg : 0 = no image by default
//hero name
TextBox t1("Magic Numbers will appear here", AUTO_ID, 10, 200, 205, 25, form1);
ComboBox arenacombo("", AUTO_ID, 10, 230,205, 200, form1);//combo box with arenas
/*****startbutton)*****/
Button Button3("START/STOP", AUTO_ID, 10, 270, 205, 40, form1);
//Status bar
StatusBar status("Time remaining: ;Stopped;Mode:",AUTO_ID,form1,3); //3 parts
ImageBox s4ibox(AUTO_ID, 0, 220, 0, 100, 321, form1);//2nd arg : 0 = no image by default
Icon icon1(101);
/******window coords of hog******/
long hogx=0;
long hogy=0;
long arxa=0;
long arya=0;
long arxr=0;
long aryr=0;
/****************/
int selectedarena=0;
void gethogcoords(){
hogx=Mouse.getXPosition();
hogy=Mouse.getYPosition();
String ctxt="X- ";
ctxt.insert(ctxt.length-1,str(hogx));
ctxt.insert(ctxt.length-1,", Y- ");
ctxt.insert(ctxt.length-1,str(hogy));
coords.text=ctxt;
}
void getarenacoords(){
arxa=Mouse.getXPosition();
arya=Mouse.getYPosition();
String ctxt="X- ";
ctxt.insert(ctxt.length-1,str(arxa));
ctxt.insert(ctxt.length-1,", Y- ");
ctxt.insert(ctxt.length-1,str(arya));
acoordsa.text=ctxt;
arxr=arxa-hogx;
aryr=arya-hogy;
ctxt="X- ";
ctxt.insert(ctxt.length-1,str(arxr));
ctxt.insert(ctxt.length-1,", Y- ");
ctxt.insert(ctxt.length-1,str(aryr));
acoordsr.text=ctxt;
}
int npadstart() {
EnumWindows(SearchProc, NULL);
SetForegroundWindow(heroesofgaia);
/*system("start notepad.exe");
heroesofgaia = FindWindow(NULL, "Play Heroes of Gaia, a free online game on Kongregate");
if(heroesofgaia ==0)
form1.msgBox("found window");
// Find client textbox
// EnumChildWindows(heroesofgaia, WindowEnumProc, NULL);
// Send keys
String blr=t1.text;
blr=blr.substr(0,1);
SendKeys(heroesofgaia,blr);
*/
return 0;
}
//send the key of first leter of hero name
//this will select that hero from the combo box
void dokeys(){
// Send keys
String blr=str(maxlevel);
blr=blr.substr(0,1);
//SendKeys(heroesofgaia,blr);
keybd_event(VkKeyScan(blr.c_str()[0]), 0x14,0 , 0); // 'T' Press
keybd_event(VkKeyScan(blr.c_str()[0]), 0x94, KEYEVENTF_KEYUP, 0); // 'T' Release
Sleep(1000);
keybd_event(VK_RETURN, 0x14, 0,0);
keybd_event(VK_RETURN, 0x94, KEYEVENTF_KEYUP,0);
Sleep(1000);
//click to set the monster lvl X-424, Y- 136
//SendClick(MOUSEEVENTF_LEFTCLICK, 424, 136);
}
void closearenamessages(){
//npadstart();
SetForegroundWindow(heroesofgaia);
Sleep(1000);
//close combat dialoge X-568, Y- 349
Mouse.setXPosition(long(hogx+568));
Mouse.setYPosition(long(hogy+349));
Sleep(200);
SendClick(MOUSEEVENTF_LEFTCLICK,int(Mouse.x),int(Mouse.y));
Sleep(3000);
}
//begin indescriminate use of magic numbers...
void arenaRun(){
togglerunning(1);
//find heroes of gaia
//npadstart();//find heroes and bring it to foreground
SetForegroundWindow(heroesofgaia);
Sleep(2000);
//open search X-776, Y- 53
Mouse.setXPosition(long(hogx+775));
Mouse.setYPosition(long(hogy+53));
Sleep(200);
SendClick(MOUSEEVENTF_LEFTCLICK,int(Mouse.x),int(Mouse.y));
Sleep(3000);
//for item modes
if(mode==1 || mode ==3){
//click item tab X-384, Y- 103
Mouse.setXPosition(long(hogx+384));
Mouse.setYPosition(long(hogy+103));
Sleep(500);
SendClick(MOUSEEVENTF_LEFTCLICK,int(Mouse.x),int(Mouse.y));
Sleep(2000);
}//endif
//click select type X-408, Y- 136
Mouse.setXPosition(long(hogx+408));
Mouse.setYPosition(long(hogy+136));
Sleep(500);
SendClick(MOUSEEVENTF_LEFTCLICK,int(Mouse.x),int(Mouse.y));
Sleep(2000);
//select monster lvl
//combo[combo.selectedItemIndex]; gets the text of the selected combo box item
dokeys();//send the key of monster level
Sleep(2000);
//select first monster in list X-608, Y- 196
Mouse.setXPosition(long(hogx+608));
Mouse.setYPosition(long(hogy+197));
Sleep(500);
if(checkforred((hogx+608), (hogy+197))==0){//theres no monster at this lvl
if(maxlevel>1){
maxlevel--;//drop down one level
dokeys();
}else {//no more monsters must quit
togglerunning(0);
idle=0;//have we run yet? no
return;
}
}
SendClick(MOUSEEVENTF_LEFTCLICK,int(Mouse.x),int(Mouse.y));
Sleep(3000);
//click attack button X-467, Y- 435 X-464, Y- 432
Mouse.setXPosition(long(hogx+464));
Mouse.setYPosition(long(hogy+432));
Sleep(500);
SendClick(MOUSEEVENTF_LEFTCLICK,int(Mouse.x),int(Mouse.y));
Sleep(3000);
//click second attack button...X-393, Y- 459
Mouse.setXPosition(long(hogx+393));
Mouse.setYPosition(long(hogy+459));
Sleep(500);
SendClick(MOUSEEVENTF_LEFTCLICK,int(Mouse.x),int(Mouse.y));
Sleep(3000);
//close arena shit...
//close search X-777, Y- 56
Mouse.setXPosition(long(hogx+777));
Mouse.setYPosition(long(hogy+56));
Sleep(200);
SendClick(MOUSEEVENTF_LEFTCLICK,int(Mouse.x),int(Mouse.y));
Sleep(3000);
//closearenamessages();
SetForegroundWindow(bot);
//shit for other modes
if(mode==2){//daily task monster mode
if(maxlevel>1)
maxlevel--;
else{
maxlevel=1+arenacombo.selectedItemIndex;//have to add 1 because we will be subtracting 1 shortly
mode=3; //this saaves restructuring
}
}
if(mode==3){//daily task item mode
if(maxlevel>1)
maxlevel--;
else{
togglerunning(0);
idle=0;//have we run yet? no
return;
}
}
togglerunning(2);
return;
}
void togglestatus(){
/***Set the statusbar***/
if(running==0){//we are stopped
status.setText(1,"Stopped");
}else if(running==1){//we are currently entering arena
status.setText(1,"Running");
}else if(running==2)
status.setText(1,"Idle");
// SET THE MODE on BAR
if(mode==0){//xp
status.setText(2,"Mode: EXP");
}else if(mode==1){//fame
status.setText(2,"Mode: fame");
}else if(mode==2){//daily task monster
status.setText(2,"Mode: daily-monster");
}else if(mode==3)//daily task item
status.setText(2,"Mode: daily-item");
}
void togglerunning(int runstate){
if(runstate==1){//run
running=1;
}else if(runstate==2){// idle (waiting until arena is ready)
running=2;
}else{//stop
running=0;
}
togglestatus();
}//end toggle running
void updatetimer(){
if(ss==0){
ss=59;
if(mm==0){
mm=59;
if(hh==0){
ss=sss;mm=mms;hh=hhs;
//togglerunning(1);
//closearenamessages();
//arenaRun();
}else{
hh--;
}
}else{
mm--;
}
}else{
ss--;
}
string stat="Time remaining: ";
stat+=str(hh);
stat+=":";
stat+=str(mm);
stat+=(":");
stat+=str(ss);
status.setText(0,stat);
}
int checkforred(int x,int y){
// Retrieve the handle to a display device context for the client
// area of the window.
HDC hdcWindow = GetDC(NULL);
COLORREF pixel=GetPixel(hdcWindow,x,y);
if((int)GetRValue(pixel)>120&&(int)GetGValue(pixel)<20&&(int)GetBValue(pixel)<20){
ReleaseDC(NULL,hdcWindow);
return 1;
}
ReleaseDC(NULL,hdcWindow);
return 0;
}
int herocheck(){//return 0 if in castle or 1 if in use
/*
red lineinfo
color : 133 9 7
position: X-816, Y- 259
*/
if(checkforred((hogx+816), (hogy+259))==0){//hero is in castle
if(idle==1){
closearenamessages();
}
Sleep(500);
togglerunning(1);
return 0;
}
running=2;
status.setText(1,"Idle-waiting on hero");
return 1;
}
int pixeltest(HWND hWnd){
// Retrieve the handle to a display device context for the client
// area of the window.
HDC hdcWindow = GetDC(NULL);
//SetForegroundWindow(hWnd);
/*
red lineinfo
color : 133 9 7
position: X-816, Y- 259
COLORREF GetPixel(
__in HDC hdc,
__in int nXPos,
__in int nYPos
);
The low-order byte contains a value for the relative intensity of red; the second
byte contains a value for green; and the third byte contains a value for blue.
The high-order byte must be zero. The maximum value for a single byte is 0xFF.
To create a COLORREF color value, use the RGB macro. To extract the individual
values for the red, green, and blue components of a color value, use the GetRValue,
GetGValue, and GetBValue macros, respectively.
*/
COLORREF pixel=GetPixel(hdcWindow, Mouse.getXPosition(),Mouse.getYPosition());
String s1="color code: ";
String s2,s3,s4;
char robot[1];
itoa((int)GetRValue(pixel),robot,10);
s2=robot;
itoa((int)GetGValue(pixel),robot,10);
s3=robot;
itoa((int)GetBValue(pixel),robot,10);
s4=robot;
s1=s2+" "+s3+" "+s4;
t1.text=s1;
//Clean up
done:
ReleaseDC(hWnd,hdcWindow);
return 0;
}
int cornerperfect(){
// Retrieve the handle to a display device context for the client
// area of the window.
HDC hdcWindow = GetDC(NULL);
SetForegroundWindow(heroesofgaia);
while(1==1 && hogx>1){//only need x to be perfect
COLORREF pixel=GetPixel(hdcWindow, (hogx),hogy);
if((int)GetRValue(pixel)<55 && (int)GetGValue(pixel)<55 && (int)GetBValue(pixel)<55){
hogx+=1;break;
}else{
hogx--;
}
}
while(1==1 && hogy>1){//only need x to be perfect
COLORREF pixel=GetPixel(hdcWindow, (hogx),hogy);
if((int)GetRValue(pixel)<55 && (int)GetGValue(pixel)<55 && (int)GetBValue(pixel)<55){
hogy+=1;break;
}else{
hogy--;
}
}
String ctxt="X- ";
ctxt.insert(ctxt.length-1,str(hogx));
ctxt.insert(ctxt.length-1,", Y- ");
ctxt.insert(ctxt.length-1,str(hogy));
coords.text=ctxt;
ReleaseDC(NULL,hdcWindow);
SetForegroundWindow(bot);
}
FormProcedure form1Proc(FormProcArgs) {
//if(GetAsyncKeyState(VK_UP) & 0x8000) form1.msgBox("UP");
//t1.text=""+message;
ON_CLOSE(){
hider=(hider==0)?1:0;
if(hider==1){
if(dispclosemsg==0)
form1.warnBox("The program is hidden but still running. right-click icon in tray to close", form1.text);
dispclosemsg=1;
form1.hide();
}else
form1.show();
}
//track changes in max level setting
ON_ITEMSELECT(arenacombo) {
maxlevel = arenacombo.selectedItemIndex;
}
//capture button click, means Button has been clicked
//button to get coords
ON_COMMAND_BY ( Button1 ) {
//Form1.msgBox("Hello Universe!");
gethogcoords();
bot=GetActiveWindow();
}
ON_COMMAND_BY ( Button2 ) {
getarenacoords();
//get HWND for heroes of gaia
EnumWindows(SearchProc, NULL);
pixeltest(heroesofgaia);
cornerperfect();
getarenacoords();
}
ON_COMMAND_BY ( Button3 ) {
maxlevel=arenacombo.selectedItemIndex;
if(running>0){
togglerunning(0);
idle=0;
ss=sss;mm=mms;hh=hhs; updatetimer();
}else{
togglerunning(2);
updatetimer();
//arenaRun();
}
}
ON_RESIZE() { //when form is resized, adjust the statusbar
status.adjust();
}
/*
ON_ITEMSELECT(arenacombo) {
t1.text = arenacombo[arenacombo.selectedItemIndex];
selectedarena=arenacombo.selectedItemIndex;
}
ON_TEXT_CHANGED(t1) { //change text of parts
//status.setText(txt1.text);
}
ON_TEXT_CHANGED(t1) {
/* int num = val(txt2.text);
if(num > 0) {
status.setParts(num); //set new number of parts
//NOTE: application can crash if number of new parts is supplied ZERO
status.setText(txt1.text); //remake popout effects
}
*/
ON_TIMER_NOTIFICATION(timer1) { //when timer named 'Timer1' notifies
//increase value of variable 'x' and assgn it to caption/title of form
//NOTE : str returns string presentation of a numeric value
//form1.caption = str(++x);
if(running>0){//run while not stopped
updatetimer();
}
}
ON_TIMER_NOTIFICATION(timer2) { //when timer named 'Timer2' notifies
togglestatus();
if(running==2){//run while idle
if(herocheck()==0){
arenaRun();
idle=1;//not actually idle... value 1 means monster has been attacked
//form1.msgBox("hero is determined to be in castle");
}
}
}
ON_TRAYICON_RIGHT_CLICK(form1) {
popup.show(form1); //show at form 1
}
ON_TRAYICON_CLICK(form1) { //check if the tray icon has been clicked
//hide or show the window on left click on the tray icon
hider=(hider==0)?1:0;
if(hider==1)
form1.hide();
else
form1.show();
//change the icon and the tooltip of icon that we set in system tray
//first argument is the icon (icon2) and second is tooltip of icon in tray
//form1.resetTrayIcon(icon2,"Tray icon tooltip changed");
//display a message box
//form1.msgBox("Notice in system tray! the icon you clicked has been changed alongwith its tooltip text...");
}
ON_COMMAND_BY(daily){
//t1.text="mode = daily tasks"+str(mode);
mode=2;
t1.text="mode = daily tasks";
}
ON_COMMAND_BY(xp){
t1.text="mode = Experience";
mode=0;
}
ON_COMMAND_BY(fame){
t1.text="mode = Fame";
mode=1;
}
ON_COMMAND_BY(__EXIT){
form1.removeTrayIcon(); //remove the icon we set when quitting application
//remove timer when quitting application (remove all timers before exitting)
form1.removeTimer(timer1);
form1.removeTimer(timer2);
Application.close();
}
ON_COMMAND_BY(i2) form1.text = "i2";
return 0;
}
rad_main()
form1.procedure = form1Proc;
form1.icon= icon1;
form1.setTrayIcon(icon1,"HoG Auto Arena - by satanicgrrl");
//load/display images from rc file
s1ibox.loadImage(102);
s2ibox.loadImage(103);
s3ibox.loadImage(104);
s4ibox.loadImage(105);
//add some enteries to combobox
arenacombo.add("Select max monster lvl");
arenacombo.add("1");
arenacombo.add("2");
arenacombo.add("3");
arenacombo.add("4");
arenacombo.add("5");
arenacombo.add("6");
arenacombo.add("7");
arenacombo.add("8");
arenacombo.select(0); //select first entry
//Set new timer, set notification time to 1 second, which will notify our Form after
//each second continously until timer is not removed
form1.setTimer(timer1, 1 * SECONDS);
form1.setTimer(timer2, 10 * SECONDS);
// label.center(); //center label in form
__EXIT = popup.add("EXIT",AUTO_ID);
i2 = popup.add("nothing interesting",AUTO_ID);
popup.addSeparator();
n = popup.addPopup("set op mode"); //sub-menus not tracked
fame = n.add("Fame Mode",AUTO_ID);
xp = n.add("XP mode",AUTO_ID);
daily = n.add("Daily Tasks",AUTO_ID);
rad_end()
on second thought you may need the icons.rc file for the tray icon to show up. just replace the filename with your icon
101 ICON "hogherotrainer.ico"