[Source code]Stride logging.
Well, I don't think I've ever contributed much to this section. Hope some of you could find some good use of this.
Basically, a stride/primitive count/vertex count recognition. I was able to find the stride in CA, until it crashed ( it's detected for CA ). Yes, I know there are probably alot of these, but I only found 1 and it kept crashing.
This is indeed, copy and paste friendly. Here we go.
Functions.h:
[highlight=cpp]
#include <fstream>
#include <iostream>
#include "Menu.h"
using namespace std;
bool On = false;
CMENU Menu;
int numvert = 0;
int primcount = 0;
int stride = 0;
LPDIRECT3DVERTEXBUFFER9 StreamData;
UINT OffsetInBytes;
UINT Stride;
HRESULT (WINAPI* Real_EndScene)(LPDIRECT3DDEVICE9);
HRESULT (WINAPI* Real_DrawIndexedPrimitive)(LPDIRECT3DDEVICE9,D3DPR IMITIVETYPE,int,UINT,UINT,UINT,UINT);
HRESULT WINAPI hook_EndScene(LPDIRECT3DDEVICE9 pDevice)
{
D3DXCreateFont(pDevice,15,0,FW_BOLD,1,false,DEFAUL T_CHARSET,OUT_DEFAULT_PRECIS,ANTIALIASED_QUALITY,D EFAULT_PITCH | FF_DONTCARE,"Arial",&Menu.cFont);
if(On){
Menu.DrawString("Made by Azu",0);
char buffer1[100],buffer2[100],buffer3[100];
sprintf(buffer1,"Primitive count: %d",primcount);
sprintf(buffer2,"Vertex count: %d",numvert);
sprintf(buffer3,"Stride: %d",stride);
Menu.DrawString(buffer1,2);
Menu.DrawString(buffer2,3);
Menu.DrawString(buffer3,4);
Menu.cFont->Release();
}
return Real_EndScene(pDevice);
}
HRESULT WINAPI hook_DrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice,D3DPRIMITIVETYPE Type,int BaseVertexIndex,UINT MinIndex,UINT NumVertices,UINT StartIndex,UINT PrimCount)
{
if(On)
{
pDevice->GetStreamSource(0,&StreamData,&OffsetInBytes,&Str ide);
if(stride == Stride || numvert == NumVertices || primcount == PrimCount)
{
pDevice->SetRenderState(D3DRS_ZENABLE,false);
pDevice->SetTexture(0,NULL);
}
StreamData->Release();
}
return Real_DrawIndexedPrimitive(pDevice,Type,BaseVertexI ndex,MinIndex,NumVertices,StartIndex,PrimCount);
}
void MainThread()
{
while(1)
{
//master key
if(GetAsyncKeyState(VK_INSERT)){ On = !On; Sleep(100); }
if(GetAsyncKeyState(VK_NUMPAD6)){ primcount++; Sleep(70); }
if(GetAsyncKeyState(VK_NUMPAD3)){ primcount--; Sleep(70); }
if(GetAsyncKeyState(VK_NUMPAD5)){ numvert++; Sleep(70); }
if(GetAsyncKeyState(VK_NUMPAD2)){ numvert--; Sleep(70); }
if(GetAsyncKeyState(VK_NUMPAD4)){ stride++; Sleep(70); }
if(GetAsyncKeyState(VK_NUMPAD1)){ stride--; Sleep(70); }
if(GetAsyncKeyState(VK_NUMPAD0)){ stride = 0; primcount = 0; numvert = 0; Sleep(70); }
if(GetAsyncKeyState(VK_DELETE))
{
ofstream LogFile;
LogFile.open("Stride log.txt");
LogFile << "Primitive count\t" << primcount << "\n";
LogFile << "Vertex count\t" << numvert << "\n";
LogFile << "Stride\t\t" << stride << "\n";
}
}
}
[/highlight]
Menu.h: (Very crappy)
[highlight=cpp]
#include "stdafx.h"
class CMENU {
public:
LPD3DXFONT cFont;
RECT cRect[100];
void SetRectArea(int);
void DrawString(char*,int);
};
void CMENU::SetRectArea(int index)
{
cRect[index].top = 10+(17*index);
cRect[index].bottom = 400;
cRect[index].right = 780;
cRect[index].left = 10;
}
void CMENU:

rawString(char* string, int index)
{
cFont->DrawTextA(0,string,-1,&cRect[index],DT_LEFT | DT_NOCLIP,D3DCOLOR_XRGB(0,0,255));
}
[/highlight]
dllmain.cpp:
[highlight=cpp]
#include "stdafx.h"
#include "Hook.h"
bool IsReady()
{
if(GetModuleHandle("d3d9.dll") != NULL) {
return true;
}
return false;
}
void HookThread()
{
Menu.SetRectArea(0);
Menu.SetRectArea(2);
Menu.SetRectArea(3);
Menu.SetRectArea(4);
while(!IsReady)
{
Sleep(200);
}
Initialize();
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(0,0,(LPTHREAD_START_ROUTINE)HookThrea d,0,0,0);
CreateThread(0,0,(LPTHREAD_START_ROUTINE)MainThrea d,0,0,0);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
[/highlight]
Hook.h:
[highlight=cpp]
#include "stdafx.h"
#include "Functions.h"
bool bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
for(;*szMask;++szMask,++pData,++bMask)
if(*szMask=='x' && *pData!=*bMask )
return false;
return (*szMask) == NULL;
}
DWORD FindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask)
{
for(DWORD i=0; i < dwLen; i++)
if( bCompare( (BYTE*)( dwAddress+i ),bMask,szMask) )
return (DWORD)(dwAddress+i);
return 0;
}
DWORD* Initialize()
{
DWORD* VTable;
DWORD D3D9ModuleBase;
do {
D3D9ModuleBase = (DWORD)GetModuleHandle("d3d9.dll");
} while(!D3D9ModuleBase);
DWORD DevicePTR = FindPattern(D3D9ModuleBase,0x128000,(PBYTE)"\xC7\x 06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86 ","xx????xx????xx");
if(DevicePTR)
{
memcpy(&VTable,(void*)(DevicePTR+2),4);
//hook functions
Real_EndScene = (HRESULT(WINAPI*)(LPDIRECT3DDEVICE9))DetourFunctio n((PBYTE)VTable[42],(PBYTE)hook_EndScene);
Real_DrawIndexedPrimitive = (HRESULT(WINAPI*)(LPDIRECT3DDEVICE9,D3DPRIMITIVETY PE,int,UINT,UINT,UINT,UINT))DetourFunction((PBYTE) VTable[82],(PBYTE)hook_DrawIndexedPrimitive);
}
return (DWORD*)VTable;
}
[/highlight]
Well, that's it.
Just want to say, I put Hook.h last 'cause I wanted to say. I am deeply ashamed for copying most of everything in Hook.h from someone else, I wasn't able to retrieve the device pointer myself, and I found this method somewhere.
I am truly sorry to those of you who hate copy and pasting. Hell_Demon please don't kill me.
The rest was made by me.
Note: If you're wondering why it says "Made by Azu". It's because on Why06's little MSN group, they call me Azu because of my MSN display name.
Second note: If anyone does know how to find the device pointer rather than the address for the virtual method in the d3d9 module, I seek help from you. If you wouldn't mind helping me find the pointer manually.
I guess this is sort of a release/request thread.