From 26124d0786d141220cdeb7d8b92cd2574d480c08 Mon Sep 17 00:00:00 2001 From: garey Date: Sat, 1 Oct 2022 22:41:42 +0500 Subject: [PATCH] Fix crash on old ReHLDS (3.10< unsupported). --- .github/workflows/cmake.yml | 5 ++++- README.md | 2 +- include/cssdk/engine/rehlds_api.h | 2 +- src/animation.cpp | 28 ++++++++++++++-------------- src/api.h | 2 +- src/main.cpp | 14 ++++++-------- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 32e66e5..a0cf31a 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -1,6 +1,9 @@ name: CMake -on: [push, pull_request] +on: + push: + tags: + - '*' jobs: build_linux: diff --git a/README.md b/README.md index 99caf1a..50f0f69 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This module fixes incorrect player server-side hitboxes in Counter-Strike 1.6, H ## Requirements One of: * HLDS version 8648 -* [REHLDS](https://github.com/dreamstalker/rehlds/releases) version 3.3 or above +* [REHLDS](https://github.com/dreamstalker/rehlds/releases) version 3.10 or above ## Fixes - [x] Fixes absolutely broken hitboxes when numblends == 1 (ducking/standing in reload weapon or plant c4 animation). - [x] Hitbox backtrack based on client-side position. diff --git a/include/cssdk/engine/rehlds_api.h b/include/cssdk/engine/rehlds_api.h index 126cf17..7977c5e 100644 --- a/include/cssdk/engine/rehlds_api.h +++ b/include/cssdk/engine/rehlds_api.h @@ -37,7 +37,7 @@ #include "pr_dlls.h" #define REHLDS_API_VERSION_MAJOR 3 -#define REHLDS_API_VERSION_MINOR 4 +#define REHLDS_API_VERSION_MINOR 10 //Steam_NotifyClientConnect hook typedef IHookChain IRehldsHook_Steam_NotifyClientConnect; diff --git a/src/animation.cpp b/src/animation.cpp index 420d6f1..5d8c006 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -1054,7 +1054,7 @@ void EXT_FUNC HL_StudioSetupBones(model_t* pModel, float frame, int sequence, co void CS_StudioProcessParams(int player, player_anim_params_s& params) { auto cl = api->GetClient(player); - if (!cl) + if (!cl || !cl->edict) return; auto pModel = api->GetModel(cl->edict->v.modelindex); if (!pModel) @@ -1066,10 +1066,12 @@ void CS_StudioProcessParams(int player, player_anim_params_s& params) return; } // Bound sequence number - if (params.sequence < 0 || params.sequence >= g_pstudiohdr->numseq) + if (params.sequence < 0) params.sequence = 0; - auto pbones = (mstudiobone_t*)((byte*)g_pstudiohdr + g_pstudiohdr->boneindex); + if (params.sequence >= g_pstudiohdr->numseq) + return; + auto pseqdesc = (mstudioseqdesc_t*)((byte*)g_pstudiohdr + g_pstudiohdr->seqindex) + params.sequence; if (player != -1) @@ -1084,21 +1086,19 @@ void CS_StudioProcessParams(int player, player_anim_params_s& params) params.f = StudioEstimateFrame(pseqdesc); - if (player != -1) + if (params.gaitsequence == ANIM_WALK_SEQUENCE) { - if (params.gaitsequence == ANIM_WALK_SEQUENCE) + if (params.blending[0] > 26) { - if (params.blending[0] > 26) - { - params.blending[0] -= 26; - } - else - { - params.blending[0] = 0; - } - params.prevseqblending[0] = params.blending[0]; + params.blending[0] -= 26; + } + else + { + params.blending[0] = 0; } + params.prevseqblending[0] = params.blending[0]; } + } void EXT_FUNC CS_StudioSetupBones(model_t* pModel, float frame, int sequence, const vec_t* angles, const vec_t* origin, const byte* pcontroller, const byte* pblending, int iBone, const edict_t* pEdict) { diff --git a/src/api.h b/src/api.h index 7926403..6541781 100644 --- a/src/api.h +++ b/src/api.h @@ -55,7 +55,7 @@ struct hlds_api : players_api svs = decltype(svs)(PatternScan::FindPattern("83 3D *? ? ? ? ? 0F 9F C0 89 04 24 E8 ? ? ? ? A1 ? ? ? ?", "engine_i486.so")); sv = decltype(sv)(PatternScan::FindPattern("A1 *? ? ? ? 85 C0 75 ? 83 C4 ? 5B 5E", "engine_i486.so")); #endif - return svs != nullptr; + return svs != nullptr && sv != nullptr; }; client_t* GetClient(size_t index) override { diff --git a/src/main.cpp b/src/main.cpp index a5b92ba..2502d5f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,13 +85,6 @@ void VectorMA(const vec_t* veca, float scale, const vec_t* vecm, vec_t* out) void TestFunc(uint32_t host_id, float t, float frac, uintptr_t sequence) { auto _host_client = api->GetClient(host_id); - if (TestingHitboxes) - { - - char msg[1024]; - snprintf(msg, 1024, "%.2f %.2f | %.2f %.2f\n", t, frac, player_params_history[host_id].hist[SV_UPDATE_MASK & sequence][1].t, player_params_history[host_id].hist[SV_UPDATE_MASK & sequence][1].frac); - g_engfuncs.pfnServerPrint(msg); - } for (int i = 0; i < api->GetMaxClients(); i++) { auto cl = api->GetClient(i); @@ -1021,10 +1014,15 @@ bool OnMetaAttach() api = std::make_unique(); if (!api->Init()) { + if (g_RehldsApi) + { + UTIL_ServerPrint("Hitbox fixer is not compatible with your ReHLDS version. Hitbox Fixer needs at least 3.10 version."); + return false; + } api = std::make_unique(); if (!api->Init()) { - UTIL_ServerPrint("Hitbox fixer is not compatible with your HLDS/ReHLDS version. Create issue on github [https://github.com/Garey27/hitbox_fixer]."); + UTIL_ServerPrint("Hitbox fixer is not compatible with your HLDS version. Create issue on github [https://github.com/Garey27/hitbox_fixer]."); return false; } }