From f3a2ee1999341373b1dc00acb74d4b378235febe Mon Sep 17 00:00:00 2001 From: Alperen Date: Tue, 9 Jun 2020 18:05:46 +0300 Subject: [PATCH] Bug fixes --- CSGOInternal/Gateway.cc | 1 + CSGOInternal/MainLoop.cc | 83 +++--- CSGOInternal/Source SDK/EntityPlayer.hpp | 67 +---- CSGOInternal/Source SDK/Interfaces.hpp | 314 ++++++++++++++++++++++- 4 files changed, 367 insertions(+), 98 deletions(-) diff --git a/CSGOInternal/Gateway.cc b/CSGOInternal/Gateway.cc index a12ae9b..95e3662 100644 --- a/CSGOInternal/Gateway.cc +++ b/CSGOInternal/Gateway.cc @@ -23,6 +23,7 @@ #include "Hooks/Hooks.hpp" #include "Settings/Settings.hpp" #include "MainMenu.hpp" + extern MidFunctionHook* pMidHook; extern AppSettings* pSettings; extern MainMenu* pMenu; diff --git a/CSGOInternal/MainLoop.cc b/CSGOInternal/MainLoop.cc index 3a7791f..2e7d8ac 100644 --- a/CSGOInternal/MainLoop.cc +++ b/CSGOInternal/MainLoop.cc @@ -81,7 +81,8 @@ MainLoop(void) if (!iEngineClient13->IsInGame()) // Player not in game return; - localPlayer = iEntityList->GetClientEntity(iEngineClient13->GetLocalPlayer()); + int j = iEngineClient13->GetLocalPlayer(); + localPlayer = (CEntityPlayer*)iEntityList->GetClientEntity(j); float distmax = FLT_MAX; int bestEnemy = -1; uintptr_t clientState = 0; @@ -95,20 +96,31 @@ MainLoop(void) // Copy view matrix float viewMatrixCopy[16] = { 0 }; memcpy(&viewMatrixCopy, (PBYTE)sig_dwViewMatrix, sizeof(viewMatrixCopy)); - + + int numberOfEntites = iEntityList->NumberOfEntities(false); // Loop in entity list - for(int i = 0; i < ENTITY_MAX_PLAYERS; i++) { - CEntityPlayer* ent = iEntityList->GetClientEntity(i); + for(int i = 0; i < numberOfEntites; i++) { + if (i == j) // Skip local + continue; - if (ent == nullptr) // Reached end of the list - break; + CEntityPlayer* ent = (CEntityPlayer*)iEntityList->GetClientEntity(i); + if (ent == nullptr) // Not valid entity + continue; + if (ent == localPlayer) // Skip local player continue; - + + if (!ent->IsPlayer()) // Entity is not player + continue; + + if (*ent->GetDormant()) // + continue; + if(pSettings->getBool(pSettings->bAimbot)) { // check this. - if (*ent->GetHealth() > 0 && *ent->GetTeam() != *localPlayer->GetTeam() && !(*ent->GetDormant()) && + + if (*ent->GetHealth() > 0 && *ent->GetTeam() != *localPlayer->GetTeam() && enemyIsVisible(ent) // Visible for us ) { // VALID ENEMY Vector myPos; @@ -130,40 +142,45 @@ MainLoop(void) } - if (!IS_VALID_ENT(ent)) - continue; + // if (!IS_VALID_ENT(ent)) + // continue; /* Drawing Stuff */ - int my_team = *localPlayer->GetTeam(); - int en_team = *ent->GetTeam(); - if (my_team == en_team) // teammate + if (*ent->GetHealth() > 0) // if enemys health > 0 { - if (pSettings->getBool(pSettings->bESP_mate)) - { - //mate esp - ent->DrawESP(viewMatrixCopy, D3DCOLOR_ARGB(255, 0, 255, 0)); - } - if (pSettings->getBool(pSettings->bSnaplines_mate)) - { - //snaplines mate - ent->DrawSnapline(viewMatrixCopy, 2, D3DCOLOR_ARGB(255, 0, 255, 0)); - } - //mybe glow - } - else // enemy - { - if (pSettings->getBool(pSettings->bESP)) + int my_team = *localPlayer->GetTeam(); + int en_team = *ent->GetTeam(); + + if (my_team == en_team) // teammate { - //enemy esp - ent->DrawESP(viewMatrixCopy, D3DCOLOR_ARGB(255, 255,0, 0)); + if (pSettings->getBool(pSettings->bESP_mate)) + { + //mate esp + ent->DrawESP(viewMatrixCopy, D3DCOLOR_ARGB(255, 0, 255, 0)); + } + if (pSettings->getBool(pSettings->bSnaplines_mate)) + { + //snaplines mate + ent->DrawSnapline(viewMatrixCopy, 2, D3DCOLOR_ARGB(255, 0, 255, 0)); + } + //maybe glow } - if (pSettings->getBool(pSettings->bSnaplines)) + else // enemy { - //enemy snaplines - ent->DrawSnapline(viewMatrixCopy, 2, D3DCOLOR_ARGB(255, 255, 0, 0)); + if (pSettings->getBool(pSettings->bESP)) + { + //enemy esp + ent->DrawESP(viewMatrixCopy, D3DCOLOR_ARGB(255, 255, 0, 0)); + } + if (pSettings->getBool(pSettings->bSnaplines)) + { + //enemy snaplines + ent->DrawSnapline(viewMatrixCopy, 2, D3DCOLOR_ARGB(255, 255, 0, 0)); + } } } + } diff --git a/CSGOInternal/Source SDK/EntityPlayer.hpp b/CSGOInternal/Source SDK/EntityPlayer.hpp index de32844..abbe7b5 100644 --- a/CSGOInternal/Source SDK/EntityPlayer.hpp +++ b/CSGOInternal/Source SDK/EntityPlayer.hpp @@ -21,8 +21,9 @@ *********************************************************************/ #pragma once #include "Netvars.hpp" +#include "Interfaces.hpp" #include "../D3D9/Drawing.hpp" - +#include #pragma warning (disable : 4244) extern uintptr_t _netvarOffsets[netvarOffsetsLength]; @@ -41,68 +42,6 @@ netvar(uintptr_t netVar) return _netvarOffsets[netVar]; } -class CEntityPlayer { -public: - int * GetHealth() { - return (int*)((uintptr_t)this + netvar(m_iHealth)); - } - int * GetTeam() { - return (int*)((uintptr_t)this + netvar(m_iTeamNum)); - } - bool *GetDormant() { - return (bool*)((uintptr_t)this + sig_bDormant); - } - int8_t GetFlags() { - return *(int8_t*)((uintptr_t)this + netvar(m_fFlags)); - } - int *GetFlashDuration() { - return (int*)((uintptr_t)this + netvar(m_flFlashDuration)); - } - Vector * GetVecOrigin() { - return (Vector*)((uintptr_t)this + netvar(m_vecOrigin)); - } - Vector * GetViewOffset(){ - return (Vector*)((uintptr_t)this + netvar(m_vecViewOffset)); - } - Vector * GetBonePos(int boneID) { - uint32_t boneMatrix = *(uintptr_t*)((uintptr_t)this + netvar(m_dwBoneMatrix)); - static Vector3 bonePos; - bonePos.x = *(float*)(boneMatrix + 0x30 * boneID + 0x0C); - bonePos.y = *(float*)(boneMatrix + 0x30 * boneID + 0x1C); - bonePos.z = *(float*)(boneMatrix + 0x30 * boneID + 0x2C); - return &bonePos; - } - Vector2 * GetAimPunchAngles() const { - return (Vector2*)((uintptr_t)this + netvar(m_aimPunchAngle)); - } - void GetViewAngles(Vector &ang) { - Vector vecOrigin = *this->GetVecOrigin(); - ang = vecOrigin + *this->GetViewOffset(); - } - /* DRAWING */ - - void DrawESP(float* v, D3DCOLOR color) - { - Vector vHead = *this->GetBonePos(8); - vHead.z += 8; - Vector vOrigin = *this->GetVecOrigin(); - Vector2 vScreen, vHead2; - - if(pDrawing->World2Screen(v,vOrigin, vScreen)) { - if(pDrawing->World2Screen(v,vHead,vHead2)) { - pDrawing->DrawEspBox(vScreen, vHead2, 2, color); - } - } - } - - void DrawSnapline(float* v, int thick, D3DCOLOR color) - { - Vector vOrigin = *this->GetVecOrigin(); - Vector2 entPos; +class IClientEntity; - if(pDrawing->World2Screen(v,vOrigin,entPos)) - pDrawing->DrawLine(entPos.x, entPos.y, pDrawing->screen_w / 2, pDrawing->screen_h , thick, color); - - } -}; diff --git a/CSGOInternal/Source SDK/Interfaces.hpp b/CSGOInternal/Source SDK/Interfaces.hpp index b1e9e00..12bd26b 100644 --- a/CSGOInternal/Source SDK/Interfaces.hpp +++ b/CSGOInternal/Source SDK/Interfaces.hpp @@ -24,7 +24,15 @@ using tCreateInterface = void* (__cdecl*)(const char* interfaceName, int * returnCode); - +typedef void* ShouldTransmitState_t; +typedef void* DataUpdateType_t; +typedef void* ClientShadowHandle_t; +typedef void* ClientRenderHandle_t; +typedef void* IPVSNotify; +typedef void* ModelInstanceHandle_t; +typedef void* SpatializationInfo_t; +typedef int ShadowType_t; +typedef int bf_read; typedef void* CBaseHandle; typedef void* INetChannel; typedef void* IServer; @@ -36,11 +44,85 @@ typedef void* CAudioSource; typedef void* ButtonCode_t; typedef int player_info_t; typedef char client_textmessage_t; +typedef float* matrix3x4_t; +class IClientEntity; class ClientClass; +class CMouthInfo; +class ICollideable; +class C_BaseEntity; +class IClientUnknown; +class IClientThinkable; +class IHandleEntity; +class IClientRenderable; + +class IHandleEntity +{ +public: + virtual ~IHandleEntity() {} + virtual void SetRefEHandle(const CBaseHandle& handle) = 0; + virtual const CBaseHandle& GetRefEHandle() const = 0; +}; + +class IClientNetworkable +{ +public: + virtual IClientUnknown* GetIClientUnknown() = 0; + + // Called by the engine when the server deletes the entity. + virtual void Release() = 0; + + // Supplied automatically by the IMPLEMENT_CLIENTCLASS macros. + virtual ClientClass* GetClientClass() = 0; + + // This tells the entity what the server says for ShouldTransmit on this entity. + // Note: This used to be EntityEnteredPVS/EntityRemainedInPVS/EntityLeftPVS. + virtual void NotifyShouldTransmit(ShouldTransmitState_t state) = 0; + + + + // + // NOTE FOR ENTITY WRITERS: + // + // In 90% of the cases, you should hook OnPreDataChanged/OnDataChanged instead of + // PreDataUpdate/PostDataUpdate. + // + // The DataChanged events are only called once per frame whereas Pre/PostDataUpdate + // are called once per packet (and sometimes multiple times per frame). + // + // OnDataChanged is called during simulation where entity origins are correct and + // attachments can be used. whereas PostDataUpdate is called while parsing packets + // so attachments and other entity origins may not be valid yet. + // + + virtual void OnPreDataChanged(DataUpdateType_t updateType) = 0; + virtual void OnDataChanged(DataUpdateType_t updateType) = 0; + + // Called when data is being updated across the network. + // Only low-level entities should need to know about these. + virtual void PreDataUpdate(DataUpdateType_t updateType) = 0; + virtual void PostDataUpdate(DataUpdateType_t updateType) = 0; + + + // Objects become dormant on the client if they leave the PVS on the server. + virtual bool IsDormant(void) = 0; + + // Ent Index is the server handle used to reference this entity. + // If the index is < 0, that indicates the entity is not known to the server + virtual int entindex(void) const = 0; + + // Server to client entity message received + virtual void ReceiveMessage(int classID, bf_read& msg) = 0; + // Get the base pointer to the networked data that GetClientClass->m_pRecvTable starts at. + // (This is usually just the "this" pointer). + virtual void* GetDataTableBasePtr() = 0; + // Tells the entity that it's about to be destroyed due to the client receiving + // an uncompressed update that's caused it to destroy all entities & recreate them. + virtual void SetDestroyedOnRecreateEntities(void) = 0; +}; class IBaseClientDLL { @@ -87,6 +169,236 @@ class IBaseClientDLL virtual void IN_DeactivateMouse(void) = 0; }; + +class IClientThinkable +{ +public: + // Gets at the containing class... + virtual IClientUnknown* GetIClientUnknown() = 0; + + virtual void ClientThink() = 0; + + // Called when you're added to the think list. + // GetThinkHandle's return value must be initialized to INVALID_THINK_HANDLE. + virtual void* GetThinkHandle() = 0; + virtual void SetThinkHandle(void* hThink) = 0; + + // Called by the client when it deletes the entity. + virtual void Release() = 0; +}; + +class IClientRenderable +{ +public: + // Gets at the containing class... + virtual IClientUnknown* GetIClientUnknown() = 0; + + // Data accessors + virtual Vector const& GetRenderOrigin(void) = 0; + virtual QAngle const& GetRenderAngles(void) = 0; + virtual bool ShouldDraw(void) = 0; + virtual bool IsTransparent(void) = 0; + virtual bool UsesPowerOfTwoFrameBufferTexture() = 0; + virtual bool UsesFullFrameBufferTexture() = 0; + + virtual ClientShadowHandle_t GetShadowHandle() const = 0; + + // Used by the leaf system to store its render handle. + virtual ClientRenderHandle_t& RenderHandle() = 0; + + // Render baby! + virtual const model_t* GetModel() const = 0; + virtual int DrawModel(int flags) = 0; + + // Get the body parameter + virtual int GetBody() = 0; + + // Determine alpha and blend amount for transparent objects based on render state info + virtual void ComputeFxBlend() = 0; + virtual int GetFxBlend(void) = 0; + + // Determine the color modulation amount + virtual void GetColorModulation(float* color) = 0; + + // Returns false if the entity shouldn't be drawn due to LOD. + // (NOTE: This is no longer used/supported, but kept in the vtable for backwards compat) + virtual bool LODTest() = 0; + + // Call this to get the current bone transforms for the model. + // currentTime parameter will affect interpolation + // nMaxBones specifies how many matrices pBoneToWorldOut can hold. (Should be greater than or + // equal to studiohdr_t::numbones. Use MAXSTUDIOBONES to be safe.) + virtual bool SetupBones(matrix3x4_t* pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime) = 0; + + virtual void SetupWeights(const matrix3x4_t* pBoneToWorld, int nFlexWeightCount, float* pFlexWeights, float* pFlexDelayedWeights) = 0; + virtual void DoAnimationEvents(void) = 0; + + // Return this if you want PVS notifications. See IPVSNotify for more info. + // Note: you must always return the same value from this function. If you don't, + // undefined things will occur, and they won't be good. + virtual IPVSNotify* GetPVSNotifyInterface() = 0; + + // Returns the bounds relative to the origin (render bounds) + virtual void GetRenderBounds(Vector& mins, Vector& maxs) = 0; + + // returns the bounds as an AABB in worldspace + virtual void GetRenderBoundsWorldspace(Vector& mins, Vector& maxs) = 0; + + // These normally call through to GetRenderAngles/GetRenderBounds, but some entities custom implement them. + virtual void GetShadowRenderBounds(Vector& mins, Vector& maxs, ShadowType_t shadowType) = 0; + + // Should this object be able to have shadows cast onto it? + virtual bool ShouldReceiveProjectedTextures(int flags) = 0; + + // These methods return true if we want a per-renderable shadow cast direction + distance + virtual bool GetShadowCastDistance(float* pDist, ShadowType_t shadowType) const = 0; + virtual bool GetShadowCastDirection(Vector* pDirection, ShadowType_t shadowType) const = 0; + + // Other methods related to shadow rendering + virtual bool IsShadowDirty() = 0; + virtual void MarkShadowDirty(bool bDirty) = 0; + + // Iteration over shadow hierarchy + virtual IClientRenderable* GetShadowParent() = 0; + virtual IClientRenderable* FirstShadowChild() = 0; + virtual IClientRenderable* NextShadowPeer() = 0; + + // Returns the shadow cast type + virtual ShadowType_t ShadowCastType() = 0; + + // Create/get/destroy model instance + virtual void CreateModelInstance() = 0; + virtual ModelInstanceHandle_t GetModelInstance() = 0; + + // Returns the transform from RenderOrigin/RenderAngles to world + virtual const matrix3x4_t& RenderableToWorldTransform() = 0; + + // Attachments + virtual int LookupAttachment(const char* pAttachmentName) = 0; + virtual bool GetAttachment(int number, Vector& origin, QAngle& angles) = 0; + virtual bool GetAttachment(int number, matrix3x4_t& matrix) = 0; + + // Rendering clip plane, should be 4 floats, return value of NULL indicates a disabled render clip plane + virtual float* GetRenderClipPlane(void) = 0; + + // Get the skin parameter + virtual int GetSkin() = 0; + + // Is this a two-pass renderable? + virtual bool IsTwoPass(void) = 0; + + virtual void OnThreadedDrawSetup() = 0; + + virtual bool UsesFlexDelayedWeights() = 0; + + virtual void RecordToolMessage() = 0; + + virtual bool IgnoresZBuffer(void) const = 0; +}; + +class IClientUnknown : public IHandleEntity +{ +public: + virtual ICollideable* GetCollideable() = 0; + virtual IClientNetworkable* GetClientNetworkable() = 0; + virtual IClientRenderable* GetClientRenderable() = 0; + virtual IClientEntity* GetIClientEntity() = 0; + virtual C_BaseEntity* GetBaseEntity() = 0; + virtual IClientThinkable* GetClientThinkable() = 0; +}; + +class IClientEntity : public IClientUnknown, public IClientRenderable, public IClientNetworkable, public IClientThinkable +{ +public: + // Delete yourself. + virtual void Release(void) = 0; + + // Network origin + angles + virtual const Vector& GetAbsOrigin(void) const = 0; + virtual const QAngle& GetAbsAngles(void) const = 0; + + virtual CMouthInfo* GetMouth(void) = 0; + + // Retrieve sound spatialization info for the specified sound on this entity + // Return false to indicate sound is not audible + virtual bool GetSoundSpatialization(SpatializationInfo_t& info) = 0; +}; + +class CEntityPlayer : IClientEntity { +public: + bool IsPlayer() { + ClientClass* cl = GetClientClass(); + if (nullptr == cl) return false; + + if (!std::string(cl->m_pNetworkName).compare("CCSPlayer")) + return true; + + return false; + } + + int* GetHealth() { + return (int*)((uintptr_t)this + netvar(m_iHealth)); + } + int* GetTeam() { + return (int*)((uintptr_t)this + netvar(m_iTeamNum)); + } + bool* GetDormant() { + return (bool*)((uintptr_t)this + sig_bDormant); + } + int8_t GetFlags() { + return *(int8_t*)((uintptr_t)this + netvar(m_fFlags)); + } + int* GetFlashDuration() { + return (int*)((uintptr_t)this + netvar(m_flFlashDuration)); + } + Vector* GetVecOrigin() { + return (Vector*)((uintptr_t)this + netvar(m_vecOrigin)); + } + Vector* GetViewOffset() { + return (Vector*)((uintptr_t)this + netvar(m_vecViewOffset)); + } + Vector* GetBonePos(int boneID) { + uint32_t boneMatrix = *(uintptr_t*)((uintptr_t)this + netvar(m_dwBoneMatrix)); + static Vector3 bonePos; + bonePos.x = *(float*)(boneMatrix + 0x30 * boneID + 0x0C); + bonePos.y = *(float*)(boneMatrix + 0x30 * boneID + 0x1C); + bonePos.z = *(float*)(boneMatrix + 0x30 * boneID + 0x2C); + return &bonePos; + } + Vector2* GetAimPunchAngles() const { + return (Vector2*)((uintptr_t)this + netvar(m_aimPunchAngle)); + } + void GetViewAngles(Vector& ang) { + Vector vecOrigin = *this->GetVecOrigin(); + ang = vecOrigin + *this->GetViewOffset(); + } + /* DRAWING */ + + void DrawESP(float* v, D3DCOLOR color) + { + Vector vHead = *this->GetBonePos(8); + vHead.z += 8; + Vector vOrigin = *this->GetVecOrigin(); + Vector2 vScreen, vHead2; + + if (pDrawing->World2Screen(v, vOrigin, vScreen)) { + if (pDrawing->World2Screen(v, vHead, vHead2)) { + pDrawing->DrawEspBox(vScreen, vHead2, 2, color); + } + } + } + + void DrawSnapline(float* v, int thick, D3DCOLOR color) + { + Vector vOrigin = *this->GetVecOrigin(); + Vector2 entPos; + + if (pDrawing->World2Screen(v, vOrigin, entPos)) + pDrawing->DrawLine(entPos.x, entPos.y, pDrawing->screen_w / 2, pDrawing->screen_h, thick, color); + + } + +}; /** * Interface IClientEntityList */