[Source code]Stride logging.

Posts 1–9 of 9 · Page 1 of 1
[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.
wow this is really long seriously for a stride logger
The device pointer shld be stored in IDirect3DDevice9 structure if I'm not wrong(most probably wrong coz I'm rusty)

edit:
spotted this off another site may help
Code:
LPDIRECT3DDEVICE9 pDirect3DDevice9 = (LPDIRECT3DDEVICE9)0x66DCF08;
cBeginScene = (Scene_p)beginscene.Hook( (DWORD)&nBeginScene, (PDWORD)pDirect3DDevice9 , 41);
why can't nothing be made to browse through each model and shader it?
Why does noone use
stride = (min+max)/2?!?!

Code:
int mins=0,maxs=10000,stride=5000;
if(GetAsyncKeyState(VK_NUMPAD4)&1)
{
    maxs=stride;
    stride = (mins+maxs)/2;
}
if(GetAsyncKeyState(VK_NUMPAD6)&1)
{
    mins=stride;
    stride = (mins+maxs)/2;
}
log(n)/log(2) where n is the maximum stride number.
for stride 0 to a 10000 it takes a max of 14 steps.
for stride 0 to 1000000 it tkes a max of 21 steps.

if(m_Stride == stride) //color me green
else if (m_Stride < stride && m_Stride > mins) //color me red
else if (m_Stride > stride && m_Stride < maxs) //color me blue

if its blue, you hit np 6, if its red you hit np 4, if its green u hit whatever key u have set to log the stride lol.

Much faster + you won't skip the correct stride because of lag
Quote Originally Posted by Hell_Demon View Post
Why does noone use
stride = (min+max)/2?!?!

Code:
int mins=0,maxs=10000,stride=5000;
if(GetAsyncKeyState(VK_NUMPAD4)&1)
{
    maxs=stride;
    stride = (mins+maxs)/2;
}
if(GetAsyncKeyState(VK_NUMPAD6)&1)
{
    mins=stride;
    stride = (mins+maxs)/2;
}
log(n)/log(2) where n is the maximum stride number.
for stride 0 to a 10000 it takes a max of 14 steps.
for stride 0 to 1000000 it tkes a max of 21 steps.

if(m_Stride == stride) //color me green
else if (m_Stride < stride && m_Stride > mins) //color me red
else if (m_Stride > stride && m_Stride < maxs) //color me blue

if its blue, you hit np 6, if its red you hit np 4, if its green u hit whatever key u have set to log the stride lol.

Much faster + you won't skip the correct stride because of lag
Damn, that's a bit confusing.

I was looking through your created threads and found something similar to this, too bad I wasn't around back then. I don't know if it was you or Azorbix who came up with that method ( or maybe everyone knows about it and I'm just stupid ) but, thanks a lot.
no idea who cme up with it, probly azorbix ^^

for comparisation(if u'd be a super human and can check 1 stride per frame):
10000 strides @ 100 fps
Your old method - 10000/100=100, 1 minute and 40 seconds if you'd be able to check 1 stride per frame
New method - log(10000)/log(2) = 14, 14/100 = about 1/6th of a second
What does stride logging do??

Is it something that you can alter to change the speed of the player??
Quote Originally Posted by KABLE View Post
What does stride logging do??

Is it something that you can alter to change the speed of the player??
Strides = like the value of body parts, grenades, anything.
Really dont know how to explain it.
Code:
if(m_FontON && m_Stride == 32 || m_Stride == 36 || m_Stride == 44){
			if(Hack.chams != 0){
				/*	Chams */
				m_device->SetTexture(0,NULL);
				m_device->SetRenderState(D3DRS_ZENABLE,false);
				m_device->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
				m_device->SetRenderState(D3DRS_LIGHTING,true);
                                if(Hack.chams == 1 && m_FontON)	{ m_device->SetTexture(0,pTexGreen); }//green
That's a instance on how you would use a stride. That's chams.
although the strides are outdated(Combat Arms).

Hope I helped.
Quote Originally Posted by Calebb View Post
Strides = like the value of body parts, grenades, anything.
Really dont know how to explain it.
Code:
if(m_FontON && m_Stride == 32 || m_Stride == 36 || m_Stride == 44){
			if(Hack.chams != 0){
				/*	Chams */
				m_device->SetTexture(0,NULL);
				m_device->SetRenderState(D3DRS_ZENABLE,false);
				m_device->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
				m_device->SetRenderState(D3DRS_LIGHTING,true);
                                if(Hack.chams == 1 && m_FontON)	{ m_device->SetTexture(0,pTexGreen); }//green
That's a instance on how you would use a stride. That's chams.
although the strides are outdated(Combat Arms).

Hope I helped.
It's funny.. I found the same 3 stride numbers for CA just the other day.
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us