I am working on my first CSGO hack. Before i get into details, the hack is external and I am using C#. My problem is that when I read the view matrix and try and convert player positions to screen points, I get ridiculously weird numbers. Sometimes the numbers when converted to strings read out "NaN" which I know means undefined. Here is a table of what I'm talking about.
ViewMatrix:
1.79498E+21 |
-1.215803E-11 |
1.680519E-33 |
-1.122565E-06 |
3.888831E-20 |
-9735.812 |
3.186712E+38 |
-8.520999E+13 |
-3.5921E-14 |
-6.890327E+13 |
-2.064528E+26 |
-6.869414E+13 |
9.530977E+14 |
-1.121148E-06 |
-5.784123E+19 |
-1.118947E-06 |
Some of the bots positions + my position(I'll filter it out later) after converted to screen
102512.2 |
Infinity |
61532.27 |
Infinity |
43722.18 |
Infinity |
38530.59 |
Infinity |
79687.25 |
Infinity |
I don't know if I am reading the view matrix wrong (I have tried multiple different ways) or if I am converting the points wrong.
Here is my code:
get Viewmatrix
Code:
public static float[] GetMatrixArray(ref ProcessMemory mem)
{
float[] flt = new float[16];
Buffer.BlockCopy(mem.ReadMem(mem.Pointer("client.dll", Offsets.viewMatrix), 64), 0, flt, 0, mem.ReadMem(mem.Pointer("client.dll", Offsets.viewMatrix), 64).Length);
//byte[] tempBytes = mem.ReadMem(mem.Pointer("client.dll", Offsets.viewMatrix), 64);
//for(int i = 0; i < 16; i++)
//{
// flt[i] = BitConverter.ToSingle(tempBytes, (i * 4));
//}
return flt;
}
World to Screen Function (Version with floats) I have another version of this function which is the same code but the Viewmatrix is a struct
Code:
bool WorldToScreenFloat(ref V3 position, ref Vector2 screenPosition)
{
float[] floatMatrix = MatrixUtils.GetMatrixArray(ref mem);
float w = 0.0F;
screenPosition.X = floatMatrix[0] * position.x + floatMatrix[1] * position.y + floatMatrix[2] * position.z + floatMatrix[3];
screenPosition.Y = floatMatrix[4] * position.x + floatMatrix[5] * position.y + floatMatrix[6] * position.z + floatMatrix[7];
w = floatMatrix[12] * position.x + floatMatrix[13] * position.y + floatMatrix[14] * position.z + floatMatrix[15];
if (w < 0.1F)
return false;
float inv = 1.0F / w;
screenPosition.X *= inv;
screenPosition.Y *= inv;
int width = Screen.PrimaryScreen.Bounds.Width;
int height = Screen.PrimaryScreen.Bounds.Height;
float x = width / 2;
float y = height / 2;
x += (float)(0.5F * screenPosition.X * width + 0.5F);
y -= (float)(0.5F * screenPosition.Y * height + 0.5F);
screenPosition.X = x + this.Left;
screenPosition.Y = y + this.Top;
return true;
}
I have also attached the image of the information from the tables outputted onto my overlay. Thank you for the help.