extensions/tf2/holiday.cpp
author Nicholas Hastings <skamonkey@gmail.com>
Mon Jun 28 17:48:14 2010 -0400 (2010-06-28)
changeset 3056 4e1591dceb8d
child 3057 e57c4ad63df5
permissions -rw-r--r--
Added forward/detour for TF2's GetHoliday function (bug 4462, r=pred)
skamonkey@3056
     1
/**
skamonkey@3056
     2
 * vim: set ts=4 :
skamonkey@3056
     3
 * =============================================================================
skamonkey@3056
     4
 * SourceMod Team Fortress 2 Extension
skamonkey@3056
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
skamonkey@3056
     6
 * =============================================================================
skamonkey@3056
     7
 *
skamonkey@3056
     8
 * This program is free software; you can redistribute it and/or modify it under
skamonkey@3056
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
skamonkey@3056
    10
 * Free Software Foundation.
skamonkey@3056
    11
 * 
skamonkey@3056
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
skamonkey@3056
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
skamonkey@3056
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
skamonkey@3056
    15
 * details.
skamonkey@3056
    16
 *
skamonkey@3056
    17
 * You should have received a copy of the GNU General Public License along with
skamonkey@3056
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
skamonkey@3056
    19
 *
skamonkey@3056
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
skamonkey@3056
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
skamonkey@3056
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
skamonkey@3056
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
skamonkey@3056
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
skamonkey@3056
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
skamonkey@3056
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
skamonkey@3056
    27
 * or <http://www.sourcemod.net/license.php>.
skamonkey@3056
    28
 *
skamonkey@3056
    29
 * Version: $Id$
skamonkey@3056
    30
 */
skamonkey@3056
    31
skamonkey@3056
    32
#include "holiday.h"
skamonkey@3056
    33
skamonkey@3056
    34
CDetour *getHolidayDetour = NULL;
skamonkey@3056
    35
skamonkey@3056
    36
IForward *g_getHolidayForward = NULL;
skamonkey@3056
    37
skamonkey@3056
    38
DETOUR_DECL_MEMBER0(GetHoliday, int)
skamonkey@3056
    39
{
skamonkey@3056
    40
	int actualres = DETOUR_MEMBER_CALL(GetHoliday)();
skamonkey@3056
    41
	if (!g_getHolidayForward)
skamonkey@3056
    42
	{
skamonkey@3056
    43
		g_pSM->LogMessage(myself, "Invalid Forward");
skamonkey@3056
    44
		return actualres;
skamonkey@3056
    45
	}
skamonkey@3056
    46
skamonkey@3056
    47
	cell_t result = 0;
skamonkey@3056
    48
	int newres = actualres;
skamonkey@3056
    49
skamonkey@3056
    50
	g_getHolidayForward->PushCellByRef(&newres);
skamonkey@3056
    51
	g_getHolidayForward->Execute(&result);
skamonkey@3056
    52
	
skamonkey@3056
    53
	if (result == Pl_Changed)
skamonkey@3056
    54
	{
skamonkey@3056
    55
		return newres;
skamonkey@3056
    56
	}
skamonkey@3056
    57
skamonkey@3056
    58
	return actualres;
skamonkey@3056
    59
}
skamonkey@3056
    60
skamonkey@3056
    61
void InitialiseGetHolidayDetour()
skamonkey@3056
    62
{
skamonkey@3056
    63
	getHolidayDetour = DETOUR_CREATE_MEMBER(GetHoliday, "GetHoliday");
skamonkey@3056
    64
skamonkey@3056
    65
	if (!getHolidayDetour)
skamonkey@3056
    66
	{
skamonkey@3056
    67
		g_pSM->LogError(myself, "GetHoliday detour failed");
skamonkey@3056
    68
		return;
skamonkey@3056
    69
	}
skamonkey@3056
    70
skamonkey@3056
    71
	getHolidayDetour->EnableDetour();
skamonkey@3056
    72
}
skamonkey@3056
    73
skamonkey@3056
    74
void RemoveGetHolidayDetour()
skamonkey@3056
    75
{
skamonkey@3056
    76
	getHolidayDetour->Destroy();
skamonkey@3056
    77
}