Skip to content

Commit b1a0457

Browse files
authored
1.0.2
1 parent 9397878 commit b1a0457

File tree

6 files changed

+394
-434
lines changed

6 files changed

+394
-434
lines changed

Config/Configs.cs

Lines changed: 3 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -5,96 +5,9 @@ namespace Spawn_Loadout_GoldKingZ.Config
55
{
66
public static class Configs
77
{
8-
9-
private static readonly string ConfigDirectoryName = "config";
10-
private static readonly string ConfigFileName = "config.json";
11-
private static string? _configFilePath;
12-
private static ConfigData? _configData;
13-
14-
private static readonly JsonSerializerOptions SerializationOptions = new()
15-
{
16-
Converters =
17-
{
18-
new JsonStringEnumConverter()
19-
},
20-
WriteIndented = true,
21-
AllowTrailingCommas = true,
22-
ReadCommentHandling = JsonCommentHandling.Skip,
23-
};
24-
25-
public static bool IsLoaded()
26-
{
27-
return _configData is not null;
28-
}
29-
30-
public static ConfigData GetConfigData()
31-
{
32-
if (_configData is null)
33-
{
34-
throw new Exception("Config not yet loaded.");
35-
}
36-
37-
return _configData;
38-
}
39-
40-
public static ConfigData Load(string modulePath)
41-
{
42-
var configFileDirectory = Path.Combine(modulePath, ConfigDirectoryName);
43-
if(!Directory.Exists(configFileDirectory))
44-
{
45-
Directory.CreateDirectory(configFileDirectory);
46-
}
47-
48-
_configFilePath = Path.Combine(configFileDirectory, ConfigFileName);
49-
if (File.Exists(_configFilePath))
50-
{
51-
_configData = JsonSerializer.Deserialize<ConfigData>(File.ReadAllText(_configFilePath), SerializationOptions);
52-
}
53-
else
54-
{
55-
_configData = new ConfigData();
56-
}
57-
58-
if (_configData is null)
59-
{
60-
throw new Exception("Failed to load configs.");
61-
}
62-
63-
SaveConfigData(_configData);
64-
65-
return _configData;
66-
}
67-
68-
private static void SaveConfigData(ConfigData configData)
69-
{
70-
if (_configFilePath is null)
71-
{
72-
throw new Exception("Config not yet loaded.");
73-
}
74-
75-
File.WriteAllText(_configFilePath, JsonSerializer.Serialize(configData, SerializationOptions));
76-
}
77-
78-
public class ConfigData
79-
{
80-
public bool GiveOneTimeLoadOutPerRound { get; set; }
81-
public bool GiveOneTimeRefillNadesPerRound { get; set; }
82-
public bool Vips_GiveOneTimeLoadOutPerRound { get; set; }
83-
public bool Vips_GiveOneTimeRefillNadesPerRound { get; set; }
84-
public string Vips { get; set; }
85-
public string empty2 { get; set; }
86-
public string Information_For_You_Dont_Delete_it { get; set; }
87-
88-
public ConfigData()
89-
{
90-
GiveOneTimeLoadOutPerRound = false;
91-
GiveOneTimeRefillNadesPerRound = false;
92-
Vips_GiveOneTimeLoadOutPerRound = false;
93-
Vips_GiveOneTimeRefillNadesPerRound = false;
94-
Vips = "@css/root,@css/admin,@css/vip,#css/admin,#css/vip";
95-
empty2 = "-----------------------------------------------------------------------------------";
96-
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";
97-
}
8+
public static class Shared {
9+
public static string? CookiesModule { get; set; }
10+
public static CustomGameData? CustomFunctions { get; set; }
9811
}
9912
}
10013
}

Config/Globals.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ namespace Spawn_Loadout_GoldKingZ;
44

55
public class Globals
66
{
7-
public static Dictionary<ulong, bool> VipsFlag = new Dictionary<ulong, bool>();
8-
public static Dictionary<ulong, bool> Gived = new Dictionary<ulong, bool>();
9-
public static Dictionary<ulong, bool> NadeGived = new Dictionary<ulong, bool>();
10-
public static Dictionary<ulong, bool> VipGived = new Dictionary<ulong, bool>();
11-
public static Dictionary<ulong, bool> VipNadeGived = new Dictionary<ulong, bool>();
7+
public static Dictionary<ulong, HashSet<string>> loadoutsGivenPerPlayer = new Dictionary<ulong, HashSet<string>>();
128
public static string SMapName => NativeAPI.GetMapName();
139
}

Config/Helper.cs

Lines changed: 144 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
using CounterStrikeSharp.API.Core;
22
using CounterStrikeSharp.API.Modules.Admin;
33
using CounterStrikeSharp.API;
4+
using Newtonsoft.Json;
5+
using Spawn_Loadout_GoldKingZ.Config;
46

57
namespace Spawn_Loadout_GoldKingZ;
68

79
public class Helper
810
{
11+
public static readonly string[] WeaponsList =
12+
{
13+
"weapon_ak47", "weapon_aug", "weapon_awp", "weapon_bizon", "weapon_cz75a", "weapon_deagle", "weapon_elite", "weapon_famas", "weapon_fiveseven", "weapon_g3sg1", "weapon_galilar",
14+
"weapon_glock", "weapon_hkp2000", "weapon_m249", "weapon_m4a1", "weapon_m4a1_silencer", "weapon_mac10", "weapon_mag7", "weapon_mp5sd", "weapon_mp7", "weapon_mp9", "weapon_negev",
15+
"weapon_nova", "weapon_p250", "weapon_p90", "weapon_revolver", "weapon_sawedoff", "weapon_scar20", "weapon_sg556", "weapon_ssg08", "weapon_tec9", "weapon_ump45", "weapon_usp_silencer", "weapon_xm1014",
16+
"weapon_decoy", "weapon_flashbang", "weapon_hegrenade", "weapon_incgrenade", "weapon_molotov", "weapon_smokegrenade","item_defuser", "item_cutters", "weapon_knife"
17+
};
918
public static bool IsPlayerInGroupPermission(CCSPlayerController player, string groups)
1019
{
1120
var excludedGroups = groups.Split(',');
@@ -27,15 +36,145 @@ public static bool IsPlayerInGroupPermission(CCSPlayerController player, string
2736

2837
public static void ClearVariables()
2938
{
30-
Globals.VipsFlag.Clear();
31-
Globals.Gived.Clear();
32-
Globals.NadeGived.Clear();
33-
Globals.VipGived.Clear();
34-
Globals.VipNadeGived.Clear();
39+
Globals.loadoutsGivenPerPlayer.Clear();
3540
}
3641
public static List<CCSPlayerController> GetAllController()
3742
{
3843
var playerList = Utilities.FindAllEntitiesByDesignerName<CCSPlayerController>("cs_player_controller").Where(p => p != null && p.IsValid && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected).ToList();
3944
return playerList;
4045
}
46+
47+
public static void GiveWeaponsToPlayer(CCSPlayerController player, string weapons)
48+
{
49+
if(player != null && player.IsValid)
50+
{
51+
string[] weaponList = weapons.Split(',');
52+
foreach (var weapon in weaponList)
53+
{
54+
Configs.Shared.CustomFunctions!.PlayerGiveNamedItem(player, weapon);
55+
56+
foreach (var entity in Utilities.FindAllEntitiesByDesignerName<CBaseEntity>(weapon))
57+
{
58+
if (entity.DesignerName != weapon) continue;
59+
if (entity == null) continue;
60+
if (entity.Entity == null) continue;
61+
if (entity.OwnerEntity == null) continue;
62+
if (entity.OwnerEntity.IsValid) continue;
63+
64+
entity.AcceptInput("Kill");
65+
break;
66+
}
67+
}
68+
}
69+
}
70+
71+
public static void ClearGroundWeapons()
72+
{
73+
foreach (string Weapons in WeaponsList)
74+
{
75+
foreach (var entity in Utilities.FindAllEntitiesByDesignerName<CBaseEntity>(Weapons))
76+
{
77+
if (entity == null) continue;
78+
if (entity.Entity == null) continue;
79+
if (entity.OwnerEntity == null) continue;
80+
if(entity.OwnerEntity.IsValid) continue;
81+
82+
entity.AcceptInput("Kill");
83+
}
84+
}
85+
}
86+
87+
public static void DropAllWeapons(CCSPlayerController player)
88+
{
89+
if(player == null || !player.IsValid)return;
90+
if(player.PlayerPawn == null || !player.PlayerPawn.IsValid)return;
91+
if(!player.PawnIsAlive)return;
92+
if(player.PlayerPawn.Value == null || !player.PlayerPawn.Value.IsValid)return;
93+
if(player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.WeaponServices.MyWeapons == null)return;
94+
95+
foreach (var weapon in player.PlayerPawn.Value.WeaponServices.MyWeapons)
96+
{
97+
if (weapon is { IsValid: true, Value.IsValid: true } && !weapon.Value.DesignerName.Contains("weapon_knife"))
98+
{
99+
player.DropActiveWeapon();
100+
101+
weapon.Value.Remove();
102+
}
103+
}
104+
105+
}
106+
public static void CreateDefaultWeaponsJson()
107+
{
108+
if (Configs.Shared.CookiesModule == null) return;
109+
var FolderConfig = Path.Combine(Configs.Shared.CookiesModule, "../../plugins/Spawn-Loadout-GoldKingZ/config/");
110+
var configcfg = Path.Combine(FolderConfig, "weapons.json");
111+
112+
if (!Directory.Exists(FolderConfig) || !File.Exists(configcfg))
113+
{
114+
if (!Directory.Exists(FolderConfig))
115+
{
116+
Directory.CreateDirectory(FolderConfig);
117+
}
118+
119+
var weaponsData = new
120+
{
121+
ANY = new
122+
{
123+
LOADOUT_1 = new
124+
{
125+
FLAGS = "@css/root,@css/admin,@css/vip,#css/admin,#css/vip",
126+
CT = "weapon_taser,weapon_decoy",
127+
T = "weapon_taser,weapon_decoy",
128+
CT_Refill_Nades = "weapon_decoy",
129+
CT_Refill_Time_InSec = 30,
130+
T_Refill_Nades = "weapon_decoy",
131+
T_Refill_Time_InSec = 30
132+
},
133+
LOADOUT_2 = new
134+
{
135+
GiveThisLoadOutPerRoundOnly = true,
136+
CT = "weapon_hkp2000,weapon_knife,weapon_smokegrenade",
137+
T = "weapon_hkp2000,weapon_knife,weapon_smokegrenade"
138+
}
139+
},
140+
hns_ = new
141+
{
142+
LOADOUT_1 = new
143+
{
144+
FLAGS = "@css/root,@css/admin,@css/vip,#css/admin,#css/vip",
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
151+
{
152+
GiveThisLoadOutPerRoundOnly = true,
153+
CT = "weapon_decoy,weapon_knife",
154+
T = "weapon_decoy,weapon_knife"
155+
}
156+
},
157+
awp_lego_2_cs2 = new
158+
{
159+
ForceStripPlayers = true,
160+
DeleteGroundWeapons = true,
161+
LOADOUT_1 = new
162+
{
163+
FLAGS = "@css/root,@css/admin,@css/vip,#css/admin,#css/vip",
164+
CT = "weapon_deagle",
165+
T = "weapon_deagle"
166+
},
167+
LOADOUT_2 = new
168+
{
169+
CT = "weapon_awp,weapon_knife",
170+
T = "weapon_awp,weapon_knife"
171+
}
172+
}
173+
};
174+
175+
var jsonContent = JsonConvert.SerializeObject(weaponsData, Formatting.Indented);
176+
177+
File.WriteAllText(configcfg, jsonContent);
178+
}
179+
}
41180
}

Config/MemoryFunctions.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System.Runtime.InteropServices;
2+
using CounterStrikeSharp.API;
3+
using CounterStrikeSharp.API.Core;
4+
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
5+
6+
namespace Spawn_Loadout_GoldKingZ;
7+
8+
public class CustomGameData
9+
{
10+
private static Dictionary<string, Dictionary<OSPlatform, string>> _customGameData = new()
11+
{
12+
{
13+
"GiveNamedItem2",
14+
new()
15+
{
16+
{
17+
OSPlatform.Linux,
18+
@"\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x53\x48\x83\xEC\x??\x48\x89\x7D\xC8\x48\x85\xF6\x74"
19+
},
20+
{
21+
OSPlatform.Windows,
22+
@"\x48\x83\xEC\x38\x48\xC7\x44\x24\x28\x00\x00\x00\x00\x45\x33\xC9\x45\x33\xC0\xC6\x44\x24\x20\x00\xE8\x??\x??\x??\x??\x48\x85"
23+
}
24+
}
25+
}
26+
};
27+
28+
private readonly MemoryFunctionVoid<IntPtr, string, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr>? GiveNamedItem2;
29+
30+
public CustomGameData()
31+
{
32+
var giveNamedItemData = GetCustomGameDataKey("GiveNamedItem2");
33+
if (giveNamedItemData is not null)
34+
{
35+
GiveNamedItem2 = new(giveNamedItemData);
36+
}
37+
}
38+
39+
private string? GetCustomGameDataKey(string key)
40+
{
41+
if (!_customGameData.TryGetValue(key, out var customGameData))
42+
{
43+
return null;
44+
}
45+
46+
OSPlatform platform;
47+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
48+
{
49+
platform = OSPlatform.Linux;
50+
}
51+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
52+
{
53+
platform = OSPlatform.Windows;
54+
}
55+
else
56+
{
57+
throw new Exception("Unsupported platform");
58+
}
59+
60+
return customGameData.TryGetValue(platform, out var customData) ? customData : null;
61+
}
62+
63+
public void PlayerGiveNamedItem(CCSPlayerController player, string item)
64+
{
65+
if (!player.PlayerPawn.IsValid) return;
66+
if (player.PlayerPawn.Value == null) return;
67+
if (!player.PlayerPawn.Value.IsValid) return;
68+
if (player.PlayerPawn.Value.ItemServices == null) return;
69+
70+
if (GiveNamedItem2 is not null)
71+
{
72+
GiveNamedItem2.Invoke(player.PlayerPawn.Value.ItemServices.Handle, item, 0, 0, 0, 0, 0, 0);
73+
}
74+
else
75+
{
76+
player.GiveNamedItem(item);
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)