# HG changeset patch # User Nicholas Hastings # Date 1277761694 14400 # Node ID 4e1591dceb8d90798d753ee778a715cdce07c263 # Parent 4c81256cac4310de138ba25297a83edd24df44ca Added forward/detour for TF2's GetHoliday function (bug 4462, r=pred) diff -r 4c81256cac43 -r 4e1591dceb8d extensions/tf2/AMBuilder --- a/extensions/tf2/AMBuilder Sun Jun 27 19:17:25 2010 -0400 +++ b/extensions/tf2/AMBuilder Mon Jun 28 17:48:14 2010 -0400 @@ -16,6 +16,7 @@ 'RegNatives.cpp', 'util.cpp', 'criticals.cpp', + 'holiday.cpp', 'CDetour/detours.cpp', 'sdk/smsdk_ext.cpp', 'asm/asm.c' diff -r 4c81256cac43 -r 4e1591dceb8d extensions/tf2/Makefile --- a/extensions/tf2/Makefile Sun Jun 27 19:17:25 2010 -0400 +++ b/extensions/tf2/Makefile Mon Jun 28 17:48:14 2010 -0400 @@ -19,7 +19,7 @@ USEMETA = true OBJECTS = sdk/smsdk_ext.cpp extension.cpp natives.cpp RegNatives.cpp criticals.cpp \ - util.cpp CDetour/detours.cpp asm/asm.c + holiday.cpp util.cpp CDetour/detours.cpp asm/asm.c ############################################## ### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### diff -r 4c81256cac43 -r 4e1591dceb8d extensions/tf2/criticals.cpp --- a/extensions/tf2/criticals.cpp Sun Jun 27 19:17:25 2010 -0400 +++ b/extensions/tf2/criticals.cpp Mon Jun 28 17:48:14 2010 -0400 @@ -188,7 +188,7 @@ } } -void InitialiseDetours() +void InitialiseCritDetours() { calcIsAttackCriticalDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelper, "CalcCritical"); calcIsAttackCriticalMeleeDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelperMelee, "CalcCriticalMelee"); @@ -222,7 +222,7 @@ } -void RemoveDetours() +void RemoveCritDetours() { calcIsAttackCriticalDetour->Destroy(); calcIsAttackCriticalMeleeDetour->Destroy(); diff -r 4c81256cac43 -r 4e1591dceb8d extensions/tf2/criticals.h --- a/extensions/tf2/criticals.h Sun Jun 27 19:17:25 2010 -0400 +++ b/extensions/tf2/criticals.h Mon Jun 28 17:48:14 2010 -0400 @@ -37,8 +37,8 @@ #include #include "CDetour/detours.h" -void InitialiseDetours(); -void RemoveDetours(); +void InitialiseCritDetours(); +void RemoveCritDetours(); extern IForward *g_critForward; diff -r 4c81256cac43 -r 4e1591dceb8d extensions/tf2/extension.cpp --- a/extensions/tf2/extension.cpp Sun Jun 27 19:17:25 2010 -0400 +++ b/extensions/tf2/extension.cpp Mon Jun 28 17:48:14 2010 -0400 @@ -36,6 +36,7 @@ #include "iplayerinfo.h" #include "sm_trie_tpl.h" #include "criticals.h" +#include "holiday.h" #include "CDetour/detours.h" /** @@ -108,10 +109,12 @@ playerhelpers->RegisterCommandTargetProcessor(this); g_critForward = forwards->CreateForward("TF2_CalcIsAttackCritical", ET_Hook, 4, NULL, Param_Cell, Param_Cell, Param_String, Param_CellByRef); + g_getHolidayForward = forwards->CreateForward("TF2_OnGetHoliday", ET_Event, 1, NULL, Param_CellByRef); g_pCVar = icvar; - m_DetoursEnabled = false; + m_CritDetoursEnabled = false; + m_GetHolidayDetourEnabled = false; return true; } @@ -155,6 +158,7 @@ plsys->RemovePluginsListener(this); forwards->ReleaseForward(g_critForward); + forwards->ReleaseForward(g_getHolidayForward); } void TF2Tools::SDK_OnAllLoaded() @@ -297,19 +301,29 @@ void TF2Tools::OnPluginLoaded(IPlugin *plugin) { - if (!m_DetoursEnabled && g_critForward->GetFunctionCount()) + if (!m_CritDetoursEnabled && g_critForward->GetFunctionCount()) { - InitialiseDetours(); - m_DetoursEnabled = true; + InitialiseCritDetours(); + m_CritDetoursEnabled = true; + } + if (!m_GetHolidayDetourEnabled && g_getHolidayForward->GetFunctionCount()) + { + InitialiseGetHolidayDetour(); + m_GetHolidayDetourEnabled = true; } } void TF2Tools::OnPluginUnloaded(IPlugin *plugin) { - if (m_DetoursEnabled && !g_critForward->GetFunctionCount()) + if (m_CritDetoursEnabled && !g_critForward->GetFunctionCount()) { - RemoveDetours(); - m_DetoursEnabled = false; + RemoveCritDetours(); + m_CritDetoursEnabled = false; + } + if (m_GetHolidayDetourEnabled && !g_getHolidayForward->GetFunctionCount()) + { + RemoveGetHolidayDetour(); + m_GetHolidayDetourEnabled = false; } } int FindResourceEntity() diff -r 4c81256cac43 -r 4e1591dceb8d extensions/tf2/extension.h --- a/extensions/tf2/extension.h Sun Jun 27 19:17:25 2010 -0400 +++ b/extensions/tf2/extension.h Mon Jun 28 17:48:14 2010 -0400 @@ -112,7 +112,8 @@ virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late); #endif private: - bool m_DetoursEnabled; + bool m_CritDetoursEnabled; + bool m_GetHolidayDetourEnabled; }; enum TFClassType diff -r 4c81256cac43 -r 4e1591dceb8d extensions/tf2/holiday.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/tf2/holiday.cpp Mon Jun 28 17:48:14 2010 -0400 @@ -0,0 +1,77 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod Team Fortress 2 Extension + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software + * by the Valve Corporation. You must obey the GNU General Public License in + * all respects for all other code used. Additionally, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ + +#include "holiday.h" + +CDetour *getHolidayDetour = NULL; + +IForward *g_getHolidayForward = NULL; + +DETOUR_DECL_MEMBER0(GetHoliday, int) +{ + int actualres = DETOUR_MEMBER_CALL(GetHoliday)(); + if (!g_getHolidayForward) + { + g_pSM->LogMessage(myself, "Invalid Forward"); + return actualres; + } + + cell_t result = 0; + int newres = actualres; + + g_getHolidayForward->PushCellByRef(&newres); + g_getHolidayForward->Execute(&result); + + if (result == Pl_Changed) + { + return newres; + } + + return actualres; +} + +void InitialiseGetHolidayDetour() +{ + getHolidayDetour = DETOUR_CREATE_MEMBER(GetHoliday, "GetHoliday"); + + if (!getHolidayDetour) + { + g_pSM->LogError(myself, "GetHoliday detour failed"); + return; + } + + getHolidayDetour->EnableDetour(); +} + +void RemoveGetHolidayDetour() +{ + getHolidayDetour->Destroy(); +} \ No newline at end of file diff -r 4c81256cac43 -r 4e1591dceb8d extensions/tf2/holiday.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/tf2/holiday.h Mon Jun 28 17:48:14 2010 -0400 @@ -0,0 +1,45 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod Team Fortress 2 Extension + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software + * by the Valve Corporation. You must obey the GNU General Public License in + * all respects for all other code used. Additionally, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ + +#ifndef _INCLUDE_SOURCEMOD_HOLIDAY_H_ +#define _INCLUDE_SOURCEMOD_HOLIDAY_H_ + +#include "extension.h" +#include +#include +#include "CDetour/detours.h" + +void InitialiseGetHolidayDetour(); +void RemoveGetHolidayDetour(); + +extern IForward *g_getHolidayForward; + +#endif //_INCLUDE_SOURCEMOD_HOLIDAY_H_ diff -r 4c81256cac43 -r 4e1591dceb8d extensions/tf2/msvc9/tf2.vcproj --- a/extensions/tf2/msvc9/tf2.vcproj Sun Jun 27 19:17:25 2010 -0400 +++ b/extensions/tf2/msvc9/tf2.vcproj Mon Jun 28 17:48:14 2010 -0400 @@ -195,6 +195,10 @@ > + + @@ -221,6 +225,10 @@ > + + diff -r 4c81256cac43 -r 4e1591dceb8d gamedata/sm-tf2.games.txt --- a/gamedata/sm-tf2.games.txt Sun Jun 27 19:17:25 2010 -0400 +++ b/gamedata/sm-tf2.games.txt Mon Jun 28 17:48:14 2010 -0400 @@ -92,6 +92,13 @@ "linux" "@_ZN15CTFPlayerShared10StunPlayerEffiP9CTFPlayer" "mac" "@_ZN15CTFPlayerShared10StunPlayerEffiP9CTFPlayer" } + "GetHoliday" + { + "library" "server" + "windows" "\x81\xEC\x2A\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x83\x2A\x2A\x2A\x56\x8B\xF1\x89\x2A\x2A\x2A\x74\x2A\xB8" + "linux" "@_ZN12CTFGameRules10GetHolidayEv" + "mac" "@_ZN12CTFGameRules10GetHolidayEv" + } } "Offsets" { diff -r 4c81256cac43 -r 4e1591dceb8d plugins/include/tf2.inc --- a/plugins/include/tf2.inc Sun Jun 27 19:17:25 2010 -0400 +++ b/plugins/include/tf2.inc Mon Jun 28 17:48:14 2010 -0400 @@ -99,6 +99,13 @@ TFCond_Jarated }; +enum TFHoliday +{ + TFHoliday_None = 1, + TFHoliday_Halloween, + TFHoliday_Birthday +}; + /** * Sets a client on fire for 10 seconds. * @@ -225,6 +232,16 @@ forward Action:TF2_CalcIsAttackCritical(client, weapon, String:weaponname[], &bool:result); /** + * Called when the game checks to see if the current day is one of its tracked holidays + * + * @note Change the value of holiday and return Plugin_Changed to override. + * Return Plugin_Continue for no change. + * + * @param holiday Current Holiday + */ +forward Action:TF2_OnGetHoliday(&TFHoliday:holiday); + +/** * Do not edit below this line! */ public Extension:__ext_tf2 =