1.1 --- a/sourcemm/metamod.cpp Sun Nov 25 01:22:41 2007 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,1272 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * ======================================================
1.7 - * Metamod:Source
1.8 - * Copyright (C) 2004-2007 AlliedModders LLC and authors.
1.9 - * All rights reserved.
1.10 - * ======================================================
1.11 - *
1.12 - * This software is provided 'as-is', without any express or implied warranty.
1.13 - * In no event will the authors be held liable for any damages arising from
1.14 - * the use of this software.
1.15 - *
1.16 - * Permission is granted to anyone to use this software for any purpose,
1.17 - * including commercial applications, and to alter it and redistribute it
1.18 - * freely, subject to the following restrictions:
1.19 - *
1.20 - * 1. The origin of this software must not be misrepresented; you must not
1.21 - * claim that you wrote the original software. If you use this software in a
1.22 - * product, an acknowledgment in the product documentation would be
1.23 - * appreciated but is not required.
1.24 - * 2. Altered source versions must be plainly marked as such, and must not be
1.25 - * misrepresented as being the original software.
1.26 - * 3. This notice may not be removed or altered from any source distribution.
1.27 - *
1.28 - * Version: $Id$
1.29 - */
1.30 -
1.31 -#if defined _DEBUG
1.32 -#define DEBUG2
1.33 -#undef _DEBUG
1.34 -#endif
1.35 -#include <interface.h>
1.36 -#include <eiface.h>
1.37 -#include "metamod.h"
1.38 -#include "metamod_provider.h"
1.39 -#include "metamod_plugins.h"
1.40 -#include "metamod_util.h"
1.41 -#include "metamod_console.h"
1.42 -#include "metamod_oslink.h"
1.43 -#if defined DEBUG2
1.44 -#undef DEBUG2
1.45 -#define _DEBUG
1.46 -#endif
1.47 -
1.48 -using namespace SourceMM;
1.49 -using namespace SourceHook;
1.50 -using namespace SourceHook::Impl;
1.51 -
1.52 -/**
1.53 - * @brief Implementation of main SourceMM GameDLL functionality
1.54 - * @file sourcemm.cpp
1.55 - */
1.56 -
1.57 -SH_DECL_MANUALHOOK4(SGD_DLLInit, 0, 0, 0, bool, CreateInterfaceFn, CreateInterfaceFn, CreateInterfaceFn, CGlobalVars *);
1.58 -SH_DECL_MANUALHOOK0(SGD_GameInit, 0, 0, 0, bool);
1.59 -SH_DECL_MANUALHOOK6(SGD_LevelInit, 0, 0, 0, bool, const char *, const char *, const char *, const char *, bool, bool);
1.60 -SH_DECL_MANUALHOOK0_void(SGD_LevelShutdown, 0, 0, 0);
1.61 -SH_DECL_MANUALHOOK0_void(SGD_DLLShutdown, 0, 0, 0);
1.62 -
1.63 -bool Handler_DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
1.64 -bool Handler_DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
1.65 -void Handler_DLLShutdown();
1.66 -void Handler_LevelShutdown();
1.67 -bool Handler_LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
1.68 -bool Handler_GameInit();
1.69 -void InitializeVSP();
1.70 -
1.71 -struct game_dll_t
1.72 -{
1.73 - HINSTANCE lib;
1.74 - CreateInterfaceFn factory;
1.75 -};
1.76 -
1.77 -String mod_path;
1.78 -String metamod_path;
1.79 -String full_bin_path;
1.80 -bool parsed_game_info = false;
1.81 -int vsp_version = 0;
1.82 -int gamedll_version = 0;
1.83 -int engine_build = SOURCE_ENGINE_UNKNOWN;
1.84 -List<game_dll_t *> gamedll_list;
1.85 -bool is_gamedll_loaded = false;
1.86 -bool in_first_level = true;
1.87 -bool is_game_init = false;
1.88 -bool vsp_load_attempted = false;
1.89 -bool vsp_load_requested = false;
1.90 -bool vsp_loaded = false;
1.91 -game_dll_t gamedll_info;
1.92 -ConVar *metamod_version = NULL;
1.93 -ConVar *mm_pluginsfile = NULL;
1.94 -IServerGameDLL *server = NULL;
1.95 -CreateInterfaceFn engine_factory = NULL;
1.96 -CreateInterfaceFn physics_factory = NULL;
1.97 -CreateInterfaceFn filesystem_factory = NULL;
1.98 -CGlobalVars *gpGlobals = NULL;
1.99 -CSourceHookImpl g_SourceHook;
1.100 -CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
1.101 -ISourceHook *g_SHPtr = &g_SourceHook;
1.102 -PluginId g_PLID = Pl_Console;
1.103 -META_RES last_meta_res;
1.104 -IServerPluginCallbacks *vsp_callbacks = NULL;
1.105 -
1.106 -MetamodSource g_Metamod;
1.107 -
1.108 -void ClearGamedllList();
1.109 -
1.110 -/* Helper Macro */
1.111 -#define IFACE_MACRO(orig,nam) \
1.112 - CPluginManager::CPlugin *pl; \
1.113 - SourceHook::List<IMetamodListener *>::iterator event; \
1.114 - IMetamodListener *api; \
1.115 - int mret = 0; \
1.116 - void *val = NULL; \
1.117 - for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
1.118 - pl = (*iter); \
1.119 - for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
1.120 - api = (*event); \
1.121 - mret = IFACE_FAILED; \
1.122 - if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
1.123 - if (ret) *ret = mret; \
1.124 - return val; \
1.125 - } \
1.126 - } \
1.127 - } \
1.128 - return (orig)(iface, ret);
1.129 -
1.130 -#define ITER_EVENT(evn, args) \
1.131 - CPluginManager::CPlugin *pl; \
1.132 - SourceHook::List<IMetamodListener *>::iterator event; \
1.133 - IMetamodListener *api; \
1.134 - for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
1.135 - pl = (*iter); \
1.136 - for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
1.137 - api = (*event); \
1.138 - api->evn args; \
1.139 - } \
1.140 - }
1.141 -
1.142 -/* Initialize everything here */
1.143 -void InitMainStates()
1.144 -{
1.145 - char full_path[PATH_SIZE] = {0};
1.146 - GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
1.147 - full_bin_path.assign(full_path);
1.148 -
1.149 - /* Like Metamod, reload plugins at the end of the map.
1.150 - * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
1.151 - * if the server is shut down (silly, but rare case).
1.152 - */
1.153 - in_first_level = true;
1.154 -
1.155 - SourceHook::MemFuncInfo info;
1.156 -
1.157 - if (!provider->GetHookInfo(ProvidedHook_DLLInit, &info))
1.158 - {
1.159 - provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::DLLInit");
1.160 - }
1.161 - SH_MANUALHOOK_RECONFIGURE(SGD_DLLInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
1.162 - SH_ADD_MANUALHOOK_STATICFUNC(SGD_DLLInit, server, Handler_DLLInit, false);
1.163 - SH_ADD_MANUALHOOK_STATICFUNC(SGD_DLLInit, server, Handler_DLLInit_Post, true);
1.164 -
1.165 - if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
1.166 - {
1.167 - provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
1.168 - }
1.169 - SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
1.170 - SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
1.171 -
1.172 - if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
1.173 - {
1.174 - provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
1.175 - }
1.176 - SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
1.177 - SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
1.178 -
1.179 - if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
1.180 - {
1.181 - provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
1.182 - }
1.183 - SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
1.184 - SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
1.185 -
1.186 - if (!provider->GetHookInfo(ProvidedHook_DLLShutdown, &info))
1.187 - {
1.188 - provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::DLLShutdown");
1.189 - }
1.190 - SH_MANUALHOOK_RECONFIGURE(SGD_DLLShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
1.191 - SH_ADD_MANUALHOOK_STATICFUNC(SGD_DLLShutdown, server, Handler_DLLShutdown, false);
1.192 -}
1.193 -
1.194 -/* This is where the magic happens */
1.195 -SMM_API void *CreateInterface(const char *iface, int *ret)
1.196 -{
1.197 - /* Prevent loading of self as a SourceMM plugin or Valve server plugin :x */
1.198 - if (strcmp(iface, METAMOD_PLAPI_NAME) == 0)
1.199 - {
1.200 - provider->DisplayWarning("Do not try loading Metamod:Source as a plugin.\n");
1.201 -
1.202 - if (ret)
1.203 - {
1.204 - *ret = IFACE_FAILED;
1.205 - }
1.206 -
1.207 - return NULL;
1.208 - }
1.209 -
1.210 - if (strncmp(iface, "ISERVERPLUGINCALLBACKS", 22) == 0)
1.211 - {
1.212 - vsp_callbacks = provider->GetVSPCallbacks(iface);
1.213 -
1.214 - if (vsp_callbacks != NULL && vsp_version == 0)
1.215 - {
1.216 - vsp_version = atoi(&iface[22]);
1.217 - }
1.218 -
1.219 - if (ret)
1.220 - {
1.221 - *ret = (vsp_callbacks != NULL) ? IFACE_OK : IFACE_FAILED;
1.222 - }
1.223 -
1.224 - return vsp_callbacks;
1.225 - }
1.226 -
1.227 - if (!parsed_game_info)
1.228 - {
1.229 - parsed_game_info = true;
1.230 - const char *game_dir = NULL;
1.231 - char game_path[PATH_SIZE];
1.232 - char mm_path[PATH_SIZE];
1.233 -
1.234 - /* Get path to SourceMM DLL */
1.235 - if (!GetFileOfAddress((void *)CreateInterface, mm_path, sizeof(mm_path)))
1.236 - {
1.237 - provider->DisplayError("GetFileOfAddress() failed! Metamod cannot load.\n");
1.238 - return NULL;
1.239 - }
1.240 -
1.241 - metamod_path.assign(mm_path);
1.242 -
1.243 - /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
1.244 - game_dir = provider->GetCommandLineValue("-game", "hl2");
1.245 -
1.246 - engine_build = provider->DetermineSourceEngine(game_dir);;
1.247 -
1.248 - /* Get absolute path */
1.249 - abspath(game_path, game_dir);
1.250 - mod_path.assign(game_path);
1.251 -
1.252 - char temp_path[PATH_SIZE];
1.253 -
1.254 - /* Path to gameinfo.txt */
1.255 - g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s", mod_path.c_str(), "gameinfo.txt");
1.256 -
1.257 - FILE *fp = fopen(temp_path, "rt");
1.258 -
1.259 - if (!fp)
1.260 - {
1.261 - provider->DisplayError("Unable to open gameinfo.txt! Metamod cannot load.\n");
1.262 - return NULL;
1.263 - }
1.264 -
1.265 - char buffer[255];
1.266 - char key[128], val[128];
1.267 - bool search = false;
1.268 - bool gamebin = false;
1.269 - char *ptr;
1.270 - const char *lptr;
1.271 - char cur_path[PATH_SIZE];
1.272 -
1.273 - getcwd(cur_path, PATH_SIZE);
1.274 -
1.275 - while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
1.276 - {
1.277 - UTIL_TrimComments(buffer);
1.278 - UTIL_TrimLeft(buffer);
1.279 - UTIL_TrimRight(buffer);
1.280 -
1.281 - if (stricmp(buffer, "SearchPaths") == 0)
1.282 - {
1.283 - search = true;
1.284 - }
1.285 -
1.286 - if (!search)
1.287 - {
1.288 - continue;
1.289 - }
1.290 -
1.291 - UTIL_KeySplit(buffer, key, sizeof(key) - 1, val, sizeof(val) - 1);
1.292 - if (stricmp(key, "Game") == 0 || stricmp(key, "GameBin") == 0)
1.293 - {
1.294 - if (stricmp(key, "Game") == 0)
1.295 - {
1.296 - gamebin = false;
1.297 - }
1.298 - else
1.299 - {
1.300 - gamebin = true;
1.301 - }
1.302 -
1.303 - if (strncmp(val, "|gameinfo_path|", sizeof("|gameinfo_path|") - 1) == 0)
1.304 - {
1.305 - ptr = &(val[sizeof("|gameinfo_path|") - 1]);
1.306 - if (ptr[0] == '.')
1.307 - {
1.308 - ptr++;
1.309 - }
1.310 - lptr = mod_path.c_str();
1.311 - } else {
1.312 - ptr = val;
1.313 - lptr = cur_path;
1.314 - }
1.315 -
1.316 - size_t ptr_len = strlen(ptr);
1.317 - if (ptr[ptr_len] == '/' || ptr[ptr_len] == '\\')
1.318 - {
1.319 - ptr[--ptr_len] = '\0';
1.320 - }
1.321 -
1.322 - /* No need to append "bin" if key is GameBin */
1.323 - if (gamebin)
1.324 - {
1.325 - g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s/%s", lptr, ptr, SERVER_DLL);
1.326 - }
1.327 - else if (!ptr[0])
1.328 - {
1.329 - g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s/%s", lptr, "bin", SERVER_DLL);
1.330 - }
1.331 - else
1.332 - {
1.333 - g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s/%s/%s", lptr, ptr, "bin", SERVER_DLL);
1.334 - }
1.335 -
1.336 - /* If not path to SourceMM... */
1.337 - if (!UTIL_PathCmp(mm_path, temp_path))
1.338 - {
1.339 - FILE *temp_fp = fopen(temp_path, "rb");
1.340 - if (!temp_fp)
1.341 - {
1.342 - continue;
1.343 - }
1.344 - fclose(temp_fp);
1.345 -
1.346 - /* Search for a matching game dll */
1.347 - List<game_dll_t *>::iterator iter;
1.348 - game_dll_t *pCheck;
1.349 - bool found = false;
1.350 - for (iter = gamedll_list.begin(); iter != gamedll_list.end(); iter++)
1.351 - {
1.352 - pCheck = (*iter);
1.353 - if (GetFileOfAddress((void *)pCheck->factory, buffer, sizeof(buffer)))
1.354 - {
1.355 - if (UTIL_PathCmp(temp_path, buffer))
1.356 - {
1.357 - found = true;
1.358 - break;
1.359 - }
1.360 - }
1.361 - }
1.362 -
1.363 - if (found)
1.364 - {
1.365 - continue;
1.366 - }
1.367 -
1.368 - HINSTANCE gamedll = dlmount(temp_path);
1.369 - if (gamedll == NULL)
1.370 - {
1.371 - continue;
1.372 - }
1.373 -
1.374 - CreateInterfaceFn fn = (CreateInterfaceFn)dlsym(gamedll, "CreateInterface");
1.375 - if (fn == NULL)
1.376 - {
1.377 - dlclose(gamedll);
1.378 - continue;
1.379 - }
1.380 -
1.381 - game_dll_t *pInfo = new game_dll_t;
1.382 - pInfo->factory = fn;
1.383 - pInfo->lib = gamedll;
1.384 - gamedll_list.push_back(pInfo);
1.385 - break;
1.386 - }
1.387 - }
1.388 - }
1.389 - fclose(fp);
1.390 - }
1.391 -
1.392 - if (!is_gamedll_loaded)
1.393 - {
1.394 - if (strncmp(iface, "ServerGameDLL", 13) == 0)
1.395 - {
1.396 - List<game_dll_t *>::iterator iter;
1.397 - game_dll_t *pInfo;
1.398 - for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
1.399 - {
1.400 - pInfo = (*iter);
1.401 - if ((server = (IServerGameDLL *)((pInfo->factory)(iface, ret))) != NULL)
1.402 - {
1.403 - if ((gamedll_version = provider->TryServerGameDLL(iface)) != 0)
1.404 - {
1.405 - /* We have a match. Erase us from the list and save our info. */
1.406 - gamedll_list.erase(iter);
1.407 - gamedll_info = *pInfo;
1.408 - delete pInfo;
1.409 - is_gamedll_loaded = true;
1.410 - break;
1.411 - }
1.412 - /* :TODO: error otherwise? */
1.413 - }
1.414 - }
1.415 -
1.416 - if (is_gamedll_loaded)
1.417 - {
1.418 - ClearGamedllList();
1.419 - InitMainStates();
1.420 - }
1.421 - else
1.422 - {
1.423 - if (ret)
1.424 - {
1.425 - *ret = IFACE_FAILED;
1.426 - }
1.427 - return NULL;
1.428 - }
1.429 - }
1.430 - else
1.431 - {
1.432 - /* wtf do we do... */
1.433 - /* :TODO: .. something a bit more intelligent? */
1.434 - provider->DisplayError("Engine requested unknown interface before GameDLL was known!\n");
1.435 - return NULL;
1.436 - }
1.437 - }
1.438 -
1.439 - /* If we got here, there's definitely a GameDLL */
1.440 - IFACE_MACRO(gamedll_info.factory, GameDLL);
1.441 -}
1.442 -
1.443 -void ClearGamedllList()
1.444 -{
1.445 - List<game_dll_t *>::iterator iter;
1.446 -
1.447 - game_dll_t *pInfo;
1.448 - for (iter = gamedll_list.begin(); iter != gamedll_list.end(); iter++)
1.449 - {
1.450 - pInfo = (*iter);
1.451 - dlclose(pInfo->lib);
1.452 - delete pInfo;
1.453 - }
1.454 -
1.455 - gamedll_list.clear();
1.456 -}
1.457 -
1.458 -int LoadPluginsFromFile(const char *_file)
1.459 -{
1.460 - FILE *fp;
1.461 - int total = 0, skipped=0;
1.462 - PluginId id;
1.463 - bool already;
1.464 -
1.465 - fp = fopen(_file, "rt");
1.466 - if (!fp)
1.467 - {
1.468 - LogMessage("[META] Could not open plugins file %s\n", _file);
1.469 - return -1;
1.470 - }
1.471 -
1.472 - char buffer[255], error[255], full_path[255];
1.473 - const char *ptr, *ext, *file;
1.474 - size_t length;
1.475 - while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
1.476 - {
1.477 - UTIL_TrimLeft(buffer);
1.478 - UTIL_TrimRight(buffer);
1.479 -
1.480 - length = strlen(buffer);
1.481 - if (!length)
1.482 - {
1.483 - continue;
1.484 - }
1.485 -
1.486 - if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
1.487 - {
1.488 - continue;
1.489 - }
1.490 -
1.491 - file = buffer;
1.492 - if (buffer[0] == '"')
1.493 - {
1.494 - char *cptr = buffer;
1.495 - file = ++cptr;
1.496 -
1.497 - while (*cptr)
1.498 - {
1.499 - if (*cptr == '"')
1.500 - {
1.501 - *cptr = '\0';
1.502 - break;
1.503 - }
1.504 - cptr++;
1.505 - }
1.506 - }
1.507 - else
1.508 - {
1.509 - char *cptr = buffer;
1.510 - while (*cptr)
1.511 - {
1.512 - if (isspace(*cptr))
1.513 - {
1.514 - char *optr = cptr;
1.515 - while (*cptr && isspace(*cptr))
1.516 - {
1.517 - cptr++;
1.518 - }
1.519 - *optr = '\0';
1.520 - UTIL_TrimRight(cptr);
1.521 - if (*cptr && isalpha(*cptr))
1.522 - {
1.523 - g_PluginMngr.SetAlias(buffer, cptr);
1.524 - file = cptr;
1.525 - }
1.526 - break;
1.527 - }
1.528 - cptr++;
1.529 - }
1.530 - }
1.531 - if (!file[0])
1.532 - {
1.533 - continue;
1.534 - }
1.535 - /* First find if it's an absolute path or not... */
1.536 - if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
1.537 - {
1.538 - /* If we're in an absolute path, ignore our normal heuristics */
1.539 - id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
1.540 - if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1.541 - {
1.542 - LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
1.543 - }
1.544 - else
1.545 - {
1.546 - if (already)
1.547 - {
1.548 - skipped++;
1.549 - }
1.550 - else
1.551 - {
1.552 - total++;
1.553 - }
1.554 - }
1.555 - }
1.556 - else
1.557 - {
1.558 - /* Attempt to find a file extension */
1.559 - ptr = UTIL_GetExtension(file);
1.560 - /* Add an extension if there's none there */
1.561 - if (!ptr)
1.562 - {
1.563 -#if defined WIN32 || defined _WIN32
1.564 - ext = ".dll";
1.565 -#else
1.566 - ext = "_i486.so";
1.567 -#endif
1.568 - }
1.569 - else
1.570 - {
1.571 - ext = "";
1.572 - }
1.573 - /* Format the new path */
1.574 - g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
1.575 - id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
1.576 - if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1.577 - {
1.578 - LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
1.579 - }
1.580 - else
1.581 - {
1.582 - if (already)
1.583 - {
1.584 - skipped++;
1.585 - }
1.586 - else
1.587 - {
1.588 - total++;
1.589 - }
1.590 - }
1.591 - }
1.592 - }
1.593 - fclose(fp);
1.594 -
1.595 - if (skipped)
1.596 - {
1.597 - LogMessage("[META] Loaded %d plugins from file (%d already loaded)", total, skipped);
1.598 - }
1.599 - else
1.600 - {
1.601 - LogMessage("[META] Loaded %d plugins from file.", total);
1.602 - }
1.603 -
1.604 - return total;
1.605 -}
1.606 -
1.607 -void InitializeVSP()
1.608 -{
1.609 - size_t len;
1.610 - char engine_file[PATH_SIZE];
1.611 - char engine_path[PATH_SIZE];
1.612 - char rel_path[PATH_SIZE * 2];
1.613 -
1.614 - GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
1.615 -
1.616 - /* Chop off the "engine" file part */
1.617 - len = strlen(engine_file);
1.618 - for (size_t i = len - 1; i >= 0 && i < len; i--)
1.619 - {
1.620 - if (engine_file[i] == '/' || engine_file[i] == '\\')
1.621 - {
1.622 - engine_file[i] = '\0';
1.623 - break;
1.624 - }
1.625 - }
1.626 - abspath(engine_path, engine_file);
1.627 -
1.628 - const char *usepath = metamod_path.c_str();
1.629 - if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
1.630 - {
1.631 - usepath = rel_path;
1.632 - }
1.633 -
1.634 - char command[PATH_SIZE * 2];
1.635 - UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
1.636 - provider->ServerCommand(command);
1.637 -}
1.638 -
1.639 -/* Wrapper function. This is called when the GameDLL thinks it's using
1.640 - * the engine's real engineFactory.
1.641 - */
1.642 -void *EngineFactory(const char *iface, int *ret)
1.643 -{
1.644 - IFACE_MACRO(engine_factory, Engine);
1.645 -}
1.646 -
1.647 -/* Wrapper function. This is called when the GameDLL thinks it's using
1.648 - * the engine's real physicsFactory.
1.649 - */
1.650 -void *PhysicsFactory(const char *iface, int *ret)
1.651 -{
1.652 - IFACE_MACRO(physics_factory, Physics);
1.653 -}
1.654 -
1.655 -/* Wrapper function. This is called when the GameDLL thinks it's using
1.656 - * the engine's real fileSystemFactory.
1.657 - */
1.658 -void *FileSystemFactory(const char *iface, int *ret)
1.659 -{
1.660 - IFACE_MACRO(filesystem_factory, FileSystem);
1.661 -}
1.662 -
1.663 -void LogMessage(const char *msg, ...)
1.664 -{
1.665 - va_list ap;
1.666 - static char buffer[2048];
1.667 -
1.668 - va_start(ap, msg);
1.669 - size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
1.670 - va_end(ap);
1.671 -
1.672 - buffer[len++] = '\n';
1.673 - buffer[len] = '\0';
1.674 -
1.675 - if (!provider->LogMessage(buffer))
1.676 - {
1.677 - fprintf(stdout, "%s", buffer);
1.678 - }
1.679 -}
1.680 -
1.681 -bool Handler_DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
1.682 -{
1.683 - engine_factory = engineFactory;
1.684 - filesystem_factory = filesystemFactory;
1.685 - physics_factory = physicsFactory;
1.686 - gpGlobals = pGlobals;
1.687 -
1.688 - provider->Notify_DLLInit_Pre(server, engineFactory, gamedll_info.factory);
1.689 -
1.690 - metamod_version = provider->CreateConVar("metamod_version",
1.691 - SOURCEMM_VERSION,
1.692 - "Metamod:Source Version",
1.693 - ConVarFlag_Notify|ConVarFlag_Replicated|ConVarFlag_SpOnly);
1.694 -
1.695 - mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
1.696 -#if defined WIN32 || defined _WIN32
1.697 - "addons\\metamod\\metaplugins.ini",
1.698 -#else
1.699 - "addons/metamod/metaplugins.ini",
1.700 -#endif
1.701 - "Metamod:Source Plugins File",
1.702 - ConVarFlag_SpOnly);
1.703 -
1.704 - const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
1.705 - if (!pluginFile)
1.706 - {
1.707 - pluginFile = provider->GetConVarString(mm_pluginsfile);
1.708 - if (pluginFile == NULL)
1.709 - {
1.710 - pluginFile = "addons/metamod/metaplugins.ini";
1.711 - }
1.712 - }
1.713 -
1.714 - char full_path[260];
1.715 - g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), pluginFile);
1.716 -
1.717 - LoadPluginsFromFile(full_path);
1.718 -
1.719 - in_first_level = true;
1.720 -
1.721 - RETURN_META_VALUE(MRES_IGNORED, true);
1.722 -}
1.723 -
1.724 -bool Handler_GameInit()
1.725 -{
1.726 - if (is_game_init)
1.727 - {
1.728 - return true;
1.729 - }
1.730 -
1.731 - if (vsp_load_requested)
1.732 - {
1.733 - InitializeVSP();
1.734 - }
1.735 -
1.736 - is_game_init = true;
1.737 -
1.738 - RETURN_META_VALUE(MRES_IGNORED, true);
1.739 -}
1.740 -
1.741 -bool Handler_DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
1.742 -{
1.743 - g_PluginMngr.SetAllLoaded();
1.744 - RETURN_META_VALUE(MRES_IGNORED, true);
1.745 -}
1.746 -
1.747 -void Handler_DLLShutdown()
1.748 -{
1.749 - /* Unload plugins */
1.750 - g_PluginMngr.UnloadAll();
1.751 -
1.752 - provider->Notify_DLLShutdown_Pre();
1.753 -
1.754 - SH_CALL(server, &IServerGameDLL::DLLShutdown)();
1.755 -
1.756 - g_SourceHook.CompleteShutdown();
1.757 -
1.758 - if (is_gamedll_loaded && gamedll_info.lib)
1.759 - {
1.760 - dlclose(gamedll_info.lib);
1.761 - is_gamedll_loaded = false;
1.762 - }
1.763 -
1.764 - RETURN_META(MRES_SUPERCEDE);
1.765 -}
1.766 -
1.767 -void Handler_LevelShutdown(void)
1.768 -{
1.769 - if (!in_first_level)
1.770 - {
1.771 - char full_path[255];
1.772 - g_Metamod.PathFormat(full_path,
1.773 - sizeof(full_path),
1.774 - "%s/%s",
1.775 - mod_path.c_str(),
1.776 - provider->GetConVarString(mm_pluginsfile));
1.777 -
1.778 - LoadPluginsFromFile(full_path);
1.779 - }
1.780 - else
1.781 - {
1.782 - in_first_level = false;
1.783 - }
1.784 -
1.785 - ITER_EVENT(OnLevelShutdown, ());
1.786 -
1.787 - RETURN_META(MRES_IGNORED);
1.788 -}
1.789 -
1.790 -bool Handler_LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
1.791 -{
1.792 - ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
1.793 -
1.794 - RETURN_META_VALUE(MRES_IGNORED, false);
1.795 -}
1.796 -
1.797 -void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
1.798 -{
1.799 - va_list ap;
1.800 - char buffer[2048];
1.801 -
1.802 - va_start(ap, msg);
1.803 - UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
1.804 - va_end(ap);
1.805 -
1.806 - LogMessage("[%s] %s", pl->GetLogTag(), buffer);
1.807 -}
1.808 -
1.809 -CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
1.810 -{
1.811 - if (syn)
1.812 - {
1.813 - return EngineFactory;
1.814 - }
1.815 -
1.816 - return engine_factory;
1.817 -}
1.818 -
1.819 -CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
1.820 -{
1.821 - if (syn)
1.822 - {
1.823 - return PhysicsFactory;
1.824 - }
1.825 -
1.826 - return physics_factory;
1.827 -}
1.828 -
1.829 -CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
1.830 -{
1.831 - if (syn)
1.832 - {
1.833 - return FileSystemFactory;
1.834 - }
1.835 -
1.836 - return filesystem_factory;
1.837 -}
1.838 -
1.839 -CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
1.840 -{
1.841 - if (syn)
1.842 - {
1.843 - return CreateInterface;
1.844 - }
1.845 -
1.846 - return gamedll_info.factory;
1.847 -}
1.848 -
1.849 -CGlobalVars *MetamodSource::GetCGlobals()
1.850 -{
1.851 - return gpGlobals;
1.852 -}
1.853 -
1.854 -void MetamodSource::SetLastMetaReturn(META_RES res)
1.855 -{
1.856 - last_meta_res = res;
1.857 -}
1.858 -
1.859 -META_RES MetamodSource::GetLastMetaReturn()
1.860 -{
1.861 - return last_meta_res;
1.862 -}
1.863 -
1.864 -void MetamodSource::ConPrint(const char *str)
1.865 -{
1.866 - provider->ConsolePrint(str);
1.867 -}
1.868 -
1.869 -void MetamodSource::ConPrintf(const char *fmt, ...)
1.870 -{
1.871 - va_list ap;
1.872 - char buffer[2048];
1.873 -
1.874 - va_start(ap, fmt);
1.875 - UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
1.876 - va_end(ap);
1.877 -
1.878 - provider->ConsolePrint(buffer);
1.879 -}
1.880 -
1.881 -void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
1.882 -{
1.883 - major = METAMOD_API_MAJOR;
1.884 - minor = METAMOD_API_MINOR;
1.885 - plvers = METAMOD_PLAPI_VERSION;
1.886 - plmin = PLAPI_MIN_VERSION;
1.887 -}
1.888 -
1.889 -void MetamodSource::GetShVersions(int &shvers, int &shimpl)
1.890 -{
1.891 - shvers = SH_IFACE_VERSION;
1.892 - shimpl = SH_IMPL_VERSION;
1.893 -}
1.894 -
1.895 -int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
1.896 -{
1.897 - int length = (int)strlen(iface);
1.898 - int i;
1.899 - int num = 0;
1.900 -
1.901 - for (i = length - 1; i >= 0; i--)
1.902 - {
1.903 - if (!isdigit(iface[i]))
1.904 - {
1.905 - if (i != length - 1)
1.906 - {
1.907 - num = 1;
1.908 - }
1.909 - break;
1.910 - }
1.911 - }
1.912 -
1.913 - if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
1.914 - {
1.915 - return -1;
1.916 - }
1.917 -
1.918 - if (i != length - 1)
1.919 - {
1.920 - num = atoi(&(iface[++i]));
1.921 - }
1.922 -
1.923 - num++;
1.924 -
1.925 - snprintf(&(iface[i]), 4, "%03d", num);
1.926 -
1.927 - return num;
1.928 -}
1.929 -
1.930 -void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
1.931 -{
1.932 - char _if[256]; /* assume no interface goes beyond this */
1.933 - size_t len = strlen(iface);
1.934 - int num = 0;
1.935 - void *pf = NULL;
1.936 -
1.937 - if (max > 999)
1.938 - {
1.939 - max = 999;
1.940 - }
1.941 -
1.942 - if (len + 4 > sizeof(_if))
1.943 - {
1.944 - if (ret)
1.945 - {
1.946 - *ret = IFACE_FAILED;
1.947 - }
1.948 - return NULL;
1.949 - }
1.950 -
1.951 - strcpy(_if, iface);
1.952 -
1.953 - do
1.954 - {
1.955 - if ((pf = (fn)(_if, ret)) != NULL)
1.956 - {
1.957 - break;
1.958 - }
1.959 - if (num > max)
1.960 - {
1.961 - break;
1.962 - }
1.963 - } while ((num = FormatIface(_if, len+1)));
1.964 -
1.965 - return pf;
1.966 -}
1.967 -
1.968 -void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
1.969 -{
1.970 - char buffer[256]; /* assume no interface will go beyond this */
1.971 - size_t len = strlen(iface);
1.972 - int ret; /* just in case something doesn't handle NULL properly */
1.973 -
1.974 - if (len > sizeof(buffer) - 4)
1.975 - {
1.976 - return NULL;
1.977 - }
1.978 -
1.979 - strcpy(buffer, iface);
1.980 -
1.981 - if (min != -1)
1.982 - {
1.983 - char *ptr = &buffer[len - 1];
1.984 - int digits = 0;
1.985 - while (isdigit(*ptr) && digits <=3)
1.986 - {
1.987 - *ptr = '\0';
1.988 - digits++;
1.989 - ptr--;
1.990 - }
1.991 - if (digits != 3)
1.992 - {
1.993 - /* for now, assume this is an error */
1.994 - strcpy(buffer, iface);
1.995 - }
1.996 - else
1.997 - {
1.998 - char num[4];
1.999 - min = (min == 0) ? 1 : min;
1.1000 - snprintf(num, sizeof(num), "%03d", min);
1.1001 - strcat(buffer, num);
1.1002 - }
1.1003 - }
1.1004 -
1.1005 - return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
1.1006 -}
1.1007 -
1.1008 -const char *MetamodSource::GetBaseDir()
1.1009 -{
1.1010 - return mod_path.c_str();
1.1011 -}
1.1012 -
1.1013 -size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
1.1014 -{
1.1015 - va_list ap;
1.1016 - va_start(ap, fmt);
1.1017 - size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
1.1018 - va_end(ap);
1.1019 -
1.1020 - for (size_t i = 0; i < mylen; i++)
1.1021 - {
1.1022 - if (buffer[i] == ALT_SEP_CHAR)
1.1023 - {
1.1024 - buffer[i] = PATH_SEP_CHAR;
1.1025 - }
1.1026 - }
1.1027 -
1.1028 - return mylen;
1.1029 -}
1.1030 -
1.1031 -void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
1.1032 -{
1.1033 - va_list ap;
1.1034 - char buffer[2048];
1.1035 -
1.1036 - va_start(ap, fmt);
1.1037 - UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
1.1038 - va_end(ap);
1.1039 -
1.1040 - provider->ClientConsolePrint(client, buffer);
1.1041 -}
1.1042 -
1.1043 -void MetamodSource::EnableVSPListener()
1.1044 -{
1.1045 - if (is_game_init && !vsp_load_requested && !vsp_loaded)
1.1046 - {
1.1047 - InitializeVSP();
1.1048 - }
1.1049 -
1.1050 - vsp_load_requested = true;
1.1051 -}
1.1052 -
1.1053 -int MetamodSource::GetVSPVersion()
1.1054 -{
1.1055 - return vsp_version;
1.1056 -}
1.1057 -
1.1058 -int MetamodSource::GetGameDLLVersion()
1.1059 -{
1.1060 - return gamedll_version;
1.1061 -}
1.1062 -
1.1063 -bool MetamodSource::RemotePrintingAvailable()
1.1064 -{
1.1065 - return provider->IsRemotePrintingAvailable();
1.1066 -}
1.1067 -
1.1068 -void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
1.1069 -{
1.1070 - if (id)
1.1071 - {
1.1072 - *id = 0;
1.1073 - }
1.1074 -
1.1075 - if (!iface)
1.1076 - {
1.1077 - return NULL;
1.1078 - }
1.1079 -
1.1080 - /* First check ours... we get first chance! */
1.1081 - if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
1.1082 - {
1.1083 - if (ret)
1.1084 - {
1.1085 - *ret = IFACE_OK;
1.1086 - }
1.1087 - return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
1.1088 - }
1.1089 - else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
1.1090 - {
1.1091 - if (ret)
1.1092 - {
1.1093 - *ret = IFACE_OK;
1.1094 - }
1.1095 - return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
1.1096 - }
1.1097 - else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
1.1098 - {
1.1099 - if (ret)
1.1100 - {
1.1101 - *ret = IFACE_OK;
1.1102 - }
1.1103 - return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
1.1104 - }
1.1105 -
1.1106 - CPluginManager::CPlugin *pl;
1.1107 - List<IMetamodListener *>::iterator event;
1.1108 - IMetamodListener *api;
1.1109 - void *value;
1.1110 -
1.1111 - int subret = 0;
1.1112 - for (PluginIter iter = g_PluginMngr._begin();
1.1113 - iter != g_PluginMngr._end();
1.1114 - iter++)
1.1115 - {
1.1116 - pl = (*iter);
1.1117 - for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
1.1118 - {
1.1119 - api = (*event);
1.1120 - subret = IFACE_FAILED;
1.1121 - if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
1.1122 - {
1.1123 - if (ret)
1.1124 - {
1.1125 - *ret = subret;
1.1126 - }
1.1127 - if (id)
1.1128 - {
1.1129 - *id = pl->m_Id;
1.1130 - }
1.1131 - return value;
1.1132 - }
1.1133 - }
1.1134 - }
1.1135 -
1.1136 - if (ret)
1.1137 - {
1.1138 - *ret = IFACE_FAILED;
1.1139 - }
1.1140 -
1.1141 - return NULL;
1.1142 -}
1.1143 -
1.1144 -void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
1.1145 -{
1.1146 - CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
1.1147 -
1.1148 - pl->m_Events.push_back(pListener);
1.1149 -}
1.1150 -
1.1151 -const char *MetamodSource::GetGameBinaryPath()
1.1152 -{
1.1153 - return full_bin_path.c_str();
1.1154 -}
1.1155 -
1.1156 -const char *MetamodSource::GetPluginsFile()
1.1157 -{
1.1158 - return provider->GetConVarString(mm_pluginsfile);
1.1159 -}
1.1160 -
1.1161 -IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
1.1162 -{
1.1163 - return provider->GetConCommandBaseAccessor();
1.1164 -}
1.1165 -
1.1166 -bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1.1167 -{
1.1168 - if (provider->IsConCommandBaseACommand(pCommand))
1.1169 - {
1.1170 - g_PluginMngr.AddPluginCmd(plugin, pCommand);
1.1171 - }
1.1172 - else
1.1173 - {
1.1174 - g_PluginMngr.AddPluginCvar(plugin, pCommand);
1.1175 - }
1.1176 -
1.1177 - return provider->RegisterConCommandBase(pCommand);
1.1178 -}
1.1179 -
1.1180 -void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1.1181 -{
1.1182 - if (provider->IsConCommandBaseACommand(pCommand))
1.1183 - {
1.1184 - g_PluginMngr.RemovePluginCmd(plugin, pCommand);
1.1185 - }
1.1186 - else
1.1187 - {
1.1188 - g_PluginMngr.RemovePluginCvar(plugin, pCommand);
1.1189 - }
1.1190 -
1.1191 - CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
1.1192 - UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
1.1193 -}
1.1194 -
1.1195 -void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
1.1196 -{
1.1197 - PluginIter iter;
1.1198 - CPluginManager::CPlugin *pPlugin;
1.1199 - List<IMetamodListener *>::iterator event;
1.1200 - IMetamodListener *pML;
1.1201 - for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
1.1202 - {
1.1203 - pPlugin = (*iter);
1.1204 - if (pPlugin->m_Status < Pl_Paused)
1.1205 - {
1.1206 - continue;
1.1207 - }
1.1208 - /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
1.1209 - if (pPlugin->m_API->GetApiVersion() < 12)
1.1210 - {
1.1211 - continue;
1.1212 - }
1.1213 - for (event=pPlugin->m_Events.begin();
1.1214 - event!=pPlugin->m_Events.end();
1.1215 - event++)
1.1216 - {
1.1217 - pML = (*event);
1.1218 - pML->OnUnlinkConCommandBase(id, pCommand);
1.1219 - }
1.1220 - }
1.1221 -
1.1222 - return provider->UnregisterConCommandBase(pCommand);
1.1223 -}
1.1224 -
1.1225 -int MetamodSource::GetUserMessageCount()
1.1226 -{
1.1227 - return provider->GetUserMessageCount();
1.1228 -}
1.1229 -
1.1230 -int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1.1231 -{
1.1232 - return provider->FindUserMessage(name, size);
1.1233 -}
1.1234 -
1.1235 -const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1.1236 -{
1.1237 - return provider->GetUserMessage(index, size);
1.1238 -}
1.1239 -
1.1240 -int MetamodSource::GetSourceEngineBuild()
1.1241 -{
1.1242 - return engine_build;
1.1243 -}
1.1244 -
1.1245 -void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks)
1.1246 -{
1.1247 - ITER_EVENT(OnVSPListening, (callbacks));
1.1248 -}
1.1249 -
1.1250 -IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
1.1251 -{
1.1252 - if (pVersion)
1.1253 - {
1.1254 - *pVersion = vsp_version;
1.1255 - }
1.1256 -
1.1257 - return vsp_callbacks;
1.1258 -}
1.1259 -
1.1260 -size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
1.1261 -{
1.1262 - va_list ap;
1.1263 - size_t result;
1.1264 -
1.1265 - va_start(ap, format);
1.1266 - result = FormatArgs(buffer, maxlength, format, ap);
1.1267 - va_end(ap);
1.1268 -
1.1269 - return result;
1.1270 -}
1.1271 -
1.1272 -size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
1.1273 -{
1.1274 - return UTIL_FormatArgs(buffer, maxlength, format, ap);
1.1275 -}