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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
|
/*
Bot replay playback logic and processes.
The recorded files are read and their information and tick data
stored into variables. A bot is then used to playback the recorded
data by setting it's origin, velocity, etc. in OnPlayerRunCmd.
*/
static int preAndPostRunTickCount;
static int playbackTick[RP_MAX_BOTS];
static ArrayList playbackTickData[RP_MAX_BOTS];
static bool inBreather[RP_MAX_BOTS];
static float breatherStartTime[RP_MAX_BOTS];
// Original bot caller, needed for OnClientPutInServer callback
static int botCaller[RP_MAX_BOTS];
// Original bot name after creation by bot_add, needed for bot removal
static char botName[RP_MAX_BOTS][MAX_NAME_LENGTH];
static bool botInGame[RP_MAX_BOTS];
static int botClient[RP_MAX_BOTS];
static bool botDataLoaded[RP_MAX_BOTS];
static int botReplayType[RP_MAX_BOTS];
static int botReplayVersion[RP_MAX_BOTS];
static int botSteamAccountID[RP_MAX_BOTS];
static int botCourse[RP_MAX_BOTS];
static int botMode[RP_MAX_BOTS];
static int botStyle[RP_MAX_BOTS];
static float botTime[RP_MAX_BOTS];
static int botTimeTicks[RP_MAX_BOTS];
static char botAlias[RP_MAX_BOTS][MAX_NAME_LENGTH];
static bool botPaused[RP_MAX_BOTS];
static bool botPlaybackPaused[RP_MAX_BOTS];
static int botKnife[RP_MAX_BOTS];
static int botWeapon[RP_MAX_BOTS];
static int botJumpType[RP_MAX_BOTS];
static float botJumpDistance[RP_MAX_BOTS];
static int botJumpBlockDistance[RP_MAX_BOTS];
static int timeOnGround[RP_MAX_BOTS];
static int timeInAir[RP_MAX_BOTS];
static int botTeleportsUsed[RP_MAX_BOTS];
static int botCurrentTeleport[RP_MAX_BOTS];
static int botButtons[RP_MAX_BOTS];
static MoveType botMoveType[RP_MAX_BOTS];
static float botTakeoffSpeed[RP_MAX_BOTS];
static float botSpeed[RP_MAX_BOTS];
static float botLastOrigin[RP_MAX_BOTS][3];
static bool hitBhop[RP_MAX_BOTS];
static bool hitPerf[RP_MAX_BOTS];
static bool botJumped[RP_MAX_BOTS];
static bool botIsTakeoff[RP_MAX_BOTS];
static bool botJustTeleported[RP_MAX_BOTS];
static float botLandingSpeed[RP_MAX_BOTS];
// =====[ PUBLIC ]=====
// Returns the client index of the replay bot, or -1 otherwise
int LoadReplayBot(int client, char[] path)
{
// Safeguard Check
if (GOKZ_GetCoreOption(client, Option_Safeguard) > Safeguard_Disabled && GOKZ_GetTimerRunning(client) && GOKZ_GetValidTimer(client))
{
if (!GOKZ_GetPaused(client) && !GOKZ_GetCanPause(client))
{
GOKZ_PrintToChat(client, true, "%t", "Safeguard - Blocked");
GOKZ_PlayErrorSound(client);
return -1;
}
}
int bot;
if (GetBotsInUse() < RP_MAX_BOTS)
{
bot = GetUnusedBot();
}
else
{
GOKZ_PrintToChat(client, true, "%t", "No Bots Available");
GOKZ_PlayErrorSound(client);
return -1;
}
if (bot == -1)
{
LogError("Unused bot could not be found even though only %d out of %d are known to be in use.",
GetBotsInUse(), RP_MAX_BOTS);
GOKZ_PlayErrorSound(client);
return -1;
}
if (!LoadPlayback(client, bot, path))
{
GOKZ_PlayErrorSound(client);
return -1;
}
ServerCommand("bot_add");
botCaller[bot] = client;
return botClient[bot];
}
// Passes the current state of the replay into the HUDInfo struct
void GetPlaybackState(int client, HUDInfo info)
{
int bot, i;
for(i = 0; i < RP_MAX_BOTS; i++)
{
bot = botClient[i] == client ? i : bot;
}
if (i == RP_MAX_BOTS + 1) return;
if (playbackTickData[bot] == INVALID_HANDLE)
{
return;
}
info.TimerRunning = botReplayType[bot] == ReplayType_Jump ? false : true;
if (botReplayVersion[bot] == 1)
{
info.Time = playbackTick[bot] * GetTickInterval();
}
else if (botReplayVersion[bot] == 2)
{
if (playbackTick[bot] < preAndPostRunTickCount)
{
info.Time = 0.0;
}
else if (playbackTick[bot] >= playbackTickData[bot].Length - preAndPostRunTickCount)
{
info.Time = botTime[bot];
}
else if (playbackTick[bot] >= preAndPostRunTickCount)
{
info.Time = (playbackTick[bot] - preAndPostRunTickCount) * GetTickInterval();
}
}
info.TimerRunning = true;
info.TimeType = botTeleportsUsed[bot] > 0 ? TimeType_Nub : TimeType_Pro;
info.Speed = botSpeed[bot];
info.Paused = false;
info.OnLadder = (botMoveType[bot] == MOVETYPE_LADDER);
info.Noclipping = false;
info.OnGround = Movement_GetOnGround(client);
info.Ducking = botButtons[bot] & IN_DUCK > 0;
info.ID = botClient[bot];
info.Jumped = botJumped[bot];
info.HitBhop = hitBhop[bot];
info.HitPerf = hitPerf[bot];
info.Buttons = botButtons[bot];
info.TakeoffSpeed = botTakeoffSpeed[bot];
info.IsTakeoff = botIsTakeoff[bot] && !Movement_GetOnGround(client);
info.CurrentTeleport = botCurrentTeleport[bot];
}
int GetBotFromClient(int client)
{
for (int bot = 0; bot < RP_MAX_BOTS; bot++)
{
if (botClient[bot] == client)
{
return bot;
}
}
return -1;
}
bool InBreather(int bot)
{
return inBreather[bot];
}
bool PlaybackPaused(int bot)
{
return botPlaybackPaused[bot];
}
void PlaybackTogglePause(int bot)
{
if(botPlaybackPaused[bot])
{
botPlaybackPaused[bot] = false;
}
else
{
botPlaybackPaused[bot] = true;
}
}
void PlaybackSkipForward(int bot)
{
if (playbackTick[bot] + RoundToZero(RP_SKIP_TIME / GetTickInterval()) < playbackTickData[bot].Length)
{
PlaybackSkipToTick(bot, playbackTick[bot] + RoundToZero(RP_SKIP_TIME / GetTickInterval()));
}
}
void PlaybackSkipBack(int bot)
{
if (playbackTick[bot] < RoundToZero(RP_SKIP_TIME / GetTickInterval()))
{
PlaybackSkipToTick(bot, 0);
}
else
{
PlaybackSkipToTick(bot, playbackTick[bot] - RoundToZero(RP_SKIP_TIME / GetTickInterval()));
}
}
int PlaybackGetTeleports(int bot)
{
return botCurrentTeleport[bot];
}
void TrySkipToTime(int client, int seconds)
{
if (!IsValidClient(client))
{
return;
}
int tick = seconds * 128 + preAndPostRunTickCount;
int bot = GetBotFromClient(GetObserverTarget(client));
if (tick >= 0 && tick < playbackTickData[bot].Length)
{
PlaybackSkipToTick(bot, tick);
}
else
{
GOKZ_PrintToChat(client, true, "%t", "Replay Controls - Invalid Time");
}
}
float GetPlaybackTime(int bot)
{
if (playbackTick[bot] < preAndPostRunTickCount)
{
return 0.0;
}
if (playbackTick[bot] >= playbackTickData[bot].Length - preAndPostRunTickCount)
{
return botTime[bot];
}
if (playbackTick[bot] >= preAndPostRunTickCount)
{
return (playbackTick[bot] - preAndPostRunTickCount) * GetTickInterval();
}
return 0.0;
}
// =====[ EVENTS ]=====
void OnClientPutInServer_Playback(int client)
{
if (!IsFakeClient(client) || IsClientSourceTV(client))
{
return;
}
// Check if an unassigned bot has joined, and assign it
for (int bot; bot < RP_MAX_BOTS; bot++)
{
// Also check if the bot was created by us.
if (!botInGame[bot] && botCaller[bot] != 0)
{
botInGame[bot] = true;
botClient[bot] = client;
GetClientName(client, botName[bot], sizeof(botName[]));
// The bot won't receive its weapons properly if we don't wait a frame
RequestFrame(SetBotStuff, bot);
if (IsValidClient(botCaller[bot]))
{
MakePlayerSpectate(botCaller[bot], botClient[bot]);
botCaller[bot] = 0;
}
break;
}
}
}
void OnClientDisconnect_Playback(int client)
{
for (int bot; bot < RP_MAX_BOTS; bot++)
{
if (botClient[bot] != client)
{
continue;
}
botInGame[bot] = false;
if (playbackTickData[bot] != null)
{
playbackTickData[bot].Clear(); // Clear it all out
botDataLoaded[bot] = false;
}
}
}
void OnPlayerRunCmd_Playback(int client, int &buttons, float vel[3], float angles[3])
{
if (!IsFakeClient(client))
{
return;
}
for (int bot; bot < RP_MAX_BOTS; bot++)
{
// Check if not the bot we're looking for
if (!botInGame[bot] || botClient[bot] != client || !botDataLoaded[bot])
{
continue;
}
switch (botReplayVersion[bot])
{
case 1: PlaybackVersion1(client, bot, buttons);
case 2: PlaybackVersion2(client, bot, buttons, vel, angles);
}
break;
}
}
void OnPlayerRunCmdPost_Playback(int client)
{
for (int bot; bot < RP_MAX_BOTS; bot++)
{
// Check if not the bot we're looking for
if (!botInGame[bot] || botClient[bot] != client || !botDataLoaded[bot])
{
continue;
}
if (botReplayVersion[bot] == 2)
{
PlaybackVersion2Post(client, bot);
}
break;
}
}
void GOKZ_OnOptionsLoaded_Playback(int client)
{
for (int bot = 0; bot < RP_MAX_BOTS; bot++)
{
if (botClient[bot] == client)
{
// Reset its movement options as it might be wrongfully changed
GOKZ_SetCoreOption(client, Option_Mode, botMode[bot]);
GOKZ_SetCoreOption(client, Option_Style, botStyle[bot]);
}
}
}
// =====[ PRIVATE ]=====
// Returns false if there was a problem loading the playback e.g. doesn't exist
static bool LoadPlayback(int client, int bot, char[] path)
{
if (!FileExists(path))
{
GOKZ_PrintToChat(client, true, "%t", "No Replay Found");
return false;
}
File file = OpenFile(path, "rb");
// Check magic number in header
int magicNumber;
file.ReadInt32(magicNumber);
if (magicNumber != RP_MAGIC_NUMBER)
{
LogError("Failed to load invalid replay file: \"%s\".", path);
delete file;
return false;
}
// Check replay format version
int formatVersion;
file.ReadInt8(formatVersion);
switch(formatVersion)
{
case 1:
{
botReplayVersion[bot] = 1;
if (!LoadFormatVersion1Replay(file, bot))
{
return false;
}
}
case 2:
{
botReplayVersion[bot] = 2;
if (!LoadFormatVersion2Replay(file, client, bot))
{
return false;
}
}
default:
{
LogError("Failed to load replay file with unsupported format version: \"%s\".", path);
delete file;
return false;
}
}
return true;
}
static bool LoadFormatVersion1Replay(File file, int bot)
{
// Old replays only support runs, not jumps
botReplayType[bot] = ReplayType_Run;
int length;
// GOKZ version
file.ReadInt8(length);
char[] gokzVersion = new char[length + 1];
file.ReadString(gokzVersion, length, length);
gokzVersion[length] = '\0';
// Map name
file.ReadInt8(length);
char[] mapName = new char[length + 1];
file.ReadString(mapName, length, length);
mapName[length] = '\0';
// Some integers...
file.ReadInt32(botCourse[bot]);
file.ReadInt32(botMode[bot]);
file.ReadInt32(botStyle[bot]);
// Old replays don't store the weapon information
botKnife[bot] = CS_WeaponIDToItemDefIndex(CSWeapon_KNIFE);
botWeapon[bot] = (botMode[bot] == Mode_Vanilla) ? -1 : CS_WeaponIDToItemDefIndex(CSWeapon_USP_SILENCER);
// Time
int timeAsInt;
file.ReadInt32(timeAsInt);
botTime[bot] = view_as<float>(timeAsInt);
// Some integers...
file.ReadInt32(botTeleportsUsed[bot]);
file.ReadInt32(botSteamAccountID[bot]);
// SteamID2
file.ReadInt8(length);
char[] steamID2 = new char[length + 1];
file.ReadString(steamID2, length, length);
steamID2[length] = '\0';
// IP
file.ReadInt8(length);
char[] IP = new char[length + 1];
file.ReadString(IP, length, length);
IP[length] = '\0';
// Alias
file.ReadInt8(length);
file.ReadString(botAlias[bot], sizeof(botAlias[]), length);
botAlias[bot][length] = '\0';
// Read tick data
file.ReadInt32(length);
// Setup playback tick data array list
if (playbackTickData[bot] == null)
{
playbackTickData[bot] = new ArrayList(IntMax(RP_V1_TICK_DATA_BLOCKSIZE, sizeof(ReplayTickData)), length);
}
else
{ // Make sure it's all clear and the correct size
playbackTickData[bot].Clear();
playbackTickData[bot].Resize(length);
}
// The replay has no replay data, this shouldn't happen normally,
// but this would cause issues in other code, so we don't even try to load this.
if (length == 0)
{
delete file;
return false;
}
any tickData[RP_V1_TICK_DATA_BLOCKSIZE];
for (int i = 0; i < length; i++)
{
file.Read(tickData, RP_V1_TICK_DATA_BLOCKSIZE, 4);
playbackTickData[bot].Set(i, view_as<float>(tickData[0]), 0); // origin[0]
playbackTickData[bot].Set(i, view_as<float>(tickData[1]), 1); // origin[1]
playbackTickData[bot].Set(i, view_as<float>(tickData[2]), 2); // origin[2]
playbackTickData[bot].Set(i, view_as<float>(tickData[3]), 3); // angles[0]
playbackTickData[bot].Set(i, view_as<float>(tickData[4]), 4); // angles[1]
playbackTickData[bot].Set(i, view_as<int>(tickData[5]), 5); // buttons
playbackTickData[bot].Set(i, view_as<int>(tickData[6]), 6); // flags
}
playbackTick[bot] = 0;
botDataLoaded[bot] = true;
delete file;
return true;
}
static bool LoadFormatVersion2Replay(File file, int client, int bot)
{
int length;
// Replay type
int replayType;
file.ReadInt8(replayType);
// GOKZ version
file.ReadInt8(length);
char[] gokzVersion = new char[length + 1];
file.ReadString(gokzVersion, length, length);
gokzVersion[length] = '\0';
// Map name
file.ReadInt8(length);
char[] mapName = new char[length + 1];
file.ReadString(mapName, length, length);
mapName[length] = '\0';
if (!StrEqual(mapName, gC_CurrentMap))
{
GOKZ_PrintToChat(client, true, "%t", "Replay Menu - Wrong Map", mapName);
delete file;
return false;
}
// Map filesize
int mapFileSize;
file.ReadInt32(mapFileSize);
// Server IP
int serverIP;
file.ReadInt32(serverIP);
// Timestamp
int timestamp;
file.ReadInt32(timestamp);
// Player Alias
file.ReadInt8(length);
file.ReadString(botAlias[bot], sizeof(botAlias[]), length);
botAlias[bot][length] = '\0';
// Player Steam ID
int steamID;
file.ReadInt32(steamID);
// Mode
file.ReadInt8(botMode[bot]);
// Style
file.ReadInt8(botStyle[bot]);
// Player Sensitivity
int intPlayerSensitivity;
file.ReadInt32(intPlayerSensitivity);
float playerSensitivity = view_as<float>(intPlayerSensitivity);
// Player MYAW
int intPlayerMYaw;
file.ReadInt32(intPlayerMYaw);
float playerMYaw = view_as<float>(intPlayerMYaw);
// Tickrate
int tickrateAsInt;
file.ReadInt32(tickrateAsInt);
float tickrate = view_as<float>(tickrateAsInt);
if (tickrate != RoundToZero(1 / GetTickInterval()))
{
GOKZ_PrintToChat(client, true, "%t", "Replay Menu - Wrong Tickrate", tickrate, (RoundToZero(1 / GetTickInterval())));
delete file;
return false;
}
// Tick Count
int tickCount;
file.ReadInt32(tickCount);
// The replay has no replay data, this shouldn't happen normally,
// but this would cause issues in other code, so we don't even try to load this.
if (tickCount == 0)
{
delete file;
return false;
}
// Equipped Weapon
file.ReadInt32(botWeapon[bot]);
// Equipped Knife
file.ReadInt32(botKnife[bot]);
// Big spit to console
PrintToConsole(client, "Replay Type: %d\nGOKZ Version: %s\nMap Name: %s\nMap Filesize: %d\nServer IP: %d\nTimestamp: %d\nPlayer Alias: %s\nPlayer Steam ID: %d\nMode: %d\nStyle: %d\nPlayer Sensitivity: %f\nPlayer m_yaw: %f\nTickrate: %f\nTick Count: %d\nWeapon: %d\nKnife: %d", replayType, gokzVersion, mapName, mapFileSize, serverIP, timestamp, botAlias[bot], steamID, botMode[bot], botStyle[bot], playerSensitivity, playerMYaw, tickrate, tickCount, botWeapon[bot], botKnife[bot]);
switch(replayType)
{
case ReplayType_Run:
{
// Time
int timeAsInt;
file.ReadInt32(timeAsInt);
botTime[bot] = view_as<float>(timeAsInt);
botTimeTicks[bot] = RoundToNearest(botTime[bot] * tickrate);
// Course
file.ReadInt8(botCourse[bot]);
// Teleports Used
file.ReadInt32(botTeleportsUsed[bot]);
// Type
botReplayType[bot] = ReplayType_Run;
// Finish spit to console
PrintToConsole(client, "Time: %f\nCourse: %d\nTeleports Used: %d", botTime[bot], botCourse[bot], botTeleportsUsed[bot]);
}
case ReplayType_Cheater:
{
// Reason
int reason;
file.ReadInt8(reason);
// Type
botReplayType[bot] = ReplayType_Cheater;
// Finish spit to console
PrintToConsole(client, "AC Reason: %s", gC_ACReasons[reason]);
}
case ReplayType_Jump:
{
// Jump Type
file.ReadInt8(botJumpType[bot]);
// Distance
file.ReadInt32(view_as<int>(botJumpDistance[bot]));
// Block Distance
file.ReadInt32(botJumpBlockDistance[bot]);
// Strafe Count
int strafeCount;
file.ReadInt8(strafeCount);
// Sync
float sync;
file.ReadInt32(view_as<int>(sync));
// Pre
float pre;
file.ReadInt32(view_as<int>(pre));
// Max
float max;
file.ReadInt32(view_as<int>(max));
// Airtime
int airtime;
file.ReadInt32(airtime);
// Type
botReplayType[bot] = ReplayType_Jump;
// Finish spit to console
PrintToConsole(client, "Jump Type: %s\nJump Distance: %f\nBlock Distance: %d\nStrafe Count: %d\nSync: %f\n Pre: %f\nMax: %f\nAirtime: %d",
gC_JumpTypes[botJumpType[bot]], botJumpDistance[bot], botJumpBlockDistance[bot], strafeCount, sync, pre, max, airtime);
}
}
// Tick Data
// Setup playback tick data array list
if (playbackTickData[bot] == null)
{
playbackTickData[bot] = new ArrayList(IntMax(RP_V1_TICK_DATA_BLOCKSIZE, sizeof(ReplayTickData)));
}
else
{
playbackTickData[bot].Clear();
}
// Read tick data
preAndPostRunTickCount = RoundToZero(RP_PLAYBACK_BREATHER_TIME / GetTickInterval());
any tickDataArray[RP_V2_TICK_DATA_BLOCKSIZE];
for (int i = 0; i < tickCount; i++)
{
file.ReadInt32(tickDataArray[RPDELTA_DELTAFLAGS]);
for (int index = 1; index < sizeof(tickDataArray); index++)
{
int currentFlag = (1 << index);
if (tickDataArray[RPDELTA_DELTAFLAGS] & currentFlag)
{
file.ReadInt32(tickDataArray[index]);
}
}
ReplayTickData tickData;
TickDataFromArray(tickDataArray, tickData);
// HACK: Jump replays don't record proper length sometimes. I don't know why.
// This leads to oversized replays full of 0s at the end.
// So, we do this horrible check to dodge that issue.
if (tickData.origin[0] == 0 && tickData.origin[1] == 0 && tickData.origin[2] == 0 && tickData.angles[0] == 0 && tickData.angles[1] == 0)
{
break;
}
playbackTickData[bot].PushArray(tickData);
}
playbackTick[bot] = 0;
botDataLoaded[bot] = true;
delete file;
return true;
}
static void PlaybackVersion1(int client, int bot, int &buttons)
{
int size = playbackTickData[bot].Length;
float repOrigin[3], repAngles[3];
int repButtons, repFlags;
// If first or last frame of the playback
if (playbackTick[bot] == 0 || playbackTick[bot] == (size - 1))
{
// Move the bot and pause them at that tick
repOrigin[0] = playbackTickData[bot].Get(playbackTick[bot], 0);
repOrigin[1] = playbackTickData[bot].Get(playbackTick[bot], 1);
repOrigin[2] = playbackTickData[bot].Get(playbackTick[bot], 2);
repAngles[0] = playbackTickData[bot].Get(playbackTick[bot], 3);
repAngles[1] = playbackTickData[bot].Get(playbackTick[bot], 4);
TeleportEntity(client, repOrigin, repAngles, view_as<float>( { 0.0, 0.0, 0.0 } ));
if (!inBreather[bot])
{
// Start the breather period
inBreather[bot] = true;
breatherStartTime[bot] = GetEngineTime();
if (playbackTick[bot] == (size - 1))
{
GOKZ_EmitSoundToClientSpectators(client, gC_ModeEndSounds[GOKZ_GetCoreOption(client, Option_Mode)], _, "Timer End");
}
}
else if (GetEngineTime() > breatherStartTime[bot] + RP_PLAYBACK_BREATHER_TIME)
{
// End the breather period
inBreather[bot] = false;
botPlaybackPaused[bot] = false;
if (playbackTick[bot] == 0)
{
GOKZ_EmitSoundToClientSpectators(client, gC_ModeStartSounds[GOKZ_GetCoreOption(client, Option_Mode)], _, "Timer Start");
}
// Start the bot if first tick. Clear bot if last tick.
playbackTick[bot]++;
if (playbackTick[bot] == size)
{
playbackTickData[bot].Clear(); // Clear it all out
botDataLoaded[bot] = false;
CancelReplayControlsForBot(bot);
ServerCommand("bot_kick %s", botName[bot]);
}
}
}
else
{
// Check whether somebody is actually spectating the bot
int spec;
for (spec = 1; spec < MAXPLAYERS + 1; spec++)
{
if (IsValidClient(spec) && GetObserverTarget(spec) == botClient[bot])
{
break;
}
}
if (spec == MAXPLAYERS + 1 && !IsReplayBotControlled(bot, botClient[bot]))
{
playbackTickData[bot].Clear();
botDataLoaded[bot] = false;
CancelReplayControlsForBot(bot);
ServerCommand("bot_kick %s", botName[bot]);
return;
}
// Load in the next tick
repOrigin[0] = playbackTickData[bot].Get(playbackTick[bot], 0);
repOrigin[1] = playbackTickData[bot].Get(playbackTick[bot], 1);
repOrigin[2] = playbackTickData[bot].Get(playbackTick[bot], 2);
repAngles[0] = playbackTickData[bot].Get(playbackTick[bot], 3);
repAngles[1] = playbackTickData[bot].Get(playbackTick[bot], 4);
repButtons = playbackTickData[bot].Get(playbackTick[bot], 5);
repFlags = playbackTickData[bot].Get(playbackTick[bot], 6);
// Check if the replay is paused
if (botPlaybackPaused[bot])
{
TeleportEntity(client, repOrigin, repAngles, view_as<float>( { 0.0, 0.0, 0.0 } ));
return;
}
// Set velocity to travel from current origin to recorded origin
float currentOrigin[3], velocity[3];
Movement_GetOrigin(client, currentOrigin);
MakeVectorFromPoints(currentOrigin, repOrigin, velocity);
ScaleVector(velocity, 128.0); // Hard-coded 128 tickrate
TeleportEntity(client, NULL_VECTOR, repAngles, velocity);
// We need the velocity directly from the replay to calculate the speeds
// for the HUD.
MakeVectorFromPoints(botLastOrigin[bot], repOrigin, velocity);
ScaleVector(velocity, 128.0); // Hard-coded 128 tickrate
CopyVector(repOrigin, botLastOrigin[bot]);
botSpeed[bot] = GetVectorHorizontalLength(velocity);
buttons = repButtons;
botButtons[bot] = repButtons;
// Should the bot be ducking?!
if (repButtons & IN_DUCK || repFlags & FL_DUCKING)
{
buttons |= IN_DUCK;
}
// If the replay file says the bot's on the ground, then fine! Unless you're going too fast...
// Note that we don't mind if replay file says bot isn't on ground but the bot is.
if (repFlags & FL_ONGROUND && Movement_GetSpeed(client) < SPEED_NORMAL * 2)
{
if (timeInAir[bot] > 0)
{
botLandingSpeed[bot] = botSpeed[bot];
timeInAir[bot] = 0;
botIsTakeoff[bot] = false;
botJumped[bot] = false;
hitBhop[bot] = false;
hitPerf[bot] = false;
if (!Movement_GetOnGround(client))
{
timeOnGround[bot] = 0;
}
}
SetEntityFlags(client, GetEntityFlags(client) | FL_ONGROUND);
Movement_SetMovetype(client, MOVETYPE_WALK);
timeOnGround[bot]++;
botTakeoffSpeed[bot] = botSpeed[bot];
}
else
{
if (timeInAir[bot] == 0)
{
botIsTakeoff[bot] = true;
botJumped[bot] = botButtons[bot] & IN_JUMP > 0;
hitBhop[bot] = (timeOnGround[bot] <= RP_MAX_BHOP_GROUND_TICKS) && botJumped[bot];
if (botMode[bot] == Mode_SimpleKZ)
{
hitPerf[bot] = timeOnGround[bot] < 3 && botJumped[bot];
}
else
{
hitPerf[bot] = timeOnGround[bot] < 2 && botJumped[bot];
}
if (hitPerf[bot])
{
if (botMode[bot] == Mode_SimpleKZ)
{
botTakeoffSpeed[bot] = FloatMin(botLandingSpeed[bot], (0.2 * botLandingSpeed[bot] + 200));
}
else if (botMode[bot] == Mode_KZTimer)
{
botTakeoffSpeed[bot] = FloatMin(botLandingSpeed[bot], 380.0);
}
else
{
botTakeoffSpeed[bot] = FloatMin(botLandingSpeed[bot], 286.0);
}
}
}
else
{
botJumped[bot] = false;
botIsTakeoff[bot] = false;
}
timeInAir[bot]++;
Movement_SetMovetype(client, MOVETYPE_NOCLIP);
}
playbackTick[bot]++;
}
}
void PlaybackVersion2(int client, int bot, int &buttons, float vel[3], float angles[3])
{
int size = playbackTickData[bot].Length;
ReplayTickData prevTickData;
ReplayTickData currentTickData;
// If first or last frame of the playback
if (playbackTick[bot] == 0 || playbackTick[bot] == (size - 1))
{
// Move the bot and pause them at that tick
playbackTickData[bot].GetArray(playbackTick[bot], currentTickData);
playbackTickData[bot].GetArray(IntMax(playbackTick[bot] - 1, 0), prevTickData);
TeleportEntity(client, currentTickData.origin, currentTickData.angles, view_as<float>( { 0.0, 0.0, 0.0 } ));
if (!inBreather[bot])
{
// Start the breather period
inBreather[bot] = true;
breatherStartTime[bot] = GetEngineTime();
}
else if (GetEngineTime() > breatherStartTime[bot] + RP_PLAYBACK_BREATHER_TIME)
{
// End the breather period
inBreather[bot] = false;
botPlaybackPaused[bot] = false;
// Start the bot if first tick. Clear bot if last tick.
playbackTick[bot]++;
if (playbackTick[bot] == size)
{
playbackTickData[bot].Clear(); // Clear it all out
botDataLoaded[bot] = false;
CancelReplayControlsForBot(bot);
ServerCommand("bot_kick %s", botName[bot]);
}
}
}
else
{
// Check whether somebody is actually spectating the bot
int spec;
for (spec = 1; spec < MAXPLAYERS + 1; spec++)
{
if (IsValidClient(spec) && GetObserverTarget(spec) == botClient[bot])
{
break;
}
}
if (spec == MAXPLAYERS + 1 && !IsReplayBotControlled(bot, botClient[bot]))
{
playbackTickData[bot].Clear();
botDataLoaded[bot] = false;
CancelReplayControlsForBot(bot);
ServerCommand("bot_kick %s", botName[bot]);
return;
}
// Load in the next tick
playbackTickData[bot].GetArray(playbackTick[bot], currentTickData);
playbackTickData[bot].GetArray(IntMax(playbackTick[bot] - 1, 0), prevTickData);
// Check if the replay is paused
if (botPlaybackPaused[bot])
{
TeleportEntity(client, currentTickData.origin, currentTickData.angles, view_as<float>( { 0.0, 0.0, 0.0 } ));
return;
}
// Play timer start/end sound, if necessary. Reset teleports
if (playbackTick[bot] == preAndPostRunTickCount && botReplayType[bot] == ReplayType_Run)
{
GOKZ_EmitSoundToClientSpectators(client, gC_ModeStartSounds[GOKZ_GetCoreOption(client, Option_Mode)], _, "Timer Start");
botCurrentTeleport[bot] = 0;
}
if (playbackTick[bot] == botTimeTicks[bot] + preAndPostRunTickCount && botReplayType[bot] == ReplayType_Run)
{
GOKZ_EmitSoundToClientSpectators(client, gC_ModeEndSounds[GOKZ_GetCoreOption(client, Option_Mode)], _, "Timer End");
}
// We use the previous position/velocity data to recreate sounds accurately.
// This might not be necessary as we already did do this in OnPlayerRunCmdPost of last tick,
// but we do it again just in case the values don't match up somehow (eg. collision with moving objects?)
TeleportEntity(client, NULL_VECTOR, prevTickData.angles, prevTickData.velocity);
// TeleportEntity does not set the absolute origin and velocity so we need to do it
// to prevent inaccurate eye position interpolation.
SetEntPropVector(client, Prop_Data, "m_vecVelocity", prevTickData.velocity);
SetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", prevTickData.velocity);
SetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", prevTickData.origin);
SetEntPropVector(client, Prop_Data, "m_vecOrigin", prevTickData.origin);
// Set buttons and potential inputs.
int newButtons;
if (currentTickData.flags & RP_IN_ATTACK)
{
newButtons |= IN_ATTACK;
}
if (currentTickData.flags & RP_IN_ATTACK2)
{
newButtons |= IN_ATTACK2;
}
if (currentTickData.flags & RP_IN_JUMP)
{
newButtons |= IN_JUMP;
}
if (currentTickData.flags & RP_IN_DUCK || currentTickData.flags & RP_FL_DUCKING)
{
newButtons |= IN_DUCK;
}
// Few assumptions here because the replay doesn't track them: Player doesn't use +klook or +strafe.
// If the assumptions are wrong we will just end up with wrong sound prediction, no big deal.
if (currentTickData.flags & RP_IN_FORWARD)
{
newButtons |= IN_FORWARD;
vel[0] += RP_PLAYER_ACCELSPEED;
}
if (currentTickData.flags & RP_IN_BACK)
{
newButtons |= IN_BACK;
vel[0] -= RP_PLAYER_ACCELSPEED;
}
if (currentTickData.flags & RP_IN_MOVELEFT)
{
newButtons |= IN_MOVELEFT;
vel[1] -= RP_PLAYER_ACCELSPEED;
}
if (currentTickData.flags & RP_IN_MOVERIGHT)
{
newButtons |= IN_MOVERIGHT;
vel[1] += RP_PLAYER_ACCELSPEED;
}
if (currentTickData.flags & RP_IN_LEFT)
{
newButtons |= IN_LEFT;
}
if (currentTickData.flags & RP_IN_RIGHT)
{
newButtons |= IN_RIGHT;
}
if (currentTickData.flags & RP_IN_RELOAD)
{
newButtons |= IN_RELOAD;
}
if (currentTickData.flags & RP_IN_SPEED)
{
newButtons |= IN_SPEED;
}
buttons = newButtons;
botButtons[bot] = buttons;
// The angles might be wrong if the player teleports, but this should only affect sound prediction.
angles = currentTickData.angles;
// Set the bot's MoveType
MoveType replayMoveType = view_as<MoveType>(prevTickData.flags & RP_MOVETYPE_MASK);
botMoveType[bot] = replayMoveType;
if (replayMoveType == MOVETYPE_WALK)
{
Movement_SetMovetype(client, MOVETYPE_WALK);
}
else if (replayMoveType == MOVETYPE_LADDER)
{
botPaused[bot] = false;
Movement_SetMovetype(client, MOVETYPE_LADDER);
}
else
{
Movement_SetMovetype(client, MOVETYPE_NOCLIP);
}
// Set some variables
if (currentTickData.flags & RP_TELEPORT_TICK)
{
botJustTeleported[bot] = true;
botCurrentTeleport[bot]++;
}
if (currentTickData.flags & RP_TAKEOFF_TICK)
{
hitPerf[bot] = currentTickData.flags & RP_HIT_PERF > 0;
botIsTakeoff[bot] = true;
botTakeoffSpeed[bot] = GetVectorHorizontalLength(currentTickData.velocity);
}
if ((currentTickData.flags & RP_SECONDARY_EQUIPPED) && !IsCurrentWeaponSecondary(client))
{
int item = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);
if (item != -1)
{
char name[64];
GetEntityClassname(item, name, sizeof(name));
FakeClientCommand(client, "use %s", name);
}
}
else if (!(currentTickData.flags & RP_SECONDARY_EQUIPPED) && IsCurrentWeaponSecondary(client))
{
int item = GetPlayerWeaponSlot(client, CS_SLOT_KNIFE);
if (item != -1)
{
char name[64];
GetEntityClassname(item, name, sizeof(name));
FakeClientCommand(client, "use %s", name);
}
}
#if defined DEBUG
if(!botPlaybackPaused[bot])
{
PrintToServer("Tick: %d", playbackTick[bot]);
PrintToServer("X %f \nY %f \nZ %f\nPitch %f\nYaw %f", currentTickData.origin[0], currentTickData.origin[1], currentTickData.origin[2], currentTickData.angles[0], currentTickData.angles[1]);
if(currentTickData.flags & RP_MOVETYPE_MASK == view_as<int>(MOVETYPE_WALK)) PrintToServer("MOVETYPE_WALK");
if(currentTickData.flags & RP_MOVETYPE_MASK == view_as<int>(MOVETYPE_LADDER)) PrintToServer("MOVETYPE_LADDER");
if(currentTickData.flags & RP_MOVETYPE_MASK == view_as<int>(MOVETYPE_NOCLIP)) PrintToServer("MOVETYPE_NOCLIP");
if(currentTickData.flags & RP_MOVETYPE_MASK == view_as<int>(MOVETYPE_NOCLIP)) PrintToServer("MOVETYPE_NONE");
if(currentTickData.flags & RP_IN_ATTACK) PrintToServer("IN_ATTACK");
if(currentTickData.flags & RP_IN_ATTACK2) PrintToServer("IN_ATTACK2");
if(currentTickData.flags & RP_IN_JUMP) PrintToServer("IN_JUMP");
if(currentTickData.flags & RP_IN_DUCK) PrintToServer("IN_DUCK");
if(currentTickData.flags & RP_IN_FORWARD) PrintToServer("IN_FORWARD");
if(currentTickData.flags & RP_IN_BACK) PrintToServer("IN_BACK");
if(currentTickData.flags & RP_IN_LEFT) PrintToServer("IN_LEFT");
if(currentTickData.flags & RP_IN_RIGHT) PrintToServer("IN_RIGHT");
if(currentTickData.flags & RP_IN_MOVELEFT) PrintToServer("IN_MOVELEFT");
if(currentTickData.flags & RP_IN_MOVERIGHT) PrintToServer("IN_MOVERIGHT");
if(currentTickData.flags & RP_IN_RELOAD) PrintToServer("IN_RELOAD");
if(currentTickData.flags & RP_IN_SPEED) PrintToServer("IN_SPEED");
if(currentTickData.flags & RP_IN_USE) PrintToServer("IN_USE");
if(currentTickData.flags & RP_IN_BULLRUSH) PrintToServer("IN_BULLRUSH");
if(currentTickData.flags & RP_FL_ONGROUND) PrintToServer("FL_ONGROUND");
if(currentTickData.flags & RP_FL_DUCKING ) PrintToServer("FL_DUCKING");
if(currentTickData.flags & RP_FL_SWIM) PrintToServer("FL_SWIM");
if(currentTickData.flags & RP_UNDER_WATER) PrintToServer("WATERLEVEL!=0");
if(currentTickData.flags & RP_TELEPORT_TICK) PrintToServer("TELEPORT");
if(currentTickData.flags & RP_TAKEOFF_TICK) PrintToServer("TAKEOFF");
if(currentTickData.flags & RP_HIT_PERF) PrintToServer("PERF");
if(currentTickData.flags & RP_SECONDARY_EQUIPPED) PrintToServer("SECONDARY_WEAPON_EQUIPPED");
PrintToServer("==============================================================");
}
#endif
}
}
void PlaybackVersion2Post(int client, int bot)
{
if (botPlaybackPaused[bot])
{
return;
}
int size = playbackTickData[bot].Length;
if (playbackTick[bot] != 0 && playbackTick[bot] != (size - 1))
{
ReplayTickData currentTickData;
ReplayTickData prevTickData;
playbackTickData[bot].GetArray(playbackTick[bot], currentTickData);
playbackTickData[bot].GetArray(IntMax(playbackTick[bot] - 1, 0), prevTickData);
// TeleportEntity does not set the absolute origin and velocity so we need to do it
// to prevent inaccurate eye position interpolation.
SetEntPropVector(client, Prop_Data, "m_vecVelocity", currentTickData.velocity);
SetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", currentTickData.velocity);
SetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", currentTickData.origin);
SetEntPropVector(client, Prop_Data, "m_vecOrigin", currentTickData.origin);
SetEntPropFloat(client, Prop_Send, "m_angEyeAngles[0]", currentTickData.angles[0]);
SetEntPropFloat(client, Prop_Send, "m_angEyeAngles[1]", currentTickData.angles[1]);
MoveType replayMoveType = view_as<MoveType>(currentTickData.flags & RP_MOVETYPE_MASK);
botMoveType[bot] = replayMoveType;
int entityFlags = GetEntityFlags(client);
if (replayMoveType == MOVETYPE_WALK)
{
if (currentTickData.flags & RP_FL_ONGROUND)
{
SetEntityFlags(client, entityFlags | FL_ONGROUND);
botPaused[bot] = false;
// The bot is on the ground, so there must be a ground entity attributed to the bot.
int groundEnt = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");
if (groundEnt == -1 && botJustTeleported[bot])
{
SetEntPropFloat(client, Prop_Send, "m_flFallVelocity", 0.0);
float endPosition[3], mins[3], maxs[3];
GetEntPropVector(client, Prop_Send, "m_vecMaxs", maxs);
GetEntPropVector(client, Prop_Send, "m_vecMins", mins);
endPosition = currentTickData.origin;
endPosition[2] -= 2.0;
TR_TraceHullFilter(currentTickData.origin, endPosition, mins, maxs, MASK_PLAYERSOLID, TraceEntityFilterPlayers);
// This should always hit.
if (TR_DidHit())
{
groundEnt = TR_GetEntityIndex();
SetEntPropEnt(client, Prop_Data, "m_hGroundEntity", groundEnt);
}
}
}
else
{
botJustTeleported[bot] = false;
}
}
if (currentTickData.flags & RP_UNDER_WATER)
{
SetEntityFlags(client, entityFlags | FL_INWATER);
}
botSpeed[bot] = GetVectorHorizontalLength(currentTickData.velocity);
playbackTick[bot]++;
}
}
// Set the bot client's GOKZ options, clan tag and name based on the loaded replay data
static void SetBotStuff(int bot)
{
if (!botInGame[bot] || !botDataLoaded[bot])
{
return;
}
int client = botClient[bot];
// Set its movement options just in case it could negatively affect the playback
GOKZ_SetCoreOption(client, Option_Mode, botMode[bot]);
GOKZ_SetCoreOption(client, Option_Style, botStyle[bot]);
// Clan tag and name
SetBotClanTag(bot);
SetBotName(bot);
// Bot takes one tick after being put in server to be able to respawn.
RequestFrame(RequestFrame_SetBotStuff, GetClientUserId(client));
}
public void RequestFrame_SetBotStuff(int userid)
{
int client = GetClientOfUserId(userid);
if (!client)
{
return;
}
int bot;
for (bot = 0; bot <= RP_MAX_BOTS; bot++)
{
if (botClient[bot] == client)
{
break;
}
else if (bot == RP_MAX_BOTS)
{
return;
}
}
// Set the bot's team based on if it's NUB or PRO
if (botReplayType[bot] == ReplayType_Run
&& GOKZ_GetTimeTypeEx(botTeleportsUsed[bot]) == TimeType_Pro)
{
GOKZ_JoinTeam(client, CS_TEAM_CT, .forceBroadcast = true);
}
else
{
GOKZ_JoinTeam(client, CS_TEAM_CT, .forceBroadcast = true);
}
// Set bot weapons
// Always start by removing the pistol and knife
int currentPistol = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);
if (currentPistol != -1)
{
RemovePlayerItem(client, currentPistol);
}
int currentKnife = GetPlayerWeaponSlot(client, CS_SLOT_KNIFE);
if (currentKnife != -1)
{
RemovePlayerItem(client, currentKnife);
}
char weaponName[128];
// Give the bot the knife stored in the replay
/*
if (botKnife[bot] != 0)
{
CS_WeaponIDToAlias(CS_ItemDefIndexToID(botKnife[bot]), weaponName, sizeof(weaponName));
Format(weaponName, sizeof(weaponName), "weapon_%s", weaponName);
GivePlayerItem(client, weaponName);
}
else
{
GivePlayerItem(client, "weapon_knife");
}
*/
// We are currently not doing that, as it would require us to disable the
// FollowCSGOServerGuidelines failsafe if the bot has a non-standard knife.
GivePlayerItem(client, "weapon_knife");
// Give the bot the pistol stored in the replay
if (botWeapon[bot] != -1)
{
CS_WeaponIDToAlias(CS_ItemDefIndexToID(botWeapon[bot]), weaponName, sizeof(weaponName));
Format(weaponName, sizeof(weaponName), "weapon_%s", weaponName);
GivePlayerItem(client, weaponName);
}
botCurrentTeleport[bot] = 0;
}
static void SetBotClanTag(int bot)
{
char tag[MAX_NAME_LENGTH];
if (botReplayType[bot] == ReplayType_Run)
{
if (botCourse[bot] == 0)
{
// KZT PRO
FormatEx(tag, sizeof(tag), "%s %s",
gC_ModeNamesShort[botMode[bot]], gC_TimeTypeNames[GOKZ_GetTimeTypeEx(botTeleportsUsed[bot])]);
}
else
{
// KZT B2 PRO
FormatEx(tag, sizeof(tag), "%s B%d %s",
gC_ModeNamesShort[botMode[bot]], botCourse[bot], gC_TimeTypeNames[GOKZ_GetTimeTypeEx(botTeleportsUsed[bot])]);
}
}
else if (botReplayType[bot] == ReplayType_Jump)
{
// KZT LJ
FormatEx(tag, sizeof(tag), "%s %s",
gC_ModeNamesShort[botMode[bot]], gC_JumpTypesShort[botJumpType[bot]]);
}
else
{
// KZT
FormatEx(tag, sizeof(tag), "%s",
gC_ModeNamesShort[botMode[bot]]);
}
CS_SetClientClanTag(botClient[bot], tag);
}
static void SetBotName(int bot)
{
char name[MAX_NAME_LENGTH];
if (botReplayType[bot] == ReplayType_Run)
{
// DanZay (01:23.45)
FormatEx(name, sizeof(name), "%s (%s)",
botAlias[bot], GOKZ_FormatTime(botTime[bot]));
}
else if (botReplayType[bot] == ReplayType_Jump)
{
if (botJumpBlockDistance[bot] == 0)
{
// DanZay (291.44)
FormatEx(name, sizeof(name), "%s (%.2f)",
botAlias[bot], botJumpDistance[bot]);
}
else
{
// DanZay (291.44 on 289 block)
FormatEx(name, sizeof(name), "%s (%.2f on %d block)",
botAlias[bot], botJumpDistance[bot], botJumpBlockDistance[bot]);
}
}
else
{
// DanZay
FormatEx(name, sizeof(name), "%s",
botAlias[bot]);
}
gB_HideNameChange = true;
SetClientName(botClient[bot], name);
}
// Returns the number of bots that are currently replaying
static int GetBotsInUse()
{
int botsInUse = 0;
for (int bot; bot < RP_MAX_BOTS; bot++)
{
if (botInGame[bot] && botDataLoaded[bot])
{
botsInUse++;
}
}
return botsInUse;
}
// Returns a bot that isn't currently replaying, or -1 if no unused bots found
static int GetUnusedBot()
{
for (int bot = 0; bot < RP_MAX_BOTS; bot++)
{
if (!botInGame[bot])
{
return bot;
}
}
return -1;
}
static void PlaybackSkipToTick(int bot, int tick)
{
if (botReplayVersion[bot] == 1)
{
// Load in the next tick
float repOrigin[3], repAngles[3];
repOrigin[0] = playbackTickData[bot].Get(tick, 0);
repOrigin[1] = playbackTickData[bot].Get(tick, 1);
repOrigin[2] = playbackTickData[bot].Get(tick, 2);
repAngles[0] = playbackTickData[bot].Get(tick, 3);
repAngles[1] = playbackTickData[bot].Get(tick, 4);
TeleportEntity(botClient[bot], repOrigin, repAngles, view_as<float>( { 0.0, 0.0, 0.0 } ));
}
else if (botReplayVersion[bot] == 2)
{
// Load in the next tick
ReplayTickData currentTickData;
playbackTickData[bot].GetArray(tick, currentTickData);
TeleportEntity(botClient[bot], currentTickData.origin, currentTickData.angles, view_as<float>( { 0.0, 0.0, 0.0 } ));
int direction = tick < playbackTick[bot] ? -1 : 1;
for (int i = playbackTick[bot]; i != tick; i += direction)
{
playbackTickData[bot].GetArray(i, currentTickData);
if (currentTickData.flags & RP_TELEPORT_TICK)
{
botCurrentTeleport[bot] += direction;
}
}
#if defined DEBUG
PrintToServer("X %f \nY %f \nZ %f\nPitch %f\nYaw %f", currentTickData.origin[0], currentTickData.origin[1], currentTickData.origin[2], currentTickData.angles[0], currentTickData.angles[1]);
if(currentTickData.flags & RP_MOVETYPE_MASK == view_as<int>(MOVETYPE_WALK)) PrintToServer("MOVETYPE_WALK");
if(currentTickData.flags & RP_MOVETYPE_MASK == view_as<int>(MOVETYPE_LADDER)) PrintToServer("MOVETYPE_LADDER");
if(currentTickData.flags & RP_MOVETYPE_MASK == view_as<int>(MOVETYPE_NOCLIP)) PrintToServer("MOVETYPE_NOCLIP");
if(currentTickData.flags & RP_MOVETYPE_MASK == view_as<int>(MOVETYPE_NONE)) PrintToServer("MOVETYPE_NONE");
if(currentTickData.flags & RP_IN_ATTACK) PrintToServer("IN_ATTACK");
if(currentTickData.flags & RP_IN_ATTACK2) PrintToServer("IN_ATTACK2");
if(currentTickData.flags & RP_IN_JUMP) PrintToServer("IN_JUMP");
if(currentTickData.flags & RP_IN_DUCK) PrintToServer("IN_DUCK");
if(currentTickData.flags & RP_IN_FORWARD) PrintToServer("IN_FORWARD");
if(currentTickData.flags & RP_IN_BACK) PrintToServer("IN_BACK");
if(currentTickData.flags & RP_IN_LEFT) PrintToServer("IN_LEFT");
if(currentTickData.flags & RP_IN_RIGHT) PrintToServer("IN_RIGHT");
if(currentTickData.flags & RP_IN_MOVELEFT) PrintToServer("IN_MOVELEFT");
if(currentTickData.flags & RP_IN_MOVERIGHT) PrintToServer("IN_MOVERIGHT");
if(currentTickData.flags & RP_IN_RELOAD) PrintToServer("IN_RELOAD");
if(currentTickData.flags & RP_IN_SPEED) PrintToServer("IN_SPEED");
if(currentTickData.flags & RP_FL_ONGROUND) PrintToServer("FL_ONGROUND");
if(currentTickData.flags & RP_FL_DUCKING ) PrintToServer("FL_DUCKING");
if(currentTickData.flags & RP_FL_SWIM) PrintToServer("FL_SWIM");
if(currentTickData.flags & RP_UNDER_WATER) PrintToServer("WATERLEVEL!=0");
if(currentTickData.flags & RP_TELEPORT_TICK) PrintToServer("TELEPORT");
if(currentTickData.flags & RP_TAKEOFF_TICK) PrintToServer("TAKEOFF");
if(currentTickData.flags & RP_HIT_PERF) PrintToServer("PERF");
if(currentTickData.flags & RP_SECONDARY_EQUIPPED) PrintToServer("SECONDARY_WEAPON_EQUIPPED");
PrintToServer("==============================================================");
#endif
}
Movement_SetMovetype(botClient[bot], MOVETYPE_NOCLIP);
playbackTick[bot] = tick;
}
static bool IsCurrentWeaponSecondary(int client)
{
int activeWeaponEnt = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
int secondaryEnt = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);
return activeWeaponEnt == secondaryEnt;
}
static void MakePlayerSpectate(int client, int bot)
{
GOKZ_JoinTeam(client, CS_TEAM_SPECTATOR);
SetEntProp(client, Prop_Send, "m_iObserverMode", 4);
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", bot);
int clientUserID = GetClientUserId(client);
DataPack data = new DataPack();
data.WriteCell(clientUserID);
data.WriteCell(GetClientUserId(bot));
CreateTimer(0.1, Timer_UpdateBotName, GetClientUserId(bot));
EnableReplayControls(client);
}
public Action Timer_UpdateBotName(Handle timer, int botUID)
{
Event e = CreateEvent("spec_target_updated");
e.SetInt("userid", botUID);
e.Fire();
return Plugin_Continue;
}
|