mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 10:43:22 +00:00
Compare commits
129 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d83783b7af | ||
|
|
8e7b4a2d40 | ||
|
|
e0fce7a4b4 | ||
|
|
8f0e8a0a63 | ||
|
|
eb6cdfc98d | ||
|
|
56537971ad | ||
|
|
43e7a3183e | ||
|
|
60c592aa54 | ||
|
|
2568f263d9 | ||
|
|
14e285d44f | ||
|
|
97b8840ac4 | ||
|
|
f820c7d251 | ||
|
|
6e5d595c0f | ||
|
|
71d57eb3ad | ||
|
|
620b067991 | ||
|
|
89c425c170 | ||
|
|
c744f2898b | ||
|
|
d04bc0879a | ||
|
|
4417b093dd | ||
|
|
3f8533ab94 | ||
|
|
55905ccc33 | ||
|
|
24fcfa0222 | ||
|
|
cd059c6bfb | ||
|
|
e338bebaec | ||
|
|
efd7f5dbef | ||
|
|
6bd002cdec | ||
|
|
3a1adf8d4a | ||
|
|
7c3fa6469b | ||
|
|
52962518fe | ||
|
|
7e12b89a9e | ||
|
|
ae56b18a3c | ||
|
|
c907911cd1 | ||
|
|
1aa486cd7d | ||
|
|
5e62c7c597 | ||
|
|
819ac6233c | ||
|
|
ed24eb0dfc | ||
|
|
1a9f7ad108 | ||
|
|
6f1a29bb39 | ||
|
|
9e64cdcd43 | ||
|
|
da86756092 | ||
|
|
22880070cd | ||
|
|
208cbe1aef | ||
|
|
c0cf9210dc | ||
|
|
5f61254b4e | ||
|
|
6cd1bb3bf5 | ||
|
|
4f94b831c2 | ||
|
|
969d40b970 | ||
|
|
0cd36a7877 | ||
|
|
a3306b5f8f | ||
|
|
379c2f797c | ||
|
|
7f41607d54 | ||
|
|
fc42190701 | ||
|
|
928c1e1466 | ||
|
|
78649f5dcf | ||
|
|
4e72f10326 | ||
|
|
3ddbf7e11e | ||
|
|
ee770fd8c2 | ||
|
|
72c5df53b5 | ||
|
|
d0ed0f4c0b | ||
|
|
643beaad46 | ||
|
|
6d44e582be | ||
|
|
813a9abcc8 | ||
|
|
b0790729be | ||
|
|
74a6dff114 | ||
|
|
e37f111f1b | ||
|
|
5e6286b667 | ||
|
|
ed4da98a50 | ||
|
|
c825febeac | ||
|
|
1e5c2a439f | ||
|
|
21eccfb6d9 | ||
|
|
a6b193cd13 | ||
|
|
b992433d44 | ||
|
|
06559af230 | ||
|
|
dfe6b200d8 | ||
|
|
3edcb5e52f | ||
|
|
28936e9bb5 | ||
|
|
2772fb59b9 | ||
|
|
0f6bb26ac9 | ||
|
|
be51e4d1e9 | ||
|
|
0d521e0cd3 | ||
|
|
00f920713d | ||
|
|
42d70690eb | ||
|
|
73e3a05270 | ||
|
|
dd9e01db54 | ||
|
|
393281ea12 | ||
|
|
a5787d95e0 | ||
|
|
6a7b15e942 | ||
|
|
8e7a2a2923 | ||
|
|
93e8af07d2 | ||
|
|
7e5485b209 | ||
|
|
414818e314 | ||
|
|
a42e9a37fc | ||
|
|
dcd68aed67 | ||
|
|
7bb97af619 | ||
|
|
cdc58df13c | ||
|
|
fe5cc9a82a | ||
|
|
01542a7dc6 | ||
|
|
a8cf33d404 | ||
|
|
e1f24abd5d | ||
|
|
646050fb72 | ||
|
|
87dadb9c62 | ||
|
|
cf421c5614 | ||
|
|
fc64e1d261 | ||
|
|
1c026c018e | ||
|
|
45fc4a86a5 | ||
|
|
ad105e5cd2 | ||
|
|
f668f56d66 | ||
|
|
de6672507a | ||
|
|
4a410fd0d8 | ||
|
|
bb08e88371 | ||
|
|
2855d4e9ae | ||
|
|
0c05c25e8e | ||
|
|
8335ede7d7 | ||
|
|
d79246f161 | ||
|
|
a504506129 | ||
|
|
7bada81eb9 | ||
|
|
2929735429 | ||
|
|
04bb7a2575 | ||
|
|
f00ba48f60 | ||
|
|
08342e4a99 | ||
|
|
29a6041d7a | ||
|
|
c44433766c | ||
|
|
a987ed972a | ||
|
|
50777661c5 | ||
|
|
31fd014f55 | ||
|
|
760429e644 | ||
|
|
304d8501cc | ||
|
|
e9f7db5171 | ||
|
|
648b928b4e |
11
.github/workflows/build.yml
vendored
11
.github/workflows/build.yml
vendored
@@ -3,8 +3,16 @@ name: Build
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
|
paths-ignore:
|
||||||
|
- '**/README.md'
|
||||||
|
- '**/.gitignore'
|
||||||
|
- '**/LICENSE'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
|
paths-ignore:
|
||||||
|
- '**/README.md'
|
||||||
|
- '**/.gitignore'
|
||||||
|
- '**/LICENSE'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
BUILD_NUMBER: ${{ github.run_number }}
|
BUILD_NUMBER: ${{ github.run_number }}
|
||||||
@@ -12,7 +20,6 @@ env:
|
|||||||
PROJECT_NAME: "WeaponPaints"
|
PROJECT_NAME: "WeaponPaints"
|
||||||
OUTPUT_PATH: "./WeaponPaints"
|
OUTPUT_PATH: "./WeaponPaints"
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
permissions: write-all
|
permissions: write-all
|
||||||
@@ -51,6 +58,8 @@ jobs:
|
|||||||
${{ env.OUTPUT_PATH }}/McMaster.NETCore.Plugins.dll \
|
${{ env.OUTPUT_PATH }}/McMaster.NETCore.Plugins.dll \
|
||||||
${{ env.OUTPUT_PATH }}/Microsoft.DotNet.PlatformAbstractions.dll \
|
${{ env.OUTPUT_PATH }}/Microsoft.DotNet.PlatformAbstractions.dll \
|
||||||
${{ env.OUTPUT_PATH }}/Microsoft.Extensions.DependencyModel.dll \
|
${{ env.OUTPUT_PATH }}/Microsoft.Extensions.DependencyModel.dll \
|
||||||
|
- name: Copy skins.json
|
||||||
|
run: cp website/data/skins.json ${{ env.OUTPUT_PATH }}/skins.json
|
||||||
- name: Zip
|
- name: Zip
|
||||||
uses: thedoctor0/zip-release@0.7.5
|
uses: thedoctor0/zip-release@0.7.5
|
||||||
with:
|
with:
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
.vs/
|
.vs/
|
||||||
bin/
|
bin/
|
||||||
obj/
|
obj/
|
||||||
|
.test/
|
||||||
|
|||||||
293
Commands.cs
Normal file
293
Commands.cs
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
|
using CounterStrikeSharp.API.Modules.Menu;
|
||||||
|
|
||||||
|
namespace WeaponPaints
|
||||||
|
{
|
||||||
|
public partial class WeaponPaints
|
||||||
|
{
|
||||||
|
private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
||||||
|
{
|
||||||
|
if (!Config.AdditionalSetting.CommandWpEnabled || !Config.AdditionalSetting.SkinEnabled || !g_bCommandsAllowed) return;
|
||||||
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
if (player == null || !player.IsValid || player.UserId == null || player.Index <= 0 || player.IsBot) return;
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player?.AuthorizedSteamID?.SteamId64,
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!commandsCooldown.TryGetValue((int)player!.UserId, out DateTime cooldownEndTime) ||
|
||||||
|
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
|
{
|
||||||
|
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
|
if (weaponSync != null)
|
||||||
|
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||||
|
if (Config.AdditionalSetting.KnifeEnabled)
|
||||||
|
{
|
||||||
|
if (weaponSync != null)
|
||||||
|
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo));
|
||||||
|
|
||||||
|
RefreshWeapons(player);
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_command_refresh_done"]))
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_command_refresh_done"]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_command_cooldown"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||||
|
{
|
||||||
|
if (!Config.AdditionalSetting.SkinEnabled) return;
|
||||||
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_info_website"]))
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_info_website", Config.Website]);
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_info_refresh"]))
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_info_refresh"]);
|
||||||
|
}
|
||||||
|
if (!Config.AdditionalSetting.KnifeEnabled) return;
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_info_knife"]))
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_info_knife"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RegisterCommands()
|
||||||
|
{
|
||||||
|
AddCommand($"css_{Config.AdditionalSetting.CommandSkin}", "Skins info", (player, info) =>
|
||||||
|
{
|
||||||
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
OnCommandWS(player, info);
|
||||||
|
});
|
||||||
|
AddCommand($"css_{Config.AdditionalSetting.CommandRefresh}", "Skins refresh", (player, info) =>
|
||||||
|
{
|
||||||
|
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||||
|
OnCommandRefresh(player, info);
|
||||||
|
});
|
||||||
|
if (Config.AdditionalSetting.CommandKillEnabled)
|
||||||
|
{
|
||||||
|
AddCommand($"css_{Config.AdditionalSetting.CommandKill}", "kill yourself", (player, info) =>
|
||||||
|
{
|
||||||
|
if (player == null || !Utility.IsPlayerValid(player) || player.PlayerPawn.Value == null || !player!.PlayerPawn.IsValid) return;
|
||||||
|
|
||||||
|
player.PlayerPawn.Value.CommitSuicide(true, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupKnifeMenu()
|
||||||
|
{
|
||||||
|
if (!Config.AdditionalSetting.KnifeEnabled || !g_bCommandsAllowed) return;
|
||||||
|
|
||||||
|
var knivesOnly = weaponList
|
||||||
|
.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet"))
|
||||||
|
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||||
|
|
||||||
|
var giveItemMenu = new ChatMenu(Localizer["wp_knife_menu_title"]);
|
||||||
|
var handleGive = (CCSPlayerController? player, ChatMenuOption option) =>
|
||||||
|
{
|
||||||
|
if (Utility.IsPlayerValid(player))
|
||||||
|
{
|
||||||
|
if (player == null) return;
|
||||||
|
var knifeName = option.Text;
|
||||||
|
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
||||||
|
if (!string.IsNullOrEmpty(knifeKey))
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_select"]))
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_knife_menu_select", knifeName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.AdditionalSetting.CommandKillEnabled)
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_knife_menu_kill"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player?.AuthorizedSteamID?.SteamId64,
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
g_playersKnife[(int)player!.Index] = knifeKey;
|
||||||
|
|
||||||
|
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
||||||
|
{
|
||||||
|
RefreshWeapons(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (weaponSync != null)
|
||||||
|
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
foreach (var knifePair in knivesOnly)
|
||||||
|
{
|
||||||
|
giveItemMenu.AddMenuOption(knifePair.Value, handleGive);
|
||||||
|
}
|
||||||
|
AddCommand($"css_{Config.AdditionalSetting.CommandKnife}", "Knife Menu", (player, info) =>
|
||||||
|
{
|
||||||
|
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||||
|
|
||||||
|
if (player == null || player.UserId == null) return;
|
||||||
|
|
||||||
|
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
||||||
|
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
|
{
|
||||||
|
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
|
ChatMenus.OpenMenu(player, giveItemMenu);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_command_cooldown"]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupSkinsMenu()
|
||||||
|
{
|
||||||
|
var classNamesByWeapon = weaponList.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
|
||||||
|
var weaponSelectionMenu = new ChatMenu(Localizer["wp_skin_menu_weapon_title"]);
|
||||||
|
|
||||||
|
// Function to handle skin selection for a specific weapon
|
||||||
|
var handleWeaponSelection = (CCSPlayerController? player, ChatMenuOption option) =>
|
||||||
|
{
|
||||||
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
|
int playerIndex = (int)player!.Index;
|
||||||
|
string selectedWeapon = option.Text;
|
||||||
|
if (classNamesByWeapon.TryGetValue(selectedWeapon, out string? selectedWeaponClassname))
|
||||||
|
{
|
||||||
|
if (selectedWeaponClassname == null) return;
|
||||||
|
var skinsForSelectedWeapon = skinsList?.Where(skin =>
|
||||||
|
skin != null &&
|
||||||
|
skin.TryGetValue("weapon_name", out var weaponName) &&
|
||||||
|
weaponName?.ToString() == selectedWeaponClassname
|
||||||
|
)?.ToList();
|
||||||
|
|
||||||
|
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
|
||||||
|
|
||||||
|
// Function to handle skin selection for the chosen weapon
|
||||||
|
var handleSkinSelection = (CCSPlayerController? p, ChatMenuOption opt) =>
|
||||||
|
{
|
||||||
|
if (p == null || !p.IsValid || p.Index <= 0) return;
|
||||||
|
|
||||||
|
playerIndex = (int)p.Index;
|
||||||
|
|
||||||
|
if (p.AuthorizedSteamID == null) return;
|
||||||
|
|
||||||
|
string steamId = p.AuthorizedSteamID.SteamId64.ToString();
|
||||||
|
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
||||||
|
{
|
||||||
|
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
|
||||||
|
{
|
||||||
|
return weaponName?.ToString() == selectedWeaponClassname;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
string selectedSkin = opt.Text;
|
||||||
|
string selectedPaintID = selectedSkin.Split('(')[1].Trim(')').Trim();
|
||||||
|
|
||||||
|
if (firstSkin != null &&
|
||||||
|
firstSkin.TryGetValue("weapon_defindex", out var weaponDefIndexObj) &&
|
||||||
|
weaponDefIndexObj != null &&
|
||||||
|
ushort.TryParse(weaponDefIndexObj.ToString(), out var weaponDefIndex) &&
|
||||||
|
ushort.TryParse(selectedPaintID, out var paintID))
|
||||||
|
{
|
||||||
|
p!.Print(Localizer["wp_skin_menu_select", selectedSkin]);
|
||||||
|
|
||||||
|
if (!gPlayerWeaponsInfo[playerIndex].TryGetValue(weaponDefIndex, out _))
|
||||||
|
{
|
||||||
|
gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = new WeaponInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
|
||||||
|
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.00001f;
|
||||||
|
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Seed = 0;
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player?.AuthorizedSteamID?.SteamId64,
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!Config.GlobalShare)
|
||||||
|
{
|
||||||
|
if (weaponSync != null)
|
||||||
|
Task.Run(async () => await weaponSync.SyncWeaponPaintToDatabase(playerInfo, weaponDefIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add skin options to the submenu for the selected weapon
|
||||||
|
if (skinsForSelectedWeapon != null)
|
||||||
|
{
|
||||||
|
foreach (var skin in skinsForSelectedWeapon.Where(s => s != null))
|
||||||
|
{
|
||||||
|
if (skin.TryGetValue("paint_name", out var paintNameObj) && skin.TryGetValue("paint", out var paintObj))
|
||||||
|
{
|
||||||
|
var paintName = paintNameObj?.ToString();
|
||||||
|
var paint = paintObj?.ToString();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(paintName) && !string.IsNullOrEmpty(paint))
|
||||||
|
{
|
||||||
|
skinSubMenu.AddMenuOption($"{paintName} ({paint})", handleSkinSelection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open the submenu for skin selection of the chosen weapon
|
||||||
|
ChatMenus.OpenMenu(player, skinSubMenu);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add weapon options to the weapon selection menu
|
||||||
|
foreach (var weaponClass in weaponList.Keys)
|
||||||
|
{
|
||||||
|
string weaponName = weaponList[weaponClass];
|
||||||
|
weaponSelectionMenu.AddMenuOption(weaponName, handleWeaponSelection);
|
||||||
|
}
|
||||||
|
// Command to open the weapon selection menu for players
|
||||||
|
AddCommand($"css_{Config.AdditionalSetting.CommandSkinSelection}", "Skins selection menu", (player, info) =>
|
||||||
|
{
|
||||||
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
|
if (player == null || player.UserId == null) return;
|
||||||
|
|
||||||
|
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
||||||
|
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
|
{
|
||||||
|
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
|
ChatMenus.OpenMenu(player, weaponSelectionMenu);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_command_cooldown"]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
Config.cs
51
Config.cs
@@ -3,29 +3,13 @@ using System.Text.Json.Serialization;
|
|||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
public class Messages
|
public class AdditionalSetting
|
||||||
{
|
{
|
||||||
[JsonPropertyName("WebsiteMessageCommand")]
|
|
||||||
public string WebsiteMessageCommand { get; set; } = "Visit {WEBSITE} where you can change skins.";
|
[JsonPropertyName("UseMetamodAlwaysLegacyModel")]
|
||||||
[JsonPropertyName("SynchronizeMessageCommand")]
|
public bool UseMetamodAlwaysLegacyModel { get; set; } = false;
|
||||||
public string SynchronizeMessageCommand { get; set; } = "Type !wp to synchronize chosen skins.";
|
|
||||||
[JsonPropertyName("KnifeMessageCommand")]
|
|
||||||
public string KnifeMessageCommand { get; set; } = "Type !knife to open knife menu.";
|
|
||||||
[JsonPropertyName("CooldownRefreshCommand")]
|
|
||||||
public string CooldownRefreshCommand { get; set; } = "You can't refresh weapon paints right now.";
|
|
||||||
[JsonPropertyName("SuccessRefreshCommand")]
|
|
||||||
public string SuccessRefreshCommand { get; set; } = "Refreshing weapon paints.";
|
|
||||||
[JsonPropertyName("ChosenKnifeMenu")]
|
|
||||||
public string ChosenKnifeMenu { get; set; } = "You have chosen {KNIFE} as your knife.";
|
|
||||||
[JsonPropertyName("ChosenKnifeMenuKill")]
|
|
||||||
public string ChosenKnifeMenuKill { get; set; } = "To correctly apply skin for knife, you need to type !kill.";
|
|
||||||
[JsonPropertyName("KnifeMenuTitle")]
|
|
||||||
public string KnifeMenuTitle { get; set; } = "Knife Menu.";
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Additional
|
[JsonPropertyName("SkinVisibilityFix")]
|
||||||
{
|
|
||||||
[JsonPropertyName("SkinVisibilityFix")]
|
|
||||||
public bool SkinVisibilityFix { get; set; } = true;
|
public bool SkinVisibilityFix { get; set; } = true;
|
||||||
|
|
||||||
[JsonPropertyName("KnifeEnabled")]
|
[JsonPropertyName("KnifeEnabled")]
|
||||||
@@ -34,7 +18,13 @@ namespace WeaponPaints
|
|||||||
[JsonPropertyName("SkinEnabled")]
|
[JsonPropertyName("SkinEnabled")]
|
||||||
public bool SkinEnabled { get; set; } = true;
|
public bool SkinEnabled { get; set; } = true;
|
||||||
|
|
||||||
[JsonPropertyName("CommandWpEnabled")]
|
[JsonPropertyName("MusicKitEnabled")]
|
||||||
|
public bool MusicKitEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
[JsonPropertyName("NameTagEnabled")]
|
||||||
|
public bool NameTagEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
[JsonPropertyName("CommandWpEnabled")]
|
||||||
public bool CommandWpEnabled { get; set; } = true;
|
public bool CommandWpEnabled { get; set; } = true;
|
||||||
|
|
||||||
[JsonPropertyName("CommandKillEnabled")]
|
[JsonPropertyName("CommandKillEnabled")]
|
||||||
@@ -46,6 +36,9 @@ namespace WeaponPaints
|
|||||||
[JsonPropertyName("CommandSkin")]
|
[JsonPropertyName("CommandSkin")]
|
||||||
public string CommandSkin { get; set; } = "ws";
|
public string CommandSkin { get; set; } = "ws";
|
||||||
|
|
||||||
|
[JsonPropertyName("CommandSkinSelection")]
|
||||||
|
public string CommandSkinSelection { get; set; } = "skins";
|
||||||
|
|
||||||
[JsonPropertyName("CommandRefresh")]
|
[JsonPropertyName("CommandRefresh")]
|
||||||
public string CommandRefresh { get; set; } = "wp";
|
public string CommandRefresh { get; set; } = "wp";
|
||||||
|
|
||||||
@@ -54,11 +47,16 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
[JsonPropertyName("GiveRandomKnife")]
|
[JsonPropertyName("GiveRandomKnife")]
|
||||||
public bool GiveRandomKnife { get; set; } = false;
|
public bool GiveRandomKnife { get; set; } = false;
|
||||||
|
|
||||||
|
[JsonPropertyName("GiveRandomSkin")]
|
||||||
|
public bool GiveRandomSkin { get; set; } = false;
|
||||||
|
[JsonPropertyName("GiveKnifeAfterRemove")]
|
||||||
|
public bool GiveKnifeAfterRemove { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WeaponPaintsConfig : BasePluginConfig
|
public class WeaponPaintsConfig : BasePluginConfig
|
||||||
{
|
{
|
||||||
public override int Version { get; set; } = 4;
|
public override int Version { get; set; } = 5;
|
||||||
|
|
||||||
[JsonPropertyName("DatabaseHost")]
|
[JsonPropertyName("DatabaseHost")]
|
||||||
public string DatabaseHost { get; set; } = "";
|
public string DatabaseHost { get; set; } = "";
|
||||||
@@ -87,11 +85,8 @@ namespace WeaponPaints
|
|||||||
[JsonPropertyName("Website")]
|
[JsonPropertyName("Website")]
|
||||||
public string Website { get; set; } = "example.com/skins";
|
public string Website { get; set; } = "example.com/skins";
|
||||||
|
|
||||||
[JsonPropertyName("Messages")]
|
[JsonPropertyName("AdditionalSetting")]
|
||||||
public Messages Messages { get; set; } = new Messages();
|
public AdditionalSetting AdditionalSetting { get; set; } = new AdditionalSetting();
|
||||||
|
|
||||||
[JsonPropertyName("Additional")]
|
|
||||||
public Additional Additional { get; set; } = new Additional();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
353
Events.cs
Normal file
353
Events.cs
Normal file
@@ -0,0 +1,353 @@
|
|||||||
|
using CounterStrikeSharp.API;
|
||||||
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
|
namespace WeaponPaints
|
||||||
|
{
|
||||||
|
public partial class WeaponPaints
|
||||||
|
{
|
||||||
|
private void OnClientPutInServer(int playerSlot)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player.SteamID,
|
||||||
|
Name = player.PlayerName,
|
||||||
|
IpAddress = player.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null) return;
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await weaponSync.GetPlayerDatabaseIndex(playerInfo);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnClientDisconnect(int playerSlot)
|
||||||
|
{
|
||||||
|
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.UserId == null) return;
|
||||||
|
|
||||||
|
g_playersDatabaseIndex.TryRemove((int)player.Index, out _);
|
||||||
|
if (Config.AdditionalSetting.KnifeEnabled)
|
||||||
|
g_playersKnife.TryRemove((int)player.Index, out _);
|
||||||
|
if (Config.AdditionalSetting.SkinEnabled)
|
||||||
|
{
|
||||||
|
if (gPlayerWeaponsInfo.TryRemove((int)player.Index, out var innerDictionary))
|
||||||
|
{
|
||||||
|
innerDictionary.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Config.AdditionalSetting.MusicKitEnabled)
|
||||||
|
g_playersMusicKit.TryRemove((int)player.Index, out _);
|
||||||
|
if (commandsCooldown.ContainsKey((int)player.UserId))
|
||||||
|
{
|
||||||
|
commandsCooldown.Remove((int)player.UserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEntityCreated(CEntityInstance entity)
|
||||||
|
{
|
||||||
|
if (!Config.AdditionalSetting.SkinEnabled) return;
|
||||||
|
if (entity == null || !entity.IsValid || string.IsNullOrEmpty(entity.DesignerName)) return;
|
||||||
|
string designerName = entity.DesignerName;
|
||||||
|
if (!weaponList.ContainsKey(designerName)) return;
|
||||||
|
bool isKnife = false;
|
||||||
|
var weapon = new CBasePlayerWeapon(entity.Handle);
|
||||||
|
|
||||||
|
if (designerName.Contains("knife") || designerName.Contains("bayonet"))
|
||||||
|
{
|
||||||
|
isKnife = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Server.NextFrame(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!weapon.IsValid) return;
|
||||||
|
if (weapon.OwnerEntity.Value == null) return;
|
||||||
|
if (weapon.OwnerEntity.Index <= 0) return;
|
||||||
|
int weaponOwner = (int)weapon.OwnerEntity.Index;
|
||||||
|
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
||||||
|
if (!pawn.IsValid) return;
|
||||||
|
|
||||||
|
var playerIndex = (int)pawn.Controller.Index;
|
||||||
|
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
|
ChangeWeaponAttributes(weapon, player, isKnife);
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (Config.AdditionalSetting.SkinVisibilityFix)
|
||||||
|
AddTimer(0.2f, () => RefreshSkins(player));
|
||||||
|
*/
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
if (player == null || !player.IsValid || !g_knifePickupCount.ContainsKey((int)player.Index) || player.IsBot || !g_playersKnife.ContainsKey((int)player.Index))
|
||||||
|
return HookResult.Continue;
|
||||||
|
|
||||||
|
|
||||||
|
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||||
|
|
||||||
|
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||||
|
&&
|
||||||
|
g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||||
|
{
|
||||||
|
g_knifePickupCount[(int)player.Index]++;
|
||||||
|
|
||||||
|
RemovePlayerKnife(player, true);
|
||||||
|
|
||||||
|
if (!PlayerHasKnife(player) && Config.AdditionalSetting.GiveKnifeAfterRemove)
|
||||||
|
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)activator.Index).OriginalController.Value;
|
||||||
|
|
||||||
|
if (player == null || player.IsBot || player.IsHLTV)
|
||||||
|
return HookResult.Continue;
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid || player.SteamID.ToString() == "" ||
|
||||||
|
!g_knifePickupCount.ContainsKey((int)player.Index) || !g_playersKnife.ContainsKey((int)player.Index))
|
||||||
|
return HookResult.Continue;
|
||||||
|
|
||||||
|
CBasePlayerWeapon weapon = new(caller.Handle);
|
||||||
|
|
||||||
|
if (weapon.AttributeManager.Item.ItemDefinitionIndex != 42 && weapon.AttributeManager.Item.ItemDefinitionIndex != 59)
|
||||||
|
return HookResult.Continue;
|
||||||
|
|
||||||
|
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||||
|
|
||||||
|
if (g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||||
|
{
|
||||||
|
g_knifePickupCount[(int)player.Index]++;
|
||||||
|
player.RemoveItemByDesignerName(weapon.DesignerName);
|
||||||
|
if (Config.AdditionalSetting.GiveKnifeAfterRemove)
|
||||||
|
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
private void OnMapStart(string mapName)
|
||||||
|
{
|
||||||
|
if (!Config.AdditionalSetting.KnifeEnabled) return;
|
||||||
|
// TODO
|
||||||
|
// needed for now
|
||||||
|
AddTimer(2.0f, () =>
|
||||||
|
{
|
||||||
|
|
||||||
|
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||||
|
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||||
|
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
|
||||||
|
|
||||||
|
if (Config.GlobalShare)
|
||||||
|
GlobalShareConnect();
|
||||||
|
|
||||||
|
weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId);
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
g_hTimerCheckSkinsData = AddTimer(10.0f, () =>
|
||||||
|
{
|
||||||
|
List<CCSPlayerController> players = Utilities.GetPlayers();
|
||||||
|
HashSet<int> playerIndexes = new HashSet<int>(gPlayerWeaponsInfo.Keys);
|
||||||
|
foreach (CCSPlayerController player in players)
|
||||||
|
{
|
||||||
|
if (player.IsBot || player.IsHLTV || player.SteamID.ToString() == "") continue;
|
||||||
|
//if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||||
|
if (playerIndexes.Contains((int)player.Index)) continue;
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player?.SteamID,
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
if (weaponSync != null)
|
||||||
|
_ = weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||||
|
}
|
||||||
|
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE | CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null) return HookResult.Continue;
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player?.SteamID,
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!g_playersDatabaseIndex.ContainsKey((int)player!.Index))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[WeaponPaints] Retrying to retrieve player {player.PlayerName} skins");
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await weaponSync.GetPlayerDatabaseIndex(playerInfo);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
if (player == null || !player.IsValid)
|
||||||
|
{
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Config.AdditionalSetting.KnifeEnabled && !PlayerHasKnife(player))
|
||||||
|
{
|
||||||
|
g_knifePickupCount[(int)player.Index] = 0;
|
||||||
|
GiveKnifeToPlayer(player);
|
||||||
|
//AddTimer(0.1f, () => GiveKnifeToPlayer(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (Config.AdditionalSetting.SkinVisibilityFix)
|
||||||
|
{
|
||||||
|
AddTimer(0.3f, () => RefreshSkins(player));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
g_bCommandsAllowed = false;
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||||
|
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||||
|
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
|
||||||
|
|
||||||
|
g_bCommandsAllowed = true;
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTick()
|
||||||
|
{
|
||||||
|
foreach (var player in Utilities.GetPlayers())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (player == null || !player.IsValid || !player.PawnIsAlive || player.IsBot || player.IsHLTV || player.Connected == PlayerConnectedState.PlayerDisconnecting) continue;
|
||||||
|
|
||||||
|
var viewModels = GetPlayerViewModels(player);
|
||||||
|
|
||||||
|
if (viewModels == null) continue;
|
||||||
|
|
||||||
|
var viewModel = viewModels[0];
|
||||||
|
if (viewModel == null || viewModel.Value == null || viewModel.Value.Weapon == null || viewModel.Value.Weapon.Value == null) continue;
|
||||||
|
CBasePlayerWeapon weapon = viewModel.Value.Weapon.Value;
|
||||||
|
|
||||||
|
if (weapon == null || !weapon.IsValid) continue;
|
||||||
|
|
||||||
|
var isKnife = viewModel.Value.VMName.Contains("knife");
|
||||||
|
|
||||||
|
if (!isKnife)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
viewModel.Value.CBodyComponent != null
|
||||||
|
&& viewModel.Value.CBodyComponent.SceneNode != null
|
||||||
|
&& weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask != 2
|
||||||
|
)
|
||||||
|
{
|
||||||
|
weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utilities.SetStateChanged(viewModel.Value, "CBaseEntity", "m_CBodyComponent");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RegisterListeners()
|
||||||
|
{
|
||||||
|
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
|
||||||
|
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
|
||||||
|
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
||||||
|
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||||
|
|
||||||
|
if (!Config.AdditionalSetting.UseMetamodAlwaysLegacyModel)
|
||||||
|
RegisterListener<Listeners.OnTick>(OnTick);
|
||||||
|
|
||||||
|
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
||||||
|
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||||
|
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||||
|
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||||
|
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
||||||
|
//RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
||||||
|
HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup, HookMode.Pre);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
||||||
|
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid || !player.EntityIndex.HasValue || player.IsHLTV) return HookResult.Continue;
|
||||||
|
|
||||||
|
int playerIndex = (int)player.EntityIndex.Value.Value;
|
||||||
|
if (Config.AdditionalSetting.SkinEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
||||||
|
if (Config.AdditionalSetting.KnifeEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
if (Config.AdditionalSetting.SkinEnabled && weaponSync != null)
|
||||||
|
if (Config.AdditionalSetting.KnifeEnabled && weaponSync != null)
|
||||||
|
});
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
15
PlayerExtensions.cs
Normal file
15
PlayerExtensions.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace WeaponPaints;
|
||||||
|
|
||||||
|
public static class PlayerExtensions
|
||||||
|
{
|
||||||
|
public static void Print(this CCSPlayerController controller, string message)
|
||||||
|
{
|
||||||
|
if (WeaponPaints._localizer == null) return;
|
||||||
|
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
|
||||||
|
_message.Append(message);
|
||||||
|
controller.PrintToChat(_message.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
11
PlayerInfo.cs
Normal file
11
PlayerInfo.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace WeaponPaints
|
||||||
|
{
|
||||||
|
public class PlayerInfo
|
||||||
|
{
|
||||||
|
public int Index { get; set; }
|
||||||
|
public int? UserId { get; set; }
|
||||||
|
public ulong? SteamId { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public string? IpAddress { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
126
README.md
126
README.md
@@ -1,42 +1,110 @@
|
|||||||
# cs2-WeaponPaints
|
# CS2 Weapon Paints
|
||||||
|
|
||||||
### Description
|
## Description
|
||||||
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for [CSSharp](https://docs.cssharp.dev/).
|
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for **[CSSharp](https://docs.cssharp.dev/docs/guides/getting-started.html)**.
|
||||||
There will be a lot of frequent changes which may break functionality or compatibility. You have been warned!
|
|
||||||
|
|
||||||
## Created [Discord server](https://discord.gg/mwEQppJ5AT) where you can discus about plugin.
|
## Created [Discord server](https://discord.gg/d9CvaYPSFe) where you can discuss about plugin.
|
||||||
|
|
||||||
### Consider to donate instead of buying from unknown sources.
|
### Consider to donate instead of buying from unknown sources.
|
||||||
[](https://ko-fi.com/E1E2G0P2O) or [Donate on Steam](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
|
[](https://ko-fi.com/E1E2G0P2O) or [](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
|
||||||
|
|
||||||
### Features
|
## Features
|
||||||
- changes only paint, seed and wear on weapons and knives
|
- Changes only paint, seed and wear on weapons and knives
|
||||||
- mysql based or global website at [weaponpaints.fun](https://weaponpaints.fun/), so you dont need mysql/website
|
- MySQL(min. ver 5.6.5) based or global website, so you dont need MySQL/Website
|
||||||
- data sync on player connect
|
- Data syncs on player connect
|
||||||
- Added command `!wp` to refresh skins (with cooldown in second can be configured)
|
- Added command **`!wp`** to refresh skins ***(with cooldown in seconds can be configured)***
|
||||||
- Added command `!ws` to show website
|
- Added command **`!ws`** to show website
|
||||||
- Added command `!knife` to show menu with knives
|
- Added command **`!knife`** to show menu with knives
|
||||||
- Knife change is now limited to have these cvars empty `mp_t_default_melee ""` and `mp_ct_default_melee ""`
|
- Knife change is now limited to have these cvars empty **`mp_t_default_melee ""`** and **`mp_ct_default_melee ""`**
|
||||||
|
- Translations support, submit a PR if you want to share your translation
|
||||||
|
|
||||||
### CS2 server:
|
**GlobalShare** - global website accessible at [weaponpaints.fun](https://weaponpaints.fun/)
|
||||||
- compile and copy plugin to plugins. Info here [https://docs.cssharp.dev/guides/hello-world-plugin/](https://docs.cssharp.dev/guides/hello-world-plugin/)
|
|
||||||
- setup `addons/counterstrikesharp/configs/plugins/WeaponPaints/WeaponPaints.json`
|
|
||||||
set `GlobalShare` to true for gloval, or include database credentials
|
|
||||||
- in `addons/counterstrikesharp/configs/core.json` set **FollowCS2ServerGuidelines** to **false**
|
|
||||||
|
|
||||||
### Web install:
|
## CS2 Server
|
||||||
- not needed if config `GlobalShare = true`
|
- Have working CounterStrikeSharp (**with RUNTIME!**)
|
||||||
- requires PHP min v7.3 (tested on php ver `8.2.3` and nginx webserver)
|
- Download from Release and copy plugin to plugins
|
||||||
- copy website to web server (img folder not needed)
|
- Run server with plugin, it will generate config if installed correctly
|
||||||
- import `database.sql` to mysql
|
- Edit `addons/counterstrikesharp/configs/`**`plugins/WeaponPaints/WeaponPaints.json`** set **`GlobalShare`** to **`true`** for global, or include database credentials
|
||||||
- get steam api key [https://steamcommunity.com/dev/apikey](https://steamcommunity.com/dev/apikey)
|
- In `addons/counterstrikesharp/configs/`**`core.json`** set **FollowCS2ServerGuidelines** to **`false`**
|
||||||
- fill in database credentials and api key in `class/config.php`
|
|
||||||
- visit website and login via steam
|
|
||||||
|
|
||||||
### Known issues
|
## Plugin Configuration
|
||||||
|
<details>
|
||||||
|
<summary>Click to expand</summary>
|
||||||
|
<code><pre>{
|
||||||
|
"Version": 4, // Don't touch
|
||||||
|
"DatabaseHost": "", // MySQL host (required if GlobalShare = false)
|
||||||
|
"DatabasePort": 3306, // MySQL port (required if GlobalShare = false)
|
||||||
|
"DatabaseUser": "", // MySQL username (required if GlobalShare = false)
|
||||||
|
"DatabasePassword": "", // MySQL user password (required if GlobalShare = false)
|
||||||
|
"DatabaseName": "", // MySQL database name (required if GlobalShare = false)
|
||||||
|
"GlobalShare": false, // Enable or disable GlobalShare, plugin can work without mysql credentials but with shared website at weaponpaints.fun
|
||||||
|
"CmdRefreshCooldownSeconds": 60, // Cooldown time in refreshing skins (!wp command)
|
||||||
|
"Prefix": "[WeaponPaints]", // Prefix every chat message
|
||||||
|
"Website": "example.com/skins", // Website used in WebsiteMessageCommand (!ws command)
|
||||||
|
"Messages": {
|
||||||
|
"WebsiteMessageCommand": "Visit {WEBSITE} where you can change skins.", // Information about website where player can change skins (!ws command) Set to empty to disable
|
||||||
|
"SynchronizeMessageCommand": "Type !wp to synchronize chosen skins.", // Information about skins refreshing (!ws command) Set to empty to disable
|
||||||
|
"KnifeMessageCommand": "Type !knife to open knife menu.", // Information about knife menu (!ws command) Set to empty to disable
|
||||||
|
"CooldownRefreshCommand": "You can\u0027t refresh weapon paints right now.", // Cooldown information (!wp command) Set to empty to disable
|
||||||
|
"SuccessRefreshCommand": "Refreshing weapon paints.", // Information about refreshing skins (!wp command) Set to empty to disable
|
||||||
|
"ChosenKnifeMenu": "You have chosen {KNIFE} as your knife.", // Information about choosen knife (!knife command) Set to empty to disable
|
||||||
|
"ChosenSkinMenu": "You have chosen {SKIN} as your skin.", // Information about choosen skin (!skins command) Set to empty to disable
|
||||||
|
"ChosenKnifeMenuKill": "To correctly apply skin for knife, you need to type !kill.", // Information about suicide after knife selection (!knife command) Set to empty to disable
|
||||||
|
"KnifeMenuTitle": "Knife Menu.", // Menu title (!knife menu)
|
||||||
|
"WeaponMenuTitle": "Weapon Menu.", // Menu title (!skins menu)
|
||||||
|
"SkinMenuTitle": "Select skin for {WEAPON}" // Menu title (!skins menu, after weapon select)
|
||||||
|
},
|
||||||
|
"Additional": {
|
||||||
|
"SkinVisibilityFix": true, // Enable or disable fix for skin visibility
|
||||||
|
"KnifeEnabled": true, // Enable or disable knife feature
|
||||||
|
"SkinEnabled": true, // Enable or disable skin feature
|
||||||
|
"CommandWpEnabled": true, // Enable or disable refreshing command
|
||||||
|
"CommandKillEnabled": true, // Enable or disable kill command
|
||||||
|
"CommandKnife": "knife", // Name of knife menu command, u can change to for e.g, knives
|
||||||
|
"CommandSkin": "ws", // Name of skin information command, u can change to for e.g, skins
|
||||||
|
"CommandSkinSelection": "skins", // Name of skins menu command, u can change to for e.g, weapons
|
||||||
|
"CommandRefresh": "wp", // Name of skin refreshing command, u can change to for e.g, refreshskins
|
||||||
|
"CommandKill": "kill", // Name of kill command, u can change to for e.g, suicide
|
||||||
|
"GiveRandomKnife": false, // Give random knife to players if they didn't choose
|
||||||
|
"GiveRandomSkins": false // Give random skins to players if they didn't choose
|
||||||
|
},
|
||||||
|
|
||||||
|
"ConfigVersion": 4 // Don't touch
|
||||||
|
}</pre></code>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
## Web install
|
||||||
|
Ignore this section if you have in config **`GlobalShare = true`**
|
||||||
|
- Minimum PHP version 5.5 (needs testing)
|
||||||
|
- Minimum MySQL version 5.6.5
|
||||||
|
- **Before using website, make sure the plugin is correctly loaded in cs2 server!** Mysql tables are created by plugin not by website.
|
||||||
|
- Copy website to web server ***(Folder `img` not needed)***
|
||||||
|
- Get [Steam API Key](https://steamcommunity.com/dev/apikey)
|
||||||
|
- Fill in database credentials and api key in `class/config.php`
|
||||||
|
- Visit website and login via steam
|
||||||
|
|
||||||
|
## Web Features
|
||||||
|
- Basic website
|
||||||
|
- Steam login/logout
|
||||||
|
- Change knife, paint, seed and wear
|
||||||
|
|
||||||
|
## Known issues
|
||||||
- Issue on Windows servers, no knives are given.
|
- Issue on Windows servers, no knives are given.
|
||||||
|
- Can cause incompatibility with plugins/maps which manipulates weapons and knives
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
<details>
|
||||||
|
**Skins are not changing:**
|
||||||
|
Set FollowCSGOGuidelines to false in cssharp’s core.jcon config
|
||||||
|
|
||||||
|
**Database error table does not exists:**
|
||||||
|
Plugin is not loaded or configured with mysql credentials. Tables are auto-created by plugin.
|
||||||
|
|
||||||
|
**Knives are disappearing:**
|
||||||
|
Set in config GiveKnifeAfterRemove to true
|
||||||
|
</details>
|
||||||
|
|
||||||
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
|
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
|
||||||
|
|
||||||
### Preview
|
## Preview
|
||||||

|

|
||||||
|
|||||||
191
Utility.cs
Normal file
191
Utility.cs
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
|
using Dapper;
|
||||||
|
using MySqlConnector;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Reflection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace WeaponPaints
|
||||||
|
{
|
||||||
|
internal static class Utility
|
||||||
|
{
|
||||||
|
internal static WeaponPaintsConfig? Config { get; set; }
|
||||||
|
|
||||||
|
internal static string BuildDatabaseConnectionString()
|
||||||
|
{
|
||||||
|
if (Config == null) return string.Empty;
|
||||||
|
var builder = new MySqlConnectionStringBuilder
|
||||||
|
{
|
||||||
|
Server = Config.DatabaseHost,
|
||||||
|
UserID = Config.DatabaseUser,
|
||||||
|
Password = Config.DatabasePassword,
|
||||||
|
Database = Config.DatabaseName,
|
||||||
|
Port = (uint)Config.DatabasePort,
|
||||||
|
};
|
||||||
|
|
||||||
|
return builder.ConnectionString;
|
||||||
|
}
|
||||||
|
internal static async void CheckDatabaseTables()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new MySqlConnection(BuildDatabaseConnectionString());
|
||||||
|
await connection.OpenAsync();
|
||||||
|
|
||||||
|
using var transaction = await connection.BeginTransactionAsync();
|
||||||
|
|
||||||
|
// Minimal version for MySQL 5.6.5
|
||||||
|
string[] sqlCommands = new string[]
|
||||||
|
{
|
||||||
|
"CREATE TABLE IF NOT EXISTS `wp_users` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `steamid` BIGINT UNSIGNED NOT NULL, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `unique_steamid` (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||||
|
"CREATE TABLE IF NOT EXISTS `wp_users_items` (`user_id` INT UNSIGNED NOT NULL, `weapon` SMALLINT UNSIGNED NOT NULL, `paint` SMALLINT UNSIGNED NOT NULL, `wear` FLOAT NOT NULL DEFAULT 0.00001, `seed` SMALLINT UNSIGNED NOT NULL DEFAULT 0, `nametag` VARCHAR(20) DEFAULT NULL, `stattrack` INT UNSIGNED NOT NULL DEFAULT 0, `stattrack_enabled` SMALLINT NOT NULL DEFAULT 0, `quality` SMALLINT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`user_id`,`weapon`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||||
|
"CREATE TABLE IF NOT EXISTS `wp_users_knife` (`user_id` INT UNSIGNED NOT NULL, `knife` VARCHAR(32) DEFAULT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||||
|
"CREATE TABLE IF NOT EXISTS `wp_users_music` (`user_id` INT UNSIGNED NOT NULL, `music` SMALLINT UNSIGNED DEFAULT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
|
||||||
|
};
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (string command in sqlCommands)
|
||||||
|
{
|
||||||
|
await connection.ExecuteAsync(command, transaction: transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
await transaction.CommitAsync();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
await transaction.RollbackAsync();
|
||||||
|
throw new Exception("[WeaponPaints] Unable to create tables!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool IsPlayerValid(CCSPlayerController? player)
|
||||||
|
{
|
||||||
|
return (player != null && player.IsValid && !player.IsBot && !player.IsHLTV && player.AuthorizedSteamID != null);
|
||||||
|
}
|
||||||
|
internal static void LoadSkinsFromFile(string filePath)
|
||||||
|
{
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
{
|
||||||
|
string json = File.ReadAllText(filePath);
|
||||||
|
var deserializedSkins = JsonConvert.DeserializeObject<List<JObject>>(json);
|
||||||
|
WeaponPaints.skinsList = deserializedSkins ?? new List<JObject>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("File not found.", filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void Log(string message)
|
||||||
|
{
|
||||||
|
Console.BackgroundColor = ConsoleColor.DarkGray;
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine("[WeaponPaints] " + message);
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string ReplaceTags(string message)
|
||||||
|
{
|
||||||
|
if (message.Contains('{'))
|
||||||
|
{
|
||||||
|
string modifiedValue = message;
|
||||||
|
if (Config != null)
|
||||||
|
{
|
||||||
|
modifiedValue = modifiedValue.Replace("{WEBSITE}", Config.Website);
|
||||||
|
}
|
||||||
|
foreach (FieldInfo field in typeof(ChatColors).GetFields())
|
||||||
|
{
|
||||||
|
string pattern = $"{{{field.Name}}}";
|
||||||
|
if (message.Contains(pattern, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
modifiedValue = modifiedValue.Replace(pattern, field.GetValue(null)!.ToString(), StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modifiedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static async Task CheckVersion(string version, ILogger logger)
|
||||||
|
{
|
||||||
|
using (HttpClient client = new HttpClient())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponseMessage response = await client.GetAsync("https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/VERSION");
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
string remoteVersion = await response.Content.ReadAsStringAsync();
|
||||||
|
remoteVersion = remoteVersion.Trim();
|
||||||
|
|
||||||
|
int comparisonResult = string.Compare(version, remoteVersion);
|
||||||
|
|
||||||
|
if (comparisonResult < 0)
|
||||||
|
{
|
||||||
|
logger.LogWarning("Plugin is outdated! Check https://github.com/Nereziel/cs2-WeaponPaints");
|
||||||
|
}
|
||||||
|
else if (comparisonResult > 0)
|
||||||
|
{
|
||||||
|
logger.LogInformation("Probably dev version detected");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.LogInformation("Plugin is up to date");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.LogWarning("Failed to check version");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void ShowAd(string moduleVersion)
|
||||||
|
{
|
||||||
|
Console.WriteLine(" ");
|
||||||
|
Console.WriteLine(" _ _ _______ _______ _______ _______ __ _ _______ _______ ___ __ _ _______ _______ ");
|
||||||
|
Console.WriteLine("| | _ | || || _ || || || | | || || _ || | | | | || || |");
|
||||||
|
Console.WriteLine("| || || || ___|| |_| || _ || _ || |_| || _ || |_| || | | |_| ||_ _|| _____|");
|
||||||
|
Console.WriteLine("| || |___ | || |_| || | | || || |_| || || | | | | | | |_____ ");
|
||||||
|
Console.WriteLine("| || ___|| || ___|| |_| || _ || ___|| || | | _ | | | |_____ |");
|
||||||
|
Console.WriteLine("| _ || |___ | _ || | | || | | || | | _ || | | | | | | | _____| |");
|
||||||
|
Console.WriteLine("|__| |__||_______||__| |__||___| |_______||_| |__||___| |__| |__||___| |_| |__| |___| |_______|");
|
||||||
|
Console.WriteLine(" >> Version: " + moduleVersion);
|
||||||
|
Console.WriteLine(" >> GitHub: https://github.com/Nereziel/cs2-WeaponPaints");
|
||||||
|
Console.WriteLine(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void TestDatabaseConnection()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new MySqlConnection(BuildDatabaseConnectionString());
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
if (connection.State != System.Data.ConnectionState.Open)
|
||||||
|
{
|
||||||
|
throw new Exception("[WeaponPaints] Unable connect to database!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
|
||||||
|
}
|
||||||
|
CheckDatabaseTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
343
WeaponAction.cs
Normal file
343
WeaponAction.cs
Normal file
@@ -0,0 +1,343 @@
|
|||||||
|
using CounterStrikeSharp.API;
|
||||||
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace WeaponPaints
|
||||||
|
{
|
||||||
|
public partial class WeaponPaints
|
||||||
|
{
|
||||||
|
internal static void ChangeWeaponAttributes(CBasePlayerWeapon? weapon, CCSPlayerController? player, bool isKnife = false)
|
||||||
|
{
|
||||||
|
if (player == null || weapon == null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
|
int playerIndex = (int)player.Index;
|
||||||
|
|
||||||
|
if (!gPlayerWeaponsInfo.ContainsKey(playerIndex)) return;
|
||||||
|
|
||||||
|
if (isKnife && !g_playersKnife.ContainsKey(playerIndex) || isKnife && g_playersKnife[playerIndex] == "weapon_knife") return;
|
||||||
|
|
||||||
|
ushort weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
||||||
|
|
||||||
|
if (isKnife)
|
||||||
|
{
|
||||||
|
weapon.AttributeManager.Item.EntityQuality = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_config.AdditionalSetting.GiveRandomSkin &&
|
||||||
|
!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
||||||
|
{
|
||||||
|
// Random skins
|
||||||
|
weapon.AttributeManager.Item.ItemID = 16384;
|
||||||
|
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
|
||||||
|
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
|
||||||
|
weapon.FallbackPaintKit = GetRandomPaint(weaponDefIndex);
|
||||||
|
weapon.FallbackSeed = 0;
|
||||||
|
weapon.FallbackWear = 0.00001f;
|
||||||
|
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||||
|
{
|
||||||
|
if (weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask != 2)
|
||||||
|
{
|
||||||
|
weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex)) return;
|
||||||
|
WeaponInfo weaponInfo = gPlayerWeaponsInfo[playerIndex][weaponDefIndex];
|
||||||
|
//Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
|
||||||
|
weapon.AttributeManager.Item.ItemID = 16384;
|
||||||
|
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
|
||||||
|
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
|
||||||
|
weapon.FallbackPaintKit = weaponInfo.Paint;
|
||||||
|
weapon.FallbackSeed = weaponInfo.Seed;
|
||||||
|
weapon.FallbackWear = weaponInfo.Wear;
|
||||||
|
|
||||||
|
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||||
|
{
|
||||||
|
if (weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask != 2)
|
||||||
|
{
|
||||||
|
weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void GiveKnifeToPlayer(CCSPlayerController? player)
|
||||||
|
{
|
||||||
|
if (!_config.AdditionalSetting.KnifeEnabled || player == null || !player.IsValid) return;
|
||||||
|
|
||||||
|
if (g_playersKnife.TryGetValue((int)player.Index, out var knife))
|
||||||
|
{
|
||||||
|
player.GiveNamedItem(knife);
|
||||||
|
}
|
||||||
|
else if (_config.AdditionalSetting.GiveRandomKnife)
|
||||||
|
{
|
||||||
|
var knifeTypes = weaponList.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet")).ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||||
|
|
||||||
|
Random random = new();
|
||||||
|
int index = random.Next(knifeTypes.Count);
|
||||||
|
var randomKnifeClass = knifeTypes.Keys.ElementAt(index);
|
||||||
|
|
||||||
|
player.GiveNamedItem(randomKnifeClass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var defaultKnife = (CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife";
|
||||||
|
player.GiveNamedItem(defaultKnife);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool PlayerHasKnife(CCSPlayerController? player)
|
||||||
|
{
|
||||||
|
if (!_config.AdditionalSetting.KnifeEnabled) return false;
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid || player.PlayerPawn == null || !player.PlayerPawn.IsValid || !player.PawnIsAlive)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.PlayerPawn?.Value == null || player.PlayerPawn?.Value.WeaponServices == null || player.PlayerPawn?.Value.ItemServices == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
|
||||||
|
if (weapons == null) return false;
|
||||||
|
foreach (var weapon in weapons)
|
||||||
|
{
|
||||||
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||||
|
{
|
||||||
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void RefreshPlayerKnife(CCSPlayerController? player)
|
||||||
|
{
|
||||||
|
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
||||||
|
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return;
|
||||||
|
|
||||||
|
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||||
|
if (weapons != null && weapons.Count > 0)
|
||||||
|
{
|
||||||
|
CCSPlayer_ItemServices service = new(player.PlayerPawn.Value.ItemServices.Handle);
|
||||||
|
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
||||||
|
|
||||||
|
foreach (var weapon in weapons)
|
||||||
|
{
|
||||||
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||||
|
{
|
||||||
|
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||||
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
|
{
|
||||||
|
if (weapon.Index <= 0) return;
|
||||||
|
int weaponEntityIndex = (int)weapon.Index;
|
||||||
|
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
||||||
|
AddTimer(0.22f, () =>
|
||||||
|
{
|
||||||
|
if (player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value!.DesignerName.Contains("knife")
|
||||||
|
||
|
||||||
|
player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value!.DesignerName.Contains("bayonet")
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (player.PawnIsAlive)
|
||||||
|
{
|
||||||
|
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
||||||
|
service.DropActivePlayerWeapon(weapon.Value);
|
||||||
|
GiveKnifeToPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Task.Delay(TimeSpan.FromSeconds(3.5)).ContinueWith(_ =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
||||||
|
|
||||||
|
if (knife != null && knife.IsValid && knife.Handle != -1 && knife.Index > 0)
|
||||||
|
{
|
||||||
|
knife.Remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
internal void RefreshSkins(CCSPlayerController? player)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
if (!Utility.IsPlayerValid(player) || !player!.PawnIsAlive) return;
|
||||||
|
|
||||||
|
AddTimer(0.18f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3"));
|
||||||
|
AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot2"));
|
||||||
|
AddTimer(0.38f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot1"));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
internal void RefreshWeapons(CCSPlayerController? player)
|
||||||
|
{
|
||||||
|
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
||||||
|
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return;
|
||||||
|
|
||||||
|
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||||
|
if (weapons != null && weapons.Count > 0)
|
||||||
|
{
|
||||||
|
CCSPlayer_ItemServices service = new(player.PlayerPawn.Value.ItemServices.Handle);
|
||||||
|
|
||||||
|
foreach (var weapon in weapons)
|
||||||
|
{
|
||||||
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||||
|
{
|
||||||
|
if (weapon.Index <= 0 || !weapon.Value.DesignerName.Contains("weapon_")) continue;
|
||||||
|
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
|
{
|
||||||
|
player.RemoveItemByDesignerName(weapon.Value.DesignerName, true);
|
||||||
|
GiveKnifeToPlayer(player);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!WeaponDefindex.ContainsKey(weapon.Value.AttributeManager.Item.ItemDefinitionIndex)) continue;
|
||||||
|
int clip1, reservedAmmo;
|
||||||
|
|
||||||
|
clip1 = weapon.Value.Clip1;
|
||||||
|
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||||
|
|
||||||
|
string weaponByDefindex = WeaponDefindex[weapon.Value.AttributeManager.Item.ItemDefinitionIndex];
|
||||||
|
player.RemoveItemByDesignerName(weapon.Value.DesignerName, true);
|
||||||
|
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weaponByDefindex));
|
||||||
|
|
||||||
|
Server.NextFrame(() =>
|
||||||
|
{
|
||||||
|
if (newWeapon == null) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
newWeapon.Clip1 = clip1;
|
||||||
|
newWeapon.ReserveAmmo[0] = reservedAmmo;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogWarning("Refreshing weapons exception");
|
||||||
|
Console.WriteLine("[WeaponPaints] Refreshing weapons exception");
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (Config.AdditionalSetting.SkinVisibilityFix)
|
||||||
|
RefreshSkins(player);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void RemovePlayerKnife(CCSPlayerController? player, bool force = false)
|
||||||
|
{
|
||||||
|
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
||||||
|
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return;
|
||||||
|
|
||||||
|
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||||
|
if (weapons != null && weapons.Count > 0)
|
||||||
|
{
|
||||||
|
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
||||||
|
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
||||||
|
|
||||||
|
foreach (var weapon in weapons)
|
||||||
|
{
|
||||||
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||||
|
{
|
||||||
|
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||||
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
|
{
|
||||||
|
if (!force)
|
||||||
|
{
|
||||||
|
if ((int)weapon.Index <= 0) return;
|
||||||
|
int weaponEntityIndex = (int)weapon.Index;
|
||||||
|
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
||||||
|
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
|
||||||
|
|
||||||
|
AddTimer(1.0f, () =>
|
||||||
|
{
|
||||||
|
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
||||||
|
if (knife != null && knife.IsValid)
|
||||||
|
{
|
||||||
|
knife.Remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
weapon.Value.Remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static int GetRandomPaint(int defindex)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (skinsList != null)
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
// Filter weapons by the provided defindex
|
||||||
|
var filteredWeapons = skinsList.FindAll(w => w["weapon_defindex"]?.ToString() == defindex.ToString());
|
||||||
|
|
||||||
|
if (filteredWeapons.Count > 0)
|
||||||
|
{
|
||||||
|
var randomWeapon = filteredWeapons[rnd.Next(filteredWeapons.Count)];
|
||||||
|
if (int.TryParse(randomWeapon["paint"]?.ToString(), out int paintValue))
|
||||||
|
{
|
||||||
|
return paintValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
private static unsafe CHandle<CBaseViewModel>[]? GetPlayerViewModels(CCSPlayerController player)
|
||||||
|
{
|
||||||
|
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.ViewModelServices == null) return null;
|
||||||
|
CCSPlayer_ViewModelServices viewModelServices = new CCSPlayer_ViewModelServices(player.PlayerPawn.Value.ViewModelServices!.Handle);
|
||||||
|
return GetFixedArray<CHandle<CBaseViewModel>>(viewModelServices.Handle, "CCSPlayer_ViewModelServices", "m_hViewModel", 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe T[] GetFixedArray<T>(nint pointer, string @class, string member, int length) where T : CHandle<CBaseViewModel>
|
||||||
|
{
|
||||||
|
nint ptr = pointer + Schema.GetSchemaOffset(@class, member);
|
||||||
|
Span<nint> references = MemoryMarshal.CreateSpan<nint>(ref ptr, length);
|
||||||
|
T[] values = new T[length];
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
values[i] = (T)Activator.CreateInstance(typeof(T), references[i])!;
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
WeaponInfo.cs
Normal file
13
WeaponInfo.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace WeaponPaints
|
||||||
|
{
|
||||||
|
public class WeaponInfo
|
||||||
|
{
|
||||||
|
public ushort Paint { get; set; }
|
||||||
|
public ushort Seed { get; set; }
|
||||||
|
public float Wear { get; set; }
|
||||||
|
public string? NameTag { get; set; }
|
||||||
|
public ushort Quality { get; set; }
|
||||||
|
public uint StatTrack { get; set; }
|
||||||
|
public bool StatTrackEnabled { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
914
WeaponPaints.cs
914
WeaponPaints.cs
@@ -1,241 +1,253 @@
|
|||||||
using CounterStrikeSharp.API;
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes;
|
using CounterStrikeSharp.API.Core.Attributes;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
|
||||||
using CounterStrikeSharp.API.Modules.Memory;
|
|
||||||
using CounterStrikeSharp.API.Modules.Menu;
|
|
||||||
using CounterStrikeSharp.API.Modules.Utils;
|
|
||||||
using MySqlConnector;
|
|
||||||
using Dapper;
|
|
||||||
using System.Runtime.ExceptionServices;
|
|
||||||
using System.Reflection;
|
|
||||||
using CounterStrikeSharp.API.Modules.Cvars;
|
using CounterStrikeSharp.API.Modules.Cvars;
|
||||||
using Newtonsoft.Json;
|
using Microsoft.Extensions.Localization;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
[MinimumApiVersion(55)]
|
|
||||||
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
[MinimumApiVersion(155)]
|
||||||
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
public override string ModuleName => "WeaponPaints";
|
internal static readonly Dictionary<string, string> weaponList = new()
|
||||||
public override string ModuleDescription => "Connector for web-based player chosen wepaon paints, and standalone for knife.";
|
{
|
||||||
public override string ModuleAuthor => "Nereziel";
|
{"weapon_deagle", "Desert Eagle"},
|
||||||
public override string ModuleVersion => "1.0";
|
{"weapon_elite", "Dual Berettas"},
|
||||||
public WeaponPaintsConfig Config { get; set; } = new();
|
{"weapon_fiveseven", "Five-SeveN"},
|
||||||
|
{"weapon_glock", "Glock-18"},
|
||||||
|
{"weapon_ak47", "AK-47"},
|
||||||
|
{"weapon_aug", "AUG"},
|
||||||
|
{"weapon_awp", "AWP"},
|
||||||
|
{"weapon_famas", "FAMAS"},
|
||||||
|
{"weapon_g3sg1", "G3SG1"},
|
||||||
|
{"weapon_galilar", "Galil AR"},
|
||||||
|
{"weapon_m249", "M249"},
|
||||||
|
{"weapon_m4a1", "M4A1"},
|
||||||
|
{"weapon_mac10", "MAC-10"},
|
||||||
|
{"weapon_p90", "P90"},
|
||||||
|
{"weapon_mp5sd", "MP5-SD"},
|
||||||
|
{"weapon_ump45", "UMP-45"},
|
||||||
|
{"weapon_xm1014", "XM1014"},
|
||||||
|
{"weapon_bizon", "PP-Bizon"},
|
||||||
|
{"weapon_mag7", "MAG-7"},
|
||||||
|
{"weapon_negev", "Negev"},
|
||||||
|
{"weapon_sawedoff", "Sawed-Off"},
|
||||||
|
{"weapon_tec9", "Tec-9"},
|
||||||
|
{"weapon_hkp2000", "P2000"},
|
||||||
|
{"weapon_mp7", "MP7"},
|
||||||
|
{"weapon_mp9", "MP9"},
|
||||||
|
{"weapon_nova", "Nova"},
|
||||||
|
{"weapon_p250", "P250"},
|
||||||
|
{"weapon_scar20", "SCAR-20"},
|
||||||
|
{"weapon_sg556", "SG 553"},
|
||||||
|
{"weapon_ssg08", "SSG 08"},
|
||||||
|
{"weapon_m4a1_silencer", "M4A1-S"},
|
||||||
|
{"weapon_usp_silencer", "USP-S"},
|
||||||
|
{"weapon_cz75a", "CZ75-Auto"},
|
||||||
|
{"weapon_revolver", "R8 Revolver"},
|
||||||
|
{ "weapon_knife", "Default Knife" },
|
||||||
|
{ "weapon_knife_m9_bayonet", "M9 Bayonet" },
|
||||||
|
{ "weapon_knife_karambit", "Karambit" },
|
||||||
|
{ "weapon_bayonet", "Bayonet" },
|
||||||
|
{ "weapon_knife_survival_bowie", "Bowie Knife" },
|
||||||
|
{ "weapon_knife_butterfly", "Butterfly Knife" },
|
||||||
|
{ "weapon_knife_falchion", "Falchion Knife" },
|
||||||
|
{ "weapon_knife_flip", "Flip Knife" },
|
||||||
|
{ "weapon_knife_gut", "Gut Knife" },
|
||||||
|
{ "weapon_knife_tactical", "Huntsman Knife" },
|
||||||
|
{ "weapon_knife_push", "Shadow Daggers" },
|
||||||
|
{ "weapon_knife_gypsy_jackknife", "Navaja Knife" },
|
||||||
|
{ "weapon_knife_stiletto", "Stiletto Knife" },
|
||||||
|
{ "weapon_knife_widowmaker", "Talon Knife" },
|
||||||
|
{ "weapon_knife_ursus", "Ursus Knife" },
|
||||||
|
{ "weapon_knife_css", "Classic Knife" },
|
||||||
|
{ "weapon_knife_cord", "Paracord Knife" },
|
||||||
|
{ "weapon_knife_canis", "Survival Knife" },
|
||||||
|
{ "weapon_knife_outdoor", "Nomad Knife" },
|
||||||
|
{ "weapon_knife_skeleton", "Skeleton Knife" }
|
||||||
|
};
|
||||||
|
public static Dictionary<int, string> WeaponDefindex { get; } = new Dictionary<int, string>
|
||||||
|
{
|
||||||
|
{ 1, "weapon_deagle" },
|
||||||
|
{ 2, "weapon_elite" },
|
||||||
|
{ 3, "weapon_fiveseven" },
|
||||||
|
{ 4, "weapon_glock" },
|
||||||
|
{ 7, "weapon_ak47" },
|
||||||
|
{ 8, "weapon_aug" },
|
||||||
|
{ 9, "weapon_awp" },
|
||||||
|
{ 10, "weapon_famas" },
|
||||||
|
{ 11, "weapon_g3sg1" },
|
||||||
|
{ 13, "weapon_galilar" },
|
||||||
|
{ 14, "weapon_m249" },
|
||||||
|
{ 16, "weapon_m4a1" },
|
||||||
|
{ 17, "weapon_mac10" },
|
||||||
|
{ 19, "weapon_p90" },
|
||||||
|
{ 23, "weapon_mp5sd" },
|
||||||
|
{ 24, "weapon_ump45" },
|
||||||
|
{ 25, "weapon_xm1014" },
|
||||||
|
{ 26, "weapon_bizon" },
|
||||||
|
{ 27, "weapon_mag7" },
|
||||||
|
{ 28, "weapon_negev" },
|
||||||
|
{ 29, "weapon_sawedoff" },
|
||||||
|
{ 30, "weapon_tec9" },
|
||||||
|
{ 32, "weapon_hkp2000" },
|
||||||
|
{ 33, "weapon_mp7" },
|
||||||
|
{ 34, "weapon_mp9" },
|
||||||
|
{ 35, "weapon_nova" },
|
||||||
|
{ 36, "weapon_p250" },
|
||||||
|
{ 38, "weapon_scar20" },
|
||||||
|
{ 39, "weapon_sg556" },
|
||||||
|
{ 40, "weapon_ssg08" },
|
||||||
|
{ 60, "weapon_m4a1_silencer" },
|
||||||
|
{ 61, "weapon_usp_silencer" },
|
||||||
|
{ 63, "weapon_cz75a" },
|
||||||
|
{ 64, "weapon_revolver" },
|
||||||
|
{ 500, "weapon_bayonet" },
|
||||||
|
{ 503, "weapon_knife_css" },
|
||||||
|
{ 505, "weapon_knife_flip" },
|
||||||
|
{ 506, "weapon_knife_gut" },
|
||||||
|
{ 507, "weapon_knife_karambit" },
|
||||||
|
{ 508, "weapon_knife_m9_bayonet" },
|
||||||
|
{ 509, "weapon_knife_tactical" },
|
||||||
|
{ 512, "weapon_knife_falchion" },
|
||||||
|
{ 514, "weapon_knife_survival_bowie" },
|
||||||
|
{ 515, "weapon_knife_butterfly" },
|
||||||
|
{ 516, "weapon_knife_push" },
|
||||||
|
{ 517, "weapon_knife_cord" },
|
||||||
|
{ 518, "weapon_knife_canis" },
|
||||||
|
{ 519, "weapon_knife_ursus" },
|
||||||
|
{ 520, "weapon_knife_gypsy_jackknife" },
|
||||||
|
{ 521, "weapon_knife_outdoor" },
|
||||||
|
{ 522, "weapon_knife_stiletto" },
|
||||||
|
{ 523, "weapon_knife_widowmaker" },
|
||||||
|
{ 525, "weapon_knife_skeleton" }
|
||||||
|
};
|
||||||
|
|
||||||
|
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
||||||
|
internal static IStringLocalizer? _localizer;
|
||||||
|
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
||||||
|
internal static ConcurrentDictionary<int, int> g_playersDatabaseIndex = new ConcurrentDictionary<int, int>();
|
||||||
|
internal static ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>();
|
||||||
|
internal static ConcurrentDictionary<int, int?> g_playersMusicKit = new ConcurrentDictionary<int, int?>();
|
||||||
|
internal static ConcurrentDictionary<int, ConcurrentDictionary<ushort, WeaponInfo>> gPlayerWeaponsInfo = new ConcurrentDictionary<int, ConcurrentDictionary<ushort, WeaponInfo>>();
|
||||||
|
internal static List<JObject> skinsList = new List<JObject>();
|
||||||
|
internal static WeaponSynchronization? weaponSync;
|
||||||
|
internal bool g_bCommandsAllowed = true;
|
||||||
|
|
||||||
|
internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php");
|
||||||
|
internal int GlobalShareServerId = 0;
|
||||||
|
internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
|
||||||
private string DatabaseConnectionString = string.Empty;
|
private string DatabaseConnectionString = string.Empty;
|
||||||
private Uri GlobalShareApi = new Uri("https://weaponpaints.fun/api.php");
|
//private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
||||||
|
public WeaponPaintsConfig Config { get; set; } = new();
|
||||||
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
|
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
||||||
|
public override string ModuleName => "WeaponPaints";
|
||||||
|
public override string ModuleVersion => "1.5.0";
|
||||||
|
|
||||||
public bool IsMatchZy = false;
|
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||||
public int GlobalShareServerId = 0;
|
{
|
||||||
|
return _config;
|
||||||
|
}
|
||||||
|
|
||||||
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
|
||||||
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponPaints = new();
|
|
||||||
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponSeed = new();
|
|
||||||
private Dictionary<ulong, Dictionary<nint, float>> gPlayerWeaponWear = new();
|
|
||||||
private Dictionary<int, string> g_playersKnife = new();
|
|
||||||
private static readonly Dictionary<string, string> knifeTypes = new()
|
|
||||||
{
|
|
||||||
{ "m9", "weapon_knife_m9_bayonet" }, { "karambit", "weapon_knife_karambit" },
|
|
||||||
{ "bayonet", "weapon_bayonet" }, { "bowie", "weapon_knife_survival_bowie" },
|
|
||||||
{ "butterfly", "weapon_knife_butterfly" }, { "falchion", "weapon_knife_falchion" },
|
|
||||||
{ "flip", "weapon_knife_flip" }, { "gut", "weapon_knife_gut" },
|
|
||||||
{ "tactical", "weapon_knife_tactical" }, { "shadow", "weapon_knife_push" },
|
|
||||||
{ "navaja", "weapon_knife_gypsy_jackknife" }, { "stiletto", "weapon_knife_stiletto" },
|
|
||||||
{ "talon", "weapon_knife_widowmaker" }, { "ursus", "weapon_knife_ursus" },
|
|
||||||
{ "css", "weapon_knife_css" }, { "paracord", "weapon_knife_cord" },
|
|
||||||
{ "survival", "weapon_knife_canis" }, { "nomad", "weapon_knife_outdoor" },
|
|
||||||
{ "skeleton", "weapon_knife_skeleton" }, { "default", "weapon_knife" }
|
|
||||||
};
|
|
||||||
private static readonly List<string> weaponList = new()
|
|
||||||
{
|
|
||||||
"weapon_deagle", "weapon_elite", "weapon_fiveseven", "weapon_glock",
|
|
||||||
"weapon_ak47", "weapon_aug", "weapon_awp", "weapon_famas",
|
|
||||||
"weapon_g3sg1", "weapon_galilar", "weapon_m249", "weapon_m4a1",
|
|
||||||
"weapon_mac10", "weapon_p90", "weapon_mp5sd", "weapon_ump45",
|
|
||||||
"weapon_xm1014", "weapon_bizon", "weapon_mag7", "weapon_negev",
|
|
||||||
"weapon_sawedoff", "weapon_tec9", "weapon_hkp2000", "weapon_mp7",
|
|
||||||
"weapon_mp9", "weapon_nova", "weapon_p250", "weapon_scar20",
|
|
||||||
"weapon_sg556", "weapon_ssg08", "weapon_m4a1_silencer", "weapon_usp_silencer",
|
|
||||||
"weapon_cz75a", "weapon_revolver", "weapon_bayonet", "weapon_knife"
|
|
||||||
};
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
SetGlobalExceptionHandler();
|
|
||||||
if (!Config.GlobalShare)
|
if (!Config.GlobalShare)
|
||||||
{
|
{
|
||||||
BuildDatabaseConnectionString();
|
DatabaseConnectionString = Utility.BuildDatabaseConnectionString();
|
||||||
TestDatabaseConnection();
|
Utility.TestDatabaseConnection();
|
||||||
}
|
}
|
||||||
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
|
||||||
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
|
|
||||||
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
|
||||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
|
||||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
|
||||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
|
||||||
RegisterEventHandler<EventItemPickup>(OnItemPickup, HookMode.Pre);
|
|
||||||
|
|
||||||
if (hotReload)
|
if (hotReload)
|
||||||
{
|
{
|
||||||
OnMapStart(string.Empty);
|
OnMapStart(string.Empty);
|
||||||
Task.Run(async () =>
|
|
||||||
|
List<CCSPlayerController> players = Utilities.GetPlayers();
|
||||||
|
|
||||||
|
foreach (CCSPlayerController player in players)
|
||||||
{
|
{
|
||||||
for (int i = 1; i <= Server.MaxPlayers; i++)
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString() == "") continue;
|
||||||
|
if (g_playersDatabaseIndex.ContainsKey((int)player.Index)) continue;
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
if (Config.Additional.KnifeEnabled)
|
UserId = player.UserId,
|
||||||
await GetKnifeFromDatabase(i);
|
Index = (int)player.Index,
|
||||||
if (Config.Additional.SkinEnabled)
|
SteamId = player?.SteamID,
|
||||||
await GetWeaponPaintsFromDatabase(i);
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
if (weaponSync != null)
|
||||||
|
{
|
||||||
|
_ = weaponSync!.GetPlayerDatabaseIndex(playerInfo);
|
||||||
}
|
}
|
||||||
});
|
g_knifePickupCount[(int)player!.Index] = 0;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
RegisterListeners();
|
||||||
|
RegisterCommands();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.AdditionalSetting.KnifeEnabled)
|
||||||
SetupMenus();
|
SetupKnifeMenu();
|
||||||
|
if (Config.AdditionalSetting.SkinEnabled)
|
||||||
|
SetupSkinsMenu();
|
||||||
|
|
||||||
|
RegisterListeners();
|
||||||
RegisterCommands();
|
RegisterCommands();
|
||||||
|
|
||||||
|
Utility.LoadSkinsFromFile(ModuleDirectory + "/skins.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnConfigParsed(WeaponPaintsConfig config)
|
public void OnConfigParsed(WeaponPaintsConfig config)
|
||||||
{
|
{
|
||||||
if (!config.GlobalShare)
|
if (!config.GlobalShare)
|
||||||
{
|
{
|
||||||
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("You need to setup Database credentials in config!");
|
// maybe more spam to get attention?
|
||||||
}
|
for (int i = 1; i <= 30; i++)
|
||||||
|
{
|
||||||
|
Console.WriteLine("[WeaponPaints] You need to setup Database credentials in config!");
|
||||||
|
}
|
||||||
|
Logger.LogError("You need to setup Database credentials in config!");
|
||||||
|
throw new Exception("[WeaponPaints] You need to setup Database credentials in config!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// maybe more spam to get attention?
|
||||||
|
for (int i = 1; i <= 30; i++)
|
||||||
|
{
|
||||||
|
Console.WriteLine("[WeaponPaints] GLOBAL SHARE IS NOT SUPPORTED NOW !!");
|
||||||
|
}
|
||||||
|
Logger.LogError("GLOBAL SHARE IS NOT SUPPORTED NOW !!");
|
||||||
|
throw new Exception("[WeaponPaints] GLOBAL SHARE IS NOT SUPPORTED NOW !!");
|
||||||
|
}
|
||||||
|
|
||||||
Config = config;
|
Config = config;
|
||||||
|
_config = config;
|
||||||
|
_localizer = Localizer;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GLOBAL SHARE IS NOT SUPPORTED NOW!
|
||||||
|
*/
|
||||||
|
if (Config.GlobalShare)
|
||||||
|
Config.GlobalShare = false;
|
||||||
|
|
||||||
|
Utility.Config = config;
|
||||||
|
Utility.ShowAd(ModuleVersion);
|
||||||
|
Task.Run(async () => await Utility.CheckVersion(ModuleVersion, Logger));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BuildDatabaseConnectionString()
|
|
||||||
{
|
|
||||||
var builder = new MySqlConnectionStringBuilder
|
|
||||||
{
|
|
||||||
Server = Config.DatabaseHost,
|
|
||||||
UserID = Config.DatabaseUser,
|
|
||||||
Password = Config.DatabasePassword,
|
|
||||||
Database = Config.DatabaseName,
|
|
||||||
Port = (uint)Config.DatabasePort,
|
|
||||||
};
|
|
||||||
|
|
||||||
DatabaseConnectionString = builder.ConnectionString;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TestDatabaseConnection()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var connection = new MySqlConnection(DatabaseConnectionString);
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
if (connection.State != System.Data.ConnectionState.Open)
|
|
||||||
{
|
|
||||||
throw new Exception("Unable connect to database!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception("Unknown mysql exception! " + ex.Message);
|
|
||||||
}
|
|
||||||
CheckDatabaseTables();
|
|
||||||
}
|
|
||||||
|
|
||||||
async private void CheckDatabaseTables()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var connection = new MySqlConnection(DatabaseConnectionString);
|
|
||||||
await connection.OpenAsync();
|
|
||||||
|
|
||||||
using var transaction = await connection.BeginTransactionAsync();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string createTable1 = "CREATE TABLE IF NOT EXISTS `wp_player_skins` (`steamid` varchar(64) NOT NULL, `weapon_defindex` int(6) NOT NULL, `weapon_paint_id` int(6) NOT NULL, `weapon_wear` float NOT NULL DEFAULT 0.0001, `weapon_seed` int(16) NOT NULL DEFAULT 0) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci";
|
|
||||||
string createTable2 = "CREATE TABLE IF NOT EXISTS `wp_player_knife` (`steamid` varchar(64) NOT NULL, `knife` varchar(64) NOT NULL, UNIQUE (`steamid`)) ENGINE = InnoDB";
|
|
||||||
|
|
||||||
await connection.ExecuteAsync(createTable1, transaction: transaction);
|
|
||||||
await connection.ExecuteAsync(createTable2, transaction: transaction);
|
|
||||||
|
|
||||||
await transaction.CommitAsync();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
await transaction.RollbackAsync();
|
|
||||||
throw new Exception("Unable to create tables!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception("Unknown mysql exception! " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: fix for map which change mp_t_default_melee
|
|
||||||
/*private HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
|
|
||||||
{
|
|
||||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
|
||||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
|
||||||
return HookResult.Continue;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public override void Unload(bool hotReload)
|
public override void Unload(bool hotReload)
|
||||||
{
|
{
|
||||||
RemoveGlobalExceptionHandler();
|
|
||||||
base.Unload(hotReload);
|
base.Unload(hotReload);
|
||||||
}
|
}
|
||||||
private void GlobalExceptionHandler(object? sender, FirstChanceExceptionEventArgs @event)
|
|
||||||
{
|
|
||||||
Log(@event.Exception.ToString());
|
|
||||||
}
|
|
||||||
private void SetGlobalExceptionHandler()
|
|
||||||
{
|
|
||||||
AppDomain.CurrentDomain.FirstChanceException += this.GlobalExceptionHandler;
|
|
||||||
}
|
|
||||||
private void RemoveGlobalExceptionHandler()
|
|
||||||
{
|
|
||||||
AppDomain.CurrentDomain.FirstChanceException -= this.GlobalExceptionHandler;
|
|
||||||
}
|
|
||||||
private void RegisterCommands()
|
|
||||||
{
|
|
||||||
AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) => { if (player == null) return; OnCommandWS(player, info); });
|
|
||||||
AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) => { if (player == null) return; OnCommandRefresh(player, info); });
|
|
||||||
if (Config.Additional.CommandKillEnabled)
|
|
||||||
{
|
|
||||||
AddCommand($"css_{Config.Additional.CommandKill}", "kill yourself", (player, info) =>
|
|
||||||
{
|
|
||||||
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
player.PlayerPawn.Value.CommitSuicide(true, false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void IncompatibilityCheck()
|
|
||||||
{
|
|
||||||
// MatchZy
|
|
||||||
if (Directory.Exists(Path.GetDirectoryName(ModuleDirectory) + "/MatchZy"))
|
|
||||||
{
|
|
||||||
Console.WriteLine("[WeaponPaints] Incompatibility found: MatchZy");
|
|
||||||
IsMatchZy = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnMapStart(string mapName)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
|
||||||
// TODO
|
|
||||||
// needed for now
|
|
||||||
AddTimer(2.0f, () =>
|
|
||||||
{
|
|
||||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
|
||||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
|
||||||
IncompatibilityCheck();
|
|
||||||
});
|
|
||||||
if (Config.GlobalShare)
|
|
||||||
GlobalShareConnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GlobalShareConnect()
|
private void GlobalShareConnect()
|
||||||
{
|
{
|
||||||
@@ -261,518 +273,16 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
Task<string> responseBodyTask = response.Content.ReadAsStringAsync();
|
Task<string> responseBodyTask = response.Content.ReadAsStringAsync();
|
||||||
responseBodyTask.Wait();
|
responseBodyTask.Wait();
|
||||||
string responseBody = responseBodyTask.Result;
|
string responseBody = responseBodyTask.Result;
|
||||||
GlobalShareServerId = Int32.Parse(responseBody);
|
GlobalShareServerId = int.Parse(responseBody);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception("Unable to retrieve serverid from GlobalShare!");
|
Logger.LogError("Unable to retrieve serverid from GlobalShare!");
|
||||||
|
throw new Exception("[WeaponPaints] Unable to retrieve serverid from GlobalShare!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.LogInformation("GlobalShare ONLINE!");
|
||||||
Console.WriteLine("[WeaponPaints] GlobalShare ONLINE");
|
Console.WriteLine("[WeaponPaints] GlobalShare ONLINE");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void OnClientPutInServer(int playerSlot)
|
|
||||||
{
|
|
||||||
int playerIndex = playerSlot + 1;
|
|
||||||
Task.Run(async () =>
|
|
||||||
{
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
|
||||||
await GetKnifeFromDatabase(playerIndex);
|
|
||||||
if (Config.Additional.SkinEnabled)
|
|
||||||
await GetWeaponPaintsFromDatabase(playerIndex);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
private void OnClientDisconnect(int playerSlot)
|
|
||||||
{
|
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
|
||||||
if (!player.IsValid || player.IsBot) return;
|
|
||||||
// TODO: Clean up after player
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
|
||||||
g_playersKnife.Remove((int)player.EntityIndex!.Value.Value);
|
|
||||||
if (Config.Additional.SkinEnabled)
|
|
||||||
gPlayerWeaponPaints.Remove(new SteamID(player.SteamID).SteamId64);
|
|
||||||
}
|
|
||||||
|
|
||||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
|
||||||
{
|
|
||||||
var player = @event.Userid;
|
|
||||||
if (!player.IsValid || !player.PlayerPawn.IsValid)
|
|
||||||
{
|
|
||||||
return HookResult.Continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
|
||||||
{
|
|
||||||
GiveKnifeToPlayer(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return HookResult.Continue;
|
|
||||||
}
|
|
||||||
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
|
||||||
{
|
|
||||||
if (!IsMatchZy) return HookResult.Continue;
|
|
||||||
|
|
||||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
|
||||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
|
||||||
|
|
||||||
return HookResult.Continue;
|
|
||||||
}
|
|
||||||
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
|
||||||
{
|
|
||||||
if (@event.Defindex == 42 || @event.Defindex == 59)
|
|
||||||
{
|
|
||||||
CCSPlayerController player = @event.Userid;
|
|
||||||
|
|
||||||
if (player.IsValid && !player.IsBot && @event.Item == "knife")
|
|
||||||
{
|
|
||||||
if (g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)
|
|
||||||
&&
|
|
||||||
g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife")
|
|
||||||
{
|
|
||||||
RefreshPlayerKnife(player, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return HookResult.Continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnEntitySpawned(CEntityInstance entity)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
|
||||||
var designerName = entity.DesignerName;
|
|
||||||
if (!weaponList.Contains(designerName)) return;
|
|
||||||
bool isKnife = false;
|
|
||||||
var weapon = new CBasePlayerWeapon(entity.Handle);
|
|
||||||
|
|
||||||
if (designerName.Contains("knife") || designerName.Contains("bayonet"))
|
|
||||||
{
|
|
||||||
isKnife = true;
|
|
||||||
}
|
|
||||||
Server.NextFrame(() =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!weapon.IsValid) return;
|
|
||||||
if (weapon.OwnerEntity.Value == null) return;
|
|
||||||
if (!weapon.OwnerEntity.Value.EntityIndex.HasValue) return;
|
|
||||||
int weaponOwner = (int)weapon.OwnerEntity.Value.EntityIndex.Value.Value;
|
|
||||||
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
|
||||||
if (!pawn.IsValid) return;
|
|
||||||
var playerIndex = (int)pawn.Controller.Value.EntityIndex!.Value.Value;
|
|
||||||
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
|
||||||
if (player == null || !player.IsValid || player.IsBot) return;
|
|
||||||
// TODO: Remove knife crashes here, needs another solution
|
|
||||||
/*if (isKnife && g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59))
|
|
||||||
{
|
|
||||||
RemoveKnifeFromPlayer(player);
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
var steamId = new SteamID(player.SteamID);
|
|
||||||
if (!gPlayerWeaponPaints.ContainsKey(steamId.SteamId64)) return;
|
|
||||||
if (!gPlayerWeaponPaints[steamId.SteamId64].ContainsKey(weapon.AttributeManager.Item.ItemDefinitionIndex)) return;
|
|
||||||
//Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
|
|
||||||
weapon.AttributeManager.Item.ItemID = 16384;
|
|
||||||
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
|
|
||||||
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
|
|
||||||
weapon.FallbackPaintKit = gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
|
||||||
weapon.FallbackSeed = gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
|
||||||
weapon.FallbackWear = gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
|
||||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
|
||||||
{
|
|
||||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
|
||||||
skeleton.ModelState.MeshGroupMask = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception) { }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
public void GiveKnifeToPlayer(CCSPlayerController? player)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
|
||||||
if (player == null || !player.IsValid) return;
|
|
||||||
|
|
||||||
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
|
|
||||||
{
|
|
||||||
player.GiveNamedItem(knife);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Config.Additional.GiveRandomKnife)
|
|
||||||
{
|
|
||||||
Random random = new Random();
|
|
||||||
int index = random.Next(knifeTypes.Count);
|
|
||||||
player.GiveNamedItem(knifeTypes.Values.ElementAt(index));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void RemoveKnifeFromPlayer(CCSPlayerController? player)
|
|
||||||
{
|
|
||||||
if (player == null || !player.IsValid || !player.PawnIsAlive) return;
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
|
||||||
foreach (var weapon in weapons)
|
|
||||||
{
|
|
||||||
if (weapon.IsValid && weapon.Value.IsValid)
|
|
||||||
{
|
|
||||||
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
|
||||||
if (weapon.Value.DesignerName.Contains("knife"))
|
|
||||||
{
|
|
||||||
weapon.Value.Remove();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void RefreshPlayerKnife(CCSPlayerController? player, bool remove = false)
|
|
||||||
{
|
|
||||||
if (player == null || !player.IsValid || !player.PawnIsAlive) return;
|
|
||||||
|
|
||||||
if (remove == true)
|
|
||||||
RemoveKnifeFromPlayer(player);
|
|
||||||
|
|
||||||
AddTimer(0.2f, () =>
|
|
||||||
{
|
|
||||||
if (!PlayerHasKnife(player))
|
|
||||||
GiveKnifeToPlayer(player);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (Config.Additional.SkinVisibilityFix)
|
|
||||||
{
|
|
||||||
AddTimer(0.2f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
|
|
||||||
AddTimer(0.3f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
|
||||||
AddTimer(0.36f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public bool PlayerHasKnife(CCSPlayerController? player)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.KnifeEnabled) return false;
|
|
||||||
|
|
||||||
if (player == null || !player.IsValid || !player.PawnIsAlive)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
|
||||||
if (weapons == null) return false;
|
|
||||||
foreach (var weapon in weapons)
|
|
||||||
{
|
|
||||||
if (weapon.IsValid && weapon.Value.IsValid)
|
|
||||||
{
|
|
||||||
if (weapon.Value.DesignerName.Contains("knife"))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private void SetupMenus()
|
|
||||||
{
|
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
|
||||||
var giveItemMenu = new ChatMenu(ReplaceTags(Config.Messages.KnifeMenuTitle));
|
|
||||||
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
|
||||||
{
|
|
||||||
string temp = "";
|
|
||||||
if (knifeTypes.TryGetValue(option.Text, out var knife))
|
|
||||||
{
|
|
||||||
g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text];
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenu))
|
|
||||||
{
|
|
||||||
temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenu}".Replace("{KNIFE}", option.Text);
|
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenuKill) && Config.Additional.CommandKillEnabled)
|
|
||||||
{
|
|
||||||
temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenuKill}";
|
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knife));
|
|
||||||
RemoveKnifeFromPlayer(player);
|
|
||||||
AddTimer(0.1f, () => GiveKnifeToPlayer(player));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
foreach (var knife in knifeTypes)
|
|
||||||
{
|
|
||||||
giveItemMenu.AddMenuOption(knife.Key, handleGive);
|
|
||||||
}
|
|
||||||
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) => { if (player == null) return; ChatMenus.OpenMenu(player, giveItemMenu); });
|
|
||||||
}
|
|
||||||
// [ConsoleCommand($"css_{Config.Additional.CommandRefresh}", "refreshskins")]
|
|
||||||
public void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled) return;
|
|
||||||
if (player == null) return;
|
|
||||||
string temp = "";
|
|
||||||
int playerIndex = (int)player.EntityIndex!.Value.Value;
|
|
||||||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
|
||||||
{
|
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
|
||||||
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex));
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
|
||||||
{
|
|
||||||
Task.Run(async () => await GetKnifeFromDatabase(playerIndex));
|
|
||||||
RemoveKnifeFromPlayer(player);
|
|
||||||
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand))
|
|
||||||
{
|
|
||||||
temp = $"{Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand))
|
|
||||||
{
|
|
||||||
temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// [ConsoleCommand($"css_{Config.Additional.CommandSkin}", "weaponskins")]
|
|
||||||
public void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
|
||||||
if (player == null) return;
|
|
||||||
|
|
||||||
string temp = "";
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand))
|
|
||||||
{
|
|
||||||
temp = $"{Config.Prefix} {Config.Messages.WebsiteMessageCommand}";
|
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand))
|
|
||||||
{
|
|
||||||
temp = $"{Config.Prefix} {Config.Messages.SynchronizeMessageCommand}";
|
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand))
|
|
||||||
{
|
|
||||||
temp = $"{Config.Prefix} {Config.Messages.KnifeMessageCommand}";
|
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
|
||||||
{
|
|
||||||
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
|
||||||
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
|
||||||
}
|
|
||||||
private async Task GetWeaponPaintsFromDatabase(int playerIndex)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
|
||||||
if (player == null || !player.IsValid || player.IsBot) return;
|
|
||||||
var steamId = new SteamID(player.SteamID);
|
|
||||||
|
|
||||||
if (Config.GlobalShare)
|
|
||||||
{
|
|
||||||
var values = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "server_id", GlobalShareServerId.ToString() },
|
|
||||||
{ "steamid", steamId.SteamId64.ToString() },
|
|
||||||
{ "skins", "1" }
|
|
||||||
};
|
|
||||||
UriBuilder builder = new UriBuilder(GlobalShareApi);
|
|
||||||
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
|
||||||
|
|
||||||
using (var httpClient = new HttpClient())
|
|
||||||
{
|
|
||||||
httpClient.BaseAddress = GlobalShareApi;
|
|
||||||
var formContent = new FormUrlEncodedContent(values);
|
|
||||||
HttpResponseMessage response = await httpClient.GetAsync(builder.Uri);
|
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
string responseBody = await response.Content.ReadAsStringAsync();
|
|
||||||
JArray jsonArray = JArray.Parse(responseBody);
|
|
||||||
if (jsonArray.Count > 0)
|
|
||||||
{
|
|
||||||
gPlayerWeaponPaints[steamId.SteamId64] = new Dictionary<nint, int>();
|
|
||||||
gPlayerWeaponWear[steamId.SteamId64] = new Dictionary<nint, float>();
|
|
||||||
gPlayerWeaponSeed[steamId.SteamId64] = new Dictionary<nint, int>();
|
|
||||||
|
|
||||||
foreach (var weapon in jsonArray)
|
|
||||||
{
|
|
||||||
int weaponDefIndex = weapon["weapon_defindex"].Value<int>();
|
|
||||||
int weaponPaintId = weapon["weapon_paint_id"].Value<int>();
|
|
||||||
float weaponWear = weapon["weapon_wear"].Value<float>();
|
|
||||||
int weaponSeed = weapon["weapon_seed"].Value<int>();
|
|
||||||
|
|
||||||
gPlayerWeaponPaints[steamId.SteamId64][weaponDefIndex] = weaponPaintId;
|
|
||||||
gPlayerWeaponWear[steamId.SteamId64][weaponDefIndex] = weaponWear;
|
|
||||||
gPlayerWeaponSeed[steamId.SteamId64][weaponDefIndex] = weaponSeed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var connection = new MySqlConnection(DatabaseConnectionString))
|
|
||||||
{
|
|
||||||
await connection.OpenAsync();
|
|
||||||
|
|
||||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
|
||||||
|
|
||||||
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = steamId.SteamId64.ToString() });
|
|
||||||
|
|
||||||
if (PlayerSkins != null && PlayerSkins.AsList().Count > 0)
|
|
||||||
{
|
|
||||||
gPlayerWeaponPaints[steamId.SteamId64] = new Dictionary<nint, int>();
|
|
||||||
gPlayerWeaponWear[steamId.SteamId64] = new Dictionary<nint, float>();
|
|
||||||
gPlayerWeaponSeed[steamId.SteamId64] = new Dictionary<nint, int>();
|
|
||||||
|
|
||||||
PlayerSkins.ToList().ForEach(row =>
|
|
||||||
{
|
|
||||||
int weaponDefIndex = row.weapon_defindex ?? default(int);
|
|
||||||
int weaponPaintId = row.weapon_paint_id ?? default(int);
|
|
||||||
float weaponWear = row.weapon_wear ?? default(float);
|
|
||||||
int weaponSeed = row.weapon_seed ?? default(int);
|
|
||||||
|
|
||||||
gPlayerWeaponPaints[steamId.SteamId64][weaponDefIndex] = weaponPaintId;
|
|
||||||
gPlayerWeaponWear[steamId.SteamId64][weaponDefIndex] = weaponWear;
|
|
||||||
gPlayerWeaponSeed[steamId.SteamId64][weaponDefIndex] = weaponSeed;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log(e.Message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private async Task GetKnifeFromDatabase(int playerIndex)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
|
||||||
if (player == null || !player.IsValid || player.IsBot) return;
|
|
||||||
var steamId = new SteamID(player.SteamID);
|
|
||||||
|
|
||||||
if (Config.GlobalShare)
|
|
||||||
{
|
|
||||||
var values = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "server_id", GlobalShareServerId.ToString() },
|
|
||||||
{ "steamid", steamId.SteamId64.ToString() },
|
|
||||||
{ "knife", "1" }
|
|
||||||
};
|
|
||||||
UriBuilder builder = new UriBuilder(GlobalShareApi);
|
|
||||||
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
|
||||||
|
|
||||||
using (var httpClient = new HttpClient())
|
|
||||||
{
|
|
||||||
httpClient.BaseAddress = GlobalShareApi;
|
|
||||||
var formContent = new FormUrlEncodedContent(values);
|
|
||||||
HttpResponseMessage response = await httpClient.GetAsync(builder.Uri);
|
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
string result = await response.Content.ReadAsStringAsync();
|
|
||||||
if (!string.IsNullOrEmpty(result))
|
|
||||||
{
|
|
||||||
g_playersKnife[playerIndex] = result;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var connection = new MySqlConnection(DatabaseConnectionString))
|
|
||||||
{
|
|
||||||
await connection.OpenAsync();
|
|
||||||
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
|
||||||
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = steamId.SteamId64.ToString() });
|
|
||||||
|
|
||||||
if (PlayerKnife != null)
|
|
||||||
{
|
|
||||||
g_playersKnife[playerIndex] = PlayerKnife;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Log($"{player.PlayerName} has this knife -> {g_playersKnife[playerIndex]}");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log(e.Message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private async Task SyncKnifeToDatabase(int playerIndex, string knife)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
|
||||||
if (player == null || !player.IsValid) return;
|
|
||||||
var steamId = new SteamID(player.SteamID);
|
|
||||||
|
|
||||||
using var connection = new MySqlConnection(DatabaseConnectionString);
|
|
||||||
await connection.OpenAsync();
|
|
||||||
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
|
||||||
await connection.ExecuteAsync(query, new { steamid = steamId.SteamId64.ToString(), newKnife = knife });
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log(e.Message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string ReplaceTags(string message)
|
|
||||||
{
|
|
||||||
if (message.Contains('{'))
|
|
||||||
{
|
|
||||||
string modifiedValue = message;
|
|
||||||
modifiedValue = modifiedValue.Replace("{WEBSITE}", Config.Website);
|
|
||||||
foreach (FieldInfo field in typeof(ChatColors).GetFields())
|
|
||||||
{
|
|
||||||
string pattern = $"{{{field.Name}}}";
|
|
||||||
if (message.Contains(pattern, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
modifiedValue = modifiedValue.Replace(pattern, field.GetValue(null)!.ToString(), StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return modifiedValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void Log(string message)
|
|
||||||
{
|
|
||||||
Console.BackgroundColor = ConsoleColor.DarkGray;
|
|
||||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
|
||||||
Console.WriteLine(message);
|
|
||||||
Console.ResetColor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,19 +5,17 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.148" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.21" />
|
<PackageReference Include="Dapper" Version="2.1.28" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
<PackageReference Include="MySqlConnector" Version="2.3.4" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="CounterStrikeSharp.API">
|
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
|
||||||
<HintPath>deps\CounterStrikeSharp.API.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
331
WeaponSynchronization.cs
Normal file
331
WeaponSynchronization.cs
Normal file
@@ -0,0 +1,331 @@
|
|||||||
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
|
using Dapper;
|
||||||
|
using MySqlConnector;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
|
namespace WeaponPaints
|
||||||
|
{
|
||||||
|
internal class WeaponSynchronization
|
||||||
|
{
|
||||||
|
private readonly WeaponPaintsConfig _config;
|
||||||
|
private readonly string _databaseConnectionString;
|
||||||
|
private readonly Uri _globalShareApi;
|
||||||
|
private readonly int _globalShareServerId;
|
||||||
|
|
||||||
|
internal WeaponSynchronization(string databaseConnectionString, WeaponPaintsConfig config, Uri globalShareApi, int globalShareServerId)
|
||||||
|
{
|
||||||
|
_databaseConnectionString = databaseConnectionString;
|
||||||
|
_config = config;
|
||||||
|
_globalShareApi = globalShareApi;
|
||||||
|
_globalShareServerId = globalShareServerId;
|
||||||
|
}
|
||||||
|
internal async Task GetPlayerDatabaseIndex(PlayerInfo player)
|
||||||
|
{
|
||||||
|
if (player.SteamId == null || player.Index == 0) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = new MySqlConnection(_databaseConnectionString))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
|
||||||
|
string query = "SELECT `id` FROM `wp_users` WHERE `steamid` = @steamid";
|
||||||
|
int? databaseIndex = await connection.QueryFirstOrDefaultAsync<int?>(query, new { steamid = player.SteamId });
|
||||||
|
if (databaseIndex != null)
|
||||||
|
{
|
||||||
|
WeaponPaints.g_playersDatabaseIndex[player.Index] = (int)databaseIndex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string insertQuery = "INSERT INTO `wp_users` (`steamid`) VALUES (@steamid)";
|
||||||
|
await connection.ExecuteAsync(insertQuery, new { steamid = player.SteamId });
|
||||||
|
Console.WriteLine("SQL Insert Query: " + insertQuery);
|
||||||
|
databaseIndex = await connection.QueryFirstOrDefaultAsync<int?>(query, new { steamid = player.SteamId });
|
||||||
|
WeaponPaints.g_playersDatabaseIndex[(int)player.Index] = (int)databaseIndex;
|
||||||
|
}
|
||||||
|
await connection.CloseAsync();
|
||||||
|
|
||||||
|
if (databaseIndex != null)
|
||||||
|
{
|
||||||
|
if (_config.AdditionalSetting.SkinEnabled)
|
||||||
|
await GetWeaponPaintsFromDatabase(player);
|
||||||
|
if (_config.AdditionalSetting.KnifeEnabled)
|
||||||
|
await GetKnifeFromDatabase(player);
|
||||||
|
if (_config.AdditionalSetting.MusicKitEnabled)
|
||||||
|
await GetMusicKitFromDatabase(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utility.Log("GetPlayerDatabaseIndex: " + e.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal async Task GetKnifeFromDatabase(PlayerInfo player)
|
||||||
|
{
|
||||||
|
if (!_config.AdditionalSetting.KnifeEnabled) return;
|
||||||
|
if (player.SteamId == null || player.Index == 0) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_config.GlobalShare)
|
||||||
|
{
|
||||||
|
var values = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "server_id", _globalShareServerId.ToString() },
|
||||||
|
{ "steamid", player.SteamId.ToString()! },
|
||||||
|
{ "knife", "1" }
|
||||||
|
};
|
||||||
|
|
||||||
|
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||||
|
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
||||||
|
|
||||||
|
using (var httpClient = new HttpClient())
|
||||||
|
{
|
||||||
|
httpClient.BaseAddress = _globalShareApi;
|
||||||
|
var formContent = new FormUrlEncodedContent(values);
|
||||||
|
HttpResponseMessage response = await httpClient.GetAsync(builder.Uri);
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
string result = await response.Content.ReadAsStringAsync();
|
||||||
|
if (!string.IsNullOrEmpty(result))
|
||||||
|
{
|
||||||
|
WeaponPaints.g_playersKnife[player.Index] = result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!WeaponPaints.g_playersDatabaseIndex.TryGetValue(player.Index, out _))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var connection = new MySqlConnection(_databaseConnectionString))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
string query = "SELECT `knife` FROM `wp_users_knife` WHERE `user_id` = @userId";
|
||||||
|
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { userId = WeaponPaints.g_playersDatabaseIndex[player.Index] });
|
||||||
|
if (PlayerKnife != null)
|
||||||
|
{
|
||||||
|
WeaponPaints.g_playersKnife[player.Index] = PlayerKnife;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await connection.CloseAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utility.Log("GetKnifeFromDatabase: " + e.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal async Task GetMusicKitFromDatabase(PlayerInfo player)
|
||||||
|
{
|
||||||
|
if (!_config.AdditionalSetting.MusicKitEnabled) return;
|
||||||
|
if (player.SteamId == null || player.Index == 0) return;
|
||||||
|
if (!WeaponPaints.g_playersDatabaseIndex.TryGetValue(player.Index, out _))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = new MySqlConnection(_databaseConnectionString))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
string query = "SELECT `music` FROM `wp_users_music` WHERE `user_id` = @userId";
|
||||||
|
int? PlayerMusitKit = await connection.QueryFirstOrDefaultAsync<int?>(query, new { userId = WeaponPaints.g_playersDatabaseIndex[player.Index] });
|
||||||
|
if (PlayerMusitKit != null)
|
||||||
|
{
|
||||||
|
WeaponPaints.g_playersMusicKit[player.Index] = PlayerMusitKit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await connection.CloseAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utility.Log("GetMusicKitFromDatabase: " + e.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
||||||
|
{
|
||||||
|
if (!_config.AdditionalSetting.SkinEnabled) return;
|
||||||
|
if (player.SteamId == null || player.Index == 0) return;
|
||||||
|
|
||||||
|
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
|
||||||
|
{
|
||||||
|
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new ConcurrentDictionary<ushort, WeaponInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_config.GlobalShare)
|
||||||
|
{
|
||||||
|
var values = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "server_id", _globalShareServerId.ToString() },
|
||||||
|
{ "steamid", player.SteamId.ToString()! },
|
||||||
|
{ "skins", "1" }
|
||||||
|
};
|
||||||
|
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||||
|
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
||||||
|
|
||||||
|
using (var httpClient = new HttpClient())
|
||||||
|
{
|
||||||
|
httpClient.BaseAddress = _globalShareApi;
|
||||||
|
var formContent = new FormUrlEncodedContent(values);
|
||||||
|
HttpResponseMessage response = await httpClient.GetAsync(builder.Uri);
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
string responseBody = await response.Content.ReadAsStringAsync();
|
||||||
|
JArray jsonArray = JArray.Parse(responseBody);
|
||||||
|
if (jsonArray != null && jsonArray.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var weapon in jsonArray)
|
||||||
|
{
|
||||||
|
ushort? weaponDefIndex = weapon["weapon_defindex"]?.Value<ushort>();
|
||||||
|
ushort? weaponPaintId = weapon["weapon_paint_id"]?.Value<ushort>();
|
||||||
|
float? weaponWear = weapon["weapon_wear"]?.Value<float>();
|
||||||
|
ushort? weaponSeed = weapon["weapon_seed"]?.Value<ushort>();
|
||||||
|
|
||||||
|
if (weaponDefIndex != null && weaponPaintId != null && weaponWear != null && weaponSeed != null)
|
||||||
|
{
|
||||||
|
WeaponInfo weaponInfo = new WeaponInfo
|
||||||
|
{
|
||||||
|
Paint = weaponPaintId.Value,
|
||||||
|
Seed = weaponSeed.Value,
|
||||||
|
Wear = weaponWear.Value,
|
||||||
|
NameTag = null
|
||||||
|
};
|
||||||
|
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex.Value] = weaponInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!WeaponPaints.g_playersDatabaseIndex.TryGetValue(player.Index, out _))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var connection = new MySqlConnection(_databaseConnectionString))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
string query = "SELECT `weapon`, `paint`, `wear`, `seed`, `nametag` FROM `wp_users_items` WHERE `user_id` = @userId";
|
||||||
|
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { userId = WeaponPaints.g_playersDatabaseIndex[player.Index] });
|
||||||
|
if (PlayerSkins != null && PlayerSkins.Any())
|
||||||
|
{
|
||||||
|
PlayerSkins.ToList().ForEach(row =>
|
||||||
|
{
|
||||||
|
ushort weaponDefIndex = row.weapon ?? default(ushort);
|
||||||
|
ushort weaponPaintId = row.paint ?? default(ushort);
|
||||||
|
float weaponWear = row.wear ?? default(float);
|
||||||
|
ushort weaponSeed = row.seed ?? default(ushort);
|
||||||
|
string weaponNameTag = row.nametag;
|
||||||
|
|
||||||
|
WeaponInfo weaponInfo = new WeaponInfo
|
||||||
|
{
|
||||||
|
Paint = weaponPaintId,
|
||||||
|
Seed = weaponSeed,
|
||||||
|
Wear = weaponWear,
|
||||||
|
NameTag = weaponNameTag
|
||||||
|
};
|
||||||
|
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex] = weaponInfo;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await connection.CloseAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utility.Log("GetWeaponPaintsFromDatabase: " + e.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal async Task SyncKnifeToDatabase(PlayerInfo player, string knife)
|
||||||
|
{
|
||||||
|
if (!_config.AdditionalSetting.KnifeEnabled) return;
|
||||||
|
if(player == null || player.Index <= 0) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!WeaponPaints.g_playersDatabaseIndex.TryGetValue(player.Index, out _))
|
||||||
|
return;
|
||||||
|
|
||||||
|
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||||
|
await connection.OpenAsync();
|
||||||
|
string query = "INSERT INTO `wp_users_knife` (`user_id`, `knife`) VALUES(@userId, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
||||||
|
await connection.ExecuteAsync(query, new { userId = WeaponPaints.g_playersDatabaseIndex[player.Index], newKnife = knife });
|
||||||
|
await connection.CloseAsync();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utility.Log(e.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal async Task SyncWeaponPaintToDatabase(PlayerInfo player, ushort weaponDefIndex)
|
||||||
|
{
|
||||||
|
if (!_config.AdditionalSetting.SkinEnabled) return;
|
||||||
|
if (player == null || player.Index <= 0) return;
|
||||||
|
|
||||||
|
if (!WeaponPaints.g_playersDatabaseIndex.TryGetValue(player.Index, out var playerDatabaseIndex))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out var playerSavedWeapons))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!playerSavedWeapons.TryGetValue(weaponDefIndex, out var weaponInfo))
|
||||||
|
return;
|
||||||
|
|
||||||
|
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||||
|
string querySql = @"
|
||||||
|
INSERT INTO `wp_users_items`
|
||||||
|
(`user_id`, `weapon`, `paint`, `wear`, `seed`)
|
||||||
|
VALUES
|
||||||
|
(@userId, @weaponDefIndex, @paintId, @wear, @seed)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
paint = @paintId,
|
||||||
|
wear = @wear,
|
||||||
|
seed = @seed";
|
||||||
|
var queryParams = new { weaponDefIndex, userId = playerDatabaseIndex, paintId = weaponInfo.Paint, wear = weaponInfo.Wear, seed = weaponInfo.Seed };
|
||||||
|
await connection.ExecuteAsync(querySql, queryParams);
|
||||||
|
await connection.CloseAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
lang/en.json
Normal file
14
lang/en.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
|
||||||
|
"wp_info_website": "Visit {lime}{0}{default} where you can change skins",
|
||||||
|
"wp_info_refresh": "Type {lime}!wp{default} to synchronize chosen skins",
|
||||||
|
"wp_info_knife": "Type {lime}!knife{default} to open knife menu",
|
||||||
|
"wp_command_cooldown": "{lightred}You can't refresh weapon paints right now",
|
||||||
|
"wp_command_refresh_done": "{lime}Refreshing weapon paints",
|
||||||
|
"wp_knife_menu_select": "You have chosen {lime}{0}{default} as your knife",
|
||||||
|
"wp_knife_menu_kill": "To correctly apply skin for knife, you need to type {lime}!kill{default}",
|
||||||
|
"wp_knife_menu_title": "Knife Menu",
|
||||||
|
"wp_skin_menu_weapon_title": "Weapon Menu",
|
||||||
|
"wp_skin_menu_skin_title": "Select skin for {lime}{0}{default}",
|
||||||
|
"wp_skin_menu_select": "You have chosen {lime}{0}{default} as your skin"
|
||||||
|
}
|
||||||
14
lang/lv.json
Normal file
14
lang/lv.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"wp_prefix": "{lightblue}[Ieroču Ādiņas] {default}",
|
||||||
|
"wp_info_website": "Apmeklē {lime}{0}{default} kur tu vari nomainīt skinus",
|
||||||
|
"wp_info_refresh": "Raksti {lime}!wp{default} lai sinhronizētu izvēlētos skinus",
|
||||||
|
"wp_info_knife": "Raksti {lime}!knife{default} lai atvērtu nažu izvēlni",
|
||||||
|
"wp_command_cooldown": "{lightred} Tu šobrīd nevari atjaunot ieroču skinus...",
|
||||||
|
"wp_command_refresh_done": "{lime}Izvēlētie skini tiek atjaunoti",
|
||||||
|
"wp_knife_menu_select": "Tu esi izvēlējies {lime}{0}{default} nazi",
|
||||||
|
"wp_knife_menu_kill": "Lai pareizi atjaunotu naža skinu, ieraksti čatā {lime}!kill{default}",
|
||||||
|
"wp_knife_menu_title": "Nažu Izvēlne",
|
||||||
|
"wp_skin_menu_weapon_title": "Ieroču Izvēlne",
|
||||||
|
"wp_skin_menu_skin_title": "Izvēlies skinu ierocim: {lime}{0}{default}",
|
||||||
|
"wp_skin_menu_select": "Tu esi izvēlējies {lime}{0}{default} kā savu skinu"
|
||||||
|
}
|
||||||
14
lang/pl.json
Normal file
14
lang/pl.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
|
||||||
|
"wp_info_website": "Odwiedź {lime}{0}{default} gdzie będziesz mógł ustawić skiny",
|
||||||
|
"wp_info_refresh": "Wpisz {lime}!wp{default} aby zsynchronizować swoje skiny",
|
||||||
|
"wp_info_knife": "Wpisz {lime}!knife{default} aby wy<77>wietlić menu no<6E>y",
|
||||||
|
"wp_command_cooldown": "{lightred}Odczekaj chwilę przed wykonaniem tej komendy...",
|
||||||
|
"wp_command_refresh_done": "{lime}Pomyslnie zsynchronizowano twoje skiny",
|
||||||
|
"wp_knife_menu_select": "Wybrałeś {lime}{0}{default} jako swój nóż",
|
||||||
|
"wp_knife_menu_kill": "Do prawidłowego zastosowania noża użyj {lime}!kill{default}",
|
||||||
|
"wp_knife_menu_title": "Menu noży",
|
||||||
|
"wp_skin_menu_weapon_title": "Menu broni",
|
||||||
|
"wp_skin_menu_skin_title": "Wybierz skin dla {lime}{0}{default}",
|
||||||
|
"wp_skin_menu_select": "Wybrałeś {lime}{0}{default} jako swój skin"
|
||||||
|
}
|
||||||
14
lang/pt-BR.json
Normal file
14
lang/pt-BR.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
|
||||||
|
"wp_info_website": "Visite {lime}{0}{default} para mudar suas skins e faca",
|
||||||
|
"wp_info_refresh": "Digite {lime}!wp{default} para sincronizar as suas skins",
|
||||||
|
"wp_info_knife": "Digite {lime}!knife{default} para abrir o menu de facas",
|
||||||
|
"wp_command_cooldown": "{lightred}Você não pode atualizar as skins das armas agora",
|
||||||
|
"wp_command_refresh_done": "{lime}Sincronizando as suas skins",
|
||||||
|
"wp_knife_menu_select": "Você escolheu {lime}{0}{default} como sua faca",
|
||||||
|
"wp_knife_menu_kill": "Para aplicar corretamente a skin da faca, você precisa digitar {lime}!kill{default}",
|
||||||
|
"wp_knife_menu_title": "Menu de Facas",
|
||||||
|
"wp_skin_menu_weapon_title": "Menu de Armas",
|
||||||
|
"wp_skin_menu_skin_title": "Selecionou a skin para {lime}{0}{default}",
|
||||||
|
"wp_skin_menu_select": "Você escolheu {lime}{0}{default} como sua skin"
|
||||||
|
}
|
||||||
14
lang/pt-PT.json
Normal file
14
lang/pt-PT.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
|
||||||
|
"wp_info_website": "Visita {lime}{0}{default} onde podes mudar as tuas skins",
|
||||||
|
"wp_info_refresh": "Digita {lime}!wp{default} para sincronizar as tuas skins",
|
||||||
|
"wp_info_knife": "Digita {lime}!knife{default} para abrir o menu de facas",
|
||||||
|
"wp_command_cooldown": "{lightred}Tu não podes sincronizar agora as tuas skins",
|
||||||
|
"wp_command_refresh_done": "{lime}Sincronizando as tuas skins",
|
||||||
|
"wp_knife_menu_select": "Tu escolheste {lime}{0}{default} como a tua faca",
|
||||||
|
"wp_knife_menu_kill": "Para aplicar corretamente a skins para a tua faca, digita {lime}!kill{default}",
|
||||||
|
"wp_knife_menu_title": "Menu Facas",
|
||||||
|
"wp_skin_menu_weapon_title": "Menu de Armas",
|
||||||
|
"wp_skin_menu_skin_title": "Escolhe a skin para {lime}{0}{default}",
|
||||||
|
"wp_skin_menu_select": "Tu escolheste {lime}{0}{default} como a tua skin"
|
||||||
|
}
|
||||||
14
lang/ru.json
Normal file
14
lang/ru.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
|
||||||
|
"wp_info_website": "Посетите сайт {lime}{0},{default} чтобы выбрать скин",
|
||||||
|
"wp_info_refresh": "Наберите в чат {lime}!wp{default} для синхронизации выбранных скинов",
|
||||||
|
"wp_info_knife": "Наберите в чат {lime}!knife,{default} чтобы выбрать нож",
|
||||||
|
"wp_command_cooldown": "{lightred}Вы не можете выбрать оружие прямо сейчас",
|
||||||
|
"wp_command_refresh_done": "{lime}Обновление скинов для оружия",
|
||||||
|
"wp_knife_menu_select": "Вы выбрали {lime}{0}{default} скин для ножа",
|
||||||
|
"wp_knife_menu_kill": "Чтобы правильно применить скин для ножа, набери в чат {lime}!kill{default}",
|
||||||
|
"wp_knife_menu_title": "Меню ножей",
|
||||||
|
"wp_skin_menu_weapon_title": "Меню оружия",
|
||||||
|
"wp_skin_menu_skin_title": "Выберите скин для {lime}{0}{default}",
|
||||||
|
"wp_skin_menu_select": "Вы выбрали {lime}{0}{default} скина для оружия"
|
||||||
|
}
|
||||||
14
lang/tr.json
Normal file
14
lang/tr.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
|
||||||
|
"wp_info_website": "Görünümleri değiştirebileceğiniz {lime}{0}{default} adresini ziyaret edin",
|
||||||
|
"wp_info_refresh": "Seçilen kaplamyı senkronize etmek için {lime}!wp{default} yazın",
|
||||||
|
"wp_info_knife": "Bıçak menüsünü açmak için {lime}!knife{default} yazın",
|
||||||
|
"wp_command_cooldown": "{lightred}Şu anda silah kaplamasını yenileyemezsiniz",
|
||||||
|
"wp_command_refresh_done": "{lime}Silah kaplaması yenileniyor",
|
||||||
|
"wp_knife_menu_select": "Bıçağınız olarak {lime}{0}{default} seçtiniz",
|
||||||
|
"wp_knife_menu_kill": "Bıçak için doğru şekilde kaplama uygulamak için {lime}!kill{default} yazmanız gerekir",
|
||||||
|
"wp_knife_menu_title": "Bıçak Menüsü",
|
||||||
|
"wp_skin_menu_weapon_title": "Silah Menüsü",
|
||||||
|
"wp_skin_menu_skin_title": "Select skin for {lime}{0}{default}",
|
||||||
|
"wp_skin_menu_select": "Teniniz olarak {lime}{0}{default} seçtiniz"
|
||||||
|
}
|
||||||
14
lang/ua.json
Normal file
14
lang/ua.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"wp_prefix": "{lightblue}[WeaponPaints] {default}",
|
||||||
|
"wp_info_website": "Відвідайте веб-сайт {lime}{0},{default} щоб вибрати скин",
|
||||||
|
"wp_info_refresh": "Напишіть у чат {lime}!wp{default} для синхронізації вибраних скинів",
|
||||||
|
"wp_info_knife": "Напишіть у чат {lime}!knife,{default} щоб вибрати ніж",
|
||||||
|
"wp_command_cooldown": "{lightred}Ви не можете вибрати зброю зараз",
|
||||||
|
"wp_command_refresh_done": "{lime}Оновлення скинів для зброї",
|
||||||
|
"wp_knife_menu_select": "Ви вибрали скин {lime}{0}{default} для ножа",
|
||||||
|
"wp_knife_menu_kill": "Щоб правильно застосувати скин для ножа, напишіть у чат {lime}!kill{default}",
|
||||||
|
"wp_knife_menu_title": "Меню ножів",
|
||||||
|
"wp_skin_menu_weapon_title": "Меню зброї",
|
||||||
|
"wp_skin_menu_skin_title": "Виберіть скин для {lime}{0}{default}",
|
||||||
|
"wp_skin_menu_select": "Ви вибрали скин {lime}{0}{default} для зброї"
|
||||||
|
}
|
||||||
14
lang/zh-cn.json
Normal file
14
lang/zh-cn.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"wp_prefix": "{lightblue}[武器皮肤] {default}",
|
||||||
|
"wp_info_website": "在线访问 {lime}{0}{default} 更改你的武器皮肤",
|
||||||
|
"wp_info_refresh": "输入 {lime}!wp{default} 进行在线皮肤同步",
|
||||||
|
"wp_info_knife": "输入 {lime}!knife{default} 打开刀菜单",
|
||||||
|
"wp_command_cooldown": "{lightred}皮肤同步刷新冷却中",
|
||||||
|
"wp_command_refresh_done": "{lime}刷新武器皮肤中",
|
||||||
|
"wp_knife_menu_select": "你选择了 {lime}{0}{default} 作为你的刀",
|
||||||
|
"wp_knife_menu_kill": "如需完全应用皮肤到刀上, 你需要输入 {lime}!kill{default} 自杀来进行刷新",
|
||||||
|
"wp_knife_menu_title": "刀菜单",
|
||||||
|
"wp_skin_menu_weapon_title": "武器菜单",
|
||||||
|
"wp_skin_menu_skin_title": "选择 {lime}{0}{default} 的皮肤",
|
||||||
|
"wp_skin_menu_select": "你选择了 {lime}{0}{default} 作为你的皮肤"
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ define('DB_NAME', '');
|
|||||||
define('DB_USER', '');
|
define('DB_USER', '');
|
||||||
define('DB_PASS', '');
|
define('DB_PASS', '');
|
||||||
|
|
||||||
|
define('WEB_STYLE_DARK', true);
|
||||||
|
|
||||||
define('STEAM_API_KEY', '');
|
define('STEAM_API_KEY', '');
|
||||||
define('STEAM_DOMAIN_NAME', '');
|
define('STEAM_DOMAIN_NAME', '');
|
||||||
define('STEAM_LOGOUT_PAGE', '');
|
define('STEAM_LOGOUT_PAGE', '');
|
||||||
|
|||||||
@@ -1,22 +1,66 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Class DataBase
|
||||||
|
*
|
||||||
|
* This class handles database operations using PDO.
|
||||||
|
*/
|
||||||
class DataBase {
|
class DataBase {
|
||||||
|
/**
|
||||||
|
* @var PDO The PDO instance for database connection.
|
||||||
|
*/
|
||||||
private $PDO;
|
private $PDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor method to initialize the database connection.
|
||||||
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->PDO = new PDO("mysql:host=".DB_HOST."; port=".DB_PORT."; dbname=".DB_NAME, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
|
try {
|
||||||
}
|
// Establish a connection to the database using PDO
|
||||||
public function select($query, $bindings = []) {
|
$this->PDO = new PDO(
|
||||||
$STH = $this->PDO->prepare($query);
|
"mysql:host=".DB_HOST.";port=".DB_PORT.";dbname=".DB_NAME,
|
||||||
$STH->execute($bindings);
|
DB_USER,
|
||||||
$result = $STH->fetchAll(PDO::FETCH_ASSOC);
|
DB_PASS
|
||||||
$result ??= false;
|
);
|
||||||
return $result;
|
// Set the connection to use utf8 encoding
|
||||||
|
$this->PDO->exec("SET NAMES utf8");
|
||||||
|
}
|
||||||
|
catch(PDOException $ex) {
|
||||||
|
// Display error message if connection fails
|
||||||
|
echo "<div style='display: flex; flex-direction: column;align-items: center;justify-content: center;text-align: center;'><h2>Problem with database!</h2>";
|
||||||
|
die("<pre style='padding: 10px;text-wrap: balance; border: 2px solid #ed6bd3;background: #252525; color: #ed6bd3; width: 50%;'>" . $ex . "</pre>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function query($query, $bindings = []){
|
/**
|
||||||
|
* Perform a SELECT query on the database.
|
||||||
|
*
|
||||||
|
* @param string $query The SQL query to execute.
|
||||||
|
* @param array $bindings An associative array of parameters and their values.
|
||||||
|
* @return array|false Returns an array of rows as associative arrays or false if no results are found.
|
||||||
|
*/
|
||||||
|
public function select($query, $bindings = array()) {
|
||||||
|
// Prepare and execute the SQL query
|
||||||
|
$STH = $this->PDO->prepare($query);
|
||||||
|
$STH->execute($bindings);
|
||||||
|
|
||||||
|
// Fetch the results as associative arrays
|
||||||
|
$result = $STH->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
if ($result === false) {
|
||||||
|
$result = array(); // Set $result to an empty array if no results found
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a non-query SQL statement on the database.
|
||||||
|
*
|
||||||
|
* @param string $query The SQL query to execute.
|
||||||
|
* @param array $bindings An associative array of parameters and their values.
|
||||||
|
* @return bool Returns true on success or false on failure.
|
||||||
|
*/
|
||||||
|
public function query($query, $bindings = array()) {
|
||||||
|
// Prepare and execute the SQL query
|
||||||
$STH = $this->PDO->prepare($query);
|
$STH = $this->PDO->prepare($query);
|
||||||
return $STH->execute($bindings);
|
return $STH->execute($bindings);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
71
website/class/header.php
Normal file
71
website/class/header.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
// Set security headers to enhance security
|
||||||
|
header("X-Frame-Options: SAMEORIGIN");
|
||||||
|
header("X-XSS-Protection: 1; mode=block");
|
||||||
|
header("X-Content-Type-Options: nosniff");
|
||||||
|
header("Referrer-Policy: no-referrer-when-downgrade");
|
||||||
|
header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://code.jquery.com; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; img-src 'self' data: https://cdn.jsdelivr.net https://steamcommunity-a.akamaihd.net https://raw.githubusercontent.com;");
|
||||||
|
|
||||||
|
|
||||||
|
// Include necessary classes and files
|
||||||
|
require 'class/config.php';
|
||||||
|
require 'class/database.php';
|
||||||
|
require 'steamauth/steamauth.php';
|
||||||
|
require 'class/utils.php';
|
||||||
|
|
||||||
|
// Create a database instance
|
||||||
|
$db = new DataBase();
|
||||||
|
|
||||||
|
// Check if the user is logged in
|
||||||
|
if (isset($_SESSION['steamid'])) {
|
||||||
|
// Insert or update user's Steam ID in the database
|
||||||
|
$steamid = $_SESSION['steamid'];
|
||||||
|
$db->query("INSERT INTO `wp_users` (`steamid`) VALUES ('{$steamid}') ON DUPLICATE KEY UPDATE `updated_at` = CURRENT_TIMESTAMP");
|
||||||
|
|
||||||
|
// Get user's database index
|
||||||
|
$userInfoQuery = $db->select("SELECT `id` FROM `wp_users` WHERE `steamid` = :steamid", ["steamid" => $steamid]);
|
||||||
|
$_SESSION['userDbIndex'] = $userDbIndex = (int)$userInfoQuery[0]['id'];
|
||||||
|
|
||||||
|
// Get weapons and skins information
|
||||||
|
$weapons = UtilsClass::getWeaponsFromArray();
|
||||||
|
$skins = UtilsClass::skinsFromJson();
|
||||||
|
|
||||||
|
// Retrieve user's selected skins and knife
|
||||||
|
$querySelected = $db->select("SELECT `weapon`, `paint`, `wear`, `seed`, `nametag` FROM `wp_users_items` WHERE `user_id` = :user_id", ["user_id" => $userDbIndex]);
|
||||||
|
$selectedSkins = UtilsClass::getSelectedSkins($querySelected);
|
||||||
|
$selectedKnifeResult = $db->select("SELECT `knife` FROM `wp_users_knife` WHERE `user_id` = :user_id", ["user_id" => $userDbIndex]);
|
||||||
|
|
||||||
|
// Determine user's selected knife or set default knife
|
||||||
|
if (!empty($selectedKnifeResult)) {
|
||||||
|
$selectedKnife = $selectedKnifeResult[0]['knife'];
|
||||||
|
} else {
|
||||||
|
$selectedKnife = "weapon_knife";
|
||||||
|
}
|
||||||
|
$knifes = UtilsClass::getKnifeTypes();
|
||||||
|
|
||||||
|
// Handle form submission
|
||||||
|
if (isset($_POST['forma'])) {
|
||||||
|
$ex = explode("-", $_POST['forma']);
|
||||||
|
|
||||||
|
// Handle knife selection
|
||||||
|
if ($ex[0] == "knife") {
|
||||||
|
$db->query("INSERT INTO `wp_users_knife` (`user_id`, `knife`) VALUES(:user_id, :knife) ON DUPLICATE KEY UPDATE `knife` = :knife", ["user_id" => $userDbIndex, "knife" => $knifes[$ex[1]]['weapon_name']]);
|
||||||
|
} else {
|
||||||
|
// Handle skin selection
|
||||||
|
if (array_key_exists($ex[1], $skins[$ex[0]]) && isset($_POST['wear']) && $_POST['wear'] >= 0.00 && $_POST['wear'] <= 1.00 && isset($_POST['seed'])) {
|
||||||
|
$wear = floatval($_POST['wear']); // wear
|
||||||
|
$seed = intval($_POST['seed']); // seed
|
||||||
|
|
||||||
|
// Check if the skin is already selected and update or insert accordingly
|
||||||
|
if (array_key_exists($ex[0], $selectedSkins)) {
|
||||||
|
$db->query("UPDATE wp_users_items SET paint = :weapon_paint_id, wear = :weapon_wear, seed = :weapon_seed WHERE user_id = :user_id AND weapon = :weapon_defindex", ["user_id" => $userDbIndex, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1], "weapon_wear" => $wear, "weapon_seed" => $seed]);
|
||||||
|
} else {
|
||||||
|
$db->query("INSERT INTO wp_users_items (`user_id`, `weapon`, `paint`, `wear`, `seed`) VALUES (:user_id, :weapon_defindex, :weapon_paint_id, :weapon_wear, :weapon_seed)", ["user_id" => $userDbIndex, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1], "weapon_wear" => $wear, "weapon_seed" => $seed]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Redirect to the same page after form submission
|
||||||
|
header("Location: {$_SERVER['PHP_SELF']}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -1,94 +1,112 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Class UtilsClass
|
||||||
|
*
|
||||||
|
* Provides utility methods for handling skin and weapon data.
|
||||||
|
*/
|
||||||
class UtilsClass
|
class UtilsClass
|
||||||
{
|
{
|
||||||
public static function skinsFromJson(): array
|
/**
|
||||||
|
* Retrieve skins data from the JSON file.
|
||||||
|
*
|
||||||
|
* @return array An associative array containing skin data.
|
||||||
|
*/
|
||||||
|
public static function skinsFromJson()
|
||||||
{
|
{
|
||||||
$skins = [];
|
$skins = array();
|
||||||
$json = json_decode(file_get_contents(__DIR__ . "/../data/skins.json"), true);
|
$jsonFilePath = __DIR__ . "/../data/skins.json";
|
||||||
|
|
||||||
foreach ($json as $skin) {
|
if (file_exists($jsonFilePath) && is_readable($jsonFilePath)) {
|
||||||
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = [
|
$json = json_decode(file_get_contents($jsonFilePath), true);
|
||||||
'weapon_name' => $skin['weapon_name'],
|
|
||||||
'paint_name' => $skin['paint_name'],
|
foreach ($json as $skin) {
|
||||||
'image_url' => $skin['image'],
|
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = array(
|
||||||
];
|
'weapon_name' => $skin['weapon_name'],
|
||||||
|
'paint_name' => $skin['paint_name'],
|
||||||
|
'image_url' => $skin['image'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Handle file not found or unreadable error
|
||||||
|
// You can throw an exception or log an error message
|
||||||
}
|
}
|
||||||
|
|
||||||
return $skins;
|
return $skins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve weapons data from the skin data array.
|
||||||
|
*
|
||||||
|
* @return array An associative array containing weapon data.
|
||||||
|
*/
|
||||||
public static function getWeaponsFromArray()
|
public static function getWeaponsFromArray()
|
||||||
{
|
{
|
||||||
$weapons = [];
|
$weapons = array();
|
||||||
$temp = self::skinsFromJson();
|
$skinsData = self::skinsFromJson();
|
||||||
|
|
||||||
foreach ($temp as $key => $value) {
|
foreach ($skinsData as $key => $value) {
|
||||||
if (key_exists($key, $weapons))
|
$weapons[$key] = array(
|
||||||
continue;
|
|
||||||
|
|
||||||
$weapons[$key] = [
|
|
||||||
'weapon_name' => $value[0]['weapon_name'],
|
'weapon_name' => $value[0]['weapon_name'],
|
||||||
'paint_name' => $value[0]['paint_name'],
|
'paint_name' => $value[0]['paint_name'],
|
||||||
'image_url' => $value[0]['image_url'],
|
'image_url' => $value[0]['image_url'],
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $weapons;
|
return $weapons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve knife types from the weapon data array.
|
||||||
|
*
|
||||||
|
* @return array An associative array containing knife types data.
|
||||||
|
*/
|
||||||
public static function getKnifeTypes()
|
public static function getKnifeTypes()
|
||||||
{
|
{
|
||||||
$knifes = [];
|
$knifes = array();
|
||||||
$temp = self::getWeaponsFromArray();
|
$weaponsData = self::getWeaponsFromArray();
|
||||||
|
|
||||||
foreach ($temp as $key => $weapon) {
|
$allowedKnifeKeys = array(
|
||||||
if (
|
500, 503, 505, 506, 507, 508, 509, 512, 514, 515,
|
||||||
!in_array($key, [
|
516, 517, 518, 519, 520, 521, 522, 523, 525
|
||||||
500,
|
);
|
||||||
503,
|
|
||||||
505,
|
|
||||||
506,
|
|
||||||
507,
|
|
||||||
508,
|
|
||||||
509,
|
|
||||||
512,
|
|
||||||
514,
|
|
||||||
515,
|
|
||||||
516,
|
|
||||||
517,
|
|
||||||
518,
|
|
||||||
519,
|
|
||||||
520,
|
|
||||||
521,
|
|
||||||
522,
|
|
||||||
523,
|
|
||||||
525
|
|
||||||
])
|
|
||||||
)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$knifes[$key] = [
|
foreach ($weaponsData as $key => $weapon) {
|
||||||
'weapon_name' => $weapon['weapon_name'],
|
if (in_array($key, $allowedKnifeKeys)) {
|
||||||
'paint_name' => rtrim(explode("|", $weapon['paint_name'])[0]),
|
$knifes[$key] = array(
|
||||||
'image_url' => $weapon['image_url'],
|
'weapon_name' => $weapon['weapon_name'],
|
||||||
];
|
'paint_name' => rtrim(explode("|", $weapon['paint_name'])[0]),
|
||||||
$knifes[0] = [
|
'image_url' => $weapon['image_url'],
|
||||||
'weapon_name' => "weapon_knife",
|
);
|
||||||
'paint_name' => "Default knife",
|
}
|
||||||
'image_url' => "https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/website/img/skins/weapon_knife.png",
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add default knife
|
||||||
|
$knifes[0] = array(
|
||||||
|
'weapon_name' => "weapon_knife",
|
||||||
|
'paint_name' => "Default knife",
|
||||||
|
'image_url' => "https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/website/img/skins/weapon_knife.png",
|
||||||
|
);
|
||||||
|
|
||||||
ksort($knifes);
|
ksort($knifes);
|
||||||
return $knifes;
|
return $knifes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSelectedSkins(array $temp)
|
/**
|
||||||
|
* Retrieve selected skins data from the database result.
|
||||||
|
*
|
||||||
|
* @param array $temp An array containing the selected skins data.
|
||||||
|
* @return array An associative array containing selected skins data.
|
||||||
|
*/
|
||||||
|
public static function getSelectedSkins($temp)
|
||||||
{
|
{
|
||||||
$selected = [];
|
$selected = array();
|
||||||
|
|
||||||
foreach ($temp as $weapon) {
|
foreach ($temp as $weapon) {
|
||||||
$selected[$weapon['weapon_defindex']] = $weapon['weapon_paint_id'];
|
$selected[$weapon['weapon']] = array(
|
||||||
|
'weapon_paint_id' => $weapon['paint'],
|
||||||
|
'weapon_seed' => $weapon['seed'],
|
||||||
|
'weapon_wear' => $weapon['wear'],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $selected;
|
return $selected;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,145 +1,36 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'class/config.php';
|
require 'class/header.php';
|
||||||
require_once 'class/database.php';
|
|
||||||
require_once 'steamauth/steamauth.php';
|
|
||||||
require_once 'class/utils.php';
|
|
||||||
|
|
||||||
|
|
||||||
$db = new DataBase();
|
|
||||||
if (isset($_SESSION['steamid'])) {
|
|
||||||
|
|
||||||
include('steamauth/userInfo.php');
|
|
||||||
$steamid = $steamprofile['steamid'];
|
|
||||||
|
|
||||||
$weapons = UtilsClass::getWeaponsFromArray();
|
|
||||||
$skins = UtilsClass::skinsFromJson();
|
|
||||||
$querySelected = $query3 = $db->select("SELECT `weapon_defindex`, `weapon_paint_id` FROM `wp_player_skins` WHERE `wp_player_skins`.`steamid` = :steamid", ["steamid" => $steamid]);
|
|
||||||
$selectedSkins = UtilsClass::getSelectedSkins($querySelected);
|
|
||||||
$selectedKnife = $db->select("SELECT * FROM `wp_player_knife` WHERE `wp_player_knife`.`steamid` = :steamid", ["steamid" => $steamid])[0];
|
|
||||||
$knifes = UtilsClass::getKnifeTypes();
|
|
||||||
|
|
||||||
if (isset($_POST['forma'])) {
|
|
||||||
$ex = explode("-", $_POST['forma']);
|
|
||||||
|
|
||||||
if ($ex[0] == "knife") {
|
|
||||||
$db->query("INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(:steamid, :knife) ON DUPLICATE KEY UPDATE `knife` = :knife", ["steamid" => $steamid, "knife" => $knifes[$ex[1]]['weapon_name']]);
|
|
||||||
} else {
|
|
||||||
if (array_key_exists($ex[1], $skins[$ex[0]])) {
|
|
||||||
if (array_key_exists($ex[0], $selectedSkins)) {
|
|
||||||
$db->query("UPDATE wp_player_skins SET weapon_paint_id = :weapon_paint_id WHERE steamid = :steamid AND weapon_defindex = :weapon_defindex", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1]]);
|
|
||||||
} else {
|
|
||||||
$db->query("INSERT INTO wp_player_skins (`steamid`, `weapon_defindex`, `weapon_paint_id`) VALUES (:steamid, :weapon_defindex, :weapon_paint_id)", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1]]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
header("Location: index.php");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en" <?php if (WEB_STYLE_DARK) echo 'data-bs-theme="dark"' ?>>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||||
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||||
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js"></script>
|
||||||
crossorigin="anonymous"></script>
|
<link rel="stylesheet" href="style.css">
|
||||||
<link rel="stylesheet" href="style.css">
|
<title>CS2 Simple Weapon Paints</title>
|
||||||
<title>CS2 Simple Weapon Paints</title>
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<?php if (!isset($_SESSION['steamid'])) : ?>
|
||||||
<?php
|
<div class='bg-primary'><h2>To choose weapon paints loadout, you need to <?php loginbutton("rectangle"); ?></h2></div>
|
||||||
if (!isset($_SESSION['steamid'])) {
|
<?php else : ?>
|
||||||
echo "<div class='bg-primary'><h2>To choose weapon paints loadout, you need to ";
|
<div class='bg-primary'><h2>Your current weapon skin loadout <a class='btn btn-danger' href='<?php echo $_SERVER['PHP_SELF']; ?>?logout'>Logout</a></h2> </div>
|
||||||
loginbutton("rectangle");
|
<div class='card-group mt-2'>
|
||||||
echo "</h2></div>";
|
<!-- Display user's selected knife -->
|
||||||
} else {
|
<?php require_once 'view/display_knife.php'; ?>
|
||||||
echo "<div class='bg-primary'>Your current weapon skin loadout<form action='' method='get'><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form></div>";
|
<!-- Display user's selected skins for different weapons -->
|
||||||
echo "<div class='card-group mt-2'>";
|
<?php require_once 'view/display_weapons.php'; ?>
|
||||||
?>
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
<div class="col-sm-2">
|
<!-- Footer section -->
|
||||||
<div class="card text-center mb-3 border border-primary">
|
<div class="container">
|
||||||
<div class="card-body">
|
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
|
||||||
<?php
|
<div class="col-md-4 d-flex align-items-center">
|
||||||
$actualKnife = $knifes[0];
|
<span class="mb-3 mb-md-0 text-body-secondary">© 2024 <a href="https://github.com/Nereziel/cs2-WeaponPaints">Nereziel/cs2-WeaponPaints</a></span>
|
||||||
foreach ($knifes as $knife) {
|
</div>
|
||||||
if ($selectedKnife['knife'] == $knife['weapon_name']) {
|
</footer>
|
||||||
$actualKnife = $knife;
|
</div>
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "<div class='card-header'>";
|
|
||||||
echo "<h6 class='card-title item-name'>Knife type</h6>";
|
|
||||||
echo "<h5 class='card-title item-name'>{$actualKnife["paint_name"]}</h5>";
|
|
||||||
echo "</div>";
|
|
||||||
echo "<img src='{$actualKnife["image_url"]}' class='skin-image'>";
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
<div class="card-footer">
|
|
||||||
<form action="" method="POST">
|
|
||||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
|
||||||
<option>Select knife</option>
|
|
||||||
<?php
|
|
||||||
foreach ($knifes as $knifeKey => $knife) {
|
|
||||||
if ($selectedKnife['knife'] == $knife['weapon_name'])
|
|
||||||
echo "<option selected value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
|
||||||
else
|
|
||||||
echo "<option value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</select>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
foreach ($weapons as $defindex => $default) { ?>
|
|
||||||
<div class="col-sm-2">
|
|
||||||
<div class="card text-center mb-3">
|
|
||||||
<div class="card-body">
|
|
||||||
<?php
|
|
||||||
if (array_key_exists($defindex, $selectedSkins)) {
|
|
||||||
echo "<div class='card-header'>";
|
|
||||||
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]]["paint_name"]}</h5>";
|
|
||||||
echo "</div>";
|
|
||||||
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]]['image_url']}' class='skin-image'>";
|
|
||||||
} else {
|
|
||||||
echo "<div class='card-header'>";
|
|
||||||
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
|
||||||
echo "</div>";
|
|
||||||
echo "<img src='{$default["image_url"]}' class='skin-image'>";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
<div class="card-footer">
|
|
||||||
<form action="" method="POST">
|
|
||||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
|
||||||
<option>Select skin</option>
|
|
||||||
<?php
|
|
||||||
foreach ($skins[$defindex] as $paintKey => $paint) {
|
|
||||||
if (array_key_exists($defindex, $selectedSkins) && $selectedSkins[$defindex] == $paintKey)
|
|
||||||
echo "<option selected value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
|
||||||
else
|
|
||||||
echo "<option value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</select>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?php } ?>
|
|
||||||
<?php } ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 126 KiB |
21
website/steamauth/licence.txt
Normal file
21
website/steamauth/licence.txt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 Benjamin Smith
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
ob_start();
|
//ob_start();
|
||||||
session_start();
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
function logoutbutton() {
|
function logoutbutton() {
|
||||||
echo "<form action='' method='get'><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form>"; //logout button
|
echo "<form><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form>"; //logout button
|
||||||
}
|
}
|
||||||
|
|
||||||
function loginbutton($buttonstyle = "square") {
|
function loginbutton($buttonstyle = "square") {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ if (empty($_SESSION['steam_uptodate']) or empty($_SESSION['steam_personaname']))
|
|||||||
$_SESSION['steam_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
|
$_SESSION['steam_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
|
||||||
$_SESSION['steam_profilestate'] = $content['response']['players'][0]['profilestate'];
|
$_SESSION['steam_profilestate'] = $content['response']['players'][0]['profilestate'];
|
||||||
$_SESSION['steam_personaname'] = $content['response']['players'][0]['personaname'];
|
$_SESSION['steam_personaname'] = $content['response']['players'][0]['personaname'];
|
||||||
$_SESSION['steam_lastlogoff'] = $content['response']['players'][0]['lastlogoff'];
|
|
||||||
$_SESSION['steam_profileurl'] = $content['response']['players'][0]['profileurl'];
|
$_SESSION['steam_profileurl'] = $content['response']['players'][0]['profileurl'];
|
||||||
$_SESSION['steam_avatar'] = $content['response']['players'][0]['avatar'];
|
$_SESSION['steam_avatar'] = $content['response']['players'][0]['avatar'];
|
||||||
$_SESSION['steam_avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
|
$_SESSION['steam_avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
|
||||||
@@ -27,7 +26,6 @@ $steamprofile['steamid'] = $_SESSION['steam_steamid'];
|
|||||||
$steamprofile['communityvisibilitystate'] = $_SESSION['steam_communityvisibilitystate'];
|
$steamprofile['communityvisibilitystate'] = $_SESSION['steam_communityvisibilitystate'];
|
||||||
$steamprofile['profilestate'] = $_SESSION['steam_profilestate'];
|
$steamprofile['profilestate'] = $_SESSION['steam_profilestate'];
|
||||||
$steamprofile['personaname'] = $_SESSION['steam_personaname'];
|
$steamprofile['personaname'] = $_SESSION['steam_personaname'];
|
||||||
$steamprofile['lastlogoff'] = $_SESSION['steam_lastlogoff'];
|
|
||||||
$steamprofile['profileurl'] = $_SESSION['steam_profileurl'];
|
$steamprofile['profileurl'] = $_SESSION['steam_profileurl'];
|
||||||
$steamprofile['avatar'] = $_SESSION['steam_avatar'];
|
$steamprofile['avatar'] = $_SESSION['steam_avatar'];
|
||||||
$steamprofile['avatarmedium'] = $_SESSION['steam_avatarmedium'];
|
$steamprofile['avatarmedium'] = $_SESSION['steam_avatarmedium'];
|
||||||
|
|||||||
42
website/view/display_knife.php
Normal file
42
website/view/display_knife.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<div class="col-sm-2">
|
||||||
|
<div class="card text-center mb-3 border border-primary">
|
||||||
|
<div class="card-body">
|
||||||
|
<?php
|
||||||
|
// Determine the user's selected knife
|
||||||
|
$actualKnife = $knifes[0];
|
||||||
|
if ($selectedKnife != null) {
|
||||||
|
foreach ($knifes as $knife) {
|
||||||
|
if ($selectedKnife == $knife['weapon_name']) {
|
||||||
|
$actualKnife = $knife;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display user's selected knife information
|
||||||
|
echo "<div class='card-header'>";
|
||||||
|
echo "<h6 class='card-title item-name'>Knife type</h6>";
|
||||||
|
echo "<h5 class='card-title item-name'>{$actualKnife["paint_name"]}</h5>";
|
||||||
|
echo "</div>";
|
||||||
|
echo "<img src='{$actualKnife["image_url"]}' class='skin-image'>";
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<!-- Form for selecting user's knife -->
|
||||||
|
<form action="" method="POST">
|
||||||
|
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||||
|
<option disabled>Select knife</option>
|
||||||
|
<?php
|
||||||
|
// Display options for selecting different knives
|
||||||
|
foreach ($knifes as $knifeKey => $knife) {
|
||||||
|
if ($selectedKnife == $knife['weapon_name'])
|
||||||
|
echo "<option selected value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||||
|
else
|
||||||
|
echo "<option value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
154
website/view/display_weapons.php
Normal file
154
website/view/display_weapons.php
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
<?php
|
||||||
|
// Display user's selected skins for different weapons
|
||||||
|
foreach ($weapons as $defindex => $default) {
|
||||||
|
?>
|
||||||
|
<div class="col-sm-2">
|
||||||
|
<div class="card text-center mb-3">
|
||||||
|
<div class="card-body">
|
||||||
|
<?php
|
||||||
|
// Determine the skin to display for the current weapon
|
||||||
|
if (array_key_exists($defindex, $selectedSkins)) {
|
||||||
|
echo "<div class='card-header'>";
|
||||||
|
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]}</h5>";
|
||||||
|
echo "</div>";
|
||||||
|
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]['image_url']}' class='skin-image'>";
|
||||||
|
} else {
|
||||||
|
echo "<div class='card-header'>";
|
||||||
|
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
||||||
|
echo "</div>";
|
||||||
|
echo "<img src='{$default["image_url"]}' class='skin-image'>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<!-- Form for selecting user's skin and settings -->
|
||||||
|
<form action="" method="POST">
|
||||||
|
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||||
|
<option disabled>Select skin</option>
|
||||||
|
<?php
|
||||||
|
// Display options for selecting different skins
|
||||||
|
foreach ($skins[$defindex] as $paintKey => $paint) {
|
||||||
|
if (array_key_exists($defindex, $selectedSkins) && $selectedSkins[$defindex]['weapon_paint_id'] == $paintKey)
|
||||||
|
echo "<option selected value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||||
|
else
|
||||||
|
echo "<option value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<br></br>
|
||||||
|
<?php
|
||||||
|
// Display settings button for selected skin
|
||||||
|
$selectedSkinInfo = isset($selectedSkins[$defindex]) ? $selectedSkins[$defindex] : null;
|
||||||
|
$steamid = $_SESSION['steamid'];
|
||||||
|
|
||||||
|
if ($selectedSkinInfo) :
|
||||||
|
?>
|
||||||
|
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#weaponModal<?php echo $defindex ?>">
|
||||||
|
Settings
|
||||||
|
</button>
|
||||||
|
<?php else : ?>
|
||||||
|
<!-- Display message if skin is not selected -->
|
||||||
|
<button type="button" class="btn btn-primary" onclick="showSkinSelectionAlert()">
|
||||||
|
Settings
|
||||||
|
</button>
|
||||||
|
<script>
|
||||||
|
function showSkinSelectionAlert() {
|
||||||
|
alert("You need to select a skin first.");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// Display modal for adjusting wear and seed values
|
||||||
|
$selectedSkinInfo = isset($selectedSkins[$defindex]['weapon_paint_id']) ? $selectedSkins[$defindex] : null;
|
||||||
|
$queryWear = $selectedSkins[$defindex]['weapon_wear'] ?? 1.0;
|
||||||
|
$initialWearValue = isset($selectedSkinInfo['weapon_wear']) ? $selectedSkinInfo['weapon_wear'] : (isset($queryWear[0]['weapon_wear']) ? $queryWear[0] : 0.0);
|
||||||
|
$querySeed = $selectedSkins[$defindex]['weapon_seed'] ?? 0;
|
||||||
|
$initialSeedValue = isset($selectedSkinInfo['weapon_seed']) ? $selectedSkinInfo['weapon_seed'] : 0;
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!-- Modal for adjusting wear and seed values -->
|
||||||
|
<div class="modal fade" id="weaponModal<?php echo $defindex ?>" tabindex="-1" role="dialog" aria-labelledby="weaponModalLabel<?php echo $defindex ?>" aria-hidden="true">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<!-- Modal header -->
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class='card-title item-name'>
|
||||||
|
<?php
|
||||||
|
if (array_key_exists($defindex, $selectedSkins)) {
|
||||||
|
echo "{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]} Settings";
|
||||||
|
} else {
|
||||||
|
echo "{$default["paint_name"]} Settings";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<!-- Modal body -->
|
||||||
|
<div class="modal-body">
|
||||||
|
<!-- Form for adjusting wear and seed values -->
|
||||||
|
<div class="form-group">
|
||||||
|
<select class="form-select" id="wearSelect<?php echo $defindex ?>" name="wearSelect" onchange="updateWearValue<?php echo $defindex ?>(this.value)">
|
||||||
|
<option disabled>Select Wear</option>
|
||||||
|
<option value="0.00" <?php echo ($initialWearValue == 0.00) ? 'selected' : ''; ?>>Factory New</option>
|
||||||
|
<option value="0.07" <?php echo ($initialWearValue == 0.07) ? 'selected' : ''; ?>>Minimal Wear</option>
|
||||||
|
<option value="0.15" <?php echo ($initialWearValue == 0.15) ? 'selected' : ''; ?>>Field-Tested</option>
|
||||||
|
<option value="0.38" <?php echo ($initialWearValue == 0.38) ? 'selected' : ''; ?>>Well-Worn</option>
|
||||||
|
<option value="0.45" <?php echo ($initialWearValue == 0.45) ? 'selected' : ''; ?>>Battle-Scarred</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="wear">Wear:</label>
|
||||||
|
<input type="text" value="<?php echo $initialWearValue; ?>" class="form-control" id="wear<?php echo $defindex ?>" name="wear">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="seed">Seed:</label>
|
||||||
|
<input type="text" value="<?php echo $initialSeedValue; ?>" class="form-control" id="seed<?php echo $defindex ?>" name="seed" oninput="validateSeed(this)">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- Modal footer -->
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||||
|
<button type="submit" class="btn btn-danger">Use</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- JavaScript functions for updating wear and seed values -->
|
||||||
|
<script>
|
||||||
|
// wear
|
||||||
|
function updateWearValue<?php echo $defindex ?>(selectedValue) {
|
||||||
|
var wearInputElement = document.getElementById("wear<?php echo $defindex ?>");
|
||||||
|
wearInputElement.value = selectedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateWear(inputElement) {
|
||||||
|
inputElement.value = inputElement.value.replace(/[^0-9]/g, '');
|
||||||
|
}
|
||||||
|
// seed
|
||||||
|
function validateSeed(input) {
|
||||||
|
// Check entered value
|
||||||
|
var inputValue = input.value.replace(/[^0-9]/g, ''); // Just get the numbers
|
||||||
|
|
||||||
|
if (inputValue === "") {
|
||||||
|
input.value = 0; // Set to 0 if empty or no numbers
|
||||||
|
} else {
|
||||||
|
var numericValue = parseInt(inputValue);
|
||||||
|
numericValue = Math.min(1000, Math.max(1, numericValue)); // Interval control
|
||||||
|
|
||||||
|
input.value = numericValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user