core/sourcemod.cpp
changeset 209 fae1894d884c
parent 183 78488edd8873
child 211 4c77142eaf36
     1.1 --- a/core/sourcemod.cpp	Wed Dec 13 11:14:25 2006 +0000
     1.2 +++ b/core/sourcemod.cpp	Wed Dec 13 11:16:20 2006 +0000
     1.3 @@ -7,6 +7,8 @@
     1.4  #include "PluginSys.h"
     1.5  #include "ForwardSys.h"
     1.6  
     1.7 +SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
     1.8 +
     1.9  SourcePawnEngine g_SourcePawn;
    1.10  SourceModBase g_SourceMod;
    1.11  
    1.12 @@ -31,16 +33,21 @@
    1.13  	g_pJIT->CloseLibrary();
    1.14  }
    1.15  
    1.16 +SourceModBase::SourceModBase()
    1.17 +{
    1.18 +	m_IsMapLoading = false;
    1.19 +}
    1.20 +
    1.21  bool SourceModBase::InitializeSourceMod(char *error, size_t err_max, bool late)
    1.22  {
    1.23 -	//:TODO: we need a localinfo system!
    1.24  	g_BaseDir.assign(g_SMAPI->GetBaseDir());
    1.25 +	g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/addons/sourcemod", g_BaseDir.c_str());
    1.26  
    1.27  	/* Attempt to load the JIT! */
    1.28  	char file[PLATFORM_MAX_PATH];
    1.29  	char myerror[255];
    1.30 -	g_SMAPI->PathFormat(file, sizeof(file), "%s/addons/sourcemod/bin/sourcepawn.jit.x86.%s",
    1.31 -		g_BaseDir.c_str(),
    1.32 +	g_SMAPI->PathFormat(file, sizeof(file), "%s/bin/sourcepawn.jit.x86.%s",
    1.33 +		GetSMBaseDir(),
    1.34  		PLATFORM_LIB_EXT
    1.35  		);
    1.36  
    1.37 @@ -112,21 +119,49 @@
    1.38  		return false;
    1.39  	}
    1.40  
    1.41 -	g_SMAPI->PathFormat(file, sizeof(file), "%s/addons/sourcemod/plugins/test.smx", g_BaseDir.c_str());
    1.42 -	IPlugin *pPlugin = g_PluginMngr.LoadPlugin(file, false, PluginType_Global, error, err_max);
    1.43 -	IPluginFunction *func = pPlugin->GetFunctionByName("Test");
    1.44 -	IPluginFunction *func2 = pPlugin->GetFunctionByName("Test2");
    1.45 -	cell_t result = 2;
    1.46 -	cell_t val = 6;
    1.47 -	ParamType types[] = {Param_Cell, Param_CellByRef};
    1.48 -	va_list ap = va_start(ap, late);
    1.49 -	CForward *fwd = CForward::CreateForward(NULL, ET_Custom, 2, types, ap);
    1.50 -	fwd->AddFunction(func);
    1.51 -	fwd->AddFunction(func2);
    1.52 -	fwd->PushCell(1);
    1.53 -	fwd->PushCellByRef(&val, 0);
    1.54 -	fwd->Execute(&result, NULL);
    1.55 -	g_PluginMngr.UnloadPlugin(pPlugin);
    1.56 +	StartSourceMod(late);
    1.57  
    1.58  	return true;
    1.59  }
    1.60 +
    1.61 +void SourceModBase::StartSourceMod(bool late)
    1.62 +{
    1.63 +	/* First initialize the global hooks we need */
    1.64 +	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
    1.65 +
    1.66 +	/* If we're late, automatically load plugins now */
    1.67 +	DoGlobalPluginLoads();
    1.68 +}
    1.69 +
    1.70 +bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
    1.71 +{
    1.72 +	m_IsMapLoading = true;
    1.73 +
    1.74 +	DoGlobalPluginLoads();
    1.75 +
    1.76 +	m_IsMapLoading = false;
    1.77 +
    1.78 +	RETURN_META_VALUE(MRES_IGNORED, true);
    1.79 +}
    1.80 +
    1.81 +void SourceModBase::DoGlobalPluginLoads()
    1.82 +{
    1.83 +	char config_path[PLATFORM_MAX_PATH];
    1.84 +	char plugins_path[PLATFORM_MAX_PATH];
    1.85 +
    1.86 +	g_SMAPI->PathFormat(config_path, 
    1.87 +		sizeof(config_path),
    1.88 +		"%s/configs/plugin_settings.cfg",
    1.89 +		GetSMBaseDir());
    1.90 +	g_SMAPI->PathFormat(plugins_path,
    1.91 +		sizeof(plugins_path),
    1.92 +		"%s/plugins",
    1.93 +		GetSMBaseDir());
    1.94 +
    1.95 +	g_PluginMngr.RefreshOrLoadPlugins(config_path, plugins_path);
    1.96 +}
    1.97 +
    1.98 +const char *SourceModBase::GetSMBaseDir()
    1.99 +{
   1.100 +	return m_SMBaseDir;
   1.101 +}