From 7f56360ee9bdcf1b39c7c55d92a9c5c615e48066 Mon Sep 17 00:00:00 2001 From: BotoX Date: Fri, 16 Dec 2016 23:45:05 +0100 Subject: [PATCH] Add forwards for Physics_RunThinkFunctions --- extension.cpp | 60 ++++++++++++++++++++++++++++++++++++++++--- gamedata/CSSFixes.txt | 6 +++++ include/CSSFixes.inc | 29 +++++++++++++++++++++ smsdk_config.h | 4 +-- 4 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 include/CSSFixes.inc diff --git a/extension.cpp b/extension.cpp index df25a0b..b4cbbd8 100644 --- a/extension.cpp +++ b/extension.cpp @@ -90,11 +90,15 @@ SMEXT_LINK(&g_Interface); IGameConfig *g_pGameConf = NULL; +IForward *g_pOnRunThinkFunctions = NULL; +IForward *g_pOnRunThinkFunctionsPost = NULL; + CDetour *detourInputTestActivator = NULL; CDetour *detourPostConstructor = NULL; CDetour *detourFindUseEntity = NULL; CDetour *detourCTraceFilterSimple = NULL; CDetour *detourMultiWaitOver = NULL; +CDetour *detourRunThinkFunctions = NULL; DETOUR_DECL_MEMBER1(InputTestActivator, void, inputdata_t *, inputdata) { @@ -150,6 +154,17 @@ DETOUR_DECL_MEMBER0(MultiWaitOver, void) DETOUR_MEMBER_CALL(MultiWaitOver)(); } +DETOUR_DECL_STATIC1(RunThinkFunctions, void, bool, simulating) +{ + g_pOnRunThinkFunctions->PushCell(simulating); + g_pOnRunThinkFunctions->Execute(); + + DETOUR_STATIC_CALL(RunThinkFunctions)(simulating); + + g_pOnRunThinkFunctionsPost->PushCell(simulating); + g_pOnRunThinkFunctionsPost->Execute(); +} + bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) { char conf_error[255] = ""; @@ -167,41 +182,56 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) if(detourInputTestActivator == NULL) { snprintf(error, maxlength, "Could not create detour for CBaseFilter_InputTestActivator"); + SDK_OnUnload(); return false; } - detourInputTestActivator->EnableDetour(); detourPostConstructor = DETOUR_CREATE_MEMBER(PostConstructor, "CBaseEntity_PostConstructor"); if(detourPostConstructor == NULL) { snprintf(error, maxlength, "Could not create detour for CBaseEntity_PostConstructor"); + SDK_OnUnload(); return false; } - detourPostConstructor->EnableDetour(); detourFindUseEntity = DETOUR_CREATE_MEMBER(FindUseEntity, "CBasePlayer_FindUseEntity"); if(detourFindUseEntity == NULL) { snprintf(error, maxlength, "Could not create detour for CBasePlayer_FindUseEntity"); + SDK_OnUnload(); return false; } - detourFindUseEntity->EnableDetour(); detourCTraceFilterSimple = DETOUR_CREATE_MEMBER(CTraceFilterSimple, "CTraceFilterSimple_CTraceFilterSimple"); if(detourCTraceFilterSimple == NULL) { snprintf(error, maxlength, "Could not create detour for CTraceFilterSimple_CTraceFilterSimple"); + SDK_OnUnload(); return false; } - detourCTraceFilterSimple->EnableDetour(); detourMultiWaitOver = DETOUR_CREATE_MEMBER(MultiWaitOver, "CTriggerMultiple_MultiWaitOver"); if(detourMultiWaitOver == NULL) { snprintf(error, maxlength, "Could not create detour for CTriggerMultiple_MultiWaitOver"); + SDK_OnUnload(); return false; } + + detourRunThinkFunctions = DETOUR_CREATE_STATIC(RunThinkFunctions, "Physics_RunThinkFunctions"); + if(detourRunThinkFunctions == NULL) + { + snprintf(error, maxlength, "Could not create detour for Physics_RunThinkFunctions"); + SDK_OnUnload(); + return false; + } + + detourInputTestActivator->EnableDetour(); + detourPostConstructor->EnableDetour(); + detourFindUseEntity->EnableDetour(); + detourCTraceFilterSimple->EnableDetour(); detourMultiWaitOver->EnableDetour(); + detourRunThinkFunctions->EnableDetour(); // Find VTable for CTraceFilterNoNPCsOrPlayer uintptr_t pCTraceFilterNoNPCsOrPlayer; @@ -218,6 +248,7 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) if(!pServerSo) { snprintf(error, maxlength, "Could not dlopen server_srv.so"); + SDK_OnUnload(); return false; } @@ -258,6 +289,9 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) dlclose(pServerSo); + g_pOnRunThinkFunctions = forwards->CreateForward("OnRunThinkFunctions", ET_Ignore, 1, NULL, Param_Cell); + g_pOnRunThinkFunctionsPost = forwards->CreateForward("OnRunThinkFunctionsPost", ET_Ignore, 1, NULL, Param_Cell); + return true; } @@ -293,6 +327,24 @@ void CSSFixes::SDK_OnUnload() detourMultiWaitOver = NULL; } + if(detourRunThinkFunctions != NULL) + { + detourRunThinkFunctions->Destroy(); + detourRunThinkFunctions = NULL; + } + + if(g_pOnRunThinkFunctions != NULL) + { + forwards->ReleaseForward(g_pOnRunThinkFunctions); + g_pOnRunThinkFunctions = NULL; + } + + if(g_pOnRunThinkFunctionsPost != NULL) + { + forwards->ReleaseForward(g_pOnRunThinkFunctionsPost); + g_pOnRunThinkFunctionsPost = NULL; + } + gameconfs->CloseGameConfigFile(g_pGameConf); // Revert all applied patches diff --git a/gamedata/CSSFixes.txt b/gamedata/CSSFixes.txt index a8e4e4f..1f215b4 100644 --- a/gamedata/CSSFixes.txt +++ b/gamedata/CSSFixes.txt @@ -39,6 +39,12 @@ "library" "server" "linux" "@_ZN16CTriggerMultiple13MultiWaitOverEv" } + + "Physics_RunThinkFunctions" + { + "library" "server" + "linux" "@_Z25Physics_RunThinkFunctionsb" + } } } } diff --git a/include/CSSFixes.inc b/include/CSSFixes.inc new file mode 100644 index 0000000..84751b4 --- /dev/null +++ b/include/CSSFixes.inc @@ -0,0 +1,29 @@ +#if defined _cssfixes_included + #endinput +#endif +#define _cssfixes_included + +forward void OnRunThinkFunctions(bool simulating); +forward void OnRunThinkFunctionsPost(bool simulating); + +public Extension:__ext_CSSFixes = +{ + name = "CSSFixes", + file = "CSSFixes.ext", +#if defined AUTOLOAD_EXTENSIONS + autoload = 1, +#else + autoload = 0, +#endif +#if defined REQUIRE_EXTENSIONS + required = 1, +#else + required = 0, +#endif +}; + +#if !defined REQUIRE_EXTENSIONS +public __ext_CSSFixes_SetNTVOptional() +{ +} +#endif diff --git a/smsdk_config.h b/smsdk_config.h index fd728ab..532a262 100644 --- a/smsdk_config.h +++ b/smsdk_config.h @@ -40,7 +40,7 @@ /* Basic information exposed publicly */ #define SMEXT_CONF_NAME "CSSFixes" #define SMEXT_CONF_DESCRIPTION "Patches bugs in the CSS server binary." -#define SMEXT_CONF_VERSION "1.2" +#define SMEXT_CONF_VERSION "1.3" #define SMEXT_CONF_AUTHOR "BotoX" #define SMEXT_CONF_URL "" #define SMEXT_CONF_LOGTAG "CSSFIXES" @@ -59,7 +59,7 @@ #define SMEXT_CONF_METAMOD /** Enable interfaces you want to use here by uncommenting lines */ -//#define SMEXT_ENABLE_FORWARDSYS +#define SMEXT_ENABLE_FORWARDSYS //#define SMEXT_ENABLE_HANDLESYS //#define SMEXT_ENABLE_PLAYERHELPERS //#define SMEXT_ENABLE_DBMANAGER