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 


Ms detours and Direct3DCreate9

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
jacekPUT
How do I cheat?
Reputation: 0

Joined: 02 Oct 2009
Posts: 1

PostPosted: Fri Oct 02, 2009 5:59 pm    Post subject: Ms detours and Direct3DCreate9 Reply with quote

I am trying to replace original Direct3DCreate9 function in an application with a piece of code provided by me. I read an article sticked at this site (i cannot post links) saying how to do it using Ms Detours 1.5, but i want to use version 2.1.
The task seems simple and i prepared this short piece of code:

Code:


IDirect3D9* iDirect3D9;

//extern "C" {
static IDirect3D9* (* RealDirect3DCreate9)(UINT) = Direct3DCreate9;
//};

IDirect3D9 * MyDirect3DCreate9(UINT SDKVersion){
   return NULL;
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                )
{

   LONG DetourAttachResult;
   LONG DetourTransactionCommitResult;

   switch (ul_reason_for_call)
   {
   case DLL_PROCESS_ATTACH:

      DetourRestoreAfterWith();
      DetourTransactionBegin();
      DetourUpdateThread(GetCurrentThread());

      DetourAttachResult = DetourAttach(&(PVOID&)RealDirect3DCreate9, MyDirect3DCreate9);

      switch(DetourAttachResult){
         case NO_ERROR:
            std::cout << "Detouring Direct3DCreate9 successful" << std::endl;
            break;
         case ERROR_INVALID_BLOCK:
            std::cout << "Detouring Direct3DCreate9 UNSUCCESSFUL: ERROR_INVALID_BLOCK" << std::endl;
            break;
         case ERROR_INVALID_HANDLE:
            std::cout << "Detouring Direct3DCreate9 UNSUCCESSFUL: ERROR_INVALID_HANDLE" << std::endl;
            break;
         case ERROR_INVALID_OPERATION:
            std::cout << "Detouring Direct3DCreate9 UNSUCCESSFUL: ERROR_INVALID_OPERATION" << std::endl;
            break;
         case ERROR_NOT_ENOUGH_MEMORY:
            std::cout << "Detouring Direct3DCreate9 UNSUCCESSFUL: ERROR_NOT_ENOUGH_MEMORY" << std::endl;
            break;
      }

      DetourTransactionCommitResult = DetourTransactionCommit();

      std::cout << "After DetourTransactionCommit" << std::endl;
      break;
   case DLL_THREAD_ATTACH:
   case DLL_THREAD_DETACH:
   case DLL_PROCESS_DETACH:
      break;
   }
   return TRUE;
}



I know that MyDirect3DCreate9 certainly does not get invoked.

When i use the same "pattern" to replace timeGetTime function, everything works fine. I probably don't know or don't understand sth concerning hooking using Detours or way the Dx gets loaded. I'd appreciate if someone could tell me why this piece of code does not work as I'd wish...

Thanks

And maybe some of you know if i could catch WPF renderinf calls, as it uses Dx?
Back to top
View user's profile Send private message
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