Problem loading .dll

Posts 1–5 of 5 · Page 1 of 1
Problem loading .dll
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. =/
dont know much about dll but i think you should include this too.
Code:
switch( dwReason ) 
	{
		case DLL_PROCESS_ATTACH:
			DisableThreadLibraryCalls( hModule );
			DetourTransactionBegin();
			DetourUpdateThread( GetCurrentThread() );
                        My_timeGetTime();
			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() );
                        My_timeGetTime();
			DetourDetach( &(PVOID&)Real_timeGetTime, My_timeGetTime);
			DetourDetach( &(PVOID&)Real_QPC, My_QPC );
			DetourTransactionCommit();
			break;
	}
no so sure but try it.
omg! Now I notice it! I dont know why this thing didnt give me an error while compiling!

Hehe! Can you see it? I forgot to return true for the DllMain. Silly me
silly you
I will close this now. I'll have many more chances to make a fool of myself before Im done with this. xD
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us