Results 1 to 7 of 7
  1. #1
    itsicevenom's Avatar
    Join Date
    Aug 2018
    Gender
    male
    Posts
    4
    Reputation
    10
    Thanks
    0

    ESP in Painttraverse drawing in wrong position

    I made an esp that is supposed to draw the name of the player above their head. It does this the majority of the time, however sometimes it will draw the name in the center of their body (where there head would be if they were crouched). I position the text using eyepos and raising it by 10.

    Not working: https://imgur.com/a/LwNRFow
    Working: https://imgur.com/a/uBOTJhl

    Code:
    #include "Hooks.h"
    #include <codecvt>
    
    PaintTraverseFn oPaintTraverse;
    vgui::HFont hFont;
    
    
    
    void __stdcall Hooks::PaintTraverse(unsigned int panel, bool forceRepaint, bool allowForce)
    {
    	oPaintTraverse(Interfaces->Panel, panel, forceRepaint, allowForce);
    
    	{
    		static int drawPanel = 0;
    		if (!drawPanel)
    			if (!strcmp(Interfaces->Panel->GetName(panel), "MatSystemTopPanel"))
    				drawPanel = panel;
    			else
    				return;
    		if (drawPanel != panel)
    			return;
    	}
    
    	if (Config.esp)
    	{
    		CBaseEntity* local = (CBaseEntity*)Interfaces->ClientEntityList->GetClientEntity(Interfaces->EngineClient->GetLocalPlayer());
    
    		
    
    		for (size_t i = 1; i <= 64; i++)
    		{
    			CBaseEntity* entity = (CBaseEntity*)Interfaces->ClientEntityList->GetClientEntity(i);
    			if (entity && entity->IsPlayer() && entity->GetHealth() && !entity->IsDormant() && i != Interfaces->EngineClient->GetLocalPlayer() && entity->GetTeam() != local->GetTeam())
    			{
    				player_info_t pInfo;
    				if (!Interfaces->EngineClient->GetPlayerInfo(entity->EntIndex(), &pInfo))
    					return;
    
    				std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> convert;
    				std::wstring name = convert.from_bytes(pInfo.name);
    
    				const wchar_t* szName = name.c_str();
    
    				Vector feetpos, eyepos;
    				if (Math.WorldToScreen(entity->GetEyePos() + Vector(0, 0, 10), eyepos) && Math.WorldToScreen(entity->GetOrigin(), feetpos))
    				{
    					int width = (feetpos.y - eyepos.y) / 2;
    					int hight = (feetpos.y - eyepos.y);
    
    					if(!hFont)
    					{
    						hFont = Interfaces->Surface->CreateFont_();
    						Interfaces->Surface->SetFontGlyphSet(hFont, "Tahoma", 12, 200, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_OUTLINE);
    					}
    
    					int w, h;
    					Interfaces->Surface->DrawSetTextColor(255, 255, 255, 255);
    					Interfaces->Surface->DrawSetTextFont(hFont);
    					Interfaces->Surface->GetTextSize(hFont, szName, w, h);
    					Interfaces->Surface->DrawSetTextPos(eyepos.x - (w / 2), eyepos.y);
    					Interfaces->Surface->DrawPrintText(szName, (int)wcslen(szName), FONT_DRAW_DEFAULT);
    				}
    			}
    		}
    	}
    }

  2. #2
    DIA4A's Avatar
    Join Date
    Jan 2020
    Gender
    male
    Posts
    102
    Reputation
    19
    Thanks
    162
    How are you getting the eye position? Is it through m_vecOrigin + m_vecViewOffset or through the ShootPosition function? Also I suggest getting their actual bounding box and drawing with that, way more stable and overall a better idea imo

  3. #3
    itsicevenom's Avatar
    Join Date
    Aug 2018
    Gender
    male
    Posts
    4
    Reputation
    10
    Thanks
    0
    Quote Originally Posted by DIA4A View Post
    How are you getting the eye position? Is it through m_vecOrigin + m_vecViewOffset or through the ShootPosition function? Also I suggest getting their actual bounding box and drawing with that, way more stable and overall a better idea imo
    Through m_vecViewOffset and origin I made a bounding box and it had the same issue

  4. #4
    DIA4A's Avatar
    Join Date
    Jan 2020
    Gender
    male
    Posts
    102
    Reputation
    19
    Thanks
    162
    Quote Originally Posted by itsicevenom View Post
    Through m_vecViewOffset and origin I made a bounding box and it had the same issue
    Show me your WorldToScreen func

  5. #5
    itsicevenom's Avatar
    Join Date
    Aug 2018
    Gender
    male
    Posts
    4
    Reputation
    10
    Thanks
    0
    Quote Originally Posted by DIA4A View Post
    Show me your WorldToScreen func
    Code:
    bool CMath::WorldToScreen(const Vector& in, Vector& out)
    {
    	if (screen_transform(in, out)) {
    		int w, h;
    		Interfaces->EngineClient->GetScreenSize(w, h);
    
    		out.x = (w / 2.0f) + (out.x * w) / 2.0f;
    		out.y = (h / 2.0f) - (out.y * h) / 2.0f;
    
    		return true;
    	}
    	return false;
    }
    Code:
    bool CMath::screen_transform(const Vector& in, Vector& out)
    {
    	static auto& w2sMatrix = Interfaces->EngineClient->WorldToScreenMatrix();
    	
    	out.x = w2sMatrix.m[0][0] * in.x + w2sMatrix.m[0][1] * in.y + w2sMatrix.m[0][2] * in.z + w2sMatrix.m[0][3];
    	out.y = w2sMatrix.m[1][0] * in.x + w2sMatrix.m[1][1] * in.y + w2sMatrix.m[1][2] * in.z + w2sMatrix.m[1][3];
    	out.z = 0.0f;
    
    	float w = w2sMatrix.m[3][0] * in.x + w2sMatrix.m[3][1] * in.y + w2sMatrix.m[3][2] * in.z + w2sMatrix.m[3][3];
    
    	if (w < 0.001f) {
    		out.x *= 100000;
    		out.y *= 100000;
    		return false;
    	}
    
    	out.x /= w;
    	out.y /= w;
    
    	return true;
    }

    The worldtoscreenmatrix() is from IEngineClient

  6. #6
    DIA4A's Avatar
    Join Date
    Jan 2020
    Gender
    male
    Posts
    102
    Reputation
    19
    Thanks
    162
    Quote Originally Posted by itsicevenom View Post
    Code:
    bool CMath::WorldToScreen(const Vector& in, Vector& out)
    {
    	if (screen_transform(in, out)) {
    		int w, h;
    		Interfaces->EngineClient->GetScreenSize(w, h);
    
    		out.x = (w / 2.0f) + (out.x * w) / 2.0f;
    		out.y = (h / 2.0f) - (out.y * h) / 2.0f;
    
    		return true;
    	}
    	return false;
    }
    Code:
    bool CMath::screen_transform(const Vector& in, Vector& out)
    {
    	static auto& w2sMatrix = Interfaces->EngineClient->WorldToScreenMatrix();
    	
    	out.x = w2sMatrix.m[0][0] * in.x + w2sMatrix.m[0][1] * in.y + w2sMatrix.m[0][2] * in.z + w2sMatrix.m[0][3];
    	out.y = w2sMatrix.m[1][0] * in.x + w2sMatrix.m[1][1] * in.y + w2sMatrix.m[1][2] * in.z + w2sMatrix.m[1][3];
    	out.z = 0.0f;
    
    	float w = w2sMatrix.m[3][0] * in.x + w2sMatrix.m[3][1] * in.y + w2sMatrix.m[3][2] * in.z + w2sMatrix.m[3][3];
    
    	if (w < 0.001f) {
    		out.x *= 100000;
    		out.y *= 100000;
    		return false;
    	}
    
    	out.x /= w;
    	out.y /= w;
    
    	return true;
    }

    The worldtoscreenmatrix() is from IEngineClient
    Looks about right, might perhaps be your matrix struct

  7. #7
    itsicevenom's Avatar
    Join Date
    Aug 2018
    Gender
    male
    Posts
    4
    Reputation
    10
    Thanks
    0
    Quote Originally Posted by DIA4A View Post
    Looks about right, might perhaps be your matrix struct
    Im not sure, from what I can tell the issue only occurs when the enemy crouches.

Similar Threads

  1. [Help] Internal esp (Hooked painttraverse) What now :/ ?
    By jjjamer in forum Counter-Strike 2 Coding & Resources
    Replies: 6
    Last Post: 08-22-2015, 11:10 AM
  2. Esp and Spectator mode isn't showing players position in present.
    By arb612 in forum Garry's Mod Discussions & Help
    Replies: 6
    Last Post: 06-17-2013, 12:49 AM
  3. ESP Drawing
    By MaxSvett in forum C# Programming
    Replies: 7
    Last Post: 01-28-2013, 02:52 PM
  4. Esp Crashing Addies wrong?
    By c0ke187 in forum Combat Arms Coding Help & Discussion
    Replies: 1
    Last Post: 05-04-2011, 05:20 AM
  5. new esp hack.. somethings wrong.. help..
    By Valkyrri in forum Call of Duty Modern Warfare 2 Help
    Replies: 1
    Last Post: 02-12-2010, 11:01 PM