Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ | Project: Cheat_Code (Open-Source)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Cheat_Code
How do I cheat?
Reputation: 1

Joined: 28 Feb 2013
Posts: 5

PostPosted: Thu Feb 28, 2013 11:10 pm    Post subject: C++ | Project: Cheat_Code (Open-Source) Reply with quote

Description
Cheat_Code is an open-source project that is written in C++ for educational and for programming purposes.

Documentation
The documentation for Cheat_Code is not yet completed.
Please click here to be redirected to the thread of Cheat_Code's documentation.

Why Did I Create Cheat_Code?
I created Cheat_Code for several reasons. One reason is mainly because I enjoy programming. Because, programming makes me think. Another reason is because I enjoy helping others who shares the same interests as me. And maybe in the near future, Cheat_Code could end up being a very useful library for many developers who enjoy making game trainers. It could make programming easier for them. Also, they can learn from the source codes of Cheat_Code. Those are some reasons why I created Cheat_Code.

Downloads
Sharing is caring.
The first version (version 1) of Cheat_Code can be downloaded right here as .zip.

Preview
Feel free to do some copying and pasting! Please do some review.

Cheat_Code.h
Code:
#ifndef CHEAT_CODE_HEADER
#define CHEAT_CODE_HEADER

#pragma region READ_ME
//////////////////////////////////////////////////////////////////////////////
//                                                                            //
// Copyright (c) 2013 - 2014, "The cheat_code" <cheat_code@aim****>.        //
// Use the code is allowed under the Artistic License 2.0 terms,            //
// as specified in the LICENSE file distributed with this code,                //
// or available from: ****://opensource.**g/licenses/artistic-license-2.0    //
//                                                                            //
//////////////////////////////////////////////////////////////////////////////
#pragma endregion READ_ME

#pragma region RELEASE_INFO
//////////////////////////////////////////////////////////////////////////////
//                                                                            //
// Author: "The cheat_code" <cheat_code@aim****>.                            //
// Version: 1                                                                //
// Released Date: 2/28/2013                                                    //
//                                                                            //
//////////////////////////////////////////////////////////////////////////////
#pragma endregion RELEASE_INFO

#define WIN32_LEAN_AND_MEAN

#include <Windows.h>

#define CHEAT_CODE_NOPS    0
#define CHEAT_CODE_ORGINAL_DISABLE_BYTES 0
#define CHEAT_CODE_DEPENDENT 0

namespace Cheat_Code
{

class Cheat
{
public:
    typedef struct FLAG_STRUCT
    {
        enum __Flags
        {
            None = 0x00,
            EnableBytes_NOP = 0x01,
            #pragma region NO MIXING
            DisableBytes_NOP = 0x02,
            DisableBytes_Original = 0x04,
            DisableBytes_OriginalEx = 0x08,
            #pragma endregion
            AutoDisable = 0x10
        };
    } CheatFlags;

    Cheat( void ) :
          Address( 0 ),
          EnableBytes( 0 ),
          DisableBytes( 0 ),
          Enabled( false ),
          Flags( CheatFlags::None )
    { };

    Cheat( __in unsigned long p_Address,
          __in char* p_EnableBytes,
          __in char* p_DisableBytes,
          __in unsigned int p_EnableBytesLength,
          __in unsigned int p_DisableBytesLength,
          __in bool p_Enabled,
          __in_opt unsigned int p_Flags = CheatFlags::None ) :
          Address( p_Address ),
          EnableBytes( p_EnableBytes ),
          DisableBytes( p_DisableBytes ),
          EnableBytesLength( p_EnableBytesLength ),
          DisableBytesLength( p_DisableBytesLength ),
          Enabled( p_Enabled ),
          Flags( p_Flags )
    {
          if( p_Flags ) FlagHandler( );
          if( p_Enabled ) Enable( true );
    };

    ~Cheat( void )
    {
          if( Flags &( CheatFlags::AutoDisable )
              && Enabled )
              Enable( false );

          if( Flags &( CheatFlags::EnableBytes_NOP )
              && EnableBytes != NULL )
              delete [ ] EnableBytes;

          if( Flags &( CheatFlags::DisableBytes_NOP ) ||
              Flags &( CheatFlags::DisableBytes_Original )
              && DisableBytes != NULL )
              delete [ ] DisableBytes;
    };

public:
    unsigned long Address;
    char* EnableBytes;
    char* DisableBytes;
    unsigned int EnableBytesLength;
    unsigned int DisableBytesLength;

private:
    unsigned int Flags;
    bool Enabled;
public:
    bool IsEnabled( void ) { return( Enabled ); };
    int Enable( __in bool p_Enable );

private:
    void FlagHandler( void );
};

namespace Util
{
    void WriteMemory( __in unsigned long Address,
                      __in char* Bytes,
                      __in unsigned int Length );
};

};

#endif // CHEAT_CODE_HEADER


Cheat_Code.cpp
Code:
#pragma region READ_ME
//////////////////////////////////////////////////////////////////////////////
//                                                                            //
// Copyright (c) 2013 - 2014, "The cheat_code" <cheat_code@aim****>.        //
// Use the code is allowed under the Artistic License 2.0 terms,            //
// as specified in the LICENSE file distributed with this code,                //
// or available from: *****//opensource****/licenses/artistic-license-2.0    //
//                                                                            //
//////////////////////////////////////////////////////////////////////////////
#pragma endregion READ_ME

#include "Cheat_Code.h"

void Cheat_Code::Cheat::FlagHandler( void )
{
    if( Flags &( CheatFlags::EnableBytes_NOP ) )
    {
        this->EnableBytes = new char[ this->EnableBytesLength + 1 ];
        ::memset( this->EnableBytes, 0x90, sizeof( char ) * this->EnableBytesLength );
        this->EnableBytes[ this->EnableBytesLength ] = '\0';
    }

    if( this->Flags &( CheatFlags::DisableBytes_NOP ) )
    {
        this->DisableBytes = new char[ this->DisableBytesLength + 1 ];
        ::memset( this->DisableBytes, 0x90, sizeof( char ) * this->DisableBytesLength );
        this->DisableBytes[ this->DisableBytesLength ] = '\0';
    }
    else if( this->Flags &( CheatFlags::DisableBytes_Original ) )
    {
        this->DisableBytes = new char[ DisableBytesLength + 1 ];
        ::memcpy( ( void * )this->DisableBytes,
                  ( const void* )this->Address,
                  ( sizeof( char ) * this->DisableBytesLength ) );
        this->DisableBytes[ this->DisableBytesLength ] = '\0';
    }
    else if( this->Flags &( CheatFlags::DisableBytes_OriginalEx ) )
    {
        this->DisableBytes = new char[ this->EnableBytesLength + 1 ];
        ::memcpy( ( void * )this->DisableBytes,
                  ( const void* )this->Address,
                  ( sizeof( char ) * this->EnableBytesLength ) );
        this->DisableBytes[ this->EnableBytesLength ] = '\0';
        this->DisableBytesLength = this->EnableBytesLength;
    }
};

int Cheat_Code::Cheat::Enable( __in bool p_Enable )
{
    if( p_Enable != this->Enabled )
    {
        if( p_Enable && this->EnableBytes > 0 && this->EnableBytesLength != 0 )
            Util::WriteMemory( this->Address, this->EnableBytes, this->EnableBytesLength );
        else if( !p_Enable && this->DisableBytes > 0 && this->DisableBytesLength != 0 )
            Util::WriteMemory( this->Address, this->DisableBytes, this->DisableBytesLength );
        else return( 0 );

        this->Enabled = p_Enable;
    }
    return( 1 );
};

void Cheat_Code::Util::WriteMemory( __in unsigned long Address,
                                    __in char* Bytes,
                                    __in unsigned int Length )
{
    unsigned long OriginalProtection = 0;

    ::VirtualProtect( ( void* )( Address ), Length, PAGE_EXECUTE_READWRITE, &OriginalProtection );
    ::memcpy( ( void * )Address, Bytes, Length );
    ::VirtualProtect( ( void* )( Address ), Length, OriginalProtection, 0 );
};


Known Bugs/Problems
If you believe you have found a new bug within Cheat_Code, please report it.
Code:

Currently, there are no known bugs within the latest version of
Cheat_Code nor are there any problems with it.



History of Changes
This is where we shall log all changes that are made within Cheat_Code.
Code:

Currently, nothing of Cheat_Code has been changed.


Suggestions and Reviews Are Not Ignored
Feel free to share your suggestions and/or reviews!

Author
The cheat_code <cheat_code@aim****>

Contributors
Currently, there are no contributors.
Back to top
View user's profile Send private message AIM Address
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Feb 28, 2013 11:22 pm    Post subject: Reply with quote

Code:
::VirtualProtect( ( void* )( Address ), Length, OriginalProtection, 0 );


This call will always fail since the last param is considered invalid.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Cheat_Code
How do I cheat?
Reputation: 1

Joined: 28 Feb 2013
Posts: 5

PostPosted: Thu Feb 28, 2013 11:28 pm    Post subject: Reply with quote

Wiccaan wrote:
Code:
::VirtualProtect( ( void* )( Address ), Length, OriginalProtection, 0 );


This call will always fail since the last param is considered invalid.


Fixed.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites