Skip to content

Commit

Permalink
update 25.07
Browse files Browse the repository at this point in the history
[add] tracing
[add] visible check example (search for "@note: this is a simple example of how to check if the player is visible")
[add] bone cache in CSkeletonInstance
[add] Matrix4x2 struct

[change] update product string version
  • Loading branch information
Exlodium committed Jul 25, 2024
1 parent f6ebdf7 commit 9f411b7
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cstrike/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* - used to verify game version
*/

#define CS_PRODUCTSTRINGVERSION CS_XOR("1.40.2.1")
#define CS_PRODUCTSTRINGVERSION CS_XOR("1.40.2.3")

/*
* game's modules
Expand Down
3 changes: 3 additions & 0 deletions cstrike/core/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ bool I::Setup()
PVS = reinterpret_cast<CPVS*>(MEM::ResolveRelativeAddress(MEM::FindPattern(ENGINE2_DLL, CS_XOR("48 8D 0D ? ? ? ? 33 D2 FF 50")), 0x3, 0x7));
bSuccess &= (PVS != nullptr);

GameTraceManager = *reinterpret_cast<CGameTraceManager**>(MEM::GetAbsoluteAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("4C 8B 3D ? ? ? ? 24 C9 0C 49 66 0F 7F 45 ?")), 0x3, 0x0));
bSuccess &= (GameTraceManager != nullptr);

return bSuccess;
}

Expand Down
2 changes: 2 additions & 0 deletions cstrike/core/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class IMaterialSystem2;
class IResourceSystem;
class CResourceHandleUtils;
class CPVS;
class CGameTraceManager;

// [d3d] struct
struct ID3D11Device;
Expand Down Expand Up @@ -74,4 +75,5 @@ namespace I
inline IResourceSystem* ResourceSystem = nullptr;
inline CResourceHandleUtils* ResourceHandleUtils = nullptr;
inline CPVS* PVS = nullptr;
inline CGameTraceManager* GameTraceManager = nullptr;
}
2 changes: 2 additions & 0 deletions cstrike/cstrike.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
<ClInclude Include="features\visuals.h" />
<ClInclude Include="features\visuals\chams.h" />
<ClInclude Include="features\visuals\overlay.h" />
<ClInclude Include="sdk\interfaces\cgametracemanager.h" />
<ClInclude Include="sdk\interfaces\ipvs.h" />
<ClInclude Include="sdk\const.h" />
<ClInclude Include="sdk\datatypes\color.h" />
Expand Down Expand Up @@ -226,6 +227,7 @@
<ClCompile Include="..\dependencies\minhook\hde\hde64.c" />
<ClCompile Include="..\dependencies\minhook\hook.c" />
<ClCompile Include="..\dependencies\minhook\trampoline.c" />
<ClCompile Include="sdk\interfaces\cgametracemanager.cpp" />
<ClCompile Include="core.cpp" />
<ClCompile Include="core\config.cpp" />
<ClCompile Include="core\convars.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions cstrike/cstrike.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@
<ClInclude Include="sdk\interfaces\ipvs.h">
<Filter>sdk\interfaces</Filter>
</ClInclude>
<ClInclude Include="sdk\interfaces\cgametracemanager.h">
<Filter>sdk\interfaces</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\dependencies\imgui\imgui.cpp">
Expand Down Expand Up @@ -421,5 +424,8 @@
<Filter>utilities</Filter>
</ClCompile>
<ClCompile Include="sdk\datatypes\keyvalues3.cpp" />
<ClCompile Include="sdk\interfaces\cgametracemanager.cpp">
<Filter>sdk\interfaces</Filter>
</ClCompile>
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions cstrike/features/visuals/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "../../sdk/entity.h"
#include "../../sdk/interfaces/cgameentitysystem.h"
#include "../../sdk/interfaces/iengineclient.h"
#include "../../sdk/interfaces/cgametracemanager.h"

// used: sdk variables
#include "../../core/sdk.h"
Expand Down Expand Up @@ -573,6 +574,20 @@ void OVERLAY::Player(CCSPlayerController* pLocal, CCSPlayerController* pPlayer,
if (pLocalPawn == nullptr || pPlayerPawn == nullptr)
return;

// @note: this is a simple example of how to check if the player is visible

// initialize trace, construct filterr and initialize ray
//GameTrace_t trace = GameTrace_t();
//TraceFilter_t filter = TraceFilter_t(0x1C3003, pLocalPawn, nullptr, 4);
//Ray_t ray = Ray_t();

// cast a ray from local player eye positon -> player head bone
// @note: would recommend checking for nullptrs
//I::GameTraceManager->TraceShape(&ray, pLocalPawn->GetEyePosition(), pPlayerPawn->GetGameSceneNode()->GetSkeletonInstance()->pBoneCache->GetOrigin(6), &filter, &trace);
// check if the hit entity is the one we wanted to check and if the trace end point is visible
//if (trace.m_pHitEntity != pPlayerPawn || !trace.IsVisible( ))
// return;

bool bIsEnemy = (pLocalPawn->IsOtherEnemy(pPlayerPawn));

// @note: only enemy overlay for now
Expand Down
66 changes: 65 additions & 1 deletion cstrike/sdk/datatypes/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,68 @@ struct ViewMatrix_t
float arrData[4][4] = {};
};

#pragma pack(pop)
#pragma pack(pop)

struct Matrix4x2_t
{
public:
Matrix3x4_t TranslateToMatrix3x4()
{
Matrix3x4_t matrix = Matrix3x4_t();
Vector4D_t vecRotation = Vector4D_t();
Vector_t vecPosition = Vector_t();

vecRotation.x = this->_21; //rot.x
vecRotation.y = this->_22; //rot.y
vecRotation.z = this->_23; //rot.z
vecRotation.w = this->_24; //rot.w

vecPosition.x = this->_11; //bonepos.x
vecPosition.y = this->_12; //bonepos.y
vecPosition.z = this->_13; //bonepos.z

matrix[0][0] = 1.0f - 2.0f * vecRotation.y * vecRotation.y - 2.0f * vecRotation.z * vecRotation.z;
matrix[1][0] = 2.0f * vecRotation.x * vecRotation.y + 2.0f * vecRotation.w * vecRotation.z;
matrix[2][0] = 2.0f * vecRotation.x * vecRotation.z - 2.0f * vecRotation.w * vecRotation.y;

matrix[0][1] = 2.0f * vecRotation.x * vecRotation.y - 2.0f * vecRotation.w * vecRotation.z;
matrix[1][1] = 1.0f - 2.0f * vecRotation.x * vecRotation.x - 2.0f * vecRotation.z * vecRotation.z;
matrix[2][1] = 2.0f * vecRotation.y * vecRotation.z + 2.0f * vecRotation.w * vecRotation.x;

matrix[0][2] = 2.0f * vecRotation.x * vecRotation.z + 2.0f * vecRotation.w * vecRotation.y;
matrix[1][2] = 2.0f * vecRotation.y * vecRotation.z - 2.0f * vecRotation.w * vecRotation.x;
matrix[2][2] = 1.0f - 2.0f * vecRotation.x * vecRotation.x - 2.0f * vecRotation.y * vecRotation.y;

matrix[0][3] = vecPosition.x;
matrix[1][3] = vecPosition.y;
matrix[2][3] = vecPosition.z;

return matrix;
}

[[nodiscard]] const Vector_t GetOrigin(int nIndex)
{
return Vector_t(this[nIndex]._11, this[nIndex]._12, this[nIndex]._13);
}

const void SetOrigin(int nIndex, Vector_t vecValue)
{
this[nIndex]._11 = vecValue.x;
this[nIndex]._12 = vecValue.y;
this[nIndex]._13 = vecValue.z;
}

[[nodiscard]] const Vector4D_t GetRotation(int nIndex)
{
return Vector4D_t(this[nIndex]._21, this[nIndex]._22, this[nIndex]._23, this[nIndex]._24);
}

union
{
struct
{
float _11, _12, _13, _14;
float _21, _22, _23, _24;
};
};
};
18 changes: 18 additions & 0 deletions cstrike/sdk/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ bool C_CSPlayerPawn::CanAttack(const float flServerTime)
return true;
}


std::uint32_t C_CSPlayerPawn::GetOwnerHandleIndex()
{
std::uint32_t Result = -1;
if (this && GetCollision() && !(GetCollision()->GetSolidFlags() & 4))
Result = this->GetOwnerHandle().GetEntryIndex();

return Result;
}

std::uint16_t C_CSPlayerPawn::GetCollisionMask()
{
if (this && GetCollision())
return GetCollision()->CollisionMask(); // Collision + 0x38

return 0;
}

bool C_CSWeaponBaseGun::CanPrimaryAttack(const int nWeaponType, const float flServerTime)
{
// check are weapon support burst mode and it's ready to attack
Expand Down
26 changes: 24 additions & 2 deletions cstrike/sdk/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,18 @@ class CEntityInstance
class CCollisionProperty
{
public:
std::uint16_t CollisionMask()
{
return *reinterpret_cast<std::uint16_t*>(reinterpret_cast<std::uintptr_t>(this) + 0x38);
}

CS_CLASS_NO_INITIALIZER(CCollisionProperty);

SCHEMA_ADD_FIELD(Vector_t, GetMins, "CCollisionProperty->m_vecMins");
SCHEMA_ADD_FIELD(Vector_t, GetMaxs, "CCollisionProperty->m_vecMaxs");

SCHEMA_ADD_FIELD(std::uint8_t, GetSolidFlags, "CCollisionProperty->m_usSolidFlags");
SCHEMA_ADD_FIELD(std::uint8_t, GetCollisionGroup, "CCollisionProperty->m_CollisionGroup");
};

class CSkeletonInstance;
Expand Down Expand Up @@ -142,7 +150,7 @@ class C_BaseEntity : public CEntityInstance
if (pClassInfo == nullptr)
return false;

return (pClassInfo->InheritsFrom(pWeaponBaseClass));
return (pClassInfo->InheritsFrom(pWeaponBaseClass));
}

static C_BaseEntity* GetLocalPlayer();
Expand Down Expand Up @@ -208,6 +216,13 @@ class C_BasePlayerPawn : public C_BaseModelEntity
SCHEMA_ADD_FIELD(CCSPlayer_WeaponServices*, GetWeaponServices, "C_BasePlayerPawn->m_pWeaponServices");
SCHEMA_ADD_FIELD(CPlayer_ItemServices*, GetItemServices, "C_BasePlayerPawn->m_pItemServices");
SCHEMA_ADD_FIELD(CPlayer_CameraServices*, GetCameraServices, "C_BasePlayerPawn->m_pCameraServices");

[[nodiscard]] Vector_t GetEyePosition()
{
Vector_t vecEyePosition = Vector_t(0.0f, 0.0f, 0.0f);
MEM::CallVFunc<void, 166U>(this, &vecEyePosition);
return vecEyePosition;
}
};

class CCSPlayer_ViewModelServices;
Expand All @@ -233,6 +248,8 @@ class C_CSPlayerPawn : public C_CSPlayerPawnBase
[[nodiscard]] bool IsOtherEnemy(C_CSPlayerPawn* pOther);
[[nodiscard]] int GetAssociatedTeam();
[[nodiscard]] bool CanAttack(const float flServerTime);
[[nodiscard]] std::uint32_t GetOwnerHandleIndex();
[[nodiscard]] std::uint16_t GetCollisionMask();

SCHEMA_ADD_FIELD(bool, IsScoped, "C_CSPlayerPawn->m_bIsScoped");
SCHEMA_ADD_FIELD(bool, IsDefusing, "C_CSPlayerPawn->m_bIsDefusing");
Expand Down Expand Up @@ -404,5 +421,10 @@ class C_BaseGrenade : public C_BaseFlex
class CSkeletonInstance : public CGameSceneNode
{
public:

MEM_PAD(0x1CC); //0x0000
int nBoneCount; //0x01CC
MEM_PAD(0x18); //0x01D0
int nMask; //0x01E8
MEM_PAD(0x4); //0x01EC
Matrix4x2_t* pBoneCache; //0x01F0
};
59 changes: 59 additions & 0 deletions cstrike/sdk/interfaces/cgametracemanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// used: game trace manager
#include "cgametracemanager.h"
// used: c_csplayerpawn
#include "../../sdk/entity.h"

SurfaceData_t* GameTrace_t::GetSurfaceData()
{
using fnGetSurfaceData = std::uint64_t(__fastcall*)(void*);
static fnGetSurfaceData oGetSurfaceData = reinterpret_cast<fnGetSurfaceData>(MEM::GetAbsoluteAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("E8 ? ? ? ? 48 85 C0 74 ? 44 38 60")), 0x1, 0x0));

#ifdef CS_PARANOID
CS_ASSERT(oGetSurfaceData != nullptr);
#endif

return reinterpret_cast<SurfaceData_t*>(oGetSurfaceData(m_pSurface));
}

int GameTrace_t::GetHitboxId()
{
if (m_pHitboxData)
return m_pHitboxData->m_nHitboxId;
return 0;
}

int GameTrace_t::GetHitgroup()
{
if (m_pHitboxData)
return m_pHitboxData->m_nHitGroup;
return 0;
}

bool GameTrace_t::IsVisible() const
{
return (m_flFraction > 0.97f);
}

TraceFilter_t::TraceFilter_t(std::uint64_t uMask, C_CSPlayerPawn* pSkip1, C_CSPlayerPawn* pSkip2, int nLayer)
{
m_uTraceMask = uMask;
m_v1[0] = m_v1[1] = 0;
m_v2 = 7;
m_v3 = nLayer;
m_v4 = 0x49;
m_v5 = 0;

if (pSkip1 != nullptr)
{
m_arrSkipHandles[0] = pSkip1->GetRefEHandle().GetEntryIndex();
m_arrSkipHandles[2] = pSkip1->GetOwnerHandleIndex();
m_arrCollisions[0] = pSkip1->GetCollisionMask();
}

if (pSkip2 != nullptr)
{
m_arrSkipHandles[0] = pSkip2->GetRefEHandle().GetEntryIndex();
m_arrSkipHandles[2] = pSkip2->GetOwnerHandleIndex();
m_arrCollisions[0] = pSkip2->GetCollisionMask();
}
}
Loading

0 comments on commit 9f411b7

Please sign in to comment.