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 


[Help] C++ SpeedHack

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Mon May 26, 2008 11:26 pm    Post subject: [Help] C++ SpeedHack Reply with quote

I am currently trying to program a SpeedHack Dll, that hooks QueryPerformanceCounter, and making it return a fake value. But whenever I inject the dll into a process, the process reaches an exception and closes, and although, the process still works if you dont click any button on the error.
But, the speedhack doesn't kick in, can anyone help? And yes, I looked at the cheatengine source, and didnt find whatsoever what i needed.

Code:

// SpeedHack.cpp : Defines the entry point for the DLL application.
//


#include "stdafx.h"
#include "windows.h"


//Variables.start//
bool isON = false;

double SpeedChoice = 1.0;

static LONGLONG oldfakevalue = 0;

static LONGLONG oldrealvalue = 0;

BOOL ret;

BOOL Stored;

LONGLONG NewValue;

LARGE_INTEGER *lpPerformanceCount;
//Variables.End//


BOOL WINAPI hook_QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount)
{

   Stored = QueryPerformanceCounter(lpPerformanceCount);

   ret = QueryPerformanceCounter(lpPerformanceCount);

   NewValue  = lpPerformanceCount->QuadPart;

   if(oldfakevalue == 0 || oldrealvalue == 0)
    {
     
      oldfakevalue = lpPerformanceCount->QuadPart;
       
      oldrealvalue = lpPerformanceCount->QuadPart;
   
   }

   NewValue = oldfakevalue + (LONGLONG)((NewValue - oldrealvalue) * SpeedChoice);

   oldrealvalue = lpPerformanceCount->QuadPart;

    oldfakevalue = NewValue;

   lpPerformanceCount->QuadPart = NewValue;

return ret;
}


void Handle_SpeedHack()
{

   while(0 == 0)
   {

   if(isON == false)
   {

      if(GetAsyncKeyState(VK_F12))
      {

         isON = true;
         
         MessageBox(0, "Speed Hack Enabled", "Speed Hack", 0);
         
         SpeedChoice = 50.0;

      }

   }

      if(isON == true)
   {

      if(GetAsyncKeyState(VK_F12))
      {

         isON = false;

         MessageBox(0, "Speed Hack Disabled", "Speed Hack", 0);

         SpeedChoice = Stored;


      }

   }

   }

}



BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                )
{
   switch (ul_reason_for_call)
   {
   case DLL_PROCESS_ATTACH:
         DisableThreadLibraryCalls(hModule);
         CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)hook_QueryPerformanceCounter, lpPerformanceCount, 0, 0 );
         CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)Handle_SpeedHack, 0, 0, 0 );
         break;
   case DLL_THREAD_ATTACH:
   case DLL_THREAD_DETACH:
   case DLL_PROCESS_DETACH:
         break;
   }
   return TRUE;
}
Back to top
View user's profile Send private message AIM Address MSN Messenger
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Tue May 27, 2008 2:41 am    Post subject: Reply with quote

I don't see the hooking part anywhere? (I mean the part where you overwrite the IAT or the first 5 bytes of the api to point to you're function)
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Tue May 27, 2008 10:58 am    Post subject: Reply with quote

QueryPerformanceCounter only gives you the value of the counter. When you change the value of lpPerformanceCount, you're only changing the value of your variable, not the counter.
And I see no loop. your counter thread goes through only once.

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Tue May 27, 2008 4:38 pm    Post subject: Reply with quote

Source code for the hack is from:
http://forum.gamedeception.net/showthread.php?t=3924

I suggest you comment that in there given credit as GD is very strict about credits. Wink

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Tue May 27, 2008 5:37 pm    Post subject: Reply with quote

@HalfPrime, i dont think i need a loop, because, isnt queryperformancecounter called several times, depending on what it's injected into?
Back to top
View user's profile Send private message AIM Address MSN Messenger
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Tue May 27, 2008 6:04 pm    Post subject: Reply with quote

Just looked at wiccaan's link and now I understand how it's supposed to work. Instead of creating the thread, you have to actually make a hook for when the app calls the function.
_________________
Back to top
View user's profile Send private message
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