@@ -174,9 +174,6 @@ bool CSourcePython::Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn
174174 // Build path to python engines directory.
175175 // ------------------------------------------------------------------
176176 char szGameDir[MAX_PATH_LENGTH ];
177- char szPythonHome[MAX_PATH_LENGTH ];
178- char szPythonEngine[MAX_PATH_LENGTH ];
179- char szSourcePython[MAX_PATH_LENGTH ];
180177
181178 // ------------------------------------------------------------------
182179 // Get the game directory.
@@ -197,54 +194,37 @@ bool CSourcePython::Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn
197194 }
198195#endif
199196
200- // ------------------------------------------------------------------
201- // Construct paths to python and the core.
202- // ------------------------------------------------------------------
203- V_snprintf (szPythonHome, MAX_PATH_LENGTH , " %s/addons/source-python" , szGameDir);
204- V_snprintf (szSourcePython, sizeof (szSourcePython), " %s/%s" , szPythonHome, CORE_NAME );
205- V_snprintf (szPythonEngine, sizeof (szPythonEngine), " %s/%s" , szPythonHome, PYLIB_NAME );
206-
207- V_FixSlashes (szSourcePython);
208- V_FixSlashes (szPythonEngine);
209-
210197 // ------------------------------------------------------------------
211198 // Load python.
212199 // ------------------------------------------------------------------
213- #ifdef _WIN32
214- m_pPython = Sys_LoadModule (szPythonEngine);
215- #else
216- // This little gem cost me an entire thursday and a night's worth of
217- // sleep. Sys_LoadModule calls dlopen(lib, RTLD_NOW). Because it omits
218- // RTLD_GLOBAL, when Core.so decides to load, it is unable to relocate
219- // python's symbols correctly causing PyThreadState_GET() to fail!
220- // Long story short, we need RTLD_NOW coupled with RTLD_GLOBAL.
221- m_pPython = (CSysModule *)dlopen (szPythonEngine, RTLD_NOW | RTLD_GLOBAL );
222- #endif
223-
224- if ( !m_pPython ) {
200+ if ( SPLoadLibrary (engine, PYLIB_NAME ) == NULL ) {
225201 Warning (" ===========================================\n " );
226- Warning (" [SP-LOADER] Could not load %s!\n " , szPythonEngine );
202+ Warning (" [SP-LOADER] Could not load %s!\n " , PYLIB_NAME );
227203 Warning (" ===========================================\n " );
228204 return false ;
229205 }
230206
231207 // ------------------------------------------------------------------
232208 // Load the Source.Python core.
233209 // ------------------------------------------------------------------
234- m_pCore = new CDllDemandLoader (szSourcePython);
235-
236- if ( !m_pCore->GetFactory () ) {
210+ m_pCore = SPLoadLibrary (engine, CORE_NAME );
211+ if (!m_pCore) {
237212 Warning (" ===========================================\n " );
238- Warning (" [SP-LOADER] Could not load the %s!\n " , szSourcePython );
213+ Warning (" [SP-LOADER] Could not load %s!\n " , CORE_NAME );
239214 Warning (" ===========================================\n " );
240215 return false ;
241216 }
242217
243- // Get the interface from it.
244- m_pCorePlugin = static_cast <IServerPluginCallbacks*>(
245- m_pCore->GetFactory ()(INTERFACEVERSION_ISERVERPLUGINCALLBACKS , NULL )
246- );
218+ // Sys_LoadModule and CDllDemandLoader seem to be broken in CS:GO
219+ #ifdef _WIN32
220+ CreateInterfaceFn pFunc = (CreateInterfaceFn) GetProcAddress ((HMODULE ) m_pCore, CREATEINTERFACE_PROCNAME );
221+ #elif __linux__
222+ CreateInterfaceFn pFunc = (CreateInterfaceFn) dlsym (m_pCore, CREATEINTERFACE_PROCNAME );
223+ #else
224+ #error Unsupported platform.
225+ #endif
247226
227+ m_pCorePlugin = static_cast <IServerPluginCallbacks*>(pFunc (INTERFACEVERSION_ISERVERPLUGINCALLBACKS , NULL ));
248228 if ( !m_pCorePlugin ) {
249229 Warning (" =========================================================================\n " );
250230 Warning (" [SP-LOADER] Could not retrieve the server plugin interface from the core!\n " );
@@ -283,7 +263,10 @@ void CSourcePython::Pause( void )
283263// ---------------------------------------------------------------------------------
284264void CSourcePython::UnPause ( void )
285265{
286- m_pCorePlugin->UnPause ();
266+ if (m_pCorePlugin != NULL )
267+ {
268+ m_pCorePlugin->UnPause ();
269+ }
287270}
288271
289272// ---------------------------------------------------------------------------------
0 commit comments