Solved Draw D3D Box

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

zoratz

Jr.Coder
Dank Tier Donator
Nobleman
Jul 22, 2013
81
838
2
Hey guys, i'm trying to draw a D3D Box with a text in CS:GO using the following code. It works well on game menu, but when I enter a new game the box disappears and only text remains. I've tryed commenting out m_Line->Release(); but had no success (i don't actually thing that changes something related to working, but does only its job).

What am I doing wrong here?

I must also say that when I change fullscreen mode or window mode or minimize the game, when it comes back, it comes all messed up (really, almost nothing appears). I read a lot about it, and I think it's because i'm not releasing the Font or the Line, something like that (i've not understood that properly yet).

PS.: Since i'm still learning DirectX, I wrapped up everything in one file to get a better view of what's happenning.

C++:
#define _CRT_SECURE_NO_WARNINGS

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

#define HOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)m##func)


typedef HRESULT(WINAPI* tEndScene)(LPDIRECT3DDEVICE9 pDevice);
tEndScene oEndScene;

using namespace std;

RECT m_Rect;

bool bDrawElements = false;

const int ES = 0;
const int DIP = 1;
const int SSS = 2;

struct D3DVERTEX
{
	FLOAT x, y, z, rhw;
	DWORD dwColour;
};

LPDIRECT3DDEVICE9 pd3dDevice;

ID3DXFont* dx_Font = NULL;
ID3DXLine* m_Line = NULL;

void DrawRect(int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9* pDevice)
{
	D3DXCreateLine(pDevice, &m_Line);
	D3DXVECTOR2 vLine[2];

	m_Line->SetWidth(w);
	m_Line->SetAntialias(false);
	m_Line->SetGLLines(true);

	vLine[0].x = x + w / 2;
	vLine[0].y = y;
	vLine[1].x = x + w / 2;
	vLine[1].y = y + h;

	m_Line->Begin();
	m_Line->Draw(vLine, 2, color);
	m_Line->End();
	m_Line->Release();
}

HRESULT WINAPI mEndScene(LPDIRECT3DDEVICE9 pDevice)
{
	if (GetAsyncKeyState(VK_INSERT) & 1)
	{
		bDrawElements = !bDrawElements;
	}
	
	if (dx_Font == NULL)
		D3DXCreateFont(pDevice, 15, 0, FW_BOLD, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Verdana", &dx_Font);

	char status[32];

	m_Rect.left = 50;
	m_Rect.top = 50;

	if (bDrawElements)
	{
		strcpy(status, "Enabled");
		DrawRect(50, 50, 100, 100, D3DCOLOR_ARGB(100, 0, 0, 255), pDevice);
	}
	else
	{
		strcpy(status, "Disabled");
	}

	dx_Font->DrawTextA(NULL, status, strlen(status), &m_Rect, DT_NOCLIP, D3DCOLOR_XRGB(0, 0, 255));

	return oEndScene(pDevice);
}

LRESULT CALLBACK MsgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

int WINAPI DllThread()
{
	DWORD table[3] = { 0 };

	IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION);
	if (!pD3D)
		return 0;

	D3DPRESENT_PARAMETERS d3dpp = { 0 };
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = GetForegroundWindow();
	d3dpp.Windowed = TRUE;

	IDirect3DDevice9* pDevice = nullptr;

	pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dpp.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice);
	if (!pDevice)
	{
		pD3D->Release();
		return 0;
	}

	DWORD* pVTable = (DWORD*)pDevice;
	pVTable = (DWORD*)pVTable[0];

	table[ES] = pVTable[42];
	table[DIP] = pVTable[82];
	table[SSS] = pVTable[100];

	HOOK(EndScene, table[ES]);

	pDevice->Release();
	pD3D->Release();

	return 0;
}

BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID lpReserved)
{
	switch (Reason)
	{
	case DLL_PROCESS_ATTACH:
		CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)DllThread, NULL, NULL, NULL);
		break;
	}
	return true;
}
 

GAFO666

Hacker
Meme Tier VIP
Aug 19, 2012
520
3,188
23
the drawing function doesnt seem to be the problem here.
hmmm create a backup and cleanup and draw between it inside of the endscene.


backup:
- save the texture of the game
- save the pixelshader of the game
- create a stateblock casing all (D3DSBT_ALL)

//draw ......

cleanup:
- set the stored texture
- set the stored shader
- apply and release the stateblock


thats how i fixed csgo issues with e.g. circles
 

zoratz

Jr.Coder
Dank Tier Donator
Nobleman
Jul 22, 2013
81
838
2
I changed it as you advised, but had no effect...
Is the first parameter of Get/SetTexture = NULL?

---- EDIT -----

I just tested with normal XRGB to see if was something with Alpha value, but it didn't work as well..

I also realised that when I start the game the box appears ok, when I enter a game it desappears for good and forever, if I return to the game menu after entering a match, it does not comes back again.
So it must be that it's not getting some render something, which i have no ideia what is...

C++:
IDirect3DBaseTexture9* pTexture;
	IDirect3DPixelShader9* pPixelShader;
	IDirect3DStateBlock9* pStateBlock;
	pDevice->GetTexture(NULL, &pTexture);
	pDevice->GetPixelShader(&pPixelShader);
	pDevice->CreateStateBlock(D3DSBT_ALL, &pStateBlock);

	if (bDrawElements)
	{
		strcpy(status, "Enabled");
		DrawRect(50, 50, 100, 100, D3DCOLOR_ARGB(100, 0, 0, 255), pDevice);
	}
	else
	{
		strcpy(status, "Disabled");
	}

	dx_Font->DrawTextA(NULL, status, strlen(status), &m_Rect, DT_NOCLIP, D3DCOLOR_XRGB(0, 0, 255));

	pDevice->SetTexture(NULL, pTexture);
	pDevice->SetPixelShader(pPixelShader);
	pStateBlock->Apply();
	pStateBlock->Release();
 
Last edited:

zoratz

Jr.Coder
Dank Tier Donator
Nobleman
Jul 22, 2013
81
838
2
Well, i've found out that it isn't layer problem (z axys)...

pDevice->Clear function with Z axys = 0 works perfectly, however there's no way to make alpha blending boxes or lines....

Draw line is still going away when entering a new match and dont come back..
 

mambda

headass
Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
2,298
37,938
269
I dont use d3d in cs, but try hooking Reset, i recall something aobut that being important, try googling about it
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods