Find a way to iterate through players (array, mapped, vector, ...), IDA, OllyDbg or CheatEngine could help you out here. Reverse the structure as far as possible, as you might find some validity checks. From that point, all you need to find are your own view angles. What to do with them, points the obvious.
Just to help you out, I wrote this up fastly. Addresses could be wrong (but I doubt it :P), I used CoD2 but I barely looked at that game in the past. In the end, you get the idea.
Code:
float diff[3]; // Difference from our own viewpoint and the target.float dx, dy; // Enemy vector to x and y angle.
// Pointer to our viewangles.
float* viewangles = ( float* ) 0x0098FDEC;
// Pointer to the original EndScene function.
void (*pEndscene)(unsigned long refdef);
// Endpoint for our hook.
void hEndscene(unsigned long refdef) {
pEndscene( refdef );
float* target = NULL;
if ( *( int* ) ( refdef + 36 ) ) {
// There is a maximum amount of 64 players, let's iterate through them.
for ( int i = 0; i < 64; i++ ) {
// Small bit of logical sense to locate the current centity pointer (in our loop).
// Centity struct located at 0x015E2A80, with a size step (devided by 1024, which are the
// max gentities / session. Resulted in 548. The rest of the code points itself.
DWORD cent = ( ( DWORD ) 0x015E2A80 + ( i * 548 ) );
// A 'vector' (float[3]) with the position is located at current centity + 492.
float* pos = *( float** ) ( cent + 492 );
// centity.currentValid is located at 480.
int valid = *( int* ) ( cent + 480 );
// If our player is valid, set it as our target.
if ( valid ) {
target = pos;
break;
}
}
if ( target != NULL ) {
VectorSubtract( target, vieworg, diff );
vectoangles( diff, dx, dy );
viewangles[0] += dy;
viewangles[1] += dx;
}
}
} Could as well just reverse the centity structure instead.
Regards.
Bookmarks