Skip to content

Commit 58622a2

Browse files
Add script_connect_debugger_on_mapspawn cvar
1 parent 97c4b05 commit 58622a2

File tree

7 files changed

+38
-26
lines changed

7 files changed

+38
-26
lines changed

sp/src/game/client/vscript_client.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extern IScriptManager *scriptmanager;
2929
extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );
3030

3131
#ifdef MAPBASE_VSCRIPT
32-
extern int vscript_debugger_port;
32+
ConVar script_connect_debugger_on_mapspawn_client( "script_connect_debugger_on_mapspawn_client", "0" );
3333
#endif
3434

3535
// #define VMPROFILE 1
@@ -687,10 +687,13 @@ bool VScriptClientInit()
687687
#endif
688688

689689
#ifdef MAPBASE_VSCRIPT
690-
if ( vscript_debugger_port )
690+
if ( script_connect_debugger_on_mapspawn_client.GetInt() == 2 )
691+
{
692+
g_pScriptVM->ConnectDebugger( vscript_debugger_port, 10.0f );
693+
}
694+
else if ( script_connect_debugger_on_mapspawn_client.GetInt() != 0 )
691695
{
692696
g_pScriptVM->ConnectDebugger( vscript_debugger_port );
693-
vscript_debugger_port = 0;
694697
}
695698
#endif
696699

sp/src/game/server/vscript_server.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );
2424

2525
#ifdef MAPBASE_VSCRIPT
26-
extern int vscript_debugger_port;
26+
ConVar script_connect_debugger_on_mapspawn( "script_connect_debugger_on_mapspawn", "0" );
2727
#endif
2828

2929
// #define VMPROFILE 1
@@ -668,10 +668,13 @@ bool VScriptServerInit()
668668
#endif
669669

670670
#ifdef MAPBASE_VSCRIPT
671-
if ( vscript_debugger_port )
671+
if ( script_connect_debugger_on_mapspawn.GetInt() == 2 )
672+
{
673+
g_pScriptVM->ConnectDebugger( vscript_debugger_port, 10.0f );
674+
}
675+
else if ( script_connect_debugger_on_mapspawn.GetInt() != 0 )
672676
{
673677
g_pScriptVM->ConnectDebugger( vscript_debugger_port );
674-
vscript_debugger_port = 0;
675678
}
676679
#endif
677680

sp/src/game/shared/vscript_shared.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );
3737
#ifdef MAPBASE_VSCRIPT
3838
// This is to ensure a dependency exists between the vscript library and the game DLLs
3939
extern int vscript_token;
40-
extern int vscript_debugger_port;
4140
int vscript_token_hack = vscript_token;
4241
#endif
4342

@@ -391,27 +390,14 @@ CON_COMMAND_F( script_debug, "Connect the vscript VM to the script debugger", FC
391390
if ( !IsCommandIssuedByServerAdmin() )
392391
return;
393392

394-
#ifdef MAPBASE_VSCRIPT
395-
#ifdef GAME_DLL
396-
int port = 1212;
397-
#else
398-
int port = 1213;
399-
#endif
400-
#endif
401-
402393
if ( !g_pScriptVM )
403394
{
404-
#ifdef MAPBASE_VSCRIPT
405-
vscript_debugger_port = port;
406-
CGMsg( 0, CON_GROUP_VSCRIPT, "VScript VM is not running, waiting for it to attach the debugger to port %d...\n", port );
407-
#else
408395
CGWarning( 0, CON_GROUP_VSCRIPT, "Scripting disabled or no server running\n" );
409-
#endif
410396
return;
411397
}
412398

413399
#ifdef MAPBASE_VSCRIPT
414-
g_pScriptVM->ConnectDebugger( port );
400+
g_pScriptVM->ConnectDebugger( vscript_debugger_port );
415401
#else
416402
g_pScriptVM->ConnectDebugger();
417403
#endif

sp/src/game/shared/vscript_shared.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class CBaseEntityScriptInstanceHelper : public IScriptInstanceHelper
4343
extern CBaseEntityScriptInstanceHelper g_BaseEntityScriptInstanceHelper;
4444

4545
#ifdef MAPBASE_VSCRIPT
46+
#ifdef GAME_DLL
47+
const int vscript_debugger_port = 1212;
48+
#else
49+
const int vscript_debugger_port = 1213;
50+
#endif
51+
4652
void RegisterSharedScriptConstants();
4753
void RegisterSharedScriptFunctions();
4854

sp/src/public/vscript/ivscript.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ class IScriptVM
839839
virtual void Shutdown() = 0;
840840

841841
#ifdef MAPBASE_VSCRIPT
842-
virtual bool ConnectDebugger( int port = 0 ) = 0;
842+
virtual bool ConnectDebugger( int port = 0, float timeout = 0.0f ) = 0;
843843
#else
844844
virtual bool ConnectDebugger() = 0;
845845
#endif

sp/src/vscript/vscript.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
IScriptVM* makeSquirrelVM();
1818

1919
int vscript_token = 0;
20-
int vscript_debugger_port = 0;
2120

2221
class CScriptManager : public CTier1AppSystem<IScriptManager>
2322
{

sp/src/vscript/vscript_squirrel.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class SquirrelVM : public IScriptVM
141141
virtual bool Init() override;
142142
virtual void Shutdown() override;
143143

144-
virtual bool ConnectDebugger( int port = 0 ) override;
144+
virtual bool ConnectDebugger( int port = 0, float timeout = 0.0f ) override;
145145
virtual void DisconnectDebugger() override;
146146

147147
virtual ScriptLanguage_t GetLanguage() override;
@@ -2077,12 +2077,27 @@ void SquirrelVM::Shutdown()
20772077

20782078
bool VScriptRunScript( const char *pszScriptName, HSCRIPT hScope, bool bWarnMissing );
20792079

2080-
bool SquirrelVM::ConnectDebugger( int port )
2080+
bool SquirrelVM::ConnectDebugger( int port, float timeout )
20812081
{
20822082
if ( !debugger_ )
20832083
{
20842084
debugger_ = sqdbg_attach_debugger( vm_ );
2085-
sqdbg_listen_socket( debugger_, port );
2085+
2086+
if ( sqdbg_listen_socket( debugger_, port ) == 0 && timeout )
2087+
{
2088+
float startTime = Plat_FloatTime();
2089+
2090+
while ( !sqdbg_is_client_connected( debugger_ ) )
2091+
{
2092+
float time = Plat_FloatTime();
2093+
if ( time - startTime > timeout )
2094+
break;
2095+
2096+
ThreadSleep( 50 );
2097+
2098+
sqdbg_frame( debugger_ );
2099+
}
2100+
}
20862101
}
20872102
else
20882103
{

0 commit comments

Comments
 (0)