From e34191c0e4f8b90774e3ca7c8a8bf622a4f075a6 Mon Sep 17 00:00:00 2001 From: Gold KingZ <48490385+oqyh@users.noreply.github.com> Date: Sat, 21 Dec 2024 20:47:15 +0400 Subject: [PATCH 01/10] Add files via upload --- Resources/RetakesAllocator_gamedata.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Resources/RetakesAllocator_gamedata.json diff --git a/Resources/RetakesAllocator_gamedata.json b/Resources/RetakesAllocator_gamedata.json new file mode 100644 index 0000000..a680ca3 --- /dev/null +++ b/Resources/RetakesAllocator_gamedata.json @@ -0,0 +1,9 @@ +{ + "GiveNamedItem2": { + "signatures": { + "library": "server", + "windows": "48 83 EC ? 48 C7 44 24 ? ? ? ? ? 45 33 C9 45 33 C0 C6 44 24 ? ? E8 ? ? ? ? 48 83 C4 ? C3 CC CC CC CC CC CC CC CC CC CC CC CC CC CC 48 83 EC", + "linux": "55 48 89 E5 41 57 41 56 41 55 41 54 53 48 83 EC ? 48 89 7D ? 44 89 45" + } + } +} From 15ef27ee9e33a85bd5f3eb3f05762f526225dc4e Mon Sep 17 00:00:00 2001 From: Gold KingZ <48490385+oqyh@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:00:19 +0400 Subject: [PATCH 02/10] Update Configs.cs --- RetakesAllocatorCore/Config/Configs.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RetakesAllocatorCore/Config/Configs.cs b/RetakesAllocatorCore/Config/Configs.cs index f40ce2f..9314897 100644 --- a/RetakesAllocatorCore/Config/Configs.cs +++ b/RetakesAllocatorCore/Config/Configs.cs @@ -8,6 +8,10 @@ namespace RetakesAllocatorCore.Config; public static class Configs { + public static class Shared + { + public static string? Module { get; set; } + } private static readonly string ConfigDirectoryName = "config"; private static readonly string ConfigFileName = "config.json"; @@ -270,6 +274,7 @@ public Dictionary< public DatabaseProvider DatabaseProvider { get; set; } = DatabaseProvider.Sqlite; public string DatabaseConnectionString { get; set; } = "Data Source=data.db; Pooling=False"; + public bool AutoUpdateSignatures { get; set; } = true; public IList Validate() { From 59d4f7af120b6bd027cefb73de8de1143a9fdc0e Mon Sep 17 00:00:00 2001 From: Gold KingZ <48490385+oqyh@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:01:39 +0400 Subject: [PATCH 03/10] Update CustomGameData.cs From 980633817ca8128212d834a8c49bde4ace046239 Mon Sep 17 00:00:00 2001 From: Gold KingZ <48490385+oqyh@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:01:52 +0400 Subject: [PATCH 04/10] Update RetakesAllocator.cs --- RetakesAllocator/RetakesAllocator.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/RetakesAllocator/RetakesAllocator.cs b/RetakesAllocator/RetakesAllocator.cs index f731006..19b4e31 100644 --- a/RetakesAllocator/RetakesAllocator.cs +++ b/RetakesAllocator/RetakesAllocator.cs @@ -49,6 +49,8 @@ public class RetakesAllocator : BasePlugin public override void Load(bool hotReload) { + Configs.Shared.Module = ModuleDirectory; + Log.Debug($"Loaded. Hot reload: {hotReload}"); ResetState(); Batteries.Init(); @@ -60,6 +62,11 @@ public override void Load(bool hotReload) RoundTypeManager.Instance.SetMap(mapName); }); + _ = Task.Run(async () => + { + await Helpers.DownloadMissingFiles(); + }); + if (Configs.GetConfigData().UseOnTickFeatures) { RegisterListener(OnTick); @@ -987,4 +994,4 @@ private void GiveDefuseKit(CCSPlayerController player) } #endregion -} \ No newline at end of file +} From b8de60381105cba3aff1eaa2308107aa4157f42f Mon Sep 17 00:00:00 2001 From: Gold KingZ <48490385+oqyh@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:02:13 +0400 Subject: [PATCH 05/10] Update PluginInfo.cs --- RetakesAllocatorCore/PluginInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RetakesAllocatorCore/PluginInfo.cs b/RetakesAllocatorCore/PluginInfo.cs index f53c7ad..f678887 100644 --- a/RetakesAllocatorCore/PluginInfo.cs +++ b/RetakesAllocatorCore/PluginInfo.cs @@ -5,7 +5,7 @@ namespace RetakesAllocatorCore; public static class PluginInfo { - public const string Version = "2.3.19"; + public const string Version = "2.4.0"; public static readonly string LogPrefix = $"[RetakesAllocator {Version}] "; From ec6599f3f1620e1ab5409ee8b0f6c72a7d6271cb Mon Sep 17 00:00:00 2001 From: Gold KingZ <48490385+oqyh@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:02:26 +0400 Subject: [PATCH 06/10] Update Helpers.cs --- RetakesAllocator/Helpers.cs | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/RetakesAllocator/Helpers.cs b/RetakesAllocator/Helpers.cs index 0f077f9..cf6b530 100644 --- a/RetakesAllocator/Helpers.cs +++ b/RetakesAllocator/Helpers.cs @@ -5,6 +5,7 @@ using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Entities.Constants; using CounterStrikeSharp.API.Modules.Utils; +using RetakesAllocatorCore.Config; using RetakesAllocatorCore; namespace RetakesAllocator; @@ -201,4 +202,91 @@ public static bool IsWindows() } public static bool IsVip(CCSPlayerController player) => AdminManager.PlayerHasPermissions(player, "@css/vip"); + + public static async Task DownloadMissingFiles() + { + string baseFolderPath = Configs.Shared.Module!; + + string gamedataFileName = "gamedata/RetakesAllocator_gamedata.json"; + string gamedataGithubUrl = "https://raw.githubusercontent.com/oqyh/cs2-retakes-allocator/main/Resources/RetakesAllocator_gamedata.json"; + string gamedataFilePath = Path.Combine(baseFolderPath, gamedataFileName); + string gamedataDirectoryPath = Path.GetDirectoryName(gamedataFilePath)!; + await CheckAndDownloadFile(gamedataFilePath, gamedataGithubUrl, gamedataDirectoryPath); + } + + public static async Task CheckAndDownloadFile(string filePath, string githubUrl, string directoryPath) + { + if (!File.Exists(filePath)) + { + if (!Directory.Exists(directoryPath)) + { + Directory.CreateDirectory(directoryPath); + } + await DownloadFileFromGithub(githubUrl, filePath); + return true; + } + else + { + if (Configs.GetConfigData().AutoUpdateSignatures) + { + bool isFileDifferent = await IsFileDifferent(filePath, githubUrl); + if (isFileDifferent) + { + File.Delete(filePath); + await DownloadFileFromGithub(githubUrl, filePath); + return true; + } + } + + } + + return false; + } + + + public static async Task IsFileDifferent(string localFilePath, string githubUrl) + { + try + { + byte[] localFileBytes = await File.ReadAllBytesAsync(localFilePath); + string localFileHash = GetFileHash(localFileBytes); + + using (HttpClient client = new HttpClient()) + { + byte[] githubFileBytes = await client.GetByteArrayAsync(githubUrl); + string githubFileHash = GetFileHash(githubFileBytes); + return localFileHash != githubFileHash; + } + } + catch (Exception ex) + { + Log.Debug($"Error comparing files: {ex.Message}"); + return false; + } + } + + public static string GetFileHash(byte[] fileBytes) + { + using (var md5 = System.Security.Cryptography.MD5.Create()) + { + byte[] hashBytes = md5.ComputeHash(fileBytes); + return BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant(); + } + } + + public static async Task DownloadFileFromGithub(string url, string destinationPath) + { + using (HttpClient client = new HttpClient()) + { + try + { + byte[] fileBytes = await client.GetByteArrayAsync(url); + await File.WriteAllBytesAsync(destinationPath, fileBytes); + } + catch (Exception ex) + { + Log.Debug($"Error downloading file: {ex.Message}"); + } + } + } } From fc5f22cb1ea9addcdf24ff1682cfc237e9d713cc Mon Sep 17 00:00:00 2001 From: Gold KingZ <48490385+oqyh@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:04:02 +0400 Subject: [PATCH 07/10] Update Helpers.cs --- RetakesAllocator/Helpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RetakesAllocator/Helpers.cs b/RetakesAllocator/Helpers.cs index cf6b530..d26c9e2 100644 --- a/RetakesAllocator/Helpers.cs +++ b/RetakesAllocator/Helpers.cs @@ -208,7 +208,7 @@ public static async Task DownloadMissingFiles() string baseFolderPath = Configs.Shared.Module!; string gamedataFileName = "gamedata/RetakesAllocator_gamedata.json"; - string gamedataGithubUrl = "https://raw.githubusercontent.com/oqyh/cs2-retakes-allocator/main/Resources/RetakesAllocator_gamedata.json"; + string gamedataGithubUrl = "https://raw.githubusercontent.com/yonilerner/cs2-retakes-allocator/main/Resources/RetakesAllocator_gamedata.json"; string gamedataFilePath = Path.Combine(baseFolderPath, gamedataFileName); string gamedataDirectoryPath = Path.GetDirectoryName(gamedataFilePath)!; await CheckAndDownloadFile(gamedataFilePath, gamedataGithubUrl, gamedataDirectoryPath); From 44ce812b294da3c1efd1037fd50a2acfb83cb725 Mon Sep 17 00:00:00 2001 From: Gold KingZ <48490385+oqyh@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:13:29 +0400 Subject: [PATCH 08/10] Update CustomGameData.cs --- RetakesAllocator/CustomGameData.cs | 65 +++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/RetakesAllocator/CustomGameData.cs b/RetakesAllocator/CustomGameData.cs index 640ace2..a2ade65 100644 --- a/RetakesAllocator/CustomGameData.cs +++ b/RetakesAllocator/CustomGameData.cs @@ -1,31 +1,16 @@ using System.Runtime.InteropServices; using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; +using RetakesAllocatorCore.Config; +using RetakesAllocatorCore; using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; +using System.Text.Json; namespace RetakesAllocator; public class CustomGameData { - private static Dictionary> _customGameData = new() - { - // Thank you to @Whaliin https://github.com/CS2Plugins/WeaponRestrict/blob/main/WeaponRestrict.json - { - "GiveNamedItem2", - new() - { - { - OSPlatform.Windows, - @"\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" - }, - { - OSPlatform.Linux, - @"\x55\x48\x89\xE5\x41\x57\x41\x56\x4D\x89\xC6\x41\x55\x49\x89\xD5\x41\x54\x49\x89\xF4" - }, - } - } - }; - + public static Dictionary> _customGameData = new(); private readonly MemoryFunctionVoid GiveNamedItem2; public readonly @@ -36,8 +21,50 @@ public readonly public CustomGameData() { + LoadCustomGameDataFromJson(); + GiveNamedItem2 = new(GetCustomGameDataKey("GiveNamedItem2")); } + public void LoadCustomGameDataFromJson() + { + string jsonFilePath = $"{Configs.Shared.Module}/../../plugins/RetakesAllocator/gamedata/RetakesAllocator_gamedata.json"; + if (!File.Exists(jsonFilePath)) + { + Log.Debug($"JSON file does not exist at path: {jsonFilePath}. Returning without loading custom game data."); + return; + } + + try + { + var jsonData = File.ReadAllText(jsonFilePath); + var jsonDocument = JsonDocument.Parse(jsonData); + + foreach (var element in jsonDocument.RootElement.EnumerateObject()) + { + string key = element.Name; + + var platformData = new Dictionary(); + + if (element.Value.TryGetProperty("signatures", out var signatures)) + { + if (signatures.TryGetProperty("windows", out var windows)) + { + platformData[OSPlatform.Windows] = windows.GetString()!; + } + + if (signatures.TryGetProperty("linux", out var linux)) + { + platformData[OSPlatform.Linux] = linux.GetString()!; + } + } + _customGameData[key] = platformData; + } + } + catch (Exception ex) + { + Log.Debug($"Error loading custom game data: {ex.Message}"); + } + } private string GetCustomGameDataKey(string key) { From a2bdb351b0aa659101d56c4d107c5e9f8c44983f Mon Sep 17 00:00:00 2001 From: Gold KingZ <48490385+oqyh@users.noreply.github.com> Date: Sun, 22 Dec 2024 02:19:26 +0400 Subject: [PATCH 09/10] Update RetakesAllocator.cs --- RetakesAllocator/RetakesAllocator.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/RetakesAllocator/RetakesAllocator.cs b/RetakesAllocator/RetakesAllocator.cs index 19b4e31..720dbff 100644 --- a/RetakesAllocator/RetakesAllocator.cs +++ b/RetakesAllocator/RetakesAllocator.cs @@ -956,7 +956,14 @@ private void AllocateItemsForPlayer(CCSPlayerController player, ICollection Date: Sun, 22 Dec 2024 02:19:44 +0400 Subject: [PATCH 10/10] Update Configs.cs --- RetakesAllocatorCore/Config/Configs.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/RetakesAllocatorCore/Config/Configs.cs b/RetakesAllocatorCore/Config/Configs.cs index 9314897..40f3aa5 100644 --- a/RetakesAllocatorCore/Config/Configs.cs +++ b/RetakesAllocatorCore/Config/Configs.cs @@ -233,6 +233,7 @@ public Dictionary< public bool ResetStateOnGameRestart { get; set; } = true; public bool AllowAllocationAfterFreezeTime { get; set; } = true; public bool UseOnTickFeatures { get; set; } = true; + public bool CapabilityWeaponPaints { get; set; } = true; public bool EnableRoundTypeAnnouncement { get; set; } = true; public bool EnableRoundTypeAnnouncementCenter { get; set; } = false; public bool EnableBombSiteAnnouncementCenter { get; set; } = false;