TF2 ext fixes for TF2 holiday system changes (bug 5150, r=asherkin).

This commit is contained in:
Nicholas Hastings 2011-10-28 19:07:40 -04:00
parent e7f5f4a6af
commit ee42f09b8d
6 changed files with 49 additions and 39 deletions

View File

@ -112,7 +112,7 @@ bool TF2Tools::SDK_OnLoad(char *error, size_t maxlength, bool late)
playerhelpers->AddClientListener(this); playerhelpers->AddClientListener(this);
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_isHolidayForward = forwards->CreateForward("TF2_OnIsHolidayActive", ET_Event, 2, NULL, Param_Cell, Param_CellByRef);
g_addCondForward = forwards->CreateForward("TF2_OnConditionAdded", ET_Ignore, 2, NULL, Param_Cell, Param_Cell); g_addCondForward = forwards->CreateForward("TF2_OnConditionAdded", ET_Ignore, 2, NULL, Param_Cell, Param_Cell);
g_removeCondForward = forwards->CreateForward("TF2_OnConditionRemoved", ET_Ignore, 2, NULL, Param_Cell, Param_Cell); 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_waitingPlayersStartForward = forwards->CreateForward("TF2_OnWaitingForPlayersStart", ET_Ignore, 0, NULL);
@ -121,7 +121,7 @@ bool TF2Tools::SDK_OnLoad(char *error, size_t maxlength, bool late)
g_pCVar = icvar; g_pCVar = icvar;
m_CritDetoursEnabled = false; m_CritDetoursEnabled = false;
m_GetHolidayDetourEnabled = false; m_IsHolidayDetourEnabled = false;
m_CondChecksEnabled = false; m_CondChecksEnabled = false;
m_RulesDetoursEnabled = false; m_RulesDetoursEnabled = false;
@ -168,7 +168,7 @@ void TF2Tools::SDK_OnUnload()
plsys->RemovePluginsListener(this); plsys->RemovePluginsListener(this);
forwards->ReleaseForward(g_critForward); forwards->ReleaseForward(g_critForward);
forwards->ReleaseForward(g_getHolidayForward); forwards->ReleaseForward(g_isHolidayForward);
forwards->ReleaseForward(g_addCondForward); forwards->ReleaseForward(g_addCondForward);
forwards->ReleaseForward(g_removeCondForward); forwards->ReleaseForward(g_removeCondForward);
forwards->ReleaseForward(g_waitingPlayersStartForward); forwards->ReleaseForward(g_waitingPlayersStartForward);
@ -320,9 +320,9 @@ void TF2Tools::OnPluginLoaded(IPlugin *plugin)
m_CritDetoursEnabled = InitialiseCritDetours(); m_CritDetoursEnabled = InitialiseCritDetours();
} }
if (!m_GetHolidayDetourEnabled && g_getHolidayForward->GetFunctionCount()) if (!m_IsHolidayDetourEnabled && g_isHolidayForward->GetFunctionCount())
{ {
m_GetHolidayDetourEnabled = InitialiseGetHolidayDetour(); m_IsHolidayDetourEnabled = InitialiseIsHolidayDetour();
} }
if (!m_CondChecksEnabled if (!m_CondChecksEnabled
@ -347,10 +347,10 @@ void TF2Tools::OnPluginUnloaded(IPlugin *plugin)
RemoveCritDetours(); RemoveCritDetours();
m_CritDetoursEnabled = false; m_CritDetoursEnabled = false;
} }
if (m_GetHolidayDetourEnabled && !g_getHolidayForward->GetFunctionCount()) if (m_IsHolidayDetourEnabled && !g_isHolidayForward->GetFunctionCount())
{ {
RemoveGetHolidayDetour(); RemoveIsHolidayDetour();
m_GetHolidayDetourEnabled = false; m_IsHolidayDetourEnabled = false;
} }
if (m_CondChecksEnabled) if (m_CondChecksEnabled)
{ {

View File

@ -118,7 +118,7 @@ public:
#endif #endif
private: private:
bool m_CritDetoursEnabled; bool m_CritDetoursEnabled;
bool m_GetHolidayDetourEnabled; bool m_IsHolidayDetourEnabled;
bool m_CondChecksEnabled; bool m_CondChecksEnabled;
bool m_RulesDetoursEnabled; bool m_RulesDetoursEnabled;
}; };

View File

@ -31,48 +31,49 @@
#include "holiday.h" #include "holiday.h"
CDetour *getHolidayDetour = NULL; CDetour *isHolidayDetour = NULL;
IForward *g_getHolidayForward = NULL; IForward *g_isHolidayForward = NULL;
DETOUR_DECL_STATIC0(GetHoliday, int) DETOUR_DECL_STATIC1(IsHolidayActive, bool, int, holiday)
{ {
int actualres = DETOUR_STATIC_CALL(GetHoliday)(); bool actualres = DETOUR_STATIC_CALL(IsHolidayActive)(holiday);
if (!g_getHolidayForward) if (!g_isHolidayForward)
{ {
g_pSM->LogMessage(myself, "Invalid Forward"); g_pSM->LogMessage(myself, "Invalid Forward");
return actualres; return actualres;
} }
cell_t result = 0; cell_t result = 0;
int newres = actualres; cell_t newres = actualres ? 1 : 0;
g_getHolidayForward->PushCellByRef(&newres); g_isHolidayForward->PushCell(holiday);
g_getHolidayForward->Execute(&result); g_isHolidayForward->PushCellByRef(&newres);
g_isHolidayForward->Execute(&result);
if (result == Pl_Changed) if (result == Pl_Changed)
{ {
return newres; return (newres == 0) ? false : true;
} }
return actualres; return actualres;
} }
bool InitialiseGetHolidayDetour() bool InitialiseIsHolidayDetour()
{ {
getHolidayDetour = DETOUR_CREATE_STATIC(GetHoliday, "GetHoliday"); isHolidayDetour = DETOUR_CREATE_STATIC(IsHolidayActive, "IsHolidayActive");
if (getHolidayDetour != NULL) if (isHolidayDetour != NULL)
{ {
getHolidayDetour->EnableDetour(); isHolidayDetour->EnableDetour();
return true; return true;
} }
g_pSM->LogError(myself, "GetHoliday detour failed"); g_pSM->LogError(myself, "IsHolidayActive detour failed");
return false; return false;
} }
void RemoveGetHolidayDetour() void RemoveIsHolidayDetour()
{ {
getHolidayDetour->Destroy(); isHolidayDetour->Destroy();
} }

View File

@ -37,9 +37,9 @@
#include <jit/x86/x86_macros.h> #include <jit/x86/x86_macros.h>
#include "CDetour/detours.h" #include "CDetour/detours.h"
bool InitialiseGetHolidayDetour(); bool InitialiseIsHolidayDetour();
void RemoveGetHolidayDetour(); void RemoveIsHolidayDetour();
extern IForward *g_getHolidayForward; extern IForward *g_isHolidayForward;
#endif //_INCLUDE_SOURCEMOD_HOLIDAY_H_ #endif //_INCLUDE_SOURCEMOD_HOLIDAY_H_

View File

@ -99,12 +99,12 @@
"linux" "@_ZN15CTFPlayerShared10StunPlayerEffiP9CTFPlayer" "linux" "@_ZN15CTFPlayerShared10StunPlayerEffiP9CTFPlayer"
"mac" "@_ZN15CTFPlayerShared10StunPlayerEffiP9CTFPlayer" "mac" "@_ZN15CTFPlayerShared10StunPlayerEffiP9CTFPlayer"
} }
"GetHoliday" "IsHolidayActive"
{ {
"library" "server" "library" "server"
"windows" "\x81\xEC\x2A\x2A\x2A\x2A\x53\x55\x56\x57\x6A\x00\xE8\x2A\x2A\x2A\x2A\x89" "windows" "\x80\x2A\x2A\x2A\x2A\x2A\x00\x75\x2A\xE8\x2A\x2A\x2A\x2A\x8B\x54\x2A\x2A\x8B"
"linux" "@_Z15UTIL_GetHolidayv" "linux" "@_Z20UTIL_IsHolidayActivei"
"mac" "@_Z15UTIL_GetHolidayv" "mac" "@_Z20UTIL_IsHolidayActivei"
} }
"MakeBleed" "MakeBleed"
{ {

View File

@ -121,8 +121,10 @@ enum TFCond
enum TFHoliday enum TFHoliday
{ {
TFHoliday_None = 1, TFHoliday_None = 1,
TFHoliday_Birthday,
TFHoliday_Halloween, TFHoliday_Halloween,
TFHoliday_Birthday TFHoliday_FullMoon,
TFHoliday_HalloweenOrFullMoon,
}; };
enum TFObjectType enum TFObjectType
@ -278,15 +280,22 @@ native TFClassType:TF2_GetClass(const String:classname[]);
forward Action:TF2_CalcIsAttackCritical(client, weapon, String:weaponname[], &bool:result); forward Action:TF2_CalcIsAttackCritical(client, weapon, String:weaponname[], &bool:result);
/** /**
* Called when the game checks to see if the current day is one of its tracked holidays * @deprecated No longer called. Use TF2_OnIsHolidayActive.
*
* @note Change the value of holiday and return Plugin_Changed to override.
* Return Plugin_Continue for no change.
*
* @param holiday Current Holiday
*/ */
#pragma deprecated No longer called. Use TF2_OnIsHolidayActive.
forward Action:TF2_OnGetHoliday(&TFHoliday:holiday); forward Action:TF2_OnGetHoliday(&TFHoliday:holiday);
/**
* Called at various times when the game checks to see if the given holiday is active.
* Return Plugin_Continue to let the original calculation or return a higher
* action to override the decision with the value of 'result'
*
* @param holiday Holiday being checked.
* @param result Buffer param for the result of the decision.
* @return Plugin_Continue for original calculation, higher value to use 'result'.
*/
forward Action:TF2_OnIsHolidayActive(TFHoliday:holiday, &bool:result);
/** /**
* Returns whether or not a client (Player) is in a duel. * Returns whether or not a client (Player) is in a duel.
* *