Autoaim Source - C++

jkmjkm

Member
Joined
Dec 11, 2004
Messages
11
Reaction score
0
EDIT: seems like the code format is cluttered - and the URL to my site filtered. Send me a PM if you want the correct link to the source!

Well, if you expected the NTPK source-code - you're wrong! ;) Nevertheless, I wrote a pretty cool autoaim for a friend tonight, and I'm sure the source-code will be of "some" interest to a few module developers (difficulty: intermediate). It's *not* the most optimal way to solve an autoaim, but touches on a few things, like reading some playerinfo directly from memory and handling a gamelist structure.

You can download the source-code directly here: http://www.****************/files/aa.zip (the compiled binary version/full project-file is included, aswell as a readme on how to use it)

It's a simple autoaim that allows you to swap through a list of players and attack them either with left or right button (attacks hide graphics, i.e. you can run while attacking). The main source code (4 main files, 2 excluded) is appended in ASCII format:

Code:
//---
//mem.h (declares unitstructure and related functions)
//---

#ifndef MEM_H
#define MEM_H

	#include "aa.h"

	#define GET_UNIT_RVA			0x869F0 // offset in d2client.dll
	#define GET_MY_UNIT_RVA			0x883D0 // offset in d2client.dll

	struct pUnit
	{
		DWORD unk[3];
		DWORD dwId; // our player id (+0x0c)
		DWORD unk2;
		char* PlayerName; // ptr to charname (+0x14)
	};

	typedef pUnit * (__fastcall * GetUnitFunc) (DWORD dwID, DWORD dwTYPE);
	typedef pUnit * (__fastcall * GetMyUnitFunc) (void);
		
	namespace mem {
		
		// prototypes
		extern BOOL init(void);
		extern char* GetPNAME(DWORD dwID);
		extern char* GetMyPNAME(VOID);
		extern DWORD GetMyPID(VOID);
	};

#endif // MEM_H
Code:
//---
//mem.cpp (defines memory functions)
//---

#include "mem.h"
#include "aa.h"

// define funcs (local to mem.cpp)
GetUnitFunc		GetUnit;
GetMyUnitFunc	GetMyUnit;

namespace mem { // experimental ;p (zoidOr elitOr)

	BOOL init(void) // some messy ptr initialization
	{
		static bInstalled=FALSE;
		if(bInstalled) return TRUE;

		HANDLE ghD2Client = LoadLibrary("D2CLIENT.DLL");
		if (!ghD2Client) return FALSE;

		GetUnit=(GetUnitFunc)(LPDWORD)((LPBYTE)ghD2Client+GET_UNIT_RVA);
		GetMyUnit=(GetMyUnitFunc)(LPDWORD)((LPBYTE)ghD2Client+GET_MY_UNIT_RVA);
		
		bInstalled=TRUE;
		return TRUE;
	}

	char* GetPNAME(DWORD dwID) // get name by id (print target name)
	{
		pUnit * p = GetUnit(dwID,0);
		return p ? p->PlayerName : "Unknown";
	}

	char* GetMyPNAME(VOID) // get our name (greeting message)
	{
		pUnit * p = GetMyUnit();
		return p ? p->PlayerName : "Unknown";
	}

	DWORD GetMyPID(VOID) // get our id (prevent adding ourself)
	{
		pUnit * p = GetMyUnit();
		return p ? p->dwId : 0;
	}
};
Code:
//---
//aa.h (global stuff&framework declarations)
//---

#ifndef AA_H
#define AA_H

	#include <windows.h>
	#include "mem.h"
	#include "framework.h"

	#define MAX_PLAYER_PER_GAME		8

	struct pGameStruct;
	
	// prototypes
	extern BOOL AddPlayer(DWORD dwID);
	extern BOOL RemovePlayer(DWORD dwID);

#endif // AA_H
Code:
//---
//aa.cpp (defines module functions & other)
//---

#include "aa.h"

int currTarget; // index of current target
char szMsg[256]; // message buffer
bool bButton; // TRUE: right button, FALSE: left button
BYTE attackTarget[9] = {0};

struct pGameStruct // our game structure (holds player infos)
{
	DWORD pID;
	bool bUsed;
}; pGameStruct gs[MAX_PLAYER_PER_GAME];


BOOL PRIVATE OnGameCommandToggle(char** argv, int argc) 
{
	if(argc!=2)return FALSE;
		bButton=1-bButton; // might produce performance-warning
		sprintf(szMsg,"Autoaim set to ÿc2%sÿc0 button.",bButton ? "RIGHT" : "LEFT");
		server->GamePrintString(szMsg);
	return TRUE;
}

BOOL PRIVATE OnGameCommandAttack(char** argv, int argc) 
{	
	if(argc!=2)return FALSE;
	if(currTarget<0) 
	{
		server->GamePrintString("Error: No target set.");
		return TRUE;
	}
	bButton ? attackTarget[0]=0x0d : attackTarget[0]=0x07; // set button type
	memcpy(&attackTarget[5],&gs[currTarget].pID,sizeof(DWORD)); // set id
	server->GameSendPacketToServer(attackTarget,sizeof(attackTarget)); // send attack
	return TRUE;
}

BOOL PRIVATE OnGameCommandPrevious(char** argv, int argc) 
{
	if(argc!=2)return FALSE;
	int buf=currTarget;
	for(int i=1;i<MAX_PLAYER_PER_GAME;i++)
	{
		if(--buf<0) // prevent out-of-bounds
			buf=MAX_PLAYER_PER_GAME-1;
		if(gs[buf].bUsed)
		{
			currTarget=buf;
			sprintf(szMsg,"Now aiming at: %s",(const char*)mem::GetPNAME(gs[buf].pID));
			server->GamePrintString(szMsg);
			return TRUE;
		}
	}
	server->GamePrintString("Could not set previous target, because no target is set.");
	return TRUE;
}

BOOL PRIVATE OnGameCommandNext(char** argv, int argc) 
{
	if(argc!=2)return FALSE;
	int buf=currTarget;
	for(int i=1;i<MAX_PLAYER_PER_GAME;i++)
	{
		if(++buf>MAX_PLAYER_PER_GAME-1) // prevent out-of-bounds
			buf=0;
		if(gs[buf].bUsed)
		{
			currTarget=buf;
			sprintf(szMsg,"Now aiming at: %s",(const char*)mem::GetPNAME(gs[buf].pID));
			server->GamePrintString(szMsg);
			return TRUE;
		}
	}
	server->GamePrintString("Could not set next target, because no target is set.");
	return TRUE;
}

BOOL PRIVATE OnGameCommandTarget(char** argv, int argc) 
{
	if(argc!=2)return FALSE;
	if(currTarget<0) 
	{
		server->GamePrintString("Error: No target set.");
		return TRUE;
	}
	sprintf(szMsg,"Current target is: %s",(const char*)mem::GetPNAME(gs[currTarget].pID));
	server->GamePrintString(szMsg);
	return TRUE;
}

BOOL EXPORT OnClientStart()
{
	mem::init(); // initializes function ptr
	return TRUE;
}

VOID EXPORT OnGameJoin(THISGAMESTRUCT* thisgame) 
{
	currTarget=-1;
	for(int i=0;i<MAX_PLAYER_PER_GAME;i++) // init gamestruct
	{
		gs[i].pID=0;
		gs[i].bUsed=FALSE;
	}
	// print greeting
	sprintf(szMsg,"Hello %s. Welcome to the world of autoaim!",(const char*)mem::GetMyPNAME());
	server->GamePrintString(szMsg);
	server->GamePrintString("Type ''.aa'' for help!");
}

DWORD EXPORT OnGamePacketBeforeReceived(BYTE* aPacket, DWORD aLen)
{
	// player joins (note: module has to be loaded when player joins)
	if(aPacket[0] == 0x5b)
	{
		if(!AddPlayer(*(DWORD*)(&aPacket[3])))
			server->GamePrintString("Error: Could not add player to list.");
		return aLen;
	}

	// player leaves (03: usual - 00: timeout)
	if (aPacket[0]==0x5a && (aPacket[1]==0x03 || aPacket[1]==0x00)) 
	{	
		if(!RemovePlayer(*(DWORD*)(&aPacket[3])))
			server->GamePrintString("Error: Could not remove player from list.");
		return aLen;
	}
	return aLen;
}

BOOL AddPlayer(DWORD dwID)
{
	if(dwID==mem::GetMyPID()) // make sure we don't add ourself
		return TRUE; // prevent error msg

	bool bFoundSlot=FALSE;
	for(int i=0;i<MAX_PLAYER_PER_GAME;i++)
	{
		if(!gs[i].bUsed)
		{
			gs[i].pID=dwID;
			gs[i].bUsed=TRUE;
			bFoundSlot=TRUE;
			break;
		}
	}

	if(!bFoundSlot)	return FALSE; // shouldn't happen
	return TRUE;
}

BOOL RemovePlayer(DWORD dwID)
{
	for(int i=0;i<MAX_PLAYER_PER_GAME;i++)
	{	
		if(gs[i].pID==dwID && gs[i].bUsed)
		{
			gs[i].pID=0;
			gs[i].bUsed=FALSE;
			return TRUE;
		}
	}
	return FALSE;
}
I suggest you download the .zip packed file from the link above, since "framework.h" and "framework.cpp" have been excluded from this post to save you from the clutter ;p. Also, this code will not work without the d2hackit framework below version 0.61!

Have fun and don't hesitate to ask questions.

-Jan
 

Trojan

Respected Member
Joined
Jun 15, 2004
Messages
3,545
Reaction score
2
Location
OG From '02
another question:

Is it trojaned or have a php script that does any ghey stuff? ^^
 

*Turok

Member!
Joined
Sep 19, 2004
Messages
314
Reaction score
0
Location
Battle.net
Website
www.battleforums.com
do u actually think we are going to belive that bs lmfao... dude... w/e .. use it urself
 

jkmjkm

Member
Joined
Dec 11, 2004
Messages
11
Reaction score
0
My god.. yes, I am hiding a trojan that will infect you immidiatly in my text files! *lol*

This forum is lost for good, don't expect to see me around here anymore.
 

_CM

Respected Member
Joined
May 19, 2003
Messages
3,874
Reaction score
3
Location
Luxembourg
jkmjkm said:
My god.. yes, I am hiding a trojan that will infect you immidiatly in my text files! *lol*

This forum is lost for good, don't expect to see me around here anymore.
Would you trust somebody who stole more than 30K accounts and hundreds of cdkeys to sell them later on? Sorry dude :(
 

Dragnskull

Retired Staff
Joined
May 30, 2003
Messages
6,812
Reaction score
12
Location
Humble, Texas
jkmjkm said:
My god.. yes, I am hiding a trojan that will infect you immidiatly in my text files! *lol*

This forum is lost for good, don't expect to see me around here anymore.

OHHHH NO MUST COMMET TEH SUICIDE NOW!!!!

on another note:

i gotta give props to 'em...he is tryin hard
 

mr-sumone

Member!
Joined
Oct 3, 2003
Messages
751
Reaction score
0
Website
Visit site
LOL dude you're saying we're lost? Seems to me as if you're lost and never finding your way back. Nobody is going to trust you after that stunt you pulled.
 

Guest

Premium Member
Joined
Jun 28, 2003
Messages
3,905
Reaction score
2
Location
New york
Website
gamerz-lounge.com
Yet, he's still online lol.
 

COTA-GoD

Member!
Joined
Jun 2, 2003
Messages
3,108
Reaction score
0
=/ whats wrong with you people...its txt files.... its your own fault for using his hacks, you arent suppost to be using them anymore, get over it.
 
Joined
Oct 25, 2002
Messages
2,783
Reaction score
0
Location
Edmonton, Alberta
Website
www.battleforums.com
he should not be accused by law that states if he has a disclamier on his site saying something could go wrong that its not his fault, but yours, your stupidity to trust somone you hardly know..in a way hes not a bad person you are..hes just how we say "exploiting" your stupidity.
True no?

I dont hate him, i have no reason to...just kinda shows you he has some brains to think of that, takes a great mind to **** with another person like that, and also think of all the work he would have to do to all those accounts to take items if he so desired.

I personally wont run may programs that arent open source, and for all you a trojan cant be in a .txt file unless it is linked to a site with a auto executing .exe that runs un ditected. Trust me those are nasty, gotta love the DSO exploit for win Xp i think thats the 1, it allows auto executing .exe's to infect you unditected..

:D
 

_CM

Respected Member
Joined
May 19, 2003
Messages
3,874
Reaction score
3
Location
Luxembourg
‘°ºO*¥§âVâGê ¥*Oº°‘ said:
he should not be accused by law that states if he has a disclamier on his site saying something could go wrong that its not his fault, but yours, your stupidity to trust somone you hardly know..in a way hes not a bad person you are..hes just how we say "exploiting" your stupidity.
True no?

I dont hate him, i have no reason to...just kinda shows you he has some brains to think of that, takes a great mind to **** with another person like that, and also think of all the work he would have to do to all those accounts to take items if he so desired.

I personally wont run may programs that arent open source, and for all you a trojan cant be in a .txt file unless it is linked to a site with a auto executing .exe that runs un ditected. Trust me those are nasty, gotta love the DSO exploit for win Xp i think thats the 1, it allows auto executing .exe's to infect you unditected..

:D
oookkkk so you downloaded HIS FAKE FORCETRADEHACK MODULE, sat in front of your monitor, watching your chars disapear and saying 'GJ DUDE! THAT WAS TEH FUNYN LETS STARTG ALL OVER AGAIN!1'?

Dont think so... I didn't download the module, but I know many people who did... And he should burn in hell for this. He even releases the source for his stupid scam... Is he really that 1337?
 

_Ace

BattleForums Senior Member
Joined
May 17, 2003
Messages
1,474
Reaction score
0
Location
Under my bed (Spain)
Website
Visit site
‘°ºO*¥§âVâGê ¥*Oº°‘ said:
he should not be accused by law that states if he has a disclamier on his site saying something could go wrong that its not his fault, but yours, your stupidity to trust somone you hardly know..in a way hes not a bad person you are..hes just how we say "exploiting" your stupidity.
True no?

I dont hate him, i have no reason to...just kinda shows you he has some brains to think of that, takes a great mind to **** with another person like that, and also think of all the work he would have to do to all those accounts to take items if he so desired.

I personally wont run may programs that arent open source, and for all you a trojan cant be in a .txt file unless it is linked to a site with a auto executing .exe that runs un ditected. Trust me those are nasty, gotta love the DSO exploit for win Xp i think thats the 1, it allows auto executing .exe's to infect you unditected..

:D
Errr... about stealing items... someone helped him :rolleyes
And yes, he is trustable, he still codes stuff and is a friend of mine ^^ (leave that beer, bitch :p)
 

NewPosts

New threads

Top