This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
store.sp
4716 lines (3946 loc) · 156 KB
/
store.sp
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
#pragma semicolon 1
#pragma newdecls required
//////////////////////////////
// INCLUDES //
//////////////////////////////
#include <sourcemod>
#include <store>
#include <store_stock>
#include <sdkhooks>
#include <sdktools>
#include <dhooks>
#undef REQUIRE_EXTENSIONS
#undef AUTOLOAD_EXTENSIONS
#undef REQUIRE_PLUGIN
#include <TransmitManager>
#include <clientprefs>
#include <fys.opts>
#include <fys.pupd>
#define AUTOLOAD_EXTENSIONS
#define REQUIRE_EXTENSIONS
#define REQUIRE_PLUGIN
// local build compile environment
#tryinclude <store_env>
//////////////////////////////
// PLUGIN DEFINITION //
//////////////////////////////
public Plugin myinfo =
{
name = "Store - The Resurrection",
author = STORE_AUTHOR,
description = "a sourcemod store system",
version = STORE_VERSION,
url = STORE_URL
};
//////////////////////////////
// DEFINITIONS //
//////////////////////////////
enum
{
OBS_MODE_NONE = 0, // not in spectator mode
OBS_MODE_DEATHCAM, // special mode for death cam animation
OBS_MODE_FREEZECAM, // zooms to a target, and freeze-frames on them
OBS_MODE_FIXED, // view from a fixed camera position
OBS_MODE_IN_EYE, // follow a player in first person view
OBS_MODE_CHASE, // follow a player in third person view
OBS_MODE_ROAMING, // free roaming
NUM_OBSERVER_MODES,
};
#define TEAM_CT 3
#define TEAM_TE 2
#define TEAM_ZM 2
#define TEAM_OB 1
#define TEAM_US 0
#define STORE_TRANSMIT_CHANNEL 5
// Server
#define COMPILE_ENVIRONMENT
// GM_TT -> ttt server
// GM_ZE -> zombie escape server
// GM_MG -> mini games server
// GM_JB -> jail break server
// GM_KZ -> kreedz server
// GM_HZ -> casual server
// GM_PR -> pure|competitive server
// GM_HG -> hunger game server
// GM_SR -> death surf server
// GM_BH -> bhop server
// GM_IS -> insurgency
// GM_EF -> left 4 dead(2)
// VERIFY CREDITS
//#define DATA_VERIFY
// [CT] [TE] tag in player skin title -> enabled by default
#define Skin_TeamTag
//#define LOG_NOT_FOUND
// Custom Module
// skin does not match with team
#if defined GM_TT || defined GM_ZE || defined GM_KZ || defined GM_BH || defined GM_SR || defined GM_JB || defined GM_HG
#define Global_Skin
#undef Skin_TeamTag
#endif
// fix arms when client team
#if defined GM_MG
#define TeamArms
#endif
// death chat
#if defined GM_ZE || defined GM_JB || defined GM_MG || defined GM_KZ || defined GM_SR || defined GM_BH || defined GM_EF
#define DeathChat
#endif
#define MAX_SKIN_LEVEL 6
//////////////////////////////
// GLOBAL VARIABLES //
//////////////////////////////
Database g_hDatabase = null;
GlobalForward g_hOnStoreAvailable = null;
GlobalForward g_hOnStoreInit = null;
GlobalForward g_hOnClientLoaded = null;
GlobalForward g_hOnClientBuyItem = null;
GlobalForward g_hOnClientPurchased = null;
GlobalForward g_hOnClientComposed = null;
GlobalForward g_hOnClientComposing = null;
GlobalForward g_hOnGiveClientItem = null;
GlobalForward g_hShouldDrawItem = null;
ArrayList g_aCaseSkins[3];
StringMap g_smParentMap = null;
ArrayList g_aLateQueue;
Store_Item g_Items[STORE_MAX_ITEMS];
Client_Data g_ClientData[MAXPLAYERS + 1];
Client_Item g_ClientItem[MAXPLAYERS + 1][STORE_MAX_ITEMS];
Type_Handler g_TypeHandlers[STORE_MAX_HANDLERS];
Menu_Handler g_MenuHandlers[STORE_MAX_HANDLERS];
Item_Plan g_PurchasePlan[STORE_MAX_ITEMS][STORE_MAX_PLANS];
Compose_Data g_Compose[MAXPLAYERS + 1];
int g_iItems = 0;
int g_iTypeHandlers = 0;
int g_iMenuHandlers = 0;
int g_iPackageHandler = -1;
int g_iClientCase[MAXPLAYERS + 1];
int g_iMenuBack[MAXPLAYERS + 1];
int g_iLastSelection[MAXPLAYERS + 1];
int g_iSelectedItem[MAXPLAYERS + 1];
int g_iSelectedPlan[MAXPLAYERS + 1];
int g_iMenuNum[MAXPLAYERS + 1];
int g_iSpam[MAXPLAYERS + 1];
int g_iDataProtect[MAXPLAYERS + 1];
bool g_bInvMode[MAXPLAYERS + 1];
bool g_bLateLoad; // check if we need actual reload map or fake reload
bool g_bStoreLoaded;
bool g_bInterMission;
// library
bool g_pClientprefs;
bool g_pfysOptions;
bool g_pfysRect;
bool g_pOpenCase;
bool g_pRandomSkin;
bool g_pTransmit;
// Case Options
static int g_inCase[4] = { 999999, 3888, 8888, 23888 };
static char g_szCase[4][32] = { "", "Normal Case", "Advanced Case", "Ultima Case" };
static float g_fCreditsTimerInterval = 0.0;
static int g_iCreditsTimerOnline = 2;
static char g_szComposeFee[][] = { "5888", "9888", "15888", "21888", "29888", "38888" };
//////////////////////////////
// MODULES //
//////////////////////////////
// Module Global Module
#include "store/cpsupport.sp"
#include "store/tpmode.sp" // Module TP
// Module Hats
#if defined GM_TT || defined GM_ZE || defined GM_MG || defined GM_JB || defined GM_HZ || defined GM_HG || defined GM_SR || defined GM_BH
#include "store/modules/hats.sp"
#endif
// Module Skin
#if defined GM_TT || defined GM_ZE || defined GM_MG || defined GM_JB || defined GM_HZ || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH
#include "store/modules/skin.sp"
#endif
// Module Neon
#if defined GM_TT || defined GM_MG || defined GM_JB || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH
#include "store/modules/neon.sp"
#endif
// Module Aura & Part
#if defined GM_TT || defined GM_MG || defined GM_JB || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH || defined GM_ZE
#include "store/modules/aura.sp"
#include "store/modules/part.sp"
#endif
// Module Trail
#if defined GM_TT || defined GM_ZE || defined GM_MG || defined GM_JB || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH
#include "store/modules/trail.sp"
#endif
// Module PLAYERS
#if defined Module_Hats || defined Module_Skin || defined Module_Neon || defined Module_Aura || defined Module_Part || defined Module_Trail
#include "store/players.sp"
#endif
// Module Grenade
#if defined GM_TT || defined GM_MG || defined GM_JB || defined GM_HZ || defined GM_HG
#include "store/grenades.sp"
#endif
// Module Spray
#if defined GM_TT || defined GM_ZE || defined GM_MG || defined GM_JB || defined GM_HZ || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH || defined GM_IS || defined GM_EF
#include "store/sprays.sp"
#endif
// Module Sound
#if defined GM_TT || defined GM_ZE || defined GM_MG || defined GM_JB || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH || defined GM_IS || defined GM_EF
#include "store/sounds.sp"
#endif
//////////////////////////////
// PLUGIN UPDATER //
//////////////////////////////
public void Pupd_OnCheckAllPlugins()
{
#if defined GM_TT
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/TT/");
#endif
#if defined GM_ZE
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/ZE/");
#endif
#if defined GM_MG
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/MG/");
#endif
#if defined GM_JB
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/JB/");
#endif
#if defined GM_KZ
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/KZ/");
#endif
#if defined GM_HZ
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/HZ/");
#endif
#if defined GM_PR
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/PR/");
#endif
#if defined GM_HG
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/HG/");
#endif
#if defined GM_SR
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/SR/");
#endif
#if defined GM_BH
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/BH/");
#endif
#if defined GM_IS
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/IS/");
#endif
#if defined GM_EF
Pupd_CheckPlugin(false, "https://build.kxnrl.com/updater/Store/EF/");
#endif
Pupd_CheckTranslation("store.phrases.txt", "https://build.kxnrl.com/updater/Store/translation/");
}
//////////////////////////////
// PLUGIN FORWARDS //
//////////////////////////////
public void OnPluginStart()
{
EngineVersion engine = GetEngineVersion();
#if defined GM_IS
if (engine != Engine_Insurgency)
SetFailState("Current game is not be supported! Insurgency only!");
#elseif defined GM_EF
if (!(engine == Engine_Left4Dead || engine == Engine_Left4Dead2))
SetFailState("Current game is not be supported! Left 4 Dead(2) only!");
#else
// Check Engine
if (engine != Engine_CSGO)
SetFailState("Current game is not be supported! CSGO only!");
#endif
g_smParentMap = new StringMap();
g_aLateQueue = new ArrayList();
// Setting default values
for (int client = 1; client <= MaxClients; ++client)
{
g_ClientData[client].iCredits = 0;
g_ClientData[client].iOriginalCredits = 0;
g_ClientData[client].iItems = 0;
}
// Register Commands
RegConsoleCmd("sm_store", Command_Store);
RegConsoleCmd("buyammo1", Command_Store);
RegConsoleCmd("primammo", Command_Store);
RegConsoleCmd("sm_shop", Command_Store);
RegConsoleCmd("sm_inv", Command_Inventory);
RegConsoleCmd("sm_inventory", Command_Inventory);
RegConsoleCmd("sm_credits", Command_Credits);
RegConsoleCmd("sm_storecase", Command_Case);
HookEvent("round_start", OnRoundStart, EventHookMode_Post);
HookEvent("player_death", OnPlayerDeath, EventHookMode_Post);
// Prevent Server freezing by SQL databsae?
if (engine == Engine_CSGO)
HookEvent("cs_win_panel_match", OnGameOver, EventHookMode_Post);
else if (engine == Engine_Insurgency)
HookEvent("game_end", OnGameOver, EventHookMode_Post);
// Load the translations file
LoadTranslations("store.phrases");
// Connect to the database
Database.Connect(SQLCallback_Connection, "csgo", 0);
for (int x = 0; x < 3; ++x) g_aCaseSkins[x] = new ArrayList(ByteCountToCells(256));
ConVar mp_match_restart_delay = FindConVar("mp_match_restart_delay");
if (mp_match_restart_delay != null)
{
// 30 sec to exec sql command.
mp_match_restart_delay.SetFloat(20.0, true, true);
mp_match_restart_delay.AddChangeHook(InterMissionLock);
}
#if defined Module_Skin
Skin_InitConVar();
#endif
TPMode_InitConVar();
}
public void OnAllPluginsLoaded()
{
g_pClientprefs = LibraryExists("clientprefs");
g_pfysOptions = LibraryExists("fys-Opts");
g_pfysRect = LibraryExists("fys-Rect");
g_pOpenCase = LibraryExists("OpenCase");
g_pRandomSkin = LibraryExists("store-randomskin");
g_pTransmit = LibraryExists("TransmitManager");
if (g_pClientprefs)
{
#if defined Module_Sound
Sounds_OnClientprefs();
#endif
}
if (g_pfysOptions)
{
}
#pragma unused g_pfysRect, g_pOpenCase, g_pTransmit
// LogMessage("Rect: %s | Case: %s", g_pfysRect ? "loaded" : "fail", g_pOpenCase ? "loaded" : "fail");
}
public void OnPluginEnd()
{
for (int client = 1; client <= MaxClients; ++client)
if (IsClientInGame(client))
if (g_ClientData[client].bLoaded)
OnClientDisconnect(client);
}
public void OnLibraryAdded(const char[] name)
{
if (strcmp(name, "clientprefs") == 0)
{
g_pClientprefs = true;
#if defined Module_Sound
Sounds_OnClientprefs();
#endif
}
if (strcmp(name, "fys-Opts") == 0)
g_pfysOptions = true;
if (strcmp(name, "fys-Rect") == 0)
g_pfysRect = true;
if (strcmp(name, "OpenCase") == 0)
g_pOpenCase = true;
if (strcmp(name, "store-randomskin") == 0)
g_pRandomSkin = true;
if (strcmp(name, "TransmitManager") == 0)
g_pTransmit = true;
}
public void OnLibraryRemoved(const char[] name)
{
if (strcmp(name, "clientprefs") == 0)
{
g_pClientprefs = false;
#if defined Module_Sound
Sounds_OnClientprefs();
#endif
}
if (strcmp(name, "fys-Opts") == 0)
g_pfysOptions = false;
if (strcmp(name, "fys-Rect") == 0)
g_pfysRect = false;
if (strcmp(name, "OpenCase") == 0)
g_pOpenCase = false;
if (strcmp(name, "store-randomskin") == 0)
g_pRandomSkin = false;
if (strcmp(name, "TransmitManager") == 0)
g_pTransmit = false;
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_hOnStoreAvailable = CreateGlobalForward("Store_OnStoreAvailable", ET_Ignore, Param_Cell);
g_hOnStoreInit = CreateGlobalForward("Store_OnStoreInit", ET_Ignore, Param_Cell);
g_hOnClientLoaded = CreateGlobalForward("Store_OnClientLoaded", ET_Ignore, Param_Cell);
g_hOnClientBuyItem = CreateGlobalForward("Store_OnClientBuyItem", ET_Event, Param_Cell, Param_String, Param_Cell, Param_Cell);
g_hOnClientPurchased = CreateGlobalForward("Store_OnClientPurchased", ET_Ignore, Param_Cell, Param_String, Param_Cell, Param_Cell);
g_hOnClientComposing = CreateGlobalForward("Store_OnClientComposing", ET_Hook, Param_Cell, Param_CellByRef, Param_Cell, Param_String, Param_String, Param_String);
g_hOnClientComposed = CreateGlobalForward("Store_OnClientComposed", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_String);
g_hOnGiveClientItem = CreateGlobalForward("Store_OnGiveClientItem", ET_Hook, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell);
g_hShouldDrawItem = CreateGlobalForward("Store_ShouldDisplayItem", ET_Hook, Param_Cell, Param_Cell, Param_String, Param_String, Param_Cell, Param_CellByRef);
CreateNative("Store_RegisterHandler", Native_RegisterHandler);
CreateNative("Store_RegisterMenuHandler", Native_RegisterMenuHandler);
CreateNative("Store_SetDataIndex", Native_SetDataIndex);
CreateNative("Store_GetDataIndex", Native_GetDataIndex);
CreateNative("Store_GetEquippedItem", Native_GetEquippedItem);
CreateNative("Store_IsClientLoaded", Native_IsClientLoaded);
CreateNative("Store_DisplayPreviousMenu", Native_DisplayPreviousMenu);
CreateNative("Store_SetClientMenu", Native_SetClientMenu);
CreateNative("Store_GetClientCredits", Native_GetClientCredits);
CreateNative("Store_SetClientCredits", Native_SetClientCredits);
CreateNative("Store_IsItemInBoughtPackage", Native_IsItemInBoughtPackage);
CreateNative("Store_DisplayConfirmMenu", Native_DisplayConfirmMenu);
CreateNative("Store_UseItem", Native_UseItem);
CreateNative("Store_GiveItem", Native_GiveItem);
CreateNative("Store_GetItemId", Native_GetItemId);
CreateNative("Store_GetTypeId", Native_GetTypeId);
CreateNative("Store_GetItemData", Native_GetItemData);
CreateNative("Store_RemoveItem", Native_RemoveItem);
CreateNative("Store_HasClientItem", Native_HasClientItem);
CreateNative("Store_ExtClientItem", Native_ExtClientItem);
CreateNative("Store_GetItemExpiration", Native_GetItemExpiration);
CreateNative("Store_SaveClientAll", Native_SaveClientAll);
CreateNative("Store_GetClientID", Native_GetClientID);
CreateNative("Store_IsClientBanned", Native_IsClientBanned);
CreateNative("Store_SetClientBanState", Native_SetClientBanState);
CreateNative("Store_HasPlayerSkin", Native_HasPlayerSkin);
CreateNative("Store_GetPlayerSkin", Native_GetPlayerSkin);
CreateNative("Store_GetClientPlayerSkins", Native_GetClientPlayerSkins);
CreateNative("Store_GetAllPlayerSkins", Native_GetAllPlayerSkins);
CreateNative("Store_GetSkinLevel", Native_GetSkinLevel);
CreateNative("Store_GetItemList", Native_GetItemList);
CreateNative("Store_IsPlayerTP", Native_IsPlayerTP);
CreateNative("Store_SetPlayerTP", Native_SetPlayerTP);
CreateNative("Store_IsPlayerHide", Native_IsPlayerHide);
CreateNative("Store_IsStoreSpray", Native_IsStoreSpray);
CreateNative("Store_ApplyPlayerSkin", Native_ApplyPlayerSkin);
CreateNative("Store_LogOpencase", Native_LogOpenCase);
CreateNative("Store_IsInDeathCamera", Native_InDeathCamera);
CreateNative("Store_IsGlobalTeam", Native_IsGlobalTeam);
CreateNative("Store_GetEquipPlayerSkin", Native_GetEquippedSkin);
CreateNative("Store_ChatSayText", Native_ChatSayText);
MarkNativeAsOptional("RegClientCookie");
MarkNativeAsOptional("GetClientCookie");
MarkNativeAsOptional("SetClientCookie");
MarkNativeAsOptional("Opts_GetOptBool");
MarkNativeAsOptional("Opts_SetOptBool");
MarkNativeAsOptional("Opts_GetOptFloat");
MarkNativeAsOptional("Pupd_CheckPlugin");
MarkNativeAsOptional("Pupd_CheckTranslation");
MarkNativeAsOptional("TransmitManager_AddEntityHooks");
MarkNativeAsOptional("TransmitManager_SetEntityOwner");
MarkNativeAsOptional("TransmitManager_SetEntityState");
MarkNativeAsOptional("TransmitManager_GetEntityState");
MarkNativeAsOptional("TransmitManager_SetEntityBlock");
MarkNativeAsOptional("TransmitManager_GetEntityBlock");
MarkNativeAsOptional("TransmitManager_IsEntityHooked");
// g_bLateLoad = late;
// engine was loaded and after 10 seconds
g_bLateLoad = GetEngineTime() >= 10.0;
// RegLibrary
RegPluginLibrary("store");
return APLRes_Success;
}
//////////////////////////////
// REST OF PLUGIN FORWARD //
//////////////////////////////
public void OnMapStart()
{
g_bInterMission = false;
for (int i = 0; i < g_iTypeHandlers; ++i)
{
if (g_TypeHandlers[i].fnMapStart != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].szPlFile))
{
Call_StartFunction(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].fnMapStart);
Call_Finish();
}
}
}
public void OnMapEnd()
{
#if defined Module_Skin
PlayerSkins_OnMapEnd();
#endif
}
//////////////////////////////
// NATIVES //
//////////////////////////////
static any Native_GetItemId(Handle myself, int numParams)
{
char uid[256];
if (GetNativeString(1, STRING(uid)) != SP_ERROR_NONE)
return -1;
return UTIL_GetItemId(uid, -1);
}
static any Native_GetTypeId(Handle myself, int numParams)
{
char type[32];
if (GetNativeString(1, STRING(type)) != SP_ERROR_NONE)
return -1;
return UTIL_GetTypeHandler(type);
}
static any Native_GetItemData(Handle myself, int numParams)
{
int itemid = GetNativeCell(1);
if (itemid < 0 || itemid > STORE_MAX_ITEMS)
ThrowNativeError(SP_ERROR_PARAM, "ItemId [%d] is not allowed.", itemid);
SetNativeArray(2, g_Items[itemid], sizeof(Store_Item));
return true;
}
static any Native_SaveClientAll(Handle myself, int numParams)
{
int client = GetNativeCell(1);
UTIL_SaveClientData(client, false);
UTIL_SaveClientInventory(client);
UTIL_SaveClientEquipment(client);
return true;
}
static any Native_GetClientID(Handle myself, int numParams)
{
return g_ClientData[GetNativeCell(1)].iId;
}
static any Native_IsClientBanned(Handle myself, int numParams)
{
return g_ClientData[GetNativeCell(1)].bBan;
}
static any Native_SetClientBanState(Handle myself, int numParams)
{
g_ClientData[GetNativeCell(1)].bBan = GetNativeCell(2);
return true;
}
static any Native_RegisterHandler(Handle plugin, int numParams)
{
if (g_iTypeHandlers == STORE_MAX_HANDLERS)
return -1;
char m_szType[32];
GetNativeString(1, STRING(m_szType));
int m_iHandler = UTIL_GetTypeHandler(m_szType);
int m_iId = g_iTypeHandlers;
if (m_iHandler != -1)
return m_iHandler;
++g_iTypeHandlers;
g_TypeHandlers[m_iId].hPlugin = plugin;
g_TypeHandlers[m_iId].fnMapStart = GetNativeFunction(2);
g_TypeHandlers[m_iId].fnReset = GetNativeFunction(3);
g_TypeHandlers[m_iId].fnConfig = GetNativeFunction(4);
g_TypeHandlers[m_iId].fnUse = GetNativeFunction(5);
g_TypeHandlers[m_iId].fnRemove = GetNativeFunction(6);
g_TypeHandlers[m_iId].bEquipable = GetNativeCell(7);
g_TypeHandlers[m_iId].bRaw = GetNativeCell(8);
g_TypeHandlers[m_iId].bDisposable = GetNativeCell(9);
strcopy(g_TypeHandlers[m_iId].szType, sizeof(Type_Handler::szType), m_szType);
char file[64];
GetPluginFilename(plugin, STRING(file));
strcopy(g_TypeHandlers[m_iId].szPlFile, sizeof(Type_Handler::szPlFile), file);
return m_iId;
}
static any Native_RegisterMenuHandler(Handle plugin, int numParams)
{
if (g_iMenuHandlers == STORE_MAX_HANDLERS)
return -1;
char m_szIdentifier[64];
GetNativeString(1, STRING(m_szIdentifier));
int m_iHandler = UTIL_GetMenuHandler(m_szIdentifier);
int m_iId = g_iMenuHandlers;
if (m_iHandler != -1)
return (g_MenuHandlers[m_iId].hPlugin == plugin) ? m_iId : -1; // Unique Plugin
++g_iMenuHandlers;
g_MenuHandlers[m_iId].hPlugin = plugin;
g_MenuHandlers[m_iId].fnMenu = GetNativeFunction(2);
g_MenuHandlers[m_iId].fnHandler = GetNativeFunction(3);
strcopy(g_MenuHandlers[m_iId].szIdentifier, sizeof(Menu_Handler::szIdentifier), m_szIdentifier);
char file[64];
GetPluginFilename(plugin, STRING(file));
strcopy(g_MenuHandlers[m_iId].szPlFile, sizeof(Menu_Handler::szPlFile), file);
return m_iId;
}
static any Native_SetDataIndex(Handle myself, int numParams)
{
int index = GetNativeCell(1);
g_Items[index].iData = GetNativeCell(2);
return g_Items[index].iData;
}
static any Native_GetDataIndex(Handle myself, int numParams)
{
return g_Items[GetNativeCell(1)].iData;
}
static any Native_GetEquippedItem(Handle myself, int numParams)
{
char m_szType[16];
GetNativeString(2, STRING(m_szType));
int m_iHandler = UTIL_GetTypeHandler(m_szType);
if (m_iHandler == -1)
return -1;
return UTIL_GetEquippedItemFromHandler(GetNativeCell(1), m_iHandler, GetNativeCell(3));
}
static any Native_IsClientLoaded(Handle myself, int numParams)
{
return g_ClientData[GetNativeCell(1)].bLoaded;
}
static any Native_DisplayPreviousMenu(Handle myself, int numParams)
{
int client = GetNativeCell(1);
switch (g_iMenuNum[client])
{
case 1: DisplayStoreMenu(client, g_iMenuBack[client], g_iLastSelection[client]);
case 2: DisplayItemMenu(client, g_iSelectedItem[client]);
case 3: DisplayPlayerMenu(client);
case 4: DisplayPlanMenu(client, g_iSelectedItem[client]);
case 5: DisplayComposeMenu(client, false);
}
return true;
}
static any Native_SetClientMenu(Handle myself, int numParams)
{
g_iMenuNum[GetNativeCell(1)] = GetNativeCell(2);
return 0;
}
static any Native_GetClientCredits(Handle myself, int numParams)
{
int client = GetNativeCell(1);
if (g_ClientData[client].bBan)
return 0;
return g_ClientData[client].iCredits;
}
static any Native_SetClientCredits(Handle myself, int numParams)
{
int client = GetNativeCell(1);
if (IsFakeClient(client) || !g_ClientData[client].bLoaded || g_ClientData[client].bBan)
return false;
int m_iCredits = GetNativeCell(2);
int difference = m_iCredits - g_ClientData[client].iCredits;
// maybe not needed?
// if going to intermission, after 3 seconds, we force disconnect client then mark as not load.
/*
if(g_bInterMission)
{
char path[128];
BuildPath(Path_SM, STRING(path), "logs/store.warn.log");
LogToFileEx(path, "Native_SetClientCredits -> %L -> %d -> %d -> %d", client, g_ClientData[client].iId, m_iCredits, difference);
return false;
}
*/
if (numParams < 3)
{
ThrowNativeError(SP_ERROR_NATIVE, "Reason is not nullable.");
return false;
}
char logMsg[128];
if (GetNativeString(3, STRING(logMsg)) != SP_ERROR_NONE)
{
ThrowNativeError(SP_ERROR_NATIVE, "Failed to get reason in native call.");
return false;
}
if (strcmp(logMsg, "未知") == 0)
{
ThrowNativeError(SP_ERROR_NATIVE, "Reason is not nullable.");
return false;
}
if (g_ClientData[client].bRefresh)
{
DataPack pack = new DataPack();
pack.WriteCell(GetClientSerial(client));
pack.WriteCell(difference);
pack.WriteCell(g_ClientData[client].iId);
pack.WriteCell(GetTime());
pack.WriteString(logMsg);
CreateTimer(1.0, Timer_SetCreditsDelay, pack, TIMER_REPEAT);
return true;
}
g_ClientData[client].iCredits = m_iCredits;
UTIL_LogMessage(client, difference, logMsg);
UTIL_SaveClientData(client, false);
return true;
}
static Action Timer_SetCreditsDelay(Handle timer, DataPack pack)
{
pack.Reset();
int serial = pack.ReadCell();
int client = GetClientFromSerial(serial);
int difference = pack.ReadCell();
int m_iStoreId = pack.ReadCell();
int iTimeStamp = pack.ReadCell();
char logMsg[256];
pack.ReadString(STRING(logMsg));
if (!client || !IsClientInGame(client))
{
delete pack;
char m_szQuery[512], eReason[256];
FormatEx(STRING(m_szQuery), "UPDATE store_players SET credits=credits+%d WHERE id=%d", difference, m_iStoreId);
SQL_TVoid(g_hDatabase, m_szQuery, DBPrio_High);
g_hDatabase.Escape(logMsg, STRING(eReason));
FormatEx(STRING(m_szQuery), "INSERT INTO store_newlogs VALUES (DEFAULT, %d, %d, %d, \"%s\", FROM_UNIXTIME(%d))", m_iStoreId, g_ClientData[client].iCredits + difference, difference, eReason, iTimeStamp);
SQL_TVoid(g_hDatabase, m_szQuery, DBPrio_Low);
return Plugin_Stop;
}
if (g_ClientData[client].bRefresh)
return Plugin_Continue;
delete pack;
if (m_iStoreId != g_ClientData[client].iId)
{
LogStoreError("SetCreditsDelay -> id not match -> id.%d ? real.%d -> \"%L\" ", m_iStoreId, g_ClientData[client].iId, client);
return Plugin_Stop;
}
g_ClientData[client].iCredits += difference;
UTIL_LogMessage(client, difference, logMsg);
UTIL_SaveClientData(client, false);
return Plugin_Stop;
}
static any Native_IsItemInBoughtPackage(Handle myself, int numParams)
{
int client = GetNativeCell(1);
int itemid = GetNativeCell(2);
int uid = GetNativeCell(3);
if (itemid >= 0)
return false;
int m_iParent = g_Items[itemid].iParent;
while (m_iParent != -1)
{
for (int i = 0; i < g_ClientData[client].iItems; ++i)
if (((uid == -1 && g_ClientItem[client][i].iUniqueId == m_iParent) || (uid != -1 && g_ClientItem[client][i].iUniqueId == uid)) && !g_ClientItem[client][i].bDeleted)
return true;
m_iParent = g_Items[m_iParent].iParent;
}
return false;
}
static any Native_DisplayConfirmMenu(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
char title[255], m_szCallback[32], m_szData[11];
GetNativeString(2, STRING(title));
DataPack pack = new DataPack();
pack.WriteCell(plugin);
pack.WriteFunction(GetNativeFunction(3));
char file[64];
GetPluginFilename(plugin, STRING(file));
pack.WriteString(file);
pack.Reset();
Menu m_hMenu = new Menu(MenuHandler_Confirm);
m_hMenu.SetTitle("%s\n ", title);
IntToString(view_as<int>(pack), STRING(m_szCallback));
IntToString(GetNativeCell(4), STRING(m_szData));
AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, m_szCallback, "%T", "Confirm_Yes", client);
AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, m_szData, "%T", "Confirm_No", client);
m_hMenu.ExitButton = false;
m_hMenu.Display(client, 0);
return 0;
}
static any Native_UseItem(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
int itemid = GetNativeCell(2);
bool synced = GetNativeCell(3);
int slot = GetNativeCell(4);
if (!Store_HasClientItem(client, itemid))
return -1;
return UTIL_UseItem(client, itemid, synced, slot);
}
static any Native_GiveItem(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
int itemid = GetNativeCell(2);
int purchase = GetNativeCell(3);
int expiration = GetNativeCell(4);
int price = GetNativeCell(5);
if (expiration < GetTime() && expiration > 0)
return false;
if (IsFakeClient(client) || !g_ClientData[client].bLoaded || g_ClientData[client].bBan)
{
LogStoreError("Native_GiveItem -> %N itemid %d purchase %d expiration %d price %d -> ban? loaded? fakeclient?", client, itemid, purchase, expiration, price);
return false;
}
if (itemid < 0)
{
LogStoreError("Native_GiveItem -> %N itemid %d purchase %d expiration %d price %d", client, itemid, purchase, expiration, price);
return false;
}
Action res = Plugin_Continue;
Call_StartForward(g_hOnGiveClientItem);
Call_PushCell(client);
Call_PushString(g_Items[itemid].szUniqueId);
Call_PushCell(purchase);
Call_PushCell(expiration);
Call_PushCell(price);
Call_Finish(res);
if (res >= Plugin_Handled)
return false;
char pFile[32];
GetPluginFilename(plugin, STRING(pFile));
if (!Store_HasClientItem(client, itemid))
{
int m_iDateOfPurchase = (purchase == 0 ? GetTime() : purchase);
int m_iDateOfExpiration = expiration;
int m_iId = g_ClientData[client].iItems++;
g_ClientItem[client][m_iId].iId = -1;
g_ClientItem[client][m_iId].iUniqueId = itemid;
g_ClientItem[client][m_iId].iDateOfPurchase = m_iDateOfPurchase;
g_ClientItem[client][m_iId].iDateOfExpiration = m_iDateOfExpiration;
g_ClientItem[client][m_iId].iPriceOfPurchase = price;
g_ClientItem[client][m_iId].bSynced = false;
g_ClientItem[client][m_iId].bDeleted = false;
UTIL_LogMessage(client, 0, "Give item [%s][%s] via native, p[%d], e[%d] from %s", g_Items[itemid].szUniqueId, g_Items[itemid].szName, m_iDateOfPurchase, expiration, pFile);
return true;
}
UTIL_LogMessage(client, 0, "Give and Ext item [%s][%s] via native, e[%d] from %s", g_Items[itemid].szUniqueId, g_Items[itemid].szName, expiration, pFile);
int ext = Store_GetItemExpiration(client, itemid);
if (ext > 0)
{
if (!Store_ExtClientItem(client, itemid, expiration == 0 ? expiration : expiration - GetTime()))
LogStoreError("Ext \"%L\" %s failed. purchase %d expiration %d price %d", client, g_Items[itemid].szName, purchase, expiration, price);
}
else
{
LogMessage("Try to extend item at %L but have ext %d", client, ext);
}
return true;
}
static any Native_RemoveItem(Handle myself, int numParams)
{
int client = GetNativeCell(1);
int itemid = GetNativeCell(2);
if (itemid > 0 && g_TypeHandlers[g_Items[itemid].iHandler].fnRemove != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].szPlFile))
{
Call_StartFunction(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].fnRemove);
Call_PushCell(client);
Call_PushCell(itemid);
Call_Finish();
}
UTIL_UnequipItem(client, itemid, false);
int m_iId = UTIL_GetClientItemId(client, itemid);
if (m_iId != -1)
g_ClientItem[client][m_iId].bDeleted = true;
return 0;
}
static any Native_GetItemExpiration(Handle myself, int numParams)
{
int client = GetNativeCell(1);
int itemid = GetNativeCell(2);
// Check if item is available?
if (itemid < 0)
return -1;
if (!g_ClientData[client].bLoaded)
return -1;
// Can he even have it?
if (g_Items[itemid].szSteam[0] != 0)
return (AllowItemForAuth(client, g_Items[itemid].szSteam)) ? 0 : -1;
if (g_Items[itemid].bVIP && AllowItemForVIP(client, true) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans == 0)
return 0;
// Is the item free (available for everyone)?
if ((!g_Items[itemid].bIgnore || g_Items[itemid].bBuyable) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans == 0)
return -1;
for (int i = 0; i < g_ClientData[client].iItems; ++i)
if (g_ClientItem[client][i].iUniqueId == itemid && !g_ClientItem[client][i].bDeleted)
return g_ClientItem[client][i].iDateOfExpiration;
return -1;
}
static any Native_HasClientItem(Handle myself, int numParams)
{