Sign in to follow this  

Faster way to obtain the pixel color

Recommended Posts

Hi people, i am currently programming some kind of logger which is being used to color the games textures to my wishes. Its planned to be one part out of my Mod for left for dead. Actually to make the game somwhat more funny. The code is planned to work as following:
#define Player ( ( ( Numvert == 1545 ) && ( startIndex = 1377 ) && ( primCount == 7568 ) ) ||                 ( ( Numvert == 7567 ) && ( startIndex = 4687 ) && ( primCount == 4687 ) ) )

In IDirect3DDevice9::DrawIndexedPrimitive9:
HRESULT WINAPI hkDrawIndexedPrimitive( LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount ) {
	if( Player ) {
		pDevice->SetRenderState( D3DRS_ZENABLE, false );
		pDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
		for( int i = 0; i < 6; i++ ) pDevice->SetTexture( i, g_pTexLightPink );
		oDrawIndexedPrimitive( pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount );
		pDevice->SetRenderState( D3DRS_ZENABLE, true );
		pDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
		for( int i = 0; i < 6; i++ ) pDevice->SetTexture( i, g_pUltraPink );
To obtain my goal i would proberbly need a Hook. Accordingly to another forum i could use the MSDetours.lib for that. Anyways, back to the entire problem.. As said already i plan some kind of logger, Pseudowise it works like this: - You enter the game and hold the middle of the screen over the texture you want to color - Press numpad1 which initiates a scan - At the start of DrawIndexedPrimitive ( DIP ) we get the color of the orginal pixel. After we apply modify the textures color - At the end of DIP we get the color again and see if it matches to the one we obtained at the start - If they differ, we log the startindex, primcount and numvert of the current texture to identify it l8er This is the way how i obtain the pixel color:
class CColorHelper {
	int r;
	int g;
	int b;
	DWORD rgb;

	void fillStruct( int pixelX, int pixelY ) {
		HDC hdc = GetDC( HWND_DESKTOP );
		rgb = GetPixel( hdc, pixelX, pixelY );
		r = GetRValue( rgb );
		g = GetGValue( rgb );
		b = GetBValue( rgb );

	static bool match( CColorHelper* color1, CColorHelper* color2 ) {
		if( color1->rgb == color2->rgb )
			return true;
		//do range scann
		return false;
CColorHelper colorBefore;
CColorHelper colorAfter;
//I'm calling it as following
 colorBefore.fillStruct( (int)( g_ViewPort.Width / 2.f ), (int)( g_ViewPort.Height / 2.f ) );
This works but lags like shit as the screenbuffer ( frontbuffer or how its called ) is locked and unlocked each run of the DIP function. Specially DIP is called a lot of times as it needs to display all textures. Does anybody know about a better way to obtain my goal? Sure i could iterate through all possible combinations of the numvert, primcount and startindex but that takes ages. I thought of something like an automatism. Well, maybe i am completly wrong and what i want to do isnt possible, but i thought if the game is able to draw all the textures in a decent time, why shouldnt i be able to obtain a single pixel? I am still at the start of my DX researches so please dont judge me for some mistakes in my code :) Just thought this forum is full of clicking experience. Any help is appreciated guys ( and girls if any )! Greetings from germany, Frank

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this