# HG changeset patch # User Ryan Stecker # Date 1338164086 -3600 # Node ID f35b66137b06c24f8864c2290cd78a0a061a84e5 # Parent 88a0d2c30bc32e1bea72e33c134cc1221be99a2c Added TF2_CanPlayerTeleport forward to the TF2 game extension (bug 5283, r=asherkin). diff -r 88a0d2c30bc3 -r f35b66137b06 extensions/tf2/AMBuilder --- a/extensions/tf2/AMBuilder Mon May 28 00:58:59 2012 +0100 +++ b/extensions/tf2/AMBuilder Mon May 28 01:14:46 2012 +0100 @@ -17,6 +17,7 @@ 'util.cpp', 'criticals.cpp', 'holiday.cpp', + 'teleporter.cpp', 'gameplayrules.cpp', 'conditions.cpp', 'CDetour/detours.cpp', diff -r 88a0d2c30bc3 -r f35b66137b06 extensions/tf2/Makefile --- a/extensions/tf2/Makefile Mon May 28 00:58:59 2012 +0100 +++ b/extensions/tf2/Makefile Mon May 28 01:14:46 2012 +0100 @@ -19,7 +19,7 @@ USEMETA = true OBJECTS = sdk/smsdk_ext.cpp extension.cpp natives.cpp RegNatives.cpp criticals.cpp \ - holiday.cpp gameplayrules.cpp conditions.cpp util.cpp CDetour/detours.cpp asm/asm.c + holiday.cpp gameplayrules.cpp conditions.cpp util.cpp teleporter.cpp CDetour/detours.cpp asm/asm.c ############################################## ### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### diff -r 88a0d2c30bc3 -r f35b66137b06 extensions/tf2/extension.cpp --- a/extensions/tf2/extension.cpp Mon May 28 00:58:59 2012 +0100 +++ b/extensions/tf2/extension.cpp Mon May 28 01:14:46 2012 +0100 @@ -39,6 +39,7 @@ #include "holiday.h" #include "conditions.h" #include "gameplayrules.h" +#include "teleporter.h" #include "CDetour/detours.h" /** @@ -117,6 +118,7 @@ g_removeCondForward = forwards->CreateForward("TF2_OnConditionRemoved", ET_Ignore, 2, NULL, Param_Cell, Param_Cell); g_waitingPlayersStartForward = forwards->CreateForward("TF2_OnWaitingForPlayersStart", ET_Ignore, 0, NULL); g_waitingPlayersEndForward = forwards->CreateForward("TF2_OnWaitingForPlayersEnd", ET_Ignore, 0, NULL); + g_teleportForward = forwards->CreateForward("TF2_OnPlayerTeleport", ET_Hook, 3, NULL, Param_Cell, Param_Cell, Param_CellByRef); g_pCVar = icvar; @@ -124,6 +126,7 @@ m_IsHolidayDetourEnabled = false; m_CondChecksEnabled = false; m_RulesDetoursEnabled = false; + m_TeleportDetourEnabled = false; return true; } @@ -173,6 +176,7 @@ forwards->ReleaseForward(g_removeCondForward); forwards->ReleaseForward(g_waitingPlayersStartForward); forwards->ReleaseForward(g_waitingPlayersEndForward); + forwards->ReleaseForward(g_teleportForward); } void TF2Tools::SDK_OnAllLoaded() @@ -338,6 +342,11 @@ { m_RulesDetoursEnabled = InitialiseRulesDetours(); } + + if (!m_TeleportDetourEnabled && g_teleportForward->GetFunctionCount()) + { + m_TeleportDetourEnabled = InitialiseTeleporterDetour(); + } } void TF2Tools::OnPluginUnloaded(IPlugin *plugin) @@ -368,6 +377,11 @@ m_RulesDetoursEnabled = false; } } + if (m_TeleportDetourEnabled && !g_teleportForward->GetFunctionCount()) + { + RemoveTeleporterDetour(); + m_TeleportDetourEnabled = false; + } } void TF2Tools::OnClientPutInServer(int client) diff -r 88a0d2c30bc3 -r f35b66137b06 extensions/tf2/extension.h --- a/extensions/tf2/extension.h Mon May 28 00:58:59 2012 +0100 +++ b/extensions/tf2/extension.h Mon May 28 01:14:46 2012 +0100 @@ -121,6 +121,7 @@ bool m_IsHolidayDetourEnabled; bool m_CondChecksEnabled; bool m_RulesDetoursEnabled; + bool m_TeleportDetourEnabled; }; enum TFClassType diff -r 88a0d2c30bc3 -r f35b66137b06 extensions/tf2/msvc10/tf2.vcxproj --- a/extensions/tf2/msvc10/tf2.vcxproj Mon May 28 00:58:59 2012 +0100 +++ b/extensions/tf2/msvc10/tf2.vcxproj Mon May 28 01:14:46 2012 +0100 @@ -114,6 +114,7 @@ + @@ -126,6 +127,7 @@ + diff -r 88a0d2c30bc3 -r f35b66137b06 extensions/tf2/msvc10/tf2.vcxproj.filters --- a/extensions/tf2/msvc10/tf2.vcxproj.filters Mon May 28 00:58:59 2012 +0100 +++ b/extensions/tf2/msvc10/tf2.vcxproj.filters Mon May 28 01:14:46 2012 +0100 @@ -57,6 +57,9 @@ asm + + Source Files + @@ -95,5 +98,8 @@ asm + + Header Files + \ No newline at end of file diff -r 88a0d2c30bc3 -r f35b66137b06 extensions/tf2/msvc9/tf2.vcproj --- a/extensions/tf2/msvc9/tf2.vcproj Mon May 28 00:58:59 2012 +0100 +++ b/extensions/tf2/msvc9/tf2.vcproj Mon May 28 01:14:46 2012 +0100 @@ -216,6 +216,10 @@ > + + @@ -250,6 +254,10 @@ > + + diff -r 88a0d2c30bc3 -r f35b66137b06 extensions/tf2/teleporter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/tf2/teleporter.cpp Mon May 28 01:14:46 2012 +0100 @@ -0,0 +1,96 @@ +/** + * 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 "teleporter.h" + +CDetour *canPlayerTeleportDetour = NULL; + +IForward *g_teleportForward = NULL; + +class CTFPlayer; + +DETOUR_DECL_MEMBER1(CanPlayerBeTeleported, bool, CTFPlayer *, pPlayer) +{ + bool origCanTeleport = DETOUR_MEMBER_CALL(CanPlayerBeTeleported)(pPlayer); + + cell_t teleporterCell = gamehelpers->EntityToBCompatRef((CBaseEntity *)this); + cell_t playerCell = gamehelpers->EntityToBCompatRef((CBaseEntity *)pPlayer); + + if (!g_teleportForward) + { + g_pSM->LogMessage(myself, "Teleport forward is invalid"); + return origCanTeleport; + } + + cell_t returnValue = origCanTeleport ? 1 : 0; + + g_teleportForward->PushCell(playerCell); // client + g_teleportForward->PushCell(teleporterCell); // teleporter + g_teleportForward->PushCellByRef(&returnValue); // return value + + cell_t result = 0; + + g_teleportForward->Execute(&result); + + if (result > Pl_Continue) + { + // plugin wants to override the game (returned something other than Plugin_Continue) + return returnValue == 1; + } + else + { + return origCanTeleport; // let the game decide + } +} + +bool InitialiseTeleporterDetour() +{ + canPlayerTeleportDetour = DETOUR_CREATE_MEMBER(CanPlayerBeTeleported, "CanPlayerTeleport"); + + if (canPlayerTeleportDetour != NULL) + { + canPlayerTeleportDetour->EnableDetour(); + return true; + } + + g_pSM->LogError(myself, "Teleport forward could not be initialized - Disabled hook"); + + return false; +} + +void RemoveTeleporterDetour() +{ + if (canPlayerTeleportDetour != NULL) + { + canPlayerTeleportDetour->Destroy(); + canPlayerTeleportDetour = NULL; + } +} diff -r 88a0d2c30bc3 -r f35b66137b06 extensions/tf2/teleporter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/tf2/teleporter.h Mon May 28 01:14:46 2012 +0100 @@ -0,0 +1,43 @@ +/** + * 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_TELEPORTER_H_ +#define _INCLUDE_SOURCEMOD_TELEPORTER_H_ + +#include "extension.h" +#include "CDetour/detours.h" + +bool InitialiseTeleporterDetour(); +void RemoveTeleporterDetour(); + +extern IForward *g_teleportForward; + +#endif //_INCLUDE_SOURCEMOD_TELEPORTER_H_ diff -r 88a0d2c30bc3 -r f35b66137b06 gamedata/sm-tf2.games.txt --- a/gamedata/sm-tf2.games.txt Mon May 28 00:58:59 2012 +0100 +++ b/gamedata/sm-tf2.games.txt Mon May 28 01:14:46 2012 +0100 @@ -120,6 +120,13 @@ "linux" "@_Z21DuelMiniGame_IsInDuelP9CTFPlayer" "mac" "@_Z21DuelMiniGame_IsInDuelP9CTFPlayer" } + "CanPlayerTeleport" + { + "library" "server" + "windows" "\x55\x8b\xec\x53\x8b\x5d\x08\x85\xdb\x56\x8b\xf1\x74\x2A\x8b\xcb\xe8\x2A\x2A\x2A\x2A\x84\xc0" + "linux" "@_ZN17CObjectTeleporter21PlayerCanBeTeleportedEP9CTFPlayer" + "mac" "@_ZN17CObjectTeleporter21PlayerCanBeTeleportedEP9CTFPlayer" + } } "Offsets" { diff -r 88a0d2c30bc3 -r f35b66137b06 plugins/include/tf2.inc --- a/plugins/include/tf2.inc Mon May 28 00:58:59 2012 +0100 +++ b/plugins/include/tf2.inc Mon May 28 01:14:46 2012 +0100 @@ -340,6 +340,19 @@ forward TF2_OnWaitingForPlayersEnd(); /** + * Called when a player attempts to use a teleporter to decide if the player should be allowed to teleport. + * Return Plugin_Continue to let the original calculation or return a higher + * action to override the decision with the value of 'result' + * + * @param client Client index. + * @param teleporter Teleporter entity index. + * @param result Buffer param for the result of the decision. + * This is prepopulated with the game's original decision to let a player teleport. + * @return Plugin_Continue for original calculation, higher value to use 'result'. + */ +forward Action:TF2_OnPlayerTeleport(client, teleporter, &bool:result); + +/** * Do not edit below this line! */ public Extension:__ext_tf2 =