2008-11-14 11:04:02 +01:00
|
|
|
/**
|
2009-11-23 06:54:55 +01:00
|
|
|
* vim: set ts=4 sw=4 tw=99 noet :
|
2008-11-14 11:04:02 +01:00
|
|
|
* ======================================================
|
|
|
|
* Metamod:Source
|
2010-05-19 08:28:55 +02:00
|
|
|
* Copyright (C) 2004-2010 AlliedModders LLC and authors.
|
2008-11-14 11:04:02 +01:00
|
|
|
* All rights reserved.
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
* In no event will the authors be held liable for any damages arising from
|
|
|
|
* the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
* freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
* claim that you wrote the original software. If you use this software in a
|
|
|
|
* product, an acknowledgment in the product documentation would be
|
|
|
|
* appreciated but is not required.
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software.
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "metamod_oslink.h"
|
|
|
|
#include "metamod.h"
|
|
|
|
#include <interface.h>
|
|
|
|
#include <eiface.h>
|
2015-04-11 16:22:15 +02:00
|
|
|
#include <metamod_version.h>
|
2008-11-14 11:04:02 +01:00
|
|
|
#include "metamod_provider.h"
|
|
|
|
#include "metamod_plugins.h"
|
|
|
|
#include "metamod_util.h"
|
|
|
|
#include "metamod_console.h"
|
2008-11-16 10:44:21 +01:00
|
|
|
#include "provider/provider_ep2.h"
|
2010-05-19 08:28:55 +02:00
|
|
|
#include <sys/stat.h>
|
2016-07-22 19:57:54 +02:00
|
|
|
#if SOURCE_ENGINE == SE_DOTA
|
2015-07-11 19:59:51 +02:00
|
|
|
#include <iserver.h>
|
|
|
|
#endif
|
2008-11-14 11:04:02 +01:00
|
|
|
|
2017-12-20 08:11:57 +01:00
|
|
|
#define X64_SUFFIX ".x64"
|
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
|
|
#define BINARY_EXT ".dll"
|
|
|
|
#elif defined(__linux__)
|
|
|
|
#define BINARY_EXT ".so"
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#define BINARY_EXT ".dylib"
|
|
|
|
#endif
|
|
|
|
|
2008-11-14 11:04:02 +01:00
|
|
|
using namespace SourceMM;
|
|
|
|
using namespace SourceHook;
|
|
|
|
using namespace SourceHook::Impl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Implementation of main SourceMM GameDLL functionality
|
|
|
|
* @file sourcemm.cpp
|
|
|
|
*/
|
|
|
|
|
2016-07-22 19:57:54 +02:00
|
|
|
#if SOURCE_ENGINE == SE_DOTA
|
2015-07-11 19:59:51 +02:00
|
|
|
// Hack to make hook decl compile when only having forward decl in header.
|
|
|
|
// (we have class structure but it requires protobuf which we don't want to include here)
|
|
|
|
class GameSessionConfiguration_t { };
|
|
|
|
|
2017-02-18 16:23:59 +01:00
|
|
|
SH_DECL_MANUALHOOK3_void(SGD_StartupServer, 0, 0, 0, const GameSessionConfiguration_t &, ISource2WorldSession *, const char *);
|
2015-07-11 19:59:51 +02:00
|
|
|
SH_DECL_MANUALHOOK2_void(SGD_Init, 0, 0, 0, GameSessionConfiguration_t *, const char *);
|
2017-02-18 16:23:20 +01:00
|
|
|
SH_DECL_MANUALHOOK3(SGD_StartChangeLevel, 0, 0, 0, CUtlVector<INetworkGameClient *> *, const char *, const char *, void *);
|
2015-07-11 19:59:51 +02:00
|
|
|
SH_DECL_MANUALHOOK5_void(SGD_SwitchToLoop, 0, 0, 0, const char *, KeyValues *, uint32, const char *, bool);
|
|
|
|
|
|
|
|
static void
|
|
|
|
Handler_SwitchToLoop(const char *, KeyValues *, uint32, const char *, bool);
|
|
|
|
|
|
|
|
static void
|
2017-02-18 16:23:59 +01:00
|
|
|
Handler_StartupServer_Post(const GameSessionConfiguration_t &, ISource2WorldSession *, const char *);
|
2015-07-11 19:59:51 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
Handler_Init(GameSessionConfiguration_t *, const char *);
|
|
|
|
|
|
|
|
static CUtlVector<INetworkGameClient *> *
|
2017-02-18 16:23:20 +01:00
|
|
|
Handler_StartChangeLevel(const char *, const char *, void *);
|
2015-07-11 19:59:51 +02:00
|
|
|
#else
|
2008-11-14 11:04:02 +01:00
|
|
|
SH_DECL_MANUALHOOK0(SGD_GameInit, 0, 0, 0, bool);
|
|
|
|
SH_DECL_MANUALHOOK6(SGD_LevelInit, 0, 0, 0, bool, const char *, const char *, const char *, const char *, bool, bool);
|
|
|
|
SH_DECL_MANUALHOOK0_void(SGD_LevelShutdown, 0, 0, 0);
|
2008-11-16 06:46:27 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
Handler_LevelShutdown();
|
|
|
|
|
|
|
|
static bool
|
|
|
|
Handler_LevelInit(char const *pMapName,
|
|
|
|
char const *pMapEntities,
|
|
|
|
char const *pOldLevel,
|
|
|
|
char const *pLandmarkName,
|
|
|
|
bool loadGame,
|
|
|
|
bool background);
|
|
|
|
|
|
|
|
static bool
|
|
|
|
Handler_GameInit();
|
2015-07-11 19:59:51 +02:00
|
|
|
#endif
|
2008-11-16 06:46:27 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
InitializeVSP();
|
|
|
|
|
2008-11-24 14:47:08 +01:00
|
|
|
static int
|
|
|
|
LoadPluginsFromFile(const char *filepath, int &skipped);
|
|
|
|
|
|
|
|
static int
|
|
|
|
LoadVDFPluginsFromDir(const char *dir, int &skipped);
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
struct game_dll_t
|
|
|
|
{
|
|
|
|
CreateInterfaceFn factory;
|
|
|
|
};
|
|
|
|
|
2008-11-16 06:46:27 +01:00
|
|
|
static String mod_path;
|
|
|
|
static String metamod_path;
|
|
|
|
static String full_bin_path;
|
|
|
|
static int vsp_version = 0;
|
|
|
|
static int gamedll_version = 0;
|
|
|
|
static int engine_build = SOURCE_ENGINE_UNKNOWN;
|
|
|
|
static List<game_dll_t *> gamedll_list;
|
|
|
|
static bool is_gamedll_loaded = false;
|
|
|
|
static bool in_first_level = true;
|
|
|
|
static bool is_game_init = false;
|
|
|
|
static bool vsp_load_requested = false;
|
|
|
|
static bool vsp_loaded = false;
|
|
|
|
static game_dll_t gamedll_info;
|
|
|
|
static ConVar *metamod_version = NULL;
|
|
|
|
static ConVar *mm_pluginsfile = NULL;
|
|
|
|
static ConVar *mm_basedir = NULL;
|
|
|
|
static CreateInterfaceFn engine_factory = NULL;
|
|
|
|
static CreateInterfaceFn physics_factory = NULL;
|
|
|
|
static CreateInterfaceFn filesystem_factory = NULL;
|
2017-12-20 08:11:57 +01:00
|
|
|
#if !defined( _WIN64 ) && !defined( __amd64__ )
|
2008-11-16 06:46:27 +01:00
|
|
|
static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
|
2016-07-22 19:59:58 +02:00
|
|
|
#endif
|
2008-11-16 06:46:27 +01:00
|
|
|
static META_RES last_meta_res;
|
|
|
|
static IServerPluginCallbacks *vsp_callbacks = NULL;
|
|
|
|
static bool were_plugins_loaded = false;
|
|
|
|
static bool g_bIsVspBridged = false;
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
MetamodSource g_Metamod;
|
2008-11-16 06:46:27 +01:00
|
|
|
PluginId g_PLID = Pl_Console;
|
|
|
|
CSourceHookImpl g_SourceHook;
|
|
|
|
ISourceHook *g_SHPtr = &g_SourceHook;
|
2008-11-14 11:04:02 +01:00
|
|
|
SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
|
|
|
|
|
|
|
|
/* Helper Macro */
|
|
|
|
#define IFACE_MACRO(orig,nam) \
|
|
|
|
CPluginManager::CPlugin *pl; \
|
|
|
|
SourceHook::List<IMetamodListener *>::iterator event; \
|
|
|
|
IMetamodListener *api; \
|
|
|
|
int mret = 0; \
|
|
|
|
void *val = NULL; \
|
|
|
|
for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
|
|
|
|
pl = (*iter); \
|
|
|
|
for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
|
|
|
|
api = (*event); \
|
2015-01-21 01:30:13 +01:00
|
|
|
mret = META_IFACE_FAILED; \
|
2008-11-14 11:04:02 +01:00
|
|
|
if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
|
|
|
|
if (ret) *ret = mret; \
|
|
|
|
return val; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return (orig)(iface, ret);
|
|
|
|
|
|
|
|
#define ITER_EVENT(evn, args) \
|
|
|
|
CPluginManager::CPlugin *pl; \
|
|
|
|
SourceHook::List<IMetamodListener *>::iterator event; \
|
|
|
|
IMetamodListener *api; \
|
|
|
|
for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
|
|
|
|
pl = (*iter); \
|
|
|
|
for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
|
|
|
|
api = (*event); \
|
|
|
|
api->evn args; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize everything here */
|
2008-11-16 06:46:27 +01:00
|
|
|
void
|
|
|
|
mm_InitializeForLoad()
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
char full_path[PATH_SIZE] = {0};
|
|
|
|
GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
|
|
|
|
full_bin_path.assign(full_path);
|
|
|
|
|
|
|
|
/* Like Metamod, reload plugins at the end of the map.
|
|
|
|
* This is so plugins can hook everything on load, BUT, new plugins will be reloaded
|
|
|
|
* if the server is shut down (silly, but rare case).
|
|
|
|
*/
|
|
|
|
in_first_level = true;
|
|
|
|
|
2016-07-22 19:57:54 +02:00
|
|
|
#if SOURCE_ENGINE == SE_DOTA
|
2015-07-11 19:59:51 +02:00
|
|
|
SourceHook::MemFuncInfo info;
|
|
|
|
|
|
|
|
if (!provider->GetHookInfo(ProvidedHook_StartupServer, &info))
|
|
|
|
{
|
|
|
|
provider->DisplayError("Metamod:Source could not find a valid hook for INetworkServerService::StartupServer");
|
|
|
|
}
|
|
|
|
SH_MANUALHOOK_RECONFIGURE(SGD_StartupServer, info.vtblindex, info.vtbloffs, info.thisptroffs);
|
|
|
|
SH_ADD_MANUALHOOK(SGD_StartupServer, netservice, SH_STATIC(Handler_StartupServer_Post), true);
|
|
|
|
|
|
|
|
if (!provider->GetHookInfo(ProvidedHook_SwitchToLoop, &info))
|
|
|
|
{
|
|
|
|
provider->DisplayError("Metamod:Source could not find a valid hook for IEngineServiceMgr::SwitchToLoop");
|
|
|
|
}
|
|
|
|
SH_MANUALHOOK_RECONFIGURE(SGD_SwitchToLoop, info.vtblindex, info.vtbloffs, info.thisptroffs);
|
|
|
|
SH_ADD_MANUALHOOK(SGD_SwitchToLoop, enginesvcmgr, SH_STATIC(Handler_SwitchToLoop), false);
|
|
|
|
#else
|
2008-11-14 11:04:02 +01:00
|
|
|
SourceHook::MemFuncInfo info;
|
|
|
|
|
|
|
|
if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
|
|
|
|
{
|
|
|
|
provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
|
|
|
|
}
|
|
|
|
SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
|
|
|
|
SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
|
|
|
|
|
|
|
|
if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
|
|
|
|
{
|
|
|
|
provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
|
|
|
|
}
|
|
|
|
SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
|
|
|
|
SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
|
|
|
|
|
|
|
|
if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
|
|
|
|
{
|
|
|
|
provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
|
|
|
|
}
|
|
|
|
SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
|
|
|
|
SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
|
2015-07-09 03:39:28 +02:00
|
|
|
#endif
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
2008-11-16 06:46:27 +01:00
|
|
|
bool
|
|
|
|
mm_DetectGameInformation()
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
char game_path[PATH_SIZE];
|
|
|
|
|
2014-06-04 18:15:33 +02:00
|
|
|
provider->GetGamePath(game_path, sizeof(game_path));
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
mod_path.assign(game_path);
|
|
|
|
|
2014-06-04 18:15:33 +02:00
|
|
|
engine_build = provider->DetermineSourceEngine();
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-24 06:22:33 +01:00
|
|
|
void *
|
|
|
|
ServerFactory(const char *iface, int *ret)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
IFACE_MACRO(gamedll_info.factory, GameDLL);
|
|
|
|
}
|
|
|
|
|
2008-11-24 14:25:46 +01:00
|
|
|
static int
|
|
|
|
LoadPluginsFromFile(const char *filepath, int &skipped)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
FILE *fp;
|
2008-11-24 14:25:46 +01:00
|
|
|
int total = 0;
|
2008-11-14 11:04:02 +01:00
|
|
|
PluginId id;
|
|
|
|
bool already;
|
|
|
|
|
2008-11-24 14:25:46 +01:00
|
|
|
skipped = 0;
|
|
|
|
|
|
|
|
fp = fopen(filepath, "rt");
|
2008-11-14 11:04:02 +01:00
|
|
|
if (!fp)
|
|
|
|
{
|
2008-11-24 14:25:46 +01:00
|
|
|
return 0;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
2008-11-24 14:25:46 +01:00
|
|
|
char buffer[255], error[255], full_path[PATH_SIZE];
|
2012-10-26 17:19:45 +02:00
|
|
|
const char *file;
|
2008-11-14 11:04:02 +01:00
|
|
|
size_t length;
|
|
|
|
while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
|
|
|
|
{
|
|
|
|
UTIL_TrimLeft(buffer);
|
|
|
|
UTIL_TrimRight(buffer);
|
|
|
|
|
|
|
|
length = strlen(buffer);
|
|
|
|
if (!length)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = buffer;
|
|
|
|
if (buffer[0] == '"')
|
|
|
|
{
|
|
|
|
char *cptr = buffer;
|
|
|
|
file = ++cptr;
|
|
|
|
|
|
|
|
while (*cptr)
|
|
|
|
{
|
|
|
|
if (*cptr == '"')
|
|
|
|
{
|
|
|
|
*cptr = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *cptr = buffer;
|
|
|
|
while (*cptr)
|
|
|
|
{
|
|
|
|
if (isspace(*cptr))
|
|
|
|
{
|
|
|
|
char *optr = cptr;
|
|
|
|
while (*cptr && isspace(*cptr))
|
|
|
|
{
|
|
|
|
cptr++;
|
|
|
|
}
|
|
|
|
*optr = '\0';
|
|
|
|
UTIL_TrimRight(cptr);
|
|
|
|
if (*cptr && isalpha(*cptr))
|
|
|
|
{
|
|
|
|
g_PluginMngr.SetAlias(buffer, cptr);
|
|
|
|
file = cptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!file[0])
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-19 08:28:55 +02:00
|
|
|
|
|
|
|
g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
|
|
|
|
|
|
|
|
id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
|
|
|
|
if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
2010-05-19 08:28:55 +02:00
|
|
|
mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-19 08:28:55 +02:00
|
|
|
if (already)
|
|
|
|
skipped++;
|
2008-11-14 11:04:02 +01:00
|
|
|
else
|
2010-05-19 08:28:55 +02:00
|
|
|
total++;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitializeVSP()
|
|
|
|
{
|
2008-11-16 06:46:27 +01:00
|
|
|
if (g_bIsVspBridged)
|
2008-11-14 11:04:02 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
size_t len;
|
|
|
|
char engine_file[PATH_SIZE];
|
|
|
|
char engine_path[PATH_SIZE];
|
|
|
|
char rel_path[PATH_SIZE * 2];
|
|
|
|
|
|
|
|
GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
|
|
|
|
|
|
|
|
/* Chop off the "engine" file part */
|
|
|
|
len = strlen(engine_file);
|
2011-04-24 04:35:10 +02:00
|
|
|
for (size_t i = len - 1; i < len; i--)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
if (engine_file[i] == '/' || engine_file[i] == '\\')
|
|
|
|
{
|
|
|
|
engine_file[i] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
abspath(engine_path, engine_file);
|
|
|
|
|
|
|
|
const char *usepath = metamod_path.c_str();
|
|
|
|
if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
|
|
|
|
{
|
|
|
|
usepath = rel_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
char command[PATH_SIZE * 2];
|
|
|
|
UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
|
|
|
|
provider->ServerCommand(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wrapper function. This is called when the GameDLL thinks it's using
|
|
|
|
* the engine's real engineFactory.
|
|
|
|
*/
|
2008-11-16 06:46:27 +01:00
|
|
|
static void *
|
|
|
|
EngineFactory(const char *iface, int *ret)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
IFACE_MACRO(engine_factory, Engine);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wrapper function. This is called when the GameDLL thinks it's using
|
|
|
|
* the engine's real physicsFactory.
|
|
|
|
*/
|
2008-11-16 06:46:27 +01:00
|
|
|
static void *
|
|
|
|
PhysicsFactory(const char *iface, int *ret)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
IFACE_MACRO(physics_factory, Physics);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wrapper function. This is called when the GameDLL thinks it's using
|
|
|
|
* the engine's real fileSystemFactory.
|
|
|
|
*/
|
2008-11-16 06:46:27 +01:00
|
|
|
static void *
|
|
|
|
FileSystemFactory(const char *iface, int *ret)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
IFACE_MACRO(filesystem_factory, FileSystem);
|
|
|
|
}
|
|
|
|
|
2008-11-16 06:46:27 +01:00
|
|
|
void
|
|
|
|
mm_LogMessage(const char *msg, ...)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
static char buffer[2048];
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
buffer[len++] = '\n';
|
|
|
|
buffer[len] = '\0';
|
|
|
|
|
|
|
|
if (!provider->LogMessage(buffer))
|
|
|
|
{
|
|
|
|
fprintf(stdout, "%s", buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-16 06:46:27 +01:00
|
|
|
static void
|
|
|
|
DoInitialPluginLoads()
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
|
|
|
|
const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
|
|
|
|
if (!pluginFile)
|
|
|
|
{
|
|
|
|
pluginFile = provider->GetConVarString(mm_pluginsfile);
|
|
|
|
if (pluginFile == NULL)
|
|
|
|
{
|
|
|
|
pluginFile = "addons/metamod/metaplugins.ini";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!mmBaseDir)
|
|
|
|
{
|
|
|
|
mmBaseDir = provider->GetConVarString(mm_basedir);
|
|
|
|
if (mmBaseDir == NULL)
|
|
|
|
{
|
|
|
|
mmBaseDir = "addons/metamod";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-24 14:25:46 +01:00
|
|
|
char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
|
2008-11-14 11:04:02 +01:00
|
|
|
|
2008-11-24 14:25:46 +01:00
|
|
|
g_Metamod.PathFormat(filepath, sizeof(filepath), "%s/%s", mod_path.c_str(), pluginFile);
|
|
|
|
g_Metamod.PathFormat(vdfpath, sizeof(vdfpath), "%s/%s", mod_path.c_str(), mmBaseDir);
|
|
|
|
mm_LoadPlugins(filepath, vdfpath);
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
2008-11-16 06:46:27 +01:00
|
|
|
void
|
|
|
|
mm_StartupMetamod(bool is_vsp_load)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
char buffer[255];
|
|
|
|
|
|
|
|
UTIL_Format(buffer,
|
|
|
|
sizeof(buffer),
|
|
|
|
"%s%s",
|
2013-11-24 04:10:27 +01:00
|
|
|
METAMOD_VERSION,
|
2008-11-14 11:04:02 +01:00
|
|
|
is_vsp_load ? "V" : "");
|
|
|
|
|
|
|
|
metamod_version = provider->CreateConVar("metamod_version",
|
2013-11-24 04:10:27 +01:00
|
|
|
METAMOD_VERSION,
|
2008-11-14 11:04:02 +01:00
|
|
|
"Metamod:Source Version",
|
|
|
|
ConVarFlag_Notify|ConVarFlag_SpOnly);
|
|
|
|
|
|
|
|
provider->SetConVarString(metamod_version, buffer);
|
|
|
|
|
|
|
|
mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
|
|
|
|
#if defined WIN32 || defined _WIN32
|
|
|
|
"addons\\metamod\\metaplugins.ini",
|
|
|
|
#else
|
|
|
|
"addons/metamod/metaplugins.ini",
|
|
|
|
#endif
|
|
|
|
"Metamod:Source Plugins File",
|
|
|
|
ConVarFlag_SpOnly);
|
|
|
|
|
|
|
|
mm_basedir = provider->CreateConVar("mm_basedir",
|
2010-05-14 07:34:56 +02:00
|
|
|
#if defined __linux__ || defined __APPLE__
|
2008-11-14 11:04:02 +01:00
|
|
|
"addons/metamod",
|
|
|
|
#else
|
|
|
|
"addons\\metamod",
|
|
|
|
#endif
|
|
|
|
"Metamod:Source Base Folder",
|
|
|
|
ConVarFlag_SpOnly);
|
2008-11-16 06:46:27 +01:00
|
|
|
|
2008-11-24 06:45:57 +01:00
|
|
|
g_bIsVspBridged = is_vsp_load;
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
if (!is_vsp_load)
|
|
|
|
{
|
|
|
|
DoInitialPluginLoads();
|
|
|
|
in_first_level = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-16 06:46:27 +01:00
|
|
|
void
|
|
|
|
mm_InitializeGlobals(CreateInterfaceFn engineFactory,
|
|
|
|
CreateInterfaceFn physicsFactory,
|
|
|
|
CreateInterfaceFn filesystemFactory,
|
|
|
|
CGlobalVars *pGlobals)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
engine_factory = engineFactory;
|
|
|
|
physics_factory = physicsFactory;
|
|
|
|
filesystem_factory = filesystemFactory;
|
|
|
|
gpGlobals = pGlobals;
|
|
|
|
provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
|
|
|
|
}
|
|
|
|
|
2015-07-11 19:59:51 +02:00
|
|
|
void
|
|
|
|
mm_UnloadMetamod()
|
|
|
|
{
|
|
|
|
/* Unload plugins */
|
|
|
|
g_PluginMngr.UnloadAll();
|
|
|
|
|
|
|
|
provider->Notify_DLLShutdown_Pre();
|
|
|
|
|
|
|
|
g_SourceHook.CompleteShutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mm_HandleGameInit()
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
if (is_game_init)
|
2015-07-11 19:59:51 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-22 19:57:54 +02:00
|
|
|
#if SOURCE_ENGINE == SE_DOTA
|
2017-04-16 22:21:02 +02:00
|
|
|
DevMsg("MMS: GameInit\n");
|
2015-07-11 19:59:51 +02:00
|
|
|
#endif
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
if (vsp_load_requested)
|
|
|
|
InitializeVSP();
|
|
|
|
|
2008-11-16 06:46:27 +01:00
|
|
|
if (g_bIsVspBridged && !were_plugins_loaded)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
DoInitialPluginLoads();
|
|
|
|
g_PluginMngr.SetAllLoaded();
|
|
|
|
were_plugins_loaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
is_game_init = true;
|
|
|
|
}
|
|
|
|
|
2008-11-16 06:46:27 +01:00
|
|
|
static void
|
2015-07-11 19:59:51 +02:00
|
|
|
mm_HandleLevelShutdown()
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
2016-07-22 19:57:54 +02:00
|
|
|
#if SOURCE_ENGINE == SE_DOTA
|
2017-04-16 22:21:02 +02:00
|
|
|
DevMsg("MMS: LevelShutdown\n");
|
2015-07-11 19:59:51 +02:00
|
|
|
#endif
|
|
|
|
|
2008-11-16 06:46:27 +01:00
|
|
|
if (g_bIsVspBridged && !were_plugins_loaded)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
DoInitialPluginLoads();
|
2009-02-17 19:58:25 +01:00
|
|
|
g_PluginMngr.SetAllLoaded();
|
2008-11-14 11:04:02 +01:00
|
|
|
were_plugins_loaded = true;
|
|
|
|
in_first_level = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_first_level)
|
|
|
|
{
|
2008-11-24 14:25:46 +01:00
|
|
|
char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
|
2008-11-14 11:04:02 +01:00
|
|
|
|
2008-11-24 14:25:46 +01:00
|
|
|
g_Metamod.PathFormat(filepath,
|
|
|
|
sizeof(filepath),
|
2008-11-14 11:04:02 +01:00
|
|
|
"%s/%s",
|
|
|
|
mod_path.c_str(),
|
|
|
|
provider->GetConVarString(mm_pluginsfile));
|
2008-11-24 14:25:46 +01:00
|
|
|
g_Metamod.PathFormat(vdfpath,
|
|
|
|
sizeof(vdfpath),
|
2008-11-14 11:04:02 +01:00
|
|
|
"%s/%s",
|
|
|
|
mod_path.c_str(),
|
|
|
|
provider->GetConVarString(mm_basedir));
|
2008-11-24 14:25:46 +01:00
|
|
|
mm_LoadPlugins(filepath, vdfpath);
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
in_first_level = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ITER_EVENT(OnLevelShutdown, ());
|
2015-07-11 19:59:51 +02:00
|
|
|
}
|
2008-11-14 11:04:02 +01:00
|
|
|
|
2015-07-11 19:59:51 +02:00
|
|
|
static void
|
|
|
|
mm_HandleLevelInit(char const *pMapName,
|
|
|
|
char const *pMapEntities,
|
|
|
|
char const *pOldLevel,
|
|
|
|
char const *pLandmarkName,
|
|
|
|
bool loadGame,
|
|
|
|
bool background)
|
|
|
|
{
|
2016-07-22 19:57:54 +02:00
|
|
|
#if SOURCE_ENGINE == SE_DOTA
|
2017-04-16 22:21:02 +02:00
|
|
|
DevMsg("MMS: LevelInit\n");
|
2015-07-11 19:59:51 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
|
|
|
|
}
|
|
|
|
#include <utlbuffer.h>
|
2016-07-22 19:57:54 +02:00
|
|
|
#if SOURCE_ENGINE == SE_DOTA
|
2015-07-11 19:59:51 +02:00
|
|
|
static void
|
|
|
|
Handler_SwitchToLoop(const char *pszLoopName, KeyValues *pKV, uint32 nId, const char *pszUnk, bool bUnk)
|
|
|
|
{
|
|
|
|
if (strcmp(pszLoopName, "levelload") == 0)
|
|
|
|
{
|
|
|
|
mm_HandleGameInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-18 16:23:59 +01:00
|
|
|
Handler_StartupServer_Post(const GameSessionConfiguration_t &config, ISource2WorldSession *, const char *)
|
2015-07-11 19:59:51 +02:00
|
|
|
{
|
|
|
|
static bool bGameServerHooked = false;
|
|
|
|
if (!bGameServerHooked)
|
|
|
|
{
|
2017-02-18 16:23:59 +01:00
|
|
|
INetworkGameServer *netserver = (META_IFACEPTR(INetworkServerService))->GetIGameServer();
|
2015-07-11 19:59:51 +02:00
|
|
|
|
|
|
|
SourceHook::MemFuncInfo info;
|
|
|
|
if (!provider->GetHookInfo(ProvidedHook_Init, &info))
|
|
|
|
{
|
|
|
|
provider->DisplayError("Metamod:Source could not find a valid hook for INetworkGameServer::Init");
|
|
|
|
}
|
|
|
|
SH_MANUALHOOK_RECONFIGURE(SGD_Init, info.vtblindex, info.vtbloffs, info.thisptroffs);
|
|
|
|
SH_ADD_MANUALVPHOOK(SGD_Init, netserver, SH_STATIC(Handler_Init), false);
|
|
|
|
|
|
|
|
if (!provider->GetHookInfo(ProvidedHook_StartChangeLevel, &info))
|
|
|
|
{
|
|
|
|
provider->DisplayError("Metamod:Source could not find a valid hook for INetworkGameServer::StartChangeLevel");
|
|
|
|
}
|
|
|
|
SH_MANUALHOOK_RECONFIGURE(SGD_StartChangeLevel, info.vtblindex, info.vtbloffs, info.thisptroffs);
|
|
|
|
SH_ADD_MANUALVPHOOK(SGD_StartChangeLevel, netserver, SH_STATIC(Handler_StartChangeLevel), false);
|
|
|
|
|
|
|
|
bGameServerHooked = true;
|
|
|
|
}
|
|
|
|
|
2017-02-18 16:23:59 +01:00
|
|
|
RETURN_META(MRES_IGNORED);
|
2015-07-11 19:59:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Handler_Init(GameSessionConfiguration_t *pConfig, const char *pszMapName)
|
|
|
|
{
|
|
|
|
static char szLastMap[260] = "";
|
|
|
|
mm_HandleLevelInit(pszMapName, "", szLastMap, "", false, false);
|
|
|
|
UTIL_Format(szLastMap, sizeof(szLastMap), "%s", pszMapName);
|
|
|
|
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CUtlVector<INetworkGameClient *> *
|
2017-02-18 16:23:20 +01:00
|
|
|
Handler_StartChangeLevel(const char *, const char *, void *)
|
2015-07-11 19:59:51 +02:00
|
|
|
{
|
|
|
|
mm_HandleLevelShutdown();
|
|
|
|
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, nullptr);
|
|
|
|
}
|
|
|
|
|
2015-07-10 15:30:28 +02:00
|
|
|
#else
|
2015-07-11 19:59:51 +02:00
|
|
|
|
|
|
|
static bool
|
|
|
|
Handler_GameInit()
|
|
|
|
{
|
|
|
|
mm_HandleGameInit();
|
|
|
|
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Handler_LevelShutdown(void)
|
|
|
|
{
|
|
|
|
mm_HandleLevelShutdown();
|
|
|
|
|
2008-11-14 11:04:02 +01:00
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2008-11-16 06:46:27 +01:00
|
|
|
static bool
|
|
|
|
Handler_LevelInit(char const *pMapName,
|
|
|
|
char const *pMapEntities,
|
|
|
|
char const *pOldLevel,
|
|
|
|
char const *pLandmarkName,
|
|
|
|
bool loadGame,
|
|
|
|
bool background)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
|
|
|
|
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, false);
|
|
|
|
}
|
2015-07-11 19:59:51 +02:00
|
|
|
#endif
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2008-11-16 10:41:17 +01:00
|
|
|
mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
|
|
|
|
{
|
|
|
|
if (syn)
|
|
|
|
return EngineFactory;
|
|
|
|
return engine_factory;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
|
|
|
|
{
|
|
|
|
if (syn)
|
|
|
|
return PhysicsFactory;
|
|
|
|
return physics_factory;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
|
|
|
|
{
|
|
|
|
if (syn)
|
|
|
|
return FileSystemFactory;
|
|
|
|
return filesystem_factory;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
|
|
|
|
{
|
|
|
|
if (syn)
|
2008-11-24 06:22:33 +01:00
|
|
|
return ServerFactory;
|
2008-11-14 11:04:02 +01:00
|
|
|
return gamedll_info.factory;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGlobalVars *MetamodSource::GetCGlobals()
|
|
|
|
{
|
|
|
|
return gpGlobals;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetamodSource::SetLastMetaReturn(META_RES res)
|
|
|
|
{
|
|
|
|
last_meta_res = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_RES MetamodSource::GetLastMetaReturn()
|
|
|
|
{
|
|
|
|
return last_meta_res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetamodSource::ConPrint(const char *str)
|
|
|
|
{
|
|
|
|
provider->ConsolePrint(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetamodSource::ConPrintf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
provider->ConsolePrint(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
|
|
|
|
{
|
|
|
|
major = METAMOD_API_MAJOR;
|
|
|
|
minor = METAMOD_API_MINOR;
|
|
|
|
plvers = METAMOD_PLAPI_VERSION;
|
|
|
|
plmin = PLAPI_MIN_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetamodSource::GetShVersions(int &shvers, int &shimpl)
|
|
|
|
{
|
|
|
|
shvers = SH_IFACE_VERSION;
|
|
|
|
shimpl = SH_IMPL_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
|
|
|
|
{
|
|
|
|
int length = (int)strlen(iface);
|
|
|
|
int i;
|
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
for (i = length - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (!isdigit(iface[i]))
|
|
|
|
{
|
|
|
|
if (i != length - 1)
|
|
|
|
{
|
|
|
|
num = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != length - 1)
|
|
|
|
{
|
|
|
|
num = atoi(&(iface[++i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
num++;
|
|
|
|
|
|
|
|
snprintf(&(iface[i]), 4, "%03d", num);
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
|
|
|
|
{
|
|
|
|
char _if[256]; /* assume no interface goes beyond this */
|
|
|
|
size_t len = strlen(iface);
|
|
|
|
int num = 0;
|
|
|
|
void *pf = NULL;
|
|
|
|
|
|
|
|
if (max > 999)
|
|
|
|
{
|
|
|
|
max = 999;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len + 4 > sizeof(_if))
|
|
|
|
{
|
|
|
|
if (ret)
|
|
|
|
{
|
2015-01-21 01:30:13 +01:00
|
|
|
*ret = META_IFACE_FAILED;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(_if, iface);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((pf = (fn)(_if, ret)) != NULL)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (num > max)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while ((num = FormatIface(_if, len+1)));
|
|
|
|
|
|
|
|
return pf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
|
|
|
|
{
|
|
|
|
char buffer[256]; /* assume no interface will go beyond this */
|
|
|
|
size_t len = strlen(iface);
|
|
|
|
int ret; /* just in case something doesn't handle NULL properly */
|
|
|
|
|
|
|
|
if (len > sizeof(buffer) - 4)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(buffer, iface);
|
|
|
|
|
|
|
|
if (min != -1)
|
|
|
|
{
|
|
|
|
char *ptr = &buffer[len - 1];
|
|
|
|
int digits = 0;
|
|
|
|
while (isdigit(*ptr) && digits <=3)
|
|
|
|
{
|
|
|
|
*ptr = '\0';
|
|
|
|
digits++;
|
|
|
|
ptr--;
|
|
|
|
}
|
|
|
|
if (digits != 3)
|
|
|
|
{
|
|
|
|
/* for now, assume this is an error */
|
|
|
|
strcpy(buffer, iface);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char num[4];
|
|
|
|
min = (min == 0) ? 1 : min;
|
|
|
|
snprintf(num, sizeof(num), "%03d", min);
|
|
|
|
strcat(buffer, num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *MetamodSource::GetBaseDir()
|
|
|
|
{
|
|
|
|
return mod_path.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mylen; i++)
|
|
|
|
{
|
|
|
|
if (buffer[i] == ALT_SEP_CHAR)
|
|
|
|
{
|
|
|
|
buffer[i] = PATH_SEP_CHAR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mylen;
|
|
|
|
}
|
|
|
|
|
2016-07-22 19:57:54 +02:00
|
|
|
#if SOURCE_ENGINE == SE_DOTA
|
2013-05-13 21:03:41 +02:00
|
|
|
void MetamodSource::ClientConPrintf(int clientIndex, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
ClientConPrintf((edict_t *)(gpGlobals->pEdicts + clientIndex), "%s", buffer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-14 11:04:02 +01:00
|
|
|
void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
provider->ClientConsolePrint(client, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetamodSource::EnableVSPListener()
|
|
|
|
{
|
|
|
|
if (is_game_init && !vsp_load_requested && !vsp_loaded)
|
2009-11-23 06:54:55 +01:00
|
|
|
{
|
2008-11-14 11:04:02 +01:00
|
|
|
InitializeVSP();
|
2009-11-23 06:54:55 +01:00
|
|
|
}
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
vsp_load_requested = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MetamodSource::GetVSPVersion()
|
|
|
|
{
|
|
|
|
return vsp_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MetamodSource::GetGameDLLVersion()
|
|
|
|
{
|
|
|
|
return gamedll_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MetamodSource::RemotePrintingAvailable()
|
|
|
|
{
|
|
|
|
return provider->IsRemotePrintingAvailable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
|
|
|
|
{
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
*id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!iface)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First check ours... we get first chance! */
|
|
|
|
if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
|
|
|
|
{
|
|
|
|
if (ret)
|
|
|
|
{
|
2015-01-21 01:30:13 +01:00
|
|
|
*ret = META_IFACE_OK;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
|
|
|
|
}
|
|
|
|
else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
|
|
|
|
{
|
|
|
|
if (ret)
|
|
|
|
{
|
2015-01-21 01:30:13 +01:00
|
|
|
*ret = META_IFACE_OK;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
|
|
|
|
}
|
|
|
|
else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
|
|
|
|
{
|
2017-12-20 08:11:57 +01:00
|
|
|
#if defined( _WIN64 ) || defined( __amd64__ )
|
2016-07-22 19:59:58 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
*ret = META_IFACE_FAILED;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
#else
|
2008-11-14 11:04:02 +01:00
|
|
|
if (ret)
|
|
|
|
{
|
2015-01-21 01:30:13 +01:00
|
|
|
*ret = META_IFACE_OK;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
|
2016-07-22 19:59:58 +02:00
|
|
|
#endif
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CPluginManager::CPlugin *pl;
|
|
|
|
List<IMetamodListener *>::iterator event;
|
|
|
|
IMetamodListener *api;
|
|
|
|
void *value;
|
|
|
|
|
|
|
|
int subret = 0;
|
|
|
|
for (PluginIter iter = g_PluginMngr._begin();
|
|
|
|
iter != g_PluginMngr._end();
|
|
|
|
iter++)
|
|
|
|
{
|
|
|
|
pl = (*iter);
|
|
|
|
for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
|
|
|
|
{
|
|
|
|
api = (*event);
|
2015-01-21 01:30:13 +01:00
|
|
|
subret = META_IFACE_FAILED;
|
2008-11-14 11:04:02 +01:00
|
|
|
if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
|
|
|
|
{
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
*ret = subret;
|
|
|
|
}
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
*id = pl->m_Id;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
2015-01-21 01:30:13 +01:00
|
|
|
*ret = META_IFACE_FAILED;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
|
|
|
|
{
|
|
|
|
CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
|
|
|
|
|
|
|
|
pl->m_Events.push_back(pListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *MetamodSource::GetGameBinaryPath()
|
|
|
|
{
|
|
|
|
return full_bin_path.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *MetamodSource::GetPluginsFile()
|
|
|
|
{
|
|
|
|
return provider->GetConVarString(mm_pluginsfile);
|
|
|
|
}
|
|
|
|
|
2008-11-24 14:25:46 +01:00
|
|
|
const char *MetamodSource::GetVDFDir()
|
|
|
|
{
|
|
|
|
return provider->GetConVarString(mm_basedir);
|
|
|
|
}
|
|
|
|
|
2008-11-14 11:04:02 +01:00
|
|
|
IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
|
|
|
|
{
|
|
|
|
return provider->GetConCommandBaseAccessor();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
|
|
|
|
{
|
|
|
|
if (provider->IsConCommandBaseACommand(pCommand))
|
|
|
|
{
|
|
|
|
g_PluginMngr.AddPluginCmd(plugin, pCommand);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_PluginMngr.AddPluginCvar(plugin, pCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
return provider->RegisterConCommandBase(pCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
|
|
|
|
{
|
|
|
|
if (provider->IsConCommandBaseACommand(pCommand))
|
|
|
|
{
|
|
|
|
g_PluginMngr.RemovePluginCmd(plugin, pCommand);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_PluginMngr.RemovePluginCvar(plugin, pCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
|
|
|
|
UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
|
|
|
|
{
|
|
|
|
PluginIter iter;
|
|
|
|
CPluginManager::CPlugin *pPlugin;
|
|
|
|
List<IMetamodListener *>::iterator event;
|
|
|
|
IMetamodListener *pML;
|
|
|
|
for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
|
|
|
|
{
|
|
|
|
pPlugin = (*iter);
|
|
|
|
if (pPlugin->m_Status < Pl_Paused)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
|
|
|
|
if (pPlugin->m_API->GetApiVersion() < 12)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (event=pPlugin->m_Events.begin();
|
|
|
|
event!=pPlugin->m_Events.end();
|
|
|
|
event++)
|
|
|
|
{
|
|
|
|
pML = (*event);
|
|
|
|
pML->OnUnlinkConCommandBase(id, pCommand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return provider->UnregisterConCommandBase(pCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
int MetamodSource::GetUserMessageCount()
|
|
|
|
{
|
|
|
|
return provider->GetUserMessageCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
|
|
|
|
{
|
|
|
|
return provider->FindUserMessage(name, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
|
|
|
|
{
|
|
|
|
return provider->GetUserMessage(index, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int MetamodSource::GetSourceEngineBuild()
|
|
|
|
{
|
|
|
|
return engine_build;
|
|
|
|
}
|
|
|
|
|
2008-11-24 06:54:03 +01:00
|
|
|
void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks, int version)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
2008-11-24 06:54:03 +01:00
|
|
|
if (version != -1)
|
|
|
|
vsp_version = version;
|
|
|
|
|
2008-11-24 06:45:57 +01:00
|
|
|
vsp_callbacks = callbacks;
|
2008-11-14 11:04:02 +01:00
|
|
|
ITER_EVENT(OnVSPListening, (callbacks));
|
2009-11-23 06:54:55 +01:00
|
|
|
|
|
|
|
if (is_gamedll_loaded)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* MM:S is loaded as a game DLL so we need to set these for mm_IsVspBridged() and
|
|
|
|
* mm_IsVspLoadComplete()
|
|
|
|
*/
|
|
|
|
g_bIsVspBridged = true;
|
|
|
|
were_plugins_loaded = true;
|
|
|
|
}
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
|
|
|
|
{
|
|
|
|
if (pVersion)
|
|
|
|
{
|
|
|
|
*pVersion = vsp_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vsp_callbacks;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
size_t result;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
result = FormatArgs(buffer, maxlength, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
|
|
|
|
{
|
|
|
|
return UTIL_FormatArgs(buffer, maxlength, format, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MetamodSource::IsLoadedAsGameDLL()
|
|
|
|
{
|
|
|
|
return is_gamedll_loaded;
|
|
|
|
}
|
|
|
|
|
2008-11-24 06:22:33 +01:00
|
|
|
void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
gamedll_info.factory = serverFactory;
|
|
|
|
gamedll_version = version;
|
2008-11-24 06:22:33 +01:00
|
|
|
is_gamedll_loaded = loaded;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
2009-11-23 06:54:55 +01:00
|
|
|
void MetamodSource::SetVSPListener(const char *path)
|
|
|
|
{
|
|
|
|
metamod_path.assign(path);
|
|
|
|
}
|
|
|
|
|
2010-05-19 08:28:55 +02:00
|
|
|
size_t MetamodSource::GetFullPluginPath(const char *plugin, char *buffer, size_t len)
|
|
|
|
{
|
|
|
|
const char *pext, *ext;
|
|
|
|
size_t num;
|
|
|
|
|
|
|
|
/* First find if it's an absolute path or not... */
|
|
|
|
if (plugin[0] == '/' || strncmp(&(plugin[1]), ":\\", 2) == 0)
|
|
|
|
{
|
|
|
|
return UTIL_Format(buffer, len, plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attempt to find a file extension */
|
|
|
|
pext = UTIL_GetExtension(plugin);
|
|
|
|
/* Add an extension if there's none there */
|
|
|
|
if (!pext)
|
|
|
|
{
|
2017-12-20 08:11:57 +01:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
|
|
#if defined(WIN64) || defined(_WIN64)
|
|
|
|
ext = X64_SUFFIX BINARY_EXT;
|
|
|
|
#else
|
|
|
|
ext = BINARY_EXT;
|
|
|
|
#endif
|
2010-05-19 08:28:55 +02:00
|
|
|
#elif defined __APPLE__
|
2017-12-20 08:11:57 +01:00
|
|
|
#if defined (__x86_64__)
|
|
|
|
ext = X64_SUFFIX BINARY_EXT;
|
|
|
|
#else
|
|
|
|
ext = BINARY_EXT;
|
|
|
|
#endif
|
2010-05-19 08:28:55 +02:00
|
|
|
#else
|
2017-12-20 08:11:57 +01:00
|
|
|
#if defined(__x86_64__)
|
|
|
|
ext = X64_SUFFIX BINARY_EXT;
|
|
|
|
#else
|
|
|
|
ext = "_i486" BINARY_EXT;
|
|
|
|
#endif
|
2010-05-19 08:28:55 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ext = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the new path */
|
|
|
|
num = PathFormat(buffer, len, "%s/%s%s", mod_path.c_str(), plugin, ext);
|
|
|
|
|
2017-12-20 08:11:57 +01:00
|
|
|
/* If path was passed without extension and it doesn't exist with "<suffix>.<ext>" try ".<ext>" */
|
|
|
|
#if defined(WIN64) || defined (_WIN64) || defined(__linux__) || defined(__x86_64__)
|
2010-05-19 08:28:55 +02:00
|
|
|
struct stat s;
|
|
|
|
if (!pext && stat(buffer, &s) != 0)
|
|
|
|
{
|
2017-12-20 08:11:57 +01:00
|
|
|
num = PathFormat(buffer, len, "%s/%s" BINARY_EXT, mod_path.c_str(), plugin);
|
2010-05-19 08:28:55 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2008-11-24 14:25:46 +01:00
|
|
|
static bool
|
|
|
|
ProcessVDF(const char *path, bool &skipped)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
|
|
|
PluginId id;
|
|
|
|
bool already;
|
2008-12-23 05:55:55 +01:00
|
|
|
char alias[24], file[255], full_path[255], error[255];
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
|
2008-11-24 14:25:46 +01:00
|
|
|
{
|
|
|
|
skipped = false;
|
|
|
|
return false;
|
|
|
|
}
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
if (alias[0] != '\0')
|
|
|
|
g_PluginMngr.SetAlias(alias, file);
|
|
|
|
|
2010-05-19 08:28:55 +02:00
|
|
|
g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
|
2008-12-23 05:55:55 +01:00
|
|
|
|
|
|
|
id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
|
2008-11-24 14:25:46 +01:00
|
|
|
skipped = already;
|
2008-11-14 11:04:02 +01:00
|
|
|
if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
|
2008-11-24 14:25:46 +01:00
|
|
|
{
|
2008-11-16 10:41:17 +01:00
|
|
|
mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
|
2008-11-24 14:25:46 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
2008-11-24 14:25:46 +01:00
|
|
|
static int
|
|
|
|
LoadVDFPluginsFromDir(const char *dir, int &skipped)
|
2008-11-14 11:04:02 +01:00
|
|
|
{
|
2008-11-24 14:25:46 +01:00
|
|
|
bool success, skip;
|
|
|
|
int total = 0;
|
2008-11-14 11:04:02 +01:00
|
|
|
char path[MAX_PATH];
|
2008-11-19 08:17:48 +01:00
|
|
|
char relpath[MAX_PATH * 2];
|
2008-11-14 11:04:02 +01:00
|
|
|
|
2008-11-24 14:25:46 +01:00
|
|
|
skipped = 0;
|
|
|
|
|
2008-11-14 11:04:02 +01:00
|
|
|
#if defined _MSC_VER
|
|
|
|
HANDLE hFind;
|
|
|
|
WIN32_FIND_DATA fd;
|
|
|
|
char error[255];
|
|
|
|
|
2008-11-19 08:14:16 +01:00
|
|
|
g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
|
2008-11-14 11:04:02 +01:00
|
|
|
if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
DWORD dw = GetLastError();
|
2008-11-19 08:14:16 +01:00
|
|
|
if (dw == ERROR_FILE_NOT_FOUND)
|
2008-11-24 14:25:46 +01:00
|
|
|
return 0;
|
2008-11-19 08:14:16 +01:00
|
|
|
|
2008-11-14 11:04:02 +01:00
|
|
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL,
|
|
|
|
dw,
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
|
error,
|
|
|
|
sizeof(error),
|
|
|
|
NULL);
|
2008-11-16 10:41:17 +01:00
|
|
|
mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
|
2008-11-24 14:25:46 +01:00
|
|
|
return 0;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
|
2008-11-19 08:17:48 +01:00
|
|
|
UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
|
2008-11-24 14:25:46 +01:00
|
|
|
success = ProcessVDF(relpath, skip);
|
|
|
|
if (skip)
|
|
|
|
skipped++;
|
|
|
|
else if (success)
|
|
|
|
total++;
|
2008-11-14 11:04:02 +01:00
|
|
|
} while (FindNextFile(hFind, &fd));
|
|
|
|
|
|
|
|
FindClose(hFind);
|
|
|
|
#else
|
|
|
|
DIR *pDir;
|
|
|
|
struct dirent *pEnt;
|
2008-11-19 08:14:16 +01:00
|
|
|
int extidx;
|
2008-11-14 11:04:02 +01:00
|
|
|
|
|
|
|
if ((pDir = opendir(dir)) == NULL)
|
|
|
|
{
|
2008-11-16 10:41:17 +01:00
|
|
|
mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
|
2008-11-24 14:25:46 +01:00
|
|
|
return 0;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((pEnt = readdir(pDir)) != NULL)
|
|
|
|
{
|
|
|
|
if (strcmp(pEnt->d_name, ".") == 0
|
|
|
|
|| strcmp(pEnt->d_name, "..") == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
extidx = strlen(pEnt->d_name) - 4;
|
|
|
|
if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
|
2008-11-19 08:17:48 +01:00
|
|
|
UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
|
2008-11-24 14:25:46 +01:00
|
|
|
success = ProcessVDF(relpath, skip);
|
|
|
|
if (skip)
|
|
|
|
skipped++;
|
|
|
|
else if (success)
|
|
|
|
total++;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir(pDir);
|
|
|
|
#endif
|
2008-11-24 14:25:46 +01:00
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mm_LoadPlugins(const char *filepath, const char *vdfpath)
|
|
|
|
{
|
|
|
|
int total, skipped, fskipped, vskipped;
|
|
|
|
const char *s = "";
|
|
|
|
|
|
|
|
total = LoadPluginsFromFile(filepath, fskipped);
|
|
|
|
total += LoadVDFPluginsFromDir(vdfpath, vskipped);
|
|
|
|
skipped = fskipped + vskipped;
|
|
|
|
|
|
|
|
if (total == 0 || total > 1)
|
|
|
|
s = "s";
|
|
|
|
|
|
|
|
if (skipped)
|
|
|
|
mm_LogMessage("[META] Loaded %d plugin%s (%d already loaded)", total, s, skipped);
|
|
|
|
else
|
|
|
|
mm_LogMessage("[META] Loaded %d plugin%s.", total, s);
|
|
|
|
|
|
|
|
return total;
|
2008-11-14 11:04:02 +01:00
|
|
|
}
|
2008-11-16 06:46:27 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
mm_IsVspBridged()
|
|
|
|
{
|
|
|
|
return g_bIsVspBridged;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
mm_IsVspLoadComplete()
|
|
|
|
{
|
|
|
|
return were_plugins_loaded;
|
|
|
|
}
|
|
|
|
|