Solved Questions/Help - chams for dx9

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

DaftHacker

Newbie
Full Member
Oct 23, 2015
11
252
0
So i have my chams working fine for my directx dll but i saw a post with someone who had some transparency included.
I was wondering how i could do this and what other things i can do.


My code:
C++:
typedef HRESULT(__stdcall* tDrawIndexedPrimitive)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount);
tDrawIndexedPrimitive oDrawIndexedPrimitive;

HRESULT __stdcall hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount)
{
	__asm nop

	HRESULT hRet = oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);

	//Toggle Chams
	if (menu.MenuOptions[CHAMS].isOn)
	{ 
		if (SPETZNAS_OPFOR)
		{
			pDevice->SetRenderState(D3DRS_ZENABLE, false);
			pDevice->SetTexture(0, drawing.TexRed);
			oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
			pDevice->SetRenderState(D3DRS_ZENABLE, true);
		}
		if (MARINES_SAS)
		{
			pDevice->SetRenderState(D3DRS_ZENABLE, false);
			pDevice->SetTexture(0, drawing.TexGreen);
			oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
			pDevice->SetRenderState(D3DRS_ZENABLE, true);
		}
	}

	return hRet;
}
Also how would i draw a part of the object a different color if it is behind an object ?
As a side question for general direct x, how come D3DCOLOR_ARGB(100, 255, 0, 0) wont show as transparent ?
My drawing code:

C++:
	D3DRECT rect = { x, y, x + width, y + height };
	pDevice->Clear(1, &rect, D3DCLEAR_TARGET | D3DCLEAR_TARGET, color, 0, 0);
 
Last edited:

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,745
40,528
316
If you want to have different colours when it's behind another object you have to draw two times. One time with z buffer enabled and one time with z buffer disabled (with a different colour of course).
To get transparent textures you probably have to mess with the renderstates:
C++:
    pTempDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    pTempDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    pTempDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    pTempDevice->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
    pTempDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    pTempDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
    pTempDevice->SetPixelShader(nullptr);
These are the renderstates I'm using for alpha drawing. Never used it in DrawIndexedPrimitive but it should do the job. You should definitly save/restore the renderstates. Maybe even use a stateblock to quickly set/restore your rendersettings.

Edit:
I thought the question about the alpha channel was for the DIP and textures.
Clear can't draw transparent stuff because for some reason the alpha channel is not supported. If you want to draw transparent stuff you have to do vertex drawing.
 
Last edited:

DaftHacker

Newbie
Full Member
Oct 23, 2015
11
252
0
If you want to have different colours when it's behind another object you have to draw two times. One time with z buffer enabled and one time with z buffer disabled (with a different colour of course).
To get transparent textures you probably have to mess with the renderstates:
C++:
    pTempDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    pTempDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    pTempDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    pTempDevice->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
    pTempDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    pTempDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
    pTempDevice->SetPixelShader(nullptr);
These are the renderstates I'm using for alpha drawing. Never used it in DrawIndexedPrimitive but it should do the job. You should definitly save/restore the renderstates. Maybe even use a stateblock to quickly set/restore your rendersettings.

Edit:
I thought the question about the alpha channel was for the DIP and textures.
Clear can't draw transparent stuff because for some reason the alpha channel is not supported. If you want to draw transparent stuff you have to do vertex drawing.
Hmm im getting some weird effects when trying to using stateblock
Fog, skybox and other shit isn't rendering correctly only when im looking at the objects i want changed.


Here is my code, im pretty sure im using it correctly:
C++:
IDirect3DStateBlock9* pStateBlock = NULL; //In my header file
				pDevice->BeginStateBlock();
				pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
				pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVDESTCOLOR);
				pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_INVSRCCOLOR);
				pDevice->SetRenderState(D3DRS_ZENABLE, false);
				pDevice->EndStateBlock(&pStateBlock);

				oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);

				pStateBlock->Apply();
				pStateBlock->Release();
I know for sure those set render states have my desired effect because i just manually used GetRenderState before settings them and then restored them. I also was looking to capture all render states, i was looking over: The effect system uses a state block to save state. After ID3DXEffect::Begin is called, a state block is created and state is captured. When ID3DXEffect::End is called, the state block state is reapplied to the device. But i dont have any ID3DXEffect variable so im not sure how to call Begin or End. I was looking at msdn for the info on state blocks https://msdn.microsoft.com/en-us/library/windows/desktop/bb206121(v=vs.85).aspx
 
Last edited:

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,745
40,528
316
Well, you first have to create the statckblock using IDirect3DDevice9::CreateStateBlock with the D3DSBT_ALL flag.
Make the stateblock global aswell. It's not really efficient to recreate it on every call.
Something like this:
C++:
IDirect3DStateBlock9 * pStateBlock = nullptr;
//in the hook:
if(!pStateBlock)
      pDevice->CreateStateBlock(D3DSTATEBLOCKTYPE::D3DSBT_ALL, &pStateBlock);

pStateBlock->Capture();
//set your render states and draw
pStateBlock->Apply();
 

DaftHacker

Newbie
Full Member
Oct 23, 2015
11
252
0
Well, you first have to create the statckblock using IDirect3DDevice9::CreateStateBlock with the D3DSBT_ALL flag.
Make the stateblock global aswell. It's not really efficient to recreate it on every call.
Something like this:
C++:
IDirect3DStateBlock9 * pStateBlock = nullptr;
//in the hook:
if(!pStateBlock)
      pDevice->CreateStateBlock(D3DSTATEBLOCKTYPE::D3DSBT_ALL, &pStateBlock);

pStateBlock->Capture();
//set your render states and draw
pStateBlock->Apply();
Hmm im still having some glitchy effects, i put: if(!pStateBlock) pDevice->CreateStateBlock(D3DSTATEBLOCKTYPE::D3DSBT_ALL, &pStateBlock); in my endscene and IDirect3DStateBlock9 * pStateBlock = nullptr; is in my header. I tried the method with some render states like D3DRS_ALPHABLENDENABLE and then tried it with only the zbuffer.
C++:
		pStateBlock->Capture();
		if (SPETZNAS_OPFOR)
		{
			pDevice->SetRenderState(D3DRS_ZENABLE, false);
			oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
		}
		pStateBlock->Apply();
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,745
40,528
316
Hmm, I have very limited d3d9 knowledge and I basically only know the things that worked for me. No idea what's wrong then. Maybe just screw state blocks and fix all the renderstates manually or idk
 
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