-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine_api.cpp
1575 lines (1203 loc) · 50.6 KB
/
engine_api.cpp
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
/*
* The GINA Bot - a computer opponent for Valve's FPS game Half-Life
* Copyright (c) 2011, Wei Mingzhi <[email protected]>
*
* This file is part of The GINA Bot.
*
* The GINA Bot is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* The GINA Bot is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with The GINA Bot; if not, visit <http://www.gnu.org/licenses>.
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*/
/***********************************************************
* engine_api.cpp *
***********************************************************
* Purpose: Implementation of Half-Life engine functions. *
* Engine-specific: yes *
***********************************************************
* Based on: HPB bot - botman's High Ping Bastard bot *
* (http://planethalflife.com/botman/) *
* *
* Partially based on: RACC by Pierre-Marie Baty *
* (http://racc.bots-united.com) *
***********************************************************/
#include "main.h"
/**
* The purpose of this function is to precache (load in memory) the 3D models that can have
* to be spawned during the game. This involves player skins, weapons, items, etc. The
* precaching of items can only be done at each loading of a new map.
*/
int pfnPrecacheModel(char* s)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "PrecacheModel(): %s", s);
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnPrecacheModel)(s);
}
/**
* The purpose of this function is to precache (load in memory) the sounds that can have to
* be played during the game. The precaching of items is done at each loading of a new map.
* We hook this function in order to compute at precache time the average loudness of the sound
* being precached, for having a quick reference when the bots have to hear one of them.
*/
int pfnPrecacheSound(char* s)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "PrecacheSound(): %s", s);
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnPrecacheSound)(s);
}
/**
* The purpose of this function is to ask the engine to set a model m (like "models/
* mechgibs.mdl") to entity e. The engine itself will provide the necessary changes
* in the edict's structure for it.
*/
void pfnSetModel(edict_t *e, const char *m)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "SetModel(): %x %s", e, m);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnSetModel)(e, m);
}
int pfnModelIndex(const char *m)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "ModelIndex(): %s", m);
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnModelIndex)(m);
}
int pfnModelFrames(int modelIndex)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "ModelFrames(): %d", modelIndex);
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnModelFrames)(modelIndex);
}
/**
* The purpose of this function is to ask the engine to set the bounding box size of the
* entity pointed to by e. The vector values passed in rgflMin and rgflMax as arrays of
* floats correspond to the lower left and upper right corners of the bounding box.
* Note that bounding boxes are always axial, i.e. parallel to the map axises.
*/
void pfnSetSize(edict_t *e, const float *rgflMin, const float *rgflMax)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "SetSize():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnSetSize)(e, rgflMin, rgflMax);
}
/**
* The purpose of this function is to ask the engine to shutdown the server and restart a
* new one running the map whose name is s1. It is used ONLY IN SINGLE PLAYER MODE and is
* transparent to the user, because it saves the player state and equipment and restores it
* back in the new level. The "changelevel trigger point" in the old level is linked to the
* new level's spawn point using the s2 string, which is formatted as follows: "trigger_name
* to spawnpoint_name", without spaces (for example, "tr_1atotr_2lm" would tell the engine
* the player has reached the trigger point "tr_1a" and has to spawn in the next level on the
* spawn point named "tr_2lm".
*/
void pfnChangeLevel(char* s1, char* s2)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "ChangeLevel(): %s, %s", s1, s2);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnChangeLevel)(s1, s2);
}
void pfnGetSpawnParms(edict_t *ent)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "GetSpawnParms(): %x", ent);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnGetSpawnParms)(ent);
}
void pfnSaveSpawnParms(edict_t *ent)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "SaveSpawnParms(): %x", ent);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnSaveSpawnParms)(ent);
}
float pfnVecToYaw(const float *rgflVector)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "VecToYaw():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnVecToYaw)(rgflVector);
}
/**
* The purpose of this function is to convert a spatial location determined by the vector
* passed in by rgflVectorIn as an array of float into absolute angles from the origin of
* the world that are written back in the rgflVectorOut array of float (which can be easily
* converted to angle vector).
*/
void pfnVecToAngles(const float *rgflVectorIn, float *rgflVectorOut)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "VecToAngles():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnVecToAngles)(rgflVectorIn, rgflVectorOut);
}
void pfnMoveToOrigin(edict_t *ent, const float *pflGoal, float dist, int iMoveType)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "MoveToOrigin():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnMoveToOrigin)(ent, pflGoal, dist, iMoveType);
}
/**
* The purpose of this function is to ask the engine to change the body angle yaw (horizontal
* angle) of a monster entity pointed to by ent towards this entity's ideal body angles
* (stored in the entity's entvars_t field in the idealpitch and ideal_yaw variables), by
* increment of the value of this entity's yaw speed (which is also stored in its entity
* variables as yaw_speed, this value setting the maximal amount of degrees the monster entity
* is allowed to turn in ONE frame).
*/
void pfnChangeYaw(edict_t* ent)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "ChangeYaw():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnChangeYaw)(ent);
}
/**
* The purpose of this function is to ask the engine to change the body angle pitch (vertical
* angle) of a monster entity pointed to by ent towards this entity's ideal body angles
* (stored in the entity's entvars_t field in the idealpitch and ideal_yaw variables), by
* increment of the value of this entity's pitch speed (which is also stored in its entity
* variables as pitch_speed, this value setting the maximal amount of degrees the monster
* entity is allowed to turn in ONE frame).
*/
void pfnChangePitch(edict_t* ent)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "ChangePitch():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnChangePitch)(ent);
}
edict_t* pfnFindEntityByString(edict_t *pEdictStartSearchAfter, const char *pszField, const char *pszValue)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "FindEntityByString(): %x, %s, %s", pEdictStartSearchAfter, pszField, pszValue);
// if we're running Counter-Strike...
if (g_General.m_iModid == MOD_CSTRIKE) {
// New round for CS 1.5 or earlier
if (strcmp(pszValue, "func_bomb_target") == 0) {
if (g_pServer) {
g_pServer->NewRound();
}
}
}
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnFindEntityByString)(pEdictStartSearchAfter, pszField, pszValue);
}
int pfnGetEntityIllum(edict_t* pEnt)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "GetEntityIllum():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnGetEntityIllum)(pEnt);
}
edict_t* pfnFindEntityInSphere(edict_t *pEdictStartSearchAfter, const float *org, float rad)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "FindEntityInSphere():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnFindEntityInSphere)(pEdictStartSearchAfter, org, rad);
}
edict_t* pfnFindClientInPVS(edict_t *pEdict)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "FindClientInPVS():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnFindClientInPVS)(pEdict);
}
edict_t* pfnEntitiesInPVS(edict_t *pplayer)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "EntitiesInPVS():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnEntitiesInPVS)(pplayer);
}
void pfnMakeVectors(const float *rgflVector)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "MakeVectors():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnMakeVectors)(rgflVector);
}
void pfnAngleVectors(const float *rgflVector, float *forward, float *right, float *up)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "AngleVectors():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnAngleVectors)(rgflVector, forward, right, up);
}
edict_t* pfnCreateEntity(void)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "CreateEntity():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnCreateEntity)();
}
void pfnRemoveEntity(edict_t* e)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "RemoveEntity():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnRemoveEntity)(e);
}
edict_t* pfnCreateNamedEntity(int className)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "CreateNamedEntity(): %s", STRING(className));
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnCreateNamedEntity)(className);
}
void pfnMakeStatic(edict_t *ent)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "MakeStatic():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnMakeStatic)(ent);
}
/**
* This function asks the engine to check if the entity e is in mid-air, or touches the floor.
* It returns a positive value (1) if entity e is touching the ground, 0 otherwise. Player
* entities are handled differently though, because such entities store their "ground state"
* directly in their entvars_t entity variables, under the flags bitmap variable (either
* FL_ONGROUND, or FL_PARTIALGROUND). That's why this function should only be used for non
* player entities.
*/
int pfnEntIsOnFloor(edict_t *e)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "EntIsOnFloor():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnEntIsOnFloor)(e);
}
/**
* This function asks the engine to change the vector location (origin) of entity e so that
* it will touch the ground. Most map makers place entities slightly in mid-air, to avoid
* the moving ones to get stuck in case they would slightly overlap each other with the
* world. Engine programmers got it fine: at each start of a new level, the appropriate
* entities are dropped to floor. Note we are not using engine physics for this, the result
* is immediate, like a teleport.
*/
int pfnDropToFloor(edict_t* e)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "DropToFloor():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnDropToFloor)(e);
}
/**
* This function is the equivalent of pfnRunPlayerMove, but for monsters. It tells the engine
* to play the movement animation of the monster character ent, which will face the direction
* yaw (yaw is a view angle), using mode iMode (determining whether the monster is allowed to
* pass through entities, for example WALKMOVE_NORMAL means the monster will collide with the
* world and activate triggers like every player would instead). dist is the distance that
* will have been walked once the animation is over, i.e. for most monsters, the step size.
* Setting it to a low value could turn your monster into a Michael Jackson "moonwalking" :)
* Note that whereas a RunPlayerMove movement lasts strictly the duration of the frame, a
* monster WalkMove extends during several frames, until the animation is completed.
*/
int pfnWalkMove(edict_t *ent, float yaw, float dist, int iMode)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "WalkMove():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnWalkMove)(ent, yaw, dist, iMode);
}
/**
* This function tells the engine to change the origin (vector location in the virtual world)
* of entity e to the vector location rgflOrigin (which must point to a vector).
*/
void pfnSetOrigin(edict_t *e, const float *rgflOrigin)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "SetOrigin():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnSetOrigin)(e, rgflOrigin);
}
/**
* This function tells the engine that the entity pointed to by "entity", is emitting a sound
* which filename is "sample", at level "channel" (CHAN_VOICE, etc...), with "volume" as
* loudness multiplicator (normal volume VOL_NORM is 1.0), with a pitch of "pitch" (normal
* pitch PITCH_NORM is 100.0), and that this sound has to be attenuated by distance in air
* according to the value of "attenuation" (normal attenuation ATTN_NORM is 0.8 ; ATTN_NONE
* means no attenuation with distance).
*/
void pfnEmitSound(edict_t *entity, int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "EmitSound(): %x, %d, %s, %f, %f, %d, %d", entity, channel, sample, volume, attenuation, fFlags, pitch);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnEmitSound)(entity, channel, sample, volume, attenuation, fFlags, pitch);
}
/**
* This function tells the engine that the entity pointed to by "entity", is emitting a sound
* which filename is "samp", at position "pos" (pos must point to a vector), with "vol" as
* loudness multiplicator (normal volume VOL_NORM is 1.0), with a pitch of "pitch" (normal
* pitch PITCH_NORM is 100.0), and that this sound has to be attenuated by distance in air
* according to the value of "attenuation" (normal attenuation ATTN_NORM is 0.8 ; ATTN_NONE
* means no attenuation with distance).
*/
void pfnEmitAmbientSound(edict_t *entity, float *pos, const char *samp, float vol, float attenuation, int fFlags, int pitch)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "EmitAmbientSound(): %x, %s, %f, %f, %d, %d", entity, samp, vol, attenuation, fFlags, pitch);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnEmitAmbientSound)(entity, pos, samp, vol, attenuation, fFlags, pitch);
}
/**
* This function is one of the most important of the game. It is a test line. By calling
* TraceLine the engine is told to check the direct reachability between two points, and to
* return the answer in a special dedicated structure. In detail, it is about starting from
* spatial location v1, going in direct line to v2 (v1 and v2 point to vectors), ignoring or
* not entities that are monsters along the way (depending whether fNoMonsters is set to
* enumerated type ignore_monsters or dont_ignore_monsters), ignoring if needed the entity it
* starts within, pentToSkip, and returning the results of the trace in structure ptr, which
* results may contain lots of useful info. The most important is the flFraction field, a
* fraction of 1 proportionnal to the distance that has been successfully reached without
* obstacles. I.e, if flFraction is 0.5, the trace has covered half the distance successfully.
*/
void pfnTraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "TraceLine():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnTraceLine)(v1, v2, fNoMonsters, pentToSkip, ptr);
}
void pfnTraceToss(edict_t* pent, edict_t* pentToIgnore, TraceResult *ptr)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "TraceToss():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnTraceToss)(pent, pentToIgnore, ptr);
}
int pfnTraceMonsterHull(edict_t *pEdict, const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "TraceMonsterHull():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnTraceMonsterHull)(pEdict, v1, v2, fNoMonsters, pentToSkip, ptr);
}
void pfnTraceHull(const float *v1, const float *v2, int fNoMonsters, int hullNumber, edict_t *pentToSkip, TraceResult *ptr)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "TraceHull():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnTraceHull)(v1, v2, fNoMonsters, hullNumber, pentToSkip, ptr);
}
void pfnTraceModel(const float *v1, const float *v2, int hullNumber, edict_t *pent, TraceResult *ptr)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "TraceModel():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnTraceModel)(v1, v2, hullNumber, pent, ptr);
}
const char *pfnTraceTexture(edict_t *pTextureEntity, const float *v1, const float *v2 )
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "TraceTexture():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnTraceTexture)(pTextureEntity, v1, v2);
}
void pfnTraceSphere(const float *v1, const float *v2, int fNoMonsters, float radius, edict_t *pentToSkip, TraceResult *ptr)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "TraceSphere():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnTraceSphere)(v1, v2, fNoMonsters, radius, pentToSkip, ptr);
}
void pfnGetAimVector(edict_t* ent, float speed, float *rgflReturn)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "GetAimVector():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnGetAimVector)(ent, speed, rgflReturn);
}
void pfnServerCommand(char* str)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "ServerCommand(): %s", str);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnServerCommand)(str);
}
void pfnServerExecute(void)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "ServerExecute():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnServerExecute)();
}
/**
* This function forces the client whose player entity is pEntity to issue a client command.
* How it works is that clients all have a g_argv global string in their client DLL that
* stores the command string; if ever that string is filled with characters, the client DLL
* sends it to the engine as a command to be executed. When the engine has executed that
* command, this g_argv string is reset to zero. Here is somehow a curious implementation of
* ClientCommand: the engine sets the command it wants the client to issue in his g_argv, then
* the client DLL sends it back to the engine, the engine receives it then executes the
* command therein. Don't ask me why we need all this complicated crap. Anyhow since bots have
* no client DLL, be certain never to call this function upon a bot entity, else it will just
* make the server crash. Since hordes of uncautious, not to say stupid, programmers don't
* even imagine some players on their servers could be bots, this check is performed less than
* sometimes actually by their side, that's why we strongly recommend to check it here too. In
* case it's a bot asking for a client command, we handle it like we do for bot commands, ie
* using FakeClientCommand().
*/
void pfnClientCommand(edict_t* pEdict, char* szFmt, ...)
{
va_list argptr;
char string[256];
va_start(argptr, szFmt);
_vsnprintf(string, sizeof(string), szFmt, argptr);
va_end(argptr);
g_Debug.DebugLog(DEBUG_ENGINEAPI, "ClientCommand(): %s", string);
CClient *pClient = CClient::Instance(pEdict);
if (pClient) {
if (pClient->IsBot()) {
g_General.FakeClientCommand(pClient, string);
if (g_fIsMetamod)
RETURN_META(MRES_SUPERCEDE);
return;
}
}
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnClientCommand)(pEdict, string);
}
void pfnParticleEffect(const float *org, const float *dir, float color, float count)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "ParticleEffect():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnParticleEffect)(org, dir, color, count);
}
void pfnLightStyle(int style, char* val)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "LightStyle():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnLightStyle)(style, val);
}
int pfnDecalIndex(const char *name)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "DecalIndex(): %s", name);
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnDecalIndex)(name);
}
int pfnPointContents(const float *rgflVector)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "PointContents():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnPointContents)(rgflVector);
}
void pfnMessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
{
const char *type = g_General.GetUserMsgName(msg_type);
g_Debug.DebugLog(DEBUG_NETMSG, "MessageBegin(): %d, %d (%s), %x", msg_dest, msg_type, type ? type : "UNKNOWN" , ed);
if (g_pServer)
g_pServer->MessageBegin(msg_type, ed);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnMessageBegin)(msg_dest, msg_type, pOrigin, ed);
}
void pfnMessageEnd(void)
{
g_Debug.DebugLog(DEBUG_NETMSG, "MessageEnd():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnMessageEnd)();
}
void pfnWriteByte(int iValue)
{
g_Debug.DebugLog(DEBUG_NETMSG, "WriteByte(): %d", iValue);
if (g_pServer)
g_pServer->MessageWrite((void *)&iValue);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnWriteByte)(iValue);
}
void pfnWriteChar(int iValue)
{
g_Debug.DebugLog(DEBUG_NETMSG, "WriteChar(): %d", iValue);
if (g_pServer)
g_pServer->MessageWrite((void *)&iValue);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnWriteChar)(iValue);
}
void pfnWriteShort(int iValue)
{
g_Debug.DebugLog(DEBUG_NETMSG, "WriteShort(): %d", iValue);
if (g_pServer)
g_pServer->MessageWrite((void *)&iValue);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnWriteShort)(iValue);
}
void pfnWriteLong(int iValue)
{
g_Debug.DebugLog(DEBUG_NETMSG, "WriteLong(): %d", iValue);
if (g_pServer)
g_pServer->MessageWrite((void *)&iValue);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnWriteLong)(iValue);
}
void pfnWriteAngle(float flValue)
{
g_Debug.DebugLog(DEBUG_NETMSG, "WriteAngle(): %f", flValue);
if (g_pServer)
g_pServer->MessageWrite((void *)&flValue);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnWriteAngle)(flValue);
}
void pfnWriteCoord(float flValue)
{
g_Debug.DebugLog(DEBUG_NETMSG, "WriteCoord(): %f", flValue);
if (g_pServer)
g_pServer->MessageWrite((void *)&flValue);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnWriteCoord)(flValue);
}
void pfnWriteString(const char *sz)
{
g_Debug.DebugLog(DEBUG_NETMSG, "WriteString(): %s", sz);
if (g_pServer)
g_pServer->MessageWrite((void *)sz);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnWriteString)(sz);
}
void pfnWriteEntity(int iValue)
{
g_Debug.DebugLog(DEBUG_NETMSG, "WriteEntity(): %d", iValue);
if (g_pServer)
g_pServer->MessageWrite((void *)&iValue);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnWriteEntity)(iValue);
}
void pfnCVarRegister(cvar_t *pCvar)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "CVarRegister():", pCvar->name);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnCVarRegister)(pCvar);
}
float pfnCVarGetFloat(const char *szVarName)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "CVarGetFloat(): %s", szVarName);
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnCVarGetFloat)(szVarName);
}
const char* pfnCVarGetString(const char *szVarName)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "CVarGetString(): %s", szVarName);
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnCVarGetString)(szVarName);
}
void pfnCVarSetFloat(const char *szVarName, float flValue)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "CVarSetFloat(): %s, %f", szVarName, flValue);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnCVarSetFloat)(szVarName, flValue);
}
void pfnCVarSetString(const char *szVarName, const char *szValue)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "CVarSetString(): %s %s", szVarName, szValue);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnCVarSetString)(szVarName, szValue);
}
void pfnEngineFprintf(FILE *pfile, char *szFmt, ...)
{
va_list argptr;
char string[256];
va_start(argptr, szFmt);
_vsnprintf(string, sizeof(string), szFmt, argptr);
va_end(argptr);
g_Debug.DebugLog(DEBUG_ENGINEAPI, "EngineFprintf(): %s", string);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnEngineFprintf)(pfile, string);
}
void pfnAlertMessage(ALERT_TYPE atype, char *szFmt, ...)
{
va_list argptr;
char string[256];
va_start(argptr, szFmt);
_vsnprintf(string, sizeof(string), szFmt, argptr);
va_end(argptr);
g_Debug.DebugLog(DEBUG_ENGINEAPI, "AlertMessage(): %d, %s", atype, string);
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnAlertMessage)(atype, string);
}
void* pfnPvAllocEntPrivateData(edict_t *pEdict, int32 cb)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "PvAllocEntPrivateData():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnPvAllocEntPrivateData)(pEdict, cb);
}
void* pfnPvEntPrivateData(edict_t *pEdict)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "PvEntPrivateData():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnPvEntPrivateData)(pEdict);
}
void pfnFreeEntPrivateData(edict_t *pEdict)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "FreeEntPrivateData():");
if (g_fIsMetamod)
RETURN_META(MRES_IGNORED);
(*g_engfuncs.pfnFreeEntPrivateData)(pEdict);
}
const char* pfnSzFromIndex(int iString)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "SzFromIndex():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnSzFromIndex)(iString);
}
int pfnAllocString(const char *szValue)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "AllocString(): %s", szValue);
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnAllocString)(szValue);
}
entvars_t* pfnGetVarsOfEnt(edict_t *pEdict)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "GetVarsOfEnt():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnGetVarsOfEnt)(pEdict);
}
edict_t* pfnPEntityOfEntOffset(int iEntOffset)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "PEntityOfEntOffset():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnPEntityOfEntOffset)(iEntOffset);
}
int pfnEntOffsetOfPEntity(const edict_t *pEdict)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "EntOffsetOfPEntity():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnEntOffsetOfPEntity)(pEdict);
}
int pfnIndexOfEdict(const edict_t *pEdict)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "IndexOfEdict():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnIndexOfEdict)(pEdict);
}
edict_t* pfnPEntityOfEntIndex(int iEntIndex)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "PEntityOfEntIndex():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnPEntityOfEntIndex)(iEntIndex);
}
edict_t* pfnFindEntityByVars(entvars_t* pvars)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "FindEntityByVars():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnFindEntityByVars)(pvars);
}
void* pfnGetModelPtr(edict_t* pEdict)
{
g_Debug.DebugLog(DEBUG_ENGINEAPI, "GetModelPtr():");
if (g_fIsMetamod)
RETURN_META_VALUE(MRES_IGNORED, 0);
return (*g_engfuncs.pfnGetModelPtr)(pEdict);
}
/**
* This function registers a "user message" by the engine side. User messages are network
* messages the game DLL asks the engine to send to clients. Since many MODs have completely
* different client features (Counter-Strike has a radar and a timer, for example), network
* messages just can't be the same for every MOD. Hence here the MOD DLL tells the engine,