ds@1952: /** ds@1952: * vim: set ts=4 : ds@1952: * ============================================================================= ds@1952: * SourceMod ds@1952: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. ds@1952: * ============================================================================= ds@1952: * ds@1952: * This program is free software; you can redistribute it and/or modify it under ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the ds@1952: * Free Software Foundation. ds@1952: * ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1952: * details. ds@1952: * ds@1952: * You should have received a copy of the GNU General Public License along with ds@1952: * this program. If not, see . ds@1952: * ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1952: * this exception to all derivative works. AlliedModders LLC defines further ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1952: * or . ds@1952: * ds@1952: * Version: $Id$ ds@1952: */ ds@1952: ds@1952: #include ds@1952: #include "sourcemod.h" ds@1952: #include "sourcemm_api.h" ds@1952: #include "systems/LibrarySys.h" ds@1952: #include "vm/sp_vm_engine.h" ds@1952: #include ds@1952: #include "PluginSys.h" ds@1952: #include "ShareSys.h" ds@1952: #include "CoreConfig.h" ds@1952: #include "Logger.h" ds@1952: #include "ExtensionSys.h" ds@1952: #include "AdminCache.h" ds@1952: #include "sm_stringutil.h" ds@1952: #include "PlayerManager.h" ds@1952: #include "Translator.h" ds@1952: #include "ForwardSys.h" ds@1952: #include "TimerSys.h" ds@1952: #include "GameConfigs.h" ds@1952: ds@1952: SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool); ds@1952: SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false); ds@1952: SH_DECL_HOOK1_void(IServerGameDLL, GameFrame, SH_NOATTRIB, false, bool); ds@1952: SH_DECL_HOOK1_void(IVEngineServer, ServerCommand, SH_NOATTRIB, false, const char *); ds@1952: ds@1952: SourcePawnEngine g_SourcePawn; ds@1952: SourceModBase g_SourceMod; ds@1952: ds@1952: ILibrary *g_pJIT = NULL; ds@1952: SourceHook::String g_BaseDir; ds@1952: ISourcePawnEngine *g_pSourcePawn = &g_SourcePawn; ds@1952: IVirtualMachine *g_pVM; ds@1952: IdentityToken_t *g_pCoreIdent = NULL; ds@1952: IForward *g_pOnMapEnd = NULL; ds@1952: bool g_Loaded = false; ds@1952: ds@1952: typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *); ds@1952: typedef int (*GIVEENGINEPOINTER2)(ISourcePawnEngine *, unsigned int api_version); ds@1952: typedef unsigned int (*GETEXPORTCOUNT)(); ds@1952: typedef IVirtualMachine *(*GETEXPORT)(unsigned int); ds@1952: typedef void (*NOTIFYSHUTDOWN)(); ds@1952: ds@1952: void ShutdownJIT() ds@1952: { ds@1952: NOTIFYSHUTDOWN notify = (NOTIFYSHUTDOWN)g_pJIT->GetSymbolAddress("NotifyShutdown"); ds@1952: if (notify) ds@1952: { ds@1952: notify(); ds@1952: } ds@1952: ds@1952: g_pJIT->CloseLibrary(); ds@1952: } ds@1952: ds@1952: SourceModBase::SourceModBase() ds@1952: { ds@1952: m_IsMapLoading = false; ds@1952: m_ExecPluginReload = false; ds@1952: m_GotBasePath = false; ds@1952: } ds@1952: ds@1952: ConfigResult SourceModBase::OnSourceModConfigChanged(const char *key, ds@1952: const char *value, ds@1952: ConfigSource source, ds@1952: char *error, ds@1952: size_t maxlength) ds@1952: { ds@1952: if (strcasecmp(key, "BasePath") == 0) ds@1952: { ds@1952: if (source == ConfigSource_Console) ds@1952: { ds@1952: UTIL_Format(error, maxlength, "Cannot be set at runtime"); ds@1952: return ConfigResult_Reject; ds@1952: } ds@1952: ds@1952: if (!m_GotBasePath) ds@1952: { ds@1952: g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), value); ds@1952: g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), value); ds@1952: ds@1952: m_GotBasePath = true; ds@1952: } ds@1952: ds@1952: return ConfigResult_Accept; ds@1952: } ds@1952: ds@1952: return ConfigResult_Ignore; ds@1952: } ds@1952: ds@1952: bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late) ds@1952: { ds@1952: const char *gamepath = g_SMAPI->GetBaseDir(); ds@1952: ds@1952: /* Store full path to game */ ds@1952: g_BaseDir.assign(gamepath); ds@1952: ds@1952: /* Store name of game directory by itself */ ds@1952: size_t len = strlen(gamepath); ds@1952: for (size_t i = len - 1; i >= 0; i--) ds@1952: { ds@1952: if (gamepath[i] == PLATFORM_SEP_CHAR) ds@1952: { ds@1952: strncopy(m_ModDir, &gamepath[++i], sizeof(m_ModDir)); ds@1952: break; ds@1952: } ds@1952: } ds@1952: ds@1952: /* Initialize CoreConfig so we can get SourceMod base path properly - this basically parses core.cfg */ ds@1952: g_CoreConfig.Initialize(); ds@1952: ds@1952: /* This shouldn't happen, but can't hurt to be safe */ ds@1952: if (!g_LibSys.PathExists(m_SMBaseDir) || !m_GotBasePath) ds@1952: { ds@1952: g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/addons/sourcemod", g_BaseDir.c_str()); ds@1952: g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "addons/sourcemod"); ds@1952: m_GotBasePath = true; ds@1952: } ds@1952: ds@1952: /* Attempt to load the JIT! */ ds@1952: char file[PLATFORM_MAX_PATH]; ds@1952: char myerror[255]; ds@1952: g_SMAPI->PathFormat(file, sizeof(file), "%s/bin/sourcepawn.jit.x86.%s", ds@1952: GetSourceModPath(), ds@1952: PLATFORM_LIB_EXT ds@1952: ); ds@1952: ds@1952: g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror)); ds@1952: if (!g_pJIT) ds@1952: { ds@1952: if (error && maxlength) ds@1952: { ds@1952: snprintf(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", ds@1952: myerror, ds@1952: PLATFORM_LIB_EXT); ds@1952: } ds@1952: return false; ds@1952: } ds@1952: ds@1952: int err; ds@1952: ds@1952: GIVEENGINEPOINTER2 jit_init2 = (GIVEENGINEPOINTER2)g_pJIT->GetSymbolAddress("GiveEnginePointer2"); ds@1952: if (!jit_init2) ds@1952: { ds@1952: GIVEENGINEPOINTER jit_init = (GIVEENGINEPOINTER)g_pJIT->GetSymbolAddress("GiveEnginePointer"); ds@1952: if (!jit_init) ds@1952: { ds@1952: ShutdownJIT(); ds@1952: if (error && maxlength) ds@1952: { ds@1952: snprintf(error, maxlength, "Failed to find GiveEnginePointer in JIT!"); ds@1952: } ds@1952: return false; ds@1952: } ds@1952: ds@1952: if ((err=jit_init(g_pSourcePawn)) != 0) ds@1952: { ds@1952: ShutdownJIT(); ds@1952: if (error && maxlength) ds@1952: { ds@1952: snprintf(error, maxlength, "GiveEnginePointer returned %d in the JIT", err); ds@1952: } ds@1952: return false; ds@1952: } ds@1952: } else { ds@1952: /* On version bumps, we should check for older versions as well, if the new version fails. ds@1952: * We can then check the exports to see if any VM versions will be sufficient. ds@1952: */ ds@1952: if ((err=jit_init2(g_pSourcePawn, SOURCEPAWN_ENGINE_API_VERSION)) != SP_ERROR_NONE) ds@1952: { ds@1952: ShutdownJIT(); ds@1952: if (error && maxlength) ds@1952: { ds@1952: snprintf(error, maxlength, "JIT incompatible with SourceMod version"); ds@1952: } ds@1952: return false; ds@1952: } ds@1952: } ds@1952: ds@1952: GETEXPORTCOUNT jit_getnum = (GETEXPORTCOUNT)g_pJIT->GetSymbolAddress("GetExportCount"); ds@1952: GETEXPORT jit_get = (GETEXPORT)g_pJIT->GetSymbolAddress("GetExport"); ds@1952: if (!jit_get) ds@1952: { ds@1952: ShutdownJIT(); ds@1952: if (error && maxlength) ds@1952: { ds@1952: snprintf(error, maxlength, "JIT is missing a necessary export!"); ds@1952: } ds@1952: return false; ds@1952: } ds@1952: ds@1952: unsigned int num = jit_getnum(); ds@1952: if (!num) ds@1952: { ds@1952: ShutdownJIT(); ds@1952: if (error && maxlength) ds@1952: { ds@1952: snprintf(error, maxlength, "JIT did not export any virtual machines!"); ds@1952: } ds@1952: return false; ds@1952: } ds@1952: ds@1952: unsigned int api_version; ds@1952: for (unsigned int i=0; iGetAPIVersion(); ds@1952: if (api_version < 3 || api_version > SOURCEPAWN_VM_API_VERSION) ds@1952: { ds@1952: if (error && maxlength) ds@1952: { ds@1952: snprintf(error, maxlength, "JIT is not a compatible version"); ds@1952: } ds@1952: g_pVM = NULL; ds@1952: continue; ds@1952: } ds@1952: break; ds@1952: } ds@1952: ds@1952: if (!g_pVM) ds@1952: { ds@1952: ShutdownJIT(); ds@1952: return false; ds@1952: } ds@1952: ds@1952: /* Hook this now so we can detect startup without calling StartSourceMod() */ ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false); ds@1952: ds@1952: /* Only load if we're not late */ ds@1952: if (!late) ds@1952: { ds@1952: StartSourceMod(false); ds@1952: } ds@1952: ds@1952: return true; ds@1952: } ds@1952: ds@1952: void SourceModBase::StartSourceMod(bool late) ds@1952: { ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false); ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, &g_Timers, &TimerSystem::GameFrame, false); ds@1952: ds@1952: enginePatch = SH_GET_CALLCLASS(engine); ds@1952: gamedllPatch = SH_GET_CALLCLASS(gamedll); ds@1952: ds@1952: g_ShareSys.Initialize(); ds@1952: ds@1952: /* Make the global core identity */ ds@1952: g_pCoreIdent = g_ShareSys.CreateCoreIdentity(); ds@1952: ds@1952: /* Notify! */ ds@1952: SMGlobalClass *pBase = SMGlobalClass::head; ds@1952: while (pBase) ds@1952: { ds@1952: pBase->OnSourceModStartup(false); ds@1952: pBase = pBase->m_pGlobalClassNext; ds@1952: } ds@1952: ds@1952: /* Notify! */ ds@1952: pBase = SMGlobalClass::head; ds@1952: while (pBase) ds@1952: { ds@1952: pBase->OnSourceModAllInitialized(); ds@1952: pBase = pBase->m_pGlobalClassNext; ds@1952: } ds@1952: ds@1952: /* Notify! */ ds@1952: pBase = SMGlobalClass::head; ds@1952: while (pBase) ds@1952: { ds@1952: pBase->OnSourceModAllInitialized_Post(); ds@1952: pBase = pBase->m_pGlobalClassNext; ds@1952: } ds@1952: ds@1952: /* Add us now... */ ds@1952: g_ShareSys.AddInterface(NULL, this); ds@1952: ds@1952: /* We're loaded! */ ds@1952: g_Loaded = true; ds@1952: ds@1952: /* Initialize VSP stuff */ ds@1952: if (vsp_interface != NULL) ds@1952: { ds@1952: g_SourceMod_Core.OnVSPListening(vsp_interface); ds@1952: } ds@1952: } ds@1952: ds@1952: static bool g_LevelEndBarrier = false; ds@1952: bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) ds@1952: { ds@1952: /* If we're not loaded... */ ds@1952: if (!g_Loaded) ds@1952: { ds@1952: /* Do all global initialization now */ ds@1952: StartSourceMod(true); ds@1952: } ds@1952: ds@1952: m_IsMapLoading = true; ds@1952: m_ExecPluginReload = true; ds@1952: ds@1952: /* Notify! */ ds@1952: SMGlobalClass *pBase = SMGlobalClass::head; ds@1952: while (pBase) ds@1952: { ds@1952: pBase->OnSourceModLevelChange(pMapName); ds@1952: pBase = pBase->m_pGlobalClassNext; ds@1952: } ds@1952: ds@1952: DoGlobalPluginLoads(); ds@1952: ds@1952: m_IsMapLoading = false; ds@1952: ds@1952: /* Notify! */ ds@1952: pBase = SMGlobalClass::head; ds@1952: while (pBase) ds@1952: { ds@1952: pBase->OnSourceModPluginsLoaded(); ds@1952: pBase = pBase->m_pGlobalClassNext; ds@1952: } ds@1952: ds@1952: if (!g_pOnMapEnd) ds@1952: { ds@1952: g_pOnMapEnd = g_Forwards.CreateForward("OnMapEnd", ET_Ignore, 0, NULL); ds@1952: } ds@1952: ds@1952: g_LevelEndBarrier = true; ds@1952: ds@1952: RETURN_META_VALUE(MRES_IGNORED, true); ds@1952: } ds@1952: ds@1952: void SourceModBase::LevelShutdown() ds@1952: { ds@1952: if (g_LevelEndBarrier) ds@1952: { ds@1952: SMGlobalClass *next = SMGlobalClass::head; ds@1952: while (next) ds@1952: { ds@1952: next->OnSourceModLevelEnd(); ds@1952: next = next->m_pGlobalClassNext; ds@1952: } ds@1952: ds@1952: if (g_pOnMapEnd != NULL) ds@1952: { ds@1952: g_pOnMapEnd->Execute(NULL); ds@1952: } ds@1952: ds@1952: g_Timers.RemoveMapChangeTimers(); ds@1952: ds@1952: g_LevelEndBarrier = false; ds@1952: } ds@1952: ds@1952: g_OnMapStarted = false; ds@1952: ds@1952: if (m_ExecPluginReload) ds@1952: { ds@1952: g_PluginSys.ReloadOrUnloadPlugins(); ds@1952: m_ExecPluginReload = false; ds@1952: } ds@1952: } ds@1952: ds@1952: bool SourceModBase::IsMapLoading() const ds@1952: { ds@1952: return m_IsMapLoading; ds@1952: } ds@1952: ds@1952: void SourceModBase::DoGlobalPluginLoads() ds@1952: { ds@1952: char config_path[PLATFORM_MAX_PATH]; ds@1952: char plugins_path[PLATFORM_MAX_PATH]; ds@1952: ds@1952: BuildPath(Path_SM, config_path, ds@1952: sizeof(config_path), ds@1952: "configs/plugin_settings.cfg"); ds@1952: BuildPath(Path_SM, plugins_path, ds@1952: sizeof(plugins_path), ds@1952: "plugins"); ds@1952: ds@1952: /* Load any auto extensions */ ds@1952: g_Extensions.TryAutoload(); ds@1952: ds@1952: /* Fire the extensions ready message */ ds@1952: g_SMAPI->MetaFactory(SOURCEMOD_NOTICE_EXTENSIONS, NULL, NULL); ds@1952: ds@1952: /* Load any game extension */ ds@1952: const char *game_ext; ds@1952: if ((game_ext = g_pGameConf->GetKeyValue("GameExtension")) != NULL) ds@1952: { ds@1952: char path[PLATFORM_MAX_PATH]; ds@1952: UTIL_Format(path, sizeof(path), "%s.ext." PLATFORM_LIB_EXT, game_ext); ds@1952: g_Extensions.LoadAutoExtension(path); ds@1952: } ds@1952: ds@1952: /* Run the first pass */ ds@1952: g_PluginSys.LoadAll_FirstPass(config_path, plugins_path); ds@1952: ds@1952: /* Mark any extensions as loaded */ ds@1952: g_Extensions.MarkAllLoaded(); ds@1952: ds@1952: /* No modules yet, it's safe to call this from here */ ds@1952: g_PluginSys.LoadAll_SecondPass(); ds@1952: ds@1952: /* Re-mark any extensions as loaded */ ds@1952: g_Extensions.MarkAllLoaded(); ds@1952: ds@1952: /* Call OnAllPluginsLoaded */ ds@1952: g_PluginSys.AllPluginsLoaded(); ds@1952: } ds@1952: ds@1952: size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...) ds@1952: { ds@1952: char _buffer[PLATFORM_MAX_PATH]; ds@1952: va_list ap; ds@1952: ds@1952: va_start(ap, format); ds@1952: vsnprintf(_buffer, PLATFORM_MAX_PATH, format, ap); ds@1952: va_end(ap); ds@1952: ds@1952: /* If we get a "file://" notation, strip off the file:// part so we're left ds@1952: * with an absolute path. Note that the absolute path gets returned, so ds@1952: * usage with relative paths here is completely invalid. ds@1952: */ ds@1952: if (type != Path_SM_Rel && strncmp(_buffer, "file://", 7) == 0) ds@1952: { ds@1952: return g_LibSys.PathFormat(buffer, maxlength, "%s", &_buffer[7]); ds@1952: } ds@1952: ds@1952: const char *base = NULL; ds@1952: if (type == Path_Game) ds@1952: { ds@1952: base = GetGamePath(); ds@1952: } ds@1952: else if (type == Path_SM) ds@1952: { ds@1952: base = GetSourceModPath(); ds@1952: } ds@1952: else if (type == Path_SM_Rel) ds@1952: { ds@1952: base = m_SMRelDir; ds@1952: } ds@1952: ds@1952: if (base) ds@1952: { ds@1952: return g_LibSys.PathFormat(buffer, maxlength, "%s/%s", base, _buffer); ds@1952: } ds@1952: else ds@1952: { ds@1952: return g_LibSys.PathFormat(buffer, maxlength, "%s", _buffer); ds@1952: } ds@1952: } ds@1952: ds@1952: void SourceModBase::CloseSourceMod() ds@1952: { ds@1952: /* Force a level end */ ds@1952: LevelShutdown(); ds@1952: ds@1952: /* Unload plugins */ ds@1952: g_PluginSys.Shutdown(); ds@1952: ds@1952: /* Unload extensions */ ds@1952: g_Extensions.Shutdown(); ds@1952: ds@1952: SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false); ds@1952: ds@1952: if (g_Loaded) ds@1952: { ds@1952: if (g_pOnMapEnd) ds@1952: { ds@1952: g_Forwards.ReleaseForward(g_pOnMapEnd); ds@1952: } ds@1952: ds@1952: /* Notify! */ ds@1952: SMGlobalClass *pBase = SMGlobalClass::head; ds@1952: while (pBase) ds@1952: { ds@1952: pBase->OnSourceModShutdown(); ds@1952: pBase = pBase->m_pGlobalClassNext; ds@1952: } ds@1952: ds@1952: /* Delete all data packs */ ds@1952: CStack::iterator iter; ds@1952: CDataPack *pd; ds@1952: for (iter=m_freepacks.begin(); iter!=m_freepacks.end(); iter++) ds@1952: { ds@1952: pd = (*iter); ds@1952: delete pd; ds@1952: } ds@1952: m_freepacks.popall(); ds@1952: ds@1952: /* Notify! */ ds@1952: pBase = SMGlobalClass::head; ds@1952: while (pBase) ds@1952: { ds@1952: pBase->OnSourceModAllShutdown(); ds@1952: pBase = pBase->m_pGlobalClassNext; ds@1952: } ds@1952: ds@1952: if (enginePatch) ds@1952: { ds@1952: SH_RELEASE_CALLCLASS(enginePatch); ds@1952: enginePatch = NULL; ds@1952: } ds@1952: ds@1952: if (gamedllPatch) ds@1952: { ds@1952: SH_RELEASE_CALLCLASS(gamedllPatch); ds@1952: gamedllPatch = NULL; ds@1952: } ds@1952: ds@1952: SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false); ds@1952: SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, &g_Timers, &TimerSystem::GameFrame, false); ds@1952: } ds@1952: ds@1952: /* Rest In Peace */ ds@1952: ShutdownJIT(); ds@1952: } ds@1952: ds@1952: void SourceModBase::LogMessage(IExtension *pExt, const char *format, ...) ds@1952: { ds@1952: IExtensionInterface *pAPI = pExt->GetAPI(); ds@1952: const char *tag = pAPI->GetExtensionTag(); ds@1952: char buffer[2048]; ds@1952: va_list ap; ds@1952: ds@1952: va_start(ap, format); ds@1952: vsnprintf(buffer, sizeof(buffer), format, ap); ds@1952: va_end(ap); ds@1952: ds@1952: if (tag) ds@1952: { ds@1952: g_Logger.LogMessage("[%s] %s", tag, buffer); ds@1952: } else { ds@1952: g_Logger.LogMessage("%s", buffer); ds@1952: } ds@1952: } ds@1952: ds@1952: void SourceModBase::LogError(IExtension *pExt, const char *format, ...) ds@1952: { ds@1952: IExtensionInterface *pAPI = pExt->GetAPI(); ds@1952: const char *tag = pAPI->GetExtensionTag(); ds@1952: char buffer[2048]; ds@1952: va_list ap; ds@1952: ds@1952: va_start(ap, format); ds@1952: vsnprintf(buffer, sizeof(buffer), format, ap); ds@1952: va_end(ap); ds@1952: ds@1952: if (tag) ds@1952: { ds@1952: g_Logger.LogError("[%s] %s", tag, buffer); ds@1952: } else { ds@1952: g_Logger.LogError("%s", buffer); ds@1952: } ds@1952: } ds@1952: ds@1952: size_t SourceModBase::FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param) ds@1952: { ds@1952: char *fmt; ds@1952: ds@1952: pContext->LocalToString(params[param], &fmt); ds@1952: ds@1952: int lparam = ++param; ds@1952: ds@1952: return atcprintf(buffer, maxlength, fmt, pContext, params, &lparam); ds@1952: } ds@1952: ds@1952: const char *SourceModBase::GetSourceModPath() const ds@1952: { ds@1952: return m_SMBaseDir; ds@1952: } ds@1952: ds@1952: const char *SourceModBase::GetGamePath() const ds@1952: { ds@1952: return g_BaseDir.c_str(); ds@1952: } ds@1952: ds@1952: unsigned int SourceModBase::SetGlobalTarget(unsigned int index) ds@1952: { ds@1952: unsigned int old = m_target; ds@1952: m_target = index; ds@1952: return old; ds@1952: } ds@1952: ds@1952: unsigned int SourceModBase::GetGlobalTarget() const ds@1952: { ds@1952: return m_target; ds@1952: } ds@1952: ds@1952: IDataPack *SourceModBase::CreateDataPack() ds@1952: { ds@1952: CDataPack *pack; ds@1952: if (m_freepacks.empty()) ds@1952: { ds@1952: pack = new CDataPack; ds@1952: } else { ds@1952: pack = m_freepacks.front(); ds@1952: m_freepacks.pop(); ds@1952: pack->Initialize(); ds@1952: } ds@1952: return pack; ds@1952: } ds@1952: ds@1952: void SourceModBase::FreeDataPack(IDataPack *pack) ds@1952: { ds@1952: m_freepacks.push(static_cast(pack)); ds@1952: } ds@1952: ds@1952: Handle_t SourceModBase::GetDataPackHandleType(bool readonly) ds@1952: { ds@1952: //:TODO: ds@1952: return 0; ds@1952: } ds@1952: ds@1952: const char *SourceModBase::GetGameFolderName() const ds@1952: { ds@1952: return m_ModDir; ds@1952: } ds@1952: ds@1952: ISourcePawnEngine *SourceModBase::GetScriptingEngine() ds@1952: { ds@1952: return g_pSourcePawn; ds@1952: } ds@1952: ds@1952: IVirtualMachine *SourceModBase::GetScriptingVM() ds@1952: { ds@1952: return g_pVM; ds@1952: } ds@1952: ds@1952: void SourceModBase::AllPluginsLoaded() ds@1952: { ds@1952: SMGlobalClass *base = SMGlobalClass::head; ds@1952: while (base) ds@1952: { ds@1952: base->OnSourceModGameInitialized(); ds@1952: base = base->m_pGlobalClassNext; ds@1952: } ds@1952: } ds@1952: ds@1952: time_t SourceModBase::GetAdjustedTime() ds@1952: { ds@1952: return ::GetAdjustedTime(); ds@1952: } ds@1952: ds@1952: void SourceModBase::AddGameFrameHook(GAME_FRAME_HOOK hook) ds@1952: { ds@1952: m_frame_hooks.push_back(hook); ds@1952: } ds@1952: ds@1952: void SourceModBase::RemoveGameFrameHook(GAME_FRAME_HOOK hook) ds@1952: { ds@1952: for (size_t i = 0; i < m_frame_hooks.size(); i++) ds@1952: { ds@1952: if (m_frame_hooks[i] == hook) ds@1952: { ds@1952: m_frame_hooks.erase(m_frame_hooks.iterAt(i)); ds@1952: return; ds@1952: } ds@1952: } ds@1952: } ds@1952: ds@1952: void SourceModBase::ProcessGameFrameHooks(bool simulating) ds@1952: { ds@1952: if (m_frame_hooks.size() == 0) ds@1952: { ds@1952: return; ds@1952: } ds@1952: ds@1952: for (size_t i = 0; i < m_frame_hooks.size(); i++) ds@1952: { ds@1952: m_frame_hooks[i](simulating); ds@1952: } ds@1952: } ds@1952: ds@1952: SMGlobalClass *SMGlobalClass::head = NULL; ds@1952: ds@1952: SMGlobalClass::SMGlobalClass() ds@1952: { ds@1952: m_pGlobalClassNext = SMGlobalClass::head; ds@1952: SMGlobalClass::head = this; ds@1952: }