Question[Question] About Chams.

Posts 1–11 of 11 · Page 1 of 1
[Question] About Chams.
Credits
  • Everyone at MPGH.
  • Everyone at GD.
  • All other sites providing helpful information.
  • Azorbix - D3D starter kit. (I'm currently using this. Works great!).
  • You, Maybe. :D


Question
I have working chams for Swat 4. Everything works, but not always on top of other textures.
Here is a picture of what is happening:

I just want some insight on what is happening and why.
This even happens in COD 2.
Any information will be appreciated. Thanks!

Define:
Code:
#define Chams ((lVerts == 38 && lPrims == 42) || (lVerts == 601 && lPrims == 496)) //Truncated
long lVerts;
long lPrims;
long lStrides;
LPDIRECT3DTEXTURE9 Blue;
LPDIRECT3DTEXTURE9 Red;
DIP
Code:
HRESULT APIENTRY hkIDirect3DDevice9::DrawIndexedPrimitive(D3DPRIMITIVETYPE Type,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount)
{
//Below used for getting model rec.
lVerts = NumVertices;
lPrims = primCount;
lStrides = m_Stride;
//----------------------
if (Chams)
{
m_pD3Ddev->SetRenderState(D3DRS_ZWRITEENABLE, true);
m_pD3Ddev->SetRenderState(D3DRS_ZENABLE,false);
m_pD3Ddev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
m_pD3Ddev->SetTexture( 0, Red);
m_pD3Ddev->DrawIndexedPrimitive(Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
m_pD3Ddev->SetRenderState(D3DRS_ZENABLE, true);
m_pD3Ddev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
m_pD3Ddev->SetTexture( 0, Blue);
}
return m_pD3Ddev->DrawIndexedPrimitive(Type,BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
}
INIT
Code:
HRESULT CD3DManager::Initialize()
{
GenerateTexture(m_pD3Ddev, &Red,D3DCOLOR_ARGB(255,255,0,0));
GenerateTexture(m_pD3Ddev, &Blue,D3DCOLOR_ARGB(255,0,0,255));
return S_OK;
}
Rest is same as Azorbix.
Can you post your whole DrawIndexedPrimitive function?
Quote Originally Posted by Void View Post
Can you post your whole DrawIndexedPrimitive function?
This would be VERY helpful in us fixing the DrawIndexedPrimitave...
Thanks for your fast replys. (First post updated).

I don't see anything wrong. Compiles perfectly. Checked coding.
I'm using Azorbics Starter kit 3b. Nothing changed other then my 2 cents.


Edit: When playing, I see them thru walls but not Objects like the cop car or a trash can.
Some games don't apply textures the same way. My guess is it has something to do with the shading being another layer. I don't remember exactly because it's been a while since I messed around with chams. I'll have to look through some code to offer a suggestion, but I'll get back to you when I get a chance.
Ok finally had a chance to get back to you. try:

in DIP
Code:
pDevice->SetRenderState(D3DRS_ZENABLE,false);
if(chams)
{
	pDevice->SetPixelShader(NULL);
	pDevice->SetPixelShader(Pixcolor[backindex]);
}
HRESULT hr = pDIP(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
 
if(zaxis)pDevice->SetRenderState(D3DRS_ZENABLE, true); //zaxis is wallhack
if(chams)pDevice->SetPixelShader(Pixcolor[frontindex]);
And u need to initialize some pixelshaders
Code:
CreateMyShader(&Pixcolor[1], pDevice,0, 255, 0,50);//green
CreateMyPixelShader
Code:
HRESULT CreateMyShader(IDirect3DPixelShader9 **pShader, IDirect3DDevice9 *Device, float red, float green, float blue, float alpha )
{
    ID3DXBuffer *MyBuffer = NULL;
    char MyShader[ 256 ];
    sprintf( MyShader, "ps.1.1\ndef c0, %f, %f, %f, %f\nmov r0,c0", red/255, green/255, blue/255, alpha/255 );
    D3DXAssembleShader( MyShader, sizeof( MyShader ), NULL, NULL, 0, &MyBuffer , NULL );
    if( FAILED( Device->CreatePixelShader((const DWORD*)MyBuffer ->GetBufferPointer(), pShader)) )return E_FAIL;
    return S_OK;
}
I have a problem with shaders. My nVidia Geforce fx 5500 says it supports PixelShader 2.0 but its not working.
Tried both 1.1 and 2.0 shaders and same outcome.

It colors in some of the models but when it colors in like 3-4 more objects, the whole screen gets colored in. Heres a few pictures:
http://img841.imageshack.us/img841/3894/test2bu.png
http://img64.imageshack.us/img64/1803/test3yf.png
2nd Picture is whats suppose to be colored on the 3rd but is not.
I have no idea. I even reset my nvidia settings to stock.

2.0 Shader
Code:
sprintf_s (szShader, "ps_2_0\ndef c0, %f, %f, %f, %f\nmov oC0, c0", r, g, b, a);
it sounds like you need to refine your model filtering. Make sure you don't have one with numVerts == 4. Sometimes games like to put giant squares in front of the screen.

EDIT: The good thing is it looks like your definitely seeing through other models, Now you just have to refine your model recognition.
Ya, I checked that. I replaced my model rec logger to use Shader instead of Texture. Shader says it's Stride 50 when it covers the screen but I only use 36.

Heres my model rec for Swat 4. Not all the NPC are logged tho. I missed a few when I was logging.
Code:
#define Chams ((lVerts == 38 && lPrims == 42) || (lVerts == 601 && lPrims == 496) || (lVerts == 27 && lPrims == 50) || (lVerts == 165 && lPrims == 1746) || (lVerts == 644 && lPrims == 512) || (lVerts == 1151 && lPrims == 1369) || (lVerts == 474 && lPrims == 689) || (lVerts == 225 && lPrims == 269) || (lVerts == 670 && lPrims == 699) || (lVerts == 885 && lPrims == 961) || (lVerts == 310 && lPrims == 398) || (lVerts == 186 && lPrims == 234) || (lVerts == 994 && lPrims == 1347) || (lVerts == 1027 && lPrims == 1331) || (lVerts == 501 && lPrims == 673) || (lVerts == 154 && lPrims == 183) || (lVerts == 600 && lPrims == 765) || (lVerts == 667 && lPrims == 864) || (lVerts == 186 && lPrims == 216) || (lVerts == 499 && lPrims == 677) || (lVerts == 808 && lPrims == 1164) || (lVerts == 966 && lPrims == 1316) || (lVerts == 564 && lPrims == 776) || (lVerts == 900 && lPrims == 1203) || (lVerts == 169 && lPrims == 225) || (lVerts == 571 && lPrims == 763) || (lVerts == 892 && lPrims == 1185) || (lVerts == 681 && lPrims == 1006) || (lVerts == 845 && lPrims == 1143) || (lVerts == 979 && lPrims == 1373) || (lVerts == 627 && lPrims == 810) || (lVerts == 673 && lPrims == 878) || (lVerts == 403 && lPrims == 549) || (lVerts == 936 && lPrims == 1313) || (lVerts == 600 && lPrims == 765) || (lVerts == 667 && lPrims == 864) || (lVerts == 950 && lPrims == 1329) || (lVerts == 479 && lPrims == 693) || (lVerts == 906 && lPrims == 1224) || (lVerts == 710 && lPrims == 936) || (lVerts == 544 && lPrims == 766) || (lVerts == 456 && lPrims == 659) || (lVerts == 896 && lPrims == 1216) || (lVerts == 714 && lPrims == 936) || (lVerts == 184 && lPrims == 239) || (lVerts == 343 && lPrims == 467) || (lVerts == 1053 && lPrims == 1438) || (lVerts == 656 && lPrims == 924) || (lVerts == 671 && lPrims == 876) || (lVerts == 594 && lPrims == 848) || (lVerts == 371 && lPrims == 345) || (lVerts == 380 && lPrims == 513))
Stride is 36 for all NPC/Swat and some objects.

--------

Here is the Model Rec script I made.
It is not pro and can be improved.
If you do improve, please post your changes! (and why if possible)
Thanks =)

Defines:
Code:
unsigned int Arr[999999]; //Stores DIP UIDs.
unsigned int ArrSize=0; //How many UIDs are in the array.
unsigned int AView=0; //Current UID I want to view.
unsigned int AVvert=0; //Used for logging
unsigned int AVprim=0; //Used for logging
unsigned int zs=0; //Used for logging
Function: (CheckArray)
Code:
bool CheckArray(unsigned int Val)
//True if its in the list or cant put in the list
//False if its a New UID.
{
bool isIN=false;
for(unsigned int Z=1; Z < ArrSize; Z++)
{
if(Arr[Z] == Val)
{
isIN = true;
}
}
if(!isIN)
{
if (ArrSize == 999997)
{
return true;
}
Arr[ArrSize] = Val;
ArrSize++;
return false;
}
return true;
}
DIP:
Code:
unsigned int tmp1;
tmp1 = (((lVerts+1200)+(lPrims+2300)+(lStrides+3400))+10000); //Creates a UID.

if (!CheckArray(V))
{
m_pD3Ddev->SetRenderState(D3DRS_ZENABLE,false);
m_pD3Ddev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
m_pD3Ddev->SetTexture( 0, Red);
m_pD3Ddev->DrawIndexedPrimitive(Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
m_pD3Ddev->SetRenderState(D3DRS_ZENABLE, true);
m_pD3Ddev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
m_pD3Ddev->SetTexture( 0, Pink);
}

if (AView > 0)
{
if (V == Arr[AView])
//Here is where AView comes into play.
//V is the UID and AView is the Current UID I want to view.
{
AVvert = lVerts;
AVprim = lPrims;
zs = lStrides;
m_pD3Ddev->SetRenderState(D3DRS_ZENABLE,false);
m_pD3Ddev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
m_pD3Ddev->SetTexture( 0, Green);
//m_pD3Ddev->SetPixelShader(Pixelcolor[2]);
m_pD3Ddev->DrawIndexedPrimitive(Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
m_pD3Ddev->SetRenderState(D3DRS_ZENABLE, true);
m_pD3Ddev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
m_pD3Ddev->SetTexture( 0, DOrange);
//m_pD3Ddev->SetPixelShader(Pixelcolor[3]);
}
}
End:
Code:
//This is where I change what UID I want to view.
if(GetAsyncKeyState(VK_NUMPAD1)&1)
{
if(AView > 0)
{
AView--;
}
else
{
AView++;
}

}

if(GetAsyncKeyState(VK_NUMPAD4)&1)
{
if(AView < 999997)
{
AView++;
}
else
{
AView--;
}
}

if(GetAsyncKeyState(VK_NUMPAD8)&1)
{
for(unsigned int Z=0; Z < ArrSize; Z++)
{
Arr[Z] = 0;
}
ArrSize = 0;
}

if(GetAsyncKeyState(VK_NUMPAD7)&1)
{
AView = 0;
}
//This is my logger. On screen Logging.
sprintf_s(str, " AV VERT: %d", AVvert); //Use your own D3Dfont! =)
sprintf_s(str2, " AV PRIM: %d", AVprim);
sprintf_s(str3,"V:%d Stride:%d",AView,zs);
sprintf_s(str4, " aSize: %d",ArrSize);
Also, Thank you so much for your input Why06.
Well I'm not going to pretend I know what you need to do here, at this point all I can do is offer some guesses. I'd hate to say it, but you might need to ask this question on another site where there are some people more knowledgeable in D3D.


I'll just tell you what I got from your code before you go. I'm not exactly sure what Aview is used for. I noticed something weird happens when ArrSize is == 99997, and there's no explanation to why that is. It seems you are calling DIP twice. Maybe you know your not, but I would have to know exactly how the Arr[Aview] thing works to be sure. It seems like an index , but that doesn't explain why it needs to be greater than 0. Last but not least it could be possible you are logging the background. Usually in games there's this giant sphere around the level which is the background. It's possible that by bringing the entire background forward would cause a similar problem blocking the entire screen. Don't take my word on any of this. Its only a guess.

I suggest trying UC of GD. Hopefully you know what forums Im talking about. If not I'll PM you. Wish I could be of more help, but I don't want to tell you something wrong so goodluck.
No need, you helped me out good enough! For the Model rec code, whenever DIP is called, I create a UID and store it(Every single model gets logged). Since I don't know how to Re-Dimension the array, I have to allow at least 10k slots. AView is the current UID I have selected. If its 999997 or less, allow it to increase, If not, decrease or it will cause a buffer overflow when it reachs 1mil cause the array size is 999999. I hope this cleared things up a bit for you. (It works great but is not optimized for performance)

Edit: Ya, I know those sites. Credits to them! They(And here) makes learning experience more comforting.
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Tags for this Thread

Need help?