@@ -78,124 +78,33 @@ public static void AdvancedServerPrintToChatAll(string message, params object[]
7878 }
7979
8080
81- public static bool IsPlayerInGroupPermission ( CCSPlayerController ? player , string groups )
81+ public static bool IsPlayerInGroupPermission ( CCSPlayerController player , string groups )
8282 {
8383 var excludedGroups = groups . Split ( ',' ) ;
8484 foreach ( var group in excludedGroups )
8585 {
86- switch ( group [ 0 ] )
86+ if ( group . StartsWith ( "#" ) )
8787 {
88- case '#' :
89- if ( AdminManager . PlayerInGroup ( player , group ) )
90- return true ;
91- break ;
92-
93- case '@' :
94- if ( AdminManager . PlayerHasPermissions ( player , group ) )
95- return true ;
96- break ;
97-
98- default :
99- return false ;
100- }
101- }
102- return false ;
103- }
104-
105- public static void CreateGameData ( string jsonFilePath )
106- {
107- if ( ! File . Exists ( jsonFilePath ) )
108- {
109- var configData = new Dictionary < string , object >
110- {
111- [ "GiveNamedItem2" ] = new Dictionary < string , object >
88+ if ( AdminManager . PlayerInGroup ( player , group ) )
11289 {
113- [ "signatures" ] = new Dictionary < string , string >
114- {
115- [ "library" ] = "server" ,
116- [ "windows" ] = "48 83 EC ? 48 C7 44 24 ? ? ? ? ? 45 33 C9 45 33 C0 C6 44 24 ? ? E8 ? ? ? ? 48 85 C0" ,
117- [ "linux" ] = "55 48 89 E5 41 57 41 56 41 55 41 54 53 48 83 EC ? 48 89 7D ? 48 85 F6 74"
118- }
90+ return true ;
11991 }
120- } ;
121-
122- var options = new JsonSerializerOptions
123- {
124- WriteIndented = true
125- } ;
12692
127- string json = System . Text . Json . JsonSerializer . Serialize ( configData , options ) ;
128- File . WriteAllText ( jsonFilePath , json ) ;
129- }
130- }
131- public static void CreateWeaponsJson ( string jsonFilePath )
132- {
133- if ( ! File . Exists ( jsonFilePath ) )
134- {
135- var configData = new Dictionary < string , object >
93+ } else if ( group . StartsWith ( "@" ) )
13694 {
137- [ "ANY" ] = new Dictionary < string , object >
138- {
139- [ "Remove_Ground_Weapons" ] = 1 ,
140- [ "LOADOUT_1" ] = new Dictionary < string , object >
141- {
142- [ "Flags" ] = "@css/root,@css/admin,@css/vip,#css/admin,#css/vip" ,
143- [ "CT" ] = "weapon_taser,weapon_decoy" ,
144- [ "T" ] = "weapon_taser,weapon_decoy" ,
145- [ "CT_Refill_Nades" ] = "weapon_decoy" ,
146- [ "CT_Refill_Time_InSec" ] = 30 ,
147- [ "T_Refill_Nades" ] = "weapon_decoy" ,
148- [ "T_Refill_Time_InSec" ] = 30
149- } ,
150- [ "LOADOUT_2" ] = new Dictionary < string , object >
151- {
152- [ "Give_This_LoadOut_PerRound_Only" ] = 1 ,
153- [ "CT" ] = "weapon_hkp2000,weapon_knife,weapon_smokegrenade" ,
154- [ "T" ] = "weapon_glock,weapon_knife,weapon_smokegrenade"
155- }
156- } ,
157- [ "hns_" ] = new Dictionary < string , object >
158- {
159- [ "LOADOUT_1" ] = new Dictionary < string , object >
160- {
161- [ "FLAGS" ] = "@css/root,@css/admin,@css/vip,#css/admin,#css/vip" ,
162- [ "CT_Refill_Nades" ] = "weapon_decoy" ,
163- [ "CT_Refill_Time_InSec" ] = 30 ,
164- [ "T_Refill_Nades" ] = "weapon_decoy" ,
165- [ "T_Refill_Time_InSec" ] = 30
166- } ,
167- [ "LOADOUT_2" ] = new Dictionary < string , object >
168- {
169- [ "Give_This_LoadOut_PerRound_Only" ] = 2 ,
170- [ "CT" ] = "weapon_decoy" ,
171- [ "T" ] = "weapon_decoy"
172- }
173- } ,
174- [ "awp_lego_2" ] = new Dictionary < string , object >
95+ if ( AdminManager . PlayerHasPermissions ( player , group ) )
17596 {
176- [ "Force_Strip_Players" ] = true ,
177- [ "Remove_Knife" ] = true ,
178- [ "Remove_BuyMenu" ] = true ,
179- [ "Remove_Custom_Point_Server_Command" ] = true ,
180- [ "Remove_Custom_Point_Client_Command" ] = true ,
181- [ "Remove_Ground_Weapons" ] = 1 ,
182- [ "Delay_InXSecs_Give_LoadOuts" ] = 1.0 ,
183- [ "LOADOUT_1" ] = new Dictionary < string , object >
184- {
185- [ "CT" ] = "weapon_ssg08" ,
186- [ "T" ] = "weapon_ssg08"
187- }
97+ return true ;
18898 }
189- } ;
190-
191- var options = new JsonSerializerOptions
99+ } else
192100 {
193- WriteIndented = true
194- } ;
195-
196- string json = System . Text . Json . JsonSerializer . Serialize ( configData , options ) ;
197- File . WriteAllText ( jsonFilePath , json ) ;
198- }
101+ if ( AdminManager . PlayerInGroup ( player , group ) )
102+ {
103+ return true ;
104+ }
105+ }
106+ }
107+ return false ;
199108 }
200109
201110 public static void ClearVariables ( )
@@ -219,6 +128,9 @@ public static void ClearVariables()
219128 SpawnLoadoutGoldKingZ . Instance . g_Main . ForceStripPlayers = false ;
220129 SpawnLoadoutGoldKingZ . Instance . g_Main . ForceRemoveGroundWeapons = 0 ;
221130 SpawnLoadoutGoldKingZ . Instance . g_Main . DelayGiveLoadOut = 0.0f ;
131+ SpawnLoadoutGoldKingZ . Instance . g_Main . GiveHealth = - 1 ;
132+ SpawnLoadoutGoldKingZ . Instance . g_Main . GiveArmor = - 1 ;
133+
222134 Server . ExecuteCommand ( "sv_buy_status_override -1" ) ;
223135 }
224136
@@ -413,6 +325,29 @@ public static void SetValuesToGlobals()
413325 SpawnLoadoutGoldKingZ . Instance . g_Main . RemoveBuyMenu = true ;
414326 }
415327 }
328+
329+ if ( jsonValues . ContainsKey ( "Players_Health" ) )
330+ {
331+ int Players_Health = jsonValues [ "Players_Health" ] != null
332+ ? ( int ) jsonValues [ "Players_Health" ]
333+ : - 1 ;
334+ if ( Players_Health > - 1 )
335+ {
336+ SpawnLoadoutGoldKingZ . Instance . g_Main . GiveHealth = Players_Health ;
337+ }
338+ }
339+
340+ if ( jsonValues . ContainsKey ( "Players_Armor" ) )
341+ {
342+ int Players_Armor = jsonValues [ "Players_Armor" ] != null
343+ ? ( int ) jsonValues [ "Players_Armor" ]
344+ : - 1 ;
345+ if ( Players_Armor > - 1 )
346+ {
347+ SpawnLoadoutGoldKingZ . Instance . g_Main . GiveArmor = Players_Armor ;
348+ }
349+ }
350+
416351 if ( jsonValues . ContainsKey ( "Remove_Knife" ) )
417352 {
418353 bool RemoveKnife = jsonValues [ "Remove_Knife" ] != null
@@ -516,5 +451,127 @@ public static void CleanUpPlayerWeapons(CCSPlayerController? player)
516451 }
517452 }
518453 }
454+
455+ public static async Task DownloadMissingFiles ( )
456+ {
457+ string baseFolderPath = Configs . Shared . CookiesModule ! ;
458+
459+ string gamedataFileName = "gamedata/Spawn_Loadout_gamedata.json" ;
460+ string gamedataGithubUrl = "https://raw.githubusercontent.com/oqyh/cs2-Spawn-Loadout-GoldKingZ/main/Resources/Spawn_Loadout_gamedata.json" ;
461+ string gamedataFilePath = Path . Combine ( baseFolderPath , gamedataFileName ) ;
462+ string gamedataDirectoryPath = Path . GetDirectoryName ( gamedataFilePath ) ! ;
463+ await CheckAndDownloadFile ( gamedataFilePath , gamedataGithubUrl , gamedataDirectoryPath ) ;
464+
465+
466+ string settingsFileName = "config/Weapons_Settings.json" ;
467+ string settingsGithubUrl = "https://raw.githubusercontent.com/oqyh/cs2-Spawn-Loadout-GoldKingZ/main/Resources/Weapons_Settings.json" ;
468+ string settingsFilePath = Path . Combine ( baseFolderPath , settingsFileName ) ;
469+ string settingsDirectoryPath = Path . GetDirectoryName ( settingsFilePath ) ! ;
470+ await DownloadFileIfNotExists ( settingsFilePath , settingsGithubUrl , settingsDirectoryPath ) ;
471+ }
472+ public static async Task DownloadFileIfNotExists ( string filePath , string githubUrl , string directoryPath )
473+ {
474+ if ( ! File . Exists ( filePath ) )
475+ {
476+ if ( ! Directory . Exists ( directoryPath ) )
477+ {
478+ Directory . CreateDirectory ( directoryPath ) ;
479+ }
480+ await DownloadFileFromGithub ( githubUrl , filePath ) ;
481+ }
482+ }
483+
484+ public static async Task < bool > CheckAndDownloadFile ( string filePath , string githubUrl , string directoryPath )
485+ {
486+ if ( ! File . Exists ( filePath ) )
487+ {
488+ if ( ! Directory . Exists ( directoryPath ) )
489+ {
490+ Directory . CreateDirectory ( directoryPath ) ;
491+ }
492+ await DownloadFileFromGithub ( githubUrl , filePath ) ;
493+ return true ;
494+ }
495+ else
496+ {
497+ if ( Configs . GetConfigData ( ) . AutoUpdateSignatures )
498+ {
499+ bool isFileDifferent = await IsFileDifferent ( filePath , githubUrl ) ;
500+ if ( isFileDifferent )
501+ {
502+ File . Delete ( filePath ) ;
503+ await DownloadFileFromGithub ( githubUrl , filePath ) ;
504+ return true ;
505+ }
506+ }
507+
508+ }
509+
510+ return false ;
511+ }
512+
513+
514+ public static async Task < bool > IsFileDifferent ( string localFilePath , string githubUrl )
515+ {
516+ try
517+ {
518+ byte [ ] localFileBytes = await File . ReadAllBytesAsync ( localFilePath ) ;
519+ string localFileHash = GetFileHash ( localFileBytes ) ;
520+
521+ using ( HttpClient client = new HttpClient ( ) )
522+ {
523+ byte [ ] githubFileBytes = await client . GetByteArrayAsync ( githubUrl ) ;
524+ string githubFileHash = GetFileHash ( githubFileBytes ) ;
525+ return localFileHash != githubFileHash ;
526+ }
527+ }
528+ catch ( Exception ex )
529+ {
530+ DebugMessage ( $ "Error comparing files: { ex . Message } ") ;
531+ return false ;
532+ }
533+ }
534+
535+ public static string GetFileHash ( byte [ ] fileBytes )
536+ {
537+ using ( var md5 = System . Security . Cryptography . MD5 . Create ( ) )
538+ {
539+ byte [ ] hashBytes = md5 . ComputeHash ( fileBytes ) ;
540+ return BitConverter . ToString ( hashBytes ) . Replace ( "-" , "" ) . ToLowerInvariant ( ) ;
541+ }
542+ }
543+
544+ public static async Task DownloadFileFromGithub ( string url , string destinationPath )
545+ {
546+ using ( HttpClient client = new HttpClient ( ) )
547+ {
548+ try
549+ {
550+ byte [ ] fileBytes = await client . GetByteArrayAsync ( url ) ;
551+ await File . WriteAllBytesAsync ( destinationPath , fileBytes ) ;
552+ }
553+ catch ( Exception ex )
554+ {
555+ DebugMessage ( $ "Error downloading file: { ex . Message } ") ;
556+ }
557+ }
558+ }
559+
560+ public static void GivePlayerHealthNArmor ( CCSPlayerController player )
561+ {
562+ if ( player == null || ! player . IsValid || ! player . PawnIsAlive ) return ;
563+
564+ if ( SpawnLoadoutGoldKingZ . Instance . g_Main . GiveHealth > - 1 )
565+ {
566+ player . PlayerPawn ! . Value ! . Health = SpawnLoadoutGoldKingZ . Instance . g_Main . GiveHealth ;
567+ Utilities . SetStateChanged ( player . PlayerPawn . Value , "CBaseEntity" , "m_iHealth" ) ;
568+ }
569+
570+ if ( SpawnLoadoutGoldKingZ . Instance . g_Main . GiveArmor > - 1 )
571+ {
572+ player . PlayerPawn ! . Value ! . ArmorValue = SpawnLoadoutGoldKingZ . Instance . g_Main . GiveArmor ;
573+ Utilities . SetStateChanged ( player . PlayerPawn . Value , "CCSPlayerPawn" , "m_ArmorValue" ) ;
574+ }
575+ }
519576
520577}
0 commit comments