D3D Menu Help

Posts 1–8 of 8 · Page 1 of 1
D3D Menu Help
Hey

Well im tryning to move on from hotkeys to a menu.
Im using hans base.

When i inject into CA, The menu shows up, But when i go ingame i DC.

I can stay in the lobby for as long as i want, But as soon as i go ingame, I DC

Could someone please tell me how to fix this?

Heres the source

Code:
#include "d3dbase.h"
#include "d3dfont9.cpp"

oEndScene	pEndScene;
oReset		pReset;

CD3DFont	*pFont=NULL;


void PreReset(pD3DdeviceX pDevice)
{
	if (pFont) {
		pFont->InvalidateDeviceObjects();
		pFont->DeleteDeviceObjects();
		pFont = NULL;
	}
}

void PostReset(pD3DdeviceX pDevice)
{
	pFont = new CD3DFont("Tahoma", 10, D3DFONT_BOLD);
	if (pFont) {
		pFont->InitDeviceObjects(pDevice);
		pFont->RestoreDeviceObjects();
	}
}

HRESULT WINAPI myReset ( pD3DdeviceX pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters )
{
    PreReset(pDevice);
    return pReset(pDevice, pPresentationParameters);
}

HRESULT WINAPI myEndScene (pD3DdeviceX pDevice)
{
	if (pFont==NULL) 
	    PostReset(pDevice);			// Create font
	else 
		DoMenu(pDevice);
	return pEndScene(pDevice);
}

void DrawBox(pD3DdeviceX pDevice, int x, int y, int w, int h, D3DCOLOR col)
{
	struct {
		float x,y,z,rhw;
		DWORD dwColor;
	} qV[4] = { { (float)x    , (float)(y+h), 0.0f, 0.0f, col},
				{ (float)x    , (float)y    , 0.0f, 0.0f, col},
				{ (float)(x+w), (float)(y+h), 0.0f, 0.0f, col},
				{ (float)(x+w), (float)y    , 0.0f, 0.0f, col} };

	pDevice->SetPixelShader(NULL);
    pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
    pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
    pDevice->SetTexture(0, NULL);
    pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,qV,sizeof(qV[0]));
}

bool bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
	for(;*szMask;++szMask,++pData,++bMask)
		if(*szMask=='x' && *pData!=*bMask)   return 0;
	return (*szMask) == NULL;
}

DWORD FindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask)
{
	for(DWORD i=0; i<dwLen; i++)
		if (bCompare((BYTE*)(dwAddress+i),bMask,szMask))  return (DWORD)(dwAddress+i);
	return 0;
}

void *DetourCreate(BYTE *src, const BYTE *dst, const int len)
{
	BYTE *jmp = (BYTE*)malloc(len+5);
	DWORD dwBack;

	VirtualProtect(src, len, PAGE_EXECUTE_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;
	for (int i=5; i<len; i++)  src[i]=0x90;
	VirtualProtect(src, len, dwBack, &dwBack);
	return (jmp-len);
}

int D3Dinit(void)
{
	DWORD		hD3D, adr, *vtbl;

	// wait for the d3dx dll
	hD3D=0;
	do {
		hD3D = (DWORD)GetModuleHandle(D3Ddllname);
		Sleep(10);
	} while(!hD3D);
	adr = FindPattern(hD3D, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx");
	if (adr) {
		memcpy(&vtbl,(void *)(adr+2),4);
		pReset	  = (oReset)	DetourCreate((PBYTE)vtbl[RESET]   , (PBYTE)myReset   ,5);
 		pEndScene = (oEndScene)	DetourCreate((PBYTE)vtbl[ENDSCENE], (PBYTE)myEndScene,5);
 	}
	CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)HACKthread, NULL, NULL, NULL);
	return 0;
}

BOOL WINAPI DllMain ( HMODULE hDll, DWORD dwReason, LPVOID lpReserved )
{
	DisableThreadLibraryCalls(hDll);
	if (dwReason == DLL_PROCESS_ATTACH) {		
		CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)D3Dinit, NULL, NULL, NULL);
	}
	return TRUE;
}
Can someone please help me?

Thanks,
acid_buRn
i dont no much about D3D menu's so i couldn't tell you whats wrong.. ill copy the code and try mess around with it
i think Hans base is patched...
also wrong addies i think,
I guess you need to update the pDevice addie and make an undetected detour.
You might need to wait for: ClientFX.fxd and CShell.dll as well. it could be detected, but I don't think so.

Also for reset all you need to do is call OnLostDevice on pfont for preReset and OnResetDevice in PostReset. Also you don't include post reset in your reset.

My theory: SInce your reset is failing, the game probably calls reset once you enter the game, but at that time your pfont has already been lost and has not been restored because you failed to do so. For that reason your game crashes.

EDIT: and oh lord you have post reset in your endscene, though I suppose it works. It looks like you just stuck these function any old place. In quite a few places the logic is a tad off. Lastly you might want to draw something, just to see if you can. Finally I'd recommend using a test environment first. I found I was able to debug a lot faster with one. Props to Voltage for that.
I kind of suggest this to everyone having problems with hooking. =\

Remove everything from your hook function and return normally. See if that crashes, if it doesn't, then there is something wrong in your code. From there you can slowly debug everything.

Hmm..
[php]
HRESULT PresentHook(Params)
{
return pPresent(Params); //return normally
}
[/php]
No! No! No1 WINAPI or stdcall. Remember? like u told me you need to specify its stdcall D:
But he did that already. And WINAPI == __stdcall, same thing.
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?