Skip to content

Commit

Permalink
Fix crash on old ReHLDS (3.10< unsupported).
Browse files Browse the repository at this point in the history
  • Loading branch information
Garey27 committed Oct 1, 2022
1 parent 8caf074 commit 26124d0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: CMake

on: [push, pull_request]
on:
push:
tags:
- '*'

jobs:
build_linux:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion include/cssdk/engine/rehlds_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect;
Expand Down
28 changes: 14 additions & 14 deletions src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
14 changes: 6 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1021,10 +1014,15 @@ bool OnMetaAttach()
api = std::make_unique<rehlds_api>();
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<hlds_api>();
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;
}
}
Expand Down

0 comments on commit 26124d0

Please sign in to comment.