@@ -58,14 +58,28 @@ DEFINE_LOGGING_CHANNEL_NO_TAGS( LOG_VScript, "VScript", 0, LS_MESSAGE, Color( 24
5858};*/
5959#endif
6060
61+ #ifdef BDSBASE
62+ #define SCRIPT_PATH " scripts/vscripts"
63+
64+ static const char * g_pszScriptExtensions[] =
65+ {
66+ " " , // SL_NONE
67+ " .gm" , // SL_GAMEMONKEY
68+ " .nut" , // SL_SQUIRREL
69+ " .lua" , // SL_LUA
70+ " .py" , // SL_PYTHON
71+ };
72+ #endif
73+
6174HSCRIPT VScriptCompileScript ( const char *pszScriptName, bool bWarnMissing )
6275{
6376 if ( !g_pScriptVM )
6477 {
6578 return NULL ;
6679 }
6780
68- static const char *pszExtensions[] =
81+ #ifndef BDSBASE
82+ static const char * pszExtensions[] =
6983 {
7084 " " , // SL_NONE
7185 " .gm" , // SL_GAMEMONKEY
@@ -74,7 +88,10 @@ HSCRIPT VScriptCompileScript( const char *pszScriptName, bool bWarnMissing )
7488 " .py" , // SL_PYTHON
7589 };
7690
77- const char *pszVMExtension = pszExtensions[g_pScriptVM->GetLanguage ()];
91+ const char * pszVMExtension = pszExtensions[g_pScriptVM->GetLanguage ()];
92+ #else
93+ const char * pszVMExtension = g_pszScriptExtensions[g_pScriptVM->GetLanguage ()];
94+ #endif
7895 const char *pszIncomingExtension = V_strrchr ( pszScriptName , ' .' );
7996 if ( pszIncomingExtension && V_strcmp ( pszIncomingExtension, pszVMExtension ) != 0 )
8097 {
@@ -83,14 +100,25 @@ HSCRIPT VScriptCompileScript( const char *pszScriptName, bool bWarnMissing )
83100 }
84101
85102 CFmtStr scriptPath;
86- if ( pszIncomingExtension )
103+ #ifdef BDSBASE
104+ if (pszIncomingExtension)
87105 {
88- scriptPath.sprintf ( " scripts/vscripts/ %s" , pszScriptName );
106+ scriptPath.sprintf (SCRIPT_PATH " / %s" , pszScriptName);
89107 }
90108 else
91- {
92- scriptPath.sprintf ( " scripts/vscripts/%s%s" , pszScriptName, pszVMExtension );
109+ {
110+ scriptPath.sprintf (SCRIPT_PATH " /%s%s" , pszScriptName, pszVMExtension);
111+ }
112+ #else
113+ if (pszIncomingExtension)
114+ {
115+ scriptPath.sprintf (" scripts/vscripts/%s" , pszScriptName);
93116 }
117+ else
118+ {
119+ scriptPath.sprintf (" scripts/vscripts/%s%s" , pszScriptName, pszVMExtension);
120+ }
121+ #endif
94122
95123 const char *pBase;
96124 CUtlBuffer bufferScript;
@@ -258,12 +286,76 @@ CON_COMMAND( script, "Run the text as a script" )
258286 }
259287}
260288
289+ #ifdef BDSBASE
290+ static void ScriptFileAutocompleteRecursive (const char * pDirectory, const char * pExtension,
291+ const char * pMatch, int & nMatches, const char * pCommandName, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
292+ {
293+ char szDirectory[MAX_PATH];
294+ V_snprintf (szDirectory, sizeof (szDirectory), " %s/*" , pDirectory);
261295
296+ FileFindHandle_t hFile;
297+ const char * pFileName = filesystem->FindFirst (szDirectory, &hFile);
298+ while (pFileName)
299+ {
300+ if (*pFileName != ' .' )
301+ {
302+ char szCompleteFilename[MAX_PATH];
303+ V_snprintf (szCompleteFilename, sizeof (szCompleteFilename), " %s/%s" , pDirectory, pFileName);
304+ if (g_pFullFileSystem->FindIsDirectory (hFile))
305+ {
306+ ScriptFileAutocompleteRecursive (szCompleteFilename, pExtension, pMatch, nMatches, pCommandName, commands);
307+ }
308+ else
309+ {
310+ const char * pFileExtension = V_strrchr (pFileName, ' .' );
311+ if (pFileExtension && !V_stricmp (pFileExtension, pExtension))
312+ {
313+ if (V_strstr (pFileName, pMatch))
314+ V_snprintf (commands[nMatches++], COMMAND_COMPLETION_ITEM_LENGTH, " %s %s" ,
315+ pCommandName, szCompleteFilename + sizeof (SCRIPT_PATH));
316+ }
317+ }
318+ }
319+
320+ if (nMatches >= COMMAND_COMPLETION_MAXITEMS)
321+ break ;
322+
323+ pFileName = filesystem->FindNext (hFile);
324+ }
325+ filesystem->FindClose (hFile);
326+ }
327+
328+ static int script_execute_autocomplete (const char * partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
329+ {
330+ int nMatches = 0 ;
331+ if (g_pScriptVM)
332+ {
333+ const char * pExtension = g_pszScriptExtensions[g_pScriptVM->GetLanguage ()];
334+ #ifdef CLIENT_DLL
335+ const char * pCommandName = " script_execute_client" ;
336+ #else
337+ const char * pCommandName = " script_execute" ;
338+ #endif
339+ const char * pMatch = partial + V_strlen (pCommandName) + 1 ;
340+
341+ ScriptFileAutocompleteRecursive (SCRIPT_PATH, pExtension, pMatch, nMatches, pCommandName, commands);
342+ }
343+ return nMatches;
344+ }
345+ #endif
262346
347+ #ifdef BDSBASE
263348#ifdef CLIENT_DLL
264- CON_COMMAND ( script_execute_client, " Run a vscript file" )
349+ CON_COMMAND_F_COMPLETION ( script_execute_client, " Run a vscript file" , FCVAR_NONE, script_execute_autocomplete )
265350#else
266- CON_COMMAND ( script_execute, " Run a vscript file" )
351+ CON_COMMAND_F_COMPLETION (script_execute, " Run a vscript file" , FCVAR_NONE, script_execute_autocomplete)
352+ #endif
353+ #else
354+ #ifdef CLIENT_DLL
355+ CON_COMMAND (script_execute_client, " Run a vscript file" )
356+ #else
357+ CON_COMMAND (script_execute, " Run a vscript file" )
358+ #endif
267359#endif
268360{
269361#ifdef CLIENT_DLL
0 commit comments