What he is asking is sometimes you hack an FPS game and you see a 16-bit number going up and down as you aim your character up and down (*cough* Unreal Tournament 2003 *cough*).
This is a sin/cos table. The 16-bit value is used to index into a table of 65,535 floats for sine values and 65,535 floats for cosine values.
Today, these tables cannot keep up with simply calling cos() or sin() due to the slowness of cache hits using tables vs. the raw speed of the FPU at simply calculating these numbers.
But they were more efficient back in the day.
So you have encountered this 16-but unsigned short that moves up and down as you angle up and down. What do you do with it? Use it as an index into one of the tables, of course.
One way is to find the tables in the game RAM.
You could copy them to your local RAM for efficient access, or use ithem directly if you are using DLL injection.
Another way is to generate your own tables. The code below illustrates how to make and use the tables.
- Code: Select all
#define LSM_TABLESIZE (0xFFFF+1)
LSREAL CMathLib::m_fCosTable[LSM_TABLESIZE] = { LSM_ZERO };
LSREAL CMathLib::m_fSinTable[LSM_TABLESIZE] = { LSM_ZERO };
…
// Create a cos/sin look-up tables.
for ( LSINT32 I = LSM_TABLESIZE; --I >= 0; ) {
LSREAL fCos = LSMCOS( (2.0 * LSM_PI_DOUBLE / LSM_TABLESIZE) * I );
LSREAL fSin = LSMSIN( (2.0 * LSM_PI_DOUBLE / LSM_TABLESIZE) * I );
m_fCosTable[I] = fCos;
m_fSinTable[I] = fSin;
}
- Code: Select all
LSMREAL fCos = m_fCosTable[ui16Index];
ui16Index here is the 16-bit value you discovered in the game. fCos represents the cosine of that value.
L. Spiro