Solved W2S Math not right?

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

HexMurder

Arcane Hacker
Dank Tier VIP
Dank Tier Donator
Jun 7, 2012
319
7,988
22
Hey guys. I was going to keep this a secret until release but now i need help so... No more secret. I am working on an esp for zombies in call of duty. I have wanted to make one of these for probably close to 6 or 7 years but never had the ability too until now. The problem i'm having is this. The W2S function seems to work up close. But when i get far away from zombies the w2s is drawing way off of the actual zombie. I provided some screenshots to help explain what i'm talking about.

Up close: (1776x1024)


Further away. You can see how off it is. (1776x1024)


If i lower the resolution this effect becomes even worse. (this is down to 1440x900)


Similar scenario but on 1920x1080


As you can see it seems to work as expected in 1080p, and not in other resolutions.

So now let me provide some information. I use this same w2s in csgo. I believe it also has a res scaling problem.
(here is said w2s func - C# btw)
C++:
public static bool WorldToScreen(Vec3 from, ref Engine.Point<float> to)
        {
            float w = 0.0f;

            to.X = Player.WorldToScreenMatrix.flMatrix[0, 0] * from.x + Player.WorldToScreenMatrix.flMatrix[0, 1] * from.y + Player.WorldToScreenMatrix.flMatrix[0, 2] * from.z + Player.WorldToScreenMatrix.flMatrix[0, 3];
            to.Y = Player.WorldToScreenMatrix.flMatrix[1, 0] * from.x + Player.WorldToScreenMatrix.flMatrix[1, 1] * from.y + Player.WorldToScreenMatrix.flMatrix[1, 2] * from.z + Player.WorldToScreenMatrix.flMatrix[1, 3];
            w = Player.WorldToScreenMatrix.flMatrix[3, 0] * from.x + Player.WorldToScreenMatrix.flMatrix[3, 1] * from.y + Player.WorldToScreenMatrix.flMatrix[3, 2] * from.z + Player.WorldToScreenMatrix.flMatrix[3, 3];
            if (w < 0.01f)
                return false;

            float invw = 1.0f / w;
            to.X *= invw;
            to.Y *= invw;

            int width = (int)(rect.right - rect.left);
            int height = (int)(rect.bottom - rect.top);

            float x = width / 2;
            float y = height / 2;

            x += 0.5f * to.X * width + 0.5f;
            y -= 0.5f * to.Y * height + 0.5f;

            to.X = x + rect.left;
            to.Y = y + rect.top;

            return true;
        }
Now i thought the rect may be giving the wrong width/height values but upon debugging i found that they are correct.

Is it possible i am using the wrong viewmatrix? I tested literally HUNDREDS of addresses that could potentially be the viewmatrix and this is the only one that seems to be right.
(really don't think viewmatrix is the problem.)

Thanks for your help. This is a loaded question so help would be very much appreciated!
If you help me solve this problem, your name will be included in the hack when i release this publicly.

EDIT:
should also add how i am drawing the line to the zombies.
C++:
if (Engine.WorldToScreen(Engine.zombie[i].position, ref W2S_FEET))
                    {
                        DrawLine(W2S_FEET.X, W2S_FEET.Y, (Engine.rect.right - Engine.rect.left) / 2, Engine.rect.bottom, 2, Color.Aqua);
                    }
 
Last edited:

HexMurder

Arcane Hacker
Dank Tier VIP
Dank Tier Donator
Jun 7, 2012
319
7,988
22
Rake;45298 said:
I notice that the HexMurder text always ends up in correct place when you stop moving the window. But your ESP boxes do not. So what is your ESP boxes code doing that your text draw in the top left isn't doing? I think that is the fastest way to identify the problem

Once the initilization begins and the dx thread starts, everything is executing in one thread?

Inside the private void timer1_Tick() and Overlay_Load() functions I don't know if the Engine.rect variable is up to date or not, it seems to only assign values but never retrieve them using GetWindowRect

Holy fuck i fixed it. Seriously one of the biggest programming headaches i have ever had. i NEVER post my code and ask for help.
The problem was this:
(last 2 lines of both of our w2s funcs)
//to.X += rect.left;
//to.Y += rect.top;

i commented those out and it works like a charm. Obviously i'm adding these again somewhere else. I don't know where, and i don't care because it works now. Thank fucking god. How do you want to be addressed in the credits homie? Rake, Rake, Rake from guided hacking? lol. I wouldn't have fixed this without what you just pointed out, so your name is going in my hack somewhere lol.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,153
78,998
2,396
Damn I remember you were having similar issues a few months ago with this :( I think your viewmatrix is ok. I'm curious, what if you just draw a dot instead of a line? Is this a GDI overlay?
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,153
78,998
2,396
I modified your code to use the same logic as my world2screen:
C++:
public static bool WorldToScreen(Vec3 from, ref Engine.Point<float> to)
{
	float w = 0.0f;
	
	Vec3 clipCoords;

	clipCoords.X = Player.WorldToScreenMatrix.flMatrix[0, 0] * from.x + Player.WorldToScreenMatrix.flMatrix[0, 1] * from.y + Player.WorldToScreenMatrix.flMatrix[0, 2] * from.z + Player.WorldToScreenMatrix.flMatrix[0, 3];
	clipCoords.Y = Player.WorldToScreenMatrix.flMatrix[1, 0] * from.x + Player.WorldToScreenMatrix.flMatrix[1, 1] * from.y + Player.WorldToScreenMatrix.flMatrix[1, 2] * from.z + Player.WorldToScreenMatrix.flMatrix[1, 3];
	w = Player.WorldToScreenMatrix.flMatrix[3, 0] * from.x + Player.WorldToScreenMatrix.flMatrix[3, 1] * from.y + Player.WorldToScreenMatrix.flMatrix[3, 2] * from.z + Player.WorldToScreenMatrix.flMatrix[3, 3];
	
	if (w < 0.01f)
		return false;
	
	Vec3 NDC;
	NDC.x = clipCoords.x / clipCoords.w;
	NDC.y = clipCoords.y / clipCoords.w;
	NDC.z = clipCoords.z / clipCoords.w;

	int width = (int)(rect.right - rect.left);
	int height = (int)(rect.bottom - rect.top);

	to.x = (width / 2 * NDC.x) + (NDC.x + width / 2);
	to.y = -(height / 2 * NDC.y) + (NDC.y + height / 2);

	to.X += rect.left;
	to.Y += rect.top;

	return true;
}
Give that a shot. Also if you have multiple position variables such as the camera position or the eye position as opposed to the body/gun position try those as well, but I think you've already tried that cuz you're a smart fella
 

HexMurder

Arcane Hacker
Dank Tier VIP
Dank Tier Donator
Jun 7, 2012
319
7,988
22
Rake;45284 said:
I modified your code to use the same logic as my world2screen:
C++:
public static bool WorldToScreen(Vec3 from, ref Engine.Point<float> to)
{
	float w = 0.0f;
	
	Vec3 clipCoords;

	clipCoords.X = Player.WorldToScreenMatrix.flMatrix[0, 0] * from.x + Player.WorldToScreenMatrix.flMatrix[0, 1] * from.y + Player.WorldToScreenMatrix.flMatrix[0, 2] * from.z + Player.WorldToScreenMatrix.flMatrix[0, 3];
	clipCoords.Y = Player.WorldToScreenMatrix.flMatrix[1, 0] * from.x + Player.WorldToScreenMatrix.flMatrix[1, 1] * from.y + Player.WorldToScreenMatrix.flMatrix[1, 2] * from.z + Player.WorldToScreenMatrix.flMatrix[1, 3];
	w = Player.WorldToScreenMatrix.flMatrix[3, 0] * from.x + Player.WorldToScreenMatrix.flMatrix[3, 1] * from.y + Player.WorldToScreenMatrix.flMatrix[3, 2] * from.z + Player.WorldToScreenMatrix.flMatrix[3, 3];
	
	if (w < 0.01f)
		return false;
	
	Vec3 NDC;
	NDC.x = clipCoords.x / clipCoords.w;
	NDC.y = clipCoords.y / clipCoords.w;
	NDC.z = clipCoords.z / clipCoords.w;

	int width = (int)(rect.right - rect.left);
	int height = (int)(rect.bottom - rect.top);

	to.x = (width / 2 * NDC.x) + (NDC.x + width / 2);
	to.y = -(height / 2 * NDC.y) + (NDC.y + height / 2);

	to.X += rect.left;
	to.Y += rect.top;

	return true;
}
Give that a shot. Also if you have multiple position variables such as the camera position or the eye position as opposed to the body/gun position try those as well, but I think you've already tried that cuz you're a smart fella
OK! i found out what the problem was! now i just have to fix it. Thanks very much for that w2s, works great. But that wasn't my problem unfortunately. I found out what was causing the alignment bug. But i have no idea how to fix it.
https://www.youtube.com/watch?v=Dpgn3F9opJc

I'm sure this is gonna be a bit much to look at but i figured i should include it so you could see how i am doing this directx overlay method.
(messy sorry)

C++:
public partial class Overlay : Form
    {
private Margins marg;
        internal struct Margins
        {
            public int Left, Right, Top, Bottom;
        }

        public IntPtr selectedWindow;
        public const string WINDOW_NAME = "Call of Duty®: BlackOps";

        IntPtr handle = FindWindow(null, WINDOW_NAME);


        [DllImport("user32.dll")]
        private static extern IntPtr GetForegroundWindow();

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetWindowRect(IntPtr hwnd, out Engine.RECT lpRect);

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);


        [DllImport("user32.dll", SetLastError = true)]

 public partial class Overlay : Form
    {
        private Margins marg;
        internal struct Margins
        {
            public int Left, Right, Top, Bottom;
        }

        public IntPtr selectedWindow;
        public const string WINDOW_NAME = "Call of Duty®: BlackOps";

        IntPtr handle = FindWindow(null, WINDOW_NAME);


        [DllImport("user32.dll")]
        private static extern IntPtr GetForegroundWindow();

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetWindowRect(IntPtr hwnd, out Engine.RECT lpRect);

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);


        [DllImport("user32.dll", SetLastError = true)]

        private static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("user32.dll")]

        static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

        [DllImport("user32.dll")]

        static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);

        public const int GWL_EXSTYLE = -20;

        public const int WS_EX_LAYERED = 0x80000;

        public const int WS_EX_TRANSPARENT = 0x20;

        public const int LWA_ALPHA = 0x2;

        public const int LWA_COLORKEY = 0x1;

        [DllImport("dwmapi.dll")]
        static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMargins);


        public static Engine.RECT GetWindowRect(IntPtr hWnd)
        {
            Engine.RECT result = new Engine.RECT();
            GetWindowRect(hWnd, out result);
            return result;
        }


        private Device device;
        private static D3D.Font font;
        private static D3D.Font fontSmall;

        private static D3D.Line line;

        public static Engine.Point<float> W2S_FEET = new Engine.Point<float>();
        public static Engine.Point<float> W2S_HEAD = new Engine.Point<float>();
        public static float boxWidth;
        public static float boxHeight;

        public Overlay()
        {
            InitializeComponent();
            Engine.rect = GetWindowRect(handle);//keeps updating if we move game around.
            selectedWindow = FindWindow(null, WINDOW_NAME);
            this.Size = new Size(Engine.rect.right - Engine.rect.left, Engine.rect.bottom - Engine.rect.top);
            

            //Make the window's border completely transparant
            SetWindowLong(this.Handle, GWL_EXSTYLE,
                    (IntPtr)(GetWindowLong(this.Handle, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT));
            //Set the Alpha on the Whole Window to 255 (solid)
            SetLayeredWindowAttributes(this.Handle, 0, 255, LWA_ALPHA);

            //This initializes the DirectX device. It needs to be done once.
            //The alpha channel in the backbuffer is critical.
            PresentParameters presentParameters = new PresentParameters();
            presentParameters.Windowed = true;
            presentParameters.SwapEffect = SwapEffect.Discard;
            presentParameters.BackBufferFormat = Format.A8R8G8B8;
            this.device = new Device(0, DeviceType.Hardware, this.Handle,
            CreateFlags.HardwareVertexProcessing, presentParameters);

          

            Thread dx = new Thread(new ThreadStart(this.dxThread));
            dx.IsBackground = true;
            dx.Start();
        }

        private void dxThread()
        {
            while (Engine.isRunning)
            {
                //Place your update logic here
                device.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1.0f, 0);
                device.RenderState.ZBufferEnable = false;
                device.RenderState.Lighting = false;
                device.RenderState.CullMode = Cull.None;
                device.Transform.Projection = Matrix.OrthoOffCenterLH(0, this.Width, this.Height, 0, 0, 1);
                device.BeginScene();

                //Place your rendering logic here
                GetWindowRect(handle, out Engine.rect);//keeps updating if we move game around.

                selectedWindow = FindWindow(null, WINDOW_NAME);
                //if (selectedWindow == GetForegroundWindow())
                {
                    DrawEsp();

                }

                device.EndScene();
                device.Present();
            }

            this.device.Dispose();
            Application.Exit();
        }

private void Overlay_Paint(object sender, PaintEventArgs e)//tried changing these margins and they seem to do nothing.
        {
            marg.Left = 0;
            marg.Top = 0;
            marg.Right = this.Width;
            marg.Bottom = this.Height;
            DwmExtendFrameIntoClientArea(this.Handle, ref marg);
        }

private void Overlay_Load(object sender, EventArgs e)//this alligns the overlay form over the games window on load.
        {
            this.Top = Engine.rect.top;
            this.Left = Engine.rect.left;
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)//this alligns the overlay form over the games windowevery 100ms in case we move it.
        {
            this.Top = Engine.rect.top;
            this.Left = Engine.rect.left;
        }
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,153
78,998
2,396
I notice that the HexMurder text always ends up in correct place when you stop moving the window. But your ESP boxes do not. So what is your ESP boxes code doing that your text draw in the top left isn't doing? I think that is the fastest way to identify the problem

Once the initilization begins and the dx thread starts, everything is executing in one thread?

Inside the private void timer1_Tick() and Overlay_Load() functions I don't know if the Engine.rect variable is up to date or not, it seems to only assign values but never retrieve them using GetWindowRect
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,153
78,998
2,396
The problem was this:
(last 2 lines of both of our w2s funcs)
//to.X += rect.left;
//to.Y += rect.top;
.
I was fairly certain that was the problem because you're already translating from screen to windows coordinates in the timer1_Tick() and Overlay_Paint() function. Glad we figured it out! You can credit me as Rake
 

HexMurder

Arcane Hacker
Dank Tier VIP
Dank Tier Donator
Jun 7, 2012
319
7,988
22
Rake;45314 said:
I was fairly certain that was the problem because you're already translating from screen to windows coordinates in the timer1_Tick() and Overlay_Paint() function. Glad we figured it out! You can credit me as Rake@GuidedHacking :) thanks
Any reason i can't leave a thanks on your posts? (perhaps i don't have enough posts myself?)

Edit: nvm...i found it lmao.
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods