diff --git a/extension/AMBuilder b/extension/AMBuilder index d3526b7..b446f75 100644 --- a/extension/AMBuilder +++ b/extension/AMBuilder @@ -37,7 +37,6 @@ def BuildExtension(): compiler = SM.DefaultCompiler() compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'extension')) - compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'extension', 'sdk')) compiler['CXXINCLUDES'].append(os.path.join(AMBuild.cache['SOURCEMOD15'], 'public')) compiler['CXXINCLUDES'].append(os.path.join(AMBuild.cache['SOURCEMOD15'], 'public', 'extensions')) @@ -56,9 +55,10 @@ def BuildExtension(): binary.AddSourceFiles('extension', [ 'extension.cpp', 'MemoryDownloader.cpp', - 'sdk/smsdk_ext.cpp' ]) + binary.AddSourceFiles(AMBuild.cache['SOURCEMOD15'], ['public/smsdk_ext.cpp']) + if AMBuild.target['platform'] in ['linux']: link = os.path.join(AMBuild.outputFolder, extension.workFolder, 'libbreakpad_client.a') target = os.path.join(AMBuild.outputFolder, 'breakpad', 'src', 'client', 'linux', 'libbreakpad_client.a') diff --git a/extension/extension.cpp b/extension/extension.cpp index f5ef477..9277ef1 100644 --- a/extension/extension.cpp +++ b/extension/extension.cpp @@ -48,7 +48,9 @@ GetSpew_t GetSpew; char spewBuffer[65536]; // Hi. -char buffer[512]; +char dumpStoragePath[512]; +char logPath[512]; + google_breakpad::ExceptionHandler *handler = NULL; struct PluginInfo { @@ -91,10 +93,10 @@ static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, return succeeded; } - my_strlcpy(buffer, descriptor.path(), sizeof(buffer)); - my_strlcat(buffer, ".txt", sizeof(buffer)); + my_strlcpy(dumpStoragePath, descriptor.path(), sizeof(dumpStoragePath)); + my_strlcat(dumpStoragePath, ".txt", sizeof(dumpStoragePath)); - int extra = sys_open(buffer, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); + int extra = sys_open(dumpStoragePath, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (extra == -1) { sys_write(STDOUT_FILENO, "Failed to open metadata file!\n", 30); return succeeded; @@ -234,9 +236,9 @@ static bool dumpCallback(const wchar_t* dump_path, printf("Wrote minidump to: %ls\\%ls.dmp\n", dump_path, minidump_id); - sprintf(buffer, "%ls\\%ls.txt", dump_path, minidump_id); + sprintf(dumpStoragePath, "%ls\\%ls.txt", dump_path, minidump_id); - FILE *extra = fopen(buffer, L"wb"); + FILE *extra = fopen(dumpStoragePath, L"wb"); if (!extra) { printf("Failed to open metadata file!\n"); return succeeded; @@ -255,7 +257,7 @@ static bool dumpCallback(const wchar_t* dump_path, #error Bad platform. #endif -void UploadCrashDump(const char *path) +bool UploadAndDeleteCrashDump(const char *path, char *response, int maxlen) { IWebForm *form = webternet->CreateForm(); @@ -266,8 +268,7 @@ void UploadCrashDump(const char *path) form->AddFile("upload_file_minidump", path); char metapath[512]; - strcpy(metapath, path); - strcat(metapath, ".txt"); + g_pSM->Format(metapath, sizeof(metapath), "%s.txt", path); if (libsys->PathExists(metapath)) { form->AddFile("upload_file_metadata", metapath); } @@ -276,76 +277,85 @@ void UploadCrashDump(const char *path) IWebTransfer *xfer = webternet->CreateSession(); xfer->SetFailOnHTTPError(true); - printf(">>> UPLOADING %s\n", path); - - if (!xfer->PostAndDownload("http://crash.limetech.org/submit", form, &data, NULL)) - { - printf(">>> UPLOAD FAILED: %s (%d)\n", xfer->LastErrorMessage(), xfer->LastErrorCode()); - } else { - printf(">>> UPLOADED CRASH DUMP"); - printf("%s", data.GetBuffer()); + bool uploaded = xfer->PostAndDownload("http://crash.limetech.org/submit", form, &data, NULL); + + if (response) { + if (uploaded) { + g_pSM->Format(response, maxlen, "%s", data.GetBuffer()); + } else { + g_pSM->Format(response, maxlen, "%s (%d)", xfer->LastErrorMessage(), xfer->LastErrorCode()); + } } if (libsys->PathExists(metapath)) { unlink(metapath); } + + unlink(path); + + return uploaded; } -class UploadThread: public IThread { -void RunThread(IThreadHandle *pHandle) +class UploadThread: public IThread { - printf("Upload thread started.\n"); + void RunThread(IThreadHandle *pHandle) { + rootconsole->ConsolePrint("Accelerator upload thread started."); - IDirectory *dumps = libsys->OpenDirectory(buffer); + FILE *log = fopen(logPath, "a"); + if (!log) { + g_pSM->LogError(myself, "Failed to open Accelerator log file: %s", logPath); + } - char path[512]; - int count = 0; + IDirectory *dumps = libsys->OpenDirectory(dumpStoragePath); + + int count = 0; + int failed = 0; + char path[512]; + char response[512]; + + while (dumps->MoreFiles()) { + if (!dumps->IsEntryFile()) { + dumps->NextEntry(); + continue; + } + + const char *name = dumps->GetEntryName(); + + int namelen = strlen(name); + if (namelen < 4 || strcmp(&name[namelen-4], ".dmp") != 0) { + dumps->NextEntry(); + continue; + } + + g_pSM->Format(path, sizeof(path), "%s/%s", dumpStoragePath, name); + bool uploaded = UploadAndDeleteCrashDump(path, response, sizeof(response)); + + if (uploaded) { + count++; + g_pSM->LogError(myself, "Accelerator uploaded crash dump: %s", response); + if (log) fprintf(log, "Uploaded crash dump: %s\n", response); + } else { + failed++; + g_pSM->LogError(myself, "Accelerator failed to upload crash dump: %s", response); + if (log) fprintf(log, "Failed to upload crash dump: %s\n", response); + } - while (dumps->MoreFiles()) - { - if (!dumps->IsEntryFile()) - { dumps->NextEntry(); - continue; } - const char *name = dumps->GetEntryName(); - int namelen = strlen(name); + libsys->CloseDirectory(dumps); - if (namelen < 4 || strcmp(&name[namelen-4], ".dmp") != 0) { - dumps->NextEntry(); - continue; + if (log) { + fclose(log); } - g_pSM->Format(path, sizeof(path), "%s/%s", buffer, name); - UploadCrashDump(path); - - int err = 0; -#if defined _LINUX - err = unlink(path); -#elif defined _WINDOWS - err = _unlink(path); -#else -#error Bad platform. -#endif - if (err != 0) { - printf(">>> FAILED TO DELETE CRASH DUMP!!!\n"); - } - - count++; - dumps->NextEntry(); + rootconsole->ConsolePrint("Accelerator upload thread finished. (%d uploaded, %d failed)", count, failed); } - libsys->CloseDirectory(dumps); - - if (count > 0) { - printf(">>> UPLOADED %d CRASH DUMPS\n", count); + void OnTerminate(IThreadHandle *pHandle, bool cancel) { + rootconsole->ConsolePrint("Accelerator upload thread terminated. (canceled = %s)", (cancel ? "true" : "false")); } -} -void OnTerminate(IThreadHandle *pHandle, bool cancel) { - printf("Upload thread terminated. (%s)\n", (cancel ? "true" : "false")); -} } uploadThread; bool Accelerator::SDK_OnLoad(char *error, size_t maxlength, bool late) @@ -353,18 +363,20 @@ bool Accelerator::SDK_OnLoad(char *error, size_t maxlength, bool late) sharesys->AddDependency(myself, "webternet.ext", true, true); SM_GET_IFACE(WEBTERNET, webternet); - g_pSM->BuildPath(Path_SM, buffer, sizeof(buffer), "data/dumps"); + g_pSM->BuildPath(Path_SM, dumpStoragePath, sizeof(dumpStoragePath), "data/dumps"); - if (!libsys->IsPathDirectory(buffer)) + if (!libsys->IsPathDirectory(dumpStoragePath)) { - if (!libsys->CreateFolder(buffer)) + if (!libsys->CreateFolder(dumpStoragePath)) { if (error) - g_pSM->Format(error, maxlength, "%s didn't exist and we couldn't create it :(", buffer); + g_pSM->Format(error, maxlength, "%s didn't exist and we couldn't create it :(", dumpStoragePath); return false; } } + g_pSM->BuildPath(Path_SM, logPath, sizeof(logPath), "logs/accelerator.log"); + threader->MakeThread(&uploadThread); if (!gameconfs->LoadGameConfigFile("accelerator.games", &gameconfig, error, maxlength)) { @@ -378,7 +390,7 @@ bool Accelerator::SDK_OnLoad(char *error, size_t maxlength, bool late) } #if defined _LINUX - google_breakpad::MinidumpDescriptor descriptor(buffer); + google_breakpad::MinidumpDescriptor descriptor(dumpStoragePath); handler = new google_breakpad::ExceptionHandler(descriptor, NULL, dumpCallback, NULL, true, -1); struct sigaction oact; @@ -387,8 +399,8 @@ bool Accelerator::SDK_OnLoad(char *error, size_t maxlength, bool late) g_pSM->AddGameFrameHook(OnGameFrame); #elif defined _WINDOWS - wchar_t *buf = new wchar_t[sizeof(buffer)]; - size_t num_chars = mbstowcs(buf, buffer, sizeof(buffer)); + wchar_t *buf = new wchar_t[sizeof(dumpStoragePath)]; + size_t num_chars = mbstowcs(buf, dumpStoragePath, sizeof(dumpStoragePath)); handler = new google_breakpad::ExceptionHandler(std::wstring(buf, num_chars), NULL, dumpCallback, NULL, google_breakpad::ExceptionHandler::HANDLER_ALL); diff --git a/extension/extension.h b/extension/extension.h index 4cf0946..97e989c 100644 --- a/extension/extension.h +++ b/extension/extension.h @@ -26,7 +26,7 @@ * @brief Accelerator extension code header. */ -#include "smsdk_ext.hpp" +#include "smsdk_ext.h" /** * @brief Sample implementation of the SDK Extension. diff --git a/extension/sdk/smsdk_ext.cpp b/extension/sdk/smsdk_ext.cpp deleted file mode 100644 index 23cccb2..0000000 --- a/extension/sdk/smsdk_ext.cpp +++ /dev/null @@ -1,465 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod Base Extension Code - * Copyright (C) 2004-2008 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$ - */ - -#include -#include -#include "smsdk_ext.hpp" - -/** - * @file smsdk_ext.cpp - * @brief Contains wrappers for making Extensions easier to write. - */ - -IExtension *myself = NULL; /**< Ourself */ -IShareSys *g_pShareSys = NULL; /**< Share system */ -IShareSys *sharesys = NULL; /**< Share system */ -ISourceMod *g_pSM = NULL; /**< SourceMod helpers */ -ISourceMod *smutils = NULL; /**< SourceMod helpers */ - -#if defined SMEXT_ENABLE_FORWARDSYS -IForwardManager *g_pForwards = NULL; /**< Forward system */ -IForwardManager *forwards = NULL; /**< Forward system */ -#endif -#if defined SMEXT_ENABLE_HANDLESYS -IHandleSys *g_pHandleSys = NULL; /**< Handle system */ -IHandleSys *handlesys = NULL; /**< Handle system */ -#endif -#if defined SMEXT_ENABLE_PLAYERHELPERS -IPlayerManager *playerhelpers = NULL; /**< Player helpers */ -#endif //SMEXT_ENABLE_PLAYERHELPERS -#if defined SMEXT_ENABLE_DBMANAGER -IDBManager *dbi = NULL; /**< DB Manager */ -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_GAMECONF -IGameConfigManager *gameconfs = NULL; /**< Game config manager */ -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_MEMUTILS -IMemoryUtils *memutils = NULL; -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_GAMEHELPERS -IGameHelpers *gamehelpers = NULL; -#endif -#if defined SMEXT_ENABLE_TIMERSYS -ITimerSystem *timersys = NULL; -#endif -#if defined SMEXT_ENABLE_ADTFACTORY -IADTFactory *adtfactory = NULL; -#endif -#if defined SMEXT_ENABLE_THREADER -IThreader *threader = NULL; -#endif -#if defined SMEXT_ENABLE_LIBSYS -ILibrarySys *libsys = NULL; -#endif -#if defined SMEXT_ENABLE_PLUGINSYS -SourceMod::IPluginManager *plsys; -#endif -#if defined SMEXT_ENABLE_MENUS -IMenuManager *menus = NULL; -#endif -#if defined SMEXT_ENABLE_ADMINSYS -IAdminSystem *adminsys = NULL; -#endif -#if defined SMEXT_ENABLE_TEXTPARSERS -ITextParsers *textparsers = NULL; -#endif -#if defined SMEXT_ENABLE_USERMSGS -IUserMessages *usermsgs = NULL; -#endif -#if defined SMEXT_ENABLE_TRANSLATOR -ITranslator *translator = NULL; -#endif -#if defined SMEXT_ENABLE_NINVOKE -INativeInterface *ninvoke = NULL; -#endif - -/** Exports the main interface */ -PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() -{ - return g_pExtensionIface; -} - -SDKExtension::SDKExtension() -{ -#if defined SMEXT_CONF_METAMOD - m_SourceMMLoaded = false; - m_WeAreUnloaded = false; - m_WeGotPauseChange = false; -#endif -} - -bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late) -{ - g_pShareSys = sharesys = sys; - myself = me; - -#if defined SMEXT_CONF_METAMOD - m_WeAreUnloaded = true; - - if (!m_SourceMMLoaded) - { - if (error) - { - snprintf(error, maxlength, "Metamod attach failed"); - } - return false; - } -#endif - SM_GET_IFACE(SOURCEMOD, g_pSM); - smutils = g_pSM; -#if defined SMEXT_ENABLE_HANDLESYS - SM_GET_IFACE(HANDLESYSTEM, g_pHandleSys); - handlesys = g_pHandleSys; -#endif -#if defined SMEXT_ENABLE_FORWARDSYS - SM_GET_IFACE(FORWARDMANAGER, g_pForwards); - forwards = g_pForwards; -#endif -#if defined SMEXT_ENABLE_PLAYERHELPERS - SM_GET_IFACE(PLAYERMANAGER, playerhelpers); -#endif -#if defined SMEXT_ENABLE_DBMANAGER - SM_GET_IFACE(DBI, dbi); -#endif -#if defined SMEXT_ENABLE_GAMECONF - SM_GET_IFACE(GAMECONFIG, gameconfs); -#endif -#if defined SMEXT_ENABLE_MEMUTILS - SM_GET_IFACE(MEMORYUTILS, memutils); -#endif -#if defined SMEXT_ENABLE_GAMEHELPERS - SM_GET_IFACE(GAMEHELPERS, gamehelpers); -#endif -#if defined SMEXT_ENABLE_TIMERSYS - SM_GET_IFACE(TIMERSYS, timersys); -#endif -#if defined SMEXT_ENABLE_ADTFACTORY - SM_GET_IFACE(ADTFACTORY, adtfactory); -#endif -#if defined SMEXT_ENABLE_THREADER - SM_GET_IFACE(THREADER, threader); -#endif -#if defined SMEXT_ENABLE_LIBSYS - SM_GET_IFACE(LIBRARYSYS, libsys); -#endif -#if defined SMEXT_ENABLE_PLUGINSYS - SM_GET_IFACE(PLUGINSYSTEM, plsys); -#endif -#if defined SMEXT_ENABLE_MENUS - SM_GET_IFACE(MENUMANAGER, menus); -#endif -#if defined SMEXT_ENABLE_ADMINSYS - SM_GET_IFACE(ADMINSYS, adminsys); -#endif -#if defined SMEXT_ENABLE_TEXTPARSERS - SM_GET_IFACE(TEXTPARSERS, textparsers); -#endif -#if defined SMEXT_ENABLE_USERMSGS - SM_GET_IFACE(USERMSGS, usermsgs); -#endif -#if defined SMEXT_ENABLE_TRANSLATOR - SM_GET_IFACE(TRANSLATOR, translator); -#endif - - if (SDK_OnLoad(error, maxlength, late)) - { -#if defined SMEXT_CONF_METAMOD - m_WeAreUnloaded = true; -#endif - return true; - } - - return false; -} - -bool SDKExtension::IsMetamodExtension() -{ -#if defined SMEXT_CONF_METAMOD - return true; -#else - return false; -#endif -} - -void SDKExtension::OnExtensionPauseChange(bool state) -{ -#if defined SMEXT_CONF_METAMOD - m_WeGotPauseChange = true; -#endif - SDK_OnPauseChange(state); -} - -void SDKExtension::OnExtensionsAllLoaded() -{ - SDK_OnAllLoaded(); -} - -void SDKExtension::OnExtensionUnload() -{ -#if defined SMEXT_CONF_METAMOD - m_WeAreUnloaded = true; -#endif - SDK_OnUnload(); -} - -const char *SDKExtension::GetExtensionAuthor() -{ - return SMEXT_CONF_AUTHOR; -} - -const char *SDKExtension::GetExtensionDateString() -{ - return SMEXT_CONF_DATESTRING; -} - -const char *SDKExtension::GetExtensionDescription() -{ - return SMEXT_CONF_DESCRIPTION; -} - -const char *SDKExtension::GetExtensionVerString() -{ - return SMEXT_CONF_VERSION; -} - -const char *SDKExtension::GetExtensionName() -{ - return SMEXT_CONF_NAME; -} - -const char *SDKExtension::GetExtensionTag() -{ - return SMEXT_CONF_LOGTAG; -} - -const char *SDKExtension::GetExtensionURL() -{ - return SMEXT_CONF_URL; -} - -bool SDKExtension::SDK_OnLoad(char *error, size_t maxlength, bool late) -{ - return true; -} - -void SDKExtension::SDK_OnUnload() -{ -} - -void SDKExtension::SDK_OnPauseChange(bool paused) -{ -} - -void SDKExtension::SDK_OnAllLoaded() -{ -} - -#if defined SMEXT_CONF_METAMOD - -PluginId g_PLID = 0; /**< Metamod plugin ID */ -ISmmPlugin *g_PLAPI = NULL; /**< Metamod plugin API */ -SourceHook::ISourceHook *g_SHPtr = NULL; /**< SourceHook pointer */ -ISmmAPI *g_SMAPI = NULL; /**< SourceMM API pointer */ - -IVEngineServer *engine = NULL; /**< IVEngineServer pointer */ -IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ - -/** Exposes the extension to Metamod */ -SMM_API void *PL_EXPOSURE(const char *name, int *code) -{ -#if defined METAMOD_PLAPI_VERSION - if (name && !strcmp(name, METAMOD_PLAPI_NAME)) -#else - if (name && !strcmp(name, PLAPI_NAME)) -#endif - { - if (code) - { - *code = IFACE_OK; - } - return static_cast(g_pExtensionIface); - } - - if (code) - { - *code = IFACE_FAILED; - } - - return NULL; -} - -bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) -{ - PLUGIN_SAVEVARS(); - -#if !defined METAMOD_PLAPI_VERSION - GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); - GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); -#else - GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); - GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); -#endif - - m_SourceMMLoaded = true; - - return SDK_OnMetamodLoad(ismm, error, maxlen, late); -} - -bool SDKExtension::Unload(char *error, size_t maxlen) -{ - if (!m_WeAreUnloaded) - { - if (error) - { - snprintf(error, maxlen, "This extension must be unloaded by SourceMod."); - } - return false; - } - - return SDK_OnMetamodUnload(error, maxlen); -} - -bool SDKExtension::Pause(char *error, size_t maxlen) -{ - if (!m_WeGotPauseChange) - { - if (error) - { - snprintf(error, maxlen, "This extension must be paused by SourceMod."); - } - return false; - } - - m_WeGotPauseChange = false; - - return SDK_OnMetamodPauseChange(true, error, maxlen); -} - -bool SDKExtension::Unpause(char *error, size_t maxlen) -{ - if (!m_WeGotPauseChange) - { - if (error) - { - snprintf(error, maxlen, "This extension must be unpaused by SourceMod."); - } - return false; - } - - m_WeGotPauseChange = false; - - return SDK_OnMetamodPauseChange(false, error, maxlen); -} - -const char *SDKExtension::GetAuthor() -{ - return GetExtensionAuthor(); -} - -const char *SDKExtension::GetDate() -{ - return GetExtensionDateString(); -} - -const char *SDKExtension::GetDescription() -{ - return GetExtensionDescription(); -} - -const char *SDKExtension::GetLicense() -{ - return SMEXT_CONF_LICENSE; -} - -const char *SDKExtension::GetLogTag() -{ - return GetExtensionTag(); -} - -const char *SDKExtension::GetName() -{ - return GetExtensionName(); -} - -const char *SDKExtension::GetURL() -{ - return GetExtensionURL(); -} - -const char *SDKExtension::GetVersion() -{ - return GetExtensionVerString(); -} - -bool SDKExtension::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late) -{ - return true; -} - -bool SDKExtension::SDK_OnMetamodUnload(char *error, size_t maxlength) -{ - return true; -} - -bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength) -{ - return true; -} - -#endif - -/* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ || defined __APPLE__ -extern "C" void __cxa_pure_virtual(void) -{ -} - -void *operator new(size_t size) -{ - return malloc(size); -} - -void *operator new[](size_t size) -{ - return malloc(size); -} - -void operator delete(void *ptr) -{ - free(ptr); -} - -void operator delete[](void * ptr) -{ - free(ptr); -} -#endif - diff --git a/extension/sdk/smsdk_ext.hpp b/extension/sdk/smsdk_ext.hpp deleted file mode 100644 index a3de9b3..0000000 --- a/extension/sdk/smsdk_ext.hpp +++ /dev/null @@ -1,339 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod Base Extension Code - * Copyright (C) 2004-2008 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_SOURCEMOD_EXTENSION_BASESDK_H_ -#define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ - -/** - * @file smsdk_ext.hpp - * @brief Contains wrappers for making Extensions easier to write. - */ - -#include "smsdk_config.hpp" -#include -#include -#include -#include -#include -#if defined SMEXT_ENABLE_FORWARDSYS -#include -#endif //SMEXT_ENABLE_FORWARDSYS -#if defined SMEXT_ENABLE_PLAYERHELPERS -#include -#endif //SMEXT_ENABLE_PlAYERHELPERS -#if defined SMEXT_ENABLE_DBMANAGER -#include -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_GAMECONF -#include -#endif -#if defined SMEXT_ENABLE_MEMUTILS -#include -#endif -#if defined SMEXT_ENABLE_GAMEHELPERS -#include -#endif -#if defined SMEXT_ENABLE_TIMERSYS -#include -#endif -#if defined SMEXT_ENABLE_ADTFACTORY -#include -#endif -#if defined SMEXT_ENABLE_THREADER -#include -#endif -#if defined SMEXT_ENABLE_LIBSYS -#include -#endif -#if defined SMEXT_ENABLE_PLUGINSYS -#include -#endif -#if defined SMEXT_ENABLE_MENUS -#include -#endif -#if defined SMEXT_ENABLE_ADMINSYS -#include -#endif -#if defined SMEXT_ENABLE_TEXTPARSERS -#include -#endif -#if defined SMEXT_ENABLE_USERMSGS -#include -#endif -#if defined SMEXT_ENABLE_TRANSLATOR -#include -#endif -#if defined SMEXT_ENABLE_NINVOKE -#include -#endif - -#if defined SMEXT_CONF_METAMOD -#include -#include -#endif - -using namespace SourceMod; -using namespace SourcePawn; - -class SDKExtension : -#if defined SMEXT_CONF_METAMOD - public ISmmPlugin, -#endif - public IExtensionInterface -{ -public: - /** Constructor */ - SDKExtension(); -public: - /** - * @brief This is called after the initial loading sequence has been processed. - * - * @param error Error message buffer. - * @param maxlength Size of error message buffer. - * @param late Whether or not the module was loaded after map load. - * @return True to succeed loading, false to fail. - */ - virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late); - - /** - * @brief This is called right before the extension is unloaded. - */ - virtual void SDK_OnUnload(); - - /** - * @brief This is called once all known extensions have been loaded. - */ - virtual void SDK_OnAllLoaded(); - - /** - * @brief Called when the pause state is changed. - */ - virtual void SDK_OnPauseChange(bool paused); - -#if defined SMEXT_CONF_METAMOD - /** - * @brief Called when Metamod is attached, before the extension version is called. - * - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @param late Whether or not Metamod considers this a late load. - * @return True to succeed, false to fail. - */ - virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late); - - /** - * @brief Called when Metamod is detaching, after the extension version is called. - * NOTE: By default this is blocked unless sent from SourceMod. - * - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @return True to succeed, false to fail. - */ - virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength); - - /** - * @brief Called when Metamod's pause state is changing. - * NOTE: By default this is blocked unless sent from SourceMod. - * - * @param paused Pause state being set. - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @return True to succeed, false to fail. - */ - virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength); -#endif - -public: //IExtensionInterface - virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late); - virtual void OnExtensionUnload(); - virtual void OnExtensionsAllLoaded(); - - /** Returns whether or not this is a Metamod-based extension */ - virtual bool IsMetamodExtension(); - - /** - * @brief Called when the pause state changes. - * - * @param state True if being paused, false if being unpaused. - */ - virtual void OnExtensionPauseChange(bool state); - - /** Returns name */ - virtual const char *GetExtensionName(); - /** Returns URL */ - virtual const char *GetExtensionURL(); - /** Returns log tag */ - virtual const char *GetExtensionTag(); - /** Returns author */ - virtual const char *GetExtensionAuthor(); - /** Returns version string */ - virtual const char *GetExtensionVerString(); - /** Returns description string */ - virtual const char *GetExtensionDescription(); - /** Returns date string */ - virtual const char *GetExtensionDateString(); -#if defined SMEXT_CONF_METAMOD -public: //ISmmPlugin - /** Called when the extension is attached to Metamod. */ - virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late); - /** Returns the author to MM */ - virtual const char *GetAuthor(); - /** Returns the name to MM */ - virtual const char *GetName(); - /** Returns the description to MM */ - virtual const char *GetDescription(); - /** Returns the URL to MM */ - virtual const char *GetURL(); - /** Returns the license to MM */ - virtual const char *GetLicense(); - /** Returns the version string to MM */ - virtual const char *GetVersion(); - /** Returns the date string to MM */ - virtual const char *GetDate(); - /** Returns the logtag to MM */ - virtual const char *GetLogTag(); - /** Called on unload */ - virtual bool Unload(char *error, size_t maxlength); - /** Called on pause */ - virtual bool Pause(char *error, size_t maxlength); - /** Called on unpause */ - virtual bool Unpause(char *error, size_t maxlength); -private: - bool m_SourceMMLoaded; - bool m_WeAreUnloaded; - bool m_WeGotPauseChange; -#endif -}; - -extern SDKExtension *g_pExtensionIface; -extern IExtension *myself; - -extern IShareSys *g_pShareSys; -extern IShareSys *sharesys; /* Note: Newer name */ -extern ISourceMod *g_pSM; -extern ISourceMod *smutils; /* Note: Newer name */ - -/* Optional interfaces are below */ -#if defined SMEXT_ENABLE_FORWARDSYS -extern IForwardManager *g_pForwards; -extern IForwardManager *forwards; /* Note: Newer name */ -#endif //SMEXT_ENABLE_FORWARDSYS -#if defined SMEXT_ENABLE_HANDLESYS -extern IHandleSys *g_pHandleSys; -extern IHandleSys *handlesys; /* Note: Newer name */ -#endif //SMEXT_ENABLE_HANDLESYS -#if defined SMEXT_ENABLE_PLAYERHELPERS -extern IPlayerManager *playerhelpers; -#endif //SMEXT_ENABLE_PLAYERHELPERS -#if defined SMEXT_ENABLE_DBMANAGER -extern IDBManager *dbi; -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_GAMECONF -extern IGameConfigManager *gameconfs; -#endif //SMEXT_ENABLE_DBMANAGER -#if defined SMEXT_ENABLE_MEMUTILS -extern IMemoryUtils *memutils; -#endif -#if defined SMEXT_ENABLE_GAMEHELPERS -extern IGameHelpers *gamehelpers; -#endif -#if defined SMEXT_ENABLE_TIMERSYS -extern ITimerSystem *timersys; -#endif -#if defined SMEXT_ENABLE_ADTFACTORY -extern IADTFactory *adtfactory; -#endif -#if defined SMEXT_ENABLE_THREADER -extern IThreader *threader; -#endif -#if defined SMEXT_ENABLE_LIBSYS -extern ILibrarySys *libsys; -#endif -#if defined SMEXT_ENABLE_PLUGINSYS -extern SourceMod::IPluginManager *plsys; -#endif -#if defined SMEXT_ENABLE_MENUS -extern IMenuManager *menus; -#endif -#if defined SMEXT_ENABLE_ADMINSYS -extern IAdminSystem *adminsys; -#endif -#if defined SMEXT_ENABLE_USERMSGS -extern IUserMessages *usermsgs; -#endif -#if defined SMEXT_ENABLE_TRANSLATOR -extern ITranslator *translator; -#endif -#if defined SMEXT_ENABLE_NINVOKE -extern INativeInterface *ninvoke; -#endif - -#if defined SMEXT_CONF_METAMOD -PLUGIN_GLOBALVARS(); -extern IVEngineServer *engine; -extern IServerGameDLL *gamedll; -#endif - -/** Creates a SourceMod interface macro pair */ -#define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION -/** Automates retrieving SourceMod interfaces */ -#define SM_GET_IFACE(prefix, addr) \ - if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \ - { \ - if (error != NULL && maxlength) \ - { \ - size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ - if (len >= maxlength) \ - { \ - error[maxlength - 1] = '\0'; \ - } \ - } \ - return false; \ - } -/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */ -#define SM_GET_LATE_IFACE(prefix, addr) \ - g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr) -/** Validates a SourceMod interface pointer */ -#define SM_CHECK_IFACE(prefix, addr) \ - if (!addr) \ - { \ - if (error != NULL && maxlength) \ - { \ - size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ - if (len >= maxlength) \ - { \ - error[maxlength - 1] = '\0'; \ - } \ - } \ - return false; \ - } - -#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ diff --git a/extension/sdk/smsdk_config.hpp b/extension/smsdk_config.h similarity index 96% rename from extension/sdk/smsdk_config.hpp rename to extension/smsdk_config.h index 4b5114a..09b1faf 100644 --- a/extension/sdk/smsdk_config.hpp +++ b/extension/smsdk_config.h @@ -76,5 +76,6 @@ //#define SMEXT_ENABLE_USERMSGS //#define SMEXT_ENABLE_TRANSLATOR //#define SMEXT_ENABLE_NINVOKE +#define SMEXT_ENABLE_ROOTCONSOLEMENU #endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_