| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e85a596 commit fcba62b
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,7 @@ | |||
| 28 | 28 | // Includes | |
| 29 | 29 | //--------------------------------------------------------------------------------- | |
| 30 | 30 | #include "sp_gamedir.h" | |
| 31 | + #include "sp_main.h" | ||
| 31 | 32 | #include "eiface.h" | |
| 32 | 33 | #include "strtools.h" | |
| 33 | 34 | ||
@@ -47,7 +48,7 @@ CGamePaths g_GamePaths; | |||
| 47 | 48 | bool CGamePaths::Initialize( void ) | |
| 48 | 49 | { | |
| 49 | 50 | if( !engine ) { | |
| 50 | - Msg("[SP] Could not initialize game paths! Engine pointer was invalid.\n"); | ||
| 51 | + Msg(MSG_PREFIX "Could not initialize game paths! Engine pointer was invalid.\n"); | ||
| 51 | 52 | return false; | |
| 52 | 53 | } | |
| 53 | 54 | ||
@@ -58,8 +59,8 @@ bool CGamePaths::Initialize( void ) | |||
| 58 | 59 | V_FixSlashes(m_szGameDir); | |
| 59 | 60 | V_FixSlashes(m_szSPDir); | |
| 60 | 61 | ||
| 61 | - DevMsg(1, "[SP] Game directory is %s\n", m_szGameDir); | ||
| 62 | - DevMsg(1, "[SP] Source-Python directory is %s\n", m_szSPDir); | ||
| 62 | + DevMsg(1, MSG_PREFIX "Game directory is %s\n", m_szGameDir); | ||
| 63 | + DevMsg(1, MSG_PREFIX "Source-Python directory is %s\n", m_szSPDir); | ||
| 63 | 64 | ||
| 64 | 65 | return true; | |
| 65 | 66 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -157,9 +157,9 @@ bool GetInterfaces( InterfaceHelper_t* pInterfaceList, CreateInterfaceFn factory | |||
| 157 | 157 | ||
| 158 | 158 | // If it's not valid, bail out. | |
| 159 | 159 | if( *pGlobal ) { | |
| 160 | - DevMsg(1, "[SP] Interface %s at %x\n", pInterface->szInterface, *pGlobal); | ||
| 160 | + DevMsg(1, MSG_PREFIX "Interface %s at %x\n", pInterface->szInterface, *pGlobal); | ||
| 161 | 161 | } else { | |
| 162 | - Warning("[SP] Could not retrieve interface %s\n", pInterface->szInterface); | ||
| 162 | + Warning(MSG_PREFIX "Could not retrieve interface %s\n", pInterface->szInterface); | ||
| 163 | 163 | return false; | |
| 164 | 164 | } | |
| 165 | 165 | ||
@@ -211,13 +211,13 @@ bool CSourcePython::Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn | |||
| 211 | 211 | ||
| 212 | 212 | // Initialize game paths. | |
| 213 | 213 | if( !g_GamePaths.Initialize() ) { | |
| 214 | - DevMsg(0, "Could not initialize game paths."); | ||
| 214 | + DevMsg(0, MSG_PREFIX "Could not initialize game paths.\n"); | ||
| 215 | 215 | return false; | |
| 216 | 216 | } | |
| 217 | 217 | ||
| 218 | 218 | // Initialize python | |
| 219 | 219 | if( !g_PythonManager.Initialize() ) { | |
| 220 | - DevMsg(0, "Could not initialize python."); | ||
| 220 | + DevMsg(0, MSG_PREFIX "Could not initialize python.\n"); | ||
| 221 | 221 | return false; | |
| 222 | 222 | } | |
| 223 | 223 | ||
@@ -377,7 +377,7 @@ void CSourcePython::OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t | |||
| 377 | 377 | EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue ) | |
| 378 | 378 | { | |
| 379 | 379 | g_AddonManager.OnQueryCvarValueFinished(iCookie, pPlayerEntity, eStatus, pCvarName, pCvarValue); | |
| 380 | - DevMsg(1, "Cvar query (cookie: %d, status: %d) - name: %s, value: %s\n", iCookie, eStatus, pCvarName, pCvarValue ); | ||
| 380 | + DevMsg(1, MSG_PREFIX "Cvar query (cookie: %d, status: %d) - name: %s, value: %s\n", iCookie, eStatus, pCvarName, pCvarValue ); | ||
| 381 | 381 | } | |
| 382 | 382 | ||
| 383 | 383 | //----------------------------------------------------------------------------- | |
@@ -386,7 +386,7 @@ void CSourcePython::OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t | |||
| 386 | 386 | void CSourcePython::FireGameEvent( IGameEvent * event ) | |
| 387 | 387 | { | |
| 388 | 388 | const char * name = event->GetName(); | |
| 389 | - DevMsg(1, "CSourcePython::FireGameEvent: Got event \"%s\"\n", name ); | ||
| 389 | + DevMsg(1, MSG_PREFIX "CSourcePython::FireGameEvent: Got event \"%s\"\n", name ); | ||
| 390 | 390 | ||
| 391 | 391 | //g_AddonManager.FireGameEvent(event); | |
| 392 | 392 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,13 @@ | |||
| 32 | 32 | #include "engine/iserverplugin.h" | |
| 33 | 33 | #include "igameevents.h" | |
| 34 | 34 | ||
| 35 | + | ||
| 36 | + //--------------------------------------------------------------------------------- | ||
| 37 | + // Definitions | ||
| 38 | + //--------------------------------------------------------------------------------- | ||
| 39 | + #define MSG_PREFIX "[Source.Python] " | ||
| 40 | + | ||
| 41 | + | ||
| 35 | 42 | //--------------------------------------------------------------------------------- | |
| 36 | 43 | // Purpose: a sample 3rd party plugin class | |
| 37 | 44 | //--------------------------------------------------------------------------------- | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ | |||
| 33 | 33 | //--------------------------------------------------------------------------------- | |
| 34 | 34 | #include "sp_python.h" | |
| 35 | 35 | #include "sp_gamedir.h" | |
| 36 | + #include "sp_main.h" | ||
| 36 | 37 | #include "eiface.h" | |
| 37 | 38 | #include "modules/export_main.h" | |
| 38 | 39 | ||
@@ -63,7 +64,7 @@ void AddToSysPath( const char* path ) | |||
| 63 | 64 | V_snprintf(szFolderPath, MAX_GAME_PATH, "%s%s", g_GamePaths.GetSPDir(), path); | |
| 64 | 65 | V_FixSlashes(szFolderPath); | |
| 65 | 66 | ||
| 66 | - DevMsg(1, "[SP] Adding %s to path\n", szFolderPath); | ||
| 67 | + DevMsg(1, MSG_PREFIX "Adding %s to path\n", szFolderPath); | ||
| 67 | 68 | std::string szCommandString = "sys.path.append(r\"" + std::string(szFolderPath) + "\")"; | |
| 68 | 69 | PyRun_SimpleString(szCommandString.c_str()); | |
| 69 | 70 | } | |
@@ -77,7 +78,7 @@ bool CPythonManager::Initialize( void ) | |||
| 77 | 78 | char szPythonHome[MAX_GAME_PATH]; | |
| 78 | 79 | V_snprintf(szPythonHome, MAX_GAME_PATH, "%s/Python3", g_GamePaths.GetSPDir()); | |
| 79 | 80 | V_FixSlashes(szPythonHome); | |
| 80 | - DevMsg(1, "[SP] Python home path set to %s\n", szPythonHome); | ||
| 81 | + DevMsg(1, MSG_PREFIX "Python home path set to %s\n", szPythonHome); | ||
| 81 | 82 | ||
| 82 | 83 | // Convert to wide char for python. | |
| 83 | 84 | wchar_t wszPythonHome[1024]; | |
@@ -92,7 +93,7 @@ bool CPythonManager::Initialize( void ) | |||
| 92 | 93 | Py_Initialize(); | |
| 93 | 94 | ||
| 94 | 95 | // Print some information | |
| 95 | - DevMsg(1, "Python version %s initialized!\n", Py_GetVersion()); | ||
| 96 | + DevMsg(1, MSG_PREFIX "Python version %s initialized!\n", Py_GetVersion()); | ||
| 96 | 97 | ||
| 97 | 98 | // Make sure sys is imported. | |
| 98 | 99 | PyRun_SimpleString("import sys"); | |
@@ -126,15 +127,19 @@ bool CPythonManager::Initialize( void ) | |||
| 126 | 127 | modulsp_init(); | |
| 127 | 128 | ||
| 128 | 129 | // Import the main module file. | |
| 129 | - DevMsg(1, "[SP] Importing main module..\n"); | ||
| 130 | - BEGIN_BOOST_PY() | ||
| 130 | + DevMsg(1, MSG_PREFIX "Importing main module..\n"); | ||
| 131 | 131 | ||
| 132 | + try { | ||
| 132 | 133 | python::import("__init__"); | |
| 134 | + } | ||
| 135 | + catch( ... ) { | ||
| 136 | + PyErr_Print(); | ||
| 137 | + PyErr_Clear(); | ||
| 138 | + DevMsg(0, MSG_PREFIX "Failed to load.\n"); | ||
| 139 | + return false; | ||
| 140 | + } | ||
| 133 | 141 | ||
| 134 | - END_BOOST_PY_NORET(); // Noret because we have more stuff to do after this import. | ||
| 135 | - | ||
| 136 | - DevMsg(0, "[Source.Python] Loaded successfully.\n"); | ||
| 137 | - | ||
| 142 | + DevMsg(0, MSG_PREFIX "Loaded successfully.\n"); | ||
| 138 | 143 | return true; | |
| 139 | 144 | } | |
| 140 | 145 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,7 @@ | |||
| 37 | 37 | #include "boost/algorithm/string.hpp" | |
| 38 | 38 | #include "boost/foreach.hpp" | |
| 39 | 39 | #include "utility/wrap_macros.h" | |
| 40 | + #include "core/sp_main.h" | ||
| 40 | 41 | ||
| 41 | 42 | //----------------------------------------------------------------------------- | |
| 42 | 43 | // If these aren't defined, we get linker errors about CBaseEdict. | |
@@ -192,7 +193,7 @@ CSendProp::CSendProp( edict_t* edict, const char* prop_name ) | |||
| 192 | 193 | ||
| 193 | 194 | if( !m_edict ) | |
| 194 | 195 | { | |
| 195 | - DevMsg(1, "[SP]: edict was not valid!\n"); | ||
| 196 | + DevMsg(1, MSG_PREFIX "edict was not valid!\n"); | ||
| 196 | 197 | return; | |
| 197 | 198 | } | |
| 198 | 199 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ | |||
| 29 | 29 | //--------------------------------------------------------------------------------- | |
| 30 | 30 | #include "boost/python.hpp" | |
| 31 | 31 | #include "core/sp_python.h" | |
| 32 | + #include "core/sp_main.h" | ||
| 32 | 33 | #include "export_main.h" | |
| 33 | 34 | #include "tier0/dbg.h" | |
| 34 | 35 | ||
@@ -67,7 +68,7 @@ void modulsp_init( void ) | |||
| 67 | 68 | char* szModuleName = g_SourcePythonModules[i].szName; | |
| 68 | 69 | ||
| 69 | 70 | // Debug info. | |
| 70 | - DevMsg(1, "[SP] Initializing %s module\n", szModuleName); | ||
| 71 | + DevMsg(1, MSG_PREFIX "Initializing %s module\n", szModuleName); | ||
| 71 | 72 | ||
| 72 | 73 | // Set the new module as the current scope. | |
| 73 | 74 | object newmodule(borrowed(PyImport_AddModule(szModuleName))); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,7 +156,7 @@ void* SPLoadLibrary( IVEngineServer* engine, const char* libraryPath ) | |||
| 156 | 156 | //--------------------------------------------------------------------------------- | |
| 157 | 157 | bool CSourcePython::Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory ) | |
| 158 | 158 | { | |
| 159 | - DevMsg(0, "[Source.Python] Loading...\n"); | ||
| 159 | + DevMsg(0, MSG_PREFIX "Loading...\n"); | ||
| 160 | 160 | ||
| 161 | 161 | IVEngineServer* engine = (IVEngineServer*)interfaceFactory(INTERFACEVERSION_VENGINESERVER, NULL); | |
| 162 | 162 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,8 @@ | |||
| 63 | 63 | # define PYLIB_NAME PYLIB_NAME_LINUX_RELEASE | |
| 64 | 64 | #endif | |
| 65 | 65 | ||
| 66 | + #define MSG_PREFIX "[Source.Python] " | ||
| 67 | + | ||
| 66 | 68 | //--------------------------------------------------------------------------------- | |
| 67 | 69 | // Purpose: a sample 3rd party plugin class | |
| 68 | 70 | //--------------------------------------------------------------------------------- | |
| Back | FazBrowse Home | New Git URL |
0 commit comments