sourcemm/episode2/provider_ep2.cpp
changeset 485 d8f0a0416936
parent 484 d86328fe5aaf
child 495 e091f2b5e913
     1.1 --- a/sourcemm/episode2/provider_ep2.cpp	Fri Dec 14 14:55:37 2007 +0000
     1.2 +++ b/sourcemm/episode2/provider_ep2.cpp	Mon Dec 24 17:00:22 2007 +0000
     1.3 @@ -43,6 +43,7 @@
     1.4  #include "console.h"
     1.5  #include "metamod_console.h"
     1.6  #include "vsp_listener.h"
     1.7 +#include <filesystem.h>
     1.8  #if defined DEBUG2
     1.9  #undef DEBUG2
    1.10  #define _DEBUG
    1.11 @@ -74,6 +75,7 @@
    1.12  BaseProvider g_Ep1Provider;
    1.13  IMetamodSourceProvider *provider = &g_Ep1Provider;
    1.14  List<ConCommandBase *> conbases_unreg;
    1.15 +IFileSystem *baseFs = NULL;
    1.16  ConCommand meta_local_cmd("meta", LocalCommand_Meta, "Metamod:Source control options");
    1.17  
    1.18  SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
    1.19 @@ -106,6 +108,13 @@
    1.20  		gameclients = (IServerGameClients *)(serverFactory("ServerGameClients004", NULL));
    1.21  	}
    1.22  
    1.23 +	baseFs = (IFileSystem *)((engineFactory)(FILESYSTEM_INTERFACE_VERSION, NULL));
    1.24 +	if (baseFs == NULL)
    1.25 +	{
    1.26 +		::LogMessage("Unable to find \"%s\": .vdf files will not be parsed", FILESYSTEM_INTERFACE_VERSION);
    1.27 +		return;
    1.28 +	}
    1.29 +
    1.30  	RegisterConCommandBase(&meta_local_cmd);
    1.31  	conbases_unreg.push_back(&meta_local_cmd);
    1.32  
    1.33 @@ -154,6 +163,11 @@
    1.34  	return convar->GetString();
    1.35  }
    1.36  
    1.37 +void BaseProvider::SetConVarString(ConVar *convar, const char *str)
    1.38 +{
    1.39 +	convar->SetValue(str);
    1.40 +}
    1.41 +
    1.42  bool BaseProvider::IsConCommandBaseACommand(ConCommandBase *pCommand)
    1.43  {
    1.44  	return pCommand->IsCommand();
    1.45 @@ -367,6 +381,68 @@
    1.46  	return g_VspListener.IsRootLoadMethod();
    1.47  }
    1.48  
    1.49 +bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len)
    1.50 +{
    1.51 +	if (baseFs == NULL)
    1.52 +	{
    1.53 +		return false;
    1.54 +	}
    1.55 +
    1.56 +	KeyValues *pValues;
    1.57 +	const char *plugin_file, *p_alias;
    1.58 +
    1.59 +	pValues = new KeyValues("Metamod Plugin");
    1.60 +
    1.61 +	if (!pValues->LoadFromFile(baseFs, file))
    1.62 +	{
    1.63 +		pValues->deleteThis();
    1.64 +		return false;
    1.65 +	}
    1.66 +
    1.67 +	if ((plugin_file = pValues->GetString("file", NULL)) == NULL)
    1.68 +	{
    1.69 +		pValues->deleteThis();
    1.70 +		return false;
    1.71 +	}
    1.72 +
    1.73 +	if ((p_alias = pValues->GetString("alias", NULL)) != NULL)
    1.74 +	{
    1.75 +		UTIL_Format(alias, alias_len, "%s", p_alias);
    1.76 +	}
    1.77 +	else
    1.78 +	{
    1.79 +		UTIL_Format(alias, alias_len, "");
    1.80 +	}
    1.81 +
    1.82 +	/* Attempt to find a file extension */
    1.83 +	if (UTIL_GetExtension(plugin_file) == NULL)
    1.84 +	{
    1.85 +		g_pMetamod->PathFormat(path, 
    1.86 +			path_len, 
    1.87 +			"%s/%s%s", 
    1.88 +			g_pMetamod->GetBaseDir(), 
    1.89 +			plugin_file, 
    1.90 +#if defined WIN32 || defined _WIN32
    1.91 +			".dll"
    1.92 +#else
    1.93 +			"_i486.so"
    1.94 +#endif
    1.95 +			);
    1.96 +	}
    1.97 +	else
    1.98 +	{
    1.99 +		g_pMetamod->PathFormat(path,
   1.100 +			path_len,
   1.101 +			"%s/%s", 
   1.102 +			g_pMetamod->GetBaseDir(),
   1.103 +			plugin_file);
   1.104 +	}
   1.105 +
   1.106 +	pValues->deleteThis();
   1.107 +
   1.108 +	return true;
   1.109 +}
   1.110 +
   1.111  class GlobCommand : public IMetamodSourceCommandInfo
   1.112  {
   1.113  public: