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 


Some one help me to figure out the problem

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

Joined: 11 Sep 2012
Posts: 30
Location: Malaysia

PostPosted: Fri May 31, 2013 7:34 am    Post subject: Some one help me to figure out the problem Reply with quote

Okay, so this is my hack , but when I click and hold left click , hack doesn't work, this is the code..

Code:

#include "stdafx.h"
#include <Windows.h>
#include "detours.h"
#include <Mmsystem.h>
#pragma comment(lib,"winmm.lib")

HANDLE WorkerThread;

DWORD   WINAPI GetTickCount_Detour(void);
DWORD   WINAPI timeGetTime_Detour(void);
BOOL   WINAPI QueryPerformanceCounter_Detour(LARGE_INTEGER *lp);

//set up our trampolines
DETOUR_TRAMPOLINE(DWORD WINAPI GetTickCount_Trampoline(void), GetTickCount);
DETOUR_TRAMPOLINE(DWORD WINAPI timeGetTime_Trampoline(void), timeGetTime);
DETOUR_TRAMPOLINE(BOOL WINAPI QueryPerformanceCounter_Trampoline(LARGE_INTEGER *lp), QueryPerformanceCounter);

//global variables for QueryPerformanceCounter hook
DWORD qpc_last_fake, qpc_last_real;

//global variables for timeGetTime hook
DWORD tgt_last_real, tgt_last_fake;

//global variables for GetTickCount hook
DWORD gtc_last_real, gtc_last_fake;

DWORD increasefactor = 200 ;
bool MouseIsDown = false;
bool ThreadIsRunning  = true;
bool Speed = false;
/**
 * Low-level Mouse Callback
 */
LRESULT CALLBACK MouseCallback( int nCode, WPARAM wParam, LPARAM lParam )
{
   /**
 * Low-level Mouse Hook
 */ 
SetWindowsHookEx( WH_MOUSE_LL , reinterpret_cast< HOOKPROC >( MouseCallback ), NULL, NULL );

    if (nCode == HC_ACTION)
    {
        switch (wParam)
        {
        case WM_LBUTTONDOWN:
            MouseIsDown = true;
            break;
        case WM_LBUTTONUP:
            MouseIsDown = false;
            break;       
        }
    }
   
    return CallNextHookEx( NULL, nCode, wParam, lParam );
}

DWORD WINAPI Thread(LPVOID parblock)
{
    while (ThreadIsRunning)
    {
       
        if (MouseIsDown = true)
        {
            Speed=true;
         
        }
   
      if (MouseIsDown = false)
      {
         Speed = false;
      }
       
    }

    return ERROR_SUCCESS;
}


DWORD WINAPI GetTickCount_Detour()
{
   DWORD ret = GetTickCount_Trampoline();

   DWORD nReal = ret;
   DWORD dReal = nReal - gtc_last_real;
   DWORD dFake = (increasefactor/100) * dReal;

   if (Speed)
   {
      ret = gtc_last_fake + dFake;
      gtc_last_fake += dFake;
   }
   else
   {
      ret = gtc_last_fake + dReal;
      gtc_last_fake += dReal;
   }

   gtc_last_real += dReal;

   return ret;
}

DWORD WINAPI timeGetTime_Detour()
{
   DWORD ret = timeGetTime_Trampoline();

   DWORD nReal = ret;
   DWORD dReal = nReal - tgt_last_real;
   DWORD dFake = (increasefactor/100) * dReal;

   if (Speed)
   {
      ret = tgt_last_fake + dFake;
      tgt_last_fake += dFake;
   }
   else
   {
      ret = tgt_last_fake + dReal;
      tgt_last_fake += dReal;
   }      

   tgt_last_real += dReal;

   return ret;
}
BOOL WINAPI QueryPerformanceCounter_Detour(LARGE_INTEGER *lp)
{
   BOOL ret = QueryPerformanceCounter_Trampoline(lp);

   DWORD nReal = lp->LowPart;
   DWORD dReal = nReal - qpc_last_real;
   DWORD dFake = (increasefactor/100) * dReal;
   if (Speed)
   {
      lp->LowPart = qpc_last_fake + dFake;
      qpc_last_fake += dFake;
   }
   else
   {
      lp->LowPart = qpc_last_fake + dReal;
      qpc_last_fake += dReal;
   }
   gtc_last_real += dReal;

   return ret;
}

BOOL WINAPI DllMain(HINSTANCE hinstModule, DWORD dwReason, LPVOID lpvReserved)

   

     if(dwReason == DLL_PROCESS_ATTACH)
  {
     DetourFunctionWithTrampoline((PBYTE)GetTickCount_Trampoline, (PBYTE)GetTickCount_Detour);
     DetourFunctionWithTrampoline((PBYTE)timeGetTime_Trampoline, (PBYTE)timeGetTime_Detour);
     DetourFunctionWithTrampoline((PBYTE)QueryPerformanceCounter_Trampoline, (PBYTE)QueryPerformanceCounter_Detour);   
     CreateThread(NULL,4096,Thread,NULL,0,NULL);
        return true;
  }
 
  return false;
}


_________________
I'm not perfect , but i'm limited
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri May 31, 2013 11:53 pm    Post subject: Reply with quote

You need to apply the mouse hook outside of the callback. Your current code never sets the hook for it.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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