forked from shavitush/bhoptimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshavit-checkpoints.sp
More file actions
2225 lines (1821 loc) · 57.6 KB
/
shavit-checkpoints.sp
File metadata and controls
2225 lines (1821 loc) · 57.6 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
/*
* shavit's Timer - Checkpoints
* by: shavit, kidfearless, Nairda, GAMMA CASE, rumour, rtldg, sh4hrazad, Ciallo-Ani, olivia, Nuko, yupi2
*
* This file is part of shavit's Timer (https://github.com/shavitush/bhoptimer)
*
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program 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
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <sourcemod>
#include <convar_class>
#include <clientprefs>
#include <dhooks>
#include <shavit/core>
#include <shavit/checkpoints>
#include <shavit/zones>
#include <shavit/physicsuntouch>
#undef REQUIRE_PLUGIN
#include <shavit/replay-recorder>
#include <shavit/replay-playback>
#include <eventqueuefix>
#pragma newdecls required
#pragma semicolon 1
#define DEBUG 0
#define CP_ANGLES (1 << 0)
#define CP_VELOCITY (1 << 1)
#define CP_DEFAULT (CP_ANGLES|CP_VELOCITY)
enum TimerAction
{
TimerAction_OnStart,
TimerAction_OnTeleport
}
enum struct persistent_data_t
{
int iSteamID;
int iDisconnectTime;
int iTimesTeleported;
ArrayList aCheckpoints;
int iCurrentCheckpoint;
cp_cache_t cpcache;
}
char gS_Map[PLATFORM_MAX_PATH];
char gS_PreviousMap[PLATFORM_MAX_PATH];
EngineVersion gEV_Type = Engine_Unknown;
bool gB_Late = false;
Convar gCV_Checkpoints = null;
Convar gCV_UseOthers = null;
Convar gCV_RestoreStates = null;
Convar gCV_PersistData = null;
Convar gCV_MaxCP = null;
Convar gCV_MaxCP_Segmented = null;
Handle gH_CheckpointsCookie = null;
Handle gH_Forwards_OnSave = null;
Handle gH_Forwards_OnTeleport = null;
Handle gH_Forwards_OnSavePre = null;
Handle gH_Forwards_OnTeleportPre = null;
Handle gH_Forwards_OnDelete = null;
Handle gH_Forwards_OnCheckpointMenuMade = null;
Handle gH_Forwards_OnCheckpointMenuSelect = null;
Handle gH_Forwards_OnCheckpointCacheSaved = null;
Handle gH_Forwards_OnCheckpointCacheLoaded = null;
chatstrings_t gS_ChatStrings;
int gI_Style[MAXPLAYERS+1];
ArrayList gA_Checkpoints[MAXPLAYERS+1];
int gI_CurrentCheckpoint[MAXPLAYERS+1];
int gI_TimesTeleported[MAXPLAYERS+1];
bool gB_InCheckpointMenu[MAXPLAYERS+1];
int gI_UsingCheckpointsOwner[MAXPLAYERS+1]; // 0 = use player's own checkpoints
int gI_CheckpointsSettings[MAXPLAYERS+1];
// save states
bool gB_SaveStates[MAXPLAYERS+1]; // whether we have data for when player rejoins from spec
ArrayList gA_PersistentData = null;
bool gB_Eventqueuefix = false;
bool gB_ReplayRecorder = false;
DynamicHook gH_CommitSuicide = null;
float gF_NextSuicide[MAXPLAYERS+1];
int gI_Offset_m_lastStandingPos = 0;
int gI_Offset_m_ladderSurpressionTimer = 0;
int gI_Offset_m_lastLadderNormal = 0;
int gI_Offset_m_lastLadderPos = 0;
int gI_Offset_m_afButtonDisabled = 0;
int gI_Offset_m_afButtonForced = 0;
public Plugin myinfo =
{
name = "[shavit] Checkpoints",
author = "shavit, KiD Fearless, Nairda, GAMMA CASE, rumour, rtldg, sh4hrazad, Ciallo-Ani, olivia, Nuko, yupi2",
description = "Checkpoints for shavit's bhop timer.",
version = SHAVIT_VERSION,
url = "https://github.com/shavitush/bhoptimer"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("Shavit_GetCheckpoint", Native_GetCheckpoint);
CreateNative("Shavit_SetCheckpoint", Native_SetCheckpoint);
CreateNative("Shavit_ClearCheckpoints", Native_ClearCheckpoints);
CreateNative("Shavit_TeleportToCheckpoint", Native_TeleportToCheckpoint);
CreateNative("Shavit_GetTotalCheckpoints", Native_GetTotalCheckpoints);
CreateNative("Shavit_SaveCheckpoint", Native_SaveCheckpoint);
CreateNative("Shavit_GetCurrentCheckpoint", Native_GetCurrentCheckpoint);
CreateNative("Shavit_SetCurrentCheckpoint", Native_SetCurrentCheckpoint);
CreateNative("Shavit_GetTimesTeleported", Native_GetTimesTeleported);
CreateNative("Shavit_SetTimesTeleported", Native_SetTimesTeleported);
CreateNative("Shavit_HasSavestate", Native_HasSavestate);
CreateNative("Shavit_LoadCheckpointCache", Native_LoadCheckpointCache);
CreateNative("Shavit_SaveCheckpointCache", Native_SaveCheckpointCache);
if (!FileExists("cfg/sourcemod/plugin.shavit-checkpoints.cfg") && FileExists("cfg/sourcemod/plugin.shavit-misc.cfg"))
{
File source = OpenFile("cfg/sourcemod/plugin.shavit-misc.cfg", "r");
File destination = OpenFile("cfg/sourcemod/plugin.shavit-checkpoints.cfg", "w");
if (source && destination)
{
char line[512];
while (!source.EndOfFile() && source.ReadLine(line, sizeof(line)))
{
ReplaceString(line, sizeof(line), "_misc_", "_checkpoints_");
destination.WriteLine("%s", line);
}
}
delete destination;
delete source;
}
RegPluginLibrary("shavit-checkpoints");
gB_Late = late;
return APLRes_Success;
}
public void OnPluginStart()
{
gH_Forwards_OnSave = CreateGlobalForward("Shavit_OnSave", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_OnTeleport = CreateGlobalForward("Shavit_OnTeleport", ET_Ignore, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_OnSavePre = CreateGlobalForward("Shavit_OnSavePre", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_OnTeleportPre = CreateGlobalForward("Shavit_OnTeleportPre", ET_Event, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_OnCheckpointMenuMade = CreateGlobalForward("Shavit_OnCheckpointMenuMade", ET_Event, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_OnCheckpointMenuSelect = CreateGlobalForward("Shavit_OnCheckpointMenuSelect", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_OnDelete = CreateGlobalForward("Shavit_OnDelete", ET_Event, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_OnCheckpointCacheSaved = CreateGlobalForward("Shavit_OnCheckpointCacheSaved", ET_Ignore, Param_Cell, Param_Array, Param_Cell, Param_Cell);
gH_Forwards_OnCheckpointCacheLoaded = CreateGlobalForward("Shavit_OnCheckpointCacheLoaded", ET_Ignore, Param_Cell, Param_Array, Param_Cell);
gEV_Type = GetEngineVersion();
RegConsoleCmd("sm_cpmenu", Command_Checkpoints, "Opens the checkpoints menu.");
RegConsoleCmd("sm_cp", Command_Checkpoints, "Opens the checkpoints menu. Alias for sm_cpmenu.");
RegConsoleCmd("sm_checkpoint", Command_Checkpoints, "Opens the checkpoints menu. Alias for sm_cpmenu.");
RegConsoleCmd("sm_checkpoints", Command_Checkpoints, "Opens the checkpoints menu. Alias for sm_cpmenu.");
RegConsoleCmd("sm_save", Command_Save, "Saves a checkpoint.");
RegConsoleCmd("sm_tele", Command_Tele, "Teleports to a checkpoint. Usage: sm_tele [number]");
RegConsoleCmd("sm_teleport", Command_Tele, "Teleports to a checkpoint. Usage: sm_tele [number]");
RegConsoleCmd("sm_prevcp", Command_PrevCheckpoint, "Selects the previous checkpoint.");
RegConsoleCmd("sm_nextcp", Command_NextCheckpoint, "Selects the next checkpoint.");
RegConsoleCmd("sm_deletecp", Command_DeleteCheckpoint, "Deletes the current checkpoint.");
gH_CheckpointsCookie = RegClientCookie("shavit_checkpoints", "Checkpoints settings", CookieAccess_Protected);
gA_PersistentData = new ArrayList(sizeof(persistent_data_t));
AddCommandListener(Command_Jointeam, "jointeam");
HookEvent("player_spawn", Player_Spawn);
HookEvent("player_team", Player_Notifications, EventHookMode_Pre);
HookEvent("player_death", Player_Notifications, EventHookMode_Pre);
LoadTranslations("common.phrases");
LoadTranslations("shavit-common.phrases");
LoadTranslations("shavit-misc.phrases");
gCV_Checkpoints = new Convar("shavit_checkpoints_enabled", "1", "Allow players to save and teleport to checkpoints.", 0, true, 0.0, true, 1.0);
gCV_UseOthers = new Convar("shavit_checkpoints_useothers", "1", "Allow players to use or duplicate another player's checkpoints.", 0, true, 0.0, true, 1.0);
gCV_RestoreStates = new Convar("shavit_checkpoints_restorestates", "1", "Save the players' timer/position etc.. when they die/change teams,\nand load the data when they spawn?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_MaxCP = new Convar("shavit_checkpoints_maxcp", "1000", "Maximum amount of checkpoints.\nNote: Very high values will result in high memory usage!", 0, true, 1.0, true, 10000.0);
gCV_MaxCP_Segmented = new Convar("shavit_checkpoints_maxcp_seg", "10", "Maximum amount of segmented checkpoints. Make this less or equal to shavit_checkpoints_maxcp.\nNote: Very high values will result in HUGE memory usage! Segmented checkpoints contain frame data!", 0, true, 1.0, true, 50.0);
gCV_PersistData = new Convar("shavit_checkpoints_persistdata", "600", "How long to persist timer data for disconnected users in seconds?\n-1 - Until map change\n0 - Disabled", 0, true, -1.0);
Convar.AutoExecConfig();
CreateTimer(10.0, Timer_Cron, 0, TIMER_REPEAT);
CreateTimer(0.5, Timer_PersistCPMenu, 0, TIMER_REPEAT);
LoadDHooks();
// modules
gB_Eventqueuefix = LibraryExists("eventqueuefix");
gB_ReplayRecorder = LibraryExists("shavit-replay-recorder");
if (gB_Late)
{
Shavit_OnChatConfigLoaded();
}
}
void LoadDHooks()
{
GameData hGameData = new GameData("shavit.games");
if (hGameData == null)
{
SetFailState("Failed to load shavit gamedata");
}
LoadPhysicsUntouch(hGameData);
if (gEV_Type == Engine_CSS)
{
if ((gI_Offset_m_lastStandingPos = GameConfGetOffset(hGameData, "CCSPlayer::m_lastStandingPos")) == -1)
{
SetFailState("Couldn't get the offset for \"CCSPlayer::m_lastStandingPos\"!");
}
if ((gI_Offset_m_ladderSurpressionTimer = GameConfGetOffset(hGameData, "CCSPlayer::m_ladderSurpressionTimer")) == -1)
{
SetFailState("Couldn't get the offset for \"CCSPlayer::m_ladderSurpressionTimer\"!");
}
if ((gI_Offset_m_lastLadderNormal = GameConfGetOffset(hGameData, "CCSPlayer::m_lastLadderNormal")) == -1)
{
SetFailState("Couldn't get the offset for \"CCSPlayer::m_lastLadderNormal\"!");
}
if ((gI_Offset_m_lastLadderPos = GameConfGetOffset(hGameData, "CCSPlayer::m_lastLadderPos")) == -1)
{
SetFailState("Couldn't get the offset for \"CCSPlayer::m_lastLadderPos\"!");
}
}
Address buttonsSig = hGameData.GetMemSig("CBasePlayer->m_afButtonDisabled");
if (buttonsSig == Address_Null)
{
SetFailState("Couldn't find signature of CBasePlayer->m_afButtonDisabled");
}
int instr = LoadFromAddress(buttonsSig, NumberType_Int32);
// The lowest two bytes are the beginning of a `mov`.
// The offset is 100% definitely totally always 16-bit.
gI_Offset_m_afButtonDisabled = instr >> 16;
gI_Offset_m_afButtonForced = gI_Offset_m_afButtonDisabled + 4;
delete hGameData;
hGameData = LoadGameConfigFile("sdktools.games");
int iOffset;
if ((iOffset = GameConfGetOffset(hGameData, "CommitSuicide")) == -1)
{
SetFailState("Couldn't get the offset for \"CommitSuicide\"!");
}
gH_CommitSuicide = new DynamicHook(iOffset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity);
gH_CommitSuicide.AddParam(HookParamType_Bool);
gH_CommitSuicide.AddParam(HookParamType_Bool);
delete hGameData;
}
public void OnLibraryAdded(const char[] name)
{
if (StrEqual(name, "shavit-replay-recorder"))
{
gB_ReplayRecorder = true;
}
else if (StrEqual(name, "eventqueuefix"))
{
gB_Eventqueuefix = true;
}
}
public void OnLibraryRemoved(const char[] name)
{
if (StrEqual(name, "shavit-replay-recorder"))
{
gB_ReplayRecorder = false;
}
else if (StrEqual(name, "eventqueuefix"))
{
gB_Eventqueuefix = false;
}
}
public void OnMapStart()
{
GetLowercaseMapName(gS_Map);
if (gB_Late)
{
gB_Late = false;
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
OnClientPutInServer(i);
if (AreClientCookiesCached(i))
{
OnClientCookiesCached(i);
Shavit_OnStyleChanged(i, 0, Shavit_GetBhopStyle(i), Shavit_GetClientTrack(i), false);
}
}
}
}
if (!StrEqual(gS_Map, gS_PreviousMap, false))
{
int iLength = gA_PersistentData.Length;
for(int i = iLength - 1; i >= 0; i--)
{
persistent_data_t aData;
gA_PersistentData.GetArray(i, aData);
DeletePersistentData(i, aData);
}
}
}
public void OnMapEnd()
{
gS_PreviousMap = gS_Map;
}
public void Shavit_OnChatConfigLoaded()
{
Shavit_GetChatStringsStruct(gS_ChatStrings);
}
public void Shavit_OnPause(int client, int track)
{
if (!gB_SaveStates[client])
{
PersistData(client, false);
}
}
public void Shavit_OnResume(int client, int track)
{
if (gB_SaveStates[client])
{
// events&outputs won't work properly unless we do this next frame...
RequestFrame(LoadPersistentData, GetClientSerial(client));
}
}
public void Shavit_OnStop(int client, int track)
{
if (gB_SaveStates[client])
{
DeletePersistentDataFromClient(client);
}
}
public Action Command_Jointeam(int client, const char[] command, int args)
{
if (!IsValidClient(client))
{
return Plugin_Continue;
}
if (!gB_SaveStates[client])
{
PersistData(client, false);
}
return Plugin_Continue;
}
public MRESReturn CBasePlayer__CommitSuicide(int client, DHookParam params)
{
//bool bExplode = params.Get(1);
bool bForce = params.Get(2);
if (IsPlayerAlive(client) && (bForce || gF_NextSuicide[client] <= GetGameTime()))
{
gF_NextSuicide[client] = GetGameTime() + 5.0;
PersistData(client, false);
}
return MRES_Ignored;
}
public Action Timer_Cron(Handle timer)
{
if (gCV_PersistData.IntValue < 0)
{
return Plugin_Continue;
}
int iTime = GetTime();
int iLength = gA_PersistentData.Length;
for(int i = iLength - 1; i >= 0; i--)
{
persistent_data_t aData;
gA_PersistentData.GetArray(i, aData);
if(aData.iDisconnectTime && (iTime - aData.iDisconnectTime >= gCV_PersistData.IntValue))
{
DeletePersistentData(i, aData);
}
}
return Plugin_Continue;
}
public Action Timer_PersistCPMenu(Handle timer)
{
if (!gCV_Checkpoints.BoolValue)
{
return Plugin_Continue;
}
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && IsPlayerAlive(i) && !IsFakeClient(i) && ShouldReopenCheckpointMenu(i))
{
OpenCPMenu(i);
}
}
return Plugin_Continue;
}
public void OnClientCookiesCached(int client)
{
if (IsFakeClient(client))
{
return;
}
char sSetting[8];
GetClientCookie(client, gH_CheckpointsCookie, sSetting, sizeof(sSetting));
if (strlen(sSetting) == 0)
{
IntToString(CP_DEFAULT, sSetting, 8);
SetClientCookie(client, gH_CheckpointsCookie, sSetting);
gI_CheckpointsSettings[client] = CP_DEFAULT;
}
else
{
gI_CheckpointsSettings[client] = StringToInt(sSetting);
}
// TODO: BAD
gI_Style[client] = Shavit_GetBhopStyle(client);
}
public void OnClientPutInServer(int client)
{
gF_NextSuicide[client] = GetGameTime();
if (IsFakeClient(client))
{
return;
}
if (gH_CommitSuicide != null)
{
gH_CommitSuicide.HookEntity(Hook_Pre, client, CBasePlayer__CommitSuicide);
}
if (!AreClientCookiesCached(client))
{
gI_Style[client] = Shavit_GetBhopStyle(client);
gI_CheckpointsSettings[client] = CP_DEFAULT;
}
if(gA_Checkpoints[client] == null)
{
gA_Checkpoints[client] = new ArrayList(sizeof(cp_cache_t));
}
else
{
ResetCheckpoints(client);
}
gB_SaveStates[client] = false;
gI_UsingCheckpointsOwner[client] = 0;
}
public void OnClientDisconnect(int client)
{
if (IsFakeClient(client))
{
return;
}
for (int i = 1; i <= MaxClients; i++)
{
if (gI_UsingCheckpointsOwner[i] == client)
{
gI_UsingCheckpointsOwner[i] = 0;
gI_CurrentCheckpoint[i] = gA_Checkpoints[i].Length;
}
}
gI_UsingCheckpointsOwner[client] = 0;
gB_InCheckpointMenu[client] = false;
PersistData(client, true);
// if data wasn't persisted, then we have checkpoints to reset...
ResetCheckpoints(client);
delete gA_Checkpoints[client];
}
void DeletePersistentDataFromClient(int client)
{
persistent_data_t aData;
int iIndex = FindPersistentData(client, aData);
if (iIndex != -1)
{
DeletePersistentData(iIndex, aData);
}
gB_SaveStates[client] = false;
}
public void Shavit_OnStyleChanged(int client, int oldstyle, int newstyle, int track, bool manual)
{
gI_Style[client] = newstyle;
bool bSegmented = Shavit_GetStyleSettingBool(newstyle, "segments");
bool bKzcheckpoints = Shavit_GetStyleSettingBool(newstyle, "kzcheckpoints");
if (gB_SaveStates[client] && manual)
{
DeletePersistentDataFromClient(client);
}
if (bSegmented || bKzcheckpoints)
{
// Gammacase somehow had this callback fire before OnClientPutInServer.
// OnClientPutInServer will still fire but we need a valid arraylist in the mean time.
if(gA_Checkpoints[client] == null)
{
gA_Checkpoints[client] = new ArrayList(sizeof(cp_cache_t));
}
if (bKzcheckpoints)
{
gI_UsingCheckpointsOwner[client] = 0;
}
OpenCheckpointsMenu(client);
if (!Shavit_GetStyleSettingBool(oldstyle, "segments") && !Shavit_GetStyleSettingBool(oldstyle, "kzcheckpoints"))
{
Shavit_PrintToChat(client, "%T", "MiscSegmentedCommand", client, gS_ChatStrings.sVariable, gS_ChatStrings.sText);
}
}
}
public Action Shavit_OnStart(int client)
{
gI_TimesTeleported[client] = 0;
// shavit-kz
if(Shavit_GetStyleSettingBool(gI_Style[client], "kzcheckpoints"))
{
ResetCheckpoints(client);
UpdateKZStyle(client, TimerAction_OnStart);
}
return Plugin_Continue;
}
public void Shavit_OnRestart(int client, int track)
{
if(gB_InCheckpointMenu[client] &&
Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints") &&
GetClientMenu(client, null) == MenuSource_None &&
IsPlayerAlive(client) && GetClientTeam(client) >= 2)
{
OpenCPMenu(client);
}
}
public void Player_Spawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (IsFakeClient(client))
{
return;
}
int serial = GetClientSerial(client);
if (gB_SaveStates[client])
{
if(gCV_RestoreStates.BoolValue)
{
// events&outputs won't work properly unless we do this next frame...
RequestFrame(LoadPersistentData, serial);
}
}
else
{
persistent_data_t aData;
int iIndex = FindPersistentData(client, aData);
if (iIndex != -1)
{
gB_SaveStates[client] = true;
// events&outputs won't work properly unless we do this next frame...
RequestFrame(LoadPersistentData, serial);
}
}
// refreshes kz cp menu if there is nothing open
if (gB_InCheckpointMenu[client] &&
Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints") &&
GetClientMenu(client, null) == MenuSource_None &&
IsPlayerAlive(client) && GetClientTeam(client) >= 2)
{
OpenCPMenu(client);
}
}
public Action Player_Notifications(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (!IsFakeClient(client))
{
if (!gB_SaveStates[client])
{
PersistData(client, false);
}
}
return Plugin_Continue;
}
bool CanSegment(int client)
{
return Shavit_GetStyleSettingBool(gI_Style[client], "segments");
}
int GetMaxCPs(int client)
{
return CanSegment(client)? gCV_MaxCP_Segmented.IntValue:gCV_MaxCP.IntValue;
}
int FindPersistentData(int client, persistent_data_t aData)
{
int iSteamID;
if((iSteamID = GetSteamAccountID(client)) != 0)
{
int index = gA_PersistentData.FindValue(iSteamID, 0);
if (index != -1)
{
gA_PersistentData.GetArray(index, aData);
return index;
}
}
return -1;
}
void PersistData(int client, bool disconnected)
{
if(!IsClientInGame(client) ||
(!IsPlayerAlive(client) && !disconnected) ||
(!IsPlayerAlive(client) && disconnected && !gB_SaveStates[client]) ||
GetSteamAccountID(client) == 0 ||
//Shavit_GetTimerStatus(client) == Timer_Stopped ||
(!gCV_RestoreStates.BoolValue && !disconnected) ||
(gCV_PersistData.IntValue == 0 && disconnected))
{
return;
}
persistent_data_t aData;
int iIndex = FindPersistentData(client, aData);
aData.iSteamID = GetSteamAccountID(client);
aData.iTimesTeleported = gI_TimesTeleported[client];
if (disconnected)
{
aData.iDisconnectTime = GetTime();
aData.iCurrentCheckpoint = gI_CurrentCheckpoint[client] > gA_Checkpoints[client].Length ? gA_Checkpoints[client].Length : gI_CurrentCheckpoint[client];
aData.aCheckpoints = gA_Checkpoints[client];
gA_Checkpoints[client] = null;
if (gB_ReplayRecorder && aData.cpcache.aFrames == null)
{
aData.cpcache.aFrames = Shavit_GetReplayData(client, true);
aData.cpcache.iPreFrames = Shavit_GetPlayerPreFrames(client);
}
}
else
{
aData.iDisconnectTime = 0;
}
if (!gB_SaveStates[client])
{
SaveCheckpointCache(client, client, aData.cpcache, -1, INVALID_HANDLE);
}
gB_SaveStates[client] = true;
if (iIndex == -1)
{
gA_PersistentData.PushArray(aData);
}
else
{
gA_PersistentData.SetArray(iIndex, aData);
}
}
void DeletePersistentData(int index, persistent_data_t data)
{
gA_PersistentData.Erase(index);
DeleteCheckpointCache(data.cpcache);
DeleteCheckpointCacheList(data.aCheckpoints);
delete data.aCheckpoints;
}
void LoadPersistentData(int serial)
{
int client = GetClientFromSerial(serial);
if(client == 0 ||
GetSteamAccountID(client) == 0 ||
GetClientTeam(client) < 2 ||
!IsPlayerAlive(client))
{
return;
}
persistent_data_t aData;
int iIndex = FindPersistentData(client, aData);
if (iIndex == -1)
{
return;
}
gB_SaveStates[client] = false;
bool bKzcheckpoints = Shavit_GetStyleSettingBool(aData.cpcache.aSnapshot.bsStyle, "kzcheckpoints");
if (LoadCheckpointCache(client, aData.cpcache, -1, bKzcheckpoints))
{
gI_TimesTeleported[client] = aData.iTimesTeleported;
if (aData.aCheckpoints != null)
{
DeleteCheckpointCacheList(gA_Checkpoints[client]);
delete gA_Checkpoints[client];
gI_CurrentCheckpoint[client] = aData.iCurrentCheckpoint;
gA_Checkpoints[client] = aData.aCheckpoints;
aData.aCheckpoints = null;
if (gA_Checkpoints[client].Length > 0)
{
OpenCheckpointsMenu(client);
}
}
}
DeletePersistentData(iIndex, aData);
}
void DeleteCheckpointCache(cp_cache_t cache)
{
delete cache.aFrames;
delete cache.aEvents;
delete cache.aOutputWaits;
delete cache.customdata;
}
void DeleteCheckpointCacheList(ArrayList cps, int client_for_callback=0)
{
if (cps != null)
{
for (int i = cps.Length - 1; i >= 0; i--)
{
if (client_for_callback)
{
Call_StartForward(gH_Forwards_OnDelete);
Call_PushCell(client_for_callback);
Call_PushCell(i+1);
Call_PushCell(true);
Call_Finish();
}
cp_cache_t cache;
cps.GetArray(i, cache);
DeleteCheckpointCache(cache);
}
cps.Clear();
}
}
void ResetCheckpoints(int client)
{
gI_CurrentCheckpoint[client] = 0;
DeleteCheckpointCacheList(gA_Checkpoints[client], client);
}
bool ShouldReopenCheckpointMenu(int client)
{
return gB_InCheckpointMenu[client];
}
public Action Command_Checkpoints(int client, int args)
{
if(client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}
if (!gA_Checkpoints[client]) // probably got here from another plugin doing `FakeClientCommandEx(param1, "sm_checkpoints");` too early or too late
{
return Plugin_Handled;
}
return OpenCheckpointsMenu(client);
}
public Action Command_Save(int client, int args)
{
if(client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}
bool bSegmenting = CanSegment(client);
if(!gCV_Checkpoints.BoolValue && !bSegmenting)
{
Shavit_PrintToChat(client, "%T", "FeatureDisabled", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText);
return Plugin_Handled;
}
if(SaveCheckpoint(client))
{
Shavit_PrintToChat(client, "%T", "MiscCheckpointsSaved", client, gI_CurrentCheckpoint[client], gS_ChatStrings.sVariable, gS_ChatStrings.sText);
if (ShouldReopenCheckpointMenu(client))
{
OpenCheckpointsMenu(client);
}
}
return Plugin_Handled;
}
public Action Command_Tele(int client, int args)
{
if(client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}
if(!gCV_Checkpoints.BoolValue)
{
Shavit_PrintToChat(client, "%T", "FeatureDisabled", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText);
return Plugin_Handled;
}
int index = gI_CurrentCheckpoint[client];
if(args > 0)
{
char arg[8];
GetCmdArg(1, arg, sizeof(arg));
int parsed = StringToInt(arg);
if(0 < parsed <= gCV_MaxCP.IntValue)
{
index = parsed;
}
}
TeleportToCheckpoint(client, index, true, client);
return Plugin_Handled;
}
public Action Command_PrevCheckpoint(int client, int args)
{
if (client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}
if (!gCV_Checkpoints.BoolValue)
{
Shavit_PrintToChat(client, "%T", "FeatureDisabled", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText);
return Plugin_Handled;
}
if (gI_CurrentCheckpoint[client] > 1)
{
gI_CurrentCheckpoint[client]--;
if (ShouldReopenCheckpointMenu(client))
{
OpenCheckpointsMenu(client);
}
}
return Plugin_Handled;
}
public Action Command_NextCheckpoint(int client, int args)
{
if (client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}
if (!gCV_Checkpoints.BoolValue)
{
Shavit_PrintToChat(client, "%T", "FeatureDisabled", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText);
return Plugin_Handled;
}
if (gI_CurrentCheckpoint[client] < gA_Checkpoints[client].Length)
{
gI_CurrentCheckpoint[client]++;
if (ShouldReopenCheckpointMenu(client))
{
OpenCheckpointsMenu(client);
}
}
return Plugin_Handled;
}
public Action Command_DeleteCheckpoint(int client, int args)
{
if (client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}
if (!gCV_Checkpoints.BoolValue)
{
Shavit_PrintToChat(client, "%T", "FeatureDisabled", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText);
return Plugin_Handled;