Solved D3D Text with injectable dll

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat
Status
Not open for further replies.

KiNG Jaydo

Newbie
Full Member
Jan 21, 2015
29
158
1
So im attempting to make a injectable menu for a game (eg csgo.). I've looked over both the ESP and Crosshair tutorials and was just wondering, what is the best way to draw text in a static location on the screen? I dont want to use an overlay as I want users to be able to run the game in fullscreen but I'm clueless as to how to use D3D in anyway. Any help is much appreciated!

PS: C# or C++ is fine. Preferred C++.
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,746
40,528
316
From where are you actually drawing this? From EndScene/Present? And do you create VertexBuffers over and over again?
I'd just use DrawPrimitiveUP and something like this:

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

#define CUSTOM_FVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)

void DrawFilledRect(int X, int Y, int Width, int Height, DWORD dwColour, IDirect3DDevice9* pDevice)
{
	
	D3DVERTEX qV[4] = 
	{
		{ 
			(float)X, (float)(Y + Height), 0.0f, 1.0f, dwColour
		},
		{ 
			(float)X, (float)Y, 0.0f, 1.0f, dwColour
		},
		{ 
			(float)(X + Width), (float)(Y + Height), 0.0f, 1.0f, dwColour
		},
		{ 
			(float)(X + Width), (float)Y, 0.0f, 1.0f, dwColour
		}
	};

	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	pDevice->SetPixelShader(nullptr);

	pDevice->SetFVF(CUSTOM_FVF);
	pDevice->SetTexture(0, nullptr);
	pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, qV, sizeof(D3DVERTEX));
}
You better save those renderstates before setting your own of course. I was too lazy to do so.
 

till0sch

Respected Hacker
Dank Tier VIP
Dank Tier Donator
Oct 14, 2012
1,104
12,593
51
look up on hooking d3d if you don't want an overlay
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,746
40,528
316
Look up d3d hooking (d3d9 or d3d11)?
Hook d3d.
Draw your text.
 

KiNG Jaydo

Newbie
Full Member
Jan 21, 2015
29
158
1
Thanks both of you! Got it working perfectly the way I want it to. (also thanks to fleep). Quick question, using a similar method to fleeps DrawFilledRect, how can i draw a gradient rectangle? is that possible with D3D?
 

KiNG Jaydo

Newbie
Full Member
Jan 21, 2015
29
158
1


It seems to have messed around with the games buffer..
This is my code, I'm just not sure if I'm doing it right :/ (ps i know im making a triangle, but i didn't think it'd really matter.. I'm just trying to wrap my head around D3D's APi)
 
Last edited:

KiNG Jaydo

Newbie
Full Member
Jan 21, 2015
29
158
1
Вroihon;39307 said:
From where are you actually drawing this? From EndScene/Present? And do you create VertexBuffers over and over again?
I'd just use DrawPrimitiveUP and something like this:

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

#define CUSTOM_FVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)

void DrawFilledRect(int X, int Y, int Width, int Height, DWORD dwColour, IDirect3DDevice9* pDevice)
{
	
	D3DVERTEX qV[4] = 
	{
		{ 
			(float)X, (float)(Y + Height), 0.0f, 1.0f, dwColour
		},
		{ 
			(float)X, (float)Y, 0.0f, 1.0f, dwColour
		},
		{ 
			(float)(X + Width), (float)(Y + Height), 0.0f, 1.0f, dwColour
		},
		{ 
			(float)(X + Width), (float)Y, 0.0f, 1.0f, dwColour
		}
	};

	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	pDevice->SetPixelShader(nullptr);

	pDevice->SetFVF(CUSTOM_FVF);
	pDevice->SetTexture(0, nullptr);
	pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, qV, sizeof(D3DVERTEX));
}
You better save those renderstates before setting your own of course. I was too lazy to do so.

That worked fairly flawlessly (with a bit of tweeking). I was able to get a gradient up but for some reason the gradient disappears when the mouse is on the screen in game; as soon as i take my mouse off onto another window it reappears! But the text remains. So i am confused.

Thank you for your suggestions!

- and yes it is called on the EndScene function
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,746
40,528
316
That worked fairly flawlessly (with a bit of tweeking). I was able to get a gradient up but for some reason the gradient disappears when the mouse is on the screen in game; as soon as i take my mouse off onto another window it reappears! But the text remains. So i am confused.

Thank you for your suggestions!

- and yes it is called on the EndScene function
Ye, I just made the func for once colour.
Anyway my guess is that the dis.-/reappearing is caused by fcked up renderstates.
Try with saving/restoring them properly. Of course only do the saving/restoring once and not for each object you're drawing.

C++:
	DWORD OldAlpha, OldDest, OldSrc, OldCull;
	IDirect3DPixelShader9* pOldShader;
	pDevice->GetRenderState(D3DRS_ALPHABLENDENABLE, &OldAlpha);
	pDevice->GetRenderState(D3DRS_DESTBLEND, &OldDest);
	pDevice->GetRenderState(D3DRS_SRCBLEND, &OldSrc);
	pDevice->GetRenderState(D3DRS_CULLMODE, &OldCull);
	pDevice->GetPixelShader(&pOldShader);
	
	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	pDevice->SetPixelShader(nullptr);

	pDevice->SetFVF(CUSTOM_FVF);
	pDevice->SetTexture(0, nullptr);
	pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, qV, sizeof(D3DVERTEX));

	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, OldAlpha);
	pDevice->SetRenderState(D3DRS_DESTBLEND, OldDest);
	pDevice->SetRenderState(D3DRS_SRCBLEND, OldSrc);
	pDevice->SetRenderState(D3DRS_CULLMODE, OldCull);
	pDevice->SetPixelShader(pOldShader);
 

KiNG Jaydo

Newbie
Full Member
Jan 21, 2015
29
158
1
Вroihon;39309 said:
Ye, I just made the func for once colour.
Anyway my guess is that the dis.-/reappearing is caused by fcked up renderstates.
Try with saving/restoring them properly. Of course only do the saving/restoring once and not for each object you're drawing.

C++:
	DWORD OldAlpha, OldDest, OldSrc, OldCull;
	IDirect3DPixelShader9* pOldShader;
	pDevice->GetRenderState(D3DRS_ALPHABLENDENABLE, &OldAlpha);
	pDevice->GetRenderState(D3DRS_DESTBLEND, &OldDest);
	pDevice->GetRenderState(D3DRS_SRCBLEND, &OldSrc);
	pDevice->GetRenderState(D3DRS_CULLMODE, &OldCull);
	pDevice->GetPixelShader(&pOldShader);
	
	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	pDevice->SetPixelShader(nullptr);

	pDevice->SetFVF(CUSTOM_FVF);
	pDevice->SetTexture(0, nullptr);
	pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, qV, sizeof(D3DVERTEX));

	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, OldAlpha);
	pDevice->SetRenderState(D3DRS_DESTBLEND, OldDest);
	pDevice->SetRenderState(D3DRS_SRCBLEND, OldSrc);
	pDevice->SetRenderState(D3DRS_CULLMODE, OldCull);
	pDevice->SetPixelShader(pOldShader);
That works but again it messes with the games buffer

eg.
 

KiNG Jaydo

Newbie
Full Member
Jan 21, 2015
29
158
1
Вroihon;39309 said:
Ye, I just made the func for once colour.
Anyway my guess is that the dis.-/reappearing is caused by fcked up renderstates.
Try with saving/restoring them properly. Of course only do the saving/restoring once and not for each object you're drawing.

C++:
	DWORD OldAlpha, OldDest, OldSrc, OldCull;
	IDirect3DPixelShader9* pOldShader;
	pDevice->GetRenderState(D3DRS_ALPHABLENDENABLE, &OldAlpha);
	pDevice->GetRenderState(D3DRS_DESTBLEND, &OldDest);
	pDevice->GetRenderState(D3DRS_SRCBLEND, &OldSrc);
	pDevice->GetRenderState(D3DRS_CULLMODE, &OldCull);
	pDevice->GetPixelShader(&pOldShader);
	
	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	pDevice->SetPixelShader(nullptr);

	pDevice->SetFVF(CUSTOM_FVF);
	pDevice->SetTexture(0, nullptr);
	pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, qV, sizeof(D3DVERTEX));

	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, OldAlpha);
	pDevice->SetRenderState(D3DRS_DESTBLEND, OldDest);
	pDevice->SetRenderState(D3DRS_SRCBLEND, OldSrc);
	pDevice->SetRenderState(D3DRS_CULLMODE, OldCull);
	pDevice->SetPixelShader(pOldShader);
Could it be possible that the FVF has any effect on the rendering?
Removing the
C++:
 pDevice->SetFVF(CUSTOM_FVF);
	pDevice->SetTexture(0, nullptr);
gets removes the screwed up rendering, but goes back to the rectangle disappearing
 
Last edited:

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,746
40,528
316
That works but again it messes with the games buffer

eg.
That can't screw up the buffer like that. The reason for that must be something else.

Could it be possible that the FVF has any effect on the rendering?
Removing the
C++:
pDevice->SetFVF(CUSTOM_FVF);
pDevice->SetTexture(0, nullptr);
gets removes the screwed up rendering, but goes back to the rectangle disappearing
In my code I forgot to save/restore the original FVF.
C++:
DWORD OldFVF;
pDevice->GetFVF(&OldFVF);
//more stuff
pDevice->SetFVF(CUSTOM_FVF);
//drawingz
pDevice->SetFVF(OldFVF);
I don't think that GetTexture is necessary. But you can try that, too.
 

KiNG Jaydo

Newbie
Full Member
Jan 21, 2015
29
158
1
Вroihon;39317 said:
That can't screw up the buffer like that. The reason for that must be something else.


In my code I forgot to save/restore the original FVF.
C++:
DWORD OldFVF;
pDevice->GetFVF(&OldFVF);
//more stuff
pDevice->SetFVF(CUSTOM_FVF);
//drawingz
pDevice->SetFVF(OldFVF);
I don't think that GetTexture is necessary. But you can try that, too.

It didnt work at first, but i fiddled around, started trying different combinations and some how got a breakthrough. By storing the old FVF but not editing it I was able to get the Primitive to show and stay on the Window. Oddly enough, without the storing of the old FVF, it no longer works.. I will review this at a later date, but for now it works! Thank you so much!!

 
Status
Not open for further replies.
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.

Similar threads

Community Mods