From 3bdc8583e5538b41114286d326dcbb653d0b09e4 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 7 Jan 2009 22:55:40 -0500 Subject: [PATCH] Exposed IServer through SDKTools (bug 3545, r=ds). --- extensions/sdktools/extension.cpp | 34 +++++++++++- extensions/sdktools/msvc9/sdktools.vcproj | 4 ++ public/extensions/ISDKTools.h | 67 +++++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 public/extensions/ISDKTools.h diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index 5810df49..d82b9aa2 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -38,6 +38,7 @@ #include "tempents.h" #include "vsound.h" #include "output.h" +#include #if SOURCE_ENGINE == SE_LEFT4DEAD #define SDKTOOLS_GAME_FILE "sdktools.games.l4d" @@ -73,6 +74,7 @@ SourceHook::CallClass *enginePatch = NULL; SourceHook::CallClass *enginesoundPatch = NULL; HandleType_t g_CallHandle = 0; HandleType_t g_TraceHandle = 0; +ISDKTools *g_pSDKTools; SMEXT_LINK(&g_SdkTools); @@ -84,6 +86,8 @@ extern sp_nativeinfo_t g_VoiceNatives[]; extern sp_nativeinfo_t g_EntInputNatives[]; extern sp_nativeinfo_t g_TeamNatives[]; +static void InitSDKToolsAPI(); + bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late) { HandleError err; @@ -148,6 +152,10 @@ bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late) VoiceInit(); + GetIServer(); + + InitSDKToolsAPI(); + return true; } @@ -255,7 +263,6 @@ void SDKTools::SDK_OnAllLoaded() s_TempEntHooks.Initialize(); s_SoundHooks.Initialize(); InitializeValveGlobals(); - GetIServer(); } bool SDKTools::QueryRunning(char *error, size_t maxlength) @@ -379,3 +386,28 @@ bool SDKTools::ProcessCommandTarget(cmd_target_info_t *info) return true; } + +class SDKTools_API : public ISDKTools +{ +public: + virtual const char *GetInterfaceName() + { + return SMINTERFACE_SDKTOOLS_NAME; + } + + virtual unsigned int GetInterfaceVersion() + { + return SMINTERFACE_SDKTOOLS_VERSION; + } + + virtual IServer *GetIServer() + { + return iserver; + } +} g_SDKTools_API; + +static void InitSDKToolsAPI() +{ + g_pSDKTools = &g_SDKTools_API; + sharesys->AddInterface(myself, g_pSDKTools); +} diff --git a/extensions/sdktools/msvc9/sdktools.vcproj b/extensions/sdktools/msvc9/sdktools.vcproj index 51d5e883..e75d1f26 100644 --- a/extensions/sdktools/msvc9/sdktools.vcproj +++ b/extensions/sdktools/msvc9/sdktools.vcproj @@ -763,6 +763,10 @@ RelativePath="..\extension.h" > + + diff --git a/public/extensions/ISDKTools.h b/public/extensions/ISDKTools.h new file mode 100644 index 00000000..289f41d1 --- /dev/null +++ b/public/extensions/ISDKTools.h @@ -0,0 +1,67 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod SDKTools Extension + * Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software + * by the Valve Corporation. You must obey the GNU General Public License in + * all respects for all other code used. Additionally, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ + +#ifndef _INCLUDE_SMEXT_I_SDKTOOLS_H_ +#define _INCLUDE_SMEXT_I_SDKTOOLS_H_ + +#include + +#define SMINTERFACE_SDKTOOLS_NAME "ISDKTools" +#define SMINTERFACE_SDKTOOLS_VERSION 1 + +class IServer; + +/** + * @brief SDKTools shared API + * @file ISDKTools.h + */ + +namespace SourceMod +{ + /** + * @brief SDKTools API. + */ + class ISDKTools : public SMInterface + { + public: + virtual const char *GetInterfaceName() = 0; + virtual unsigned int GetInterfaceVersion() = 0; + public: + /** + * @brief Returns a pointer to IServer if one was found. + * + * @return IServer pointer, or NULL if SDKTools was unable to find one. + */ + virtual IServer* GetIServer() = 0; + }; +} + +#endif /* _INCLUDE_SMEXT_I_SDKTOOLS_H_ */