Skip to content

Commit 6a9a218

Browse files
authored
1.0.7
1 parent a94e20d commit 6a9a218

File tree

4 files changed

+180
-128
lines changed

4 files changed

+180
-128
lines changed

Config/Configs.cs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ public static class Shared {
1313
}
1414

1515
private static readonly string ConfigDirectoryName = "config";
16-
private static readonly string ConfigDirectoryName2 = "gamedata";
1716
private static readonly string ConfigFileName = "config.json";
18-
private static readonly string jsonFilePath2 = "Spawn_Loadout_gamedata.json";
19-
private static string? _jsonFilePath2;
20-
private static readonly string jsonFilePath3 = "Weapons_Settings.json";
21-
private static string? _jsonFilePath3;
2217
private static string? _configFilePath;
2318
private static ConfigData? _configData;
2419

@@ -57,19 +52,6 @@ public static ConfigData Load(string modulePath)
5752
Directory.CreateDirectory(configFileDirectory);
5853
}
5954

60-
var configFileDirectory2 = Path.Combine(modulePath, ConfigDirectoryName2);
61-
if(!Directory.Exists(configFileDirectory2))
62-
{
63-
Directory.CreateDirectory(configFileDirectory2);
64-
}
65-
66-
67-
_jsonFilePath2 = Path.Combine(configFileDirectory2, jsonFilePath2);
68-
Helper.CreateGameData(_jsonFilePath2);
69-
70-
_jsonFilePath3 = Path.Combine(configFileDirectory, jsonFilePath3);
71-
Helper.CreateWeaponsJson(_jsonFilePath3);
72-
7355
_configFilePath = Path.Combine(configFileDirectory, ConfigFileName);
7456
if (File.Exists(_configFilePath))
7557
{
@@ -111,6 +93,7 @@ public class ConfigData
11193
public string SL_Reload_Weapons_Settings_Flags { get; set; }
11294
public string SL_Reload_Weapons_Settings_CommandsInGame { get; set; }
11395
public string empty1 { get; set; }
96+
public bool AutoUpdateSignatures { get; set; }
11497
public bool EnableDebug { get; set; }
11598
public string empty2 { get; set; }
11699
public string Information_For_You_Dont_Delete_it { get; set; }
@@ -120,7 +103,8 @@ public ConfigData()
120103
empty = "----------------------------[ ↓ Spawn Loadout Configs ↓ ]---------------------------------";
121104
SL_Reload_Weapons_Settings_Flags = "@css/root,@css/admin";
122105
SL_Reload_Weapons_Settings_CommandsInGame = "!loadouts,!relaodloadouts,!restartloadouts,!loadout,!relaodloadout,!restartloadout";
123-
empty1 = "----------------------------[ ↓ Debug ↓ ]----------------------------------------------";
106+
empty1 = "----------------------------[ ↓ Utilities ↓ ]----------------------------------------------";
107+
AutoUpdateSignatures = true;
124108
EnableDebug = false;
125109
empty2 = "----------------------------[ ↓ Info For All Configs Above ↓ ]----------------------------";
126110
Information_For_You_Dont_Delete_it = " Vist [https://github.com/oqyh/cs2-Spawn-Loadout-GoldKingZ/tree/main?tab=readme-ov-file#-configuration-] To Understand All Above";

Config/Globals.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class Globals
1313
public bool ForceRemoveClientCommands = false;
1414
public bool ForceStripPlayers = false;
1515
public int ForceRemoveGroundWeapons = 0;
16+
public int GiveArmor = -1;
17+
public int GiveHealth = -1;
1618
public float DelayGiveLoadOut = 0.0f;
1719

1820
public class GetPlayerWeapons

Config/Helper.cs

Lines changed: 163 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)