42
42
#include " tier0/memdbgon.h"
43
43
44
44
extern IScriptManager *scriptmanager;
45
- CNetMsgScriptHelper *g_ScriptNetMsg = new CNetMsgScriptHelper();
46
45
47
46
// =============================================================================
48
47
// Net Prop Manager
@@ -401,7 +400,7 @@ class CScriptGameEventListener : public IGameEventListener2, public CAutoGameSys
401
400
// int m_nEventTick;
402
401
403
402
static StringHashFunctor Hash;
404
- static inline unsigned int HashContext ( const char * c ) { return (c && *c) ? Hash (c) : 0 ; }
403
+ static inline unsigned int HashContext ( const char * c ) { return c ? Hash (c) : 0 ; }
405
404
406
405
inline int GetIndex ()
407
406
{
@@ -574,11 +573,10 @@ void CScriptGameEventListener::LoadEventsFromFile( const char *filename, const c
574
573
void CScriptGameEventListener::DumpEventListeners ()
575
574
{
576
575
CGMsg ( 0 , CON_GROUP_VSCRIPT, " --- Script game event listener dump start\n " );
577
- CGMsg ( 0 , CON_GROUP_VSCRIPT, " # ADDRESS ID CONTEXT\n " );
576
+ CGMsg ( 0 , CON_GROUP_VSCRIPT, " # ID CONTEXT\n " );
578
577
FOR_EACH_VEC ( s_Listeners, i )
579
578
{
580
- CGMsg ( 0 , CON_GROUP_VSCRIPT, " %d (0x%p) %d : %u\n " , i,
581
- (void *)s_Listeners[i],
579
+ CGMsg ( 0 , CON_GROUP_VSCRIPT, " %d : %d : %u\n " , i,
582
580
s_Listeners[i]->GetIndex (),
583
581
s_Listeners[i]->m_iContextHash );
584
582
}
@@ -755,14 +753,12 @@ bool CScriptGameEventListener::StopListeningToGameEvent( int listener )
755
753
void CScriptGameEventListener::StopListeningToAllGameEvents ( const char * szContext )
756
754
{
757
755
unsigned int hash = HashContext ( szContext );
758
-
759
- // Iterate from the end so they can be safely removed as they are deleted
760
756
for ( int i = s_Listeners.Count (); i--; )
761
757
{
762
758
CScriptGameEventListener *pCur = s_Listeners[i];
763
759
if ( pCur->m_iContextHash == hash )
764
760
{
765
- s_Listeners.Remove (i); // keep list order
761
+ s_Listeners.FastRemove (i);
766
762
delete pCur;
767
763
}
768
764
}
@@ -1202,10 +1198,7 @@ HSCRIPT CScriptReadWriteFile::KeyValuesRead( const char *szFile )
1202
1198
1203
1199
return hScript;
1204
1200
}
1205
- #undef SCRIPT_MAX_FILE_READ_SIZE
1206
- #undef SCRIPT_MAX_FILE_WRITE_SIZE
1207
- #undef SCRIPT_RW_PATH_ID
1208
- #undef SCRIPT_RW_FULL_PATH_FMT
1201
+
1209
1202
1210
1203
// =============================================================================
1211
1204
// Network message helper
@@ -1215,6 +1208,8 @@ HSCRIPT CScriptReadWriteFile::KeyValuesRead( const char *szFile )
1215
1208
// The custom message name is hashed and sent as word with the message.
1216
1209
// =============================================================================
1217
1210
1211
+ static CNetMsgScriptHelper scriptnetmsg;
1212
+ CNetMsgScriptHelper *g_ScriptNetMsg = &scriptnetmsg;
1218
1213
1219
1214
#ifdef GAME_DLL
1220
1215
#define m_MsgIn_ () m_MsgIn->
@@ -2181,23 +2176,23 @@ END_SCRIPTDESC();
2181
2176
// =============================================================================
2182
2177
// ConVars
2183
2178
// =============================================================================
2184
- class CScriptConCommand : public ICommandCallback , public ICommandCompletionCallback
2179
+ class CScriptConCommand : public ConCommand , public ICommandCallback , public ICommandCompletionCallback
2185
2180
{
2181
+ typedef ConCommand BaseClass;
2182
+
2186
2183
public:
2187
2184
~CScriptConCommand ()
2188
2185
{
2189
2186
Unregister ();
2190
- delete m_pBase;
2191
2187
}
2192
2188
2193
2189
CScriptConCommand ( const char *name, HSCRIPT fn, const char *helpString, int flags, ConCommand *pLinked = NULL )
2190
+ : BaseClass( name, this , helpString, flags, 0 ),
2191
+ m_pLinked (pLinked),
2192
+ m_hCallback(fn),
2193
+ m_hCompletionCallback(NULL )
2194
2194
{
2195
- m_pBase = new ConCommand ( name, this , helpString, flags, 0 );
2196
- m_pLinked = pLinked;
2197
- m_hCallback = fn;
2198
- m_hCompletionCallback = NULL ;
2199
2195
m_nCmdNameLen = V_strlen (name) + 1 ;
2200
-
2201
2196
Assert ( m_nCmdNameLen - 1 <= 128 );
2202
2197
}
2203
2198
@@ -2272,17 +2267,17 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall
2272
2267
2273
2268
if (fn)
2274
2269
{
2275
- if ( !m_pBase-> IsRegistered () )
2270
+ if ( !BaseClass:: IsRegistered () )
2276
2271
return ;
2277
2272
2278
- m_pBase-> m_pCommandCompletionCallback = this ;
2279
- m_pBase-> m_bHasCompletionCallback = true ;
2273
+ BaseClass:: m_pCommandCompletionCallback = this ;
2274
+ BaseClass:: m_bHasCompletionCallback = true ;
2280
2275
m_hCompletionCallback = fn;
2281
2276
}
2282
2277
else
2283
2278
{
2284
- m_pBase-> m_pCommandCompletionCallback = NULL ;
2285
- m_pBase-> m_bHasCompletionCallback = false ;
2279
+ BaseClass:: m_pCommandCompletionCallback = NULL ;
2280
+ BaseClass:: m_bHasCompletionCallback = false ;
2286
2281
m_hCompletionCallback = NULL ;
2287
2282
}
2288
2283
}
@@ -2291,7 +2286,7 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall
2291
2286
{
2292
2287
if (fn)
2293
2288
{
2294
- if ( !m_pBase-> IsRegistered () )
2289
+ if ( !BaseClass:: IsRegistered () )
2295
2290
Register ();
2296
2291
2297
2292
if ( m_hCallback )
@@ -2306,8 +2301,8 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall
2306
2301
2307
2302
inline void Unregister ()
2308
2303
{
2309
- if ( g_pCVar && m_pBase-> IsRegistered () )
2310
- g_pCVar->UnregisterConCommand ( m_pBase );
2304
+ if ( g_pCVar && BaseClass:: IsRegistered () )
2305
+ g_pCVar->UnregisterConCommand ( this );
2311
2306
2312
2307
if ( g_pScriptVM )
2313
2308
{
@@ -2324,30 +2319,29 @@ class CScriptConCommand : public ICommandCallback, public ICommandCompletionCall
2324
2319
inline void Register ()
2325
2320
{
2326
2321
if ( g_pCVar )
2327
- g_pCVar->RegisterConCommand ( m_pBase );
2322
+ g_pCVar->RegisterConCommand ( this );
2328
2323
}
2329
2324
2330
2325
HSCRIPT m_hCallback;
2326
+ ConCommand *m_pLinked;
2331
2327
HSCRIPT m_hCompletionCallback;
2332
2328
int m_nCmdNameLen;
2333
- ConCommand *m_pLinked;
2334
- ConCommand *m_pBase;
2335
2329
};
2336
2330
2337
- class CScriptConVar
2331
+ class CScriptConVar : public ConVar
2338
2332
{
2333
+ typedef ConVar BaseClass;
2334
+
2339
2335
public:
2340
2336
~CScriptConVar ()
2341
2337
{
2342
2338
Unregister ();
2343
- delete m_pBase;
2344
2339
}
2345
2340
2346
2341
CScriptConVar ( const char *pName, const char *pDefaultValue, const char *pHelpString, int flags/* , float fMin, float fMax*/ )
2347
- {
2348
- m_pBase = new ConVar ( pName, pDefaultValue, flags, pHelpString );
2349
- m_hCallback = NULL ;
2350
- }
2342
+ : BaseClass( pName, pDefaultValue, flags, pHelpString ),
2343
+ m_hCallback (NULL )
2344
+ {}
2351
2345
2352
2346
void SetChangeCallback ( HSCRIPT fn )
2353
2347
{
@@ -2359,19 +2353,19 @@ class CScriptConVar
2359
2353
if (fn)
2360
2354
{
2361
2355
m_hCallback = fn;
2362
- m_pBase-> InstallChangeCallback ( (FnChangeCallback_t)ScriptConVarCallback );
2356
+ BaseClass:: InstallChangeCallback ( (FnChangeCallback_t)ScriptConVarCallback );
2363
2357
}
2364
2358
else
2365
2359
{
2366
2360
m_hCallback = NULL ;
2367
- m_pBase-> InstallChangeCallback ( NULL );
2361
+ BaseClass:: InstallChangeCallback ( NULL );
2368
2362
}
2369
2363
}
2370
2364
2371
2365
inline void Unregister ()
2372
2366
{
2373
- if ( g_pCVar && m_pBase-> IsRegistered () )
2374
- g_pCVar->UnregisterConCommand ( m_pBase );
2367
+ if ( g_pCVar && BaseClass:: IsRegistered () )
2368
+ g_pCVar->UnregisterConCommand ( this );
2375
2369
2376
2370
if ( g_pScriptVM )
2377
2371
{
@@ -2380,7 +2374,6 @@ class CScriptConVar
2380
2374
}
2381
2375
2382
2376
HSCRIPT m_hCallback;
2383
- ConVar *m_pBase;
2384
2377
};
2385
2378
2386
2379
static CUtlMap< unsigned int , bool > g_ConVarsBlocked ( DefLessFunc(unsigned int ) );
@@ -2541,8 +2534,8 @@ void CScriptConvarAccessor::RegisterCommand( const char *name, HSCRIPT fn, const
2541
2534
int idx = g_ScriptConCommands.Find (hash);
2542
2535
if ( idx == g_ScriptConCommands.InvalidIndex () )
2543
2536
{
2544
- ConCommand *pLinked = NULL ;
2545
- if ( g_pCVar-> FindVar (name) || ( ((pLinked = g_pCVar-> FindCommand (name)) != NULL ) && !IsOverridable (hash) ) )
2537
+ ConCommandBase *pBase = g_pCVar-> FindCommandBase (name) ;
2538
+ if ( pBase && ( !pBase-> IsCommand () || !IsOverridable (hash) ) )
2546
2539
{
2547
2540
DevWarning ( 1 , " CScriptConvarAccessor::RegisterCommand unable to register blocked ConCommand: %s\n " , name );
2548
2541
return ;
@@ -2551,7 +2544,7 @@ void CScriptConvarAccessor::RegisterCommand( const char *name, HSCRIPT fn, const
2551
2544
if ( !fn )
2552
2545
return ;
2553
2546
2554
- CScriptConCommand *p = new CScriptConCommand ( name, fn, helpString, flags, pLinked );
2547
+ CScriptConCommand *p = new CScriptConCommand ( name, fn, helpString, flags, static_cast < ConCommand* >(pBase) );
2555
2548
g_ScriptConCommands.Insert ( hash, p );
2556
2549
}
2557
2550
else
@@ -2589,7 +2582,7 @@ void CScriptConvarAccessor::RegisterConvar( const char *name, const char *pDefau
2589
2582
int idx = g_ScriptConVars.Find (hash);
2590
2583
if ( idx == g_ScriptConVars.InvalidIndex () )
2591
2584
{
2592
- if ( g_pCVar->FindVar (name) || g_pCVar-> FindCommand (name) )
2585
+ if ( g_pCVar->FindCommandBase (name) )
2593
2586
{
2594
2587
DevWarning ( 1 , " CScriptConvarAccessor::RegisterConvar unable to register blocked ConCommand: %s\n " , name );
2595
2588
return ;
0 commit comments