
https://www.unknowncheats.me/forum/counterstrike-1-5-1-6-and-mods/399009-hitbox-calculated-dynamic-esp-box.html


I just discovered that 
SetupPlayerModel(ent->index - 1) 
will return correct player model so that hitboxes has no bug, also PlayerInfo(id - 1), 
playermove pmove->player_index + 1 will return same index as GetLocalPlayer()->index

Code:
player_info_s* player = g_Studio.PlayerInfo(id - 1);
Code:

if (ent && ent->player)
	{
		model_t* pModel = g_Studio.SetupPlayerModel(ent->index - 1);
		if (!pModel)
			return;
		studiohdr_t* pStudioHeader = (studiohdr_t*)g_Studio.Mod_Extradata(pModel);
		mstudiobbox_t* pHitbox = (mstudiobbox_t*)((byte*)pStudioHeader + pStudioHeader->hitboxindex);
		mstudiobone_t* pbones = (mstudiobone_t*)((byte*)pStudioHeader + pStudioHeader->boneindex);
		BoneMatrix_t* pBoneMatrix = (BoneMatrix_t*)g_Studio.StudioGetBoneTransform();
 
		if (pBoneMatrix && pbones)
		{
			if (!g_Player[ent->index].bGotBonePlayer)
			{
				g_Player[ent->index].iMaxBones = pStudioHeader->numbones;
 
				for (unsigned int i = 0; i < pStudioHeader->numbones; i++)
				{
					g_PlayerExtraInfoList[ent->index].iParent[i] = pbones[i].parent;
					Vector origin;
					origin[0] = (*pBoneMatrix)[i][0][3];
					origin[1] = (*pBoneMatrix)[i][1][3];
					origin[2] = (*pBoneMatrix)[i][2][3];
					g_PlayerExtraInfoList[ent->index].vBone[i] = origin;
 
					origin[0] = (*pBoneMatrix)[pbones[i].parent][0][3];
					origin[1] = (*pBoneMatrix)[pbones[i].parent][1][3];
					origin[2] = (*pBoneMatrix)[pbones[i].parent][2][3];
					g_PlayerExtraInfoList[ent->index].vBoneParent[i] = origin;
				}
				g_Player[ent->index].bGotBonePlayer = true;
			}
		}
		if (pBoneMatrix && pHitbox)
		{
			if (!g_Player[ent->index].bGotHitboxPlayer)
			{
				g_Player[ent->index].iMaxHitboxes = pStudioHeader->numhitboxes;
 
				for (unsigned int i = 0; i < pStudioHeader->numhitboxes; i++)
				{
					Vector vBBMax, vBBMin, vCubePointsTrans[8], vCubePoints[8];
					Vector vEye = pmove->origin + pmove->view_ofs;
 
					VectorTransform(pHitbox[i].bbmin, (*pBoneMatrix)[pHitbox[i].bone], vBBMin);
					VectorTransform(pHitbox[i].bbmax, (*pBoneMatrix)[pHitbox[i].bone], vBBMax);
					g_PlayerExtraInfoList[ent->index].vHitbox[i] = (vBBMax + vBBMin) * 0.5f;
					g_PlayerExtraInfoList[ent->index].fHitboxFOV[i] = g_Local.vPrevForward.AngleBetween(g_PlayerExtraInfoList[ent->index].vHitbox[i] - vEye);
 
					vCubePoints[0] = Vector(pHitbox[i].bbmin.x, pHitbox[i].bbmin.y, pHitbox[i].bbmin.z);
					vCubePoints[1] = Vector(pHitbox[i].bbmin.x, pHitbox[i].bbmax.y, pHitbox[i].bbmin.z);
					vCubePoints[2] = Vector(pHitbox[i].bbmax.x, pHitbox[i].bbmax.y, pHitbox[i].bbmin.z);
					vCubePoints[3] = Vector(pHitbox[i].bbmax.x, pHitbox[i].bbmin.y, pHitbox[i].bbmin.z);
					vCubePoints[4] = Vector(pHitbox[i].bbmax.x, pHitbox[i].bbmax.y, pHitbox[i].bbmax.z);
					vCubePoints[5] = Vector(pHitbox[i].bbmin.x, pHitbox[i].bbmax.y, pHitbox[i].bbmax.z);
					vCubePoints[6] = Vector(pHitbox[i].bbmin.x, pHitbox[i].bbmin.y, pHitbox[i].bbmax.z);
					vCubePoints[7] = Vector(pHitbox[i].bbmax.x, pHitbox[i].bbmin.y, pHitbox[i].bbmax.z);
 
					for (unsigned int x = 0; x < 8; x++)
					{
						VectorTransform(vCubePoints[x], (*pBoneMatrix)[pHitbox[i].bone], vCubePointsTrans[x]);
						g_PlayerExtraInfoList[ent->index].vHitboxMulti[i][x] = vCubePointsTrans[x];
						g_PlayerExtraInfoList[ent->index].fHitboxPointsFOV[i][x] = g_Local.vPrevForward.AngleBetween(g_PlayerExtraInfoList[ent->index].vHitboxMulti[i][x] - vEye);
					}
				}
				g_Player[ent->index].bGotHitboxPlayer = true;
			}
		}
	}

