❓ How to update an hack
i have this source code and what do i do to update this hack?
Code:
#include <Windows.h>
#include <String>
#include "Misc.h"
//Pointers
cg_t *pCG=(cg_t*)0x2E488E80;
refdef_t *pRefDef=(refdef_t*)0x2E4D6710;
entity_t *pEntity=(entity_t*)0x2E52DCC0;
client_t *pClient=(client_t*)0x2E4F28D0;
w2s_t *pW2S=(w2s_t*)0x1238948;
//Engine functions
int(*CG_IsVisible)(int a1,entity_t *pEntity)=(int(__cdecl*)(int,entity_t*))0x60A1E0;
int(*R_RegisterTag)(char *szName)=(int(__cdecl*)(char*))0x496490;
DWORD(*CG_GetPlayerMesh)(int iClientNum,int a2)=(DWORD(__cdecl*)(int,int))0x53E850;
signed int(*CG_GetTagPos)(entity_t *pEntity,DWORD dwMeshResult,int iTag,float *flOut)=(signed int(__cdecl*)(entity_t*,DWORD,int,float*))0x65E940;
weaponinfo_t*(*CG_GetWeaponInfo)(BYTE bWeaponID)=(weaponinfo_t*(__cdecl*)(BYTE))0x53DFF0;
int(*CG_DrawEngineText)(char *szText,int iMaxStrLen,void *pFont,float x,float y,float flScaleX,float flScaleY,float a8,float* pColor,int iFlags)=(int(__cdecl *)(char*,int,void*,float,float,float,float,float,PFLOAT,int ))0x6F1FD0;
int(*CG_StrWidth)(int a1,char *szString,int iMaxLen,void *pFont)=(int(__cdecl*)(int,char*,int,void*))0x714AD0;
int(*CG_StrHeight)(void *pFont)=(int(__cdecl*)(void*))0x47FAB0;
void*(*R_RegisterFont)(char *szFontName)=(void*(__cdecl*)(char*))0x4D3140;
shader_t*(*R_RegisterShader)(char *szName,int a2)=(shader_t*(__cdecl*)(char*,int))0x715740;
SIZE_T(*CG_DrawStretchPic)(float x,float y,float w,float h,float a5,float a6,float a7,float a8,float *flColor,shader_t *pShader)=(SIZE_T(__cdecl*)(float,float,float,float,float,float,float,float,float*,shader_t*))0x6F1A60;
SIZE_T(*CG_DrawRotatedPic)(DWORD *pScreenMatrix,float x,float y,float w,float h,float flAngle,float *flColor,shader_t *pShader)=(SIZE_T(__cdecl*)(DWORD*,float,float,float,float,float,float*,shader_t*))0x472EF0;
#define StrHeight CG_StrHeight(R_RegisterFont(DEFAULT_FONT))-4
//Misc
#define DEFAULT_FONT "fonts/smalldevfont"
HANDLE hExceptionHandler=INVALID_HANDLE_VALUE;
DWORD dwDVar=0x1025B88; //cg_drawFPS - one of MANY DVars, this one do draw above everything (including when ur not even ingame) without having to change retaddrs etc.
DWORD dwRestoreDVar=0x0;
color_t rgb(int r,int g,int b)
{
color_t tmp={r,g,b,255};
return tmp;
}
color_t rgb(int r,int g,int b,int a)
{
color_t tmp={r,g,b,a};
return tmp;
}
//Vector math
#define POW(x) ((x) * (x))
#define DotProduct(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
#define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
#define VectorDistance(a,b) (sqrt(POW(a[0]-b[0]) + POW(a[1]-b[1]) + POW(a[2]-b[2])))
#define ScreenDistance(a,b) (sqrt(POW(a[0]-b[0]) + POW(a[1]-b[1])))
#define DistanceBox(a,b,c) ((c*((float)(*(int*)0x2A81000))/pRefDef->flFOV) * 18.0f / (VectorDistance(a,b)/55.0f))
//Engine W2S
bool WorldToScreen(float *flLocation,float *flOut)
{
Vector vLocal;
VectorSubtract(flLocation,pRefDef->vViewOrg,vLocal);
float flZ = DotProduct(pRefDef->vViewAxis[0],vLocal);
float flX = DotProduct(pRefDef->vViewAxis[1],vLocal);
float flY = DotProduct(pRefDef->vViewAxis[2],vLocal);
if(flZ>=0.0)
{
float flTmp=1.0f/flZ;
float flCenterX=pW2S->Width * 0.5f;
float flCenterY=pW2S->Height * 0.5f;
flOut[0] = ((1.0f - (flX / pRefDef->flFOVX * flTmp)) * flCenterX) + pW2S->ukn1;
flOut[1] = ((*(float*)0xC027B4 - (flY / pRefDef->flFOVY * flTmp)) * flCenterY) + pW2S->ukn2;
return true;
}
return false;
}
/* This is also the same, but the above one is 100% like engine does it
bool WorldToScreen(float *flLocation,float *flOut)
{
Vector vLocal;
VectorSubtract(flLocation,pRefDef->vViewOrg,vLocal);
float flZ = DotProduct(pRefDef->vViewAxis[0],vLocal);
float flX = DotProduct(pRefDef->vViewAxis[1],vLocal);
float flY = DotProduct(pRefDef->vViewAxis[2],vLocal);
if(flZ>=0.0f)
{
float flTmp=1.0f/flZ;
flOut[0] = (1.0f - (flX / pRefDef->flFOVX * flTmp)) * ((float)pRefDef->iWidth/2);
flOut[1] = (1.0f - (flY / pRefDef->flFOVY * flTmp)) * ((float)pRefDef->iHeight/2);
return true;
}
return false;
}*/
//Get Tag Pos
bool GetTagPos(entity_t *pEntity,char *szBone,float *flOut)
{
short shBone=R_RegisterTag(szBone); //Register bone
DWORD dwMesh=CG_GetPlayerMesh(pEntity->iClientNum,pEntity->iUsedForPlayerMesh_0); //pEntity->iUsedForPlayerMesh_0 seems to be 0 always, perhaps its used for special entities?
if(dwMesh && shBone && CG_GetTagPos(pEntity,dwMesh,shBone,flOut))
return true;
return false;
}
//Draw Rotated Stretch Pic
void DrawRotatedShader(bool bCenter,int x,int y,int w,int h,float flAngle,color_t clrColor,shader_t *pShader)
{
if(bCenter)
{
x-=w/2;
y-=h/2;
}
if(!pShader)
pShader=R_RegisterShader("white",7);
float flColor[4]={(float)clrColor.r/255.0f,(float)clrColor.g/255.0f,(float)clrColor.b/255.0f,(float)clrColor.a/255.0f};
CG_DrawRotatedPic((DWORD*)0x12389C8,(float)x,(float)y,(float)w,(float)h,flAngle,flColor,pShader);
}
//Draw Engine String
void DrawEngineString(bool bCenter,int x,int *y,color_t clrColor,char *szString,...)
{
char szBuf[500];
va_list valist;
va_start(valist,szString);
_vsnprintf_s(szBuf,sizeof(szBuf),szString,valist);
va_end(valist);
int iWidth=CG_StrWidth(0,szBuf,0x7FFFFFFF,R_RegisterFont(DEFAULT_FONT));
if(bCenter)
x-=iWidth/2;
//tint a background (since its only used for ESP)
DrawRotatedShader(false,x-2,*y,iWidth+4,StrHeight,0,rgb(0,0,0,128),0);
float flColor[4]={(float)clrColor.r/255.0f,(float)clrColor.g/255.0f,(float)clrColor.b/255.0f,(float)clrColor.a/255.0f};
CG_DrawEngineText(szBuf,0x7FFFFFFF,R_RegisterFont(DEFAULT_FONT),(float)x-1,(float)*y+StrHeight+1,1.0f,1.0f,0,flColor,FL_FONT_SHADOW);
*y-=(StrHeight+2);
}
//Draw a box around player and return height of the box in pixels
int VectorToScreenDistance(float *flOrigin1,float *flOrigin2)
{
Vector vScreen1,vScreen2;
WorldToScreen(flOrigin1,vScreen1);
WorldToScreen(flOrigin2,vScreen2);
return (int)ScreenDistance(vScreen1,vScreen2);
}
//Get player color
color_t GetEntityColor(entity_t *pEntity)
{
int iMyTeam=pClient[pCG->iClientNum].iTeam;
int iTeam=pClient[pEntity->iClientNum].iTeam;
bool bVisible=(CG_IsVisible(0,pEntity)==1);
if(iMyTeam==iTeam && iMyTeam!=0)
{
if(bVisible) return rgb(128,255,50);
return rgb(50,128,255);
}
if(bVisible) return rgb(255,255,50);
return rgb(255,50,50);
}
//Draw a box around player
int DrawPlayerBox(entity_t *pEntity,color_t clrColor)
{
Vector vTop;
Vector vBot=pEntity->vOrigin;
if(!GetTagPos(pEntity,"j_helmet",vTop))
return 0;
vTop.z+=10;
vBot.z-=5;
int iDistance=VectorToScreenDistance(vTop,vBot);
int iWidth=(int)DistanceBox(pRefDef->vViewOrg,vTop,25);
if(pEntity->iFlags&FL_CROUCH)
iWidth=(int)DistanceBox(pRefDef->vViewOrg,vTop,35);
Vector vScreen;
if(WorldToScreen(vTop,vScreen))
{
int x=(int)vScreen[0]-iWidth/2;
int y=(int)vScreen[1];
DrawRotatedShader(false,x-1,y,1,iDistance,0,clrColor,0);
DrawRotatedShader(false,x+iWidth,y,1,iDistance,0,clrColor,0);
DrawRotatedShader(false,x-1,y-1,iWidth+2,1,0,clrColor,0);
DrawRotatedShader(false,x-1,y+iDistance,iWidth+2,1,0,clrColor,0);
return iDistance;
}
return 0;
}
void Draw_On_Screen()
{
Vector vScreen;
//Loop through 18 entities/clients (players)
for(int i=0;i<18;++i)
{
int iBoxHeight=0;
entity_t *pEnt=&pEntity[i]; //Create a temporary pointer to make life easier
client_t *pCli=&pClient[i]; //Create a temporary pointer to make life easier
if(!(pEnt->bAlive&2) || pEnt->bEntityType!=ET_PLAYER || pEnt->iClientNum==pCG->iClientNum || !WorldToScreen(pEnt->vOrigin,vScreen)) //Validity check
continue;
//Get player color
color_t clrTeam=GetEntityColor(pEnt);
if(!(iBoxHeight=DrawPlayerBox(pEnt,clrTeam)))
continue;
//Set x position
int x=(int)vScreen[0];
//Set y position to under the box
int y=(int)vScreen[1]+10;
//Weapon shader
if(pEnt->iWeaponID && CG_GetWeaponInfo(pEnt->iWeaponID)->pWeapon2)
{
int iWpnWidth=(int)DistanceBox(pRefDef->vViewOrg,pEnt->vOrigin,280);
int iWpnHeight=(int)DistanceBox(pRefDef->vViewOrg,pEnt->vOrigin,140);
if(iWpnWidth>80) iWpnWidth=80;
if(iWpnHeight>40) iWpnHeight=40;
if(iWpnWidth<50) iWpnWidth=50;
if(iWpnHeight<25) iWpnHeight=25;
DrawRotatedShader(false,x-iWpnWidth/2,y,iWpnWidth,iWpnHeight,0,rgb(clrTeam.r,clrTeam.g,clrTeam.b,200),CG_GetWeaponInfo(pEnt->iWeaponID)->pWeapon2->pShader);
}
//Set y position to above box (where strings will be)
y-=(iBoxHeight + StrHeight + 12);
//Weapon
if(pEnt->iWeaponID && CG_GetWeaponInfo(pEnt->iWeaponID)->szName)
DrawEngineString(true,x,&y,rgb(255,255,255),CG_GetWeaponInfo(pEnt->iWeaponID)->szWeaponName);
//Name
DrawEngineString(true,x,&y,clrTeam,pCli->szName);
//Distance
DrawEngineString(true,x,&y,clrTeam,"%.0f^3m",VectorDistance(pRefDef->vViewOrg,pEnt->vOrigin)/55.0f);
}
}
DWORD dwRetAddr=0x7CF1D0; //The original ret addr
__declspec(naked)void HUD_DrawGate() //Complete and utterly unnecesary. but im gonna do it anyways as an example..
{
__asm PUSHAD;
Draw_On_Screen(); //Call our function
__asm POPAD;
__asm JMP [dwRetAddr]; //Go back to whatever function that was supposed to be called
}
long __stdcall pExceptionHandler(_EXCEPTION_POINTERS *pException)
{
//Eip is at exception location (inside some kinda DVar function that checks for 0 pointers lul)
//Compare ESP to retaddr incase of more exceptions using same DVar function, note, there are quite a few DVar functions:P
//If your planning on using only one exception (drawing) then its no point comparing retaddr :P
if(pException->ContextRecord->Eip==0x5792A9 && *(DWORD*)pException->ContextRecord->Esp==0x7CF1D0)
{
pException->ContextRecord->Eax=dwRestoreDVar; //Restore Eax to DVar
Draw_On_Screen(); //Call it directly, this is enough for drawing since this is most likely in EndFrame (havent checked)
return EXCEPTION_CONTINUE_EXECUTION;
//Here are a few other example methods (there are more ways to do it! explore and have fun):
*(DWORD*)pException->ContextRecord->Esp=(DWORD)HUD_DrawGate; //Change ret addr from the dvar function to ours
//or change ret addr at the very end of the function (Not DVar) to our function
dwRetAddr=*(DWORD*)(pException->ContextRecord->Esp+0x38); //set RetAddr to whatever return address there is so that we can jump to that after our function has been called
*(DWORD*)(pException->ContextRecord->Esp+0x38)=(DWORD)HUD_DrawGate; //Set return address to our function
}
return EXCEPTION_CONTINUE_SEARCH;
}
int __stdcall DllMain(_In_ HANDLE _HDllHandle, _In_ DWORD _Reason, _In_opt_ LPVOID _Reserved)
{
if(_Reason==DLL_PROCESS_ATTACH)
{
hExceptionHandler=AddVectoredExceptionHandler(1,pExceptionHandler); //Set handle to our exception handler and add it (reason we set a handle to it is because we want to remove it)
dwRestoreDVar=*(DWORD*)dwDVar; //Set RestoreDVar to whatever value DVar is holding
*(DWORD*)dwDVar=1; //Invalidate pointer to create an exception
return 1;
}
if(_Reason==DLL_PROCESS_DETACH)
{
while(*(DWORD*)dwDVar==1) //Make sure DVar is restored before removing exceptionhandler
*(DWORD*)dwDVar=dwRestoreDVar;
RemoveVectoredExceptionHandler(hExceptionHandler); //Remove exception handler
}
return 0;
}
