I've been working on a speedhack, using Detours 2.1 (because I figure its time to move on). Anyhow the I did a bit of pruning to the detours header file so that I wouldn't have to require or ship detoured.dll with every hack I make....
The problem is its not working. I get no compile time errors, but it looks like as if in runtime there is no entry point for my .dll. At first I thought it might just be CA, but now I see it is failing in multiple applications. So if someone could take a look as to why it may not be loading properly I'd really appreciate it.
Code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
//#pragma comment( "detours.lib" )
#include "detours.h"
DWORD (__stdcall *Real_timeGetTime)(void) = timeGetTime;
BOOL (__stdcall *Real_QPC)(LARGE_INTEGER *lp) = QueryPerformanceCounter;
float factorset = 1.0;//initial value: 1.0
bool speedhack = 0;//initial state: off
void SpeedLoop()
{
while(1)
{
if(GetAsyncKeyState(0x5A))//Z key
{
factorset -= .25;
}
if(GetAsyncKeyState(0x43))//C key
{
factorset += .25;
}
if(GetAsyncKeyState(0x54))//T key
{
if(speedhack)speedhack = 0;//off
else speedhack = 1;//on
}
Sleep(300);
}
}
DWORD My_timeGetTime()
{
DWORD factor = 1.0;
DWORD currentreal = 0.0;
if(speedhack)factor = factorset;
else factor = 1.0;
static DWORD oldtGT = 0;
if(oldtGT==0)
{
oldtGT = Real_timeGetTime();
return oldtGT;
}
currentreal = Real_timeGetTime();
DWORD newret;
newret = currentreal+((currentreal-oldtGT)*(factor-1));
oldtGT=currentreal;
return newret;
}
BOOL My_QPC(LARGE_INTEGER *lp)
{
static __int64 oldfake = 0;
static __int64 oldreal = 0;
__int64 factor = 1;
if(speedhack)factor = factorset;//remember this variable
else factor = 1;
__int64 newvalue;
if( oldfake == 0 || oldreal == 0 )
{
oldfake = lp->QuadPart;
oldreal = lp->QuadPart;
}
newvalue = lp->QuadPart;
newvalue = oldfake + (__int64)((newvalue - oldreal) * (factor-1));
oldreal = lp->QuadPart;
oldfake = newvalue;
lp->QuadPart = newvalue;
return Real_QPC(lp);
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch( dwReason )
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls( hModule );
DetourTransactionBegin();
DetourUpdateThread( GetCurrentThread() );
DetourAttach( &(PVOID&)Real_timeGetTime, My_timeGetTime);
DetourAttach( &(PVOID&)Real_QPC, My_QPC );
DetourTransactionCommit();
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)SpeedLoop, NULL, NULL, NULL);
break;
case DLL_PROCESS_DETACH:
DetourTransactionBegin();
DetourUpdateThread( GetCurrentThread() );
DetourDetach( &(PVOID&)Real_timeGetTime, My_timeGetTime);
DetourDetach( &(PVOID&)Real_QPC, My_QPC );
DetourTransactionCommit();
break;
}
}
Right now it only detours QueryPerformanceCounter and timeGetTime, but I expect to add GetTickCount and implement a better UI, which you guys have already helped me with once I get the damned thing to work. =/