Added forward/detour for TF2's GetHoliday function (bug 4462, r=pred)
authorNicholas Hastings <skamonkey@gmail.com>
Mon Jun 28 17:48:14 2010 -0400 (2010-06-28)
changeset 30564e1591dceb8d
parent 3055 4c81256cac43
child 3057 e57c4ad63df5
Added forward/detour for TF2's GetHoliday function (bug 4462, r=pred)
extensions/tf2/AMBuilder
extensions/tf2/Makefile
extensions/tf2/criticals.cpp
extensions/tf2/criticals.h
extensions/tf2/extension.cpp
extensions/tf2/extension.h
extensions/tf2/holiday.cpp
extensions/tf2/holiday.h
extensions/tf2/msvc9/tf2.vcproj
gamedata/sm-tf2.games.txt
plugins/include/tf2.inc
     1.1 --- a/extensions/tf2/AMBuilder	Sun Jun 27 19:17:25 2010 -0400
     1.2 +++ b/extensions/tf2/AMBuilder	Mon Jun 28 17:48:14 2010 -0400
     1.3 @@ -16,6 +16,7 @@
     1.4  	'RegNatives.cpp',
     1.5  	'util.cpp',
     1.6  	'criticals.cpp',
     1.7 +	'holiday.cpp',
     1.8  	'CDetour/detours.cpp',
     1.9  	'sdk/smsdk_ext.cpp',
    1.10  	'asm/asm.c'
     2.1 --- a/extensions/tf2/Makefile	Sun Jun 27 19:17:25 2010 -0400
     2.2 +++ b/extensions/tf2/Makefile	Mon Jun 28 17:48:14 2010 -0400
     2.3 @@ -19,7 +19,7 @@
     2.4  USEMETA = true
     2.5  
     2.6  OBJECTS = sdk/smsdk_ext.cpp extension.cpp natives.cpp RegNatives.cpp criticals.cpp \
     2.7 -	util.cpp CDetour/detours.cpp asm/asm.c
     2.8 +	holiday.cpp util.cpp CDetour/detours.cpp asm/asm.c
     2.9  
    2.10  ##############################################
    2.11  ### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
     3.1 --- a/extensions/tf2/criticals.cpp	Sun Jun 27 19:17:25 2010 -0400
     3.2 +++ b/extensions/tf2/criticals.cpp	Mon Jun 28 17:48:14 2010 -0400
     3.3 @@ -188,7 +188,7 @@
     3.4  	}
     3.5  }
     3.6  
     3.7 -void InitialiseDetours()
     3.8 +void InitialiseCritDetours()
     3.9  {
    3.10  	calcIsAttackCriticalDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelper, "CalcCritical");
    3.11  	calcIsAttackCriticalMeleeDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelperMelee, "CalcCriticalMelee");
    3.12 @@ -222,7 +222,7 @@
    3.13  
    3.14  }
    3.15  
    3.16 -void RemoveDetours()
    3.17 +void RemoveCritDetours()
    3.18  {
    3.19  	calcIsAttackCriticalDetour->Destroy();
    3.20  	calcIsAttackCriticalMeleeDetour->Destroy();
     4.1 --- a/extensions/tf2/criticals.h	Sun Jun 27 19:17:25 2010 -0400
     4.2 +++ b/extensions/tf2/criticals.h	Mon Jun 28 17:48:14 2010 -0400
     4.3 @@ -37,8 +37,8 @@
     4.4  #include <jit/x86/x86_macros.h>
     4.5  #include "CDetour/detours.h"
     4.6  
     4.7 -void InitialiseDetours();
     4.8 -void RemoveDetours();
     4.9 +void InitialiseCritDetours();
    4.10 +void RemoveCritDetours();
    4.11  
    4.12  extern IForward *g_critForward;
    4.13  
     5.1 --- a/extensions/tf2/extension.cpp	Sun Jun 27 19:17:25 2010 -0400
     5.2 +++ b/extensions/tf2/extension.cpp	Mon Jun 28 17:48:14 2010 -0400
     5.3 @@ -36,6 +36,7 @@
     5.4  #include "iplayerinfo.h"
     5.5  #include "sm_trie_tpl.h"
     5.6  #include "criticals.h"
     5.7 +#include "holiday.h"
     5.8  #include "CDetour/detours.h"
     5.9  
    5.10  /**
    5.11 @@ -108,10 +109,12 @@
    5.12  	playerhelpers->RegisterCommandTargetProcessor(this);
    5.13  
    5.14  	g_critForward = forwards->CreateForward("TF2_CalcIsAttackCritical", ET_Hook, 4, NULL, Param_Cell, Param_Cell, Param_String, Param_CellByRef);
    5.15 +	g_getHolidayForward = forwards->CreateForward("TF2_OnGetHoliday", ET_Event, 1, NULL, Param_CellByRef);
    5.16  
    5.17  	g_pCVar = icvar;
    5.18  
    5.19 -	m_DetoursEnabled = false;
    5.20 +	m_CritDetoursEnabled = false;
    5.21 +	m_GetHolidayDetourEnabled = false;
    5.22  
    5.23  	return true;
    5.24  }
    5.25 @@ -155,6 +158,7 @@
    5.26  	plsys->RemovePluginsListener(this);
    5.27  
    5.28  	forwards->ReleaseForward(g_critForward);
    5.29 +	forwards->ReleaseForward(g_getHolidayForward);
    5.30  }
    5.31  
    5.32  void TF2Tools::SDK_OnAllLoaded()
    5.33 @@ -297,19 +301,29 @@
    5.34  
    5.35  void TF2Tools::OnPluginLoaded(IPlugin *plugin)
    5.36  {
    5.37 -	if (!m_DetoursEnabled && g_critForward->GetFunctionCount())
    5.38 +	if (!m_CritDetoursEnabled && g_critForward->GetFunctionCount())
    5.39  	{
    5.40 -		InitialiseDetours();
    5.41 -		m_DetoursEnabled = true;
    5.42 +		InitialiseCritDetours();
    5.43 +		m_CritDetoursEnabled = true;
    5.44 +	}
    5.45 +	if (!m_GetHolidayDetourEnabled && g_getHolidayForward->GetFunctionCount())
    5.46 +	{
    5.47 +		InitialiseGetHolidayDetour();
    5.48 +		m_GetHolidayDetourEnabled = true;
    5.49  	}
    5.50  }
    5.51  
    5.52  void TF2Tools::OnPluginUnloaded(IPlugin *plugin)
    5.53  {
    5.54 -	if (m_DetoursEnabled && !g_critForward->GetFunctionCount())
    5.55 +	if (m_CritDetoursEnabled && !g_critForward->GetFunctionCount())
    5.56  	{
    5.57 -		RemoveDetours();
    5.58 -		m_DetoursEnabled = false;
    5.59 +		RemoveCritDetours();
    5.60 +		m_CritDetoursEnabled = false;
    5.61 +	}
    5.62 +	if (m_GetHolidayDetourEnabled && !g_getHolidayForward->GetFunctionCount())
    5.63 +	{
    5.64 +		RemoveGetHolidayDetour();
    5.65 +		m_GetHolidayDetourEnabled = false;
    5.66  	}
    5.67  }
    5.68  int FindResourceEntity()
     6.1 --- a/extensions/tf2/extension.h	Sun Jun 27 19:17:25 2010 -0400
     6.2 +++ b/extensions/tf2/extension.h	Mon Jun 28 17:48:14 2010 -0400
     6.3 @@ -112,7 +112,8 @@
     6.4  	virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
     6.5  #endif
     6.6  private:
     6.7 -	bool m_DetoursEnabled;
     6.8 +	bool m_CritDetoursEnabled;
     6.9 +	bool m_GetHolidayDetourEnabled;
    6.10  };
    6.11  
    6.12  enum TFClassType
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/extensions/tf2/holiday.cpp	Mon Jun 28 17:48:14 2010 -0400
     7.3 @@ -0,0 +1,77 @@
     7.4 +/**
     7.5 + * vim: set ts=4 :
     7.6 + * =============================================================================
     7.7 + * SourceMod Team Fortress 2 Extension
     7.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     7.9 + * =============================================================================
    7.10 + *
    7.11 + * This program is free software; you can redistribute it and/or modify it under
    7.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    7.13 + * Free Software Foundation.
    7.14 + * 
    7.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    7.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    7.18 + * details.
    7.19 + *
    7.20 + * You should have received a copy of the GNU General Public License along with
    7.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    7.22 + *
    7.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    7.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    7.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    7.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    7.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    7.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    7.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    7.30 + * or <http://www.sourcemod.net/license.php>.
    7.31 + *
    7.32 + * Version: $Id$
    7.33 + */
    7.34 +
    7.35 +#include "holiday.h"
    7.36 +
    7.37 +CDetour *getHolidayDetour = NULL;
    7.38 +
    7.39 +IForward *g_getHolidayForward = NULL;
    7.40 +
    7.41 +DETOUR_DECL_MEMBER0(GetHoliday, int)
    7.42 +{
    7.43 +	int actualres = DETOUR_MEMBER_CALL(GetHoliday)();
    7.44 +	if (!g_getHolidayForward)
    7.45 +	{
    7.46 +		g_pSM->LogMessage(myself, "Invalid Forward");
    7.47 +		return actualres;
    7.48 +	}
    7.49 +
    7.50 +	cell_t result = 0;
    7.51 +	int newres = actualres;
    7.52 +
    7.53 +	g_getHolidayForward->PushCellByRef(&newres);
    7.54 +	g_getHolidayForward->Execute(&result);
    7.55 +	
    7.56 +	if (result == Pl_Changed)
    7.57 +	{
    7.58 +		return newres;
    7.59 +	}
    7.60 +
    7.61 +	return actualres;
    7.62 +}
    7.63 +
    7.64 +void InitialiseGetHolidayDetour()
    7.65 +{
    7.66 +	getHolidayDetour = DETOUR_CREATE_MEMBER(GetHoliday, "GetHoliday");
    7.67 +
    7.68 +	if (!getHolidayDetour)
    7.69 +	{
    7.70 +		g_pSM->LogError(myself, "GetHoliday detour failed");
    7.71 +		return;
    7.72 +	}
    7.73 +
    7.74 +	getHolidayDetour->EnableDetour();
    7.75 +}
    7.76 +
    7.77 +void RemoveGetHolidayDetour()
    7.78 +{
    7.79 +	getHolidayDetour->Destroy();
    7.80 +}
    7.81 \ No newline at end of file
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/extensions/tf2/holiday.h	Mon Jun 28 17:48:14 2010 -0400
     8.3 @@ -0,0 +1,45 @@
     8.4 +/**
     8.5 + * vim: set ts=4 :
     8.6 + * =============================================================================
     8.7 + * SourceMod Team Fortress 2 Extension
     8.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     8.9 + * =============================================================================
    8.10 + *
    8.11 + * This program is free software; you can redistribute it and/or modify it under
    8.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    8.13 + * Free Software Foundation.
    8.14 + * 
    8.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    8.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    8.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    8.18 + * details.
    8.19 + *
    8.20 + * You should have received a copy of the GNU General Public License along with
    8.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    8.22 + *
    8.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    8.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    8.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    8.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    8.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    8.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    8.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    8.30 + * or <http://www.sourcemod.net/license.php>.
    8.31 + *
    8.32 + * Version: $Id$
    8.33 + */
    8.34 +
    8.35 +#ifndef _INCLUDE_SOURCEMOD_HOLIDAY_H_
    8.36 +#define _INCLUDE_SOURCEMOD_HOLIDAY_H_
    8.37 +
    8.38 +#include "extension.h"
    8.39 +#include <jit/jit_helpers.h>
    8.40 +#include <jit/x86/x86_macros.h>
    8.41 +#include "CDetour/detours.h"
    8.42 +
    8.43 +void InitialiseGetHolidayDetour();
    8.44 +void RemoveGetHolidayDetour();
    8.45 +
    8.46 +extern IForward *g_getHolidayForward;
    8.47 +
    8.48 +#endif //_INCLUDE_SOURCEMOD_HOLIDAY_H_
     9.1 --- a/extensions/tf2/msvc9/tf2.vcproj	Sun Jun 27 19:17:25 2010 -0400
     9.2 +++ b/extensions/tf2/msvc9/tf2.vcproj	Mon Jun 28 17:48:14 2010 -0400
     9.3 @@ -195,6 +195,10 @@
     9.4  				>
     9.5  			</File>
     9.6  			<File
     9.7 +				RelativePath="..\holiday.cpp"
     9.8 +				>
     9.9 +			</File>
    9.10 +			<File
    9.11  				RelativePath="..\natives.cpp"
    9.12  				>
    9.13  			</File>
    9.14 @@ -221,6 +225,10 @@
    9.15  				>
    9.16  			</File>
    9.17  			<File
    9.18 +				RelativePath="..\holiday.h"
    9.19 +				>
    9.20 +			</File>
    9.21 +			<File
    9.22  				RelativePath="..\RegNatives.h"
    9.23  				>
    9.24  			</File>
    10.1 --- a/gamedata/sm-tf2.games.txt	Sun Jun 27 19:17:25 2010 -0400
    10.2 +++ b/gamedata/sm-tf2.games.txt	Mon Jun 28 17:48:14 2010 -0400
    10.3 @@ -92,6 +92,13 @@
    10.4  				"linux"		"@_ZN15CTFPlayerShared10StunPlayerEffiP9CTFPlayer"
    10.5  				"mac"		"@_ZN15CTFPlayerShared10StunPlayerEffiP9CTFPlayer"
    10.6  			}
    10.7 +			"GetHoliday"
    10.8 +			{
    10.9 +				"library"	"server"
   10.10 +				"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"
   10.11 +				"linux"		"@_ZN12CTFGameRules10GetHolidayEv"
   10.12 +				"mac"		"@_ZN12CTFGameRules10GetHolidayEv"
   10.13 +			}
   10.14  		}
   10.15  		"Offsets"
   10.16  		{
    11.1 --- a/plugins/include/tf2.inc	Sun Jun 27 19:17:25 2010 -0400
    11.2 +++ b/plugins/include/tf2.inc	Mon Jun 28 17:48:14 2010 -0400
    11.3 @@ -99,6 +99,13 @@
    11.4  	TFCond_Jarated
    11.5  };
    11.6  
    11.7 +enum TFHoliday
    11.8 +{
    11.9 +	TFHoliday_None = 1,
   11.10 +	TFHoliday_Halloween,
   11.11 +	TFHoliday_Birthday
   11.12 +};
   11.13 +
   11.14  /**
   11.15   * Sets a client on fire for 10 seconds.
   11.16   *
   11.17 @@ -225,6 +232,16 @@
   11.18  forward Action:TF2_CalcIsAttackCritical(client, weapon, String:weaponname[], &bool:result);
   11.19  
   11.20  /**
   11.21 + * Called when the game checks to see if the current day is one of its tracked holidays
   11.22 + *
   11.23 + * @note Change the value of holiday and return Plugin_Changed to override.
   11.24 + *       Return Plugin_Continue for no change.
   11.25 + *
   11.26 + * @param holiday		Current Holiday
   11.27 + */
   11.28 +forward Action:TF2_OnGetHoliday(&TFHoliday:holiday);
   11.29 +
   11.30 +/**
   11.31   * Do not edit below this line!
   11.32   */
   11.33  public Extension:__ext_tf2 =