Go Back   UnKnoWnCheaTs - Multiplayer Game Hacks and Cheats > Anti-Cheat Software & Programming > Anti-Cheat Bypass

- Sponsored Advertisement -
http://www.myfpscheats.com/

Welcome to the UnKnoWnCheaTs - Multiplayer Game Hacks and Cheats.
You have to register before you can post and see and access any of the advanced forum features, please click the register link to proceed to the registration form. To start viewing threads or posts, select a forum that you want to visit from the selection below.
Anti-Cheat Bypass
punkbuster vac gameguard esl xray screenshot detection undetected source code tutorial
You are Unregistered, please register to gain Full access.    
Reply
 
Thread Tools

Direct3D9 Interface Hooking
Old 01-23-2007, 03:38 AM   #1


Roverturbo's Avatar

Join Date: Feb 2005
Posts: 5,035
Reputation: 92245
Rep Power: 1108
Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (?)
I am GOD? Hmm K. God
Points: 69,891, Level: 38
Points: 69,891, Level: 38 Points: 69,891, Level: 38 Points: 69,891, Level: 38
Activity: 18.4%
Activity: 18.4% Activity: 18.4% Activity: 18.4%
Last Achievements
Direct3D9 Interface Hooking

I was planning on maybe releasing some hacks but atm i just don't have the time, so i'm releasing one of my undetected d3d9 bases as i have other methods to fall back on.

Reset, EndScene and DrawIndexedPrimitive are already hooked as a example..

I'm sure once you have read the source and understand it, you wont have any problems adding other member functions using d3d9.h as a reference to the device interface.


Code:
//=====================================================================================

// Roverturbo | www.uc-forum.com

#include <windows.h>

#include <d3d9.h>
#pragma comment(lib, "d3d9.lib")

#include <d3dx9.h>
#pragma comment(lib, "d3dx9.lib")

//=====================================================================================

typedef HRESULT (WINAPI* CreateDevice_Prototype)        (LPDIRECT3D9, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE9*);
typedef HRESULT (WINAPI* Reset_Prototype)               (LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
typedef HRESULT (WINAPI* EndScene_Prototype)            (LPDIRECT3DDEVICE9);
typedef HRESULT (WINAPI* DrawIndexedPrimitive_Prototype)(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);

CreateDevice_Prototype         CreateDevice_Pointer         = NULL;
Reset_Prototype                Reset_Pointer                = NULL;
EndScene_Prototype             EndScene_Pointer             = NULL;
DrawIndexedPrimitive_Prototype DrawIndexedPrimitive_Pointer = NULL;

HRESULT WINAPI Direct3DCreate9_VMTable    (VOID);
HRESULT WINAPI CreateDevice_Detour        (LPDIRECT3D9, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE9*);
HRESULT WINAPI Reset_Detour               (LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
HRESULT WINAPI EndScene_Detour            (LPDIRECT3DDEVICE9);
HRESULT WINAPI DrawIndexedPrimitive_Detour(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);

DWORD WINAPI VirtualMethodTableRepatchingLoopToCounterExtensionRepatching(LPVOID);
PDWORD Direct3D_VMTable = NULL;

//=====================================================================================

BOOL WINAPI DllMain(HINSTANCE hinstModule, DWORD dwReason, LPVOID lpvReserved)
{
  if(dwReason == DLL_PROCESS_ATTACH)
  {
    DisableThreadLibraryCalls(hinstModule);

    if(Direct3DCreate9_VMTable() == D3D_OK)
    return TRUE;
  }

  return FALSE;
}

//=====================================================================================

HRESULT WINAPI Direct3DCreate9_VMTable(VOID)
{
  LPDIRECT3D9 Direct3D_Object = Direct3DCreate9(D3D_SDK_VERSION);

  if(Direct3D_Object == NULL)
  return D3DERR_INVALIDCALL;
  
  Direct3D_VMTable = (PDWORD)*(PDWORD)Direct3D_Object;
  Direct3D_Object->Release();

  DWORD dwProtect;

  if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
  {
    *(PDWORD)&CreateDevice_Pointer = Direct3D_VMTable[16];
    *(PDWORD)&Direct3D_VMTable[16] = (DWORD)CreateDevice_Detour;

    if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), dwProtect, &dwProtect) == 0)
    return D3DERR_INVALIDCALL;
  }
  else
  return D3DERR_INVALIDCALL;

  return D3D_OK;
}

//=====================================================================================

HRESULT WINAPI CreateDevice_Detour(LPDIRECT3D9 Direct3D_Object, UINT Adapter, D3DDEVTYPE DeviceType, HWND FocusWindow, 
                    DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* PresentationParameters, 
                    LPDIRECT3DDEVICE9* Returned_Device_Interface)
{
  HRESULT Returned_Result = CreateDevice_Pointer(Direct3D_Object, Adapter, DeviceType, FocusWindow, BehaviorFlags, 
                                              PresentationParameters, Returned_Device_Interface);
   
  DWORD dwProtect;

  if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
  {
    *(PDWORD)&Direct3D_VMTable[16] = *(PDWORD)&CreateDevice_Pointer;
    CreateDevice_Pointer           = NULL;

    if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), dwProtect, &dwProtect) == 0)
    return D3DERR_INVALIDCALL;
  }
  else
  return D3DERR_INVALIDCALL;

  if(Returned_Result == D3D_OK)
  {
    Direct3D_VMTable = (PDWORD)*(PDWORD)*Returned_Device_Interface;

    *(PDWORD)&Reset_Pointer                = (DWORD)Direct3D_VMTable[16];
    *(PDWORD)&EndScene_Pointer             = (DWORD)Direct3D_VMTable[42];
    *(PDWORD)&DrawIndexedPrimitive_Pointer = (DWORD)Direct3D_VMTable[82];

    if(CreateThread(NULL, 0, VirtualMethodTableRepatchingLoopToCounterExtensionRepatching, NULL, 0, NULL) == NULL)
    return D3DERR_INVALIDCALL;
  }
    
  return Returned_Result;
}

//=====================================================================================

HRESULT WINAPI Reset_Detour(LPDIRECT3DDEVICE9 Device_Interface, D3DPRESENT_PARAMETERS* PresentationParameters)
{
  return Reset_Pointer(Device_Interface, PresentationParameters);
}

//=====================================================================================

HRESULT WINAPI EndScene_Detour(LPDIRECT3DDEVICE9 Device_Interface)
{
  return EndScene_Pointer(Device_Interface);
}

//=====================================================================================

HRESULT WINAPI DrawIndexedPrimitive_Detour(LPDIRECT3DDEVICE9 Device_Interface, D3DPRIMITIVETYPE Type, INT BaseIndex, 
                                           UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount)
{
  LPDIRECT3DVERTEXBUFFER9 Stream_Data;
  UINT Offset = 0;
  UINT Stride = 0;

  if(Device_Interface->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
  Stream_Data->Release();

  if(Stride == 0)
  {
  }

  return DrawIndexedPrimitive_Pointer(Device_Interface, Type, BaseIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
}

//=====================================================================================

DWORD WINAPI VirtualMethodTableRepatchingLoopToCounterExtensionRepatching(LPVOID Param)
{
  UNREFERENCED_PARAMETER(Param); 

  while(1)
  {
    Sleep(100);

    *(PDWORD)&Direct3D_VMTable[16] = (DWORD)Reset_Detour;
    *(PDWORD)&Direct3D_VMTable[42] = (DWORD)EndScene_Detour;
    *(PDWORD)&Direct3D_VMTable[82] = (DWORD)DrawIndexedPrimitive_Detour;
  }

  return 1;
}

//=====================================================================================
If you don't know how to use it, then you need to learn some basic C++ and Direct3D. Please don't post my stuff on other sites, you can link to this post only. And by using this source you automatically agree to not use it in any form of pay hack.

Thank you to MSDN and the DirectX Software Development Kit for their useful information.

EDIT:

Updated.

EDIT:

Updated.

EDIT:

Updated.
__________________


I've learned that something constructive comes from every defeat.

Sometimes i say things i shouldn't, and sometimes i say what other people are thinking.

Real programmer's don't document, if it was hard to write, it should be hard to understand.

First learn computer science and all the theory, next develop a programming style, then forget all that and just hack.

Roverturbo is online now

Reply With Quote


Old 01-23-2007, 10:56 PM   #2
Level 3

rahilb's Avatar

Join Date: Jun 2006
Posts: 6
Reputation: 10
Rep Power: 70
rahilb has made posts that are generally average in quality
Is this using that "vTable" I have heard so much about?
rahilb is offline

Reply With Quote

Old 01-24-2007, 08:17 AM   #3
Level 3

silverfish's Avatar

Join Date: Dec 2006
Posts: 436
Reputation: 8917
Rep Power: 160
silverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATS
Points: 9,557, Level: 11
Points: 9,557, Level: 11 Points: 9,557, Level: 11 Points: 9,557, Level: 11
Activity: 4.2%
Activity: 4.2% Activity: 4.2% Activity: 4.2%
Last Achievements
I think so



Code:
lpVtbl
This looks like how he is identifying each hook.

Code:
...
pdwVMTable[41]
...
pdwVMTable[42]
...
pdwVMTable[100]
silverfish is online now

Reply With Quote

Old 01-24-2007, 08:23 AM   #4
Level 3

silverfish's Avatar

Join Date: Dec 2006
Posts: 436
Reputation: 8917
Rep Power: 160
silverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATS
Points: 9,557, Level: 11
Points: 9,557, Level: 11 Points: 9,557, Level: 11 Points: 9,557, Level: 11
Activity: 4.2%
Activity: 4.2% Activity: 4.2% Activity: 4.2%
Last Achievements
Do you help with crashing probs?

I am using this as a new base then I am going to moving all my hacks over to this new project...no more starter kit.

I have compiled it successfully but it crashes right after injection on either my game or the d3d demo binaries that come with the SDK (ShadowVolume.exe). I am merely trying to inject an empty-nohacks-included dlll; just want to see it attach.

What am I missing?
silverfish is online now

Reply With Quote

Old 01-24-2007, 11:38 AM   #5
Administrator

Alkatraz's Avatar

Join Date: Nov 2004
Location: In your darkest Fears you will find me!
Posts: 5,318
Reputation: 62788
Rep Power: 822
Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!Alkatraz has a huge epeen!
Points: 55,278, Level: 35
Points: 55,278, Level: 35 Points: 55,278, Level: 35 Points: 55,278, Level: 35
Activity: 41.4%
Activity: 41.4% Activity: 41.4% Activity: 41.4%
Last Achievements
Award-Showcase
Great job there Rover. One excellent contribution to the community. Hopefully now that you've released 2 and HB's as well. D3D's will start poping up all over the site with luck.
__________________


Sexy Siggy By zero_tolerance





Alkatraz is online now

Reply With Quote

Old 01-24-2007, 11:43 AM   #6
My household appliance is on drugs. Horrible.

s0beit's Avatar

Join Date: Oct 2005
Location: ALWAYS WON NEVER DEFEAT
Posts: 812
Reputation: 70378
Rep Power: 796
s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (1)
Points: 46,529, Level: 32
Points: 46,529, Level: 32 Points: 46,529, Level: 32 Points: 46,529, Level: 32
Activity: 2.2%
Activity: 2.2% Activity: 2.2% Activity: 2.2%
Last Achievements
Quote:
Originally Posted by Alkatraz. View Post
Great job there Rover. One excellent contribution to the community. Hopefully now that you've released 2 and HB's as well. D3D's will start poping up all over the site with luck.
this could definatley use more protection, not just a suggestion

but still again good work, but i would use some other form of table hooking to hook and unhook Direct3DCreate9 *hint*

and definatley unhook CreateDevice *doublehint*
__________________
s0beit is offline

Reply With Quote

Old 01-24-2007, 01:39 PM   #7


Roverturbo's Avatar

Threadstarter
Join Date: Feb 2005
Posts: 5,035
Reputation: 92245
Rep Power: 1108
Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (?)
I am GOD? Hmm K. God
Points: 69,891, Level: 38
Points: 69,891, Level: 38 Points: 69,891, Level: 38 Points: 69,891, Level: 38
Activity: 18.4%
Activity: 18.4% Activity: 18.4% Activity: 18.4%
Last Achievements
Quote:
Originally Posted by gC-Admin View Post
this could definatley use more protection, not just a suggestion

but still again good work, but i would use some other form of table hooking to hook and unhook Direct3DCreate9 *hint*

and definatley unhook CreateDevice *doublehint*
That is upto you, i don't need to change anything... If i wanted to add protection to avoid it being detected, i would of just posted something that makes all Direct3D hacks undetected again...

I have other methods to fall back on and when PB does detect it, i'd put my money on it taking no more than 15 minutes to make it undetected again... That is were my fun comes from...
__________________


I've learned that something constructive comes from every defeat.

Sometimes i say things i shouldn't, and sometimes i say what other people are thinking.

Real programmer's don't document, if it was hard to write, it should be hard to understand.

First learn computer science and all the theory, next develop a programming style, then forget all that and just hack.

Roverturbo is online now

Reply With Quote

Old 01-24-2007, 04:15 PM   #8
My household appliance is on drugs. Horrible.

s0beit's Avatar

Join Date: Oct 2005
Location: ALWAYS WON NEVER DEFEAT
Posts: 812
Reputation: 70378
Rep Power: 796
s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (1)
Points: 46,529, Level: 32
Points: 46,529, Level: 32 Points: 46,529, Level: 32 Points: 46,529, Level: 32
Activity: 2.2%
Activity: 2.2% Activity: 2.2% Activity: 2.2%
Last Achievements
indeed, here is how i restored CreateDevice:
PHP Code:
//global
PVOID pvBackupCreate8 NULL;

//backup [before you change it]
pvBackupCreate8 = ( DWORD* )ulObject[15];

//restore
*( DWORD* )nCreateDevice = *( DWORD* )pvBackupCreate8
needless to say i have alot of work to do on punkbuster, it has really been cracking down recently and the regular evasion techniques wont fly. ( i suspect itll get more difficult in the future )
__________________
s0beit is offline

Reply With Quote

Old 01-24-2007, 06:47 PM   #9


Roverturbo's Avatar

Threadstarter
Join Date: Feb 2005
Posts: 5,035
Reputation: 92245
Rep Power: 1108
Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (?)
I am GOD? Hmm K. God
Points: 69,891, Level: 38
Points: 69,891, Level: 38 Points: 69,891, Level: 38 Points: 69,891, Level: 38
Activity: 18.4%
Activity: 18.4% Activity: 18.4% Activity: 18.4%
Last Achievements
NTAPI is a good place to start when playing with PB.... Bypassing their lame stuff is very feasible this way.
__________________


I've learned that something constructive comes from every defeat.

Sometimes i say things i shouldn't, and sometimes i say what other people are thinking.

Real programmer's don't document, if it was hard to write, it should be hard to understand.

First learn computer science and all the theory, next develop a programming style, then forget all that and just hack.

Roverturbo is online now

Reply With Quote

Old 01-26-2007, 05:20 PM   #10
Level 3

silverfish's Avatar

Join Date: Dec 2006
Posts: 436
Reputation: 8917
Rep Power: 160
silverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATS
Points: 9,557, Level: 11
Points: 9,557, Level: 11 Points: 9,557, Level: 11 Points: 9,557, Level: 11
Activity: 4.2%
Activity: 4.2% Activity: 4.2% Activity: 4.2%
Last Achievements
This is just a simple test to put text on the screen but it keeps crashing with a stack overflow.


Code:
#include "d3d9font.h"
#include <windows.h>
#include <detours.h>
#include <d3d9.h>
#pragma comment(lib, "d3d9.lib")

CD3DFont *pD3DFont;
bool FontCreated=false;
D3DVIEWPORT9 oViewport;

//=====================================================================================


typedef HRESULT (WINAPI* BeginScene_t)(LPDIRECT3DDEVICE9 pDevice);

BeginScene_t pBeginScene;

HRESULT WINAPI nBeginScene(LPDIRECT3DDEVICE9 pDevice)
{
  pDevice->GetViewport(&oViewport);
	return pBeginScene(pDevice);
}


//=====================================================================================


typedef HRESULT (WINAPI* EndScene_t)(LPDIRECT3DDEVICE9 pDevice);

EndScene_t pEndScene;

HRESULT WINAPI nEndScene(LPDIRECT3DDEVICE9 pDevice)
{
	//** Test Text Output **//
	pD3DFont->DrawText(oViewport.Width/2 - 60,oViewport.Height/2,D3DCOLOR_ARGB(255,255,0,0),"D3D Successfully Hooked", D3DFONT_FILTERED);
	//**//
	return pEndScene(pDevice);
}

//=====================================================================================


typedef HRESULT (WINAPI* DrawIndexedPrimitive_t)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE pType, 
											     int iBaseIndex, unsigned int uiMinIndex, unsigned int uiNumVertices, 
												 unsigned int uiStartIndex, unsigned int uiPrimitiveCount);

DrawIndexedPrimitive_t pDrawIndexedPrimitive;

HRESULT WINAPI nDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE pType, int iBaseIndex, 
									 unsigned int uiMinIndex, unsigned int uiNumVertices, unsigned int uiStartIndex, 
									 unsigned int uiPrimitiveCount)
{

  return pDrawIndexedPrimitive(pDevice, pType, iBaseIndex, uiMinIndex, uiNumVertices, uiStartIndex, uiPrimitiveCount);

}


//=====================================================================================


typedef HRESULT (WINAPI* SetStreamSource_t)(LPDIRECT3DDEVICE9 pDevice, unsigned int uiStreamNumber,
											LPDIRECT3DVERTEXBUFFER9 pStreamData, unsigned int uiOffsetInBytes, 
											unsigned int uiStride);

SetStreamSource_t pSetStreamSource;

HRESULT WINAPI nSetStreamSource(LPDIRECT3DDEVICE9 pDevice, unsigned int uiStreamNumber, 
								LPDIRECT3DVERTEXBUFFER9 pStreamData, unsigned int uiOffsetInBytes, 
								unsigned int uiStride)
{

  return pSetStreamSource(pDevice, uiStreamNumber, pStreamData, uiOffsetInBytes, uiStride);

}


//=====================================================================================


typedef HRESULT (WINAPI* CreateDevice_t)(void* pDirect3D, unsigned int uiAdapter, D3DDEVTYPE pDeviceType, 
										 HWND hFocusWindow, unsigned long ulBehaviorFlags, 
										 D3DPRESENT_PARAMETERS* pPresentationParameters, 
										 LPDIRECT3DDEVICE9* ppReturnedDeviceInterface);

CreateDevice_t pCreateDevice;

HRESULT WINAPI nCreateDevice(void* pDirect3D, unsigned int uiAdapter, D3DDEVTYPE pDeviceType, HWND hFocusWindow, 
							 unsigned long ulBehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, 
							 LPDIRECT3DDEVICE9* ppReturnedDeviceInterface)
{

  HRESULT hrReturn = pCreateDevice(pDirect3D, uiAdapter, pDeviceType, hFocusWindow, ulBehaviorFlags, 
	                               pPresentationParameters, ppReturnedDeviceInterface);


  if(hrReturn == D3D_OK)
  {
  
    unsigned long* pInterface = (unsigned long*)*(unsigned long*)*ppReturnedDeviceInterface;


    pBeginScene = (BeginScene_t)DetourFunction((unsigned char*)pInterface[41], 
		                                       (unsigned char*)&nBeginScene);

    pEndScene = (EndScene_t)DetourFunction((unsigned char*)pInterface[42], 
		                                   (unsigned char*)&nEndScene);

    pDrawIndexedPrimitive = (DrawIndexedPrimitive_t)DetourFunction((unsigned char*)pInterface[82], 
		                                                           (unsigned char*)&nDrawIndexedPrimitive);

    pSetStreamSource = (SetStreamSource_t)DetourFunction((unsigned char*)pInterface[100], 
		                                                 (unsigned char*)&nSetStreamSource);

  }
	
  return hrReturn;

}


//=====================================================================================


DETOUR_TRAMPOLINE(LPDIRECT3D9 WINAPI pDirect3DCreate9(unsigned int SDKVersion), Direct3DCreate9);

LPDIRECT3D9 WINAPI nDirect3DCreate9(unsigned int SDKVersion)
{

  LPDIRECT3D9 pDirect3D = pDirect3DCreate9(SDKVersion);

  
  if(pDirect3D != NULL)
  {

    unsigned long* ulObject = (unsigned long*)pDirect3D;
     
	ulObject = (unsigned long*)ulObject[0];

    *(unsigned long*)&pCreateDevice = ulObject[16];


    unsigned long ulProtect;

    VirtualProtect(&ulObject[16], 4, PAGE_EXECUTE_READWRITE, &ulProtect);
	
	*(unsigned long*)&ulObject[16] = (unsigned long)nCreateDevice;
	
    VirtualProtect(&ulObject[16], 4, ulProtect, &ulProtect);
	
  }

  DetourRemove((unsigned char*)pDirect3DCreate9, (unsigned char*)nDirect3DCreate9);

  return pDirect3D;

}


//=====================================================================================


unsigned int APIENTRY DllMain(HMODULE hModule, unsigned long ulReason, void* vpReserved)
{

  if(ulReason == DLL_PROCESS_ATTACH)
  {

    unsigned int uiReturn = DetourFunctionWithTrampoline((unsigned char*)pDirect3DCreate9, 
		                                                 (unsigned char*)nDirect3DCreate9);

    return uiReturn;

  }

  return 0;

}
Anyone else have this problem?
silverfish is online now

Reply With Quote

Old 01-26-2007, 06:04 PM   #11
Level 3

Sparten's Avatar

Join Date: Aug 2004
Posts: 263
Reputation: 7870
Rep Power: 175
Sparten DEFINES UNKNOWNCHEATSSparten DEFINES UNKNOWNCHEATSSparten DEFINES UNKNOWNCHEATSSparten DEFINES UNKNOWNCHEATSSparten DEFINES UNKNOWNCHEATSSparten DEFINES UNKNOWNCHEATSSparten DEFINES UNKNOWNCHEATSSparten DEFINES UNKNOWNCHEATSSparten DEFINES UNKNOWNCHEATSSparten DEFINES UNKNOWNCHEATSSparten DEFINES UNKNOWNCHEATS
Points: 10,154, Level: 12
Points: 10,154, Level: 12 Points: 10,154, Level: 12 Points: 10,154, Level: 12
Activity: 3.2%
Activity: 3.2% Activity: 3.2% Activity: 3.2%
Last Achievements
Quote:
Originally Posted by silverfish View Post
This is just a simple test to put text on the screen but it keeps crashing with a stack overflow.

Code:
HRESULT WINAPI nEndScene(LPDIRECT3DDEVICE9 pDevice)
{
	//** Test Text Output **//
	pD3DFont->DrawText(oViewport.Width/2 - 60,oViewport.Height/2,D3DCOLOR_ARGB(255,255,0,0),"D3D Successfully Hooked", D3DFONT_FILTERED);
	//**//
	return pEndScene(pDevice);
}
Anyone else have this problem?
put in "_asm NOP;" at the start of the function and see if that fixes the problem.
__________________
Who is "General Failure" and why is he reading my harddisk
Sparten is online now

Reply With Quote

Old 01-26-2007, 07:22 PM   #12
Level 3

silverfish's Avatar

Join Date: Dec 2006
Posts: 436
Reputation: 8917
Rep Power: 160
silverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATS
Points: 9,557, Level: 11
Points: 9,557, Level: 11 Points: 9,557, Level: 11 Points: 9,557, Level: 11
Activity: 4.2%
Activity: 4.2% Activity: 4.2% Activity: 4.2%
Last Achievements
Code:
typedef HRESULT (WINAPI* EndScene_t)(LPDIRECT3DDEVICE9 pDevice);

EndScene_t pEndScene;

HRESULT WINAPI nEndScene(LPDIRECT3DDEVICE9 pDevice)
{
	_asm NOP;
	//** Test Text Output **//
	 pD3DFont->DrawText(oViewport.Width/2 - 60,oViewport.Height/2,D3DCOLOR_ARGB(255,255,0,0),"D3D Successfully Hooked", D3DFONT_FILTERED);
	//**//
	return pEndScene(pDevice);
}

Still crashes. I created a new base hook with this to avoid any conflicts. I have all the correct libs referenced...so I don't think I missing anything.
silverfish is online now

Reply With Quote

Old 01-27-2007, 01:06 PM   #13
Level 3

rahilb's Avatar

Join Date: Jun 2006
Posts: 6
Reputation: 10
Rep Power: 70
rahilb has made posts that are generally average in quality
how could I implement in starterkit?
rahilb is offline

Reply With Quote

Old 01-28-2007, 11:29 AM   #14
My household appliance is on drugs. Horrible.

s0beit's Avatar

Join Date: Oct 2005
Location: ALWAYS WON NEVER DEFEAT
Posts: 812
Reputation: 70378
Rep Power: 796
s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (1)
Points: 46,529, Level: 32
Points: 46,529, Level: 32 Points: 46,529, Level: 32 Points: 46,529, Level: 32
Activity: 2.2%
Activity: 2.2% Activity: 2.2% Activity: 2.2%
Last Achievements
@silverfish

try this:
PHP Code:
HRESULT WINAPI nEndScene(LPDIRECT3DDEVICE9 pDevice)
{
    
_asm pushad;
    
//** Test Text Output **//
     
pD3DFont->DrawText(oViewport.Width/60,oViewport.Height/2,D3DCOLOR_ARGB(255,255,0,0),"D3D Successfully Hooked"D3DFONT_FILTERED);
    
//**//
     
_asm popad;
    return 
pEndScene(pDevice);

__________________
s0beit is offline

Reply With Quote

Old 01-29-2007, 07:55 PM   #15
Level 3

silverfish's Avatar

Join Date: Dec 2006
Posts: 436
Reputation: 8917
Rep Power: 160
silverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATS
Points: 9,557, Level: 11
Points: 9,557, Level: 11 Points: 9,557, Level: 11 Points: 9,557, Level: 11
Activity: 4.2%
Activity: 4.2% Activity: 4.2% Activity: 4.2%
Last Achievements
Quote:
Originally Posted by gC-Admin View Post
@silverfish

try this:
PHP Code:
HRESULT WINAPI nEndScene(LPDIRECT3DDEVICE9 pDevice)
{
    
_asm pushad;
    
//** Test Text Output **//
     
pD3DFont->DrawText(oViewport.Width/60,oViewport.Height/2,D3DCOLOR_ARGB(255,255,0,0),"D3D Successfully Hooked"D3DFONT_FILTERED);
    
//**//
     
_asm popad;
    return 
pEndScene(pDevice);


Thanks gc-admin. The problem was actually a flag in VS2005 that jacked it up. I just created a new project and didn't mess with any optimization this time - seems to attached and not crash. Annoying.

Now the new problem of course. I have put various simple D3D print-to-screen goodies in this hook and have yet to see anything show up. Can you take a look and give me the heads up?

Code:
//=====================================================================================

/* Roverturbo | www.unknowncheats.com | www.darkhex.us */

//=====================================================================================

#define _CRT_SECURE_NO_WARNINGS // disable deprecated warnings
#include <windows.h>
#include <detours.h>
#include <d3d9.h>
#include <time.h> // header file for time functions
#include <stdio.h> //header file for (sprintf)
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib") //D3DXCreateLine needs this
#include <d3dx9.h> //header file for crosshair stuff
#include "d3d9font.h" //header file for default d3d font class

// disable annoying warnings
#pragma warning (disable: 4312) //conversion from 'unsigned long' to 'unsigned long *' of greater size
#pragma warning (disable: 4311) //pointer truncation from 'HRESULT
#pragma warning (disable: 4099) //disable debug warning (detours.pdb)
#pragma warning (disable: 4244) //disable conversion from 'DWORD' to 'FLOAT', possible loss of data (crosshair function)

// vars for another simple print text to screen
bool FontCreated = false;
CD3DFont *pD3DFont;

// vars for time and date stuff
char cTimeAndDate[80];
time_t tValue;

// vars for screen resolution stuff
D3DVIEWPORT9 oViewport;
char cResolution[101];

//vars for framerate
float fFps = 0.0f;
float fLastTickCount = 0.0f;
float fCurrentTickCount;
char cFrameRate[50] = {0};

//vars for drawing a simple crosshair
ID3DXLine *pLine;
D3DXVECTOR2 XhairUp       [1];
D3DXVECTOR2 XhairDwn      [1];
D3DXVECTOR2 XhairLft      [1];
D3DXVECTOR2 XhairRgt      [1];
bool DrawXhair = true;


//=====================================================================================


typedef HRESULT (WINAPI* BeginScene_t)(LPDIRECT3DDEVICE9 pDevice);

BeginScene_t pBeginScene;

HRESULT WINAPI nBeginScene(LPDIRECT3DDEVICE9 pDevice)
{
	pDevice->GetViewport(&oViewport); //setup viewport

	D3DXCreateLine(pDevice, &pLine); //setup crosshair

	if(!FontCreated) //setup font for simple text to screen
	{
		FontCreated = true;
		pD3DFont = new CD3DFont("Arial", 8);
		pD3DFont->InitDeviceObjects(pDevice); 
		pD3DFont->RestoreDeviceObjects();
	}
	return pBeginScene(pDevice);
}

//=====================================================================================


typedef HRESULT (WINAPI* EndScene_t)(LPDIRECT3DDEVICE9 pDevice);

EndScene_t pEndScene;

HRESULT WINAPI nEndScene(LPDIRECT3DDEVICE9 pDevice)
{

	fCurrentTickCount = clock() * 0.001f; 
	++fFps;

	if((fCurrentTickCount - fLastTickCount) > 1.0f)
	{
		fLastTickCount = fCurrentTickCount;
		sprintf(cFrameRate, "[ FPS: %d ]", int(fFps)); //print framerate
		fFps = 0;
	}

	sprintf(cResolution, "[ %d x %d ]", oViewport.Width, oViewport.Height); //print screen res

	tValue = time(NULL);
	strftime(cTimeAndDate, sizeof(cTimeAndDate), "[ %a - %b %d - %i:%m %p ]", localtime(&tValue)); //print local time


	//draw crosshair in center of sceen
	if (DrawXhair) 
	{     
		if(pLine) 
		{     
			pLine->SetWidth( 1.0 );// Width
			pLine->SetAntialias( true );// AA
			pLine->SetGLLines( true );// OpenGL Style Lines

			XhairUp[0].x = (oViewport.Width/2); 
			XhairUp[0].y = (oViewport.Height/2); 
			XhairUp[1].x = (oViewport.Width/2); 
			XhairUp[1].y = (oViewport.Height/2) - 8;

			pLine->Begin( );
			pLine->Draw( XhairUp, 2, D3DCOLOR_XRGB( 0, 255, 0 ) );
			pLine->End( );

			XhairDwn[0].x = (oViewport.Width/2); 
			XhairDwn[0].y = (oViewport.Height/2); 
			XhairDwn[1].x = (oViewport.Width/2); 
			XhairDwn[1].y = (oViewport.Height/2) + 8;

			pLine->Begin( );
			pLine->Draw( XhairDwn, 2, D3DCOLOR_XRGB( 0, 255, 0 ) );
			pLine->End( );

			XhairLft[0].x = (oViewport.Width/2); 
			XhairLft[0].y = (oViewport.Height/2); 
			XhairLft[1].x = (oViewport.Width/2) - 8; 
			XhairLft[1].y = (oViewport.Height/2);

			pLine->Begin( );
			pLine->Draw( XhairLft, 2, D3DCOLOR_XRGB( 0, 255, 0 ) );
			pLine->End( );

			XhairRgt[0].x = (oViewport.Width/2); 
			XhairRgt[0].y = (oViewport.Height/2); 
			XhairRgt[1].x = (oViewport.Width/2) + 8; 
			XhairRgt[1].y = (oViewport.Height/2);

			pLine->Begin( );
			pLine->Draw( XhairRgt, 2, D3DCOLOR_XRGB( 0, 255, 0 ) );
			pLine->End( );
		}
	}
	pD3DFont->DrawText(oViewport.Width/2,oViewport.Height/2,D3DCOLOR_ARGB(255,255,0,0),"D3D successfully hooked", D3DFONT_FILTERED); //print in center of screen

	return pEndScene(pDevice);
}


//=====================================================================================


typedef HRESULT (WINAPI* DrawIndexedPrimitive_t)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE pType, 
												 int iBaseIndex, unsigned int uiMinIndex, unsigned int uiNumVertices, 
												 unsigned int uiStartIndex, unsigned int uiPrimitiveCount);

DrawIndexedPrimitive_t pDrawIndexedPrimitive;

HRESULT WINAPI nDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE pType, int iBaseIndex, 
									 unsigned int uiMinIndex, unsigned int uiNumVertices, unsigned int uiStartIndex, 
									 unsigned int uiPrimitiveCount)
{

	return pDrawIndexedPrimitive(pDevice, pType, iBaseIndex, uiMinIndex, uiNumVertices, uiStartIndex, uiPrimitiveCount);

}


//=====================================================================================


typedef HRESULT (WINAPI* SetStreamSource_t)(LPDIRECT3DDEVICE9 pDevice, unsigned int uiStreamNumber,
											LPDIRECT3DVERTEXBUFFER9 pStreamData, unsigned int uiOffsetInBytes, 
											unsigned int uiStride);

SetStreamSource_t pSetStreamSource;

HRESULT WINAPI nSetStreamSource(LPDIRECT3DDEVICE9 pDevice, unsigned int uiStreamNumber, 
								LPDIRECT3DVERTEXBUFFER9 pStreamData, unsigned int uiOffsetInBytes, 
								unsigned int uiStride)
{

	return pSetStreamSource(pDevice, uiStreamNumber, pStreamData, uiOffsetInBytes, uiStride);

}


//=====================================================================================


typedef HRESULT (WINAPI* CreateDevice_t)(void* pDirect3D, unsigned int uiAdapter, D3DDEVTYPE pDeviceType, 
										 HWND hFocusWindow, unsigned long ulBehaviorFlags, 
										 D3DPRESENT_PARAMETERS* pPresentationParameters, 
										 LPDIRECT3DDEVICE9* ppReturnedDeviceInterface);

CreateDevice_t pCreateDevice;

HRESULT WINAPI nCreateDevice(void* pDirect3D, unsigned int uiAdapter, D3DDEVTYPE pDeviceType, HWND hFocusWindow, 
							 unsigned long ulBehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, 
							 LPDIRECT3DDEVICE9* ppReturnedDeviceInterface)
{

	HRESULT hrReturn = pCreateDevice(pDirect3D, uiAdapter, pDeviceType, hFocusWindow, ulBehaviorFlags, 
		pPresentationParameters, ppReturnedDeviceInterface);


	if(hrReturn == D3D_OK)
	{

		unsigned long* pInterface = (unsigned long*)*(unsigned long*)*ppReturnedDeviceInterface;


		pBeginScene = (BeginScene_t)DetourFunction((unsigned char*)pInterface[41], 
			(unsigned char*)&nBeginScene);

		pEndScene = (EndScene_t)DetourFunction((unsigned char*)pInterface[42], 
			(unsigned char*)&nEndScene);

		pDrawIndexedPrimitive = (DrawIndexedPrimitive_t)DetourFunction((unsigned char*)pInterface[82], 
			(unsigned char*)&nDrawIndexedPrimitive);

		pSetStreamSource = (SetStreamSource_t)DetourFunction((unsigned char*)pInterface[100], 
			(unsigned char*)&nSetStreamSource);

	}

	return hrReturn;

}


//=====================================================================================


DETOUR_TRAMPOLINE(LPDIRECT3D9 WINAPI pDirect3DCreate9(unsigned int SDKVersion), Direct3DCreate9);

LPDIRECT3D9 WINAPI nDirect3DCreate9(unsigned int SDKVersion)
{

	LPDIRECT3D9 pDirect3D = pDirect3DCreate9(SDKVersion);


	if(pDirect3D != NULL)
	{

		unsigned long* ulObject = (unsigned long*)pDirect3D;

		ulObject = (unsigned long*)ulObject[0];

		*(unsigned long*)&pCreateDevice = ulObject[16];


		unsigned long ulProtect;

		VirtualProtect(&ulObject[16], 4, PAGE_EXECUTE_READWRITE, &ulProtect);

		*(unsigned long*)&ulObject[16] = (unsigned long)nCreateDevice;

		VirtualProtect(&ulObject[16], 4, ulProtect, &ulProtect);

	}

	DetourRemove((unsigned char*)pDirect3DCreate9, (unsigned char*)nDirect3DCreate9);

	return pDirect3D;

}


//=====================================================================================


unsigned int APIENTRY DllMain(HMODULE hModule, unsigned long ulReason, void* vpReserved)
{

	if(ulReason == DLL_PROCESS_ATTACH)
	{

		unsigned int uiReturn = DetourFunctionWithTrampoline((unsigned char*)pDirect3DCreate9, 
			(unsigned char*)nDirect3DCreate9);

		return uiReturn;

	}

	return 0;

}
silverfish is online now

Reply With Quote

Old 01-31-2007, 02:45 AM   #16


Roverturbo's Avatar

Threadstarter
Join Date: Feb 2005
Posts: 5,035
Reputation: 92245
Rep Power: 1108
Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (?)
I am GOD? Hmm K. God
Points: 69,891, Level: 38
Points: 69,891, Level: 38 Points: 69,891, Level: 38 Points: 69,891, Level: 38
Activity: 18.4%
Activity: 18.4% Activity: 18.4% Activity: 18.4%
Last Achievements
Unless you use your draw text function to print the contents of cFrameRate, cResolution and cTimeAndDate then you wont see anything... You construct the strings using sprintf and strftime but you never use them...

From looking at your additions i see you trying to print text one time... Does the below work?

Code:
pD3DFont->DrawText(oViewport.Width/2,oViewport.Height/2,D3DCOLOR_ARGB(255,255,0,0),"D3D successfully hooked", D3DFONT_FILTERED);
__________________


I've learned that something constructive comes from every defeat.

Sometimes i say things i shouldn't, and sometimes i say what other people are thinking.

Real programmer's don't document, if it was hard to write, it should be hard to understand.

First learn computer science and all the theory, next develop a programming style, then forget all that and just hack.

Roverturbo is online now

Reply With Quote

Old 01-31-2007, 06:02 PM   #17
Level 3

silverfish's Avatar

Join Date: Dec 2006
Posts: 436
Reputation: 8917
Rep Power: 160
silverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATS
Points: 9,557, Level: 11
Points: 9,557, Level: 11 Points: 9,557, Level: 11 Points: 9,557, Level: 11
Activity: 4.2%
Activity: 4.2% Activity: 4.2% Activity: 4.2%
Last Achievements
Code:
pD3DFont->DrawText(oViewport.Width/2,oViewport.Height/2,D3DCOLOR_ARGB(255,255,0,0),"D3D successfully hooked", D3DFONT_FILTERED);
Nothing gets printed to screen.

I was trying the different print-to-screen ways I have done in the past. None are working.
silverfish is online now

Reply With Quote

Old 02-01-2007, 09:43 AM   #18
My household appliance is on drugs. Horrible.

s0beit's Avatar

Join Date: Oct 2005
Location: ALWAYS WON NEVER DEFEAT
Posts: 812
Reputation: 70378
Rep Power: 796
s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!s0beit has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (1)
Points: 46,529, Level: 32
Points: 46,529, Level: 32 Points: 46,529, Level: 32 Points: 46,529, Level: 32
Activity: 2.2%
Activity: 2.2% Activity: 2.2% Activity: 2.2%
Last Achievements
perhaps you have not hooked Reset?

you should hook reset and ensure your text is still working even after reset

also ensure you initiate the font in BeginScene ( once ) you can then re-initate it upon every reset.
__________________
s0beit is offline

Reply With Quote

Old 02-01-2007, 06:00 PM   #19
Level 3

silverfish's Avatar

Join Date: Dec 2006
Posts: 436
Reputation: 8917
Rep Power: 160
silverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATSsilverfish DEFINES UNKNOWNCHEATS
Points: 9,557, Level: 11
Points: 9,557, Level: 11 Points: 9,557, Level: 11 Points: 9,557, Level: 11
Activity: 4.2%
Activity: 4.2% Activity: 4.2% Activity: 4.2%
Last Achievements
I have this already in BeginScene():

Code:
pD3DFont = new CD3DFont("Arial", 8);
pD3DFont->InitDeviceObjects(pDevice); 
pD3DFont->RestoreDeviceObjects();
Hmm...does Roverturbo's hook do some resetting as a part of his detouring that is say, different than Azorbix'x starter kit? This would make sense since the starter kit works simply by setting up the font in BeginScene() and printing it in EndScene() and Roverturbo's requires the Reset() to be hooked as well.

I added this new Reset hook:
Code:
//===================================================================================== Reset


typedef HRESULT (WINAPI* Reset_t)(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS pPresentationParameters);

Reset_t pReset;

HRESULT WINAPI nReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS pPresentationParameters)
{
	pD3DFont = new CD3DFont("Arial", 8);
	pD3DFont->InitDeviceObjects(pDevice); 
	pD3DFont->RestoreDeviceObjects();

	return pReset(pDevice, pPresentationParameters);
}
Then with the rest of the detours

Code:
...
pReset = (Reset_t)DetourFunction((unsigned char*)pInterface[16], (unsigned char*)&nReset);
...
Assuming I have the correct index number, it looks fine to me and compiles, yet still does not print or show anything on screen.


Here is the rest of my source in it's entirety
Code:
//=====================================================================================

/* Roverturbo | www.unknowncheats.com | www.darkhex.us */

//=====================================================================================

#define _CRT_SECURE_NO_WARNINGS // disable deprecated warnings
#include <windows.h>
#include <detours.h>
#include <d3d9.h>
#include <time.h> // header file for time functions
#include <stdio.h> //header file for (sprintf)
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib") //D3DXCreateLine needs this
#include <d3dx9.h> //header file for crosshair stuff
#include "d3d9font.h" //header file for default d3d font class

// disable annoying warnings
#pragma warning (disable: 4312) //conversion from 'unsigned long' to 'unsigned long *' of greater size
#pragma warning (disable: 4311) //pointer truncation from 'HRESULT
#pragma warning (disable: 4099) //disable debug warning (detours.pdb)
#pragma warning (disable: 4244) //disable conversion from 'DWORD' to 'FLOAT', possible loss of data (crosshair function)

// vars for another simple print text to screen
bool FontCreated = false;
CD3DFont *pD3DFont;

// vars for time and date stuff
char cTimeAndDate[80];
time_t tValue;

// vars for screen resolution stuff
D3DVIEWPORT9 oViewport;
char cResolution[101];

//vars for framerate
float fFps = 0.0f;
float fLastTickCount = 0.0f;
float fCurrentTickCount;
char cFrameRate[50] = {0};

//vars for drawing a simple crosshair
ID3DXLine *pLine;
D3DXVECTOR2 XhairUp       [1];
D3DXVECTOR2 XhairDwn      [1];
D3DXVECTOR2 XhairLft      [1];
D3DXVECTOR2 XhairRgt      [1];
bool DrawXhair = true;

//vars for box crosshair
D3DXVECTOR2 CrosshairX[2], CrosshairY[2];
bool drawCross = true;

//vars for clock
int Clock = true;

//===================================================================================== Reset


typedef HRESULT (WINAPI* Reset_t)(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS pPresentationParameters);

Reset_t pReset;

HRESULT WINAPI nReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS pPresentationParameters)
{
	pDevice->GetViewport(&oViewport); //setup viewport

	pD3DFont = new CD3DFont("Arial", 8);
	pD3DFont->InitDeviceObjects(pDevice); 
	pD3DFont->RestoreDeviceObjects();

	return pReset(pDevice, pPresentationParameters);
}

//=====================================================================================


typedef HRESULT (WINAPI* BeginScene_t)(LPDIRECT3DDEVICE9 pDevice);

BeginScene_t pBeginScene;

HRESULT WINAPI nBeginScene(LPDIRECT3DDEVICE9 pDevice)
{
	pDevice->GetViewport(&oViewport); //setup viewport

	D3DXCreateLine(pDevice, &pLine); //setup crosshair

	//setup font for simple text to screen

	pD3DFont = new CD3DFont("Arial", 8);
	pD3DFont->InitDeviceObjects(pDevice); 
	pD3DFont->RestoreDeviceObjects();
	
	//** setup box crosshair **//
	float ScreenCenterX = (float)oViewport.Width / 2 + oViewport.X;
	float ScreenCenterY = (float)oViewport.Height / 2 + oViewport.Y;

	D3DXCreateLine( pDevice, &pLine);
	pLine->SetWidth(4.0);
	pLine->SetAntialias(false);
	pLine->SetGLLines(true);

	CrosshairX[0].x = ScreenCenterX-1-2;
	CrosshairX[0].y = ScreenCenterY;
	CrosshairX[1].x = ScreenCenterX-1+2;
	CrosshairX[1].y = ScreenCenterY;
	CrosshairY[0].x = ScreenCenterX-1;
	CrosshairY[0].y = ScreenCenterY-2;
	CrosshairY[1].x = ScreenCenterX-1;
	CrosshairY[1].y = ScreenCenterY+2;
	//**//

	return pBeginScene(pDevice);
}

//=====================================================================================


typedef HRESULT (WINAPI* EndScene_t)(LPDIRECT3DDEVICE9 pDevice);

EndScene_t pEndScene;

HRESULT WINAPI nEndScene(LPDIRECT3DDEVICE9 pDevice)
{
	fCurrentTickCount = clock() * 0.001f; 
	++fFps;

	if((fCurrentTickCount - fLastTickCount) > 1.0f)
	{
		fLastTickCount = fCurrentTickCount;
		sprintf(cFrameRate, "[ FPS: %d ]", int(fFps)); //print framerate
		fFps = 0;
	}

	sprintf(cResolution, "[ %d x %d ]", oViewport.Width, oViewport.Height); //print screen res

	tValue = time(NULL);
	strftime(cTimeAndDate, sizeof(cTimeAndDate), "[ %a - %b %d - %i:%m %p ]", localtime(&tValue)); //print local time


	//draw crosshair in center of sceen
	if (DrawXhair) 
	{     
		if(pLine) 
		{     
			pLine->SetWidth( 1.0 );// Width
			pLine->SetAntialias( true );// AA
			pLine->SetGLLines( true );// OpenGL Style Lines

			XhairUp[0].x = (oViewport.Width/2); 
			XhairUp[0].y = (oViewport.Height/2); 
			XhairUp[1].x = (oViewport.Width/2); 
			XhairUp[1].y = (oViewport.Height/2) - 8;

			pLine->Begin( );
			pLine->Draw( XhairUp, 2, D3DCOLOR_XRGB( 0, 255, 0 ) );
			pLine->End( );

			XhairDwn[0].x = (oViewport.Width/2); 
			XhairDwn[0].y = (oViewport.Height/2); 
			XhairDwn[1].x = (oViewport.Width/2); 
			XhairDwn[1].y = (oViewport.Height/2) + 8;

			pLine->Begin( );
			pLine->Draw( XhairDwn, 2, D3DCOLOR_XRGB( 0, 255, 0 ) );
			pLine->End( );

			XhairLft[0].x = (oViewport.Width/2); 
			XhairLft[0].y = (oViewport.Height/2); 
			XhairLft[1].x = (oViewport.Width/2) - 8; 
			XhairLft[1].y = (oViewport.Height/2);

			pLine->Begin( );
			pLine->Draw( XhairLft, 2, D3DCOLOR_XRGB( 0, 255, 0 ) );
			pLine->End( );

			XhairRgt[0].x = (oViewport.Width/2); 
			XhairRgt[0].y = (oViewport.Height/2); 
			XhairRgt[1].x = (oViewport.Width/2) + 8; 
			XhairRgt[1].y = (oViewport.Height/2);

			pLine->Begin( );
			pLine->Draw( XhairRgt, 2, D3DCOLOR_XRGB( 0, 255, 0 ) );
			pLine->End( );
		}

		// Crosshair Toggle
		if(GetAsyncKeyState(VK_NUMPAD0)&1)
		{
			drawCross=!drawCross;
		}
		if(drawCross)
		{
			pLine->Begin();
			pLine->Draw(CrosshairX,  2, D3DCOLOR_RGBA(0, 255, 0, 255)); 
			pLine->End();
			pLine->Begin();
			pLine->Draw(CrosshairY,  2, D3DCOLOR_RGBA(0, 255, 0, 255)); 
			pLine->End();
		}
		//**//

		//**Clock**//
		if(GetAsyncKeyState(VK_MULTIPLY)&1)
		{
			Clock=!Clock;
		}
		char Timestruct[16] = "hh':'mm':'ss tt"; 
		char TimeString[25];                        
		GetTimeFormat(NULL,NULL,NULL,NULL,Timestruct,15);
		sprintf(TimeString,"[ %s ]",Timestruct); 
		if(Clock) 
		{
			pD3DFont->DrawText(20,50,D3DCOLOR_ARGB(255,255,255,255),TimeString,D3DFONT_FILTERED);
		}
		//**//
	}
	
	pD3DFont->DrawText(oViewport.Width/2,oViewport.Height/2,D3DCOLOR_ARGB(255,255,0,0),"D3D Successfully hooked", D3DFONT_FILTERED); //print in center of screen

	return pEndScene(pDevice);
}


//=====================================================================================

typedef HRESULT (WINAPI* DrawIndexedPrimitive_t)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE pType, int iBaseIndex, unsigned int uiMinIndex, unsigned int uiNumVertices, unsigned int uiStartIndex, unsigned int uiPrimitiveCount);

DrawIndexedPrimitive_t pDrawIndexedPrimitive;

HRESULT WINAPI nDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE pType, int iBaseIndex, 
									 unsigned int uiMinIndex, unsigned int uiNumVertices, unsigned int uiStartIndex, 
									 unsigned int uiPrimitiveCount)
{

	return pDrawIndexedPrimitive(pDevice, pType, iBaseIndex, uiMinIndex, uiNumVertices, uiStartIndex, uiPrimitiveCount);

}


//=====================================================================================

typedef HRESULT (WINAPI* SetStreamSource_t)(LPDIRECT3DDEVICE9 pDevice, unsigned int uiStreamNumber,	LPDIRECT3DVERTEXBUFFER9 pStreamData, unsigned int uiOffsetInBytes, unsigned int uiStride);

SetStreamSource_t pSetStreamSource;

HRESULT WINAPI nSetStreamSource(LPDIRECT3DDEVICE9 pDevice, unsigned int uiStreamNumber, 
								LPDIRECT3DVERTEXBUFFER9 pStreamData, unsigned int uiOffsetInBytes, 
								unsigned int uiStride)
{

	return pSetStreamSource(pDevice, uiStreamNumber, pStreamData, uiOffsetInBytes, uiStride);

}


//=====================================================================================


typedef HRESULT (WINAPI* CreateDevice_t)(void* pDirect3D, unsigned int uiAdapter, D3DDEVTYPE pDeviceType, 
										 HWND hFocusWindow, unsigned long ulBehaviorFlags, 
										 D3DPRESENT_PARAMETERS* pPresentationParameters, 
										 LPDIRECT3DDEVICE9* ppReturnedDeviceInterface);

CreateDevice_t pCreateDevice;

HRESULT WINAPI nCreateDevice(void* pDirect3D, unsigned int uiAdapter, D3DDEVTYPE pDeviceType, HWND hFocusWindow, 
							 unsigned long ulBehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, 
							 LPDIRECT3DDEVICE9* ppReturnedDeviceInterface)
{

	HRESULT hrReturn = pCreateDevice(pDirect3D, uiAdapter, pDeviceType, hFocusWindow, ulBehaviorFlags, 
		pPresentationParameters, ppReturnedDeviceInterface);


	if(hrReturn == D3D_OK)
	{

		unsigned long* pInterface = (unsigned long*)*(unsigned long*)*ppReturnedDeviceInterface;

		pReset = (Reset_t)DetourFunction((unsigned char*)pInterface[16], (unsigned char*)&nReset);

		pBeginScene = (BeginScene_t)DetourFunction((unsigned char*)pInterface[41], (unsigned char*)&nBeginScene);

		pEndScene = (EndScene_t)DetourFunction((unsigned char*)pInterface[42], (unsigned char*)&nEndScene);

		pDrawIndexedPrimitive = (DrawIndexedPrimitive_t)DetourFunction((unsigned char*)pInterface[82], (unsigned char*)&nDrawIndexedPrimitive);

		pSetStreamSource = (SetStreamSource_t)DetourFunction((unsigned char*)pInterface[100], (unsigned char*)&nSetStreamSource);

	}

	return hrReturn;

}


//=====================================================================================


DETOUR_TRAMPOLINE(LPDIRECT3D9 WINAPI pDirect3DCreate9(unsigned int SDKVersion), Direct3DCreate9);

LPDIRECT3D9 WINAPI nDirect3DCreate9(unsigned int SDKVersion)
{

	LPDIRECT3D9 pDirect3D = pDirect3DCreate9(SDKVersion);


	if(pDirect3D != NULL)
	{

		unsigned long* ulObject = (unsigned long*)pDirect3D;

		ulObject = (unsigned long*)ulObject[0];

		*(unsigned long*)&pCreateDevice = ulObject[16];


		unsigned long ulProtect;

		VirtualProtect(&ulObject[16], 4, PAGE_EXECUTE_READWRITE, &ulProtect);

		*(unsigned long*)&ulObject[16] = (unsigned long)nCreateDevice;

		VirtualProtect(&ulObject[16], 4, ulProtect, &ulProtect);

	}

	DetourRemove((unsigned char*)pDirect3DCreate9, (unsigned char*)nDirect3DCreate9);

	return pDirect3D;

}


//=====================================================================================


unsigned int APIENTRY DllMain(HMODULE hModule, unsigned long ulReason, void* vpReserved)
{

	if(ulReason == DLL_PROCESS_ATTACH)
	{

		unsigned int uiReturn = DetourFunctionWithTrampoline((unsigned char*)pDirect3DCreate9, 
			(unsigned char*)nDirect3DCreate9);

		return uiReturn;

	}

	return 0;

}

Last edited by silverfish; 02-01-2007 at 10:52 PM.
silverfish is online now

Reply With Quote

Old 02-01-2007, 10:52 PM   #20


Roverturbo's Avatar

Threadstarter
Join Date: Feb 2005
Posts: 5,035
Reputation: 92245
Rep Power: 1108
Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (?)
I am GOD? Hmm K. God
Points: 69,891, Level: 38
Points: 69,891, Level: 38 Points: 69,891, Level: 38 Points: 69,891, Level: 38
Activity: 18.4%
Activity: 18.4% Activity: 18.4% Activity: 18.4%
Last Achievements
Hmm, you shouldn't need to hook reset to get any font to work...

The reason most people hook reset is because when you press alt + tab to minimize the game window all video memory resources are released and the device is reset.

Calling the ID3DXFONT interface functions OnLostDevice and OnResetDevice in reset will re-acquire resources when the window is restored stopping a lock up occurring.
__________________


I've learned that something constructive comes from every defeat.

Sometimes i say things i shouldn't, and sometimes i say what other people are thinking.

Real programmer's don't document, if it was hard to write, it should be hard to understand.

First learn computer science and all the theory, next develop a programming style, then forget all that and just hack.

Roverturbo is online now

Reply With Quote
Reply  

  • Submit Thread to Digg
  • Submit Thread to del.icio.us
  • Submit Thread to StumbleUpon
  • Submit Thread to Google
  • Submit Thread to Facebook
  • Submit Thread to My Yahoo!
  • Submit Thread to MySpace
  • Submit Thread to Twitter
  • Submit Thread to Reddit



Tags
direct3d9, hooking, interface
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT +1. The time now is 03:32 PM.