sourcemm/metamod_plugins.cpp
changeset 400 beabd7f601c2
parent 397 936c1a0b6900
child 407 af2530a35c5c
     1.1 --- a/sourcemm/metamod_plugins.cpp	Mon Oct 08 20:12:06 2007 +0000
     1.2 +++ b/sourcemm/metamod_plugins.cpp	Mon Oct 08 20:21:14 2007 +0000
     1.3 @@ -60,6 +60,17 @@
     1.4  
     1.5  CPluginManager g_PluginMngr;
     1.6  
     1.7 +MetamodVersionInfo GlobVersionInfo = 
     1.8 +{
     1.9 +	METAMOD_API_MAJOR,
    1.10 +	METAMOD_API_MINOR,
    1.11 +	SH_IFACE_VERSION,
    1.12 +	SH_IMPL_VERSION,
    1.13 +	PLAPI_MIN_VERSION,
    1.14 +	METAMOD_PLAPI_VERSION,
    1.15 +	SOURCE_ENGINE_UNKNOWN
    1.16 +};
    1.17 +
    1.18  CPluginManager::CPluginManager()
    1.19  {
    1.20  	m_LastId = Pl_MinId;
    1.21 @@ -139,7 +150,7 @@
    1.22  	}
    1.23  }
    1.24  
    1.25 -CPluginManager::CPlugin::CPlugin() : m_Id(0), m_Source(0), m_API(NULL), m_Lib(NULL)
    1.26 +CPluginManager::CPlugin::CPlugin() : m_Id(0), m_Source(0), m_API(NULL), m_Lib(NULL), m_UnloadFn(NULL)
    1.27  {
    1.28  
    1.29  }
    1.30 @@ -415,63 +426,96 @@
    1.31  		}
    1.32  		else
    1.33  		{
    1.34 -			CreateInterfaceFn pfn = (CreateInterfaceFn)(dlsym(pl->m_Lib, PL_EXPOSURE_C));
    1.35 -			if (!pfn)
    1.36 +			pl->m_API = NULL;
    1.37 +			
    1.38 +			/**
    1.39 +			 * First, try the new "advanced" interface
    1.40 +			 */
    1.41 +			METAMOD_FN_LOAD fnLoad = (METAMOD_FN_LOAD)dlsym(pl->m_Lib, "CreateInterface_MMS");
    1.42 +			if (fnLoad != NULL)
    1.43  			{
    1.44 -				if (error)
    1.45 +				if (GlobVersionInfo.source_engine == SOURCE_ENGINE_UNKNOWN)
    1.46  				{
    1.47 -					UTIL_Format(error, maxlen, "Function %s not found", PL_EXPOSURE_C);
    1.48 +					GlobVersionInfo.source_engine = g_Metamod.GetSourceEngineBuild();
    1.49  				}
    1.50 -				pl->m_Status = Pl_Error;
    1.51 +
    1.52 +				pl->m_API = fnLoad(&GlobVersionInfo, NULL);
    1.53 +				pl->m_UnloadFn = (METAMOD_FN_UNLOAD)dlsym(pl->m_Lib, "UnloadInterface_MMS");
    1.54  			}
    1.55 -			else
    1.56 +
    1.57 +			/**
    1.58 +			 * If we didn't get anything, try the normal/simple interface.
    1.59 +			 */
    1.60 +			if (pl->m_API == NULL)
    1.61  			{
    1.62 -				pl->m_API = static_cast<ISmmPlugin *>((pfn)(METAMOD_PLAPI_NAME, NULL));
    1.63 -				if (!pl->m_API)
    1.64 +				CreateInterfaceFn pfn = (CreateInterfaceFn)(dlsym(pl->m_Lib, PL_EXPOSURE_C));
    1.65 +				if (!pfn)
    1.66  				{
    1.67  					if (error)
    1.68  					{
    1.69 -						UTIL_Format(error, maxlen, "Failed to get API");
    1.70 +						UTIL_Format(error, maxlen, "Function %s not found", PL_EXPOSURE_C);
    1.71  					}
    1.72  					pl->m_Status = Pl_Error;
    1.73  				}
    1.74  				else
    1.75  				{
    1.76 -					int api = pl->m_API->GetApiVersion();
    1.77 -					if (api < PLAPI_MIN_VERSION)
    1.78 +					pl->m_API = static_cast<ISmmPlugin *>((pfn)(METAMOD_PLAPI_NAME, NULL));
    1.79 +
    1.80 +					if (!pl->m_API)
    1.81  					{
    1.82  						if (error)
    1.83  						{
    1.84 -							UTIL_Format(error, maxlen, "Plugin API %d is out of date with required minimum (%d)", api, PLAPI_MIN_VERSION);
    1.85 -						}
    1.86 -						pl->m_Status = Pl_Error;
    1.87 -					}
    1.88 -					else if (api > METAMOD_PLAPI_VERSION)
    1.89 -					{
    1.90 -						if (error)
    1.91 -						{
    1.92 -							UTIL_Format(error, maxlen, "Plugin API %d is newer than internal version (%d)", api, METAMOD_PLAPI_VERSION);
    1.93 +							UTIL_Format(error, maxlen, "Failed to get API");
    1.94  						}
    1.95  						pl->m_Status = Pl_Error;
    1.96  					}
    1.97 -					else
    1.98 +				}
    1.99 +			}
   1.100 +
   1.101 +			if (pl->m_API != NULL)
   1.102 +			{
   1.103 +				int api = pl->m_API->GetApiVersion();
   1.104 +				if (api < PLAPI_MIN_VERSION)
   1.105 +				{
   1.106 +					if (error)
   1.107  					{
   1.108 -						if (pl->m_API->Load(pl->m_Id, &g_Metamod, error, maxlen, m_AllLoaded))
   1.109 +						if (api == 13)
   1.110  						{
   1.111 -							pl->m_Status = Pl_Running;
   1.112 -							if (m_AllLoaded)
   1.113 -							{
   1.114 -								//API 4 is when we added this callback
   1.115 -								//Removing this code as the min version is now 5
   1.116 -								//if (pl->m_API->GetApiVersion() >= 4)
   1.117 -								pl->m_API->AllPluginsLoaded();
   1.118 -							}
   1.119 +							UTIL_Format(error, maxlen, "Plugin uses experimental Metamod build, probably 1.6.x (%d < %d)", api, PLAPI_MIN_VERSION);
   1.120 +						}
   1.121 +						else if (api <= 12 && api >= 7)
   1.122 +						{
   1.123 +							UTIL_Format(error, maxlen, "Older Metamod version required, probably 1.4.x (%d < %d)", api, PLAPI_MIN_VERSION);
   1.124  						}
   1.125  						else
   1.126  						{
   1.127 -							pl->m_Status = Pl_Refused;
   1.128 +							UTIL_Format(error, maxlen, "Older Metamod version required, probably 1.0 (%d < %d)", api, PLAPI_MIN_VERSION);
   1.129  						}
   1.130  					}
   1.131 +					pl->m_Status = Pl_Error;
   1.132 +				}
   1.133 +				else if (api > METAMOD_PLAPI_VERSION)
   1.134 +				{
   1.135 +					if (error)
   1.136 +					{
   1.137 +						UTIL_Format(error, maxlen, "Plugin requires newer Metamod version (%d > %d)", api, METAMOD_PLAPI_VERSION);
   1.138 +					}
   1.139 +					pl->m_Status = Pl_Error;
   1.140 +				}
   1.141 +				else
   1.142 +				{
   1.143 +					if (pl->m_API->Load(pl->m_Id, &g_Metamod, error, maxlen, m_AllLoaded))
   1.144 +					{
   1.145 +						pl->m_Status = Pl_Running;
   1.146 +						if (m_AllLoaded)
   1.147 +						{
   1.148 +							pl->m_API->AllPluginsLoaded();
   1.149 +						}
   1.150 +					}
   1.151 +					else
   1.152 +					{
   1.153 +						pl->m_Status = Pl_Refused;
   1.154 +					}
   1.155  				}
   1.156  			}
   1.157  		}
   1.158 @@ -483,6 +527,11 @@
   1.159  		g_SourceHook.UnloadPlugin(pl->m_Id);
   1.160  		UnregAllConCmds(pl);
   1.161  
   1.162 +		if (pl->m_UnloadFn != NULL)
   1.163 +		{
   1.164 +			pl->m_UnloadFn();
   1.165 +		}
   1.166 +
   1.167  		dlclose(pl->m_Lib);
   1.168  		pl->m_Lib = NULL;
   1.169  		pl->m_API = NULL;
   1.170 @@ -510,6 +559,11 @@
   1.171  
   1.172  			UnregAllConCmds(pl);
   1.173  
   1.174 +			if (pl->m_UnloadFn != NULL)
   1.175 +			{
   1.176 +				pl->m_UnloadFn();
   1.177 +			}
   1.178 +
   1.179  			//Clean up the DLL
   1.180  			dlclose(pl->m_Lib);
   1.181  			pl->m_Lib = NULL;