• Amused
  • Angry
  • Annoyed
  • Awesome
  • Bemused
  • Cocky
  • Cool
  • Crazy
  • Crying
  • Down
  • Drunk
  • Embarrased
  • Enraged
  • Friendly
  • Geeky
  • Godly
  • Happy
  • Hateful
  • Hungry
  • Innocent
  • Meh
  • Piratey
  • Poorly
  • Sad
  • Secret
  • Shy
  • Sneaky
  • Tired
  • Wtf
  • At Work
  • CodenzHub
  • Coding
  • Deejaying
  • Donating
  • Drinking
  • Eating
  • Editing
  • Hacking
  • Hate Mailing
  • Jamin'
  • Lagging
  • Live Streaming
  • Lurking
  • No Status
  • Pawning
  • PC Gaming
  • PS Gaming
  • Raging
  • Reversing
  • Sleeping
  • Steam Gaming
  • Trolling
  • TwitchStreamer
  • Vodka!
  • Watching TV/Movie
  • Xbox Gaming
  • Youtuber
  • Zombies
  • Results 1 to 7 of 7
    1. #1
      Newbie
      Learning to hack games!
       
      Feeling Normal
       
      Chriko2502's Avatar
      Join Date
      Jul 2013
      Posts
      8
      Thanks (-->)
      0
      Thanks (<--)
      0

      DIRECTX MENU - Help

      John Kittz
      Hi there,
      i watched nearly all tut from Fleep and most of all work very fine...
      but with the DIRECTX MENU i have a lot of trouble

      Following code works with win7 to simply draw a filled rectangle with a borderbox.
      But when i inject this code in my directx(9) game on win8. the game crahes...

      because of the created logfile i think the pattern or detour function is the problem.
      i tried to get this work but failed Perhaps someone can help me?!

      Would be the happiest person in the world
      Thx so far
      Chriko2502

      Code:
      #define _CRT_SECURE_NO_WARNINGS 
      
      #include <Windows.h> 
      #include <cstdio> 
      #include <time.h>
      #include <d3d9.h> 
      #include <d3dx9.h>  
      
      const D3DCOLOR fontRed = D3DCOLOR_ARGB(255, 255, 0, 0);
      const D3DCOLOR fontGreen = D3DCOLOR_ARGB(255, 0, 255, 0);
      const D3DCOLOR fontBlue = D3DCOLOR_ARGB(255, 0, 0, 255);
      const D3DCOLOR fontWhite = D3DCOLOR_ARGB(255, 255, 255, 255);
      const D3DCOLOR fontBlack = D3DCOLOR_ARGB(255, 0, 0, 0);
      
      HRESULT __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice); 
      
      typedef HRESULT(__stdcall* EndScene_t)(LPDIRECT3DDEVICE9); 
      EndScene_t pEndScene;  
      
      DWORD WINAPI HookThread();
      void add_log(char* format, ...); 
      void* DetourFunc(PBYTE src, const PBYTE dst, const int len);
      bool bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask);
      DWORD dwFindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask);  
      
      void DrawFilledRectangle(int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9 *d3dDevice);
      void DrawBorderBox(int x, int y, int w, int h, int thickness, D3DCOLOR color, IDirect3DDevice9 *d3dDevice);
      
      HMODULE hModD3D9 = NULL; 
      FARPROC dwEndScene = NULL;
      HANDLE tmpHandle = NULL;
      DWORD* VTableStart = NULL;
      DWORD tempadd = NULL;
      
      BOOL WINAPI DllMain(HINSTANCE hinstDll,DWORD Reason,LPVOID Reserved) {  
      	switch(Reason) {  
      	case DLL_PROCESS_ATTACH:    
      		add_log("==========LOG START=========="); 
      		add_log("DLL Attached");    
      		add_log("Creating Thread...");    
      		tmpHandle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&HookThread, 0, 0, 0);    
      		if (!tmpHandle) {    
      			add_log("ThreadCreation Failed!"); 
      		}    break;  
      	case DLL_PROCESS_DETACH:   
      		add_log("DLL Detached");  
      		add_log("==========LOG END==========\n\n\n");  
      		break;  
      	} 
      	return 1;
      }  
      
      DWORD WINAPI HookThread(void) {
      	add_log("Thread Created");  
      	
      	while (!hModD3D9) {   
      		add_log("Searching d3d9.dll..."); 
      		hModD3D9 = GetModuleHandle(L"d3d9.dll"); 
      		Sleep(100);  
      	}  
      	add_log("Found d3d9.dll: %x !", hModD3D9);  
      
      	tempadd = dwFindPattern((DWORD)hModD3D9, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx");
      	VTableStart = (DWORD*) *(DWORD*)(tempadd+2);  
      
      	dwEndScene = (FARPROC) VTableStart[42]; 
      	pEndScene = (EndScene_t) DetourFunc((PBYTE) dwEndScene, (PBYTE)hkEndScene, 5); 
      
      	while (true)  { 
      		Sleep(500); 
      	} 
      	return 0;
      }  
      
      void add_log(char* format, ...) { 
      	HANDLE filehandle; 
      	DWORD dwReadBytes;  
      	char buffer[2048]; 
      	char writebuffer[2048]; 
      	va_list args;
      	va_start(args, format);
      	vsprintf (buffer, format, args);  
      	filehandle = CreateFile(L"Log.txt", GENERIC_WRITE, 0, 0, OPEN_ALWAYS, 0, 0); 
      	SetFilePointer(filehandle, 0, 0, FILE_END); 
      	char date[18]; 
      	_strdate(date); 
      	date[8] = ' ';  
      	_strtime(date+9);
      	sprintf_s(writebuffer, 2048, "Log Added (%s): %s\r\n", date, buffer);
      	WriteFile(filehandle, writebuffer, strlen(writebuffer), &dwReadBytes, 0);  
      	CloseHandle(filehandle);
      } 
      
       void* DetourFunc(PBYTE src, const PBYTE dst, const int len) { 
      	 DWORD dwback; 
      	 BYTE* jmp = (BYTE*)malloc(len+5); 
      	 VirtualProtect(src, len, PAGE_READWRITE, &dwback); 
      	 memcpy(jmp, src, len); 
      	 jmp += len;  
      	 jmp[0] = 0xE9; 
      	 *(DWORD*)(jmp+1) = (DWORD)(src + len - jmp) - 5; 
      	 src[0] = 0xE9;
      	 *(DWORD*)(src+1) = (DWORD)(dst - src) - 5; 
      	 VirtualProtect(src, len, dwback, &dwback); 
      	 VirtualProtect(jmp-len, len+5, PAGE_EXECUTE_READWRITE, &dwback); 
      	 return (jmp - len); 
       } 
      
      bool bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask) { 
      	for(;*szMask;++szMask,++pData,++bMask)  { 
      		if(*szMask=='x' && *pData!=*bMask )   {  
      			return false;  
      		}  
      	} 
      	return (*szMask) == NULL; 
      }  
      
      DWORD dwFindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask) {  
      	for(DWORD i=0; i < dwLen; i++)  {  
      		if( bDataCompare( (BYTE*)( dwAddress+i ),bMask,szMask) )   { 
      			return (DWORD)(dwAddress+i);   
      		}  
      	} 
      	return 0; 
      }  
      
      HRESULT __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice) { 
      	//D3DRECT rect = {10, 10, 110, 110}; 
      	//pDevice->Clear(1, &rect, D3DCLEAR_TARGET, fontGreen, 0, 0); 
      	
      	DrawFilledRectangle(55, 20, 200, 50, fontBlue, pDevice);
      	DrawBorderBox(55, 20, 200, 50, 4, fontBlack, pDevice);
      
      	return pEndScene(pDevice); 
      } 
      
      
      void DrawFilledRectangle(int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9 *d3dDevice) {
      	D3DRECT rct = {x , y, x + w, y + h};
      	d3dDevice->Clear(1, &rct, D3DCLEAR_TARGET | D3DCLEAR_TARGET, color, 0, 0);
      }
      
      void DrawBorderBox(int x, int y, int w, int h, int thickness, D3DCOLOR color, IDirect3DDevice9 *d3dDevice){
      	DrawFilledRectangle(x, y, w, thickness, color, d3dDevice);
      	DrawFilledRectangle(x, y, thickness, h, color, d3dDevice);
      	DrawFilledRectangle(x + w, y, thickness, h, color, d3dDevice);
      	DrawFilledRectangle(x, y+h, thickness + w, thickness, color, d3dDevice);
      }

    2. #2
      Global Moderator
      give me my colorz back
      FeelsBadMan
       
      Coding
       
      till0sch's Avatar
      Join Date
      Oct 2012
      Location
      Germany.
      Posts
      1,168
      Thanks (-->)
      179
      Thanks (<--)
      340
      Quote Originally Posted by Crypt View Post
      I have never tried using that DetourFunction. Your pattern seems fine, and the way you detour it is fine as well.

      In the C/C++ section I have released a D3D9 Hook, try it out with MS Detours, if that works try it with your DetourFunction.

      - What game are you doing as well?

      EDIT: I just tested your code, and it seems to work just fine! I'm running Windows 7 x64, so Windows 8 might be the problem, shouldn't be since the pattern works on Windows 8 as well. Sure the game are using DirectX 9?
      I got the same code base for detouring EndScene and it works on Windows 7 64 bit for me too. I guess it's Windows 8.

    3. #3
      Kim Kong Trasher
      I don't have status.
       
      Raging
       
      c5's Avatar
      Join Date
      Jul 2012
      Location
      Mankei Iland
      Posts
      1,221
      Thanks (-->)
      97
      Thanks (<--)
      491
      You want to go over the arguments you are passing to the detourfunction. That function is your badboy
      Last edited by c5; 07-21-2013 at 06:07 AM.
      DIRECTX MENU - Help

    4. #4
      Newbie
      Learning to hack games!
       
      Feeling Normal
       
      Chriko2502's Avatar
      Join Date
      Jul 2013
      Posts
      8
      Thanks (-->)
      0
      Thanks (<--)
      0
      Quote Originally Posted by Crypt View Post
      EDIT: I just tested your code, and it seems to work just fine! I'm running Windows 7 x64, so Windows 8 might be the problem, shouldn't be since the pattern works on Windows 8 as well. Sure the game are using DirectX 9?
      Of cause its running fine And Yeah Win8 is the problem, but what to do?!


      I guess it's Windows 8.
      Yeah sure it is But what i have to do to get my filled ractengle with borderbox on win8?

      Perhaps one of u guys can help me? Get it to work on win8 and win7? Game is not choosen yet, only wants to learn how to make a ingame menu for games... Code tested on different directx9 games.... Always working (win7)

    5. #5
      Global Moderator
      give me my colorz back
      FeelsBadMan
       
      Coding
       
      till0sch's Avatar
      Join Date
      Oct 2012
      Location
      Germany.
      Posts
      1,168
      Thanks (-->)
      179
      Thanks (<--)
      340
      How about giving everything out on hooking? Like the address of EndScene etc...

    6. #6
      Newbie
      Learning to hack games!
       
      Feeling Normal
       
      Chriko2502's Avatar
      Join Date
      Jul 2013
      Posts
      8
      Thanks (-->)
      0
      Thanks (<--)
      0
      Hi, it's me again

      i am wondering what i do wrong.... Perhaps u can help me? THX!
      I want to write some stuff in my d3d hack, but the compiler says no -.-

      When i uncomment the "drawtext things" code workes fine With them it will not...
      Code:
      #include <Windows.h> 
      #include <cstdio> 
      #include <time.h>
      #include <iostream>
      #include <d3d9.h> 
      #include <d3dx9.h>  
      
      const D3DCOLOR fontRed = D3DCOLOR_ARGB(255, 255, 0, 0);
      const D3DCOLOR fontGreen = D3DCOLOR_ARGB(255, 0, 255, 0);
      const D3DCOLOR fontBlue = D3DCOLOR_ARGB(255, 0, 0, 255);
      const D3DCOLOR fontWhite = D3DCOLOR_ARGB(255, 255, 255, 255);
      const D3DCOLOR fontBlack = D3DCOLOR_ARGB(255, 0, 0, 0);
      
      HRESULT __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice); 
      
      typedef HRESULT(__stdcall* EndScene_t)(LPDIRECT3DDEVICE9); 
      EndScene_t pEndScene;  
      
      DWORD WINAPI HookThread();
      void CreateLog(char* format, ...); 
      void* DetourFunc(PBYTE src, const PBYTE dst, const int len);
      bool bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask);
      DWORD dwFindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask);  
      
      void DrawFilledRectangle(int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9 *d3dDevice);
      void DrawBorderBox(int x, int y, int w, int h, int thickness, D3DCOLOR color, IDirect3DDevice9 *d3dDevice);
      void DrawFont (int X, int Y, D3DCOLOR Color, char *format, ...);
      
      HMODULE hModD3D9 = NULL; 
      FARPROC dwEndScene = NULL;
      HANDLE tmpHandle = NULL;
      DWORD* VTableStart = NULL;
      DWORD tempadd = NULL;
      
      ID3DXFont *pFont = NULL;
      
      BOOL WINAPI DllMain(HINSTANCE hinstDll,DWORD Reason,LPVOID Reserved) {  
      	switch(Reason) {  
      	case DLL_PROCESS_ATTACH:    
      		CreateLog("==========LOG START=========="); 
      		CreateLog("DLL Attached");    
      		CreateLog("Creating Thread...");    
      		tmpHandle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&HookThread, 0, 0, 0);    
      		if (!tmpHandle) {    
      			CreateLog("ThreadCreation Failed!"); 
      		}    break;  
      	case DLL_PROCESS_DETACH:   
      		CreateLog("DLL Detached");  
      		CreateLog("==========LOG END==========\n\n\n");  
      		break;  
      	} 
      	return 1;
      }  
      
      DWORD WINAPI HookThread(void) {
      	CreateLog("Thread Created");  
      	
      	while (!hModD3D9) {   
      		CreateLog("Searching d3d9.dll..."); 
      		hModD3D9 = GetModuleHandle("d3d9.dll"); 
      		Sleep(100);  
      	}  
      	CreateLog("Found d3d9.dll: %x !", hModD3D9);  
      
      	tempadd = dwFindPattern((DWORD)hModD3D9, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx");
      	CreateLog("PatternFound!"); 
      	VTableStart = (DWORD*) *(DWORD*)(tempadd+2);  
      
      	dwEndScene = (FARPROC) VTableStart[42]; 
      	pEndScene = (EndScene_t) DetourFunc((PBYTE) dwEndScene, (PBYTE)hkEndScene, 5); 
      
      	while (true)  { 
      		Sleep(500); 
      	} 
      	return 0;
      }  
      
      void CreateLog(char* format, ...) { 
      	HANDLE filehandle; 
      	DWORD dwReadBytes;  
      	char buffer[2048]; 
      	char writebuffer[2048]; 
      	va_list args;
      	va_start(args, format);
      	vsprintf (buffer, format, args);  
      	filehandle = CreateFile("Log.txt", GENERIC_WRITE, 0, 0, OPEN_ALWAYS, 0, 0); 
      	SetFilePointer(filehandle, 0, 0, FILE_END); 
      	char date[18]; 
      	_strdate(date); 
      	date[8] = ' ';  
      	_strtime(date+9);
      	sprintf_s(writebuffer, 2048, "Log Added (%s): %s\r\n", date, buffer);
      	WriteFile(filehandle, writebuffer, strlen(writebuffer), &dwReadBytes, 0);  
      	CloseHandle(filehandle);
      } 
      
       void* DetourFunc(PBYTE src, const PBYTE dst, const int len) { 
      	 DWORD dwback; 
      	 BYTE* jmp = (BYTE*)malloc(len+5); 
      	 VirtualProtect(src, len, PAGE_READWRITE, &dwback); 
      	 memcpy(jmp, src, len); 
      	 jmp += len;  
      	 jmp[0] = 0xE9; 
      	 *(DWORD*)(jmp+1) = (DWORD)(src + len - jmp) - 5; 
      	 src[0] = 0xE9;
      	 *(DWORD*)(src+1) = (DWORD)(dst - src) - 5; 
      	 VirtualProtect(src, len, dwback, &dwback); 
      	 VirtualProtect(jmp-len, len+5, PAGE_EXECUTE_READWRITE, &dwback); 
      	 return (jmp - len); 
       } 
      
      bool bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask) { 
      	for(;*szMask;++szMask,++pData,++bMask)  { 
      		if(*szMask=='x' && *pData!=*bMask )   {  
      			return false;  
      		}  
      	} 
      	return (*szMask) == NULL; 
      }  
      
      DWORD dwFindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask) {  
      	for(DWORD i=0; i < dwLen; i++)  {  
      		if( bDataCompare( (BYTE*)( dwAddress+i ),bMask,szMask) )   { 
      			return (DWORD)(dwAddress+i);   
      		}  
      	} 
      	return 0; 
      }  
      
      HRESULT __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice) { 
      	CreateLog("DrawIngameMenu"); 
      	
      	DrawFilledRectangle(55, 20, 200, 50, fontBlue, pDevice);
      	DrawBorderBox(55, 20, 200, 50, 4, fontBlack, pDevice);
      
      	D3DXCreateFont(pDevice, 14, 0, FW_NORMAL, 1, 0, DEFAULT_CHARSET,  OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &pFont );      
      	DrawFont( 300, 50, fontRed, "My first Text");
      
      
      	return pEndScene(pDevice); 
      } 
      
      void DrawFilledRectangle(int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9 *d3dDevice) {
      	CreateLog("DrawFilledRectangle"); 
      	D3DRECT rct = {x , y, x + w, y + h};
      	d3dDevice->Clear(1, &rct, D3DCLEAR_TARGET | D3DCLEAR_TARGET, color, 0, 0);
      }
      
      void DrawBorderBox(int x, int y, int w, int h, int thickness, D3DCOLOR color, IDirect3DDevice9 *d3dDevice){
      	CreateLog("DrawBorderBox");
      	DrawFilledRectangle(x, y, w, thickness, color, d3dDevice);
      	DrawFilledRectangle(x, y, thickness, h, color, d3dDevice);
      	DrawFilledRectangle(x + w, y, thickness, h, color, d3dDevice);
      	DrawFilledRectangle(x, y+h, thickness + w, thickness, color, d3dDevice);
      }
      
      
      void DrawFont (int X, int Y, D3DCOLOR Color, char *format, ...) { 
      	char buffer[256];        
      	va_list args; // deswegen: #include <cstdio>      
      	va_start (args, format);   
      	vsprintf (buffer,format, args);    
      	RECT FontRect = { X, Y, X + 120, Y + 16 };    
      	pFont->DrawText( NULL, buffer, -1, &FontRect, DT_NOCLIP , Color ); // Zeichnen  
      	va_end (args); 
      }
      The Error which came up is
      Code:
       Quelle.obj : error LNK2001: Nicht aufgelöstes externes Symbol "[email protected]".
      Perhaps someone can help? i would be very happy!
      Last edited by Chriko2502; 08-12-2013 at 11:46 AM.

    7. #7
      Newbie
      Learning to hack games!
       
      Feeling Normal
       
      Chriko2502's Avatar
      Join Date
      Jul 2013
      Posts
      8
      Thanks (-->)
      0
      Thanks (<--)
      0
      Cheats'n'Trainers
      Quote Originally Posted by Crypt View Post
      has been answered countless times on this forum, if you took 10 seconds of your life to use the search button.
      Sorry didnt found it u have a link for me?

      Quote Originally Posted by Crypt View Post
      also, why are you calling D3DXCreateFont each frame
      Yeah sure it makes no sense, i only wanted to test it because i am new to this stuff... and i failed
      In final version i'll only will do it once....

    Similar Game Hacker Threads

    1. [Source Code] DirectX D3D Menu Source Code
      By thebassdropper in forum Direct-X, OpenGL
      Replies: 8
      Last Post: 03-27-2017, 06:44 AM
    2. [Tutorial] How to make a DirectX Menu [C++]
      By TastyHorror in forum Tutorials and Snippets
      Replies: 14
      Last Post: 10-19-2016, 04:30 PM
    3. [Help] DirectX menu crash
      By till0sch in forum Direct-X, OpenGL
      Replies: 2
      Last Post: 04-21-2015, 04:11 AM
    4. [Help] Directx menu text
      By Chriko2502 in forum GH Tutorials Help
      Replies: 11
      Last Post: 08-27-2013, 01:24 AM
    5. [Help] DirectX menu
      By wooolly in forum GH Tutorials Help
      Replies: 12
      Last Post: 01-22-2013, 05:32 AM

    Tags for this Thread