forked from ReactiveDrop/reactivedrop_public_src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
1543 lines (1297 loc) · 42.1 KB
/
client.cpp
File metadata and controls
1543 lines (1297 loc) · 42.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//======= Copyright (c) 1996-2009, Valve Corporation, All rights reserved. ======
//
// Purpose: client/server game specific stuff
//
//===============================================================================
#include "cbase.h"
#include "player.h"
#include "client.h"
#include "soundent.h"
#include "gamerules.h"
#include "game.h"
#include "physics.h"
#include "entitylist.h"
#include "shake.h"
#include "globalstate.h"
#include "event_tempentity_tester.h"
#include "ndebugoverlay.h"
#include "engine/IEngineSound.h"
#include <ctype.h>
#include "tier1/strtools.h"
#include "te_effect_dispatch.h"
#include "globals.h"
#include "nav_mesh.h"
#include "team.h"
#include "EventLog.h"
#include "datacache/imdlcache.h"
#include "basemultiplayerplayer.h"
#include "voice_gamemgr.h"
#include "fmtstr.h"
#include "videocfg/videocfg.h"
#ifdef HL2_DLL
#include "weapon_physcannon.h"
#endif
#ifdef INFESTED_DLL
#include "asw_gamerules.h"
#include "asw_player.h"
#include "asw_marine.h"
#include "asw_equipment_list.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern int giPrecacheGrunt;
extern bool IsInCommentaryMode( void );
ConVar *sv_cheats = NULL;
ConVar rd_check_clientdll_consistency( "rd_check_clientdll_consistency", RD_IS_RELEASE ? "1" : "0", FCVAR_NOTIFY, "If 1, client.dll must match on the client and server. Default is 0 on beta, 1 on other branches." );
#define P_MAX_LEN 127 //used in CheckChatText and Host_Say to limit p pointer where pszFormat + pszPrefix + pszLocation + p as main text and few more symbols define the full text string. should be under 256
//also seems not to be really usefull without client adjustment m_pInput->SetMaximumCharCount( 127 ); in hud_basechat.cpp
char * CheckChatText( CBasePlayer *pPlayer, char *text )
{
char *p = text;
// invalid if NULL or empty
if ( !text || !text[0] )
return NULL;
int length = Q_strlen( text );
// remove quotes (leading & trailing) if present
if (*p == '"')
{
p++;
length -=2;
p[length] = 0;
}
// cut off after P_MAX_LEN chars
if ( length > P_MAX_LEN )
{
// don't split utf-8 code point
size_t i = P_MAX_LEN;
while( i > 0 && ( static_cast<uint8_t>(p[i]) & 0b1100'0000 ) == 0b1000'0000 ) --i;
p[i] = '\0';
}
GameRules()->CheckChatText( pPlayer, p );
return p;
}
//// HOST_SAY
// String comes in as
// say blah blah blah
// or as
// blah blah blah
//
void Host_Say( edict_t *pEdict, const CCommand &args, bool teamonly )
{
CBasePlayer *client;
int j;
char *p;
char text[256];
char szTemp[256];
const char *cpSay = "say";
const char *cpSayTeam = "say_team";
const char *pcmd = args[0];
bool bSenderDead = false;
// We can get a raw string now, without the "say " prepended
if ( args.ArgC() == 0 )
return;
if ( !stricmp( pcmd, cpSay) || !stricmp( pcmd, cpSayTeam ) )
{
if ( args.ArgC() >= 2 )
{
//p = (char *)args.ArgS();
Q_strncpy(szTemp, args.ArgS(), sizeof(szTemp) - 1);
szTemp[sizeof(szTemp) - 1] = '\0';
p = szTemp;
}
else
{
// say with a blank message, nothing to do
return;
}
}
else // Raw text, need to prepend argv[0]
{
if ( args.ArgC() >= 2 )
{
Q_snprintf( szTemp,sizeof(szTemp), "%s %s", pcmd, args.ArgS() );
}
else
{
// Just a one word command, use the first word...sigh
Q_snprintf( szTemp,sizeof(szTemp), "%s", pcmd );
}
p = szTemp;
}
CBasePlayer *pPlayer = NULL;
if ( pEdict )
{
pPlayer = ((CBasePlayer *)CBaseEntity::Instance( pEdict ));
Assert( pPlayer );
// make sure the text has valid content
p = CheckChatText( pPlayer, p );
}
if ( !p )
return;
if ( pEdict )
{
if ( !pPlayer->CanSpeak() )
return;
// See if the player wants to modify of check the text
pPlayer->CheckChatText( p, P_MAX_LEN ); // though the buffer szTemp that p points to is 256,
// chat text is capped to P_MAX_LEN in CheckChatText above //this one is actually empty
// make sure the text has valid content
p = CheckChatText( pPlayer, p );
if ( !p )
return;
Assert( strlen( pPlayer->GetPlayerName() ) > 0 );
bSenderDead = ( pPlayer->m_lifeState != LIFE_ALIVE );
}
else
{
bSenderDead = false;
}
const char *pszFormat = NULL;
const char *pszPrefix = NULL;
const char *pszLocation = NULL;
if ( g_pGameRules )
{
pszFormat = g_pGameRules->GetChatFormat( teamonly, pPlayer );
pszPrefix = g_pGameRules->GetChatPrefix( teamonly, pPlayer );
pszLocation = g_pGameRules->GetChatLocation( teamonly, pPlayer );
}
const char *pszPlayerName = pPlayer ? pPlayer->GetPlayerName():"Console";
if ( pszPrefix && strlen( pszPrefix ) > 0 )
{
if ( pszLocation && strlen( pszLocation ) )
{
Q_snprintf( text, sizeof(text), "%s %s @ %s: ", pszPrefix, pszPlayerName, pszLocation );
}
else
{
Q_snprintf( text, sizeof(text), "%s %s: ", pszPrefix, pszPlayerName );
}
}
else
{
Q_snprintf( text, sizeof(text), "%s: ", pszPlayerName );
}
j = sizeof(text) - 2 - strlen(text); // -2 for /n and null terminator
if ( (int)strlen(p) > j )
p[j] = 0;
Q_strncat( text, p, sizeof( text ), COPY_ALL_CHARACTERS );
Q_strncat( text, "\n", sizeof( text ), COPY_ALL_CHARACTERS );
// loop through all players
// Start with the first player.
// This may return the world in single player if the client types something between levels or during spawn
// so check it, or it will infinite loop
client = NULL;
for ( int i = 1; i <= gpGlobals->maxClients; i++ )
{
client = ToBaseMultiplayerPlayer( UTIL_PlayerByIndex( i ) );
if ( !client || !client->edict() )
continue;
if ( client->edict() != pEdict )
{
if ( !(client->IsNetClient()) ) // Not a client ? (should never be true)
continue;
if ( teamonly && !g_pGameRules->PlayerCanHearChat( client, pPlayer ) )
continue;
if ( pPlayer && !client->CanHearAndReadChatFrom( pPlayer ) )
continue;
if ( pPlayer && GetVoiceGameMgr() && GetVoiceGameMgr()->IsPlayerIgnoringPlayer( pPlayer->entindex(), i ) )
continue;
}
const char* newText = text;
#ifdef INFESTED_DLL
if ( CAlienSwarm *pAlienSwarm = ASWGameRules() )
{
ScriptVariant_t args[3];
args[0] = ToHScript( client );
args[1] = ToHScript( pPlayer );
args[2] = ScriptVariant_t( newText );
pAlienSwarm->RunScriptFunctionInListenerScopes( "OnReceivedTextMessage", &args[2], NELEMS(args), args );
ScriptVariant_t result = args[2];
if ( result.m_type != FIELD_CSTRING )
continue;
newText = result.m_pszString;
}
#endif // INFESTED_DLL
CSingleUserRecipientFilter user( client );
user.MakeReliable();
if ( pszFormat )
{
UTIL_SayText2Filter( user, pPlayer, true, pszFormat, pszPlayerName, p, pszLocation );
}
else
{
UTIL_SayTextFilter( user, newText, pPlayer, true );
}
}
// echo to server console
// Adrian: Only do this if we're running a dedicated server since we already print to console on the client.
if ( engine->IsDedicatedServer() )
Msg( "%s", text );
Assert( p );
int userid = 0;
const char *networkID = "Console";
const char *playerName = "Console";
const char *playerTeam = "Console";
if ( pPlayer )
{
userid = pPlayer->GetUserID();
networkID = pPlayer->GetNetworkIDString();
playerName = pPlayer->GetPlayerName();
CTeam *team = pPlayer->GetTeam();
if ( team )
{
playerTeam = team->GetName();
}
}
if ( teamonly )
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" say_team \"%s\"\n", playerName, userid, networkID, playerTeam, p );
else
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" say \"%s\"\n", playerName, userid, networkID, playerTeam, p );
IGameEvent * event = gameeventmanager->CreateEvent( "player_say" );
if ( event ) // will be null if there are no listeners!
{
event->SetInt("userid", userid );
event->SetString("text", p );
event->SetInt("priority", 1 ); // HLTV event priority, not transmitted
gameeventmanager->FireEvent( event );
}
}
PRECACHE_REGISTER_BEGIN( GLOBAL, ClientPrecache )
// Precache cable textures.
PRECACHE( MODEL, "cable/cable.vmt" )
PRECACHE( MODEL, "cable/cable_lit.vmt" )
PRECACHE( MODEL, "cable/chain.vmt" )
PRECACHE( MODEL, "cable/rope.vmt" )
PRECACHE( MODEL, "sprites/blueglow1.vmt" )
PRECACHE( MODEL, "sprites/purpleglow1.vmt" )
PRECACHE( MODEL, "sprites/purplelaser1.vmt" )
PRECACHE( GAMESOUND, "Error" )
PRECACHE( GAMESOUND, "Hud.Hint" )
PRECACHE( GAMESOUND, "Player.FallDamage" )
PRECACHE( GAMESOUND, "Player.Swim" )
// General HUD sounds
PRECACHE( GAMESOUND, "Player.PickupWeapon" )
PRECACHE( GAMESOUND, "Player.DenyWeaponSelection" )
PRECACHE( GAMESOUND, "Player.WeaponSelected" )
PRECACHE( GAMESOUND, "Player.WeaponSelectionClose" )
PRECACHE( GAMESOUND, "Player.WeaponSelectionMoveSlot" )
// General legacy temp ents sounds
PRECACHE( GAMESOUND, "Bounce.Glass" )
PRECACHE( GAMESOUND, "Bounce.Metal" )
PRECACHE( GAMESOUND, "Bounce.Flesh" )
PRECACHE( GAMESOUND, "Bounce.Wood" )
PRECACHE( GAMESOUND, "Bounce.Shrapnel" )
PRECACHE( GAMESOUND, "Bounce.ShotgunShell" )
PRECACHE( GAMESOUND, "Bounce.Shell" )
PRECACHE( GAMESOUND, "Bounce.Concrete" )
PRECACHE( GAMESOUND, "BaseEntity.EnterWater" )
PRECACHE( GAMESOUND, "BaseEntity.ExitWater" )
// Game Instructor sounds
PRECACHE( GAMESOUND, "Instructor.LessonStart" )
PRECACHE( GAMESOUND, "Instructor.ImportantLessonStart" )
PRECACHE_REGISTER_END()
void ClientPrecache( void )
{
ClientGamePrecache();
if ( !IsX360() && !engine->IsDedicatedServerForXbox() )
{
// Force levels
char pBuf[MAX_PATH];
for ( int i = 0; i < CPU_LEVEL_PC_COUNT; ++i )
{
Q_snprintf( pBuf, sizeof( pBuf ), "cfg/cpu_level_%d_pc.ekv", i );
engine->ForceExactFile( pBuf );
Q_snprintf( pBuf, sizeof( pBuf ), "cfg/cpu_level_%d_pc_ss.ekv", i );
engine->ForceExactFile( pBuf );
}
for ( int i = 0; i < GPU_LEVEL_PC_COUNT; ++i )
{
Q_snprintf( pBuf, sizeof( pBuf ), "cfg/gpu_level_%d_pc.ekv", i );
engine->ForceExactFile( pBuf );
}
for ( int i = 0; i < MEM_LEVEL_PC_COUNT; ++i )
{
Q_snprintf( pBuf, sizeof( pBuf ), "cfg/mem_level_%d_pc.ekv", i );
engine->ForceExactFile( pBuf );
}
for ( int i = 0; i < GPU_MEM_LEVEL_PC_COUNT; ++i )
{
Q_snprintf( pBuf, sizeof( pBuf ), "cfg/gpu_mem_level_%d_pc.ekv", i );
engine->ForceExactFile( pBuf );
}
}
else
{
engine->ForceExactFile( "cfg/mem_level_360.ekv" );
engine->ForceExactFile( "cfg/gpu_mem_level_360.ekv" );
engine->ForceExactFile( "cfg/gpu_level_360.ekv" );
engine->ForceExactFile( "cfg/cpu_level_360.ekv" );
engine->ForceExactFile( "cfg/cpu_level_360_ss.ekv" );
}
if ( rd_check_clientdll_consistency.GetBool() )
{
engine->ForceExactFile( "bin/client.dll" );
}
}
CON_COMMAND_F( cast_ray, "Tests collision detection", FCVAR_CHEAT )
{
CBasePlayer *pPlayer = UTIL_GetCommandClient();
Vector forward;
trace_t tr;
pPlayer->EyeVectors( &forward );
Vector start = pPlayer->EyePosition();
UTIL_TraceLine(start, start + forward * MAX_COORD_RANGE, MASK_SOLID, pPlayer, COLLISION_GROUP_NONE, &tr );
if ( tr.DidHit() )
{
DevMsg(1, "Hit %s\nposition %.2f, %.2f, %.2f\nangles %.2f, %.2f, %.2f\n", tr.m_pEnt->GetClassname(),
tr.m_pEnt->GetAbsOrigin().x, tr.m_pEnt->GetAbsOrigin().y, tr.m_pEnt->GetAbsOrigin().z,
tr.m_pEnt->GetAbsAngles().x, tr.m_pEnt->GetAbsAngles().y, tr.m_pEnt->GetAbsAngles().z );
DevMsg(1, "Hit: hitbox %d, hitgroup %d, physics bone %d, solid %d, surface %s, surfaceprop %s, contents %08lx\n", tr.hitbox, tr.hitgroup, tr.physicsbone, tr.m_pEnt->GetSolid(), tr.surface.name, physprops->GetPropName( tr.surface.surfaceProps ), tr.contents );
NDebugOverlay::Line( start, tr.endpos, 0, 255, 0, false, 10 );
NDebugOverlay::Line( tr.endpos, tr.endpos + tr.plane.normal * 12, 255, 255, 0, false, 10 );
}
}
CON_COMMAND_F( cast_hull, "Tests hull collision detection", FCVAR_CHEAT )
{
CBasePlayer *pPlayer = UTIL_GetCommandClient();
Vector forward;
trace_t tr;
Vector extents;
extents.Init(16,16,16);
pPlayer->EyeVectors( &forward );
Vector start = pPlayer->EyePosition();
UTIL_TraceHull(start, start + forward * MAX_COORD_RANGE, -extents, extents, MASK_SOLID, pPlayer, COLLISION_GROUP_NONE, &tr );
if ( tr.DidHit() )
{
DevMsg(1, "Hit %s\nposition %.2f, %.2f, %.2f\nangles %.2f, %.2f, %.2f\n", tr.m_pEnt->GetClassname(),
tr.m_pEnt->GetAbsOrigin().x, tr.m_pEnt->GetAbsOrigin().y, tr.m_pEnt->GetAbsOrigin().z,
tr.m_pEnt->GetAbsAngles().x, tr.m_pEnt->GetAbsAngles().y, tr.m_pEnt->GetAbsAngles().z );
DevMsg(1, "Hit: hitbox %d, hitgroup %d, physics bone %d, solid %d, surface %s, surfaceprop %s\n", tr.hitbox, tr.hitgroup, tr.physicsbone, tr.m_pEnt->GetSolid(), tr.surface.name, physprops->GetPropName( tr.surface.surfaceProps ) );
NDebugOverlay::SweptBox( start, tr.endpos, -extents, extents, vec3_angle, 0, 0, 255, 0, 10 );
Vector end = tr.endpos;// - tr.plane.normal * DotProductAbs( tr.plane.normal, extents );
NDebugOverlay::Line( end, end + tr.plane.normal * 24, 255, 255, 64, false, 10 );
}
}
//-----------------------------------------------------------------------------
// Purpose: Used to find targets for ent_* commands
// Without a name, returns the entity under the player's crosshair.
// With a name it finds entities via name/classname/index
//-----------------------------------------------------------------------------
CBaseEntity *GetNextCommandEntity( CBasePlayer *pPlayer, const char *name, CBaseEntity *ent )
{
if ( !pPlayer )
return NULL;
// If no name was given set bits based on the picked
if (FStrEq(name,""))
{
// If we've already found an entity, return NULL.
// Makes it easier to write code using this func.
if ( ent )
return NULL;
return pPlayer ? pPlayer->FindPickerEntity() : NULL;
}
int index = atoi( name );
if ( index )
{
// If we've already found an entity, return NULL.
// Makes it easier to write code using this func.
if ( ent )
return NULL;
return CBaseEntity::Instance( index );
}
// Loop through all entities matching, starting from the specified previous
while ( (ent = gEntList.NextEnt(ent)) != NULL )
{
if ( (ent->GetEntityName() != NULL_STRING && ent->NameMatches(name)) ||
(ent->m_iClassname != NULL_STRING && ent->ClassMatches(name)) )
{
return ent;
}
}
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose: called each time a player uses a "cmd" command
// Input : pPlayer - the player who issued the command
//-----------------------------------------------------------------------------
void SetDebugBits( CBasePlayer* pPlayer, const char *name, int bit )
{
if ( !pPlayer )
return;
CBaseEntity *pEntity = NULL;
while ( (pEntity = GetNextCommandEntity( pPlayer, name, pEntity )) != NULL )
{
if (pEntity->m_debugOverlays & bit)
{
pEntity->m_debugOverlays &= ~bit;
}
else
{
pEntity->m_debugOverlays |= bit;
#ifdef AI_MONITOR_FOR_OSCILLATION
if( pEntity->IsNPC() )
{
pEntity->MyNPCPointer()->m_ScheduleHistory.RemoveAll();
}
#endif//AI_MONITOR_FOR_OSCILLATION
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : pKillTargetName -
//-----------------------------------------------------------------------------
void KillTargets( const char *pKillTargetName )
{
CBaseEntity *pentKillTarget = NULL;
DevMsg( 2, "KillTarget: %s\n", pKillTargetName );
pentKillTarget = gEntList.FindEntityByName( NULL, pKillTargetName );
while ( pentKillTarget )
{
UTIL_Remove( pentKillTarget );
DevMsg( 2, "killing %s\n", STRING( pentKillTarget->m_iClassname ) );
pentKillTarget = gEntList.FindEntityByName( pentKillTarget, pKillTargetName );
}
}
//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
void ConsoleKillTarget( CBasePlayer *pPlayer, const char *name )
{
// If no name was given use the picker
if (FStrEq(name,""))
{
CBaseEntity *pEntity = pPlayer ? pPlayer->FindPickerEntity() : NULL;
if ( pEntity )
{
UTIL_Remove( pEntity );
Msg( "killing %s\n", pEntity->GetDebugName() );
return;
}
}
// Otherwise use name or classname
KillTargets( name );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CPointClientCommand : public CPointEntity
{
public:
DECLARE_CLASS( CPointClientCommand, CPointEntity );
DECLARE_DATADESC();
void InputCommand( inputdata_t& inputdata );
};
void CPointClientCommand::InputCommand( inputdata_t& inputdata )
{
if ( !inputdata.value.String()[0] )
return;
edict_t *pClient = NULL;
if ( gpGlobals->maxClients == 1 )
{
pClient = INDEXENT( 1 );
}
else
{
// In multiplayer, send it back to the activator
CBasePlayer *player = dynamic_cast< CBasePlayer * >( inputdata.pActivator );
if ( player )
{
pClient = player->edict();
}
if ( IsInCommentaryMode() && !pClient )
{
// Commentary is stuffing a command in. We'll pretend it came from the first player.
pClient = INDEXENT( 1 );
}
}
if ( !pClient || !pClient->GetUnknown() )
return;
engine->ClientCommand( pClient, "%s\n", inputdata.value.String() );
}
BEGIN_DATADESC( CPointClientCommand )
DEFINE_INPUTFUNC( FIELD_STRING, "Command", InputCommand ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( point_clientcommand, CPointClientCommand );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CPointServerCommand : public CPointEntity
{
public:
DECLARE_CLASS( CPointServerCommand, CPointEntity );
DECLARE_DATADESC();
void InputCommand( inputdata_t& inputdata );
};
//-----------------------------------------------------------------------------
// Purpose:
// Input : inputdata -
//-----------------------------------------------------------------------------
void CPointServerCommand::InputCommand( inputdata_t& inputdata )
{
if ( !inputdata.value.String()[0] )
return;
engine->ServerCommand( UTIL_VarArgs( "%s\n", inputdata.value.String() ) );
}
BEGIN_DATADESC( CPointServerCommand )
DEFINE_INPUTFUNC( FIELD_STRING, "Command", InputCommand ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( point_servercommand, CPointServerCommand );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CPointBroadcastClientCommand : public CPointEntity
{
public:
DECLARE_CLASS( CPointBroadcastClientCommand, CPointEntity );
DECLARE_DATADESC();
void InputCommand( inputdata_t& inputdata );
};
//-----------------------------------------------------------------------------
// Purpose:
// Input : inputdata -
//-----------------------------------------------------------------------------
void CPointBroadcastClientCommand::InputCommand( inputdata_t& inputdata )
{
if ( !inputdata.value.String()[0] )
return;
for ( int i = 1; i <= gpGlobals->maxClients; ++i )
{
CBasePlayer *pl = UTIL_PlayerByIndex( i );
if ( !pl )
continue;
edict_t *pClient = pl->edict();
if ( !pClient || !pClient->GetUnknown() )
continue;
engine->ClientCommand( pClient, "%s\n", inputdata.value.String() );
}
}
BEGIN_DATADESC( CPointBroadcastClientCommand )
DEFINE_INPUTFUNC( FIELD_STRING, "Command", InputCommand ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( point_broadcastclientcommand, CPointBroadcastClientCommand );
//------------------------------------------------------------------------------
// Purpose : Draw a line betwen two points. White if no world collisions, red if collisions
// Input :
// Output :
//------------------------------------------------------------------------------
void CC_DrawLine( const CCommand &args )
{
Vector startPos;
Vector endPos;
startPos.x = atof(args[1]);
startPos.y = atof(args[2]);
startPos.z = atof(args[3]);
endPos.x = atof(args[4]);
endPos.y = atof(args[5]);
endPos.z = atof(args[6]);
UTIL_AddDebugLine(startPos,endPos,true,true);
}
static ConCommand drawline("drawline", CC_DrawLine, "Draws line between two 3D Points.\n\tGreen if no collision\n\tRed is collides with something\n\tArguments: x1 y1 z1 x2 y2 z2", FCVAR_CHEAT);
//------------------------------------------------------------------------------
// Purpose : Draw a cross at a points.
// Input :
// Output :
//------------------------------------------------------------------------------
void CC_DrawCross( const CCommand &args )
{
Vector vPosition;
vPosition.x = atof(args[1]);
vPosition.y = atof(args[2]);
vPosition.z = atof(args[3]);
// Offset since min and max z in not about center
Vector mins = Vector(-5,-5,-5);
Vector maxs = Vector(5,5,5);
Vector start = mins + vPosition;
Vector end = maxs + vPosition;
UTIL_AddDebugLine(start,end,true,true);
start.x += (maxs.x - mins.x);
end.x -= (maxs.x - mins.x);
UTIL_AddDebugLine(start,end,true,true);
start.y += (maxs.y - mins.y);
end.y -= (maxs.y - mins.y);
UTIL_AddDebugLine(start,end,true,true);
start.x -= (maxs.x - mins.x);
end.x += (maxs.x - mins.x);
UTIL_AddDebugLine(start,end,true,true);
}
static ConCommand drawcross("drawcross", CC_DrawCross, "Draws a cross at the given location\n\tArguments: x y z", FCVAR_CHEAT);
#define TALK_INTERVAL 0.66 // min time between say commands from a client
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
CON_COMMAND( say, "Display player message" )
{
CBasePlayer *pPlayer = ToBasePlayer( UTIL_GetCommandClient() );
if ( pPlayer )
{
if (( pPlayer->LastTimePlayerTalked() + TALK_INTERVAL ) < gpGlobals->curtime)
{
Host_Say( pPlayer->edict(), args, 0 );
pPlayer->NotePlayerTalked();
}
}
else
{
Host_Say( NULL, args, 0 );
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
CON_COMMAND( say_team, "Display player message to team" )
{
CBasePlayer *pPlayer = ToBasePlayer( UTIL_GetCommandClient() );
if (pPlayer)
{
if (( pPlayer->LastTimePlayerTalked() + TALK_INTERVAL ) < gpGlobals->curtime)
{
Host_Say( pPlayer->edict(), args, 1 );
pPlayer->NotePlayerTalked();
}
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void CC_Player_SetModel( const CCommand &args )
{
if ( gpGlobals->deathmatch )
return;
CBasePlayer *pPlayer = ToBasePlayer( UTIL_GetCommandClient() );
if ( pPlayer && args.ArgC() == 2)
{
static char szName[256];
Q_snprintf( szName, sizeof( szName ), "models/%s.mdl", args[1] );
pPlayer->SetModel( szName );
UTIL_SetSize(pPlayer, VEC_HULL_MIN, VEC_HULL_MAX);
}
}
static ConCommand setmodel("setmodel", CC_Player_SetModel, "Changes's player's model", FCVAR_CHEAT );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CC_Player_TestDispatchEffect( const CCommand &args )
{
CBasePlayer *pPlayer = ToBasePlayer( UTIL_GetCommandClient() );
if ( !pPlayer)
return;
if ( args.ArgC() < 2 )
{
Msg(" Usage: test_dispatcheffect <effect name> <distance away> <flags> <magnitude> <scale>\n " );
Msg(" defaults are: <distance 1024> <flags 0> <magnitude 0> <scale 0>\n" );
return;
}
// Optional distance
float flDistance = 1024;
if ( args.ArgC() >= 3 )
{
flDistance = atoi( args[ 2 ] );
}
// Optional flags
float flags = 0;
if ( args.ArgC() >= 4 )
{
flags = atoi( args[ 3 ] );
}
// Optional magnitude
float magnitude = 0;
if ( args.ArgC() >= 5 )
{
magnitude = atof( args[ 4 ] );
}
// Optional scale
float scale = 0;
if ( args.ArgC() >= 6 )
{
scale = atof( args[ 5 ] );
}
Vector vecForward;
QAngle vecAngles = pPlayer->EyeAngles();
AngleVectors( vecAngles, &vecForward );
// Trace forward
trace_t tr;
Vector vecSrc = pPlayer->EyePosition();
Vector vecEnd = vecSrc + (vecForward * flDistance);
UTIL_TraceLine( vecSrc, vecEnd, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, &tr );
// Fill out the generic data
CEffectData data;
// If we hit something, use that data
if ( tr.fraction < 1.0 )
{
data.m_vOrigin = tr.endpos;
VectorAngles( tr.plane.normal, data.m_vAngles );
data.m_vNormal = tr.plane.normal;
}
else
{
data.m_vOrigin = vecEnd;
data.m_vAngles = vecAngles;
AngleVectors( vecAngles, &data.m_vNormal );
}
data.m_nEntIndex = pPlayer->entindex();
data.m_fFlags = flags;
data.m_flMagnitude = magnitude;
data.m_flScale = scale;
PrecacheEffect( (char *)args[1] );
DispatchEffect( (char *)args[1], data );
}
static ConCommand test_dispatcheffect("test_dispatcheffect", CC_Player_TestDispatchEffect, "Test a clientside dispatch effect.\n\tUsage: test_dispatcheffect <effect name> <distance away> <flags> <magnitude> <scale>\n\tDefaults are: <distance 1024> <flags 0> <magnitude 0> <scale 0>\n", FCVAR_CHEAT);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void CC_Player_Use( const CCommand &args )
{
CBasePlayer *pPlayer = ToBasePlayer( UTIL_GetCommandClient() );
if ( pPlayer)
{
pPlayer->SelectItem((char *)args[1]);
}
}
static ConCommand use("use", CC_Player_Use, "Use a particular weapon\t\nArguments: <weapon_name>");
class SimplePhysicsTraceFilter : public IPhysicsTraceFilter
{
CBaseEntity *m_pEntity;
int m_mask;
public:
SimplePhysicsTraceFilter( CBaseEntity *pEntity, int mask )
{
m_pEntity = pEntity;
m_mask = mask;
}
virtual bool ShouldHitObject( IPhysicsObject *pObject, int contentsMask )
{
if ( m_pEntity->VPhysicsGetObject() == pObject )
return false;
if ( (m_mask & contentsMask) == 0 )
return false;
return true;
}
virtual PhysicsTraceType_t GetTraceType() const
{
return VPHYSICS_TRACE_STATIC_AND_MOVING;
}
};
//------------------------------------------------------------------------------
// A small wrapper around SV_Move that never clips against the supplied entity.
//------------------------------------------------------------------------------
bool TestEntityPosition ( CBaseEntity *pEntity, unsigned int mask )
{
trace_t trace;
IPhysicsObject *physObject = pEntity->VPhysicsGetObject();
const Vector &origin = pEntity->GetAbsOrigin();
if ( physObject )
{
QAngle angles = pEntity->GetAbsAngles();
//Vector obbMins, obbMaxs;
Vector mins, maxs;
//obbMins = pEntity->CollisionProp()->OBBMins();
//obbMaxs = pEntity->CollisionProp()->OBBMaxs();
//pEntity->CollisionProp()->CollisionAABBToWorldAABB( obbMins, obbMaxs, &mins, &maxs );
pEntity->CollisionProp()->WorldSpaceSurroundingBounds( &mins, &maxs );
UTIL_TraceHull( vec3_origin, vec3_origin, mins, maxs, mask, pEntity, COLLISION_GROUP_NONE, &trace );
//SimplePhysicsTraceFilter filter( pEntity, (int)mask );
//physenv->SweepCollideable( physObject->GetCollide(), origin, origin, angles, mask, &filter, &trace );
}
else
{
UTIL_TraceEntity( pEntity, origin, origin, mask, &trace );
}
return (trace.startsolid == 0);
}
//------------------------------------------------------------------------------
// Searches along the direction ray in steps of "step" to see if
// the entity position is passible.
// Used for putting the player in valid space when toggling off noclip mode.
//------------------------------------------------------------------------------
static int FindPassableSpace( CBaseEntity *pEntity, unsigned int mask, const Vector& direction, float step, Vector& oldorigin )
{
int i;
for ( i = 0; i < 100; i++ )
{
Vector origin = pEntity->GetAbsOrigin();
VectorMA( origin, step, direction, origin );
pEntity->SetAbsOrigin( origin );
if ( TestEntityPosition( pEntity, mask ) )
{
VectorCopy( pEntity->GetAbsOrigin(), oldorigin );
return 1;
}
}
return 0;
}
//------------------------------------------------------------------------------
// Test various directions for empty space -- for debugging only; this is slow and
// meant for finding a place to put a noclipped player who goes solid again.
//------------------------------------------------------------------------------
bool FindEmptySpace( CBaseEntity *pEntity, unsigned int mask, const Vector &forward, const Vector &right, const Vector &up, Vector *testOrigin )
{
return FindPassableSpace( pEntity, mask, forward, 1, *testOrigin ) || // forward
FindPassableSpace( pEntity, mask, right, 1, *testOrigin ) || // right
FindPassableSpace( pEntity, mask, right, -1, *testOrigin ) || // left
FindPassableSpace( pEntity, mask, up, 1, *testOrigin ) || // up
FindPassableSpace( pEntity, mask, up, -1, *testOrigin ) || // down
FindPassableSpace( pEntity, mask, forward, -1, *testOrigin ) ; // back
}
//------------------------------------------------------------------------------
// Noclip
//------------------------------------------------------------------------------
ConVar noclip_fixup( "noclip_fixup", "1", FCVAR_CHEAT );
void EnableNoClip( CBasePlayer *pPlayer )
{
// Disengage from hierarchy
pPlayer->SetParent( NULL );
pPlayer->SetMoveType( MOVETYPE_NOCLIP );
ClientPrint( pPlayer, HUD_PRINTCONSOLE, "noclip ON\n" );
pPlayer->AddEFlags( EFL_NOCLIP_ACTIVE );
pPlayer->NoClipStateChanged();
UTIL_LogPrintf( "%s entered NOCLIP mode\n", GameLogSystem()->FormatPlayer( pPlayer ) );
}
void DisableNoClip( CBasePlayer *pPlayer )
{
CPlayerState *pl = pPlayer->PlayerData();
Assert( pl );
pPlayer->RemoveEFlags( EFL_NOCLIP_ACTIVE );