Skip to content

Commit 999f788

Browse files
authored
1.0.0
1 parent 98a0555 commit 999f788

File tree

8 files changed

+533
-0
lines changed

8 files changed

+533
-0
lines changed

Config/Configs.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
4+
namespace Spawn_Loadout_GoldKingZ.Config
5+
{
6+
public static class Configs
7+
{
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 GiveOneTimePerRound { get; set; }
81+
public string Vips { get; set; }
82+
public string empty2 { get; set; }
83+
public string Information_For_You_Dont_Delete_it { get; set; }
84+
85+
public ConfigData()
86+
{
87+
GiveOneTimePerRound = false;
88+
Vips = "@css/root,@css/admin,@css/vip,#css/admin,#css/vip";
89+
empty2 = "-----------------------------------------------------------------------------------";
90+
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";
91+
}
92+
}
93+
}
94+
}

CounterStrikeSharp.API.dll

1.4 MB
Binary file not shown.

Helper/Globals.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using CounterStrikeSharp.API.Core;
2+
3+
namespace Spawn_Loadout_GoldKingZ;
4+
5+
public class Globals
6+
{
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 string SMapName => NativeAPI.GetMapName();
10+
}

Helper/Helper.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using CounterStrikeSharp.API.Core;
2+
using CounterStrikeSharp.API.Modules.Admin;
3+
4+
namespace Spawn_Loadout_GoldKingZ;
5+
6+
public class Helper
7+
{
8+
public static bool IsPlayerInGroupPermission(CCSPlayerController player, string groups)
9+
{
10+
var excludedGroups = groups.Split(',');
11+
foreach (var group in excludedGroups)
12+
{
13+
if (group.StartsWith("#"))
14+
{
15+
if (AdminManager.PlayerInGroup(player, group))
16+
return true;
17+
}
18+
else if (group.StartsWith("@"))
19+
{
20+
if (AdminManager.PlayerHasPermissions(player, group))
21+
return true;
22+
}
23+
}
24+
return false;
25+
}
26+
27+
public static void ClearVariables()
28+
{
29+
Globals.Gived.Clear();
30+
Globals.VipsFlag.Clear();
31+
}
32+
}

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\x18\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\x2A\x2A\x2A\x2A\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+
}

Newtonsoft.Json.dll

696 KB
Binary file not shown.

0 commit comments

Comments
 (0)