1.1 --- a/sourcemm/ISmmPlugin.h Fri Dec 14 14:55:37 2007 +0000
1.2 +++ b/sourcemm/ISmmPlugin.h Mon Dec 24 17:00:22 2007 +0000
1.3 @@ -385,6 +385,11 @@
1.4 * loading plugin should use ISmmAPI::GetVSPInfo() before relying on
1.5 * this callback.
1.6 *
1.7 + * This callback is never called if Metamod:Source is in VSP mode.
1.8 + * If in VSP mode, a VSP instance is automatically and always available
1.9 + * via ISmmAPI::GetVSPInfo(), which should be called anyway (to handle
1.10 + * late loading cases).
1.11 + *
1.12 * @param iface Interface pointer. If NULL, then the VSP
1.13 * listening construct failed to initialize and
1.14 * is not available.
2.1 --- a/sourcemm/changelog.txt Fri Dec 14 14:55:37 2007 +0000
2.2 +++ b/sourcemm/changelog.txt Mon Dec 24 17:00:22 2007 +0000
2.3 @@ -8,6 +8,9 @@
2.4 instance pointer rather than a callclass pointer.
2.5 - Metamod:Source has now received a large internal rewrite to improve coding
2.6 standards and to separate internal logic from engine specifics.
2.7 + - Added ability to load from a VDF file instead of gameinfo.txt.
2.8 + - Added ability to load MM:S plugins from VDF files.
2.9 + - Added mm_basedir cvar to specify Metamod's base folder.
2.10 - Added API for getting highest supported IServerPluginCallbacks interface
2.11 version.
2.12 - Added API for detecting the engine version.
3.1 --- a/sourcemm/episode2/provider_ep2.cpp Fri Dec 14 14:55:37 2007 +0000
3.2 +++ b/sourcemm/episode2/provider_ep2.cpp Mon Dec 24 17:00:22 2007 +0000
3.3 @@ -43,6 +43,7 @@
3.4 #include "console.h"
3.5 #include "metamod_console.h"
3.6 #include "vsp_listener.h"
3.7 +#include <filesystem.h>
3.8 #if defined DEBUG2
3.9 #undef DEBUG2
3.10 #define _DEBUG
3.11 @@ -74,6 +75,7 @@
3.12 BaseProvider g_Ep1Provider;
3.13 IMetamodSourceProvider *provider = &g_Ep1Provider;
3.14 List<ConCommandBase *> conbases_unreg;
3.15 +IFileSystem *baseFs = NULL;
3.16 ConCommand meta_local_cmd("meta", LocalCommand_Meta, "Metamod:Source control options");
3.17
3.18 SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
3.19 @@ -106,6 +108,13 @@
3.20 gameclients = (IServerGameClients *)(serverFactory("ServerGameClients004", NULL));
3.21 }
3.22
3.23 + baseFs = (IFileSystem *)((engineFactory)(FILESYSTEM_INTERFACE_VERSION, NULL));
3.24 + if (baseFs == NULL)
3.25 + {
3.26 + ::LogMessage("Unable to find \"%s\": .vdf files will not be parsed", FILESYSTEM_INTERFACE_VERSION);
3.27 + return;
3.28 + }
3.29 +
3.30 RegisterConCommandBase(&meta_local_cmd);
3.31 conbases_unreg.push_back(&meta_local_cmd);
3.32
3.33 @@ -154,6 +163,11 @@
3.34 return convar->GetString();
3.35 }
3.36
3.37 +void BaseProvider::SetConVarString(ConVar *convar, const char *str)
3.38 +{
3.39 + convar->SetValue(str);
3.40 +}
3.41 +
3.42 bool BaseProvider::IsConCommandBaseACommand(ConCommandBase *pCommand)
3.43 {
3.44 return pCommand->IsCommand();
3.45 @@ -367,6 +381,68 @@
3.46 return g_VspListener.IsRootLoadMethod();
3.47 }
3.48
3.49 +bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len)
3.50 +{
3.51 + if (baseFs == NULL)
3.52 + {
3.53 + return false;
3.54 + }
3.55 +
3.56 + KeyValues *pValues;
3.57 + const char *plugin_file, *p_alias;
3.58 +
3.59 + pValues = new KeyValues("Metamod Plugin");
3.60 +
3.61 + if (!pValues->LoadFromFile(baseFs, file))
3.62 + {
3.63 + pValues->deleteThis();
3.64 + return false;
3.65 + }
3.66 +
3.67 + if ((plugin_file = pValues->GetString("file", NULL)) == NULL)
3.68 + {
3.69 + pValues->deleteThis();
3.70 + return false;
3.71 + }
3.72 +
3.73 + if ((p_alias = pValues->GetString("alias", NULL)) != NULL)
3.74 + {
3.75 + UTIL_Format(alias, alias_len, "%s", p_alias);
3.76 + }
3.77 + else
3.78 + {
3.79 + UTIL_Format(alias, alias_len, "");
3.80 + }
3.81 +
3.82 + /* Attempt to find a file extension */
3.83 + if (UTIL_GetExtension(plugin_file) == NULL)
3.84 + {
3.85 + g_pMetamod->PathFormat(path,
3.86 + path_len,
3.87 + "%s/%s%s",
3.88 + g_pMetamod->GetBaseDir(),
3.89 + plugin_file,
3.90 +#if defined WIN32 || defined _WIN32
3.91 + ".dll"
3.92 +#else
3.93 + "_i486.so"
3.94 +#endif
3.95 + );
3.96 + }
3.97 + else
3.98 + {
3.99 + g_pMetamod->PathFormat(path,
3.100 + path_len,
3.101 + "%s/%s",
3.102 + g_pMetamod->GetBaseDir(),
3.103 + plugin_file);
3.104 + }
3.105 +
3.106 + pValues->deleteThis();
3.107 +
3.108 + return true;
3.109 +}
3.110 +
3.111 class GlobCommand : public IMetamodSourceCommandInfo
3.112 {
3.113 public:
4.1 --- a/sourcemm/episode2/provider_ep2.h Fri Dec 14 14:55:37 2007 +0000
4.2 +++ b/sourcemm/episode2/provider_ep2.h Mon Dec 24 17:00:22 2007 +0000
4.3 @@ -68,6 +68,7 @@
4.4 const char *help,
4.5 int flags);
4.6 virtual const char *GetConVarString(ConVar *convar);
4.7 + virtual void SetConVarString(ConVar *convar, const char *str);
4.8 virtual const char *GetGameDescription();
4.9 virtual IConCommandBaseAccessor *GetConCommandBaseAccessor();
4.10 virtual bool RegisterConCommandBase(ConCommandBase *pCommand);
4.11 @@ -78,6 +79,7 @@
4.12 virtual const char *GetUserMessage(int index, int *size=NULL);
4.13 virtual int DetermineSourceEngine(const char *game);
4.14 virtual bool IsAlternatelyLoaded();
4.15 + virtual bool ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len);
4.16 };
4.17
4.18 extern IVEngineServer *engine;
5.1 --- a/sourcemm/episode2/vsp_listener.cpp Fri Dec 14 14:55:37 2007 +0000
5.2 +++ b/sourcemm/episode2/vsp_listener.cpp Mon Dec 24 17:00:22 2007 +0000
5.3 @@ -218,6 +218,7 @@
5.4
5.5 InitializeForLoad();
5.6 InitializeGlobals(interfaceFactory, interfaceFactory, interfaceFactory, pGlobals);
5.7 + StartupMetamod(true);
5.8
5.9 const ConCommandBase *pBase = icvar->GetCommands();
5.10 while (pBase != NULL)
5.11 @@ -240,7 +241,10 @@
5.12 m_bLoaded = true;
5.13 SetLoadable(false);
5.14
5.15 - g_Metamod.NotifyVSPListening(this);
5.16 + if (!m_bIsRootLoadMethod)
5.17 + {
5.18 + g_Metamod.NotifyVSPListening(this);
5.19 + }
5.20
5.21 return true;
5.22 }
6.1 --- a/sourcemm/metamod.cpp Fri Dec 14 14:55:37 2007 +0000
6.2 +++ b/sourcemm/metamod.cpp Mon Dec 24 17:00:22 2007 +0000
6.3 @@ -64,6 +64,7 @@
6.4 bool Handler_LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
6.5 bool Handler_GameInit();
6.6 void InitializeVSP();
6.7 +void LookForVDFs(const char *dir);
6.8
6.9 struct game_dll_t
6.10 {
6.11 @@ -88,6 +89,7 @@
6.12 game_dll_t gamedll_info;
6.13 ConVar *metamod_version = NULL;
6.14 ConVar *mm_pluginsfile = NULL;
6.15 +ConVar *mm_basedir = NULL;
6.16 IServerGameDLL *server = NULL;
6.17 CreateInterfaceFn engine_factory = NULL;
6.18 CreateInterfaceFn physics_factory = NULL;
6.19 @@ -102,6 +104,7 @@
6.20 bool were_plugins_loaded = false;
6.21
6.22 MetamodSource g_Metamod;
6.23 +SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
6.24
6.25 void ClearGamedllList();
6.26
6.27 @@ -699,6 +702,7 @@
6.28 void DoInitialPluginLoads()
6.29 {
6.30 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
6.31 + const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
6.32 if (!pluginFile)
6.33 {
6.34 pluginFile = provider->GetConVarString(mm_pluginsfile);
6.35 @@ -707,20 +711,41 @@
6.36 pluginFile = "addons/metamod/metaplugins.ini";
6.37 }
6.38 }
6.39 + if (!mmBaseDir)
6.40 + {
6.41 + mmBaseDir = provider->GetConVarString(mm_basedir);
6.42 + if (mmBaseDir == NULL)
6.43 + {
6.44 + mmBaseDir = "addons/metamod";
6.45 + }
6.46 + }
6.47
6.48 char full_path[260];
6.49 - g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), pluginFile);
6.50
6.51 + g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), pluginFile);
6.52 LoadPluginsFromFile(full_path);
6.53 +
6.54 + g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), mmBaseDir);
6.55 + LookForVDFs(full_path);
6.56 }
6.57
6.58 -void StartupMetamod(bool bWaitForGameInit)
6.59 +void StartupMetamod(bool is_vsp_load)
6.60 {
6.61 + char buffer[255];
6.62 +
6.63 + UTIL_Format(buffer,
6.64 + sizeof(buffer),
6.65 + "%s%s",
6.66 + SOURCEMM_VERSION,
6.67 + is_vsp_load ? "V" : "");
6.68 +
6.69 metamod_version = provider->CreateConVar("metamod_version",
6.70 SOURCEMM_VERSION,
6.71 "Metamod:Source Version",
6.72 ConVarFlag_Notify|ConVarFlag_Replicated|ConVarFlag_SpOnly);
6.73
6.74 + provider->SetConVarString(metamod_version, buffer);
6.75 +
6.76 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
6.77 #if defined WIN32 || defined _WIN32
6.78 "addons\\metamod\\metaplugins.ini",
6.79 @@ -730,7 +755,16 @@
6.80 "Metamod:Source Plugins File",
6.81 ConVarFlag_SpOnly);
6.82
6.83 - if (!bWaitForGameInit)
6.84 + mm_basedir = provider->CreateConVar("mm_basedir",
6.85 +#if defined __linux__
6.86 + "addons/metamod",
6.87 +#else
6.88 + "addons\\metamod",
6.89 +#endif
6.90 + "Metamod:Source Base Folder",
6.91 + ConVarFlag_SpOnly);
6.92 +
6.93 + if (!is_vsp_load)
6.94 {
6.95 DoInitialPluginLoads();
6.96 in_first_level = true;
6.97 @@ -827,13 +861,20 @@
6.98 if (!in_first_level)
6.99 {
6.100 char full_path[255];
6.101 +
6.102 g_Metamod.PathFormat(full_path,
6.103 sizeof(full_path),
6.104 "%s/%s",
6.105 mod_path.c_str(),
6.106 provider->GetConVarString(mm_pluginsfile));
6.107 + LoadPluginsFromFile(full_path);
6.108
6.109 - LoadPluginsFromFile(full_path);
6.110 + g_Metamod.PathFormat(full_path,
6.111 + sizeof(full_path),
6.112 + "%s/%s",
6.113 + mod_path.c_str(),
6.114 + provider->GetConVarString(mm_basedir));
6.115 + LookForVDFs(full_path);
6.116 }
6.117 else
6.118 {
6.119 @@ -1347,3 +1388,95 @@
6.120 {
6.121 return were_plugins_loaded;
6.122 }
6.123 +
6.124 +void ProcessVDF(const char *path)
6.125 +{
6.126 + PluginId id;
6.127 + bool already;
6.128 + char alias[24], file[255], error[255];
6.129 +
6.130 + if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
6.131 + {
6.132 + return;
6.133 + }
6.134 +
6.135 + if (alias[0] != '\0')
6.136 + {
6.137 + g_PluginMngr.SetAlias(alias, file);
6.138 + }
6.139 +
6.140 + id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
6.141 + if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
6.142 + {
6.143 + LogMessage("[META] Failed to load plugin %s: %s", file, error);
6.144 + }
6.145 +}
6.146 +
6.147 +void LookForVDFs(const char *dir)
6.148 +{
6.149 + char path[MAX_PATH];
6.150 +
6.151 +#if defined _MSC_VER
6.152 + HANDLE hFind;
6.153 + WIN32_FIND_DATA fd;
6.154 + char error[255];
6.155 +
6.156 + g_Metamod.PathFormat(path, sizeof(path), "%s\\*.*", dir);
6.157 + if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
6.158 + {
6.159 + DWORD dw = GetLastError();
6.160 + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
6.161 + NULL,
6.162 + dw,
6.163 + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
6.164 + error,
6.165 + sizeof(error),
6.166 + NULL);
6.167 + LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
6.168 + return;
6.169 + }
6.170 +
6.171 + do
6.172 + {
6.173 + if (strcmp(fd.cFileName, ".") == 0
6.174 + || strcmp(fd.cFileName, "..") == 0)
6.175 + {
6.176 + continue;
6.177 + }
6.178 + if (strstr(fd.cFileName, ".vdf") == NULL)
6.179 + {
6.180 + continue;
6.181 + }
6.182 + g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
6.183 + ProcessVDF(path);
6.184 + } while (FindNextFile(hFind, &fd));
6.185 +
6.186 + FindClose(hFind);
6.187 +#else
6.188 + DIR *pDir;
6.189 + struct dirent *pEnt;
6.190 +
6.191 + if ((pDir = opendir(dir)) == NULL)
6.192 + {
6.193 + LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
6.194 + return;
6.195 + }
6.196 +
6.197 + while ((pEnt = readdir(pDir)) != NULL)
6.198 + {
6.199 + if (strcmp(pEnt->d_name, ".") == 0
6.200 + || strcmp(pEnt->d_name, "..") == 0)
6.201 + {
6.202 + continue;
6.203 + }
6.204 + if (strstr(pEnt->d_name, ".vdf") == NULL)
6.205 + {
6.206 + continue;
6.207 + }
6.208 + g_SmmAPI.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
6.209 + ProcessVDF(path);
6.210 + }
6.211 +
6.212 + closedir(pDir);
6.213 +#endif
6.214 +}
7.1 --- a/sourcemm/metamod.h Fri Dec 14 14:55:37 2007 +0000
7.2 +++ b/sourcemm/metamod.h Mon Dec 24 17:00:22 2007 +0000
7.3 @@ -110,6 +110,7 @@
7.4 CreateInterfaceFn physicsFactory,
7.5 CreateInterfaceFn filesystemFactory,
7.6 CGlobalVars *pGlobals);
7.7 +void StartupMetamod(bool is_vsp_load);
7.8 void UnloadMetamod();
7.9
7.10 extern MetamodSource g_Metamod;
8.1 --- a/sourcemm/metamod_provider.h Fri Dec 14 14:55:37 2007 +0000
8.2 +++ b/sourcemm/metamod_provider.h Mon Dec 24 17:00:22 2007 +0000
8.3 @@ -220,6 +220,14 @@
8.4 virtual const char *GetConVarString(ConVar *convar) =0;
8.5
8.6 /**
8.7 + * @brief Sets a ConVar string.
8.8 + *
8.9 + * @param convar ConVar pointer.
8.10 + * @param str String pointer.
8.11 + */
8.12 + virtual void SetConVarString(ConVar *convar, const char *str) =0;
8.13 +
8.14 + /**
8.15 * @brief Retrieves the game description.
8.16 *
8.17 * @return Game description.
8.18 @@ -297,12 +305,19 @@
8.19 * @return True if loaded, false otherwise.
8.20 */
8.21 virtual bool IsAlternatelyLoaded() =0;
8.22 +
8.23 + /**
8.24 + * @brief Processes a VDF plugin file.
8.25 + *
8.26 + */
8.27 + virtual bool ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len) =0;
8.28 };
8.29 };
8.30
8.31 extern PluginId g_PLID;
8.32 extern SourceHook::ISourceHook *g_SHPtr;
8.33 extern SourceMM::IMetamodSourceProvider *provider;
8.34 +extern SourceMM::ISmmAPI *g_pMetamod;
8.35
8.36 #endif //_INCLUDE_METAMOD_SOURCE_SUPPORT_H_
8.37
9.1 --- a/sourcemm/metamod_util.h Fri Dec 14 14:55:37 2007 +0000
9.2 +++ b/sourcemm/metamod_util.h Mon Dec 24 17:00:22 2007 +0000
9.3 @@ -95,4 +95,6 @@
9.4 const char *relTo,
9.5 const char *relFrom);
9.6
9.7 +void LogMessage(const char *msg, ...);
9.8 +
9.9 #endif //_INCLUDE_UTIL_H