Add WaitingForPlayers forwards to TF2 extension (bug 4704, r=pred)

This commit is contained in:
Brett Powell 2010-11-19 17:58:46 +13:00
parent 6267c17c6b
commit c9eaca0e56
8 changed files with 177 additions and 1 deletions

View File

@ -17,6 +17,7 @@ binary.AddSourceFiles('extensions/tf2', [
'util.cpp', 'util.cpp',
'criticals.cpp', 'criticals.cpp',
'holiday.cpp', 'holiday.cpp',
'gameplayrules.cpp'
'CDetour/detours.cpp', 'CDetour/detours.cpp',
'sdk/smsdk_ext.cpp', 'sdk/smsdk_ext.cpp',
'asm/asm.c' 'asm/asm.c'

View File

@ -19,7 +19,7 @@ PROJECT = game.tf2
USEMETA = true USEMETA = true
OBJECTS = sdk/smsdk_ext.cpp extension.cpp natives.cpp RegNatives.cpp criticals.cpp \ OBJECTS = sdk/smsdk_ext.cpp extension.cpp natives.cpp RegNatives.cpp criticals.cpp \
holiday.cpp util.cpp CDetour/detours.cpp asm/asm.c holiday.cpp gameplayrules.cpp util.cpp CDetour/detours.cpp asm/asm.c
############################################## ##############################################
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### ### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###

View File

@ -37,6 +37,7 @@
#include "sm_trie_tpl.h" #include "sm_trie_tpl.h"
#include "criticals.h" #include "criticals.h"
#include "holiday.h" #include "holiday.h"
#include "gameplayrules.h"
#include "CDetour/detours.h" #include "CDetour/detours.h"
/** /**
@ -110,11 +111,14 @@ bool TF2Tools::SDK_OnLoad(char *error, size_t maxlength, bool late)
g_critForward = forwards->CreateForward("TF2_CalcIsAttackCritical", ET_Hook, 4, NULL, Param_Cell, Param_Cell, Param_String, Param_CellByRef); 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_getHolidayForward = forwards->CreateForward("TF2_OnGetHoliday", ET_Event, 1, NULL, Param_CellByRef);
g_waitingPlayersStartForward = forwards->CreateForward("TF2_OnWaitingForPlayersStart", ET_Ignore, 0, NULL);
g_waitingPlayersEndForward = forwards->CreateForward("TF2_OnWaitingForPlayersEnd", ET_Ignore, 0, NULL);
g_pCVar = icvar; g_pCVar = icvar;
m_CritDetoursEnabled = false; m_CritDetoursEnabled = false;
m_GetHolidayDetourEnabled = false; m_GetHolidayDetourEnabled = false;
m_RulesDetoursEnabled = false;
return true; return true;
} }
@ -159,6 +163,8 @@ void TF2Tools::SDK_OnUnload()
forwards->ReleaseForward(g_critForward); forwards->ReleaseForward(g_critForward);
forwards->ReleaseForward(g_getHolidayForward); forwards->ReleaseForward(g_getHolidayForward);
forwards->ReleaseForward(g_waitingPlayersStartForward);
forwards->ReleaseForward(g_waitingPlayersEndForward);
} }
void TF2Tools::SDK_OnAllLoaded() void TF2Tools::SDK_OnAllLoaded()
@ -311,6 +317,14 @@ void TF2Tools::OnPluginLoaded(IPlugin *plugin)
InitialiseGetHolidayDetour(); InitialiseGetHolidayDetour();
m_GetHolidayDetourEnabled = true; m_GetHolidayDetourEnabled = true;
} }
if (!m_RulesDetoursEnabled)
{
if(g_waitingPlayersStartForward->GetFunctionCount() || g_waitingPlayersEndForward->GetFunctionCount())
{
InitialiseRulesDetours();
m_RulesDetoursEnabled = true;
}
}
} }
void TF2Tools::OnPluginUnloaded(IPlugin *plugin) void TF2Tools::OnPluginUnloaded(IPlugin *plugin)
@ -325,6 +339,14 @@ void TF2Tools::OnPluginUnloaded(IPlugin *plugin)
RemoveGetHolidayDetour(); RemoveGetHolidayDetour();
m_GetHolidayDetourEnabled = false; m_GetHolidayDetourEnabled = false;
} }
if (m_RulesDetoursEnabled)
{
if(!g_waitingPlayersStartForward->GetFunctionCount() || !g_waitingPlayersEndForward->GetFunctionCount())
{
RemoveRulesDetours();
m_RulesDetoursEnabled = false;
}
}
} }
int FindResourceEntity() int FindResourceEntity()
{ {

View File

@ -114,6 +114,7 @@ public:
private: private:
bool m_CritDetoursEnabled; bool m_CritDetoursEnabled;
bool m_GetHolidayDetourEnabled; bool m_GetHolidayDetourEnabled;
bool m_RulesDetoursEnabled;
}; };
enum TFClassType enum TFClassType

View File

@ -0,0 +1,83 @@
/**
* 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 "gameplayrules.h"
CDetour *setInWaitingForPlayersDetour = NULL;
IForward *g_waitingPlayersStartForward = NULL;
IForward *g_waitingPlayersEndForward = NULL;
DETOUR_DECL_MEMBER1(SetInWaitingForPlayers, void, bool, bWaitingForPlayers)
{
DETOUR_MEMBER_CALL(SetInWaitingForPlayers)(bWaitingForPlayers);
if (bWaitingForPlayers)
{
if (!g_waitingPlayersStartForward)
{
g_pSM->LogMessage(myself, "Invalid Forward");
}
else
{
g_waitingPlayersStartForward->Execute(NULL);
}
}
else
{
if (!g_waitingPlayersEndForward)
{
g_pSM->LogMessage(myself, "Invalid Forward");
}
else
{
g_waitingPlayersEndForward->Execute(NULL);
}
}
}
void InitialiseRulesDetours()
{
setInWaitingForPlayersDetour = DETOUR_CREATE_MEMBER(SetInWaitingForPlayers, "SetInWaitingForPlayers");
if (setInWaitingForPlayersDetour != NULL)
{
setInWaitingForPlayersDetour->EnableDetour();
return;
}
g_pSM->LogError(myself, "No Gameplay Rules detours could be initialized - Disabled Gameplay Rules functions");
}
void RemoveRulesDetours()
{
setInWaitingForPlayersDetour->Destroy();
}

View File

@ -0,0 +1,46 @@
/**
* 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_GAMEPLAY_RULES_H_
#define _INCLUDE_SOURCEMOD_GAMEPLAY_RULES_H_
#include "extension.h"
#include <jit/jit_helpers.h>
#include <jit/x86/x86_macros.h>
#include "CDetour/detours.h"
void InitialiseRulesDetours();
void RemoveRulesDetours();
extern IForward *g_waitingPlayersStartForward;
extern IForward *g_waitingPlayersEndForward;
#endif //_INCLUDE_SOURCEMOD_GAMEPLAY_RULES_H_

View File

@ -59,6 +59,7 @@
<Tool <Tool
Name="VCResourceCompilerTool" Name="VCResourceCompilerTool"
PreprocessorDefinitions="BINARY_NAME=\&quot;$(TargetFileName)\&quot;" PreprocessorDefinitions="BINARY_NAME=\&quot;$(TargetFileName)\&quot;"
AdditionalIncludeDirectories=""
/> />
<Tool <Tool
Name="VCPreLinkEventTool" Name="VCPreLinkEventTool"
@ -194,6 +195,10 @@
RelativePath="..\extension.cpp" RelativePath="..\extension.cpp"
> >
</File> </File>
<File
RelativePath="..\gameplayrules.cpp"
>
</File>
<File <File
RelativePath="..\holiday.cpp" RelativePath="..\holiday.cpp"
> >
@ -224,6 +229,10 @@
RelativePath="..\extension.h" RelativePath="..\extension.h"
> >
</File> </File>
<File
RelativePath="..\gameplayrules.h"
>
</File>
<File <File
RelativePath="..\holiday.h" RelativePath="..\holiday.h"
> >

View File

@ -280,6 +280,20 @@ forward Action:TF2_OnGetHoliday(&TFHoliday:holiday);
*/ */
native bool:TF2_IsPlayerInDuel(client); native bool:TF2_IsPlayerInDuel(client);
/**
* Called when the server enters the Waiting for Players round state
*
* @noreturn
*/
forward TF2_OnWaitingForPlayersStart();
/**
* Called when the server exits the Waiting for Players round state
*
* @noreturn
*/
forward TF2_OnWaitingForPlayersEnd();
/** /**
* Do not edit below this line! * Do not edit below this line!
*/ */