From de0f49248d9b729cc3b31c77f5117a11d398c366 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Mon, 23 Jun 2014 16:23:49 -0400 Subject: [PATCH 1/2] Update TF2_IsHolidayActive native to virtually call gamerules IsHolidayActive. --- extensions/tf2/natives.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/extensions/tf2/natives.cpp b/extensions/tf2/natives.cpp index 0f2a7133..36d808d9 100644 --- a/extensions/tf2/natives.cpp +++ b/extensions/tf2/natives.cpp @@ -555,19 +555,27 @@ cell_t TF2_IsHolidayActive(IPluginContext *pContext, const cell_t *params) { static ICallWrapper *pWrapper = NULL; - // UTIL_IsHolidayActive(int) + // CTFGameRules::IsHolidayActive(int) if (!pWrapper) { - REGISTER_NATIVE_ADDR("IsHolidayActive", - PassInfo pass[1]; \ - pass[0].flags = PASSFLAG_BYVAL; \ - pass[0].size = sizeof(int); \ - pass[0].type = PassType_Basic; \ - PassInfo ret; \ - ret.flags = PASSFLAG_BYVAL; \ - ret.size = sizeof(bool); \ - ret.type = PassType_Basic; \ - pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &ret, pass, 1)) + int offset; + if (!g_pGameConf->GetOffset("IsHolidayActive", &offset)) + { + return pContext->ThrowNativeError("Failed to locate function"); + } + + PassInfo pass[1]; + pass[0].flags = PASSFLAG_BYVAL; + pass[0].size = sizeof(int); + pass[0].type = PassType_Basic; + PassInfo ret; + ret.flags = PASSFLAG_BYVAL; + ret.size = sizeof(bool); + ret.type = PassType_Basic; + + pWrapper = g_pBinTools->CreateVCall(offset, 0, 0, &ret, pass, 1); + + g_RegNatives.Register(pWrapper); } unsigned char vstk[sizeof(int)]; From bbdf40160ccb8284eeecca365bac04b73273a7c6 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Mon, 23 Jun 2014 19:24:27 -0400 Subject: [PATCH 2/2] Add missing thisptr to call. --- extensions/tf2/natives.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extensions/tf2/natives.cpp b/extensions/tf2/natives.cpp index 36d808d9..75835f8d 100644 --- a/extensions/tf2/natives.cpp +++ b/extensions/tf2/natives.cpp @@ -34,6 +34,8 @@ #include "time.h" #include "RegNatives.h" +#include + // native TF2_MakeBleed(client, attacker, Float:duration) cell_t TF2_MakeBleed(IPluginContext *pContext, const cell_t *params) { @@ -553,6 +555,12 @@ cell_t TF2_IsPlayerInDuel(IPluginContext *pContext, const cell_t *params) // native bool:TF2_IsHolidayActive(TFHoliday:holiday); cell_t TF2_IsHolidayActive(IPluginContext *pContext, const cell_t *params) { + void *pGameRules; + if (!g_pSDKTools || !(pGameRules = g_pSDKTools->GetGameRules())) + { + return pContext->ThrowNativeError("Failed to find GameRules"); + } + static ICallWrapper *pWrapper = NULL; // CTFGameRules::IsHolidayActive(int) @@ -578,8 +586,10 @@ cell_t TF2_IsHolidayActive(IPluginContext *pContext, const cell_t *params) g_RegNatives.Register(pWrapper); } - unsigned char vstk[sizeof(int)]; + unsigned char vstk[sizeof(void *) + sizeof(int)]; unsigned char *vptr = vstk; + *(void **)vptr = pGameRules; + vptr += sizeof(void *); *(int *)vptr = params[1]; bool retValue;