Added TF2_CanPlayerTeleport forward to the TF2 game extension (bug 5283, r=asherkin).

This commit is contained in:
Ryan Stecker
2012-05-28 01:14:46 +01:00
parent 70994cb4b2
commit 3d25938dd7
11 changed files with 192 additions and 1 deletions
+1
View File
@@ -17,6 +17,7 @@ binary.AddSourceFiles('extensions/tf2', [
'util.cpp',
'criticals.cpp',
'holiday.cpp',
'teleporter.cpp',
'gameplayrules.cpp',
'conditions.cpp',
'CDetour/detours.cpp',
+1 -1
View File
@@ -19,7 +19,7 @@ PROJECT = game.tf2
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 ###
+14
View File
@@ -39,6 +39,7 @@
#include "holiday.h"
#include "conditions.h"
#include "gameplayrules.h"
#include "teleporter.h"
#include "CDetour/detours.h"
/**
@@ -117,6 +118,7 @@ bool TF2Tools::SDK_OnLoad(char *error, size_t maxlength, bool late)
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 @@ bool TF2Tools::SDK_OnLoad(char *error, size_t maxlength, bool late)
m_IsHolidayDetourEnabled = false;
m_CondChecksEnabled = false;
m_RulesDetoursEnabled = false;
m_TeleportDetourEnabled = false;
return true;
}
@@ -173,6 +176,7 @@ void TF2Tools::SDK_OnUnload()
forwards->ReleaseForward(g_removeCondForward);
forwards->ReleaseForward(g_waitingPlayersStartForward);
forwards->ReleaseForward(g_waitingPlayersEndForward);
forwards->ReleaseForward(g_teleportForward);
}
void TF2Tools::SDK_OnAllLoaded()
@@ -338,6 +342,11 @@ void TF2Tools::OnPluginLoaded(IPlugin *plugin)
{
m_RulesDetoursEnabled = InitialiseRulesDetours();
}
if (!m_TeleportDetourEnabled && g_teleportForward->GetFunctionCount())
{
m_TeleportDetourEnabled = InitialiseTeleporterDetour();
}
}
void TF2Tools::OnPluginUnloaded(IPlugin *plugin)
@@ -368,6 +377,11 @@ void TF2Tools::OnPluginUnloaded(IPlugin *plugin)
m_RulesDetoursEnabled = false;
}
}
if (m_TeleportDetourEnabled && !g_teleportForward->GetFunctionCount())
{
RemoveTeleporterDetour();
m_TeleportDetourEnabled = false;
}
}
void TF2Tools::OnClientPutInServer(int client)
+1
View File
@@ -121,6 +121,7 @@ private:
bool m_IsHolidayDetourEnabled;
bool m_CondChecksEnabled;
bool m_RulesDetoursEnabled;
bool m_TeleportDetourEnabled;
};
enum TFClassType
+2
View File
@@ -114,6 +114,7 @@
<ClCompile Include="..\holiday.cpp" />
<ClCompile Include="..\natives.cpp" />
<ClCompile Include="..\RegNatives.cpp" />
<ClCompile Include="..\teleporter.cpp" />
<ClCompile Include="..\util.cpp" />
<ClCompile Include="..\sdk\smsdk_ext.cpp" />
<ClCompile Include="..\CDetour\detours.cpp" />
@@ -126,6 +127,7 @@
<ClInclude Include="..\gameplayrules.h" />
<ClInclude Include="..\holiday.h" />
<ClInclude Include="..\RegNatives.h" />
<ClInclude Include="..\teleporter.h" />
<ClInclude Include="..\util.h" />
<ClInclude Include="..\sdk\smsdk_config.h" />
<ClInclude Include="..\sdk\smsdk_ext.h" />
@@ -57,6 +57,9 @@
<ClCompile Include="..\asm\asm.c">
<Filter>asm</Filter>
</ClCompile>
<ClCompile Include="..\teleporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\conditions.h">
@@ -95,5 +98,8 @@
<ClInclude Include="..\asm\asm.h">
<Filter>asm</Filter>
</ClInclude>
<ClInclude Include="..\teleporter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
+8
View File
@@ -215,6 +215,10 @@
RelativePath="..\RegNatives.cpp"
>
</File>
<File
RelativePath="..\teleporter.cpp"
>
</File>
<File
RelativePath="..\util.cpp"
>
@@ -249,6 +253,10 @@
RelativePath="..\RegNatives.h"
>
</File>
<File
RelativePath="..\teleporter.h"
>
</File>
<File
RelativePath="..\util.h"
>
+96
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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 <http://www.sourcemod.net/license.php>.
*
* 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;
}
}
+43
View File
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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 <http://www.sourcemod.net/license.php>.
*
* 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_