core/NextMap.cpp
author Matt Woodrow <pred@alliedmods.net>
Sun May 25 07:11:16 2008 +0000 (2008-05-25)
changeset 2077 3c6fe374e8b7
child 2203 159ab9bad58c
permissions -rw-r--r--
Fixed amb1454 - Nextmap broken on mods that use the scores usermsg differently to CS:S
pred@2077
     1
/**
pred@2077
     2
 * vim: set ts=4 :
pred@2077
     3
 * =============================================================================
pred@2077
     4
 * SourceMod
pred@2077
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
pred@2077
     6
 * =============================================================================
pred@2077
     7
 *
pred@2077
     8
 * This program is free software; you can redistribute it and/or modify it under
pred@2077
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
pred@2077
    10
 * Free Software Foundation.
pred@2077
    11
 * 
pred@2077
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
pred@2077
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@2077
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
pred@2077
    15
 * details.
pred@2077
    16
 *
pred@2077
    17
 * You should have received a copy of the GNU General Public License along with
pred@2077
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
pred@2077
    19
 *
pred@2077
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
pred@2077
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@2077
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@2077
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
pred@2077
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
pred@2077
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
pred@2077
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@2077
    27
 * or <http://www.sourcemod.net/license.php>.
pred@2077
    28
 *
pred@2077
    29
 * Version: $Id$
pred@2077
    30
 */
pred@2077
    31
pred@2077
    32
#include "NextMap.h"
pred@2077
    33
#include "Logger.h"
pred@2077
    34
#include "sourcemm_api.h"
pred@2077
    35
#include "sm_stringutil.h"
pred@2077
    36
pred@2077
    37
NextMapManager g_NextMap;
pred@2077
    38
pred@2077
    39
SH_DECL_HOOK2_void(IVEngineServer, ChangeLevel, SH_NOATTRIB, 0, const char *, const char *);
pred@2077
    40
pred@2077
    41
ConVar sm_nextmap("sm_nextmap", "", FCVAR_NOTIFY);
pred@2077
    42
pred@2077
    43
void NextMapManager::OnSourceModAllInitialized_Post()
pred@2077
    44
{
pred@2077
    45
#if defined ORANGEBOX_BUILD
pred@2077
    46
	SH_ADD_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
pred@2077
    47
#else
pred@2077
    48
	SH_ADD_HOOK_MEMFUNC(IVEngineServer, ChangeLevel, engine, this, &NextMapManager::HookChangeLevel, false);
pred@2077
    49
#endif
pred@2077
    50
}
pred@2077
    51
pred@2077
    52
void NextMapManager::OnSourceModShutdown()
pred@2077
    53
{
pred@2077
    54
#if defined ORANGEBOX_BUILD
pred@2077
    55
	SH_REMOVE_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false);
pred@2077
    56
#else
pred@2077
    57
	SH_REMOVE_HOOK_MEMFUNC(IVEngineServer, ChangeLevel, engine, this, &NextMapManager::HookChangeLevel, false);
pred@2077
    58
#endif
pred@2077
    59
}
pred@2077
    60
pred@2077
    61
const char *NextMapManager::GetNextMap()
pred@2077
    62
{
pred@2077
    63
	return sm_nextmap.GetString();
pred@2077
    64
}
pred@2077
    65
pred@2077
    66
bool NextMapManager::SetNextMap(const char *map)
pred@2077
    67
{
pred@2077
    68
	if (!engine->IsMapValid(map))
pred@2077
    69
	{
pred@2077
    70
		return false;
pred@2077
    71
	}
pred@2077
    72
pred@2077
    73
	sm_nextmap.SetValue(map);
pred@2077
    74
pred@2077
    75
	return true;
pred@2077
    76
}
pred@2077
    77
pred@2077
    78
void NextMapManager::HookChangeLevel(const char *map, const char *unknown)
pred@2077
    79
{
pred@2077
    80
	const char *newmap = sm_nextmap.GetString();
pred@2077
    81
pred@2077
    82
	if (newmap[0] == 0 || !engine->IsMapValid(newmap))
pred@2077
    83
	{
pred@2077
    84
		RETURN_META(MRES_IGNORED);
pred@2077
    85
	}
pred@2077
    86
pred@2077
    87
	g_Logger.LogMessage("[SM] Changed map to \"%s\"", newmap);
pred@2077
    88
pred@2077
    89
	RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown));
pred@2077
    90
}