Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit 93313c1

Browse files
committed
fix: The default weapons are now customizable
1 parent a807e9a commit 93313c1

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
-- 2024.04.13 - 1.3.4
2+
3+
- fix: Possible fix for GiveNamedItem2 problems on some servers
4+
- fix: The default weapons are now customizable
5+
6+
17
-- 2024.04.11 - 1.3.3
28

39
- fix: Remove HLTV from queues(?)

src-plugin/Plugin/Models/ArenaPlayerModel.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,12 @@ public void ShowWeaponSubPreferenceMenu(WeaponType weaponType)
214214
MenuManager.OpenChatMenu(Controller, primaryPreferenceMenu);
215215
}
216216

217-
public static MemoryFunctionVoid<IntPtr, string, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr> GiveNamedItem2Linux = new(@"\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");
218-
public static MemoryFunctionVoid<IntPtr, string, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr> GiveNamedItem2Windows = new(@"\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");
219217
public void PlayerGiveNamedItem(CCSPlayerController player, CsItem item)
220218
{
221219
if (!player.PlayerPawn.IsValid || player.PlayerPawn.Value == null || !player.PlayerPawn.Value.IsValid || player.PlayerPawn.Value.ItemServices == null)
222220
return;
223221

224-
var GiveNamedItem2 = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? GiveNamedItem2Linux : RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? GiveNamedItem2Windows : null;
225-
226-
if (!Plugin.Config.CompatibilitySettings.MetamodSkinchanger || GiveNamedItem2 is null)
222+
if (!Plugin.Config.CompatibilitySettings.MetamodSkinchanger || Plugin.GiveNamedItem2 is null)
227223
{
228224
player.GiveNamedItem(item);
229225
return;
@@ -236,7 +232,7 @@ public void PlayerGiveNamedItem(CCSPlayerController player, CsItem item)
236232

237233
try
238234
{
239-
GiveNamedItem2.Invoke(player.PlayerPawn.Value.ItemServices.Handle, itemName, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
235+
Plugin.GiveNamedItem2.Invoke(player.PlayerPawn.Value.ItemServices.Handle, itemName, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
240236
}
241237
catch (Exception e)
242238
{

src-plugin/Plugin/PluginConfig.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ public sealed class PluginConfig : BasePluginConfig
132132
[JsonPropertyName("compatibility-settings")]
133133
public CompatibilitySettings CompatibilitySettings { get; set; } = new CompatibilitySettings();
134134

135+
[JsonPropertyName("default-weapon-settings")]
136+
public DefaultWeaponSettings DefaultWeaponSettings { get; set; } = new DefaultWeaponSettings();
137+
135138
[JsonPropertyName("ConfigVersion")]
136139
public override int Version { get; set; } = 1;
137140
}
@@ -196,6 +199,27 @@ public sealed class CommandSettings
196199
};
197200
}
198201

202+
public sealed class DefaultWeaponSettings
203+
{
204+
[JsonPropertyName("default-rifle")]
205+
public int? DefaultRifle { get; set; } = null;
206+
207+
[JsonPropertyName("default-sniper")]
208+
public int? DefaultSniper { get; set; } = null;
209+
210+
[JsonPropertyName("default-smg")]
211+
public int? DefaultSMG { get; set; } = null;
212+
213+
[JsonPropertyName("default-lmg")]
214+
public int? DefaultLMG { get; set; } = null;
215+
216+
[JsonPropertyName("default-shotgun")]
217+
public int? DefaultShotgun { get; set; } = null;
218+
219+
[JsonPropertyName("default-pistol")]
220+
public int? DefaultPistol { get; set; } = null;
221+
}
222+
199223
public sealed class DatabaseSettings
200224
{
201225
[JsonPropertyName("host")]

src-plugin/Plugin/PluginDatabase.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ public async Task LoadPlayerAsync(ulong SteamID)
5252
{
5353
string tablePrefix = Config.DatabaseSettings.TablePrefix;
5454

55+
DefaultWeaponSettings dws = Config.DefaultWeaponSettings;
56+
5557
string sqlInsertOrUpdate = $@"
56-
INSERT INTO `{tablePrefix}k4-arenas` (`steamid64`, `lastseen`, `rounds`)
57-
VALUES (@SteamID, CURRENT_TIMESTAMP, @Rounds)
58-
ON DUPLICATE KEY UPDATE `lastseen` = CURRENT_TIMESTAMP;";
58+
INSERT INTO `{tablePrefix}k4-arenas` (`steamid64`, `lastseen`, `rifle`, `sniper`, `shotgun`, `smg`, `lmg`, `pistol`, `rounds`)
59+
VALUES (@SteamID, CURRENT_TIMESTAMP, {dws.DefaultRifle}, {dws.DefaultRifle}, {dws.DefaultShotgun}, {dws.DefaultSMG}, {dws.DefaultLMG}, {dws.DefaultPistol}, @Rounds)
60+
ON DUPLICATE KEY UPDATE `lastseen` = CURRENT_TIMESTAMP;";
5961

6062
string sqlSelect = $@"
61-
SELECT `rifle`, `sniper`, `shotgun`, `smg`, `lmg`, `pistol`, `rounds`
62-
FROM `{tablePrefix}k4-arenas` WHERE `steamid64` = @SteamID;";
63+
SELECT `rifle`, `sniper`, `shotgun`, `smg`, `lmg`, `pistol`, `rounds`
64+
FROM `{tablePrefix}k4-arenas` WHERE `steamid64` = @SteamID;";
6365

6466
using MySqlConnection connection = CreateConnection(Config);
6567
await connection.OpenAsync();

0 commit comments

Comments
 (0)