This speed hack seems logical to me and has no compile time errors, So Im guessing it loads correctly. However the speedhack simply does not work. As you can tell its kind of messy. There are parts merely commented out, while I set my focus to another part of the program. For this reason I will describe the program in 3 logical parts. This will make it easy to understand:
1. The Detours. There are three detours set in this program to alter the Windows API functions:
timeGetTime()
QueryPerformanceCounter()
GetTickCount()
2. The Speed Controls. This part adjusts the speed. Do not pay to much attention to the create window thing. Im working on implementing that inside of the hack. Unless ofcourse you want to offer help which I'll gladly except. Focus more on the factors controlling the speed of the detoured functions.
3. The DllMain.
The fault might be here. Maybe it is not loading correctly. To be honest I don't know. All I know is the game does not shut down when I inject it anymore, but perhaps it could be many things.
However it has to be something wrong with one or more these 3 logical sections. For some reason I have a feeling that its the DllMain, because thats where I had a problem last time. I forgot to return true and the program didn't load of initialize properly. not sure =/
[PHP]
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include "detours.h"
/****************NOTES**********************
Title: SpeedHack v.0.1
This is a C++ style conversion of Dark_Byte's Speedhack. Completely recoded, from the
ground up, using a slight aleration of DB's original method, with the Detours Library 2.1
provided by Microsoft, rather then hooking. This is still in aplha testing.
Might be some problems with a smooth dialing of speed due to factor conversions
Also lacks UI, but plan on adding in next compilation.
Thanks to: Hell_Demon & Matrix_NEO006
Credits: why06 (why06mail@gmail.com) for MPGH.net
********************************************/
DWORD (__stdcall *Real_timeGetTime)(void) = ( DWORD(WINAPI *)(void))GetProcAddress(GetModuleHandleA("Kernel32 .dll"),"timeGetTime");
BOOL (__stdcall *Real_QPC)(LARGE_INTEGER *lp) = (BOOL(WINAPI *)(LARGE_INTEGER *))GetProcAddress(GetModuleHandleA("Kernel32.dll") , "QueryPerformanceCounter");
DWORD (WINAPI *Real_GetTickCount)(void) = (DWORD (WINAPI *)(void))GetProcAddress(GetModuleHandleA("Kernel32 .dll"), "GetTickCount");
HWND hBox;
char buf[200] = {0};
float factorset = 2.0;//initial value: 1.0
bool speedhack = 1;//initial state: off
void SpeedLoop()
{
HWND hWnd;
hWnd = (HWND)GetForegroundWindow();
hBox = CreateWindowA("button", "Change Points", WS_VISIBLE | WS_CHILD, 50, 105, 100, 20, hWnd, (HMENU)1, NULL, NULL);
while(1)
{
GetDlgItemTextA(hBox, 4, buf, 256); //get the text or integer that user has entered and store it in buf
factorset = atoi(buf); //macro atoi, to convert the string to an integer,
/*
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(30);
}
}
DWORD My_timeGetTime()
{
float factor = 1.0;
DWORD currentreal = 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 + (DWORD)((currentreal-oldtGT)*(factor-1));
oldtGT=currentreal;
return newret;
}
BOOL My_QPC(LARGE_INTEGER *lp)
{
static __int64 oldfake = 0;
static __int64 oldreal = 0;
float factor = 1.0;
if(speedhack)factor = factorset;//remember this variable
else factor = 1.0;
__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);
}
DWORD My_GetTickCount()
{
float factor = 1.0;
DWORD new_count = 0;
DWORD currentreal = 0;
if(speedhack)factor = factorset;//on
else factor = 1;//off
static DWORD old_count = 0;
if(old_count == 0)
{
old_count = Real_GetTickCount();
return old_count;
}
currentreal = Real_GetTickCount();
new_count = currentreal + (DWORD)(new_count-old_count) * (factor-1);
old_count = currentreal;
return new_count;
}
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 );
DetourAttach( &(PVOID&)Real_GetTickCount, My_GetTickCount);
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 );
DetourDetach(&(PVOID&)Real_GetTickCount, My_GetTickCount);
DetourTransactionCommit();
break;
}
return TRUE;
}
[/PHP]
Its a lot of code, so it may be easier to look at in a compiler. I've been going over it all day myself, so I figure its about time to ask for some help. Windows is definitely not my specialty... ;l (or anything for that matter, but no need to get picky
)