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;
}






