Skip to content

Commit

Permalink
Fix linux missing library.
Browse files Browse the repository at this point in the history
Add config
Add unload option.
  • Loading branch information
Garey Akhmetshin committed Apr 11, 2022
1 parent 184eb54 commit f6355ee
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- name: Archive artifacts
run: |
mkdir -p addons/hitbox_fix
cp hitbox_fix_mm.dll hitbox_fix_mm_i386.so addons/hitbox_fix
cp dist/hbf.cfg hitbox_fix_mm.dll hitbox_fix_mm_i386.so addons/hitbox_fix
7z a -tzip hitbox_fix-bin-${RELEASE_VERSION}.zip addons
- name: Release
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ else()
#set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -static-libstdc++ -static-libgcc")
set_target_properties(HitboxFix PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)

endif()
Expand Down
1 change: 1 addition & 0 deletions dist/hbf.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hbf_enabled "1"
4 changes: 2 additions & 2 deletions include/cssdk/common/r_studioint.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ typedef struct sv_blending_interface_s
void ( *SV_StudioSetupBones )( struct model_s *pModel,
float frame,
int sequence,
const vec3_t angles,
const vec3_t origin,
const vec_t* angles,
const vec_t* origin,
const byte *pcontroller,
const byte *pblending,
int iBone,
Expand Down
5 changes: 5 additions & 0 deletions src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,11 @@ void SV_StudioSetupBones(model_t* pModel, float frame, int sequence, const vec_t
static float pos4[MAXSTUDIOBONES][3];
static vec4_t q4[MAXSTUDIOBONES];

if (!phf_hitbox_fix->value)
{
orig_interface.SV_StudioSetupBones(pModel, frame, sequence, angles, origin, pcontroller, pblending, iBone, pEdict);
return;
}

if (ENTINDEX(pEdict) <= g_RehldsSvs->GetMaxClients())
{
Expand Down
70 changes: 66 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
cvar_t* sv_unlag;
cvar_t* sv_maxunlag;
cvar_t* sv_unlagpush;
cvar_t hf_hitbox_fix = { "hbf_enabled", "1", FCVAR_SERVER | FCVAR_PROTECTED, 0.0f, NULL };
cvar_t* phf_hitbox_fix;
char g_ExecConfigCmd[MAX_PATH];
const char CFG_FILE[] = "hbf.cfg";
extern server_studio_api_t IEngineStudio;
extern studiohdr_t* g_pstudiohdr;
extern float(*g_pRotationMatrix)[3][4];
extern float(*g_pBoneTransform)[128][3][4];
void StudioProcessGait(int index);

sv_blending_interface_s** orig_ppinterface;
sv_blending_interface_s orig_interface;
// Resource counts
#define MAX_MODEL_INDEX_BITS 9 // sent as a short
#define MAX_MODELS (1<<MAX_MODEL_INDEX_BITS)
Expand Down Expand Up @@ -665,8 +670,10 @@ static bool Init = false;
int (*Server_GetBlendingInterfaceOrig)(int version, struct sv_blending_interface_s** ppinterface, struct engine_studio_api_s* pstudio, float* rotationmatrix, float* bonetransform);
int Server_GetBlendingInterface(int version, struct sv_blending_interface_s** ppinterface, struct engine_studio_api_s* pstudio, float* rotationmatrix, float* bonetransform)
{
orig_ppinterface = ppinterface;
subhook_remove(Server_GetBlendingInterfaceHook);
Server_GetBlendingInterfaceOrig(version, ppinterface, pstudio, rotationmatrix, bonetransform);
orig_interface = **ppinterface;
subhook_install(Server_GetBlendingInterfaceHook);
if (version != SV_BLENDING_INTERFACE_VERSION)
return 0;
Expand All @@ -684,6 +691,56 @@ int Server_GetBlendingInterface(int version, struct sv_blending_interface_s** pp
return 1;
}

void Revoice_Exec_Config()
{
if (!g_ExecConfigCmd[0]) {
return;
}

g_engfuncs.pfnServerCommand(g_ExecConfigCmd);
g_engfuncs.pfnServerExecute();
}

void NormalizePath(char* path)
{
for (char* cp = path; *cp; cp++) {
if (isupper(*cp))
*cp = tolower(*cp);

if (*cp == '\\')
*cp = '/';
}
}

void HF_Exec_Config()
{
if (!g_ExecConfigCmd[0]) {
return;
}

g_engfuncs.pfnServerCommand(g_ExecConfigCmd);
g_engfuncs.pfnServerExecute();
}

bool HF_Init_Config()
{
const char* pszGameDir = GET_GAME_INFO(PLID, GINFO_GAMEDIR);
const char* pszPluginDir = GET_PLUGIN_PATH(PLID);

char szRelativePath[MAX_PATH];
strncpy(szRelativePath, &pszPluginDir[strlen(pszGameDir) + 1], sizeof(szRelativePath) - 1);
szRelativePath[sizeof(szRelativePath) - 1] = '\0';
NormalizePath(szRelativePath);

char* pos = strrchr(szRelativePath, '/');
if (pos) {
*(pos + 1) = '\0';
}

snprintf(g_ExecConfigCmd, sizeof(g_ExecConfigCmd), "exec \"%s%s\"\n", szRelativePath, CFG_FILE);
return true;
}

bool OnMetaAttach()
{
if (Init)
Expand All @@ -697,15 +754,19 @@ bool OnMetaAttach()
sv_unlag = g_engfuncs.pfnCVarGetPointer("sv_unlag");
sv_maxunlag = g_engfuncs.pfnCVarGetPointer("sv_maxunlag");
sv_unlagpush = g_engfuncs.pfnCVarGetPointer("sv_unlagpush");
//engine_patcher = std::make_unique< CDynPatcher>();
CVAR_REGISTER(&hf_hitbox_fix);
phf_hitbox_fix = CVAR_GET_POINTER(hf_hitbox_fix.name);
HF_Init_Config();
HF_Exec_Config();


#if 1
#if defined(__linux__) || defined(__APPLE__)


ModuleInfo info = Handles::GetModuleInfo("cs.so");
Server_GetBlendingInterfaceOrig = decltype(Server_GetBlendingInterfaceOrig)(dlsym(info.handle, "Server_GetBlendingInterface"));

printf("[Hitbox Fix] Found Server_GetBlendingInterface at 0x%p\n", Server_GetBlendingInterfaceOrig);
Server_GetBlendingInterfaceHook = subhook_new(
(void*)Server_GetBlendingInterfaceOrig, (void*)Server_GetBlendingInterface, (subhook_flags_t)0);
subhook_install(Server_GetBlendingInterfaceHook);
Expand All @@ -728,5 +789,6 @@ bool OnMetaAttach()

void OnMetaDetach()
{

subhook_remove(Server_GetBlendingInterfaceHook);
(*orig_ppinterface)->SV_StudioSetupBones = orig_interface.SV_StudioSetupBones;
}
2 changes: 1 addition & 1 deletion src/meta_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugin_info_t Plugin_info =
"https://github.com/Garey27/hitbox_fixer", // url
"HBFix", // logtag, all caps please
PT_STARTUP, // (when) loadable
PT_NEVER, // (when) unloadable
PT_ANYTIME, // (when) unloadable
};

C_DLLEXPORT int Meta_Query(char *interfaceVersion, plugin_info_t* *plinfo, mutil_funcs_t *pMetaUtilFuncs)
Expand Down
4 changes: 3 additions & 1 deletion src/precompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ extern void (PlayerPreThinkPre)(edict_t* pEntity);
extern void (PlayerPostThinkPost)(edict_t* pEntity);
extern void (UpdateClientDataPost) (const struct edict_s* ent, int sendweapons, struct clientdata_s* cd);
extern int (AddToFullPackPost)(struct entity_state_s* state, int e, edict_t* ent, edict_t* host, int hostflags, int player, unsigned char* pSet);
extern void (PutInServer) (edict_t* pEntity);
extern void (PutInServer) (edict_t* pEntity);
extern sv_blending_interface_s orig_interface;
extern cvar_t* phf_hitbox_fix;

0 comments on commit f6355ee

Please sign in to comment.