Added TF2_CanPlayerTeleport forward to the TF2 game extension (bug 5283, r=asherkin).
authorRyan Stecker <voidedweasel@gmail.com>
Mon May 28 01:14:46 2012 +0100 (2012-05-28)
changeset 3533f35b66137b06
parent 3532 88a0d2c30bc3
child 3534 25d1266f1ed5
Added TF2_CanPlayerTeleport forward to the TF2 game extension (bug 5283, r=asherkin).
extensions/tf2/AMBuilder
extensions/tf2/Makefile
extensions/tf2/extension.cpp
extensions/tf2/extension.h
extensions/tf2/msvc10/tf2.vcxproj
extensions/tf2/msvc10/tf2.vcxproj.filters
extensions/tf2/msvc9/tf2.vcproj
extensions/tf2/teleporter.cpp
extensions/tf2/teleporter.h
gamedata/sm-tf2.games.txt
plugins/include/tf2.inc
     1.1 --- a/extensions/tf2/AMBuilder	Mon May 28 00:58:59 2012 +0100
     1.2 +++ b/extensions/tf2/AMBuilder	Mon May 28 01:14:46 2012 +0100
     1.3 @@ -17,6 +17,7 @@
     1.4  	'util.cpp',
     1.5  	'criticals.cpp',
     1.6  	'holiday.cpp',
     1.7 +	'teleporter.cpp',
     1.8  	'gameplayrules.cpp',
     1.9  	'conditions.cpp',
    1.10  	'CDetour/detours.cpp',
     2.1 --- a/extensions/tf2/Makefile	Mon May 28 00:58:59 2012 +0100
     2.2 +++ b/extensions/tf2/Makefile	Mon May 28 01:14:46 2012 +0100
     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 -	holiday.cpp gameplayrules.cpp conditions.cpp util.cpp CDetour/detours.cpp asm/asm.c
     2.8 +	holiday.cpp gameplayrules.cpp conditions.cpp util.cpp teleporter.cpp CDetour/detours.cpp asm/asm.c
     2.9  
    2.10  ##############################################
    2.11  ### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
     3.1 --- a/extensions/tf2/extension.cpp	Mon May 28 00:58:59 2012 +0100
     3.2 +++ b/extensions/tf2/extension.cpp	Mon May 28 01:14:46 2012 +0100
     3.3 @@ -39,6 +39,7 @@
     3.4  #include "holiday.h"
     3.5  #include "conditions.h"
     3.6  #include "gameplayrules.h"
     3.7 +#include "teleporter.h"
     3.8  #include "CDetour/detours.h"
     3.9  
    3.10  /**
    3.11 @@ -117,6 +118,7 @@
    3.12  	g_removeCondForward = forwards->CreateForward("TF2_OnConditionRemoved", ET_Ignore, 2, NULL, Param_Cell, Param_Cell);
    3.13  	g_waitingPlayersStartForward = forwards->CreateForward("TF2_OnWaitingForPlayersStart", ET_Ignore, 0, NULL);
    3.14  	g_waitingPlayersEndForward = forwards->CreateForward("TF2_OnWaitingForPlayersEnd", ET_Ignore, 0, NULL);
    3.15 +	g_teleportForward = forwards->CreateForward("TF2_OnPlayerTeleport", ET_Hook, 3, NULL, Param_Cell, Param_Cell, Param_CellByRef);
    3.16  
    3.17  	g_pCVar = icvar;
    3.18  
    3.19 @@ -124,6 +126,7 @@
    3.20  	m_IsHolidayDetourEnabled = false;
    3.21  	m_CondChecksEnabled = false;
    3.22  	m_RulesDetoursEnabled = false;
    3.23 +	m_TeleportDetourEnabled = false;
    3.24  
    3.25  	return true;
    3.26  }
    3.27 @@ -173,6 +176,7 @@
    3.28  	forwards->ReleaseForward(g_removeCondForward);
    3.29  	forwards->ReleaseForward(g_waitingPlayersStartForward);
    3.30  	forwards->ReleaseForward(g_waitingPlayersEndForward);
    3.31 +	forwards->ReleaseForward(g_teleportForward);
    3.32  }
    3.33  
    3.34  void TF2Tools::SDK_OnAllLoaded()
    3.35 @@ -338,6 +342,11 @@
    3.36  	{
    3.37  		m_RulesDetoursEnabled = InitialiseRulesDetours();
    3.38  	}
    3.39 +
    3.40 +	if (!m_TeleportDetourEnabled && g_teleportForward->GetFunctionCount())
    3.41 +	{
    3.42 +		m_TeleportDetourEnabled = InitialiseTeleporterDetour();
    3.43 +	}
    3.44  }
    3.45  
    3.46  void TF2Tools::OnPluginUnloaded(IPlugin *plugin)
    3.47 @@ -368,6 +377,11 @@
    3.48  			m_RulesDetoursEnabled = false;
    3.49  		}
    3.50  	}
    3.51 +	if (m_TeleportDetourEnabled && !g_teleportForward->GetFunctionCount())
    3.52 +	{
    3.53 +		RemoveTeleporterDetour();
    3.54 +		m_TeleportDetourEnabled = false;
    3.55 +	}
    3.56  }
    3.57  
    3.58  void TF2Tools::OnClientPutInServer(int client)
     4.1 --- a/extensions/tf2/extension.h	Mon May 28 00:58:59 2012 +0100
     4.2 +++ b/extensions/tf2/extension.h	Mon May 28 01:14:46 2012 +0100
     4.3 @@ -121,6 +121,7 @@
     4.4  	bool m_IsHolidayDetourEnabled;
     4.5  	bool m_CondChecksEnabled;
     4.6  	bool m_RulesDetoursEnabled;
     4.7 +	bool m_TeleportDetourEnabled;
     4.8  };
     4.9  
    4.10  enum TFClassType
     5.1 --- a/extensions/tf2/msvc10/tf2.vcxproj	Mon May 28 00:58:59 2012 +0100
     5.2 +++ b/extensions/tf2/msvc10/tf2.vcxproj	Mon May 28 01:14:46 2012 +0100
     5.3 @@ -114,6 +114,7 @@
     5.4      <ClCompile Include="..\holiday.cpp" />
     5.5      <ClCompile Include="..\natives.cpp" />
     5.6      <ClCompile Include="..\RegNatives.cpp" />
     5.7 +    <ClCompile Include="..\teleporter.cpp" />
     5.8      <ClCompile Include="..\util.cpp" />
     5.9      <ClCompile Include="..\sdk\smsdk_ext.cpp" />
    5.10      <ClCompile Include="..\CDetour\detours.cpp" />
    5.11 @@ -126,6 +127,7 @@
    5.12      <ClInclude Include="..\gameplayrules.h" />
    5.13      <ClInclude Include="..\holiday.h" />
    5.14      <ClInclude Include="..\RegNatives.h" />
    5.15 +    <ClInclude Include="..\teleporter.h" />
    5.16      <ClInclude Include="..\util.h" />
    5.17      <ClInclude Include="..\sdk\smsdk_config.h" />
    5.18      <ClInclude Include="..\sdk\smsdk_ext.h" />
     6.1 --- a/extensions/tf2/msvc10/tf2.vcxproj.filters	Mon May 28 00:58:59 2012 +0100
     6.2 +++ b/extensions/tf2/msvc10/tf2.vcxproj.filters	Mon May 28 01:14:46 2012 +0100
     6.3 @@ -57,6 +57,9 @@
     6.4      <ClCompile Include="..\asm\asm.c">
     6.5        <Filter>asm</Filter>
     6.6      </ClCompile>
     6.7 +    <ClCompile Include="..\teleporter.cpp">
     6.8 +      <Filter>Source Files</Filter>
     6.9 +    </ClCompile>
    6.10    </ItemGroup>
    6.11    <ItemGroup>
    6.12      <ClInclude Include="..\conditions.h">
    6.13 @@ -95,5 +98,8 @@
    6.14      <ClInclude Include="..\asm\asm.h">
    6.15        <Filter>asm</Filter>
    6.16      </ClInclude>
    6.17 +    <ClInclude Include="..\teleporter.h">
    6.18 +      <Filter>Header Files</Filter>
    6.19 +    </ClInclude>
    6.20    </ItemGroup>
    6.21  </Project>
    6.22 \ No newline at end of file
     7.1 --- a/extensions/tf2/msvc9/tf2.vcproj	Mon May 28 00:58:59 2012 +0100
     7.2 +++ b/extensions/tf2/msvc9/tf2.vcproj	Mon May 28 01:14:46 2012 +0100
     7.3 @@ -216,6 +216,10 @@
     7.4  				>
     7.5  			</File>
     7.6  			<File
     7.7 +				RelativePath="..\teleporter.cpp"
     7.8 +				>
     7.9 +			</File>
    7.10 +			<File
    7.11  				RelativePath="..\util.cpp"
    7.12  				>
    7.13  			</File>
    7.14 @@ -250,6 +254,10 @@
    7.15  				>
    7.16  			</File>
    7.17  			<File
    7.18 +				RelativePath="..\teleporter.h"
    7.19 +				>
    7.20 +			</File>
    7.21 +			<File
    7.22  				RelativePath="..\util.h"
    7.23  				>
    7.24  			</File>
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/extensions/tf2/teleporter.cpp	Mon May 28 01:14:46 2012 +0100
     8.3 @@ -0,0 +1,96 @@
     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 +#include "teleporter.h"
    8.36 +
    8.37 +CDetour *canPlayerTeleportDetour = NULL;
    8.38 +
    8.39 +IForward *g_teleportForward = NULL;
    8.40 +
    8.41 +class CTFPlayer;
    8.42 +
    8.43 +DETOUR_DECL_MEMBER1(CanPlayerBeTeleported, bool, CTFPlayer *, pPlayer)
    8.44 +{
    8.45 +	bool origCanTeleport = DETOUR_MEMBER_CALL(CanPlayerBeTeleported)(pPlayer);
    8.46 +
    8.47 +	cell_t teleporterCell = gamehelpers->EntityToBCompatRef((CBaseEntity *)this);
    8.48 +	cell_t playerCell = gamehelpers->EntityToBCompatRef((CBaseEntity *)pPlayer);
    8.49 +
    8.50 +	if (!g_teleportForward)
    8.51 +	{
    8.52 +		g_pSM->LogMessage(myself, "Teleport forward is invalid");
    8.53 +		return origCanTeleport;
    8.54 +	}
    8.55 +
    8.56 +	cell_t returnValue = origCanTeleport ? 1 : 0;
    8.57 +
    8.58 +	g_teleportForward->PushCell(playerCell); // client
    8.59 +	g_teleportForward->PushCell(teleporterCell); // teleporter
    8.60 +	g_teleportForward->PushCellByRef(&returnValue); // return value
    8.61 +
    8.62 +	cell_t result = 0;
    8.63 +
    8.64 +	g_teleportForward->Execute(&result);
    8.65 +
    8.66 +	if (result > Pl_Continue)
    8.67 +	{
    8.68 +		// plugin wants to override the game (returned something other than Plugin_Continue)
    8.69 +		return returnValue == 1;
    8.70 +	}
    8.71 +	else
    8.72 +	{
    8.73 +		return origCanTeleport; // let the game decide
    8.74 +	}
    8.75 +}
    8.76 +
    8.77 +bool InitialiseTeleporterDetour()
    8.78 +{
    8.79 +	canPlayerTeleportDetour = DETOUR_CREATE_MEMBER(CanPlayerBeTeleported, "CanPlayerTeleport");
    8.80 +
    8.81 +	if (canPlayerTeleportDetour != NULL)
    8.82 +	{
    8.83 +		canPlayerTeleportDetour->EnableDetour();
    8.84 +		return true;
    8.85 +	}
    8.86 +
    8.87 +	g_pSM->LogError(myself, "Teleport forward could not be initialized - Disabled hook");
    8.88 +
    8.89 +	return false;
    8.90 +}
    8.91 +
    8.92 +void RemoveTeleporterDetour()
    8.93 +{
    8.94 +	if (canPlayerTeleportDetour != NULL)
    8.95 +	{
    8.96 +		canPlayerTeleportDetour->Destroy();
    8.97 +		canPlayerTeleportDetour = NULL;
    8.98 +	}
    8.99 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/extensions/tf2/teleporter.h	Mon May 28 01:14:46 2012 +0100
     9.3 @@ -0,0 +1,43 @@
     9.4 +/**
     9.5 + * vim: set ts=4 :
     9.6 + * =============================================================================
     9.7 + * SourceMod Team Fortress 2 Extension
     9.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     9.9 + * =============================================================================
    9.10 + *
    9.11 + * This program is free software; you can redistribute it and/or modify it under
    9.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    9.13 + * Free Software Foundation.
    9.14 + * 
    9.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    9.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    9.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    9.18 + * details.
    9.19 + *
    9.20 + * You should have received a copy of the GNU General Public License along with
    9.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    9.22 + *
    9.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    9.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    9.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    9.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    9.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    9.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    9.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    9.30 + * or <http://www.sourcemod.net/license.php>.
    9.31 + *
    9.32 + * Version: $Id$
    9.33 + */
    9.34 +
    9.35 +#ifndef _INCLUDE_SOURCEMOD_TELEPORTER_H_
    9.36 +#define _INCLUDE_SOURCEMOD_TELEPORTER_H_
    9.37 +
    9.38 +#include "extension.h"
    9.39 +#include "CDetour/detours.h"
    9.40 +
    9.41 +bool InitialiseTeleporterDetour();
    9.42 +void RemoveTeleporterDetour();
    9.43 +
    9.44 +extern IForward *g_teleportForward;
    9.45 +
    9.46 +#endif //_INCLUDE_SOURCEMOD_TELEPORTER_H_
    10.1 --- a/gamedata/sm-tf2.games.txt	Mon May 28 00:58:59 2012 +0100
    10.2 +++ b/gamedata/sm-tf2.games.txt	Mon May 28 01:14:46 2012 +0100
    10.3 @@ -120,6 +120,13 @@
    10.4  				"linux"		"@_Z21DuelMiniGame_IsInDuelP9CTFPlayer"
    10.5  				"mac"		"@_Z21DuelMiniGame_IsInDuelP9CTFPlayer"
    10.6  			}
    10.7 +			"CanPlayerTeleport"
    10.8 +			{
    10.9 +				"library"	"server"
   10.10 +				"windows"	"\x55\x8b\xec\x53\x8b\x5d\x08\x85\xdb\x56\x8b\xf1\x74\x2A\x8b\xcb\xe8\x2A\x2A\x2A\x2A\x84\xc0"
   10.11 +				"linux"		"@_ZN17CObjectTeleporter21PlayerCanBeTeleportedEP9CTFPlayer"
   10.12 +				"mac"		"@_ZN17CObjectTeleporter21PlayerCanBeTeleportedEP9CTFPlayer"
   10.13 +			}
   10.14  		}
   10.15  		"Offsets"
   10.16  		{
    11.1 --- a/plugins/include/tf2.inc	Mon May 28 00:58:59 2012 +0100
    11.2 +++ b/plugins/include/tf2.inc	Mon May 28 01:14:46 2012 +0100
    11.3 @@ -340,6 +340,19 @@
    11.4  forward TF2_OnWaitingForPlayersEnd();
    11.5  
    11.6  /**
    11.7 + * Called when a player attempts to use a teleporter to decide if the player should be allowed to teleport.
    11.8 + * Return Plugin_Continue to let the original calculation or return a higher
    11.9 + * action to override the decision with the value of 'result'
   11.10 + *
   11.11 + * @param client		Client index.
   11.12 + * @param teleporter	Teleporter entity index.
   11.13 + * @param result		Buffer param for the result of the decision.
   11.14 + *						This is prepopulated with the game's original decision to let a player teleport.
   11.15 + * @return				Plugin_Continue for original calculation, higher value to use 'result'.
   11.16 + */
   11.17 +forward Action:TF2_OnPlayerTeleport(client, teleporter, &bool:result);
   11.18 + 
   11.19 +/**
   11.20   * Do not edit below this line!
   11.21   */
   11.22  public Extension:__ext_tf2 =