Skip to content

Commit 734130a

Browse files
authored
Merge pull request #431 from samisalreadytaken/dev
vscript saverestore and debugger fixes
2 parents b3d5152 + 9b8ba3c commit 734130a

File tree

8 files changed

+638
-306
lines changed

8 files changed

+638
-306
lines changed

sp/src/game/shared/mapbase/vscript_singletons.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5146,6 +5146,11 @@ bool CScriptConvarAccessor::Init()
51465146
AddBlockedConVar( "cl_allowdownload" );
51475147
AddBlockedConVar( "cl_allowupload" );
51485148
AddBlockedConVar( "cl_downloadfilter" );
5149+
#ifdef GAME_DLL
5150+
AddBlockedConVar( "script_connect_debugger_on_mapspawn" );
5151+
#else
5152+
AddBlockedConVar( "script_connect_debugger_on_mapspawn_client" );
5153+
#endif
51495154

51505155
return true;
51515156
}

sp/src/vscript/sqdbg/sqdbg/debug.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,23 @@
106106
} while(0)
107107
#endif
108108
#define Verify( x ) Assert(x)
109+
#define STATIC_ASSERT( x ) static_assert( x, #x )
109110
#else
110111
#define DebuggerBreak() ((void)0)
111112
#define Assert( x ) ((void)0)
112113
#define AssertMsg( x, msg ) ((void)0)
113114
#define AssertMsg1( x, msg, a1 ) ((void)0)
114115
#define AssertMsg2( x, msg, a1, a2 ) ((void)0)
115116
#define Verify( x ) x
117+
#define STATIC_ASSERT( x )
116118
#endif // _DEBUG
117119

118120
#endif
119121

120122
#include <tier0/dbg.h>
121123

124+
#define STATIC_ASSERT COMPILE_TIME_ASSERT
125+
122126
// Misdefined for GCC in platform.h
123127
#undef UNREACHABLE
124128

sp/src/vscript/sqdbg/sqdbg/json.h

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,13 @@ static inline void PutStr( CBuffer *buffer, const string_t &str )
275275
#ifdef SQDBG_VALIDATE_SENT_MSG
276276
for ( unsigned int i = 0; i < str.len; i++ )
277277
{
278-
AssertMsg( IN_RANGE_CHAR( str.ptr[i], 0x20, 0x7E ) &&
279-
( ( str.ptr[i] != '\\' && str.ptr[i] != '\"' ) || ( i && str.ptr[i-1] == '\\' ) ),
280-
"control char in json string" );
278+
if ( str.ptr[i] == '\\' && ( str.ptr[i+1] == '\\' || str.ptr[i+1] == '\"' ) )
279+
{
280+
i++;
281+
continue;
282+
}
283+
284+
AssertMsg( str.ptr[i] != '\\' && IN_RANGE_CHAR( str.ptr[i], 0x20, 0x7E ), "control char in json string" );
281285
}
282286
#endif
283287
}
@@ -433,7 +437,7 @@ static inline void PutStr( CBuffer *buffer, const string_t &str, bool quote )
433437
idx += printhex< true, false >(
434438
mem + idx,
435439
buffer->Capacity() - idx,
436-
(SQChar)*(unsigned char*)c );
440+
(SQUnsignedChar)*(unsigned char*)c );
437441
}
438442
}
439443
}
@@ -503,6 +507,7 @@ static inline void PutInt( CBuffer *buffer, I val )
503507
template < bool padding, typename I >
504508
static inline void PutHex( CBuffer *buffer, I val )
505509
{
510+
STATIC_ASSERT( IS_UNSIGNED( I ) );
506511
buffer->base.Ensure( buffer->Size() + countdigits<16>( val ) + 1 );
507512
int len = printhex< padding >( buffer->Base() + buffer->Size(), buffer->Capacity() - buffer->Size(), val );
508513
buffer->size += len;
@@ -699,7 +704,7 @@ class wjson_table_t : public wjson_t
699704
}
700705
else
701706
{
702-
PutHex< false >( m_pBuffer, val );
707+
PutHex< false >( m_pBuffer, cast_unsigned( I, val ) );
703708
}
704709
PutChar( m_pBuffer, ']' );
705710
PutChar( m_pBuffer, '\"' );
@@ -850,7 +855,7 @@ class JSONParser
850855
else
851856
{
852857
buf = m_Allocator->Alloc(5);
853-
int i = printhex< true, true, false >( buf, 5, token );
858+
int i = printhex< true, true, false >( buf, 5, (unsigned char)token );
854859
Assert( i == 4 );
855860
buf[i] = 0;
856861
}
@@ -877,6 +882,24 @@ class JSONParser
877882
m_error[len] = 0;
878883
}
879884

885+
bool IsValue( char token )
886+
{
887+
switch ( token )
888+
{
889+
case Token_String:
890+
case Token_Integer:
891+
case Token_Float:
892+
case Token_False:
893+
case Token_True:
894+
case Token_Null:
895+
case Token_Table:
896+
case Token_Array:
897+
return true;
898+
default:
899+
return false;
900+
}
901+
}
902+
880903
char NextToken( string_t &token )
881904
{
882905
while ( m_cur < m_end )
@@ -1206,7 +1229,7 @@ class JSONParser
12061229
type = NextToken( token );
12071230
type = ParseValue( type, token, &kv->val );
12081231

1209-
if ( type == Token_Error )
1232+
if ( !IsValue( type ) )
12101233
{
12111234
SetError( "invalid token %s @ %i", Char(type), Index() );
12121235
return Token_Error;
@@ -1239,7 +1262,7 @@ class JSONParser
12391262

12401263
for (;;)
12411264
{
1242-
if ( type == Token_Error )
1265+
if ( !IsValue( type ) )
12431266
{
12441267
SetError( "expected '%c', got %s @ %i", ']', Char(type), Index() );
12451268
return Token_Error;
@@ -1315,7 +1338,7 @@ class JSONParser
13151338
value->type = JSON_NULL;
13161339
return type;
13171340
default:
1318-
return type;
1341+
return Token_Error;
13191342
}
13201343
}
13211344
};

sp/src/vscript/sqdbg/sqdbg/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ class CServerSocket
842842
m_pRecvBufPtr( m_pRecvBuf ),
843843
m_bWSAInit( false )
844844
{
845-
Assert( sizeof(m_pRecvBuf) <= ( 1 << ( sizeof(CMessagePool::message_t::len) * 8 ) ) );
845+
STATIC_ASSERT( sizeof(m_pRecvBuf) <= ( 1 << ( sizeof(CMessagePool::message_t::len) * 8 ) ) );
846846
}
847847
};
848848

0 commit comments

Comments
 (0)