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 


[C++] Process Speed Hack crashes game

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

Joined: 20 Dec 2009
Posts: 28

PostPosted: Sun Feb 13, 2011 11:28 am    Post subject: [C++] Process Speed Hack crashes game Reply with quote

Hi all, I'm not sure if it's good section, if it isn't, can some Admin/Mod move it to General Programming? Well guys I tried to do a basic Process Speed Hack..yep it work's but at 90% of time it crashes my game..however the Cheat Engine SpeedHack work's always..idk what's wrong. I'm hooking GetTickCount function with Trampoline Detour, my code:

Code:
#include "detours.h"

DWORD   WINAPI GetTickCount_Detour(void);
DETOUR_TRAMPOLINE(DWORD WINAPI GetTickCount_Trampoline(void),GetTickCount);

DWORD WINAPI GetTickCount_Detour()
{
     return GetTickCount_Trampoline();
}


BOOL WINAPI DllMain ( HMODULE hDll, DWORD dwReason, LPVOID lpReserved )
{
   DisableThreadLibraryCalls(hDll);

   if (dwReason == DLL_PROCESS_ATTACH) {
      DetourFunctionWithTrampoline((PBYTE)GetTickCount_Trampoline,(PBYTE)GetTickCount_Detour);
   }

   if (dwReason == DLL_PROCESS_DETACH) {
           DetourRemove((PBYTE)GetTickCount_Trampoline,(PBYTE)GetTickCount_Detour);
   }

   return TRUE;
}


Even if it's empty and returns to original function it crashes my game :/

Update: soz I posted old code
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 475

Joined: 09 May 2003
Posts: 25985
Location: The netherlands

PostPosted: Sun Feb 13, 2011 11:45 am    Post subject: Reply with quote

no idea. Perhaps the detours version you use has trouble with hooking it ?
(gettickcount is not like any other win api. for example it doesn't have the usual hook position in place that most other win apis do)

But I've got no experience with detours. Might as well be a parameter you're giving wrong . (The DETOUR_TRAMPOLINE macro call is correct ?)

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Sun Feb 13, 2011 1:52 pm    Post subject: Reply with quote

Detouring without actually having code inside the hook sometimes has issues and can cause crashes because you aren't actually doing anything. (v1.5 of Detours was known to have this issue.)

Also hooking an API and doing nothing to alter it kinda has no point to be hooked, you haven't actually done anything to manipulate the API so there isn't a reason to hook it.

Keep in mind since you hooked with DetourFunctionWithTrampoline, if you plan to allow unhooking of it you need to use DetourRemoveWithTrampoline.

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

Joined: 20 Dec 2009
Posts: 28

PostPosted: Sun Feb 13, 2011 2:33 pm    Post subject: Reply with quote

Hmm well Im using exactly MS Detours v1.5 :S I don't know why but ppl don't use newest MS Detours v2.1, should I try?

DetourRemoveWithTrampoline and DetourRemove is the same.

Ok so you suggest me to put there some code?

BTW. Dark how did you then made a speed hack in CE? U are unhooking it or what?
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: Sun Feb 13, 2011 3:18 pm    Post subject: Reply with quote

Cheat Engines speedhack hooks GetTickCount and QueryPerformanceCounter. But you have to alter their operation in order to achieve the actual speed hack result. Just hooking onto them doesn't make it happen.

You can view the speed hack source of Cheat Engine here:
http://ce.colddot.nl/browser/Cheat%20Engine%206/speedhack

Most people don't use Detours 2.1 because of the updated EULA. Mainly due to the requirement of detoured.dll having to be released with all packages.

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

Joined: 20 Dec 2009
Posts: 28

PostPosted: Sun Feb 13, 2011 4:07 pm    Post subject: Reply with quote

Thx for help. Yep I know that I need to return fake results, well I found this code on Google:
Code:

DWORD gtc_last_real, gtc_last_fake;

DWORD increasefactor = 200;
DWORD speedenabled = 1;

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

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

   if (speedenabled == 1)
   {
      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;
}


But still crashes game :/
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: Sun Feb 13, 2011 5:12 pm    Post subject: Reply with quote

You'll need to debug then to further diagnose the actual cause of the crash.
_________________
- 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 Gamehacking 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