IMPORT
authorMatt Woodrow <pred@alliedmods.net>
Fri Feb 20 15:24:04 2009 +1300 (2009-02-20)
changeset 04c53fd0b014e
child 1 abd35d097176
IMPORT
CDetour/detourhelpers.h
CDetour/detours.cpp
CDetour/detours.h
Makefile
asm/asm.c
asm/asm.h
extension.cpp
extension.h
msvc9/sdk.sln
msvc9/sdk.vcproj
runteamlogic.txt
sdk/smsdk_config.h
sdk/smsdk_ext.cpp
sdk/smsdk_ext.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/CDetour/detourhelpers.h	Fri Feb 20 15:24:04 2009 +1300
     1.3 @@ -0,0 +1,98 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod
     1.8 + * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     1.9 + * =============================================================================
    1.10 + *
    1.11 + * This program is free software; you can redistribute it and/or modify it under
    1.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 + * Free Software Foundation.
    1.14 + * 
    1.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 + * details.
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License along with
    1.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 + *
    1.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 + * or <http://www.sourcemod.net/license.php>.
    1.31 + *
    1.32 + * Version: $Id: detourhelpers.h 248 2008-08-27 00:56:22Z pred $
    1.33 + */
    1.34 +
    1.35 +#ifndef _INCLUDE_SOURCEMOD_DETOURHELPERS_H_
    1.36 +#define _INCLUDE_SOURCEMOD_DETOURHELPERS_H_
    1.37 +
    1.38 +#if defined PLATFORM_LINUX
    1.39 +#include <sys/mman.h>
    1.40 +#define	PAGE_SIZE	4096
    1.41 +#define ALIGN(ar) ((long)ar & ~(PAGE_SIZE-1))
    1.42 +#define	PAGE_EXECUTE_READWRITE	PROT_READ|PROT_WRITE|PROT_EXEC
    1.43 +#endif
    1.44 +
    1.45 +struct patch_t
    1.46 +{
    1.47 +	patch_t()
    1.48 +	{
    1.49 +		patch[0] = 0;
    1.50 +		bytes = 0;
    1.51 +	}
    1.52 +	unsigned char patch[20];
    1.53 +	size_t bytes;
    1.54 +};
    1.55 +
    1.56 +inline void ProtectMemory(void *addr, int length, int prot)
    1.57 +{
    1.58 +#if defined PLATFORM_LINUX
    1.59 +	void *addr2 = (void *)ALIGN(addr);
    1.60 +	mprotect(addr2, sysconf(_SC_PAGESIZE), prot);
    1.61 +#elif defined PLATFORM_WINDOWS
    1.62 +	DWORD old_prot;
    1.63 +	VirtualProtect(addr, length, prot, &old_prot);
    1.64 +#endif
    1.65 +}
    1.66 +
    1.67 +inline void SetMemPatchable(void *address, size_t size)
    1.68 +{
    1.69 +	ProtectMemory(address, (int)size, PAGE_EXECUTE_READWRITE);
    1.70 +}
    1.71 +
    1.72 +inline void DoGatePatch(unsigned char *target, void *callback)
    1.73 +{
    1.74 +	SetMemPatchable(target, 20);
    1.75 +
    1.76 +	target[0] = 0xFF;	/* JMP */
    1.77 +	target[1] = 0x25;	/* MEM32 */
    1.78 +	*(void **)(&target[2]) = callback;
    1.79 +}
    1.80 +
    1.81 +inline void ApplyPatch(void *address, int offset, const patch_t *patch, patch_t *restore)
    1.82 +{
    1.83 +	ProtectMemory(address, 20, PAGE_EXECUTE_READWRITE);
    1.84 +
    1.85 +	unsigned char *addr = (unsigned char *)address + offset;
    1.86 +	if (restore)
    1.87 +	{
    1.88 +		for (size_t i=0; i<patch->bytes; i++)
    1.89 +		{
    1.90 +			restore->patch[i] = addr[i];
    1.91 +		}
    1.92 +		restore->bytes = patch->bytes;
    1.93 +	}
    1.94 +
    1.95 +	for (size_t i=0; i<patch->bytes; i++)
    1.96 +	{
    1.97 +		addr[i] = patch->patch[i];
    1.98 +	}
    1.99 +}
   1.100 +
   1.101 +#endif //_INCLUDE_SOURCEMOD_DETOURHELPERS_H_
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/CDetour/detours.cpp	Fri Feb 20 15:24:04 2009 +1300
     2.3 @@ -0,0 +1,192 @@
     2.4 +/**
     2.5 +* vim: set ts=4 :
     2.6 +* =============================================================================
     2.7 +* SourceMod
     2.8 +* Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     2.9 +* =============================================================================
    2.10 +*
    2.11 +* This program is free software; you can redistribute it and/or modify it under
    2.12 +* the terms of the GNU General Public License, version 3.0, as published by the
    2.13 +* Free Software Foundation.
    2.14 +* 
    2.15 +* This program is distributed in the hope that it will be useful, but WITHOUT
    2.16 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    2.17 +* FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    2.18 +* details.
    2.19 +*
    2.20 +* You should have received a copy of the GNU General Public License along with
    2.21 +* this program.  If not, see <http://www.gnu.org/licenses/>.
    2.22 +*
    2.23 +* As a special exception, AlliedModders LLC gives you permission to link the
    2.24 +* code of this program (as well as its derivative works) to "Half-Life 2," the
    2.25 +* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    2.26 +* by the Valve Corporation.  You must obey the GNU General Public License in
    2.27 +* all respects for all other code used.  Additionally, AlliedModders LLC grants
    2.28 +* this exception to all derivative works.  AlliedModders LLC defines further
    2.29 +* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    2.30 +* or <http://www.sourcemod.net/license.php>.
    2.31 +*
    2.32 +* Version: $Id: detours.cpp 248 2008-08-27 00:56:22Z pred $
    2.33 +*/
    2.34 +
    2.35 +#include "detours.h"
    2.36 +#include <asm/asm.h>
    2.37 +
    2.38 +ISourcePawnEngine *CDetourManager::spengine = NULL;
    2.39 +IGameConfig *CDetourManager::gameconf = NULL;
    2.40 +
    2.41 +void CDetourManager::Init(ISourcePawnEngine *spengine, IGameConfig *gameconf)
    2.42 +{
    2.43 +	CDetourManager::spengine = spengine;
    2.44 +	CDetourManager::gameconf = gameconf;
    2.45 +}
    2.46 +
    2.47 +CDetour *CDetourManager::CreateDetour(void *callbackfunction, void **trampoline, const char *signame)
    2.48 +{
    2.49 +	CDetour *detour = new CDetour(callbackfunction, trampoline, signame);
    2.50 +	if (detour)
    2.51 +	{
    2.52 +		if (!detour->Init(spengine, gameconf))
    2.53 +		{
    2.54 +			delete detour;
    2.55 +			return NULL;
    2.56 +		}
    2.57 +
    2.58 +		return detour;
    2.59 +	}
    2.60 +
    2.61 +	return NULL;
    2.62 +}
    2.63 +
    2.64 +CDetour::CDetour(void *callbackfunction, void **trampoline, const char *signame)
    2.65 +{
    2.66 +	enabled = false;
    2.67 +	detoured = false;
    2.68 +	detour_address = NULL;
    2.69 +	detour_trampoline = NULL;
    2.70 +	this->signame = signame;
    2.71 +	this->detour_callback = callbackfunction;
    2.72 +	spengine = NULL;
    2.73 +	gameconf = NULL;
    2.74 +	this->trampoline = trampoline;
    2.75 +}
    2.76 +
    2.77 +bool CDetour::Init(ISourcePawnEngine *spengine, IGameConfig *gameconf)
    2.78 +{
    2.79 +	this->spengine = spengine;
    2.80 +	this->gameconf = gameconf;
    2.81 +
    2.82 +	if (!CreateDetour())
    2.83 +	{
    2.84 +		enabled = false;
    2.85 +		return enabled;
    2.86 +	}
    2.87 +
    2.88 +	enabled = true;
    2.89 +
    2.90 +	return enabled;
    2.91 +}
    2.92 +
    2.93 +void CDetour::Destroy()
    2.94 +{
    2.95 +	DeleteDetour();
    2.96 +	delete this;
    2.97 +}
    2.98 +
    2.99 +bool CDetour::IsEnabled()
   2.100 +{
   2.101 +	return enabled;
   2.102 +}
   2.103 +
   2.104 +bool CDetour::CreateDetour()
   2.105 +{
   2.106 +	if (!gameconf->GetMemSig(signame, &detour_address))
   2.107 +	{
   2.108 +		g_pSM->LogError(myself, "Could not locate %s - Disabling detour", signame);
   2.109 +		return false;
   2.110 +	}
   2.111 +
   2.112 +	if (!detour_address)
   2.113 +	{
   2.114 +		g_pSM->LogError(myself, "Sigscan for %s failed - Disabling detour to prevent crashes", signame);
   2.115 +		return false;
   2.116 +	}
   2.117 +
   2.118 +	detour_restore.bytes = copy_bytes((unsigned char *)detour_address, NULL, OP_JMP_SIZE+1);
   2.119 +
   2.120 +	/* First, save restore bits */
   2.121 +	for (size_t i=0; i<detour_restore.bytes; i++)
   2.122 +	{
   2.123 +		detour_restore.patch[i] = ((unsigned char *)detour_address)[i];
   2.124 +	}
   2.125 +
   2.126 +	JitWriter wr;
   2.127 +	JitWriter *jit = &wr;
   2.128 +	jit_uint32_t CodeSize = 0;
   2.129 +	
   2.130 +	wr.outbase = NULL;
   2.131 +	wr.outptr = NULL;
   2.132 +
   2.133 +jit_rewind:
   2.134 +
   2.135 +	/* Patch old bytes in */
   2.136 +	if (wr.outbase != NULL)
   2.137 +	{
   2.138 +		copy_bytes((unsigned char *)detour_address, (unsigned char*)wr.outptr, detour_restore.bytes);
   2.139 +	}
   2.140 +	wr.outptr += detour_restore.bytes;
   2.141 +
   2.142 +	/* Return to the original function */
   2.143 +	jitoffs_t call = IA32_Jump_Imm32(jit, 0);
   2.144 +	IA32_Write_Jump32_Abs(jit, call, (unsigned char *)detour_address + detour_restore.bytes);
   2.145 +
   2.146 +	if (wr.outbase == NULL)
   2.147 +	{
   2.148 +		CodeSize = wr.get_outputpos();
   2.149 +		wr.outbase = (jitcode_t)spengine->AllocatePageMemory(CodeSize);
   2.150 +		spengine->SetReadWrite(wr.outbase);
   2.151 +		wr.outptr = wr.outbase;
   2.152 +		detour_trampoline = wr.outbase;
   2.153 +		goto jit_rewind;
   2.154 +	}
   2.155 +
   2.156 +	spengine->SetReadExecute(wr.outbase);
   2.157 +
   2.158 +	*trampoline = detour_trampoline;
   2.159 +
   2.160 +	return true;
   2.161 +}
   2.162 +
   2.163 +void CDetour::DeleteDetour()
   2.164 +{
   2.165 +	if (detoured)
   2.166 +	{
   2.167 +		DisableDetour();
   2.168 +	}
   2.169 +
   2.170 +	if (detour_trampoline)
   2.171 +	{
   2.172 +		/* Free the allocated trampoline memory */
   2.173 +		spengine->FreePageMemory(detour_trampoline);
   2.174 +		detour_trampoline = NULL;
   2.175 +	}
   2.176 +}
   2.177 +
   2.178 +void CDetour::EnableDetour()
   2.179 +{
   2.180 +	if (!detoured)
   2.181 +	{
   2.182 +		DoGatePatch((unsigned char *)detour_address, &detour_callback);
   2.183 +		detoured = true;
   2.184 +	}
   2.185 +}
   2.186 +
   2.187 +void CDetour::DisableDetour()
   2.188 +{
   2.189 +	if (detoured)
   2.190 +	{
   2.191 +		/* Remove the patch */
   2.192 +		ApplyPatch(detour_address, 0, &detour_restore, NULL);
   2.193 +		detoured = false;
   2.194 +	}
   2.195 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/CDetour/detours.h	Fri Feb 20 15:24:04 2009 +1300
     3.3 @@ -0,0 +1,226 @@
     3.4 +/**
     3.5 +* vim: set ts=4 :
     3.6 +* =============================================================================
     3.7 +* SourceMod
     3.8 +* Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     3.9 +* =============================================================================
    3.10 +*
    3.11 +* This program is free software; you can redistribute it and/or modify it under
    3.12 +* the terms of the GNU General Public License, version 3.0, as published by the
    3.13 +* Free Software Foundation.
    3.14 +* 
    3.15 +* This program is distributed in the hope that it will be useful, but WITHOUT
    3.16 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    3.17 +* FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    3.18 +* details.
    3.19 +*
    3.20 +* You should have received a copy of the GNU General Public License along with
    3.21 +* this program.  If not, see <http://www.gnu.org/licenses/>.
    3.22 +*
    3.23 +* As a special exception, AlliedModders LLC gives you permission to link the
    3.24 +* code of this program (as well as its derivative works) to "Half-Life 2," the
    3.25 +* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    3.26 +* by the Valve Corporation.  You must obey the GNU General Public License in
    3.27 +* all respects for all other code used.  Additionally, AlliedModders LLC grants
    3.28 +* this exception to all derivative works.  AlliedModders LLC defines further
    3.29 +* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    3.30 +* or <http://www.sourcemod.net/license.php>.
    3.31 +*
    3.32 +* Version: $Id: detours.h 257 2008-09-23 03:12:13Z pred $
    3.33 +*/
    3.34 +
    3.35 +#ifndef _INCLUDE_SOURCEMOD_DETOURS_H_
    3.36 +#define _INCLUDE_SOURCEMOD_DETOURS_H_
    3.37 +
    3.38 +#include "extension.h"
    3.39 +#include <jit/jit_helpers.h>
    3.40 +#include <jit/x86/x86_macros.h>
    3.41 +#include "detourhelpers.h"
    3.42 +
    3.43 +/**
    3.44 + * CDetours class for SourceMod Extensions by pRED*
    3.45 + * detourhelpers.h entirely stolen from CSS:DM and were written by BAILOPAN (I assume).
    3.46 + * asm.h/c from devmaster.net (thanks cybermind) edited by pRED* to handle gcc -fPIC thunks correctly
    3.47 + * Concept by Nephyrin Zey (http://www.doublezen.net/) and Windows Detour Library (http://research.microsoft.com/sn/detours/)
    3.48 + * Member function pointer ideas by Don Clugston (http://www.codeproject.com/cpp/FastDelegate.asp)
    3.49 + */
    3.50 +
    3.51 +#define DETOUR_MEMBER_CALL(name) (this->*name##_Actual)
    3.52 +#define DETOUR_STATIC_CALL(name) (name##_Actual)
    3.53 +
    3.54 +#define DETOUR_DECL_STATIC0(name, ret) \
    3.55 +ret (*name##_Actual)(void) = NULL; \
    3.56 +ret name(void)
    3.57 +
    3.58 +#define DETOUR_DECL_STATIC1(name, ret, p1type, p1name) \
    3.59 +ret (*name##_Actual)(p1type) = NULL; \
    3.60 +ret name(p1type p1name)
    3.61 +
    3.62 +#define DETOUR_DECL_MEMBER0(name, ret) \
    3.63 +class name##Class \
    3.64 +{ \
    3.65 +public: \
    3.66 +	ret name(); \
    3.67 +	static ret (name##Class::* name##_Actual)(void); \
    3.68 +}; \
    3.69 +ret (name##Class::* name##Class::name##_Actual)(void) = NULL; \
    3.70 +ret name##Class::name()
    3.71 +
    3.72 +#define DETOUR_DECL_MEMBER1(name, ret, p1type, p1name) \
    3.73 +class name##Class \
    3.74 +{ \
    3.75 +public: \
    3.76 +	ret name(p1type p1name); \
    3.77 +	static ret (name##Class::* name##_Actual)(p1type); \
    3.78 +}; \
    3.79 +ret (name##Class::* name##Class::name##_Actual)(p1type) = NULL; \
    3.80 +ret name##Class::name(p1type p1name)
    3.81 +
    3.82 +#define DETOUR_DECL_MEMBER2(name, ret, p1type, p1name, p2type, p2name) \
    3.83 +class name##Class \
    3.84 +{ \
    3.85 +public: \
    3.86 +	ret name(p1type p1name, p2type p2name); \
    3.87 +	static ret (name##Class::* name##_Actual)(p1type, p2type); \
    3.88 +}; \
    3.89 +ret (name##Class::* name##Class::name##_Actual)(p1type, p2type) = NULL; \
    3.90 +ret name##Class::name(p1type p1name, p2type p2name)
    3.91 +
    3.92 +#define DETOUR_DECL_MEMBER3(name, ret, p1type, p1name, p2type, p2name, p3type, p3name) \
    3.93 +class name##Class \
    3.94 +{ \
    3.95 +public: \
    3.96 +	ret name(p1type p1name, p2type p2name, p3type p3name); \
    3.97 +	static ret (name##Class::* name##_Actual)(p1type, p2type, p3type); \
    3.98 +}; \
    3.99 +ret (name##Class::* name##Class::name##_Actual)(p1type, p2type, p3type) = NULL; \
   3.100 +ret name##Class::name(p1type p1name, p2type p2name, p3type p3name)
   3.101 +
   3.102 +#define GET_MEMBER_CALLBACK(name) (void *)GetCodeAddress(&name##Class::name)
   3.103 +#define GET_MEMBER_TRAMPOLINE(name) (void **)(&name##Class::name##_Actual)
   3.104 +
   3.105 +#define GET_STATIC_CALLBACK(name) (void *)&name
   3.106 +#define GET_STATIC_TRAMPOLINE(name) (void **)&name##_Actual
   3.107 +
   3.108 +#define DETOUR_CREATE_MEMBER(name, gamedata) CDetourManager::CreateDetour(GET_MEMBER_CALLBACK(name), GET_MEMBER_TRAMPOLINE(name), gamedata);
   3.109 +#define DETOUR_CREATE_STATIC(name, gamedata) CDetourManager::CreateDetour(GET_STATIC_CALLBACK(name), GET_STATIC_TRAMPOLINE(name), gamedata);
   3.110 +
   3.111 +
   3.112 +class GenericClass {};
   3.113 +typedef void (GenericClass::*VoidFunc)();
   3.114 +
   3.115 +inline void *GetCodeAddr(VoidFunc mfp)
   3.116 +{
   3.117 +	return *(void **)&mfp;
   3.118 +}
   3.119 +
   3.120 +/**
   3.121 + * Converts a member function pointer to a void pointer.
   3.122 + * This relies on the assumption that the code address lies at mfp+0
   3.123 + * This is the case for both g++ and later MSVC versions on non virtual functions but may be different for other compilers
   3.124 + * Based on research by Don Clugston : http://www.codeproject.com/cpp/FastDelegate.asp
   3.125 + */
   3.126 +#define GetCodeAddress(mfp) GetCodeAddr(reinterpret_cast<VoidFunc>(mfp))
   3.127 +
   3.128 +class CDetourManager;
   3.129 +
   3.130 +class CDetour
   3.131 +{
   3.132 +public:
   3.133 +
   3.134 +	bool IsEnabled();
   3.135 +
   3.136 +	/**
   3.137 +	 * These would be somewhat self-explanatory I hope
   3.138 +	 */
   3.139 +	void EnableDetour();
   3.140 +	void DisableDetour();
   3.141 +
   3.142 +	void Destroy();
   3.143 +
   3.144 +	friend class CDetourManager;
   3.145 +
   3.146 +protected:
   3.147 +	CDetour(void *callbackfunction, void **trampoline, const char *signame);
   3.148 +
   3.149 +	bool Init(ISourcePawnEngine *spengine, IGameConfig *gameconf);
   3.150 +private:
   3.151 +
   3.152 +	/* These create/delete the allocated memory */
   3.153 +	bool CreateDetour();
   3.154 +	void DeleteDetour();
   3.155 +
   3.156 +	bool enabled;
   3.157 +	bool detoured;
   3.158 +
   3.159 +	patch_t detour_restore;
   3.160 +	/* Address of the detoured function */
   3.161 +	void *detour_address;
   3.162 +	/* Address of the allocated trampoline function */
   3.163 +	void *detour_trampoline;
   3.164 +	/* Address of the callback handler */
   3.165 +	void *detour_callback;
   3.166 +	/* The function pointer used to call our trampoline */
   3.167 +	void **trampoline;
   3.168 +	
   3.169 +	const char *signame;
   3.170 +	ISourcePawnEngine *spengine;
   3.171 +	IGameConfig *gameconf;
   3.172 +};
   3.173 +
   3.174 +class CDetourManager
   3.175 +{
   3.176 +public:
   3.177 +
   3.178 +	static void Init(ISourcePawnEngine *spengine, IGameConfig *gameconf);
   3.179 +
   3.180 +	/**
   3.181 +	 * Creates a new detour
   3.182 +	 *
   3.183 +	 * @param callbackfunction			Void pointer to your detour callback function.
   3.184 +	 * @param trampoline				Address of the trampoline pointer
   3.185 +	 * @param signame					Section name containing a signature to fetch from the gamedata file.
   3.186 +	 * @return							A new CDetour pointer to control your detour.
   3.187 +	 *
   3.188 +	 * Example:
   3.189 +	 *
   3.190 +	 * CBaseServer::ConnectClient(netadr_s &, int, int, int, char  const*, char  const*, char  const*, int)
   3.191 +	 *
   3.192 +	 * Define a new class with the required function and a member function pointer to the same type:
   3.193 +	 *
   3.194 +	 * class CBaseServerDetour
   3.195 +	 * {
   3.196 +	 * public:
   3.197 +	 *		 bool ConnectClient(void *netaddr_s, int, int, int, char  const*, char  const*, char  const*, int);
   3.198 +	 *		 static bool (CBaseServerDetour::* ConnectClient_Actual)(void *netaddr_s, int, int, int, char  const*, char  const*, char  const*, int);
   3.199 +	 * }
   3.200 +	 *
   3.201 +	 *	void *callbackfunc = GetCodeAddress(&CBaseServerDetour::ConnectClient);
   3.202 +	 *	void **trampoline = (void **)(&CBaseServerDetour::ConnectClient_Actual);
   3.203 +	 *
   3.204 +	 * Creation:
   3.205 +	 * CDetourManager::CreateDetour(callbackfunc,  trampoline, "ConnectClient");
   3.206 +	 *
   3.207 +	 * Usage:
   3.208 +	 *
   3.209 +	 * CBaseServerDetour::ConnectClient(void *netaddr_s, int, int, int, char  const*, char  const*, char  const*, int)
   3.210 +	 * {
   3.211 +	 *			//pre hook code
   3.212 +	 *			bool result = (this->*ConnectClient_Actual)(netaddr_s, rest of params);
   3.213 +	 *			//post hook code
   3.214 +	 *			return result;
   3.215 +	 * }
   3.216 +	 *
   3.217 +	 * Note we changed the netadr_s reference into a void* to avoid needing to define the type
   3.218 +	 */
   3.219 +	static CDetour *CreateDetour(void *callbackfunction, void **trampoline, const char *signame);
   3.220 +
   3.221 +	friend class CBlocker;
   3.222 +	friend class CDetour;
   3.223 +
   3.224 +private:
   3.225 +	static ISourcePawnEngine *spengine;
   3.226 +	static IGameConfig *gameconf;
   3.227 +};
   3.228 +
   3.229 +#endif // _INCLUDE_SOURCEMOD_DETOURS_H_
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/Makefile	Fri Feb 20 15:24:04 2009 +1300
     4.3 @@ -0,0 +1,130 @@
     4.4 +# (C)2004-2008 SourceMod Development Team
     4.5 +# Makefile written by David "BAILOPAN" Anderson
     4.6 +
     4.7 +SMSDK = ../..
     4.8 +SRCDS_BASE = ~/srcds
     4.9 +HL2SDK_ORIG = ../../../hl2sdk
    4.10 +HL2SDK_OB = ../../../hl2sdk-ob
    4.11 +SOURCEMM14 = ../../../sourcemm-1.4
    4.12 +SOURCEMM16 = ../../../sourcemm-1.6
    4.13 +
    4.14 +#####################################
    4.15 +### EDIT BELOW FOR OTHER PROJECTS ###
    4.16 +#####################################
    4.17 +
    4.18 +PROJECT = runteamlogic
    4.19 +
    4.20 +#Uncomment for Metamod: Source enabled extension
    4.21 +USEMETA = true
    4.22 +
    4.23 +OBJECTS = sdk/smsdk_ext.cpp extension.cpp CDetour/detours.cpp asm/asm.c
    4.24 +
    4.25 +##############################################
    4.26 +### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
    4.27 +##############################################
    4.28 +
    4.29 +C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -pipe -fno-strict-aliasing
    4.30 +C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3
    4.31 +C_GCC4_FLAGS = -fvisibility=hidden
    4.32 +CPP_GCC4_FLAGS = -fvisibility-inlines-hidden
    4.33 +CPP = gcc-4.1
    4.34 +
    4.35 +override ENGSET = false
    4.36 +ifeq "$(ENGINE)" "original"
    4.37 +	HL2SDK = $(HL2SDK_ORIG)
    4.38 +	HL2PUB = $(HL2SDK_ORIG)/public
    4.39 +	HL2LIB = $(HL2SDK_ORIG)/linux_sdk
    4.40 +	METAMOD = $(SOURCEMM14)
    4.41 +	INCLUDE += -I$(HL2SDK)/public/dlls
    4.42 +	SRCDS = $(SRCDS_BASE)
    4.43 +	override ENGSET = true
    4.44 +endif
    4.45 +ifeq "$(ENGINE)" "orangebox"
    4.46 +	HL2SDK = $(HL2SDK_OB)
    4.47 +	HL2PUB = $(HL2SDK_OB)/public
    4.48 +	HL2LIB = $(HL2SDK_OB)/lib/linux
    4.49 +	CFLAGS += -DORANGEBOX_BUILD
    4.50 +	METAMOD = $(SOURCEMM16)
    4.51 +	INCLUDE += -I$(HL2SDK)/public/game/server
    4.52 +	SRCDS = $(SRCDS_BASE)/orangebox
    4.53 +	override ENGSET = true
    4.54 +endif
    4.55 +
    4.56 +ifeq "$(USEMETA)" "true"
    4.57 +	LINK_HL2 = $(HL2LIB)/tier1_i486.a vstdlib_i486.so tier0_i486.so
    4.58 +
    4.59 +	LINK += $(LINK_HL2)
    4.60 +
    4.61 +	INCLUDE += -I. -I.. -Isdk -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 \
    4.62 +		-I$(METAMOD) -I$(METAMOD)/sourcehook -I$(METAMOD)/sourcemm -I$(SMSDK)/public \
    4.63 +		-I$(SMSDK)/public/sourcepawn 
    4.64 +else
    4.65 +	INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn
    4.66 +endif
    4.67 +
    4.68 +LINK += -static-libgcc
    4.69 +
    4.70 +CFLAGS += -D_LINUX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \
    4.71 +	-D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -Wno-switch \
    4.72 +	-Wno-unused -mfpmath=sse -msse -DSOURCEMOD_BUILD -DHAVE_STDINT_H -m32
    4.73 +CPPFLAGS += -Wno-non-virtual-dtor -fno-exceptions -fno-rtti
    4.74 +
    4.75 +################################################
    4.76 +### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
    4.77 +################################################
    4.78 +
    4.79 +ifeq "$(DEBUG)" "true"
    4.80 +	BIN_DIR = Debug
    4.81 +	CFLAGS += $(C_DEBUG_FLAGS)
    4.82 +else
    4.83 +	BIN_DIR = Release
    4.84 +	CFLAGS += $(C_OPT_FLAGS)
    4.85 +endif
    4.86 +
    4.87 +ifeq "$(USEMETA)" "true"
    4.88 +	BIN_DIR := $(BIN_DIR).$(ENGINE)
    4.89 +endif
    4.90 +
    4.91 +GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1)
    4.92 +ifeq "$(GCC_VERSION)" "4"
    4.93 +	CFLAGS += $(C_GCC4_FLAGS)
    4.94 +	CPPFLAGS += $(CPP_GCC4_FLAGS)
    4.95 +endif
    4.96 +
    4.97 +BINARY = $(PROJECT).ext.so
    4.98 +
    4.99 +OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
   4.100 +
   4.101 +$(BIN_DIR)/%.o: %.cpp
   4.102 +	$(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o [email protected] -c $<
   4.103 +
   4.104 +all: check
   4.105 +	mkdir -p $(BIN_DIR)/sdk
   4.106 +	mkdir -p $(BIN_DIR)/CDetour
   4.107 +	mkdir -p $(BIN_DIR)/asm
   4.108 +	if [ "$(USEMETA)" == "true" ]; then \
   4.109 +		ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so; \
   4.110 +		ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so; \
   4.111 +	fi
   4.112 +	$(MAKE) -f Makefile extension
   4.113 +
   4.114 +check:
   4.115 +	if [ "$(USEMETA)" == "true" ] && [ "$(ENGSET)" == "false" ]; then \
   4.116 +		echo "You must supply ENGINE=orangebox or ENGINE=original"; \
   4.117 +		exit 1; \
   4.118 +	fi
   4.119 +
   4.120 +extension: check $(OBJ_LINUX)
   4.121 +	$(CPP) $(INCLUDE) $(OBJ_LINUX) $(LINK) -m32 -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
   4.122 +
   4.123 +debug:
   4.124 +	$(MAKE) -f Makefile all DEBUG=true
   4.125 +
   4.126 +default: all
   4.127 +
   4.128 +clean: check
   4.129 +	rm -rf $(BIN_DIR)/*.o
   4.130 +	rm -rf $(BIN_DIR)/sdk/*.o
   4.131 +	rm -rf $(BIN_DIR)/CDetour/*.o
   4.132 +	rm -rf $(BIN_DIR)/asm/*.o
   4.133 +	rm -rf $(BIN_DIR)/$(BINARY)
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/asm/asm.c	Fri Feb 20 15:24:04 2009 +1300
     5.3 @@ -0,0 +1,421 @@
     5.4 +#include "asm.h"
     5.5 +
     5.6 +#ifndef WIN32
     5.7 +#define _GNU_SOURCE
     5.8 +#include <dlfcn.h>
     5.9 +#include <string.h>
    5.10 +
    5.11 +#define REG_EAX			0
    5.12 +#define REG_ECX			1
    5.13 +#define REG_EDX			2
    5.14 +#define REG_EBX			3
    5.15 +
    5.16 +#define IA32_MOV_REG_IMM		0xB8	// encoding is +r <imm32>
    5.17 +#endif
    5.18 +
    5.19 +extern void Msg( const char *, ... );
    5.20 +
    5.21 +/**
    5.22 +* Checks if a call to a fpic thunk has just been written into dest.
    5.23 +* If found replaces it with a direct mov that sets the required register to the value of pc.
    5.24 +*
    5.25 +* @param dest		Destination buffer where a call opcode + addr (5 bytes) has just been written.
    5.26 +* @param pc		The program counter value that needs to be set (usually the next address from the source).
    5.27 +* @noreturn
    5.28 +*/
    5.29 +void check_thunks(unsigned char *dest, unsigned char *pc)
    5.30 +{
    5.31 +#if defined WIN32
    5.32 +	return;
    5.33 +#else
    5.34 +	/* Step write address back 4 to the start of the function address */
    5.35 +	unsigned char *writeaddr = dest - 4;
    5.36 +	unsigned char *calloffset = *(unsigned char **)writeaddr;
    5.37 +	unsigned char *calladdr = (unsigned char *)(dest + (unsigned int)calloffset);
    5.38 +
    5.39 +	/* Lookup name of function being called */
    5.40 +	if ((*calladdr == 0x8B) && (*(calladdr+2) == 0x24) && (*(calladdr+3) == 0xC3))
    5.41 +	{
    5.42 +		//a thunk maybe?
    5.43 +		char movByte = IA32_MOV_REG_IMM;
    5.44 +
    5.45 +		/* Calculate the correct mov opcode */
    5.46 +		switch (*(calladdr+1))
    5.47 +		{
    5.48 +		case 0x04:
    5.49 +			{
    5.50 +				movByte += REG_EAX;
    5.51 +				break;
    5.52 +			}
    5.53 +		case 0x1C:
    5.54 +			{
    5.55 +				movByte += REG_EBX;
    5.56 +				break;
    5.57 +			}
    5.58 +		case 0x0C:
    5.59 +			{
    5.60 +				movByte += REG_ECX;
    5.61 +				break;
    5.62 +			}
    5.63 +		case 0x14:
    5.64 +			{
    5.65 +				movByte += REG_EDX;
    5.66 +				break;
    5.67 +			}
    5.68 +		default:
    5.69 +			{
    5.70 +				Msg("Unknown thunk: %c\n", *(calladdr+1));
    5.71 +				break;
    5.72 +			}
    5.73 +		}
    5.74 +
    5.75 +		/* Move our write address back one to where the call opcode was */
    5.76 +		writeaddr--;
    5.77 +
    5.78 +
    5.79 +		/* Write our mov */
    5.80 +		*writeaddr = movByte;
    5.81 +		writeaddr++;
    5.82 +
    5.83 +		/* Write the value - The provided program counter value */
    5.84 +		*(void **)writeaddr = (void *)pc;
    5.85 +		writeaddr += 4;
    5.86 +	}
    5.87 +
    5.88 +	return;
    5.89 +#endif
    5.90 +}
    5.91 +
    5.92 +//if dest is NULL, returns minimum number of bytes needed to be copied
    5.93 +//if dest is not NULL, it will copy the bytes to dest as well as fix CALLs and JMPs
    5.94 +//http://www.devmaster.net/forums/showthread.php?t=2311
    5.95 +int copy_bytes(unsigned char *func, unsigned char* dest, int required_len) {
    5.96 +	int bytecount = 0;
    5.97 +
    5.98 +	while(bytecount < required_len && *func != 0xCC)
    5.99 +	{
   5.100 +		// prefixes F0h, F2h, F3h, 66h, 67h, D8h-DFh, 2Eh, 36h, 3Eh, 26h, 64h and 65h
   5.101 +		int operandSize = 4;
   5.102 +		int FPU = 0;
   5.103 +		int twoByte = 0;
   5.104 +		unsigned char opcode = 0x90;
   5.105 +		unsigned char modRM = 0xFF;
   5.106 +		while(*func == 0xF0 ||
   5.107 +			  *func == 0xF2 ||
   5.108 +			  *func == 0xF3 ||
   5.109 +			 (*func & 0xFC) == 0x64 ||
   5.110 +			 (*func & 0xF8) == 0xD8 ||
   5.111 +			 (*func & 0x7E) == 0x62)
   5.112 +		{
   5.113 +			if(*func == 0x66)
   5.114 +			{
   5.115 +				operandSize = 2;
   5.116 +			}
   5.117 +			else if((*func & 0xF8) == 0xD8)
   5.118 +			{
   5.119 +				FPU = *func;
   5.120 +				if (dest)
   5.121 +						*dest++ = *func++;
   5.122 +				else
   5.123 +						func++;
   5.124 +				bytecount++;
   5.125 +				break;
   5.126 +			}
   5.127 +
   5.128 +			if (dest)
   5.129 +				*dest++ = *func++;
   5.130 +			else
   5.131 +				func++;
   5.132 +			bytecount++;
   5.133 +		}
   5.134 +
   5.135 +		// two-byte opcode byte
   5.136 +		if(*func == 0x0F)
   5.137 +		{
   5.138 +			twoByte = 1;
   5.139 +			if (dest)
   5.140 +				*dest++ = *func++;
   5.141 +			else
   5.142 +				func++;
   5.143 +			bytecount++;
   5.144 +		}
   5.145 +
   5.146 +		// opcode byte
   5.147 +		opcode = *func++;
   5.148 +		if (dest) *dest++ = opcode;
   5.149 +		bytecount++;
   5.150 +
   5.151 +		// mod R/M byte
   5.152 +		modRM = 0xFF;
   5.153 +		if(FPU)
   5.154 +		{
   5.155 +			if((opcode & 0xC0) != 0xC0)
   5.156 +			{
   5.157 +				modRM = opcode;
   5.158 +			}
   5.159 +		}
   5.160 +		else if(!twoByte)
   5.161 +		{
   5.162 +			if((opcode & 0xC4) == 0x00 ||
   5.163 +			   (opcode & 0xF4) == 0x60 && ((opcode & 0x0A) == 0x02 || (opcode & 0x09) == 0x09) ||
   5.164 +			   (opcode & 0xF0) == 0x80 ||
   5.165 +			   (opcode & 0xF8) == 0xC0 && (opcode & 0x0E) != 0x02 ||
   5.166 +			   (opcode & 0xFC) == 0xD0 ||
   5.167 +			   (opcode & 0xF6) == 0xF6)
   5.168 +			{
   5.169 +				modRM = *func++;
   5.170 +				if (dest) *dest++ = modRM;
   5.171 +				bytecount++;
   5.172 +			}
   5.173 +		}
   5.174 +		else
   5.175 +		{
   5.176 +			if((opcode & 0xF0) == 0x00 && (opcode & 0x0F) >= 0x04 && (opcode & 0x0D) != 0x0D ||
   5.177 +			   (opcode & 0xF0) == 0x30 ||
   5.178 +			   opcode == 0x77 ||
   5.179 +			   (opcode & 0xF0) == 0x80 ||
   5.180 +			   (opcode & 0xF0) == 0xA0 && (opcode & 0x07) <= 0x02 ||
   5.181 +			   (opcode & 0xF8) == 0xC8)
   5.182 +			{
   5.183 +				// No mod R/M byte
   5.184 +			}
   5.185 +			else
   5.186 +			{
   5.187 +				modRM = *func++;
   5.188 +				if (dest) *dest++ = modRM;
   5.189 +				bytecount++;
   5.190 +			}
   5.191 +		}
   5.192 +
   5.193 +		// SIB
   5.194 +		if((modRM & 0x07) == 0x04 &&
   5.195 +		   (modRM & 0xC0) != 0xC0)
   5.196 +		{
   5.197 +			if (dest)
   5.198 +				*dest++ = *func++;   //SIB
   5.199 +			else
   5.200 +				func++;
   5.201 +			bytecount++;
   5.202 +		}
   5.203 +
   5.204 +		// mod R/M displacement
   5.205 +
   5.206 +		// Dword displacement, no base
   5.207 +	if((modRM & 0xC5) == 0x05) {
   5.208 +		if (dest) {
   5.209 +			*(unsigned int*)dest = *(unsigned int*)func;
   5.210 +			dest += 4;
   5.211 +		}
   5.212 +		func += 4;
   5.213 +		bytecount += 4;
   5.214 +	}
   5.215 +
   5.216 +		// Byte displacement
   5.217 +	if((modRM & 0xC0) == 0x40) {
   5.218 +		if (dest)
   5.219 +			*dest++ = *func++;
   5.220 +		else
   5.221 +			func++;
   5.222 +		bytecount++;
   5.223 +	}
   5.224 +
   5.225 +		// Dword displacement
   5.226 +	if((modRM & 0xC0) == 0x80) {
   5.227 +		if (dest) {
   5.228 +			*(unsigned int*)dest = *(unsigned int*)func;
   5.229 +			dest += 4;
   5.230 +		}
   5.231 +		func += 4;
   5.232 +		bytecount += 4;
   5.233 +	}
   5.234 +
   5.235 +		// immediate
   5.236 +		if(FPU)
   5.237 +		{
   5.238 +			// Can't have immediate operand
   5.239 +		}
   5.240 +		else if(!twoByte)
   5.241 +		{
   5.242 +			if((opcode & 0xC7) == 0x04 ||
   5.243 +			   (opcode & 0xFE) == 0x6A ||   // PUSH/POP/IMUL
   5.244 +			   (opcode & 0xF0) == 0x70 ||   // Jcc
   5.245 +			   opcode == 0x80 ||
   5.246 +			   opcode == 0x83 ||
   5.247 +			   (opcode & 0xFD) == 0xA0 ||   // MOV
   5.248 +			   opcode == 0xA8 ||			// TEST
   5.249 +			   (opcode & 0xF8) == 0xB0 ||   // MOV
   5.250 +			   (opcode & 0xFE) == 0xC0 ||   // RCL
   5.251 +			   opcode == 0xC6 ||			// MOV
   5.252 +			   opcode == 0xCD ||			// INT
   5.253 +			   (opcode & 0xFE) == 0xD4 ||   // AAD/AAM
   5.254 +			   (opcode & 0xF8) == 0xE0 ||   // LOOP/JCXZ
   5.255 +			   opcode == 0xEB ||
   5.256 +			   opcode == 0xF6 && (modRM & 0x30) == 0x00)   // TEST
   5.257 +			{
   5.258 +				if (dest)
   5.259 +					*dest++ = *func++;
   5.260 +				else
   5.261 +					func++;
   5.262 +				bytecount++;
   5.263 +			}
   5.264 +		else if((opcode & 0xF7) == 0xC2) // RET
   5.265 +			{
   5.266 +				if (dest) {
   5.267 +					*(unsigned short*)dest = *(unsigned short*)func;
   5.268 +					dest += 2;
   5.269 +				}
   5.270 +				func += 2;
   5.271 +				bytecount += 2;
   5.272 +			}
   5.273 +			else if((opcode & 0xFC) == 0x80 ||
   5.274 +					(opcode & 0xC7) == 0x05 ||
   5.275 +					(opcode & 0xF8) == 0xB8 ||
   5.276 +					(opcode & 0xFE) == 0xE8 ||	  // CALL/Jcc
   5.277 +					(opcode & 0xFE) == 0x68 ||
   5.278 +					(opcode & 0xFC) == 0xA0 ||
   5.279 +					(opcode & 0xEE) == 0xA8 ||
   5.280 +					opcode == 0xC7 ||
   5.281 +					opcode == 0xF7 && (modRM & 0x30) == 0x00)
   5.282 +			{
   5.283 +				if (dest) {
   5.284 +					//Fix CALL/JMP offset
   5.285 +					if ((opcode & 0xFE) == 0xE8) {
   5.286 +						if (operandSize == 4)
   5.287 +						{
   5.288 +							*(long*)dest = ((func + *(long*)func) - dest);
   5.289 +
   5.290 +							//pRED* edit. func is the current address of the call address, +4 is the next instruction, so the value of $pc
   5.291 +							check_thunks(dest+4, func+4);
   5.292 +						}
   5.293 +						else
   5.294 +							*(short*)dest = ((func + *(short*)func) - dest);
   5.295 +
   5.296 +					} else {
   5.297 +						if (operandSize == 4)
   5.298 +							*(unsigned long*)dest = *(unsigned long*)func;
   5.299 +						else
   5.300 +							*(unsigned short*)dest = *(unsigned short*)func;
   5.301 +					}
   5.302 +					dest += operandSize;
   5.303 +				}
   5.304 +				func += operandSize;
   5.305 +				bytecount += operandSize;
   5.306 +
   5.307 +			}
   5.308 +		}
   5.309 +		else
   5.310 +		{
   5.311 +			if(opcode == 0xBA ||			// BT
   5.312 +			   opcode == 0x0F ||			// 3DNow!
   5.313 +			   (opcode & 0xFC) == 0x70 ||   // PSLLW
   5.314 +			   (opcode & 0xF7) == 0xA4 ||   // SHLD
   5.315 +			   opcode == 0xC2 ||
   5.316 +			   opcode == 0xC4 ||
   5.317 +			   opcode == 0xC5 ||
   5.318 +			   opcode == 0xC6)
   5.319 +			{
   5.320 +				if (dest)
   5.321 +					*dest++ = *func++;
   5.322 +				else
   5.323 +					func++;
   5.324 +			}
   5.325 +			else if((opcode & 0xF0) == 0x80) // Jcc -i
   5.326 +			{
   5.327 +				if (dest) {
   5.328 +					if (operandSize == 4)
   5.329 +						*(unsigned long*)dest = *(unsigned long*)func;
   5.330 +					else
   5.331 +						*(unsigned short*)dest = *(unsigned short*)func;
   5.332 +
   5.333 +					dest += operandSize;
   5.334 +				}
   5.335 +				func += operandSize;
   5.336 +				bytecount += operandSize;
   5.337 +			}
   5.338 +		}
   5.339 +	}
   5.340 +
   5.341 +	return bytecount;
   5.342 +}
   5.343 +
   5.344 +//insert a specific JMP instruction at the given location
   5.345 +void inject_jmp(void* src, void* dest) {
   5.346 +	*(unsigned char*)src = OP_JMP;
   5.347 +	*(long*)((unsigned char*)src+1) = (long)((unsigned char*)dest - ((unsigned char*)src + OP_JMP_SIZE));
   5.348 +}
   5.349 +
   5.350 +//fill a given block with NOPs
   5.351 +void fill_nop(void* src, unsigned int len) {
   5.352 +	unsigned char* src2 = (unsigned char*)src;
   5.353 +	while (len) {
   5.354 +		*src2++ = OP_NOP;
   5.355 +		--len;
   5.356 +	}
   5.357 +}
   5.358 +
   5.359 +void* eval_jump(void* src) {
   5.360 +	unsigned char* addr = (unsigned char*)src;
   5.361 +
   5.362 +	if (!addr) return 0;
   5.363 +
   5.364 +	//import table jump
   5.365 +	if (addr[0] == OP_PREFIX && addr[1] == OP_JMP_SEG) {
   5.366 +		addr += 2;
   5.367 +		addr = *(unsigned char**)addr;
   5.368 +		//TODO: if addr points into the IAT
   5.369 +		return *(void**)addr;
   5.370 +	}
   5.371 +
   5.372 +	//8bit offset
   5.373 +	else if (addr[0] == OP_JMP_BYTE) {
   5.374 +		addr = &addr[OP_JMP_BYTE_SIZE] + *(char*)&addr[1];
   5.375 +		//mangled 32bit jump?
   5.376 +		if (addr[0] = OP_JMP) {
   5.377 +			addr = addr + *(int*)&addr[1];
   5.378 +		}
   5.379 +		return addr;
   5.380 +	}
   5.381 +	/*
   5.382 +	//32bit offset
   5.383 +	else if (addr[0] == OP_JMP) {
   5.384 +		addr = &addr[OP_JMP_SIZE] + *(int*)&addr[1];
   5.385 +	}
   5.386 +	*/
   5.387 +
   5.388 +	return addr;
   5.389 +}
   5.390 +/*
   5.391 +from ms detours package
   5.392 +static bool detour_is_imported(PBYTE pbCode, PBYTE pbAddress)
   5.393 +{
   5.394 +	MEMORY_BASIC_INFORMATION mbi;
   5.395 +	VirtualQuery((PVOID)pbCode, &mbi, sizeof(mbi));
   5.396 +	__try {
   5.397 +		PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)mbi.AllocationBase;
   5.398 +		if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) {
   5.399 +			return false;
   5.400 +		}
   5.401 +
   5.402 +		PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PBYTE)pDosHeader +
   5.403 +														  pDosHeader->e_lfanew);
   5.404 +		if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) {
   5.405 +			return false;
   5.406 +		}
   5.407 +
   5.408 +		if (pbAddress >= ((PBYTE)pDosHeader +
   5.409 +						  pNtHeader->OptionalHeader
   5.410 +						  .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress) &&
   5.411 +			pbAddress < ((PBYTE)pDosHeader +
   5.412 +						 pNtHeader->OptionalHeader
   5.413 +						 .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress +
   5.414 +						 pNtHeader->OptionalHeader
   5.415 +						 .DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size)) {
   5.416 +			return true;
   5.417 +		}
   5.418 +		return false;
   5.419 +	}
   5.420 +	__except(EXCEPTION_EXECUTE_HANDLER) {
   5.421 +		return false;
   5.422 +	}
   5.423 +}
   5.424 +*/
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/asm/asm.h	Fri Feb 20 15:24:04 2009 +1300
     6.3 @@ -0,0 +1,40 @@
     6.4 +#ifndef __ASM_H__
     6.5 +#define __ASM_H__
     6.6 +
     6.7 +#define OP_JMP				0xE9
     6.8 +#define OP_JMP_SIZE			5
     6.9 +
    6.10 +#define OP_NOP				0x90
    6.11 +#define OP_NOP_SIZE			1
    6.12 +
    6.13 +#define OP_PREFIX			0xFF
    6.14 +#define OP_JMP_SEG			0x25
    6.15 +
    6.16 +#define OP_JMP_BYTE			0xEB
    6.17 +#define OP_JMP_BYTE_SIZE	2
    6.18 +
    6.19 +#ifdef __cplusplus
    6.20 +extern "C" {
    6.21 +#endif
    6.22 +
    6.23 +void check_thunks(unsigned char *dest, unsigned char *pc);
    6.24 +
    6.25 +//if dest is NULL, returns minimum number of bytes needed to be copied
    6.26 +//if dest is not NULL, it will copy the bytes to dest as well as fix CALLs and JMPs
    6.27 +//http://www.devmaster.net/forums/showthread.php?t=2311
    6.28 +int copy_bytes(unsigned char *func, unsigned char* dest, int required_len);
    6.29 +
    6.30 +//insert a specific JMP instruction at the given location
    6.31 +void inject_jmp(void* src, void* dest);
    6.32 +
    6.33 +//fill a given block with NOPs
    6.34 +void fill_nop(void* src, unsigned int len);
    6.35 +
    6.36 +//evaluate a JMP at the target
    6.37 +void* eval_jump(void* src);
    6.38 +
    6.39 +#ifdef __cplusplus
    6.40 +}
    6.41 +#endif
    6.42 +
    6.43 +#endif //__ASM_H__
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/extension.cpp	Fri Feb 20 15:24:04 2009 +1300
     7.3 @@ -0,0 +1,134 @@
     7.4 +/**
     7.5 + * vim: set ts=4 :
     7.6 + * =============================================================================
     7.7 + * SourceMod Sample Extension
     7.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     7.9 + * =============================================================================
    7.10 + *
    7.11 + * This program is free software; you can redistribute it and/or modify it under
    7.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    7.13 + * Free Software Foundation.
    7.14 + * 
    7.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    7.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    7.18 + * details.
    7.19 + *
    7.20 + * You should have received a copy of the GNU General Public License along with
    7.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    7.22 + *
    7.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    7.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    7.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    7.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    7.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    7.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    7.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    7.30 + * or <http://www.sourcemod.net/license.php>.
    7.31 + *
    7.32 + * Version: $Id: extension.cpp 249 2008-08-27 21:48:35Z pred $
    7.33 + */
    7.34 +
    7.35 +#include "extension.h"
    7.36 +
    7.37 +/**
    7.38 + * @file extension.cpp
    7.39 + * @brief Implement extension code here.
    7.40 + */
    7.41 +
    7.42 +Sample g_Sample;		/**< Global singleton for extension's main interface */
    7.43 +
    7.44 +SMEXT_LINK(&g_Sample);
    7.45 +
    7.46 +CDetour *runTeamLogicDetour;
    7.47 +CDetour *playerByIndexDetour;
    7.48 +
    7.49 +IGameConfig *g_pGameConf = NULL;
    7.50 +
    7.51 +//edict_t *(*UTIL_PlayerByIndex_Actual)(int) = NULL;
    7.52 +
    7.53 +//void (CTFGameRules::* CTFGameRules::Arena_RunTeamLogic_Actual)(void);
    7.54 +
    7.55 +int TempMax = 0;
    7.56 +CGlobalVars *gpGlobals;
    7.57 +
    7.58 +DETOUR_DECL_STATIC1(UTIL_PlayerByIndex, edict_t *, int, client)
    7.59 +{
    7.60 +	if (TempMax)
    7.61 +	{
    7.62 +		gpGlobals->maxClients = TempMax;
    7.63 +	}
    7.64 +
    7.65 +	edict_t *pPlayer = DETOUR_STATIC_CALL(UTIL_PlayerByIndex)(client);
    7.66 +
    7.67 +	if (TempMax)
    7.68 +	{
    7.69 +		gpGlobals->maxClients = 48;
    7.70 +	}
    7.71 +
    7.72 +	return pPlayer;
    7.73 +}
    7.74 +
    7.75 +DETOUR_DECL_MEMBER0(Arena_RunTeamLogic, void)
    7.76 +{
    7.77 +	TempMax = gpGlobals->maxClients;
    7.78 +	gpGlobals->maxClients = 48;
    7.79 +
    7.80 +	//(this->*Arena_RunTeamLogic_Actual)();
    7.81 +	DETOUR_MEMBER_CALL(Arena_RunTeamLogic)();
    7.82 +
    7.83 +	gpGlobals->maxClients = TempMax;
    7.84 +	TempMax = 0;
    7.85 +}
    7.86 +
    7.87 +void SetupDetours()
    7.88 +{
    7.89 +	//void *callback = GET_MEMBER_CALLBACK(CTFGameRules, Arena_RunTeamLogic);
    7.90 +	//void **trampoline = GET_MEMBER_TRAMPOLINE(CTFGameRules, Arena_RunTeamLogic);
    7.91 +
    7.92 +	runTeamLogicDetour = DETOUR_CREATE_MEMBER(Arena_RunTeamLogic, "RunTeamLogic");
    7.93 +	runTeamLogicDetour->EnableDetour();
    7.94 +
    7.95 +	//void *callback = (void *)&UTIL_PlayerByIndex;
    7.96 +	//void **trampoline = (void **)&UTIL_PlayerByIndex_Actual;
    7.97 +
    7.98 +	playerByIndexDetour = DETOUR_CREATE_STATIC(UTIL_PlayerByIndex, "PlayerByIndex");
    7.99 +	playerByIndexDetour->EnableDetour();
   7.100 +}
   7.101 +
   7.102 +void RemoveDetours()
   7.103 +{
   7.104 +	runTeamLogicDetour->Destroy();
   7.105 +	playerByIndexDetour->Destroy();
   7.106 +}
   7.107 +
   7.108 +bool Sample::SDK_OnLoad(char *error, size_t maxlength, bool late)
   7.109 +{
   7.110 +	char conf_error[255] = "";
   7.111 +	if (!gameconfs->LoadGameConfigFile("runteamlogic", &g_pGameConf, conf_error, sizeof(conf_error)))
   7.112 +	{
   7.113 +		if (conf_error)
   7.114 +		{
   7.115 +			snprintf(error, maxlength, "Could not read runteamlogic.txt: %s", conf_error);
   7.116 +		}
   7.117 +		return false;
   7.118 +	}
   7.119 +
   7.120 +	CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf);
   7.121 +
   7.122 +	SetupDetours();
   7.123 +
   7.124 +	return true;
   7.125 +}
   7.126 +
   7.127 +void Sample::SDK_OnUnload()
   7.128 +{
   7.129 +	RemoveDetours();
   7.130 +}
   7.131 +
   7.132 +bool Sample::SDK_OnMetamodLoad( ISmmAPI *ismm, char *error, size_t maxlength, bool late )
   7.133 +{
   7.134 +	gpGlobals = ismm->GetCGlobals();
   7.135 +
   7.136 +	return true;
   7.137 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/extension.h	Fri Feb 20 15:24:04 2009 +1300
     8.3 @@ -0,0 +1,123 @@
     8.4 +/**
     8.5 + * vim: set ts=4 :
     8.6 + * =============================================================================
     8.7 + * SourceMod Sample Extension
     8.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     8.9 + * =============================================================================
    8.10 + *
    8.11 + * This program is free software; you can redistribute it and/or modify it under
    8.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    8.13 + * Free Software Foundation.
    8.14 + * 
    8.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    8.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    8.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    8.18 + * details.
    8.19 + *
    8.20 + * You should have received a copy of the GNU General Public License along with
    8.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    8.22 + *
    8.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    8.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    8.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    8.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    8.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    8.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    8.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    8.30 + * or <http://www.sourcemod.net/license.php>.
    8.31 + *
    8.32 + * Version: $Id: extension.h 249 2008-08-27 21:48:35Z pred $
    8.33 + */
    8.34 +
    8.35 +#ifndef _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
    8.36 +#define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
    8.37 +
    8.38 +/**
    8.39 + * @file extension.h
    8.40 + * @brief Sample extension code header.
    8.41 + */
    8.42 +
    8.43 +#include "smsdk_ext.h"
    8.44 +#include "CDetour/detours.h"
    8.45 +
    8.46 +
    8.47 +/**
    8.48 + * @brief Sample implementation of the SDK Extension.
    8.49 + * Note: Uncomment one of the pre-defined virtual functions in order to use it.
    8.50 + */
    8.51 +class Sample : public SDKExtension
    8.52 +{
    8.53 +public:
    8.54 +	/**
    8.55 +	 * @brief This is called after the initial loading sequence has been processed.
    8.56 +	 *
    8.57 +	 * @param error		Error message buffer.
    8.58 +	 * @param maxlength	Size of error message buffer.
    8.59 +	 * @param late		Whether or not the module was loaded after map load.
    8.60 +	 * @return			True to succeed loading, false to fail.
    8.61 +	 */
    8.62 +	virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
    8.63 +	
    8.64 +	/**
    8.65 +	 * @brief This is called right before the extension is unloaded.
    8.66 +	 */
    8.67 +	virtual void SDK_OnUnload();
    8.68 +
    8.69 +	/**
    8.70 +	 * @brief This is called once all known extensions have been loaded.
    8.71 +	 * Note: It is is a good idea to add natives here, if any are provided.
    8.72 +	 */
    8.73 +	//virtual void SDK_OnAllLoaded();
    8.74 +
    8.75 +	/**
    8.76 +	 * @brief Called when the pause state is changed.
    8.77 +	 */
    8.78 +	//virtual void SDK_OnPauseChange(bool paused);
    8.79 +
    8.80 +	/**
    8.81 +	 * @brief this is called when Core wants to know if your extension is working.
    8.82 +	 *
    8.83 +	 * @param error		Error message buffer.
    8.84 +	 * @param maxlength	Size of error message buffer.
    8.85 +	 * @return			True if working, false otherwise.
    8.86 +	 */
    8.87 +	//virtual bool QueryRunning(char *error, size_t maxlength);
    8.88 +public:
    8.89 +#if defined SMEXT_CONF_METAMOD
    8.90 +	/**
    8.91 +	 * @brief Called when Metamod is attached, before the extension version is called.
    8.92 +	 *
    8.93 +	 * @param error			Error buffer.
    8.94 +	 * @param maxlength		Maximum size of error buffer.
    8.95 +	 * @param late			Whether or not Metamod considers this a late load.
    8.96 +	 * @return				True to succeed, false to fail.
    8.97 +	 */
    8.98 +	virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
    8.99 +
   8.100 +	/**
   8.101 +	 * @brief Called when Metamod is detaching, after the extension version is called.
   8.102 +	 * NOTE: By default this is blocked unless sent from SourceMod.
   8.103 +	 *
   8.104 +	 * @param error			Error buffer.
   8.105 +	 * @param maxlength		Maximum size of error buffer.
   8.106 +	 * @return				True to succeed, false to fail.
   8.107 +	 */
   8.108 +	//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
   8.109 +
   8.110 +	/**
   8.111 +	 * @brief Called when Metamod's pause state is changing.
   8.112 +	 * NOTE: By default this is blocked unless sent from SourceMod.
   8.113 +	 *
   8.114 +	 * @param paused		Pause state being set.
   8.115 +	 * @param error			Error buffer.
   8.116 +	 * @param maxlength		Maximum size of error buffer.
   8.117 +	 * @return				True to succeed, false to fail.
   8.118 +	 */
   8.119 +	//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
   8.120 +#endif
   8.121 +};
   8.122 +
   8.123 +//edict_t *UTIL_PlayerByIndex(int client);
   8.124 +//extern edict_t *(*UTIL_PlayerByIndex_Actual)(int);
   8.125 +
   8.126 +#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/msvc9/sdk.sln	Fri Feb 20 15:24:04 2009 +1300
     9.3 @@ -0,0 +1,38 @@
     9.4 +
     9.5 +Microsoft Visual Studio Solution File, Format Version 10.00
     9.6 +# Visual Studio 2008
     9.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdk", "sdk.vcproj", "{B3E797CF-4E77-4C9D-B8A8-7589B6902206}"
     9.8 +EndProject
     9.9 +Global
    9.10 +	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    9.11 +		Debug - Episode 1|Win32 = Debug - Episode 1|Win32
    9.12 +		Debug - Old Metamod|Win32 = Debug - Old Metamod|Win32
    9.13 +		Debug - Orange Box|Win32 = Debug - Orange Box|Win32
    9.14 +		Debug|Win32 = Debug|Win32
    9.15 +		Release - Episode 1|Win32 = Release - Episode 1|Win32
    9.16 +		Release - Old Metamod|Win32 = Release - Old Metamod|Win32
    9.17 +		Release - Orange Box|Win32 = Release - Orange Box|Win32
    9.18 +		Release|Win32 = Release|Win32
    9.19 +	EndGlobalSection
    9.20 +	GlobalSection(ProjectConfigurationPlatforms) = postSolution
    9.21 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Debug - Episode 1|Win32.ActiveCfg = Debug - Episode 1|Win32
    9.22 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Debug - Episode 1|Win32.Build.0 = Debug - Episode 1|Win32
    9.23 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Debug - Old Metamod|Win32.ActiveCfg = Debug - Old Metamod|Win32
    9.24 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Debug - Old Metamod|Win32.Build.0 = Debug - Old Metamod|Win32
    9.25 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Debug - Orange Box|Win32.ActiveCfg = Debug - Orange Box|Win32
    9.26 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Debug - Orange Box|Win32.Build.0 = Debug - Orange Box|Win32
    9.27 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Debug|Win32.ActiveCfg = Debug|Win32
    9.28 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Debug|Win32.Build.0 = Debug|Win32
    9.29 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Release - Episode 1|Win32.ActiveCfg = Release - Episode 1|Win32
    9.30 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Release - Episode 1|Win32.Build.0 = Release - Episode 1|Win32
    9.31 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Release - Old Metamod|Win32.ActiveCfg = Release - Old Metamod|Win32
    9.32 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Release - Old Metamod|Win32.Build.0 = Release - Old Metamod|Win32
    9.33 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Release - Orange Box|Win32.ActiveCfg = Release - Orange Box|Win32
    9.34 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Release - Orange Box|Win32.Build.0 = Release - Orange Box|Win32
    9.35 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Release|Win32.ActiveCfg = Release|Win32
    9.36 +		{B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Release|Win32.Build.0 = Release|Win32
    9.37 +	EndGlobalSection
    9.38 +	GlobalSection(SolutionProperties) = preSolution
    9.39 +		HideSolutionNode = FALSE
    9.40 +	EndGlobalSection
    9.41 +EndGlobal
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/msvc9/sdk.vcproj	Fri Feb 20 15:24:04 2009 +1300
    10.3 @@ -0,0 +1,739 @@
    10.4 +<?xml version="1.0" encoding="Windows-1252"?>
    10.5 +<VisualStudioProject
    10.6 +	ProjectType="Visual C++"
    10.7 +	Version="9.00"
    10.8 +	Name="sdk"
    10.9 +	ProjectGUID="{B3E797CF-4E77-4C9D-B8A8-7589B6902206}"
   10.10 +	RootNamespace="sdk"
   10.11 +	Keyword="Win32Proj"
   10.12 +	TargetFrameworkVersion="131072"
   10.13 +	>
   10.14 +	<Platforms>
   10.15 +		<Platform
   10.16 +			Name="Win32"
   10.17 +		/>
   10.18 +	</Platforms>
   10.19 +	<ToolFiles>
   10.20 +	</ToolFiles>
   10.21 +	<Configurations>
   10.22 +		<Configuration
   10.23 +			Name="Debug|Win32"
   10.24 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
   10.25 +			IntermediateDirectory="$(ConfigurationName)"
   10.26 +			ConfigurationType="2"
   10.27 +			CharacterSet="2"
   10.28 +			>
   10.29 +			<Tool
   10.30 +				Name="VCPreBuildEventTool"
   10.31 +			/>
   10.32 +			<Tool
   10.33 +				Name="VCCustomBuildTool"
   10.34 +			/>
   10.35 +			<Tool
   10.36 +				Name="VCXMLDataGeneratorTool"
   10.37 +			/>
   10.38 +			<Tool
   10.39 +				Name="VCWebServiceProxyGeneratorTool"
   10.40 +			/>
   10.41 +			<Tool
   10.42 +				Name="VCMIDLTool"
   10.43 +			/>
   10.44 +			<Tool
   10.45 +				Name="VCCLCompilerTool"
   10.46 +				Optimization="0"
   10.47 +				AdditionalIncludeDirectories="..;..\sdk;..\..;..\..\sourcepawn"
   10.48 +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD;ORANGEBOX_BUILD"
   10.49 +				MinimalRebuild="true"
   10.50 +				BasicRuntimeChecks="3"
   10.51 +				RuntimeLibrary="1"
   10.52 +				EnableEnhancedInstructionSet="1"
   10.53 +				RuntimeTypeInfo="false"
   10.54 +				UsePrecompiledHeader="0"
   10.55 +				WarningLevel="3"
   10.56 +				Detect64BitPortabilityProblems="false"
   10.57 +				DebugInformationFormat="4"
   10.58 +			/>
   10.59 +			<Tool
   10.60 +				Name="VCManagedResourceCompilerTool"
   10.61 +			/>
   10.62 +			<Tool
   10.63 +				Name="VCResourceCompilerTool"
   10.64 +			/>
   10.65 +			<Tool
   10.66 +				Name="VCPreLinkEventTool"
   10.67 +			/>
   10.68 +			<Tool
   10.69 +				Name="VCLinkerTool"
   10.70 +				OutputFile="$(OutDir)\sample.ext.dll"
   10.71 +				LinkIncremental="2"
   10.72 +				IgnoreDefaultLibraryNames="LIBC;LIBCD;LIBCMT"
   10.73 +				GenerateDebugInformation="true"
   10.74 +				SubSystem="2"
   10.75 +				RandomizedBaseAddress="1"
   10.76 +				DataExecutionPrevention="0"
   10.77 +				TargetMachine="1"
   10.78 +			/>
   10.79 +			<Tool
   10.80 +				Name="VCALinkTool"
   10.81 +			/>
   10.82 +			<Tool
   10.83 +				Name="VCManifestTool"
   10.84 +			/>
   10.85 +			<Tool
   10.86 +				Name="VCXDCMakeTool"
   10.87 +			/>
   10.88 +			<Tool
   10.89 +				Name="VCBscMakeTool"
   10.90 +			/>
   10.91 +			<Tool
   10.92 +				Name="VCFxCopTool"
   10.93 +			/>
   10.94 +			<Tool
   10.95 +				Name="VCAppVerifierTool"
   10.96 +			/>
   10.97 +			<Tool
   10.98 +				Name="VCPostBuildEventTool"
   10.99 +			/>
  10.100 +		</Configuration>
  10.101 +		<Configuration
  10.102 +			Name="Release|Win32"
  10.103 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
  10.104 +			IntermediateDirectory="$(ConfigurationName)"
  10.105 +			ConfigurationType="2"
  10.106 +			CharacterSet="2"
  10.107 +			WholeProgramOptimization="1"
  10.108 +			>
  10.109 +			<Tool
  10.110 +				Name="VCPreBuildEventTool"
  10.111 +			/>
  10.112 +			<Tool
  10.113 +				Name="VCCustomBuildTool"
  10.114 +			/>
  10.115 +			<Tool
  10.116 +				Name="VCXMLDataGeneratorTool"
  10.117 +			/>
  10.118 +			<Tool
  10.119 +				Name="VCWebServiceProxyGeneratorTool"
  10.120 +			/>
  10.121 +			<Tool
  10.122 +				Name="VCMIDLTool"
  10.123 +			/>
  10.124 +			<Tool
  10.125 +				Name="VCCLCompilerTool"
  10.126 +				FavorSizeOrSpeed="1"
  10.127 +				AdditionalIncludeDirectories="..;..\sdk;..\..;..\..\sourcepawn"
  10.128 +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD;ORANGEBOX_BUILD"
  10.129 +				RuntimeLibrary="0"
  10.130 +				EnableEnhancedInstructionSet="1"
  10.131 +				RuntimeTypeInfo="false"
  10.132 +				UsePrecompiledHeader="0"
  10.133 +				WarningLevel="3"
  10.134 +				Detect64BitPortabilityProblems="false"
  10.135 +				DebugInformationFormat="3"
  10.136 +			/>
  10.137 +			<Tool
  10.138 +				Name="VCManagedResourceCompilerTool"
  10.139 +			/>
  10.140 +			<Tool
  10.141 +				Name="VCResourceCompilerTool"
  10.142 +			/>
  10.143 +			<Tool
  10.144 +				Name="VCPreLinkEventTool"
  10.145 +			/>
  10.146 +			<Tool
  10.147 +				Name="VCLinkerTool"
  10.148 +				OutputFile="$(OutDir)\sample.ext.dll"
  10.149 +				LinkIncremental="1"
  10.150 +				IgnoreDefaultLibraryNames="LIBC;LIBCD;LIBCMTD"
  10.151 +				GenerateDebugInformation="true"
  10.152 +				SubSystem="2"
  10.153 +				OptimizeReferences="2"
  10.154 +				EnableCOMDATFolding="2"
  10.155 +				RandomizedBaseAddress="1"
  10.156 +				DataExecutionPrevention="0"
  10.157 +				TargetMachine="1"
  10.158 +			/>
  10.159 +			<Tool
  10.160 +				Name="VCALinkTool"
  10.161 +			/>
  10.162 +			<Tool
  10.163 +				Name="VCManifestTool"
  10.164 +			/>
  10.165 +			<Tool
  10.166 +				Name="VCXDCMakeTool"
  10.167 +			/>
  10.168 +			<Tool
  10.169 +				Name="VCBscMakeTool"
  10.170 +			/>
  10.171 +			<Tool
  10.172 +				Name="VCFxCopTool"
  10.173 +			/>
  10.174 +			<Tool
  10.175 +				Name="VCAppVerifierTool"
  10.176 +			/>
  10.177 +			<Tool
  10.178 +				Name="VCPostBuildEventTool"
  10.179 +			/>
  10.180 +		</Configuration>
  10.181 +		<Configuration
  10.182 +			Name="Debug - Old Metamod|Win32"
  10.183 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
  10.184 +			IntermediateDirectory="$(ConfigurationName)"
  10.185 +			ConfigurationType="2"
  10.186 +			CharacterSet="2"
  10.187 +			>
  10.188 +			<Tool
  10.189 +				Name="VCPreBuildEventTool"
  10.190 +			/>
  10.191 +			<Tool
  10.192 +				Name="VCCustomBuildTool"
  10.193 +			/>
  10.194 +			<Tool
  10.195 +				Name="VCXMLDataGeneratorTool"
  10.196 +			/>
  10.197 +			<Tool
  10.198 +				Name="VCWebServiceProxyGeneratorTool"
  10.199 +			/>
  10.200 +			<Tool
  10.201 +				Name="VCMIDLTool"
  10.202 +			/>
  10.203 +			<Tool
  10.204 +				Name="VCCLCompilerTool"
  10.205 +				Optimization="0"
  10.206 +				AdditionalIncludeDirectories="..;..\sdk;..\..;..\..\sourcepawn;&quot;$(HL2SDK)\public&quot;;&quot;$(HL2SDK)\public\dlls&quot;;&quot;$(HL2SDK)\public\engine&quot;;&quot;$(HL2SDK)\public\tier0&quot;;&quot;$(HL2SDK)\public\tier1&quot;;&quot;$(SOURCEMM14)&quot;;&quot;$(SOURCEMM14)\sourcemm&quot;;&quot;$(SOURCEMM14)\sourcehook&quot;"
  10.207 +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD"
  10.208 +				MinimalRebuild="true"
  10.209 +				BasicRuntimeChecks="3"
  10.210 +				RuntimeLibrary="1"
  10.211 +				EnableEnhancedInstructionSet="1"
  10.212 +				RuntimeTypeInfo="false"
  10.213 +				UsePrecompiledHeader="0"
  10.214 +				WarningLevel="3"
  10.215 +				Detect64BitPortabilityProblems="false"
  10.216 +				DebugInformationFormat="4"
  10.217 +			/>
  10.218 +			<Tool
  10.219 +				Name="VCManagedResourceCompilerTool"
  10.220 +			/>
  10.221 +			<Tool
  10.222 +				Name="VCResourceCompilerTool"
  10.223 +			/>
  10.224 +			<Tool
  10.225 +				Name="VCPreLinkEventTool"
  10.226 +			/>
  10.227 +			<Tool
  10.228 +				Name="VCLinkerTool"
  10.229 +				AdditionalDependencies="&quot;$(HL2SDK)\lib\public\tier0.lib&quot; &quot;$(HL2SDK)\lib\public\tier1.lib&quot; &quot;$(HL2SDK)\lib\public\vstdlib.lib&quot;"
  10.230 +				OutputFile="$(OutDir)\sample.ext.dll"
  10.231 +				LinkIncremental="2"
  10.232 +				IgnoreDefaultLibraryNames="LIBC;LIBCD;LIBCMT"
  10.233 +				GenerateDebugInformation="true"
  10.234 +				SubSystem="2"
  10.235 +				RandomizedBaseAddress="1"
  10.236 +				DataExecutionPrevention="0"
  10.237 +				TargetMachine="1"
  10.238 +			/>
  10.239 +			<Tool
  10.240 +				Name="VCALinkTool"
  10.241 +			/>
  10.242 +			<Tool
  10.243 +				Name="VCManifestTool"
  10.244 +			/>
  10.245 +			<Tool
  10.246 +				Name="VCXDCMakeTool"
  10.247 +			/>
  10.248 +			<Tool
  10.249 +				Name="VCBscMakeTool"
  10.250 +			/>
  10.251 +			<Tool
  10.252 +				Name="VCFxCopTool"
  10.253 +			/>
  10.254 +			<Tool
  10.255 +				Name="VCAppVerifierTool"
  10.256 +			/>
  10.257 +			<Tool
  10.258 +				Name="VCPostBuildEventTool"
  10.259 +			/>
  10.260 +		</Configuration>
  10.261 +		<Configuration
  10.262 +			Name="Release - Old Metamod|Win32"
  10.263 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
  10.264 +			IntermediateDirectory="$(ConfigurationName)"
  10.265 +			ConfigurationType="2"
  10.266 +			CharacterSet="2"
  10.267 +			WholeProgramOptimization="1"
  10.268 +			>
  10.269 +			<Tool
  10.270 +				Name="VCPreBuildEventTool"
  10.271 +			/>
  10.272 +			<Tool
  10.273 +				Name="VCCustomBuildTool"
  10.274 +			/>
  10.275 +			<Tool
  10.276 +				Name="VCXMLDataGeneratorTool"
  10.277 +			/>
  10.278 +			<Tool
  10.279 +				Name="VCWebServiceProxyGeneratorTool"
  10.280 +			/>
  10.281 +			<Tool
  10.282 +				Name="VCMIDLTool"
  10.283 +			/>
  10.284 +			<Tool
  10.285 +				Name="VCCLCompilerTool"
  10.286 +				FavorSizeOrSpeed="1"
  10.287 +				AdditionalIncludeDirectories="..;..\sdk;..\..;..\..\sourcepawn;&quot;$(HL2SDK)\public&quot;;&quot;$(HL2SDK)\public\dlls&quot;;&quot;$(HL2SDK)\public\engine&quot;;&quot;$(HL2SDK)\public\tier0&quot;;&quot;$(HL2SDK)\public\tier1&quot;;&quot;$(SOURCEMM14)&quot;;&quot;$(SOURCEMM14)\sourcemm&quot;;&quot;$(SOURCEMM14)\sourcehook&quot;"
  10.288 +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD"
  10.289 +				RuntimeLibrary="0"
  10.290 +				EnableEnhancedInstructionSet="1"
  10.291 +				RuntimeTypeInfo="false"
  10.292 +				UsePrecompiledHeader="0"
  10.293 +				WarningLevel="3"
  10.294 +				Detect64BitPortabilityProblems="false"
  10.295 +				DebugInformationFormat="3"
  10.296 +			/>
  10.297 +			<Tool
  10.298 +				Name="VCManagedResourceCompilerTool"
  10.299 +			/>
  10.300 +			<Tool
  10.301 +				Name="VCResourceCompilerTool"
  10.302 +			/>
  10.303 +			<Tool
  10.304 +				Name="VCPreLinkEventTool"
  10.305 +			/>
  10.306 +			<Tool
  10.307 +				Name="VCLinkerTool"
  10.308 +				AdditionalDependencies="&quot;$(HL2SDK)\lib\public\tier0.lib&quot; &quot;$(HL2SDK)\lib\public\tier1.lib&quot; &quot;$(HL2SDK)\lib\public\vstdlib.lib&quot;"
  10.309 +				OutputFile="$(OutDir)\sample.ext.dll"
  10.310 +				LinkIncremental="1"
  10.311 +				IgnoreDefaultLibraryNames="LIBC;LIBCD;LIBCMTD"
  10.312 +				GenerateDebugInformation="true"
  10.313 +				SubSystem="2"
  10.314 +				OptimizeReferences="2"
  10.315 +				EnableCOMDATFolding="2"
  10.316 +				RandomizedBaseAddress="1"
  10.317 +				DataExecutionPrevention="0"
  10.318 +				TargetMachine="1"
  10.319 +			/>
  10.320 +			<Tool
  10.321 +				Name="VCALinkTool"
  10.322 +			/>
  10.323 +			<Tool
  10.324 +				Name="VCManifestTool"
  10.325 +			/>
  10.326 +			<Tool
  10.327 +				Name="VCXDCMakeTool"
  10.328 +			/>
  10.329 +			<Tool
  10.330 +				Name="VCBscMakeTool"
  10.331 +			/>
  10.332 +			<Tool
  10.333 +				Name="VCFxCopTool"
  10.334 +			/>
  10.335 +			<Tool
  10.336 +				Name="VCAppVerifierTool"
  10.337 +			/>
  10.338 +			<Tool
  10.339 +				Name="VCPostBuildEventTool"
  10.340 +			/>
  10.341 +		</Configuration>
  10.342 +		<Configuration
  10.343 +			Name="Debug - Orange Box|Win32"
  10.344 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
  10.345 +			IntermediateDirectory="$(ConfigurationName)"
  10.346 +			ConfigurationType="2"
  10.347 +			CharacterSet="2"
  10.348 +			>
  10.349 +			<Tool
  10.350 +				Name="VCPreBuildEventTool"
  10.351 +			/>
  10.352 +			<Tool
  10.353 +				Name="VCCustomBuildTool"
  10.354 +			/>
  10.355 +			<Tool
  10.356 +				Name="VCXMLDataGeneratorTool"
  10.357 +			/>
  10.358 +			<Tool
  10.359 +				Name="VCWebServiceProxyGeneratorTool"
  10.360 +			/>
  10.361 +			<Tool
  10.362 +				Name="VCMIDLTool"
  10.363 +			/>
  10.364 +			<Tool
  10.365 +				Name="VCCLCompilerTool"
  10.366 +				Optimization="0"
  10.367 +				AdditionalIncludeDirectories="..;..\sdk;..\..;..\..\sourcepawn;&quot;$(HL2SDKOB)\public&quot;;&quot;$(HL2SDKOB)\public\engine&quot;;&quot;$(HL2SDKOB)\public\game\server&quot;;&quot;$(HL2SDKOB)\public\tier0&quot;;&quot;$(HL2SDKOB)\public\tier1&quot;;&quot;$(SOURCEMM16)&quot;;&quot;$(SOURCEMM16)\sourcemm&quot;;&quot;$(SOURCEMM16)\sourcehook&quot;"
  10.368 +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD;ORANGEBOX_BUILD"
  10.369 +				MinimalRebuild="true"
  10.370 +				BasicRuntimeChecks="3"
  10.371 +				RuntimeLibrary="1"
  10.372 +				EnableEnhancedInstructionSet="1"
  10.373 +				RuntimeTypeInfo="false"
  10.374 +				UsePrecompiledHeader="0"
  10.375 +				WarningLevel="3"
  10.376 +				Detect64BitPortabilityProblems="false"
  10.377 +				DebugInformationFormat="4"
  10.378 +			/>
  10.379 +			<Tool
  10.380 +				Name="VCManagedResourceCompilerTool"
  10.381 +			/>
  10.382 +			<Tool
  10.383 +				Name="VCResourceCompilerTool"
  10.384 +			/>
  10.385 +			<Tool
  10.386 +				Name="VCPreLinkEventTool"
  10.387 +			/>
  10.388 +			<Tool
  10.389 +				Name="VCLinkerTool"
  10.390 +				AdditionalDependencies="&quot;$(HL2SDKOB)\lib\public\tier0.lib&quot; &quot;$(HL2SDKOB)\lib\public\tier1.lib&quot; &quot;$(HL2SDKOB)\lib\public\vstdlib.lib&quot;"
  10.391 +				OutputFile="$(OutDir)\sample.ext.dll"
  10.392 +				LinkIncremental="2"
  10.393 +				IgnoreDefaultLibraryNames="LIBC;LIBCD;LIBCMT"
  10.394 +				GenerateDebugInformation="true"
  10.395 +				SubSystem="2"
  10.396 +				RandomizedBaseAddress="1"
  10.397 +				DataExecutionPrevention="0"
  10.398 +				TargetMachine="1"
  10.399 +			/>
  10.400 +			<Tool
  10.401 +				Name="VCALinkTool"
  10.402 +			/>
  10.403 +			<Tool
  10.404 +				Name="VCManifestTool"
  10.405 +			/>
  10.406 +			<Tool
  10.407 +				Name="VCXDCMakeTool"
  10.408 +			/>
  10.409 +			<Tool
  10.410 +				Name="VCBscMakeTool"
  10.411 +			/>
  10.412 +			<Tool
  10.413 +				Name="VCFxCopTool"
  10.414 +			/>
  10.415 +			<Tool
  10.416 +				Name="VCAppVerifierTool"
  10.417 +			/>
  10.418 +			<Tool
  10.419 +				Name="VCPostBuildEventTool"
  10.420 +			/>
  10.421 +		</Configuration>
  10.422 +		<Configuration
  10.423 +			Name="Release - Orange Box|Win32"
  10.424 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
  10.425 +			IntermediateDirectory="$(ConfigurationName)"
  10.426 +			ConfigurationType="2"
  10.427 +			CharacterSet="2"
  10.428 +			WholeProgramOptimization="1"
  10.429 +			>
  10.430 +			<Tool
  10.431 +				Name="VCPreBuildEventTool"
  10.432 +			/>
  10.433 +			<Tool
  10.434 +				Name="VCCustomBuildTool"
  10.435 +			/>
  10.436 +			<Tool
  10.437 +				Name="VCXMLDataGeneratorTool"
  10.438 +			/>
  10.439 +			<Tool
  10.440 +				Name="VCWebServiceProxyGeneratorTool"
  10.441 +			/>
  10.442 +			<Tool
  10.443 +				Name="VCMIDLTool"
  10.444 +			/>
  10.445 +			<Tool
  10.446 +				Name="VCCLCompilerTool"
  10.447 +				FavorSizeOrSpeed="1"
  10.448 +				AdditionalIncludeDirectories="..;..\sdk;..\..;..\..\sourcepawn;&quot;$(HL2SDKOB)\public&quot;;&quot;$(HL2SDKOB)\public\engine&quot;;&quot;$(HL2SDKOB)\public\game\server&quot;;&quot;$(HL2SDKOB)\public\tier0&quot;;&quot;$(HL2SDKOB)\public\tier1&quot;;&quot;$(SOURCEMM16)&quot;;&quot;$(SOURCEMM16)\sourcemm&quot;;&quot;$(SOURCEMM16)\sourcehook&quot;"
  10.449 +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD;ORANGEBOX_BUILD"
  10.450 +				RuntimeLibrary="0"
  10.451 +				EnableEnhancedInstructionSet="1"
  10.452 +				RuntimeTypeInfo="false"
  10.453 +				UsePrecompiledHeader="0"
  10.454 +				WarningLevel="3"
  10.455 +				Detect64BitPortabilityProblems="false"
  10.456 +				DebugInformationFormat="3"
  10.457 +			/>
  10.458 +			<Tool
  10.459 +				Name="VCManagedResourceCompilerTool"
  10.460 +			/>
  10.461 +			<Tool
  10.462 +				Name="VCResourceCompilerTool"
  10.463 +			/>
  10.464 +			<Tool
  10.465 +				Name="VCPreLinkEventTool"
  10.466 +			/>
  10.467 +			<Tool
  10.468 +				Name="VCLinkerTool"
  10.469 +				AdditionalDependencies="&quot;$(HL2SDKOB)\lib\public\tier0.lib&quot; &quot;$(HL2SDKOB)\lib\public\tier1.lib&quot; &quot;$(HL2SDKOB)\lib\public\vstdlib.lib&quot;"
  10.470 +				OutputFile="$(OutDir)\sample.ext.dll"
  10.471 +				LinkIncremental="1"
  10.472 +				IgnoreDefaultLibraryNames="LIBC;LIBCD;LIBCMTD"
  10.473 +				GenerateDebugInformation="true"
  10.474 +				SubSystem="2"
  10.475 +				OptimizeReferences="2"
  10.476 +				EnableCOMDATFolding="2"
  10.477 +				RandomizedBaseAddress="1"
  10.478 +				DataExecutionPrevention="0"
  10.479 +				TargetMachine="1"
  10.480 +			/>
  10.481 +			<Tool
  10.482 +				Name="VCALinkTool"
  10.483 +			/>
  10.484 +			<Tool
  10.485 +				Name="VCManifestTool"
  10.486 +			/>
  10.487 +			<Tool
  10.488 +				Name="VCXDCMakeTool"
  10.489 +			/>
  10.490 +			<Tool
  10.491 +				Name="VCBscMakeTool"
  10.492 +			/>
  10.493 +			<Tool
  10.494 +				Name="VCFxCopTool"
  10.495 +			/>
  10.496 +			<Tool
  10.497 +				Name="VCAppVerifierTool"
  10.498 +			/>
  10.499 +			<Tool
  10.500 +				Name="VCPostBuildEventTool"
  10.501 +			/>
  10.502 +		</Configuration>
  10.503 +		<Configuration
  10.504 +			Name="Debug - Episode 1|Win32"
  10.505 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
  10.506 +			IntermediateDirectory="$(ConfigurationName)"
  10.507 +			ConfigurationType="2"
  10.508 +			CharacterSet="2"
  10.509 +			>
  10.510 +			<Tool
  10.511 +				Name="VCPreBuildEventTool"
  10.512 +			/>
  10.513 +			<Tool
  10.514 +				Name="VCCustomBuildTool"
  10.515 +			/>
  10.516 +			<Tool
  10.517 +				Name="VCXMLDataGeneratorTool"
  10.518 +			/>
  10.519 +			<Tool
  10.520 +				Name="VCWebServiceProxyGeneratorTool"
  10.521 +			/>
  10.522 +			<Tool
  10.523 +				Name="VCMIDLTool"
  10.524 +			/>
  10.525 +			<Tool
  10.526 +				Name="VCCLCompilerTool"
  10.527 +				Optimization="0"
  10.528 +				AdditionalIncludeDirectories="..;..\sdk;..\..;..\..\sourcepawn;&quot;$(HL2SDK)\public&quot;;&quot;$(HL2SDK)\public\dlls&quot;;&quot;$(HL2SDK)\public\engine&quot;;&quot;$(HL2SDK)\public\tier0&quot;;&quot;$(HL2SDK)\public\tier1&quot;;&quot;$(SOURCEMM16)&quot;;&quot;$(SOURCEMM16)\sourcemm&quot;;&quot;$(SOURCEMM16)\sourcehook&quot;"
  10.529 +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD"
  10.530 +				MinimalRebuild="true"
  10.531 +				BasicRuntimeChecks="3"
  10.532 +				RuntimeLibrary="1"
  10.533 +				EnableEnhancedInstructionSet="1"
  10.534 +				RuntimeTypeInfo="false"
  10.535 +				UsePrecompiledHeader="0"
  10.536 +				WarningLevel="3"
  10.537 +				Detect64BitPortabilityProblems="false"
  10.538 +				DebugInformationFormat="4"
  10.539 +			/>
  10.540 +			<Tool
  10.541 +				Name="VCManagedResourceCompilerTool"
  10.542 +			/>
  10.543 +			<Tool
  10.544 +				Name="VCResourceCompilerTool"
  10.545 +			/>
  10.546 +			<Tool
  10.547 +				Name="VCPreLinkEventTool"
  10.548 +			/>
  10.549 +			<Tool
  10.550 +				Name="VCLinkerTool"
  10.551 +				AdditionalDependencies="&quot;$(HL2SDK)\lib\public\tier0.lib&quot; &quot;$(HL2SDK)\lib\public\tier1.lib&quot; &quot;$(HL2SDK)\lib\public\vstdlib.lib&quot;"
  10.552 +				OutputFile="$(OutDir)\sample.ext.dll"
  10.553 +				LinkIncremental="2"
  10.554 +				IgnoreDefaultLibraryNames="LIBC;LIBCD;LIBCMT"
  10.555 +				GenerateDebugInformation="true"
  10.556 +				SubSystem="2"
  10.557 +				RandomizedBaseAddress="1"
  10.558 +				DataExecutionPrevention="0"
  10.559 +				TargetMachine="1"
  10.560 +			/>
  10.561 +			<Tool
  10.562 +				Name="VCALinkTool"
  10.563 +			/>
  10.564 +			<Tool
  10.565 +				Name="VCManifestTool"
  10.566 +			/>
  10.567 +			<Tool
  10.568 +				Name="VCXDCMakeTool"
  10.569 +			/>
  10.570 +			<Tool
  10.571 +				Name="VCBscMakeTool"
  10.572 +			/>
  10.573 +			<Tool
  10.574 +				Name="VCFxCopTool"
  10.575 +			/>
  10.576 +			<Tool
  10.577 +				Name="VCAppVerifierTool"
  10.578 +			/>
  10.579 +			<Tool
  10.580 +				Name="VCPostBuildEventTool"
  10.581 +			/>
  10.582 +		</Configuration>
  10.583 +		<Configuration
  10.584 +			Name="Release - Episode 1|Win32"
  10.585 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
  10.586 +			IntermediateDirectory="$(ConfigurationName)"
  10.587 +			ConfigurationType="2"
  10.588 +			CharacterSet="2"
  10.589 +			WholeProgramOptimization="1"
  10.590 +			>
  10.591 +			<Tool
  10.592 +				Name="VCPreBuildEventTool"
  10.593 +			/>
  10.594 +			<Tool
  10.595 +				Name="VCCustomBuildTool"
  10.596 +			/>
  10.597 +			<Tool
  10.598 +				Name="VCXMLDataGeneratorTool"
  10.599 +			/>
  10.600 +			<Tool
  10.601 +				Name="VCWebServiceProxyGeneratorTool"
  10.602 +			/>
  10.603 +			<Tool
  10.604 +				Name="VCMIDLTool"
  10.605 +			/>
  10.606 +			<Tool
  10.607 +				Name="VCCLCompilerTool"
  10.608 +				FavorSizeOrSpeed="1"
  10.609 +				AdditionalIncludeDirectories="..;..\sdk;..\..;..\..\sourcepawn;&quot;$(HL2SDK)\public&quot;;&quot;$(HL2SDK)\public\dlls&quot;;&quot;$(HL2SDK)\public\engine&quot;;&quot;$(HL2SDK)\public\tier0&quot;;&quot;$(HL2SDK)\public\tier1&quot;;&quot;$(SOURCEMM16)&quot;;&quot;$(SOURCEMM16)\sourcemm&quot;;&quot;$(SOURCEMM16)\sourcehook&quot;"
  10.610 +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD"
  10.611 +				RuntimeLibrary="0"
  10.612 +				EnableEnhancedInstructionSet="1"
  10.613 +				RuntimeTypeInfo="false"
  10.614 +				UsePrecompiledHeader="0"
  10.615 +				WarningLevel="3"
  10.616 +				Detect64BitPortabilityProblems="false"
  10.617 +				DebugInformationFormat="3"
  10.618 +			/>
  10.619 +			<Tool
  10.620 +				Name="VCManagedResourceCompilerTool"
  10.621 +			/>
  10.622 +			<Tool
  10.623 +				Name="VCResourceCompilerTool"
  10.624 +			/>
  10.625 +			<Tool
  10.626 +				Name="VCPreLinkEventTool"
  10.627 +			/>
  10.628 +			<Tool
  10.629 +				Name="VCLinkerTool"
  10.630 +				AdditionalDependencies="&quot;$(HL2SDK)\lib\public\tier0.lib&quot; &quot;$(HL2SDK)\lib\public\tier1.lib&quot; &quot;$(HL2SDK)\lib\public\vstdlib.lib&quot;"
  10.631 +				OutputFile="$(OutDir)\sample.ext.dll"
  10.632 +				LinkIncremental="1"
  10.633 +				IgnoreDefaultLibraryNames="LIBC;LIBCD;LIBCMTD"
  10.634 +				GenerateDebugInformation="true"
  10.635 +				SubSystem="2"
  10.636 +				OptimizeReferences="2"
  10.637 +				EnableCOMDATFolding="2"
  10.638 +				RandomizedBaseAddress="1"
  10.639 +				DataExecutionPrevention="0"
  10.640 +				TargetMachine="1"
  10.641 +			/>
  10.642 +			<Tool
  10.643 +				Name="VCALinkTool"
  10.644 +			/>
  10.645 +			<Tool
  10.646 +				Name="VCManifestTool"
  10.647 +			/>
  10.648 +			<Tool
  10.649 +				Name="VCXDCMakeTool"
  10.650 +			/>
  10.651 +			<Tool
  10.652 +				Name="VCBscMakeTool"
  10.653 +			/>
  10.654 +			<Tool
  10.655 +				Name="VCFxCopTool"
  10.656 +			/>
  10.657 +			<Tool
  10.658 +				Name="VCAppVerifierTool"
  10.659 +			/>
  10.660 +			<Tool
  10.661 +				Name="VCPostBuildEventTool"
  10.662 +			/>
  10.663 +		</Configuration>
  10.664 +	</Configurations>
  10.665 +	<References>
  10.666 +	</References>
  10.667 +	<Files>
  10.668 +		<Filter
  10.669 +			Name="Source Files"
  10.670 +			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
  10.671 +			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
  10.672 +			>
  10.673 +			<File
  10.674 +				RelativePath="..\extension.cpp"
  10.675 +				>
  10.676 +			</File>
  10.677 +		</Filter>
  10.678 +		<Filter
  10.679 +			Name="Header Files"
  10.680 +			Filter="h;hpp;hxx;hm;inl;inc;xsd"
  10.681 +			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
  10.682 +			>
  10.683 +			<File
  10.684 +				RelativePath="..\extension.h"
  10.685 +				>
  10.686 +			</File>
  10.687 +		</Filter>
  10.688 +		<Filter
  10.689 +			Name="Resource Files"
  10.690 +			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
  10.691 +			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
  10.692 +			>
  10.693 +		</Filter>
  10.694 +		<Filter
  10.695 +			Name="SourceMod SDK"
  10.696 +			UniqueIdentifier="{31958233-BB2D-4e41-A8F9-CE8A4684F436}"
  10.697 +			>
  10.698 +			<File
  10.699 +				RelativePath="..\sdk\smsdk_config.h"
  10.700 +				>
  10.701 +			</File>
  10.702 +			<File
  10.703 +				RelativePath="..\sdk\smsdk_ext.cpp"
  10.704 +				>
  10.705 +			</File>
  10.706 +			<File
  10.707 +				RelativePath="..\sdk\smsdk_ext.h"
  10.708 +				>
  10.709 +			</File>
  10.710 +		</Filter>
  10.711 +		<Filter
  10.712 +			Name="CDetour"
  10.713 +			>
  10.714 +			<File
  10.715 +				RelativePath="..\CDetour\detourhelpers.h"
  10.716 +				>
  10.717 +			</File>
  10.718 +			<File
  10.719 +				RelativePath="..\CDetour\detours.cpp"
  10.720 +				>
  10.721 +			</File>
  10.722 +			<File
  10.723 +				RelativePath="..\CDetour\detours.h"
  10.724 +				>
  10.725 +			</File>
  10.726 +		</Filter>
  10.727 +		<Filter
  10.728 +			Name="asm"
  10.729 +			>
  10.730 +			<File
  10.731 +				RelativePath="..\asm\asm.c"
  10.732 +				>
  10.733 +			</File>
  10.734 +			<File
  10.735 +				RelativePath="..\asm\asm.h"
  10.736 +				>
  10.737 +			</File>
  10.738 +		</Filter>
  10.739 +	</Files>
  10.740 +	<Globals>
  10.741 +	</Globals>
  10.742 +</VisualStudioProject>
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/runteamlogic.txt	Fri Feb 20 15:24:04 2009 +1300
    11.3 @@ -0,0 +1,21 @@
    11.4 +"Games"
    11.5 +{
    11.6 +	"#default"
    11.7 +	{
    11.8 +		"Signatures"
    11.9 +		{
   11.10 +			"RunTeamLogic"
   11.11 +			{
   11.12 +				"library"		"server"
   11.13 +				"linux"			"@_ZN12CTFGameRules18Arena_RunTeamLogicEv"
   11.14 +				"windows"		"\x83\xEC\x18\x56\x8B\xF1\x8B\x06\x8B\x90\x74\x02\x00\x00"
   11.15 +			}
   11.16 +			"PlayerByIndex"
   11.17 +			{
   11.18 +				"library"		"server"
   11.19 +				"linux"			"@_Z18UTIL_PlayerByIndexi"
   11.20 +				"windows"		"\x8B\x44\x24\x04\x56\x33\xF6\x85\xC0\x7E\x3B"
   11.21 +			}
   11.22 +		}
   11.23 +	}
   11.24 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/sdk/smsdk_config.h	Fri Feb 20 15:24:04 2009 +1300
    12.3 @@ -0,0 +1,80 @@
    12.4 +/**
    12.5 + * vim: set ts=4 :
    12.6 + * =============================================================================
    12.7 + * SourceMod Sample Extension
    12.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
    12.9 + * =============================================================================
   12.10 + *
   12.11 + * This program is free software; you can redistribute it and/or modify it under
   12.12 + * the terms of the GNU General Public License, version 3.0, as published by the
   12.13 + * Free Software Foundation.
   12.14 + * 
   12.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
   12.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   12.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
   12.18 + * details.
   12.19 + *
   12.20 + * You should have received a copy of the GNU General Public License along with
   12.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
   12.22 + *
   12.23 + * As a special exception, AlliedModders LLC gives you permission to link the
   12.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
   12.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
   12.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
   12.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
   12.28 + * this exception to all derivative works.  AlliedModders LLC defines further
   12.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
   12.30 + * or <http://www.sourcemod.net/license.php>.
   12.31 + *
   12.32 + * Version: $Id: smsdk_config.h 248 2008-08-27 00:56:22Z pred $
   12.33 + */
   12.34 +
   12.35 +#ifndef _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
   12.36 +#define _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
   12.37 +
   12.38 +/**
   12.39 + * @file smsdk_config.h
   12.40 + * @brief Contains macros for configuring basic extension information.
   12.41 + */
   12.42 +
   12.43 +/* Basic information exposed publicly */
   12.44 +#define SMEXT_CONF_NAME			"Sample Extension"
   12.45 +#define SMEXT_CONF_DESCRIPTION	"Sample extension to help developers"
   12.46 +#define SMEXT_CONF_VERSION		"0.0.0.0"
   12.47 +#define SMEXT_CONF_AUTHOR		"AlliedModders"
   12.48 +#define SMEXT_CONF_URL			"http://www.sourcemod.net/"
   12.49 +#define SMEXT_CONF_LOGTAG		"SAMPLE"
   12.50 +#define SMEXT_CONF_LICENSE		"GPL"
   12.51 +#define SMEXT_CONF_DATESTRING	__DATE__
   12.52 +
   12.53 +/** 
   12.54 + * @brief Exposes plugin's main interface.
   12.55 + */
   12.56 +#define SMEXT_LINK(name) SDKExtension *g_pExtensionIface = name;
   12.57 +
   12.58 +/**
   12.59 + * @brief Sets whether or not this plugin required Metamod.
   12.60 + * NOTE: Uncomment to enable, comment to disable.
   12.61 + */
   12.62 +#define SMEXT_CONF_METAMOD		
   12.63 +
   12.64 +/** Enable interfaces you want to use here by uncommenting lines */
   12.65 +//#define SMEXT_ENABLE_FORWARDSYS
   12.66 +//#define SMEXT_ENABLE_HANDLESYS
   12.67 +//#define SMEXT_ENABLE_PLAYERHELPERS
   12.68 +//#define SMEXT_ENABLE_DBMANAGER
   12.69 +#define SMEXT_ENABLE_GAMECONF
   12.70 +//#define SMEXT_ENABLE_MEMUTILS
   12.71 +//#define SMEXT_ENABLE_GAMEHELPERS
   12.72 +//#define SMEXT_ENABLE_TIMERSYS
   12.73 +//#define SMEXT_ENABLE_THREADER
   12.74 +//#define SMEXT_ENABLE_LIBSYS
   12.75 +//#define SMEXT_ENABLE_MENUS
   12.76 +//#define SMEXT_ENABLE_ADTFACTORY
   12.77 +//#define SMEXT_ENABLE_PLUGINSYS
   12.78 +//#define SMEXT_ENABLE_ADMINSYS
   12.79 +//#define SMEXT_ENABLE_TEXTPARSERS
   12.80 +//#define SMEXT_ENABLE_USERMSGS
   12.81 +//#define SMEXT_ENABLE_TRANSLATOR
   12.82 +
   12.83 +#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/sdk/smsdk_ext.cpp	Fri Feb 20 15:24:04 2009 +1300
    13.3 @@ -0,0 +1,461 @@
    13.4 +/**
    13.5 + * vim: set ts=4 :
    13.6 + * =============================================================================
    13.7 + * SourceMod Base Extension Code
    13.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
    13.9 + * =============================================================================
   13.10 + *
   13.11 + * This program is free software; you can redistribute it and/or modify it under
   13.12 + * the terms of the GNU General Public License, version 3.0, as published by the
   13.13 + * Free Software Foundation.
   13.14 + * 
   13.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
   13.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
   13.18 + * details.
   13.19 + *
   13.20 + * You should have received a copy of the GNU General Public License along with
   13.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
   13.22 + *
   13.23 + * As a special exception, AlliedModders LLC gives you permission to link the
   13.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
   13.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
   13.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
   13.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
   13.28 + * this exception to all derivative works.  AlliedModders LLC defines further
   13.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
   13.30 + * or <http://www.sourcemod.net/license.php>.
   13.31 + *
   13.32 + * Version: $Id: smsdk_ext.cpp 248 2008-08-27 00:56:22Z pred $
   13.33 + */
   13.34 +
   13.35 +#include <stdio.h>
   13.36 +#include <malloc.h>
   13.37 +#include "smsdk_ext.h"
   13.38 +
   13.39 +/**
   13.40 + * @file smsdk_ext.cpp
   13.41 + * @brief Contains wrappers for making Extensions easier to write.
   13.42 + */
   13.43 +
   13.44 +IExtension *myself = NULL;				/**< Ourself */
   13.45 +IShareSys *g_pShareSys = NULL;			/**< Share system */
   13.46 +IShareSys *sharesys = NULL;				/**< Share system */
   13.47 +ISourceMod *g_pSM = NULL;				/**< SourceMod helpers */
   13.48 +ISourceMod *smutils = NULL;				/**< SourceMod helpers */
   13.49 +
   13.50 +#if defined SMEXT_ENABLE_FORWARDSYS
   13.51 +IForwardManager *g_pForwards = NULL;	/**< Forward system */
   13.52 +IForwardManager *forwards = NULL;		/**< Forward system */
   13.53 +#endif
   13.54 +#if defined SMEXT_ENABLE_HANDLESYS
   13.55 +IHandleSys *g_pHandleSys = NULL;		/**< Handle system */
   13.56 +IHandleSys *handlesys = NULL;			/**< Handle system */
   13.57 +#endif
   13.58 +#if defined SMEXT_ENABLE_PLAYERHELPERS
   13.59 +IPlayerManager *playerhelpers = NULL;	/**< Player helpers */
   13.60 +#endif //SMEXT_ENABLE_PLAYERHELPERS
   13.61 +#if defined SMEXT_ENABLE_DBMANAGER
   13.62 +IDBManager *dbi = NULL;					/**< DB Manager */
   13.63 +#endif //SMEXT_ENABLE_DBMANAGER
   13.64 +#if defined SMEXT_ENABLE_GAMECONF
   13.65 +IGameConfigManager *gameconfs = NULL;	/**< Game config manager */
   13.66 +#endif //SMEXT_ENABLE_DBMANAGER
   13.67 +#if defined SMEXT_ENABLE_MEMUTILS
   13.68 +IMemoryUtils *memutils = NULL;
   13.69 +#endif //SMEXT_ENABLE_DBMANAGER
   13.70 +#if defined SMEXT_ENABLE_GAMEHELPERS
   13.71 +IGameHelpers *gamehelpers = NULL;
   13.72 +#endif
   13.73 +#if defined SMEXT_ENABLE_TIMERSYS
   13.74 +ITimerSystem *timersys = NULL;
   13.75 +#endif
   13.76 +#if defined SMEXT_ENABLE_ADTFACTORY
   13.77 +IADTFactory *adtfactory = NULL;
   13.78 +#endif
   13.79 +#if defined SMEXT_ENABLE_THREADER
   13.80 +IThreader *threader = NULL;
   13.81 +#endif
   13.82 +#if defined SMEXT_ENABLE_LIBSYS
   13.83 +ILibrarySys *libsys = NULL;
   13.84 +#endif
   13.85 +#if defined SMEXT_ENABLE_PLUGINSYS
   13.86 +SourceMod::IPluginManager *plsys;
   13.87 +#endif
   13.88 +#if defined SMEXT_ENABLE_MENUS
   13.89 +IMenuManager *menus = NULL;
   13.90 +#endif
   13.91 +#if defined SMEXT_ENABLE_ADMINSYS
   13.92 +IAdminSystem *adminsys = NULL;
   13.93 +#endif
   13.94 +#if defined SMEXT_ENABLE_TEXTPARSERS
   13.95 +ITextParsers *textparsers = NULL;
   13.96 +#endif
   13.97 +#if defined SMEXT_ENABLE_USERMSGS
   13.98 +IUserMessages *usermsgs = NULL;
   13.99 +#endif
  13.100 +#if defined SMEXT_ENABLE_TRANSLATOR
  13.101 +ITranslator *translator = NULL;
  13.102 +#endif
  13.103 +
  13.104 +/** Exports the main interface */
  13.105 +PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI()
  13.106 +{
  13.107 +	return g_pExtensionIface;
  13.108 +}
  13.109 +
  13.110 +SDKExtension::SDKExtension()
  13.111 +{
  13.112 +#if defined SMEXT_CONF_METAMOD
  13.113 +	m_SourceMMLoaded = false;
  13.114 +	m_WeAreUnloaded = false;
  13.115 +	m_WeGotPauseChange = false;
  13.116 +#endif
  13.117 +}
  13.118 +
  13.119 +bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late)
  13.120 +{
  13.121 +	g_pShareSys = sharesys = sys;
  13.122 +	myself = me;
  13.123 +
  13.124 +#if defined SMEXT_CONF_METAMOD
  13.125 +	m_WeAreUnloaded = true;
  13.126 +
  13.127 +	if (!m_SourceMMLoaded)
  13.128 +	{
  13.129 +		if (error)
  13.130 +		{
  13.131 +			snprintf(error, maxlength, "Metamod attach failed");
  13.132 +		}
  13.133 +		return false;
  13.134 +	}
  13.135 +#endif
  13.136 +	SM_GET_IFACE(SOURCEMOD, g_pSM);
  13.137 +	smutils = g_pSM;
  13.138 +#if defined SMEXT_ENABLE_HANDLESYS
  13.139 +	SM_GET_IFACE(HANDLESYSTEM, g_pHandleSys);
  13.140 +	handlesys = g_pHandleSys;
  13.141 +#endif
  13.142 +#if defined SMEXT_ENABLE_FORWARDSYS
  13.143 +	SM_GET_IFACE(FORWARDMANAGER, g_pForwards);
  13.144 +	forwards = g_pForwards;
  13.145 +#endif
  13.146 +#if defined SMEXT_ENABLE_PLAYERHELPERS
  13.147 +	SM_GET_IFACE(PLAYERMANAGER, playerhelpers);
  13.148 +#endif
  13.149 +#if defined SMEXT_ENABLE_DBMANAGER
  13.150 +	SM_GET_IFACE(DBI, dbi);
  13.151 +#endif
  13.152 +#if defined SMEXT_ENABLE_GAMECONF
  13.153 +	SM_GET_IFACE(GAMECONFIG, gameconfs);
  13.154 +#endif
  13.155 +#if defined SMEXT_ENABLE_MEMUTILS
  13.156 +	SM_GET_IFACE(MEMORYUTILS, memutils);
  13.157 +#endif
  13.158 +#if defined SMEXT_ENABLE_GAMEHELPERS
  13.159 +	SM_GET_IFACE(GAMEHELPERS, gamehelpers);
  13.160 +#endif
  13.161 +#if defined SMEXT_ENABLE_TIMERSYS
  13.162 +	SM_GET_IFACE(TIMERSYS, timersys);
  13.163 +#endif
  13.164 +#if defined SMEXT_ENABLE_ADTFACTORY
  13.165 +	SM_GET_IFACE(ADTFACTORY, adtfactory);
  13.166 +#endif
  13.167 +#if defined SMEXT_ENABLE_THREADER
  13.168 +	SM_GET_IFACE(THREADER, threader);
  13.169 +#endif
  13.170 +#if defined SMEXT_ENABLE_LIBSYS
  13.171 +	SM_GET_IFACE(LIBRARYSYS, libsys);
  13.172 +#endif
  13.173 +#if defined SMEXT_ENABLE_PLUGINSYS
  13.174 +	SM_GET_IFACE(PLUGINSYSTEM, plsys);
  13.175 +#endif
  13.176 +#if defined SMEXT_ENABLE_MENUS
  13.177 +	SM_GET_IFACE(MENUMANAGER, menus);
  13.178 +#endif
  13.179 +#if defined SMEXT_ENABLE_ADMINSYS
  13.180 +	SM_GET_IFACE(ADMINSYS, adminsys);
  13.181 +#endif
  13.182 +#if defined SMEXT_ENABLE_TEXTPARSERS
  13.183 +	SM_GET_IFACE(TEXTPARSERS, textparsers);
  13.184 +#endif
  13.185 +#if defined SMEXT_ENABLE_USERMSGS
  13.186 +	SM_GET_IFACE(USERMSGS, usermsgs);
  13.187 +#endif
  13.188 +#if defined SMEXT_ENABLE_TRANSLATOR
  13.189 +	SM_GET_IFACE(TRANSLATOR, translator);
  13.190 +#endif
  13.191 +
  13.192 +	if (SDK_OnLoad(error, maxlength, late))
  13.193 +	{
  13.194 +#if defined SMEXT_CONF_METAMOD
  13.195 +		m_WeAreUnloaded = true;
  13.196 +#endif
  13.197 +		return true;
  13.198 +	}
  13.199 +
  13.200 +	return false;
  13.201 +}
  13.202 +
  13.203 +bool SDKExtension::IsMetamodExtension()
  13.204 +{
  13.205 +#if defined SMEXT_CONF_METAMOD
  13.206 +	return true;
  13.207 +#else
  13.208 +	return false;
  13.209 +#endif
  13.210 +}
  13.211 +
  13.212 +void SDKExtension::OnExtensionPauseChange(bool state)
  13.213 +{
  13.214 +#if defined SMEXT_CONF_METAMOD
  13.215 +	m_WeGotPauseChange = true;
  13.216 +#endif
  13.217 +	SDK_OnPauseChange(state);
  13.218 +}
  13.219 +
  13.220 +void SDKExtension::OnExtensionsAllLoaded()
  13.221 +{
  13.222 +	SDK_OnAllLoaded();
  13.223 +}
  13.224 +
  13.225 +void SDKExtension::OnExtensionUnload()
  13.226 +{
  13.227 +#if defined SMEXT_CONF_METAMOD
  13.228 +	m_WeAreUnloaded = true;
  13.229 +#endif
  13.230 +	SDK_OnUnload();
  13.231 +}
  13.232 +
  13.233 +const char *SDKExtension::GetExtensionAuthor()
  13.234 +{
  13.235 +	return SMEXT_CONF_AUTHOR;
  13.236 +}
  13.237 +
  13.238 +const char *SDKExtension::GetExtensionDateString()
  13.239 +{
  13.240 +	return SMEXT_CONF_DATESTRING;
  13.241 +}
  13.242 +
  13.243 +const char *SDKExtension::GetExtensionDescription()
  13.244 +{
  13.245 +	return SMEXT_CONF_DESCRIPTION;
  13.246 +}
  13.247 +
  13.248 +const char *SDKExtension::GetExtensionVerString()
  13.249 +{
  13.250 +	return SMEXT_CONF_VERSION;
  13.251 +}
  13.252 +
  13.253 +const char *SDKExtension::GetExtensionName()
  13.254 +{
  13.255 +	return SMEXT_CONF_NAME;
  13.256 +}
  13.257 +
  13.258 +const char *SDKExtension::GetExtensionTag()
  13.259 +{
  13.260 +	return SMEXT_CONF_LOGTAG;
  13.261 +}
  13.262 +
  13.263 +const char *SDKExtension::GetExtensionURL()
  13.264 +{
  13.265 +	return SMEXT_CONF_URL;
  13.266 +}
  13.267 +
  13.268 +bool SDKExtension::SDK_OnLoad(char *error, size_t maxlength, bool late)
  13.269 +{
  13.270 +	return true;
  13.271 +}
  13.272 +
  13.273 +void SDKExtension::SDK_OnUnload()
  13.274 +{
  13.275 +}
  13.276 +
  13.277 +void SDKExtension::SDK_OnPauseChange(bool paused)
  13.278 +{
  13.279 +}
  13.280 +
  13.281 +void SDKExtension::SDK_OnAllLoaded()
  13.282 +{
  13.283 +}
  13.284 +
  13.285 +#if defined SMEXT_CONF_METAMOD
  13.286 +
  13.287 +PluginId g_PLID = 0;						/**< Metamod plugin ID */
  13.288 +ISmmPlugin *g_PLAPI = NULL;					/**< Metamod plugin API */
  13.289 +SourceHook::ISourceHook *g_SHPtr = NULL;	/**< SourceHook pointer */
  13.290 +ISmmAPI *g_SMAPI = NULL;					/**< SourceMM API pointer */
  13.291 +
  13.292 +IVEngineServer *engine = NULL;				/**< IVEngineServer pointer */
  13.293 +IServerGameDLL *gamedll = NULL;				/**< IServerGameDLL pointer */
  13.294 +
  13.295 +/** Exposes the extension to Metamod */
  13.296 +SMM_API void *PL_EXPOSURE(const char *name, int *code)
  13.297 +{
  13.298 +#if defined METAMOD_PLAPI_VERSION
  13.299 +	if (name && !strcmp(name, METAMOD_PLAPI_NAME))
  13.300 +#else
  13.301 +	if (name && !strcmp(name, PLAPI_NAME))
  13.302 +#endif
  13.303 +	{
  13.304 +		if (code)
  13.305 +		{
  13.306 +			*code = IFACE_OK;
  13.307 +		}
  13.308 +		return static_cast<void *>(g_pExtensionIface);
  13.309 +	}
  13.310 +
  13.311 +	if (code)
  13.312 +	{
  13.313 +		*code = IFACE_FAILED;
  13.314 +	}
  13.315 +
  13.316 +	return NULL;
  13.317 +}
  13.318 +
  13.319 +bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
  13.320 +{
  13.321 +	PLUGIN_SAVEVARS();
  13.322 +
  13.323 +#if !defined METAMOD_PLAPI_VERSION
  13.324 +	GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
  13.325 +	GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
  13.326 +#else
  13.327 +	GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
  13.328 +	GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
  13.329 +#endif
  13.330 +
  13.331 +	m_SourceMMLoaded = true;
  13.332 +
  13.333 +	return SDK_OnMetamodLoad(ismm, error, maxlen, late);
  13.334 +}
  13.335 +
  13.336 +bool SDKExtension::Unload(char *error, size_t maxlen)
  13.337 +{
  13.338 +	if (!m_WeAreUnloaded)
  13.339 +	{
  13.340 +		if (error)
  13.341 +		{
  13.342 +			snprintf(error, maxlen, "This extension must be unloaded by SourceMod.");
  13.343 +		}
  13.344 +		return false;
  13.345 +	}
  13.346 +
  13.347 +	return SDK_OnMetamodUnload(error, maxlen);
  13.348 +}
  13.349 +
  13.350 +bool SDKExtension::Pause(char *error, size_t maxlen)
  13.351 +{
  13.352 +	if (!m_WeGotPauseChange)
  13.353 +	{
  13.354 +		if (error)
  13.355 +		{
  13.356 +			snprintf(error, maxlen, "This extension must be paused by SourceMod.");
  13.357 +		}
  13.358 +		return false;
  13.359 +	}
  13.360 +
  13.361 +	m_WeGotPauseChange = false;
  13.362 +
  13.363 +	return SDK_OnMetamodPauseChange(true, error, maxlen);
  13.364 +}
  13.365 +
  13.366 +bool SDKExtension::Unpause(char *error, size_t maxlen)
  13.367 +{
  13.368 +	if (!m_WeGotPauseChange)
  13.369 +	{
  13.370 +		if (error)
  13.371 +		{
  13.372 +			snprintf(error, maxlen, "This extension must be unpaused by SourceMod.");
  13.373 +		}
  13.374 +		return false;
  13.375 +	}
  13.376 +
  13.377 +	m_WeGotPauseChange = false;
  13.378 +
  13.379 +	return SDK_OnMetamodPauseChange(false, error, maxlen);
  13.380 +}
  13.381 +
  13.382 +const char *SDKExtension::GetAuthor()
  13.383 +{
  13.384 +	return GetExtensionAuthor();
  13.385 +}
  13.386 +
  13.387 +const char *SDKExtension::GetDate()
  13.388 +{
  13.389 +	return GetExtensionDateString();
  13.390 +}
  13.391 +
  13.392 +const char *SDKExtension::GetDescription()
  13.393 +{
  13.394 +	return GetExtensionDescription();
  13.395 +}
  13.396 +
  13.397 +const char *SDKExtension::GetLicense()
  13.398 +{
  13.399 +	return SMEXT_CONF_LICENSE;
  13.400 +}
  13.401 +
  13.402 +const char *SDKExtension::GetLogTag()
  13.403 +{
  13.404 +	return GetExtensionTag();
  13.405 +}
  13.406 +
  13.407 +const char *SDKExtension::GetName()
  13.408 +{
  13.409 +	return GetExtensionName();
  13.410 +}
  13.411 +
  13.412 +const char *SDKExtension::GetURL()
  13.413 +{
  13.414 +	return GetExtensionURL();
  13.415 +}
  13.416 +
  13.417 +const char *SDKExtension::GetVersion()
  13.418 +{
  13.419 +	return GetExtensionVerString();
  13.420 +}
  13.421 +
  13.422 +bool SDKExtension::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late)
  13.423 +{
  13.424 +	return true;
  13.425 +}
  13.426 +
  13.427 +bool SDKExtension::SDK_OnMetamodUnload(char *error, size_t maxlength)
  13.428 +{
  13.429 +	return true;
  13.430 +}
  13.431 +
  13.432 +bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength)
  13.433 +{
  13.434 +	return true;
  13.435 +}
  13.436 +
  13.437 +#endif
  13.438 +
  13.439 +/* Overload a few things to prevent libstdc++ linking */
  13.440 +#if defined __linux__
  13.441 +extern "C" void __cxa_pure_virtual(void)
  13.442 +{
  13.443 +}
  13.444 +
  13.445 +void *operator new(size_t size)
  13.446 +{
  13.447 +	return malloc(size);
  13.448 +}
  13.449 +
  13.450 +void *operator new[](size_t size) 
  13.451 +{
  13.452 +	return malloc(size);
  13.453 +}
  13.454 +
  13.455 +void operator delete(void *ptr) 
  13.456 +{
  13.457 +	free(ptr);
  13.458 +}
  13.459 +
  13.460 +void operator delete[](void * ptr)
  13.461 +{
  13.462 +	free(ptr);
  13.463 +}
  13.464 +#endif
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/sdk/smsdk_ext.h	Fri Feb 20 15:24:04 2009 +1300
    14.3 @@ -0,0 +1,333 @@
    14.4 +/**
    14.5 + * vim: set ts=4 :
    14.6 + * =============================================================================
    14.7 + * SourceMod Base Extension Code
    14.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
    14.9 + * =============================================================================
   14.10 + *
   14.11 + * This program is free software; you can redistribute it and/or modify it under
   14.12 + * the terms of the GNU General Public License, version 3.0, as published by the
   14.13 + * Free Software Foundation.
   14.14 + * 
   14.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
   14.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   14.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
   14.18 + * details.
   14.19 + *
   14.20 + * You should have received a copy of the GNU General Public License along with
   14.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
   14.22 + *
   14.23 + * As a special exception, AlliedModders LLC gives you permission to link the
   14.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
   14.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
   14.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
   14.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
   14.28 + * this exception to all derivative works.  AlliedModders LLC defines further
   14.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
   14.30 + * or <http://www.sourcemod.net/license.php>.
   14.31 + *
   14.32 + * Version: $Id: smsdk_ext.h 248 2008-08-27 00:56:22Z pred $
   14.33 + */
   14.34 +
   14.35 +#ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
   14.36 +#define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
   14.37 +
   14.38 +/**
   14.39 + * @file smsdk_ext.h
   14.40 + * @brief Contains wrappers for making Extensions easier to write.
   14.41 + */
   14.42 +
   14.43 +#include "smsdk_config.h"
   14.44 +#include <IExtensionSys.h>
   14.45 +#include <IHandleSys.h>
   14.46 +#include <sp_vm_api.h>
   14.47 +#include <sm_platform.h>
   14.48 +#include <ISourceMod.h>
   14.49 +#if defined SMEXT_ENABLE_FORWARDSYS
   14.50 +#include <IForwardSys.h>
   14.51 +#endif //SMEXT_ENABLE_FORWARDSYS
   14.52 +#if defined SMEXT_ENABLE_PLAYERHELPERS
   14.53 +#include <IPlayerHelpers.h>
   14.54 +#endif //SMEXT_ENABLE_PlAYERHELPERS
   14.55 +#if defined SMEXT_ENABLE_DBMANAGER
   14.56 +#include <IDBDriver.h>
   14.57 +#endif //SMEXT_ENABLE_DBMANAGER
   14.58 +#if defined SMEXT_ENABLE_GAMECONF
   14.59 +#include <IGameConfigs.h>
   14.60 +#endif
   14.61 +#if defined SMEXT_ENABLE_MEMUTILS
   14.62 +#include <IMemoryUtils.h>
   14.63 +#endif
   14.64 +#if defined SMEXT_ENABLE_GAMEHELPERS
   14.65 +#include <IGameHelpers.h>
   14.66 +#endif
   14.67 +#if defined SMEXT_ENABLE_TIMERSYS
   14.68 +#include <ITimerSystem.h>
   14.69 +#endif
   14.70 +#if defined SMEXT_ENABLE_ADTFACTORY
   14.71 +#include <IADTFactory.h>
   14.72 +#endif
   14.73 +#if defined SMEXT_ENABLE_THREADER
   14.74 +#include <IThreader.h>
   14.75 +#endif
   14.76 +#if defined SMEXT_ENABLE_LIBSYS
   14.77 +#include <ILibrarySys.h>
   14.78 +#endif
   14.79 +#if defined SMEXT_ENABLE_PLUGINSYS
   14.80 +#include <IPluginSys.h>
   14.81 +#endif
   14.82 +#if defined SMEXT_ENABLE_MENUS
   14.83 +#include <IMenuManager.h>
   14.84 +#endif
   14.85 +#if defined SMEXT_ENABLE_ADMINSYS
   14.86 +#include <IAdminSystem.h>
   14.87 +#endif
   14.88 +#if defined SMEXT_ENABLE_TEXTPARSERS
   14.89 +#include <ITextParsers.h>
   14.90 +#endif
   14.91 +#if defined SMEXT_ENABLE_USERMSGS
   14.92 +#include <IUserMessages.h>
   14.93 +#endif
   14.94 +#if defined SMEXT_ENABLE_TRANSLATOR
   14.95 +#include <ITranslator.h>
   14.96 +#endif
   14.97 +
   14.98 +#if defined SMEXT_CONF_METAMOD
   14.99 +#include <ISmmPlugin.h>
  14.100 +#include <eiface.h>
  14.101 +#endif
  14.102 +
  14.103 +using namespace SourceMod;
  14.104 +using namespace SourcePawn;
  14.105 +
  14.106 +class SDKExtension : 
  14.107 +#if defined SMEXT_CONF_METAMOD
  14.108 +	public ISmmPlugin,
  14.109 +#endif
  14.110 +	public IExtensionInterface
  14.111 +{
  14.112 +public:
  14.113 +	/** Constructor */
  14.114 +	SDKExtension();
  14.115 +public:
  14.116 +	/**
  14.117 +	 * @brief This is called after the initial loading sequence has been processed.
  14.118 +	 *
  14.119 +	 * @param error		Error message buffer.
  14.120 +	 * @param maxlength	Size of error message buffer.
  14.121 +	 * @param late		Whether or not the module was loaded after map load.
  14.122 +	 * @return			True to succeed loading, false to fail.
  14.123 +	 */
  14.124 +	virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
  14.125 +	
  14.126 +	/**
  14.127 +	 * @brief This is called right before the extension is unloaded.
  14.128 +	 */
  14.129 +	virtual void SDK_OnUnload();
  14.130 +
  14.131 +	/**
  14.132 +	 * @brief This is called once all known extensions have been loaded.
  14.133 +	 */
  14.134 +	virtual void SDK_OnAllLoaded();
  14.135 +
  14.136 +	/**
  14.137 +	 * @brief Called when the pause state is changed.
  14.138 +	 */
  14.139 +	virtual void SDK_OnPauseChange(bool paused);
  14.140 +
  14.141 +#if defined SMEXT_CONF_METAMOD
  14.142 +	/**
  14.143 +	 * @brief Called when Metamod is attached, before the extension version is called.
  14.144 +	 *
  14.145 +	 * @param error			Error buffer.
  14.146 +	 * @param maxlength		Maximum size of error buffer.
  14.147 +	 * @param late			Whether or not Metamod considers this a late load.
  14.148 +	 * @return				True to succeed, false to fail.
  14.149 +	 */
  14.150 +	virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
  14.151 +
  14.152 +	/**
  14.153 +	 * @brief Called when Metamod is detaching, after the extension version is called.
  14.154 +	 * NOTE: By default this is blocked unless sent from SourceMod.
  14.155 +	 *
  14.156 +	 * @param error			Error buffer.
  14.157 +	 * @param maxlength		Maximum size of error buffer.
  14.158 +	 * @return				True to succeed, false to fail.
  14.159 +	 */
  14.160 +	virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
  14.161 +
  14.162 +	/**
  14.163 +	 * @brief Called when Metamod's pause state is changing.
  14.164 +	 * NOTE: By default this is blocked unless sent from SourceMod.
  14.165 +	 *
  14.166 +	 * @param paused		Pause state being set.
  14.167 +	 * @param error			Error buffer.
  14.168 +	 * @param maxlength		Maximum size of error buffer.
  14.169 +	 * @return				True to succeed, false to fail.
  14.170 +	 */
  14.171 +	virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
  14.172 +#endif
  14.173 +
  14.174 +public: //IExtensionInterface
  14.175 +	virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
  14.176 +	virtual void OnExtensionUnload();
  14.177 +	virtual void OnExtensionsAllLoaded();
  14.178 +
  14.179 +	/** Returns whether or not this is a Metamod-based extension */
  14.180 +	virtual bool IsMetamodExtension();
  14.181 +
  14.182 +	/**
  14.183 +	 * @brief Called when the pause state changes.
  14.184 +	 * 
  14.185 +	 * @param state			True if being paused, false if being unpaused.
  14.186 +	 */
  14.187 +	virtual void OnExtensionPauseChange(bool state);
  14.188 +
  14.189 +	/** Returns name */
  14.190 +	virtual const char *GetExtensionName();
  14.191 +	/** Returns URL */
  14.192 +	virtual const char *GetExtensionURL();
  14.193 +	/** Returns log tag */
  14.194 +	virtual const char *GetExtensionTag();
  14.195 +	/** Returns author */
  14.196 +	virtual const char *GetExtensionAuthor();
  14.197 +	/** Returns version string */
  14.198 +	virtual const char *GetExtensionVerString();
  14.199 +	/** Returns description string */
  14.200 +	virtual const char *GetExtensionDescription();
  14.201 +	/** Returns date string */
  14.202 +	virtual const char *GetExtensionDateString();
  14.203 +#if defined SMEXT_CONF_METAMOD
  14.204 +public: //ISmmPlugin
  14.205 +	/** Called when the extension is attached to Metamod. */
  14.206 +	virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
  14.207 +	/** Returns the author to MM */
  14.208 +	virtual const char *GetAuthor();
  14.209 +	/** Returns the name to MM */
  14.210 +	virtual const char *GetName();
  14.211 +	/** Returns the description to MM */
  14.212 +	virtual const char *GetDescription();
  14.213 +	/** Returns the URL to MM */
  14.214 +	virtual const char *GetURL();
  14.215 +	/** Returns the license to MM */
  14.216 +	virtual const char *GetLicense();
  14.217 +	/** Returns the version string to MM */
  14.218 +	virtual const char *GetVersion();
  14.219 +	/** Returns the date string to MM */
  14.220 +	virtual const char *GetDate();
  14.221 +	/** Returns the logtag to MM */
  14.222 +	virtual const char *GetLogTag();
  14.223 +	/** Called on unload */
  14.224 +	virtual bool Unload(char *error, size_t maxlength);
  14.225 +	/** Called on pause */
  14.226 +	virtual bool Pause(char *error, size_t maxlength);
  14.227 +	/** Called on unpause */
  14.228 +	virtual bool Unpause(char *error, size_t maxlength);
  14.229 +private:
  14.230 +	bool m_SourceMMLoaded;
  14.231 +	bool m_WeAreUnloaded;
  14.232 +	bool m_WeGotPauseChange;
  14.233 +#endif
  14.234 +};
  14.235 +
  14.236 +extern SDKExtension *g_pExtensionIface;
  14.237 +extern IExtension *myself;
  14.238 +
  14.239 +extern IShareSys *g_pShareSys;
  14.240 +extern IShareSys *sharesys;				/* Note: Newer name */
  14.241 +extern ISourceMod *g_pSM;
  14.242 +extern ISourceMod *smutils;				/* Note: Newer name */
  14.243 +
  14.244 +/* Optional interfaces are below */
  14.245 +#if defined SMEXT_ENABLE_FORWARDSYS
  14.246 +extern IForwardManager *g_pForwards;
  14.247 +extern IForwardManager *forwards;		/* Note: Newer name */
  14.248 +#endif //SMEXT_ENABLE_FORWARDSYS
  14.249 +#if defined SMEXT_ENABLE_HANDLESYS
  14.250 +extern IHandleSys *g_pHandleSys;
  14.251 +extern IHandleSys *handlesys;			/* Note: Newer name */
  14.252 +#endif //SMEXT_ENABLE_HANDLESYS
  14.253 +#if defined SMEXT_ENABLE_PLAYERHELPERS
  14.254 +extern IPlayerManager *playerhelpers;
  14.255 +#endif //SMEXT_ENABLE_PLAYERHELPERS
  14.256 +#if defined SMEXT_ENABLE_DBMANAGER
  14.257 +extern IDBManager *dbi;
  14.258 +#endif //SMEXT_ENABLE_DBMANAGER
  14.259 +#if defined SMEXT_ENABLE_GAMECONF
  14.260 +extern IGameConfigManager *gameconfs;
  14.261 +#endif //SMEXT_ENABLE_DBMANAGER
  14.262 +#if defined SMEXT_ENABLE_MEMUTILS
  14.263 +extern IMemoryUtils *memutils;
  14.264 +#endif
  14.265 +#if defined SMEXT_ENABLE_GAMEHELPERS
  14.266 +extern IGameHelpers *gamehelpers;
  14.267 +#endif
  14.268 +#if defined SMEXT_ENABLE_TIMERSYS
  14.269 +extern ITimerSystem *timersys;
  14.270 +#endif
  14.271 +#if defined SMEXT_ENABLE_ADTFACTORY
  14.272 +extern IADTFactory *adtfactory;
  14.273 +#endif
  14.274 +#if defined SMEXT_ENABLE_THREADER
  14.275 +extern IThreader *threader;
  14.276 +#endif
  14.277 +#if defined SMEXT_ENABLE_LIBSYS
  14.278 +extern ILibrarySys *libsys;
  14.279 +#endif
  14.280 +#if defined SMEXT_ENABLE_PLUGINSYS
  14.281 +extern SourceMod::IPluginManager *plsys;
  14.282 +#endif
  14.283 +#if defined SMEXT_ENABLE_MENUS
  14.284 +extern IMenuManager *menus;
  14.285 +#endif
  14.286 +#if defined SMEXT_ENABLE_ADMINSYS
  14.287 +extern IAdminSystem *adminsys;
  14.288 +#endif
  14.289 +#if defined SMEXT_ENABLE_USERMSGS
  14.290 +extern IUserMessages *usermsgs;
  14.291 +#endif
  14.292 +#if defined SMEXT_ENABLE_TRANSLATOR
  14.293 +extern ITranslator *translator;
  14.294 +#endif
  14.295 +
  14.296 +#if defined SMEXT_CONF_METAMOD
  14.297 +PLUGIN_GLOBALVARS();
  14.298 +extern IVEngineServer *engine;
  14.299 +extern IServerGameDLL *gamedll;
  14.300 +#endif
  14.301 +
  14.302 +/** Creates a SourceMod interface macro pair */
  14.303 +#define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
  14.304 +/** Automates retrieving SourceMod interfaces */
  14.305 +#define SM_GET_IFACE(prefix, addr) \
  14.306 +	if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
  14.307 +	{ \
  14.308 +		if (error != NULL && maxlength) \
  14.309 +		{ \
  14.310 +			size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
  14.311 +			if (len >= maxlength) \
  14.312 +			{ \
  14.313 +				error[maxlength - 1] = '\0'; \
  14.314 +			} \
  14.315 +		} \
  14.316 +		return false; \
  14.317 +	}
  14.318 +/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
  14.319 +#define SM_GET_LATE_IFACE(prefix, addr) \
  14.320 +	g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
  14.321 +/** Validates a SourceMod interface pointer */
  14.322 +#define SM_CHECK_IFACE(prefix, addr) \
  14.323 +	if (!addr) \
  14.324 +	{ \
  14.325 +		if (error != NULL && maxlength) \
  14.326 +		{ \
  14.327 +			size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
  14.328 +			if (len >= maxlength) \
  14.329 +			{ \
  14.330 +				error[maxlength - 1] = '\0'; \
  14.331 +			} \
  14.332 +		} \
  14.333 +		return false; \
  14.334 +	}
  14.335 +
  14.336 +#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_