[C++] Advanced Patch Class - Get your hack releases more stable!

04/02/2011 18:31 r a z e r _#1
This will help you coders to get your releases more stable.
Credts: r a z e r _ (me).

-----

// usage 1, simple address:

#define adr_speed 0x...
mp<float> speed( adr_speed );
speed *= 2.0f; // increase speed by factor 2
speed = 500.0f; // set speed to 500
speed.reset(); // reset speed to old value

//usage 2, pointer + offset:

#define ptr_player 0x...
#define ofs_z 0x...
mp<float> pos_z( ptr_player, ofs_z );
//superjump example:
pos_z += 10.0f;
// for resetting the value:
pos_z.reset();
// for re-saving the patch value:
pos_z.save();
// for reading the value:
pos_z.get();

// the following operators are added to the class:
// # =
// # +=
// # -=
// # *=
// # /=

//mp.h

Code:
template <class type>
class mp {
public:
	mp( unsigned long adr );
	mp( unsigned long ptr, unsigned long ofs );
	type get();
	void reset();
	void save();
	void operator=( type val );
	void operator+=( type val );
	void operator*=( type val );
	void operator-=( type val );
	void operator/=( type val );
private:
	type *adr;
	unsigned long *ptr;
	unsigned long ofs;
	bool patched;
	type sval;
};

template <class type>
mp<type>::mp( unsigned long adr ) {
	this->adr = (type*)(adr);
	this->ptr = NULL;
	this->ofs = NULL;
	this->sval = *this->adr;
	this->patched = false;
}

template <class type>
mp<type>::mp( unsigned long *ptr, unsigned long ofs ) {
	this->adr = NULL;
	this->ptr = (unsigned long*)(ptr);
	this->ofs = (unsigned long)(ofs);
	this->sval = *(type*)(*this->ptr+this->ofs);
	this->patched = false;
}

template <class type>
void mp<type>::operator=( type val ) {
	if( this->adr )
		*this->adr = val;
	else if( *this->ptr )
		*(type*)( *this->ptr + this->ofs ) = val;
	if( this->adr || *this->ptr ) 
		this->patched = true;
}

template <class type>
void mp<type>::operator+=( type val ) {
	if( this->adr )
		*this->adr += val;
	else if( *this->ptr )
		*(type*)( *this->ptr + this->ofs ) += val;
	if( this->adr || *this->ptr ) 
		this->patched = true;
}	

template <class type>
void mp<type>::operator-=( type val ) {
	if( this->adr )
		*this->adr -= val;
	else if( *this->ptr )
		*(type*)( *this->ptr + this->ofs ) -= val;
	if( this->adr || *this->ptr ) 
		this->patched = true;
}	

template <class type>
void mp<type>::operator*=( type val ) {
	if( this->adr )
		*this->adr *= val;
	else if( *this->ptr )
		*(type*)( *this->ptr + this->ofs ) *= val;
	if( this->adr || *this->ptr ) 
		this->patched = true;
}	

template <class type>
void mp<type>::operator/=( type val ) {
	if( this->adr )
		*this->adr *= (1/val);
	else if( *this->ptr )
		*(type*)( *this->ptr + this->ofs ) *= (1/val)
	if( this->adr || *this->ptr ) 
		this->patched = true;
}	

template <class type>
type mp<type>::get() {
	if( this->adr )
		return *this->adr;
	else if( *this->ptr )
		return *(type*)( *this->ptr + this->ofs );
	return 0;
}

template <class type>
void mp<type>::reset() {
	if( this->adr )
		*this->adr = this->sval;
	else if( *this->ptr )
		*(type*)( *this->ptr + this->ofs ) = this->sval;
	if( this->adr || *this->ptr ) 
		this->patched = false;
}

template <class type>
void mp<type>::save() {
	if( this->adr ) 
		this->sval = *this->adr;
	else if ( *this->ptr )
		this->sval = *(type*)( *this->ptr + this->ofs );
	this->patched = false;
}
04/02/2011 18:33 Lord0fCyberWar#2
Ich verstehe zwar kein Wort, aber es sieht hilfreich aus ^^

Kommt aber in die Guide-Sektion.

#moverequest
04/02/2011 18:33 theitfan1337#3
Sehr nice.
04/02/2011 18:34 Arkane´#4
lol nice thank you alot
04/02/2011 18:37 r a z e r _#5
Quote:
Originally Posted by Lord0fCyberWar View Post
Ich verstehe zwar kein Wort, aber es sieht hilfreich aus ^^

Kommt aber in die Guide-Sektion.

#moverequest
Coder wissen das zu verwenden. BTW wenn die Mods dir zustimmen sollen sie es ruhig moven, hatte kA wohin. Es soll auf jeden Fall nicht in den Sammelthread, da diese Source dort unterginge.
04/02/2011 18:41 xxkingskill#6
:)
04/02/2011 18:44 r a z e r _#7
Quote:
Originally Posted by xxkingskill View Post
es gibt in epvp keine coder, oder die c++ können.
das ist alles nur c&p ;)

Ich habe das nicht nur hier realeased, deswegen hab ich mir auch nicht die Mühe gemacht es nochmal ins deutsche zu übersetzen.