Get Obstruction Hit Location CoD4

From UnKnoWnCheaTs Game Hacking Wiki
Jump to: navigation, search

Posted by uNrEaL.



The point of this code it to determine the location of the blocking surface when you call CG_Trace. This is useful for many things, but, I won't say anything about that, I'll leave it up to the user to be creative and think of the possibilities of which this code can enable. To use this code, simply add it after your call to CG_Trace, inside the same function.

My exact code from my cheat looks as follows, however most of you have made the decision to use the game's math system (vec3_t), and their operator definitions, so I'll post both codes. I use my own math, that's why my code looks a bit different.

pTraceResult->HitLocation = Vector( pStartLocation->X + ( ( pEndLocation->X - pStartLocation->X ) * pTraceResult->Fraction ), pStartLocation->Y + ( ( pEndLocation->Y - pStartLocation->Y ) * pTraceResult->Fraction ), pStartLocation->Z + ( ( pEndLocation->Z - pStartLocation->Z ) * pTraceResult->Fraction ) );
The "HitLocation" variable of the trace_t class begins at 0x30, and ends at 0x3C. It is nothing more than a Vector, and so implementing it as a vec3_t would work just fine. I know that this is the offset to the vector because I had to manually reverse how the game determines the hit location and stores the value in the tract_t structure. The reason we have to do all of this by hand is because CG_Trace itself doesn't do it, it is done by the game after the function has been called.

I love the FPU Stack and FPU Maths in Assembly. =)

For use with the vec3_t math system:

pTraceResult->HitLocation[ 0 ] = pStartLocation[ 0 ] + ( ( pEndLocation[ 0 ] - pStartLocation[ 0 ] ) * pTraceResult->Fraction );
pTraceResult->HitLocation[ 1 ] = pStartLocation[ 1 ] + ( ( pEndLocation[ 1 ] - pStartLocation[ 1 ] ) * pTraceResult->Fraction );
pTraceResult->HitLocation[ 2 ] = pStartLocation[ 2 ] + ( ( pEndLocation[ 2 ] - pStartLocation[ 2 ] ) * pTraceResult->Fraction );
Or you can just ignore the whole bit of adding the variable into the trace_t structure, and just do a global definition of it and set the members of it that way. It's completely up to you.

This work is solely my own, there are no need for credits. All that was used was a bit of brain power and IDA Professional.

Cheers, and enjoy.