mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-25 20:58:05 +00:00
Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09d9de2a2a | ||
|
|
362084c503 | ||
|
|
8cf175d336 | ||
|
|
84adfa8085 | ||
|
|
286d97d125 | ||
|
|
4d3db5b34f | ||
|
|
85d4e11f26 | ||
|
|
34b086a140 | ||
|
|
ad73e0a85d | ||
|
|
25c205e53d | ||
|
|
1366e141a7 | ||
|
|
5465b982b7 | ||
|
|
ead5ae23a3 | ||
|
|
ff2e7ffd6b | ||
|
|
c9a1fad496 | ||
|
|
0d4d01800d | ||
|
|
19d004c21d | ||
|
|
391efd5cac | ||
|
|
3cf9a67ee2 | ||
|
|
ddb4fb7cba | ||
|
|
e75d48bd0d | ||
|
|
959123344f | ||
|
|
14b0b8153f | ||
|
|
fa48245b34 | ||
|
|
5d5e0f2bd1 | ||
|
|
726e67865c | ||
|
|
868e6c8746 | ||
|
|
a1285bef26 | ||
|
|
b1920f312c | ||
|
|
5e9850bece | ||
|
|
e1802fd0f0 | ||
|
|
267de3c4de | ||
|
|
9f24fbf3ef | ||
|
|
9c23545173 | ||
|
|
40d1088ee6 | ||
|
|
e7f546ed58 | ||
|
|
beab940ebb | ||
|
|
7dc78e7706 | ||
|
|
02208095f0 |
14
.github/FUNDING.yml
vendored
Normal file
14
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: nereziel # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||||
|
polar: # Replace with a single Polar username
|
||||||
|
custom: ['https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||||
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@@ -63,11 +63,7 @@ jobs:
|
|||||||
- name: Copy gloves.json
|
- name: Copy gloves.json
|
||||||
run: cp website/data/gloves.json ${{ env.OUTPUT_PATH }}/gloves.json
|
run: cp website/data/gloves.json ${{ env.OUTPUT_PATH }}/gloves.json
|
||||||
- name: Zip
|
- name: Zip
|
||||||
uses: thedoctor0/zip-release@0.7.5
|
run: zip -r "${{ env.PROJECT_NAME }}.zip" "${{ env.OUTPUT_PATH }}" gamedata/
|
||||||
with:
|
|
||||||
type: 'zip'
|
|
||||||
filename: '${{ env.PROJECT_NAME }}.zip'
|
|
||||||
path: ${{ env.OUTPUT_PATH }}
|
|
||||||
- name: Clean files Website
|
- name: Clean files Website
|
||||||
run: |
|
run: |
|
||||||
rm -rf website/img/
|
rm -rf website/img/
|
||||||
|
|||||||
175
Commands.cs
175
Commands.cs
@@ -13,39 +13,54 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return;
|
if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return;
|
||||||
|
|
||||||
int playerIndex = (int)player!.Index;
|
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
|
Slot = player.Slot,
|
||||||
Index = (int)player.Index,
|
Index = (int)player.Index,
|
||||||
SteamId = player?.SteamID.ToString(),
|
SteamId = player?.SteamID.ToString(),
|
||||||
Name = player?.PlayerName,
|
Name = player?.PlayerName,
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||||
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
|
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
|
||||||
|
|
||||||
if (Config.Additional.GloveEnabled && weaponSync != null)
|
|
||||||
Task.Run(async () => await weaponSync.GetGloveFromDatabase(playerInfo));
|
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
|
||||||
{
|
{
|
||||||
if (weaponSync != null)
|
var weaponTasks = new List<Task>();
|
||||||
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo));
|
|
||||||
|
|
||||||
|
weaponTasks.Add(Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (Config.Additional.GloveEnabled)
|
||||||
|
{
|
||||||
|
weaponTasks.Add(Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await weaponSync.GetGloveFromDatabase(playerInfo);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
{
|
||||||
|
weaponTasks.Add(Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
Task.WaitAll(weaponTasks.ToArray());
|
||||||
|
|
||||||
|
RefreshGloves(player);
|
||||||
RefreshWeapons(player);
|
RefreshWeapons(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Localizer["wp_command_refresh_done"]))
|
if (!string.IsNullOrEmpty(Localizer["wp_command_refresh_done"]))
|
||||||
{
|
{
|
||||||
player!.Print(Localizer["wp_command_refresh_done"]);
|
player!.Print(Localizer["wp_command_refresh_done"]);
|
||||||
@@ -96,7 +111,7 @@ namespace WeaponPaints
|
|||||||
});
|
});
|
||||||
AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) =>
|
AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) =>
|
||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
OnCommandRefresh(player, info);
|
OnCommandRefresh(player, info);
|
||||||
});
|
});
|
||||||
if (Config.Additional.CommandKillEnabled)
|
if (Config.Additional.CommandKillEnabled)
|
||||||
@@ -140,18 +155,20 @@ namespace WeaponPaints
|
|||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
|
Slot = player.Slot,
|
||||||
Index = (int)player.Index,
|
Index = (int)player.Index,
|
||||||
SteamId = player.SteamID.ToString(),
|
SteamId = player.SteamID.ToString(),
|
||||||
Name = player.PlayerName,
|
Name = player.PlayerName,
|
||||||
IpAddress = player.IpAddress?.Split(":")[0]
|
IpAddress = player.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
g_playersKnife[(int)player!.Index] = knifeKey;
|
g_playersKnife[player.Slot] = knifeKey;
|
||||||
|
|
||||||
if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE)
|
if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE)
|
||||||
AddTimer(0.15f, () => RefreshWeapons(player), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
RefreshWeapons(player);
|
||||||
|
|
||||||
_ = weaponSync?.SyncKnifeToDatabase(playerInfo, knifeKey) ?? Task.CompletedTask;
|
if (weaponSync != null)
|
||||||
|
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
foreach (var knifePair in knivesOnly)
|
foreach (var knifePair in knivesOnly)
|
||||||
@@ -164,10 +181,10 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (player == null || player.UserId == null) return;
|
if (player == null || player.UserId == null) return;
|
||||||
|
|
||||||
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||||
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
giveItemMenu.PostSelectAction = PostSelectAction.Close;
|
giveItemMenu.PostSelectAction = PostSelectAction.Close;
|
||||||
MenuManager.OpenChatMenu(player, giveItemMenu);
|
MenuManager.OpenChatMenu(player, giveItemMenu);
|
||||||
return;
|
return;
|
||||||
@@ -189,7 +206,6 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
int playerIndex = (int)player!.Index;
|
|
||||||
string selectedWeapon = option.Text;
|
string selectedWeapon = option.Text;
|
||||||
if (classNamesByWeapon.TryGetValue(selectedWeapon, out string? selectedWeaponClassname))
|
if (classNamesByWeapon.TryGetValue(selectedWeapon, out string? selectedWeaponClassname))
|
||||||
{
|
{
|
||||||
@@ -201,15 +217,12 @@ namespace WeaponPaints
|
|||||||
)?.ToList();
|
)?.ToList();
|
||||||
|
|
||||||
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
|
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
|
||||||
skinSubMenu.PostSelectAction = PostSelectAction.Close;
|
|
||||||
|
|
||||||
// Function to handle skin selection for the chosen weapon
|
// Function to handle skin selection for the chosen weapon
|
||||||
var handleSkinSelection = (CCSPlayerController p, ChatMenuOption opt) =>
|
var handleSkinSelection = (CCSPlayerController p, ChatMenuOption opt) =>
|
||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(p)) return;
|
if (!Utility.IsPlayerValid(p)) return;
|
||||||
|
|
||||||
playerIndex = (int)p.Index;
|
|
||||||
|
|
||||||
string steamId = p.SteamID.ToString();
|
string steamId = p.SteamID.ToString();
|
||||||
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
||||||
{
|
{
|
||||||
@@ -220,8 +233,9 @@ namespace WeaponPaints
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
string selectedSkin = opt.Text;
|
string selectedSkin = opt.Text;
|
||||||
string selectedPaintID = selectedSkin.Split('(')[1].Trim(')').Trim();
|
string selectedPaintID = selectedSkin.Substring(selectedSkin.LastIndexOf('(') + 1).Trim(')');
|
||||||
|
|
||||||
if (firstSkin != null &&
|
if (firstSkin != null &&
|
||||||
firstSkin.TryGetValue("weapon_defindex", out var weaponDefIndexObj) &&
|
firstSkin.TryGetValue("weapon_defindex", out var weaponDefIndexObj) &&
|
||||||
@@ -243,32 +257,37 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
p.Print(Localizer["wp_skin_menu_select", selectedSkin]);
|
p.Print(Localizer["wp_skin_menu_select", selectedSkin]);
|
||||||
|
|
||||||
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
if (!gPlayerWeaponsInfo[p.Slot].ContainsKey(weaponDefIndex))
|
||||||
{
|
{
|
||||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = new WeaponInfo();
|
gPlayerWeaponsInfo[p.Slot][weaponDefIndex] = new WeaponInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
|
gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Paint = paintID;
|
||||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.01f;
|
gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Wear = 0.01f;
|
||||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Seed = 0;
|
gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Seed = 0;
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = p.UserId,
|
UserId = p.UserId,
|
||||||
|
Slot = p.Slot,
|
||||||
Index = (int)p.Index,
|
Index = (int)p.Index,
|
||||||
SteamId = p.SteamID.ToString(),
|
SteamId = p.SteamID.ToString(),
|
||||||
Name = p.PlayerName,
|
Name = p.PlayerName,
|
||||||
IpAddress = p.IpAddress?.Split(":")[0]
|
IpAddress = p.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE)
|
if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE && weaponSync != null)
|
||||||
AddTimer(0.15f, () => RefreshWeapons(p), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
|
||||||
|
|
||||||
|
|
||||||
if (!Config.GlobalShare)
|
|
||||||
{
|
{
|
||||||
if (weaponSync != null)
|
RefreshWeapons(player);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
|
Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Utility.Log($"Error syncing weapon paints: {ex.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -290,9 +309,8 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (player != null && Utility.IsPlayerValid(player))
|
||||||
// Open the submenu for skin selection of the chosen weapon
|
MenuManager.OpenChatMenu(player, skinSubMenu);
|
||||||
MenuManager.OpenChatMenu(player, skinSubMenu);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -309,10 +327,10 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (player == null || player.UserId == null) return;
|
if (player == null || player.UserId == null) return;
|
||||||
|
|
||||||
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||||
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
MenuManager.OpenChatMenu(player, weaponSelectionMenu);
|
MenuManager.OpenChatMenu(player, weaponSelectionMenu);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -326,12 +344,12 @@ namespace WeaponPaints
|
|||||||
private void SetupGlovesMenu()
|
private void SetupGlovesMenu()
|
||||||
{
|
{
|
||||||
var glovesSelectionMenu = new ChatMenu(Localizer["wp_glove_menu_title"]);
|
var glovesSelectionMenu = new ChatMenu(Localizer["wp_glove_menu_title"]);
|
||||||
|
glovesSelectionMenu.PostSelectAction = PostSelectAction.Close;
|
||||||
|
|
||||||
var handleGloveSelection = (CCSPlayerController? player, ChatMenuOption option) =>
|
var handleGloveSelection = (CCSPlayerController? player, ChatMenuOption option) =>
|
||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player) || player is null) return;
|
||||||
|
|
||||||
uint playerIndex = player!.Index;
|
|
||||||
string selectedPaintName = option.Text;
|
string selectedPaintName = option.Text;
|
||||||
|
|
||||||
var selectedGlove = glovesList.FirstOrDefault(g => g.ContainsKey("paint_name") && g["paint_name"]?.ToString() == selectedPaintName);
|
var selectedGlove = glovesList.FirstOrDefault(g => g.ContainsKey("paint_name") && g["paint_name"]?.ToString() == selectedPaintName);
|
||||||
@@ -355,6 +373,7 @@ namespace WeaponPaints
|
|||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
|
Slot = player.Slot,
|
||||||
Index = (int)player.Index,
|
Index = (int)player.Index,
|
||||||
SteamId = player.SteamID.ToString(),
|
SteamId = player.SteamID.ToString(),
|
||||||
Name = player.PlayerName,
|
Name = player.PlayerName,
|
||||||
@@ -362,16 +381,43 @@ namespace WeaponPaints
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (paint != 0)
|
if (paint != 0)
|
||||||
g_playersGlove[playerIndex] = ((ushort)weaponDefindex, paint);
|
{
|
||||||
|
g_playersGlove[player.Slot] = (ushort)weaponDefindex;
|
||||||
|
|
||||||
|
if (!gPlayerWeaponsInfo[player.Slot].ContainsKey(weaponDefindex))
|
||||||
|
{
|
||||||
|
WeaponInfo weaponInfo = new();
|
||||||
|
weaponInfo.Paint = paint;
|
||||||
|
gPlayerWeaponsInfo[player.Slot][weaponDefindex] = weaponInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
g_playersGlove.TryRemove(playerIndex, out _);
|
{
|
||||||
|
g_playersGlove.TryRemove(player.Slot, out _);
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Localizer["wp_glove_menu_select"]))
|
if (!string.IsNullOrEmpty(Localizer["wp_glove_menu_select"]))
|
||||||
{
|
{
|
||||||
player!.Print(Localizer["wp_glove_menu_select", selectedPaintName]);
|
player!.Print(Localizer["wp_glove_menu_select", selectedPaintName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = weaponSync?.SyncGloveToDatabase(playerInfo, (ushort)weaponDefindex, paint) ?? Task.CompletedTask;
|
if (weaponSync != null)
|
||||||
|
{
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await weaponSync.SyncGloveToDatabase(playerInfo, weaponDefindex);
|
||||||
|
|
||||||
|
if (!gPlayerWeaponsInfo[playerInfo.Slot].ContainsKey(weaponDefindex))
|
||||||
|
{
|
||||||
|
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex] = new WeaponInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Paint = paint;
|
||||||
|
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Wear = 0.00f;
|
||||||
|
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Seed = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
RefreshGloves(player);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -387,24 +433,23 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
// Command to open the weapon selection menu for players
|
// Command to open the weapon selection menu for players
|
||||||
AddCommand($"css_{Config.Additional.CommandGlove}", "Gloves selection menu", (player, info) =>
|
AddCommand($"css_{Config.Additional.CommandGlove}", "Gloves selection menu", (player, info) =>
|
||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||||
|
|
||||||
if (player == null || player.UserId == null) return;
|
if (player == null || player.UserId == null) return;
|
||||||
|
|
||||||
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||||
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
glovesSelectionMenu.PostSelectAction = PostSelectAction.Close;
|
MenuManager.OpenChatMenu(player, glovesSelectionMenu);
|
||||||
MenuManager.OpenChatMenu(player, glovesSelectionMenu);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
{
|
||||||
{
|
player!.Print(Localizer["wp_command_cooldown"]);
|
||||||
player!.Print(Localizer["wp_command_cooldown"]);
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,9 +5,6 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
public class Additional
|
public class Additional
|
||||||
{
|
{
|
||||||
[JsonPropertyName("SkinVisibilityFix")]
|
|
||||||
public bool SkinVisibilityFix { get; set; } = true;
|
|
||||||
|
|
||||||
[JsonPropertyName("KnifeEnabled")]
|
[JsonPropertyName("KnifeEnabled")]
|
||||||
public bool KnifeEnabled { get; set; } = true;
|
public bool KnifeEnabled { get; set; } = true;
|
||||||
|
|
||||||
@@ -56,7 +53,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
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; } = "";
|
||||||
@@ -73,9 +70,6 @@ namespace WeaponPaints
|
|||||||
[JsonPropertyName("DatabaseName")]
|
[JsonPropertyName("DatabaseName")]
|
||||||
public string DatabaseName { get; set; } = "";
|
public string DatabaseName { get; set; } = "";
|
||||||
|
|
||||||
[JsonPropertyName("GlobalShare")]
|
|
||||||
public bool GlobalShare { get; set; } = false;
|
|
||||||
|
|
||||||
[JsonPropertyName("CmdRefreshCooldownSeconds")]
|
[JsonPropertyName("CmdRefreshCooldownSeconds")]
|
||||||
public int CmdRefreshCooldownSeconds { get; set; } = 60;
|
public int CmdRefreshCooldownSeconds { get; set; } = 60;
|
||||||
|
|
||||||
|
|||||||
449
Events.cs
449
Events.cs
@@ -1,245 +1,157 @@
|
|||||||
using CounterStrikeSharp.API;
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||||
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
|
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
public partial class WeaponPaints
|
public partial class WeaponPaints
|
||||||
{
|
{
|
||||||
private void OnClientPutInServer(int playerSlot)
|
[GameEventHandler]
|
||||||
|
public HookResult OnClientFullConnect(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
|
||||||
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17 ||
|
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17 ||
|
||||||
weaponSync == null) return;
|
weaponSync == null || _database == null) return HookResult.Continue;
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
|
Slot = player.Slot,
|
||||||
Index = (int)player.Index,
|
Index = (int)player.Index,
|
||||||
SteamId = player.SteamID.ToString(),
|
SteamId = player.SteamID.ToString(),
|
||||||
Name = player.PlayerName,
|
Name = player.PlayerName,
|
||||||
IpAddress = player.IpAddress?.Split(":")[0]
|
IpAddress = player.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
Task.Run(async () =>
|
try
|
||||||
{
|
{
|
||||||
|
List<Task> tasks = new List<Task>();
|
||||||
|
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
await weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
{
|
||||||
|
tasks.Add(Task.Run(() => weaponSync.GetWeaponPaintsFromDatabase(playerInfo)));
|
||||||
|
}
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
await weaponSync.GetKnifeFromDatabase(playerInfo);
|
{
|
||||||
|
tasks.Add(Task.Run(() => weaponSync.GetKnifeFromDatabase(playerInfo)));
|
||||||
|
}
|
||||||
if (Config.Additional.GloveEnabled)
|
if (Config.Additional.GloveEnabled)
|
||||||
await weaponSync.GetGloveFromDatabase(playerInfo);
|
{
|
||||||
});
|
tasks.Add(Task.Run(() => weaponSync.GetGloveFromDatabase(playerInfo)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClientDisconnect(int playerSlot)
|
Task.WaitAll(tasks.ToArray());
|
||||||
{
|
}
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
catch (AggregateException ex)
|
||||||
|
|
||||||
if (player is null || !player.IsValid || !player.UserId.HasValue || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17) return;
|
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
|
||||||
g_playersKnife.TryRemove((int)player.Index, out _);
|
|
||||||
if (Config.Additional.GloveEnabled)
|
|
||||||
g_playersGlove.TryRemove(player.Index, out _);
|
|
||||||
|
|
||||||
if (Config.Additional.SkinEnabled && gPlayerWeaponsInfo.TryGetValue((int)player.Index, out var innerDictionary))
|
|
||||||
{
|
{
|
||||||
innerDictionary.Clear();
|
// Handle the exception
|
||||||
gPlayerWeaponsInfo.TryRemove((int)player.Index, out _);
|
foreach (var innerException in ex.InnerExceptions)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"An error occurred for player {player}: {innerException.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commandsCooldown.Remove((int)player.UserId);
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEntityCreated(CEntityInstance entity)
|
[GameEventHandler]
|
||||||
|
public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
CCSPlayerController player = @event.Userid;
|
||||||
|
|
||||||
|
if (player is null || !player.IsValid || player.IsBot ||
|
||||||
|
player.IsHLTV || player.SteamID.ToString().Length != 17) return HookResult.Continue;
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Slot = player.Slot,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player.SteamID.ToString(),
|
||||||
|
Name = player.PlayerName,
|
||||||
|
IpAddress = player.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
if (Config.Additional.SkinEnabled)
|
||||||
|
{
|
||||||
|
gPlayerWeaponsInfo.TryRemove(player.Slot, out _);
|
||||||
|
}
|
||||||
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
{
|
||||||
|
g_playersKnife.TryRemove(player.Slot, out _);
|
||||||
|
}
|
||||||
|
if (Config.Additional.GloveEnabled)
|
||||||
|
{
|
||||||
|
g_playersGlove.TryRemove(player.Slot, out _);
|
||||||
|
}
|
||||||
|
|
||||||
|
commandsCooldown.Remove(player.Slot);
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon weapon)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
if (!Config.Additional.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"))
|
if (player is null || weapon is null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
||||||
{
|
|
||||||
isKnife = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Server.NextFrame(() =>
|
if (!gPlayerWeaponsInfo.ContainsKey(player.Slot)) return;
|
||||||
|
|
||||||
|
bool isKnife = weapon.DesignerName.Contains("knife") || weapon.DesignerName.Contains("bayonet");
|
||||||
|
|
||||||
|
if (isKnife && !g_playersKnife.ContainsKey(player.Slot) || isKnife && g_playersKnife[player.Slot] == "weapon_knife") return;
|
||||||
|
|
||||||
|
if (isKnife)
|
||||||
{
|
{
|
||||||
try
|
var newDefIndex = WeaponDefindex.FirstOrDefault(x => x.Value == g_playersKnife[player.Slot]);
|
||||||
|
if (newDefIndex.Key == 0) return;
|
||||||
|
|
||||||
|
if (weapon.AttributeManager.Item.ItemDefinitionIndex != newDefIndex.Key)
|
||||||
{
|
{
|
||||||
if (!weapon.IsValid) return;
|
SubclassChange(weapon, (ushort)newDefIndex.Key);
|
||||||
if (weapon.OwnerEntity.Value == null) return;
|
|
||||||
if (weapon.OwnerEntity.Index <= 0) return;
|
|
||||||
int weaponOwner = (int)weapon.OwnerEntity.Index;
|
|
||||||
CBasePlayerPawn? pawn = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)weaponOwner);
|
|
||||||
//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) { }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
|
weapon.AttributeManager.Item.ItemDefinitionIndex = (ushort)newDefIndex.Key;
|
||||||
{
|
weapon.AttributeManager.Item.EntityQuality = 3;
|
||||||
CCSPlayerController? player = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)activator.Index).OriginalController.Value;
|
|
||||||
|
|
||||||
if (player == null || player.IsBot || player.IsHLTV ||
|
|
||||||
player.SteamID.ToString().Length != 17 || !g_knifePickupCount.TryGetValue((int)player.Index, out var pickupCount) ||
|
|
||||||
!g_playersKnife.ContainsKey((int)player.Index))
|
|
||||||
{
|
|
||||||
return HookResult.Continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CBasePlayerWeapon weapon = new(caller.Handle);
|
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
||||||
|
int fallbackPaintKit = 0;
|
||||||
|
|
||||||
if (weapon.AttributeManager.Item.ItemDefinitionIndex != 42 && weapon.AttributeManager.Item.ItemDefinitionIndex != 59)
|
if (_config.Additional.GiveRandomSkin &&
|
||||||
|
!gPlayerWeaponsInfo[player.Slot].ContainsKey(weaponDefIndex))
|
||||||
{
|
{
|
||||||
return HookResult.Continue;
|
// 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.000001f;
|
||||||
|
CAttributeList_SetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "set item texture prefab", weapon.FallbackPaintKit);
|
||||||
|
|
||||||
if (pickupCount >= 2)
|
fallbackPaintKit = weapon.FallbackPaintKit;
|
||||||
{
|
|
||||||
return HookResult.Continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_playersKnife[(int)player.Index] != "weapon_knife")
|
if (fallbackPaintKit == 0)
|
||||||
{
|
return;
|
||||||
pickupCount++;
|
|
||||||
g_knifePickupCount[(int)player.Index] = pickupCount;
|
|
||||||
|
|
||||||
if (Config.Additional.GiveKnifeAfterRemove)
|
var foundSkin = skinsList.FirstOrDefault(skin =>
|
||||||
|
((int?)skin?["weapon_defindex"] ?? 0) == weaponDefIndex &&
|
||||||
|
((int?)skin?["paint"] ?? 0) == fallbackPaintKit &&
|
||||||
|
skin?["paint_name"] != null
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||||
{
|
{
|
||||||
AddTimer(0.10f, () =>
|
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||||
{
|
|
||||||
RefreshWeapons(player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return HookResult.Continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnMapStart(string mapName)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.KnifeEnabled && !Config.Additional.SkinEnabled && !Config.Additional.GloveEnabled) return;
|
|
||||||
|
|
||||||
if (_database != null)
|
|
||||||
weaponSync = new WeaponSynchronization(_database, Config, GlobalShareApi, GlobalShareServerId);
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
|
||||||
{
|
|
||||||
CCSPlayerController? player = @event.Userid;
|
|
||||||
|
|
||||||
if (player is null || !player.IsValid || !Config.Additional.KnifeEnabled && !Config.Additional.GloveEnabled)
|
|
||||||
return HookResult.Continue;
|
|
||||||
|
|
||||||
if (g_playersGlove.TryGetValue(player.Index, out var gloveInfo) && gloveInfo.Paint != 0)
|
|
||||||
{
|
|
||||||
player.PlayerPawn!.Value!.EconGloves.ItemDefinitionIndex = gloveInfo.Definition;
|
|
||||||
player.PlayerPawn!.Value!.EconGloves.ItemIDLow = 16384 & 0xFFFFFFFF;
|
|
||||||
player.PlayerPawn!.Value!.EconGloves.ItemIDHigh = 16384 >> 32;
|
|
||||||
player.PlayerPawn!.Value!.EconGloves.EntityQuality = 3;
|
|
||||||
player.PlayerPawn!.Value!.EconGloves.EntityLevel = 1;
|
|
||||||
|
|
||||||
Server.NextFrame(() =>
|
|
||||||
{
|
|
||||||
player.PlayerPawn!.Value!.EconGloves.Initialized = true;
|
|
||||||
SetPlayerBody(player, "default_gloves", 1);
|
|
||||||
SetOrAddAttributeValueByName(player.PlayerPawn!.Value!.EconGloves.NetworkedDynamicAttributes, "set item texture prefab", gloveInfo.Paint);
|
|
||||||
|
|
||||||
Utilities.SetStateChanged(player.PlayerPawn.Value, "CCSPlayerPawn", "m_EconGloves");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
g_knifePickupCount[(int)player.Index] = 0;
|
|
||||||
GiveKnifeToPlayer(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 is null || !player.IsValid || !player.PawnIsAlive || player.SteamID.ToString().Length != 17
|
|
||||||
|| player.IsBot || player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (Config.Additional.ShowSkinImage && PlayerWeaponImage.ContainsKey(player.Slot) && !string.IsNullOrEmpty(PlayerWeaponImage[player.Slot]))
|
|
||||||
{
|
|
||||||
player.PrintToCenterHtml("<img src='{PATH}'</img>".Replace("{PATH}", PlayerWeaponImage[player.Slot]));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.PlayerPawn?.IsValid != true || player.PlayerPawn?.Value?.IsValid != true)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var viewModels = GetPlayerViewModels(player);
|
|
||||||
if (viewModels == null || viewModels.Length == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var viewModel = viewModels[0];
|
|
||||||
if (viewModel == null || viewModel.Value == null || viewModel.Value.Weapon == null || viewModel.Value.Weapon.Value == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var weapon = viewModel.Value.Weapon.Value;
|
|
||||||
if (weapon == null || !weapon.IsValid || weapon.FallbackPaintKit == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (viewModel.Value.VMName.Contains("knife"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var sceneNode = viewModel.Value.CBodyComponent?.SceneNode;
|
|
||||||
if (sceneNode == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var skeleton = GetSkeletonInstance(sceneNode);
|
|
||||||
if (skeleton == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 };
|
int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 };
|
||||||
if (newPaints.Contains(weapon.FallbackPaintKit))
|
|
||||||
|
if (newPaints.Contains(fallbackPaintKit))
|
||||||
{
|
{
|
||||||
skeleton.ModelState.MeshGroupMask = 1;
|
skeleton.ModelState.MeshGroupMask = 1;
|
||||||
}
|
}
|
||||||
@@ -250,30 +162,161 @@ namespace WeaponPaints
|
|||||||
skeleton.ModelState.MeshGroupMask = 2;
|
skeleton.ModelState.MeshGroupMask = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Utilities.SetStateChanged(viewModel.Value, "CBaseEntity", "m_CBodyComponent");
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
|
||||||
|
var viewModels = GetPlayerViewModels(player);
|
||||||
|
if (viewModels == null || viewModels.Length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var viewModel = viewModels[0];
|
||||||
|
if (viewModel == null || viewModel.Value == null || viewModel.Value.Weapon == null || viewModel.Value.Weapon.Value == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Utilities.SetStateChanged(viewModel.Value, "CBaseEntity", "m_CBodyComponent");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gPlayerWeaponsInfo[player.Slot].ContainsKey(weaponDefIndex)) return;
|
||||||
|
WeaponInfo weaponInfo = gPlayerWeaponsInfo[player.Slot][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;
|
||||||
|
CAttributeList_SetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "set item texture prefab", weapon.FallbackPaintKit);
|
||||||
|
|
||||||
|
fallbackPaintKit = weapon.FallbackPaintKit;
|
||||||
|
|
||||||
|
if (fallbackPaintKit == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var foundSkin1 = skinsList.FirstOrDefault(skin =>
|
||||||
|
((int?)skin?["weapon_defindex"] ?? 0) == weaponDefIndex &&
|
||||||
|
((int?)skin?["paint"] ?? 0) == fallbackPaintKit &&
|
||||||
|
skin?["paint_name"] != null
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||||
|
{
|
||||||
|
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||||
|
int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 };
|
||||||
|
if (newPaints.Contains(fallbackPaintKit))
|
||||||
{
|
{
|
||||||
|
skeleton.ModelState.MeshGroupMask = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (skeleton.ModelState.MeshGroupMask != 2)
|
||||||
|
{
|
||||||
|
skeleton.ModelState.MeshGroupMask = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var viewModels1 = GetPlayerViewModels(player);
|
||||||
|
if (viewModels1 == null || viewModels1.Length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var viewModel1 = viewModels1[0];
|
||||||
|
if (viewModel1 == null || viewModel1.Value == null || viewModel1.Value.Weapon == null || viewModel1.Value.Weapon.Value == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Utilities.SetStateChanged(viewModel1.Value, "CBaseEntity", "m_CBodyComponent");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMapStart(string mapName)
|
||||||
|
{
|
||||||
|
if (!Config.Additional.KnifeEnabled && !Config.Additional.SkinEnabled && !Config.Additional.GloveEnabled) return;
|
||||||
|
|
||||||
|
if (_database != null)
|
||||||
|
weaponSync = new WeaponSynchronization(_database, Config);
|
||||||
|
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
|
||||||
|
if (player is null || !player.IsValid || !Config.Additional.KnifeEnabled && !Config.Additional.GloveEnabled)
|
||||||
|
return HookResult.Continue;
|
||||||
|
|
||||||
|
CCSPlayerPawn? pawn = player.PlayerPawn.Value;
|
||||||
|
|
||||||
|
if (pawn == null || !pawn.IsValid)
|
||||||
|
return HookResult.Continue;
|
||||||
|
|
||||||
|
g_knifePickupCount[player.Slot] = 0;
|
||||||
|
|
||||||
|
//if (!PlayerHasKnife(player))
|
||||||
|
//GiveKnifeToPlayer(player);
|
||||||
|
|
||||||
|
Server.NextFrame(() =>
|
||||||
|
{
|
||||||
|
RefreshGloves(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HookResult OnGiveNamedItemPost(DynamicHook hook)
|
||||||
|
{
|
||||||
|
var itemServices = hook.GetParam<CCSPlayer_ItemServices>(0);
|
||||||
|
var weapon = hook.GetReturn<CBasePlayerWeapon>(0);
|
||||||
|
if (!weapon.DesignerName.Contains("weapon"))
|
||||||
|
return HookResult.Continue;
|
||||||
|
|
||||||
|
var player = GetPlayerFromItemServices(itemServices);
|
||||||
|
if (player != null)
|
||||||
|
GivePlayerWeaponSkin(player, weapon);
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegisterListeners()
|
private void RegisterListeners()
|
||||||
{
|
{
|
||||||
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
|
|
||||||
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
|
|
||||||
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
|
||||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||||
RegisterListener<Listeners.OnTick>(OnTick);
|
|
||||||
|
|
||||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||||
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||||
|
|
||||||
//RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
|
||||||
|
|
||||||
HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup);
|
//HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
public class PlayerInfo
|
public class PlayerInfo
|
||||||
{
|
{
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
|
public int Slot { get; set; }
|
||||||
public int? UserId { get; set; }
|
public int? UserId { get; set; }
|
||||||
public string? SteamId { get; set; }
|
public string? SteamId { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
|||||||
20
README.md
20
README.md
@@ -10,21 +10,18 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
|||||||
|
|
||||||
## 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, so you dont need MySQL/Website
|
- MySQL based
|
||||||
- Data syncs on player connect
|
- Data syncs on player connect
|
||||||
- Added command **`!wp`** to refresh skins ***(with cooldown in seconds 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 ""`**
|
|
||||||
- Translations support, submit a PR if you want to share your translation
|
- Translations support, submit a PR if you want to share your translation
|
||||||
|
|
||||||
**GlobalShare** - global website accessible at [weaponpaints.fun](https://weaponpaints.fun/)
|
|
||||||
|
|
||||||
## CS2 Server
|
## CS2 Server
|
||||||
- Have working CounterStrikeSharp (**with RUNTIME!**)
|
- Have working CounterStrikeSharp (**with RUNTIME!**)
|
||||||
- Download from Release and copy plugin to plugins
|
- Download from Release and copy plugin to plugins
|
||||||
- Run server with plugin, **it will generate config if installed correctly!**
|
- Run server with plugin, **it will generate config if installed correctly!**
|
||||||
- Edit `addons/counterstrikesharp/configs/`**`plugins/WeaponPaints/WeaponPaints.json`** set **`GlobalShare`** to **`true`** for global, or include database credentials
|
- Edit `addons/counterstrikesharp/configs/`**`plugins/WeaponPaints/WeaponPaints.json`** include database credentials
|
||||||
- In `addons/counterstrikesharp/configs/`**`core.json`** set **FollowCS2ServerGuidelines** to **`false`**
|
- In `addons/counterstrikesharp/configs/`**`core.json`** set **FollowCS2ServerGuidelines** to **`false`**
|
||||||
|
|
||||||
## Plugin Configuration
|
## Plugin Configuration
|
||||||
@@ -32,12 +29,11 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
|||||||
<summary>Click to expand</summary>
|
<summary>Click to expand</summary>
|
||||||
<code><pre>{
|
<code><pre>{
|
||||||
"Version": 4, // Don't touch
|
"Version": 4, // Don't touch
|
||||||
"DatabaseHost": "", // MySQL host (required if GlobalShare = false)
|
"DatabaseHost": "", // MySQL host
|
||||||
"DatabasePort": 3306, // MySQL port (required if GlobalShare = false)
|
"DatabasePort": 3306, // MySQL port
|
||||||
"DatabaseUser": "", // MySQL username (required if GlobalShare = false)
|
"DatabaseUser": "", // MySQL username
|
||||||
"DatabasePassword": "", // MySQL user password (required if GlobalShare = false)
|
"DatabasePassword": "", // MySQL user password
|
||||||
"DatabaseName": "", // MySQL database name (required if GlobalShare = false)
|
"DatabaseName": "", // MySQL database name
|
||||||
"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)
|
"CmdRefreshCooldownSeconds": 60, // Cooldown time in refreshing skins (!wp command)
|
||||||
"Prefix": "[WeaponPaints]", // Prefix every chat message
|
"Prefix": "[WeaponPaints]", // Prefix every chat message
|
||||||
"Website": "example.com/skins", // Website used in WebsiteMessageCommand (!ws command)
|
"Website": "example.com/skins", // Website used in WebsiteMessageCommand (!ws command)
|
||||||
@@ -55,7 +51,6 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
|||||||
"SkinMenuTitle": "Select skin for {WEAPON}" // Menu title (!skins menu, after weapon select)
|
"SkinMenuTitle": "Select skin for {WEAPON}" // Menu title (!skins menu, after weapon select)
|
||||||
},
|
},
|
||||||
"Additional": {
|
"Additional": {
|
||||||
"SkinVisibilityFix": true, // Enable or disable fix for skin visibility
|
|
||||||
"KnifeEnabled": true, // Enable or disable knife feature
|
"KnifeEnabled": true, // Enable or disable knife feature
|
||||||
"SkinEnabled": true, // Enable or disable skin feature
|
"SkinEnabled": true, // Enable or disable skin feature
|
||||||
"CommandWpEnabled": true, // Enable or disable refreshing command
|
"CommandWpEnabled": true, // Enable or disable refreshing command
|
||||||
@@ -74,7 +69,6 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
## Web install
|
## Web install
|
||||||
Disregard if the config is **`GlobalShare = true`**
|
|
||||||
- Requires PHP >= 7.4 ***(Tested on php ver **`8.2.3`** and nginx webserver)***
|
- Requires PHP >= 7.4 ***(Tested on php ver **`8.2.3`** and nginx webserver)***
|
||||||
- **Before using website, make sure the plugin is correctly loaded in cs2 server!** Mysql tables are created by plugin not by website.
|
- **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)***
|
- Copy website to web server ***(Folder `img` not needed)***
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ namespace WeaponPaints
|
|||||||
@"CREATE TABLE IF NOT EXISTS `wp_player_gloves` (
|
@"CREATE TABLE IF NOT EXISTS `wp_player_gloves` (
|
||||||
`steamid` varchar(64) NOT NULL,
|
`steamid` varchar(64) NOT NULL,
|
||||||
`weapon_defindex` int(11) NOT NULL,
|
`weapon_defindex` int(11) NOT NULL,
|
||||||
`paint` int(11) NOT NULL,
|
|
||||||
UNIQUE (`steamid`)
|
UNIQUE (`steamid`)
|
||||||
) ENGINE=InnoDB"
|
) ENGINE=InnoDB"
|
||||||
};
|
};
|
||||||
@@ -86,8 +85,8 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (player is null) return false;
|
if (player is null) return false;
|
||||||
|
|
||||||
return (player is not null && player.IsValid && !player.IsBot && !player.IsHLTV
|
return (player is not null && player.IsValid && !player.IsBot && !player.IsHLTV && player.UserId.HasValue
|
||||||
&& WeaponPaints.weaponSync != null && player.Connected == PlayerConnectedState.PlayerConnected);
|
&& WeaponPaints.weaponSync != null && player.Connected == PlayerConnectedState.PlayerConnected && player.SteamID.ToString().Length == 17);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LoadSkinsFromFile(string filePath)
|
internal static void LoadSkinsFromFile(string filePath)
|
||||||
|
|||||||
426
WeaponAction.cs
426
WeaponAction.cs
@@ -1,6 +1,7 @@
|
|||||||
using CounterStrikeSharp.API;
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Memory;
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
|
using CounterStrikeSharp.API.Modules.Timers;
|
||||||
using CounterStrikeSharp.API.Modules.Utils;
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
@@ -13,23 +14,29 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (player is null || weapon is null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
if (player is null || weapon is null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
int playerIndex = (int)player.Index;
|
if (!gPlayerWeaponsInfo.ContainsKey(player.Slot)) return;
|
||||||
|
|
||||||
if (!gPlayerWeaponsInfo.ContainsKey(playerIndex)) return;
|
if (isKnife && !g_playersKnife.ContainsKey(player.Slot) || isKnife && g_playersKnife[player.Slot] == "weapon_knife") return;
|
||||||
|
|
||||||
if (isKnife && !g_playersKnife.ContainsKey(playerIndex) || isKnife && g_playersKnife[playerIndex] == "weapon_knife") return;
|
|
||||||
|
|
||||||
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
|
||||||
|
|
||||||
if (isKnife)
|
if (isKnife)
|
||||||
{
|
{
|
||||||
|
var newDefIndex = WeaponDefindex.FirstOrDefault(x => x.Value == g_playersKnife[player.Slot]);
|
||||||
|
if (newDefIndex.Key == 0) return;
|
||||||
|
|
||||||
|
if (weapon.AttributeManager.Item.ItemDefinitionIndex != newDefIndex.Key)
|
||||||
|
{
|
||||||
|
SubclassChange(weapon, (ushort)newDefIndex.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
weapon.AttributeManager.Item.ItemDefinitionIndex = (ushort)newDefIndex.Key;
|
||||||
weapon.AttributeManager.Item.EntityQuality = 3;
|
weapon.AttributeManager.Item.EntityQuality = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fallbackPaintKit = weapon.FallbackPaintKit;
|
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
||||||
|
int fallbackPaintKit = 0;
|
||||||
|
|
||||||
if (_config.Additional.GiveRandomSkin &&
|
if (_config.Additional.GiveRandomSkin &&
|
||||||
!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
!gPlayerWeaponsInfo[player.Slot].ContainsKey(weaponDefIndex))
|
||||||
{
|
{
|
||||||
// Random skins
|
// Random skins
|
||||||
weapon.AttributeManager.Item.ItemID = 16384;
|
weapon.AttributeManager.Item.ItemID = 16384;
|
||||||
@@ -38,6 +45,7 @@ namespace WeaponPaints
|
|||||||
weapon.FallbackPaintKit = GetRandomPaint(weaponDefIndex);
|
weapon.FallbackPaintKit = GetRandomPaint(weaponDefIndex);
|
||||||
weapon.FallbackSeed = 0;
|
weapon.FallbackSeed = 0;
|
||||||
weapon.FallbackWear = 0.000001f;
|
weapon.FallbackWear = 0.000001f;
|
||||||
|
CAttributeList_SetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "set item texture prefab", weapon.FallbackPaintKit);
|
||||||
|
|
||||||
fallbackPaintKit = weapon.FallbackPaintKit;
|
fallbackPaintKit = weapon.FallbackPaintKit;
|
||||||
|
|
||||||
@@ -49,11 +57,11 @@ namespace WeaponPaints
|
|||||||
((int?)skin?["paint"] ?? 0) == fallbackPaintKit &&
|
((int?)skin?["paint"] ?? 0) == fallbackPaintKit &&
|
||||||
skin?["paint_name"] != null
|
skin?["paint_name"] != null
|
||||||
);
|
);
|
||||||
|
/*
|
||||||
string skinName = foundSkin?["paint_name"]?.ToString() ?? "";
|
string skinName = foundSkin?["paint_name"]?.ToString() ?? "";
|
||||||
if (!string.IsNullOrEmpty(skinName))
|
if (!string.IsNullOrEmpty(skinName))
|
||||||
new SchemaString<CEconItemView>(weapon.AttributeManager.Item, "m_szCustomName").Set(skinName);
|
new SchemaString<CEconItemView>(weapon.AttributeManager.Item, "m_szCustomName").Set(skinName);
|
||||||
|
*/
|
||||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||||
{
|
{
|
||||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||||
@@ -86,8 +94,8 @@ namespace WeaponPaints
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex)) return;
|
if (!gPlayerWeaponsInfo[player.Slot].ContainsKey(weaponDefIndex)) return;
|
||||||
WeaponInfo weaponInfo = gPlayerWeaponsInfo[playerIndex][weaponDefIndex];
|
WeaponInfo weaponInfo = gPlayerWeaponsInfo[player.Slot][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]}");
|
//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.ItemID = 16384;
|
||||||
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
|
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
|
||||||
@@ -95,6 +103,7 @@ namespace WeaponPaints
|
|||||||
weapon.FallbackPaintKit = weaponInfo.Paint;
|
weapon.FallbackPaintKit = weaponInfo.Paint;
|
||||||
weapon.FallbackSeed = weaponInfo.Seed;
|
weapon.FallbackSeed = weaponInfo.Seed;
|
||||||
weapon.FallbackWear = weaponInfo.Wear;
|
weapon.FallbackWear = weaponInfo.Wear;
|
||||||
|
CAttributeList_SetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "set item texture prefab", weapon.FallbackPaintKit);
|
||||||
|
|
||||||
fallbackPaintKit = weapon.FallbackPaintKit;
|
fallbackPaintKit = weapon.FallbackPaintKit;
|
||||||
|
|
||||||
@@ -107,10 +116,11 @@ namespace WeaponPaints
|
|||||||
skin?["paint_name"] != null
|
skin?["paint_name"] != null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
var skinName1 = foundSkin1?["paint_name"]?.ToString() ?? "";
|
var skinName1 = foundSkin1?["paint_name"]?.ToString() ?? "";
|
||||||
if (!string.IsNullOrEmpty(skinName1))
|
if (!string.IsNullOrEmpty(skinName1))
|
||||||
new SchemaString<CEconItemView>(weapon.AttributeManager.Item, "m_szCustomName").Set(skinName1);
|
new SchemaString<CEconItemView>(weapon.AttributeManager.Item, "m_szCustomName").Set(skinName1);
|
||||||
|
*/
|
||||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||||
{
|
{
|
||||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||||
@@ -143,8 +153,10 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
|
if (!_config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
|
||||||
|
|
||||||
|
if (PlayerHasKnife(player)) return;
|
||||||
|
|
||||||
string knifeToGive;
|
string knifeToGive;
|
||||||
if (g_playersKnife.TryGetValue((int)player.Index, out var knife))
|
if (g_playersKnife.TryGetValue(player.Slot, out var knife))
|
||||||
{
|
{
|
||||||
knifeToGive = knife;
|
knifeToGive = knife;
|
||||||
}
|
}
|
||||||
@@ -174,12 +186,12 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return false;
|
if (!_config.Additional.KnifeEnabled) return false;
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.PlayerPawn == null || !player.PlayerPawn.IsValid || !player.PawnIsAlive)
|
if (player == null || !player.IsValid || player.PlayerPawn == null || !player.PlayerPawn.IsValid)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.PlayerPawn?.Value == null || player.PlayerPawn?.Value.WeaponServices == null || player.PlayerPawn?.Value.ItemServices == null)
|
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
|
var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
|
||||||
@@ -199,154 +211,248 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
internal void RefreshWeapons(CCSPlayerController? player)
|
internal void RefreshWeapons(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
|
if (!g_bCommandsAllowed) return;
|
||||||
if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE)
|
if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||||
|
|
||||||
if (weapons == null || weapons.Count == 0)
|
if (weapons == null || weapons.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
if (player.Team == CsTeam.None || player.Team == CsTeam.Spectator)
|
||||||
if (weapons != null && weapons.Count > 0)
|
|
||||||
{
|
|
||||||
//Dictionary<string, (int, int)> weaponsWithAmmo = new Dictionary<string, (int, int)>();
|
|
||||||
Dictionary<string, List<(int, int)>> weaponsWithAmmo = new Dictionary<string, List<(int, int)>>();
|
|
||||||
bool bomb = false;
|
|
||||||
bool defuser = player.PawnHasDefuser;
|
|
||||||
bool healthshot = false;
|
|
||||||
|
|
||||||
// Iterate through each weapon
|
|
||||||
foreach (var weapon in weapons)
|
|
||||||
{
|
|
||||||
if (weapon == null || !weapon.IsValid || weapon.Value == null ||
|
|
||||||
!weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string? weaponByDefindex = null;
|
|
||||||
|
|
||||||
CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData;
|
|
||||||
|
|
||||||
if (weaponData != null)
|
|
||||||
{
|
|
||||||
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_C4)
|
|
||||||
bomb = true;
|
|
||||||
|
|
||||||
if (weaponData.Name.Equals("weapon_healtshot"))
|
|
||||||
healthshot = true;
|
|
||||||
|
|
||||||
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_GRENADES || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_UTILITY || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_BOOSTS)
|
|
||||||
{
|
|
||||||
int clip1 = weapon.Value.Clip1;
|
|
||||||
int reservedAmmo = weapon.Value.ReserveAmmo[0];
|
|
||||||
|
|
||||||
weaponsWithAmmo.Add(weapon.Value.DesignerName, new List<(int, int)>() { (clip1, reservedAmmo) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!weapon.Value.DesignerName.Contains("knife") && WeaponDefindex.TryGetValue(weapon.Value.AttributeManager.Item.ItemDefinitionIndex, out weaponByDefindex) && weaponByDefindex != null)
|
|
||||||
{
|
|
||||||
int clip1 = weapon.Value.Clip1;
|
|
||||||
int reservedAmmo = weapon.Value.ReserveAmmo[0];
|
|
||||||
|
|
||||||
if (!weaponsWithAmmo.ContainsKey(weaponByDefindex))
|
|
||||||
{
|
|
||||||
weaponsWithAmmo.Add(weaponByDefindex, new List<(int, int)>());
|
|
||||||
}
|
|
||||||
|
|
||||||
weaponsWithAmmo[weaponByDefindex].Add((clip1, reservedAmmo));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.LogWarning(ex.Message);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player.RemoveWeapons();
|
|
||||||
AddTimer(0.35f, () =>
|
|
||||||
{
|
|
||||||
GiveKnifeToPlayer(player);
|
|
||||||
|
|
||||||
if (bomb)
|
|
||||||
player.GiveNamedItem("weapon_c4");
|
|
||||||
|
|
||||||
if (defuser)
|
|
||||||
{
|
|
||||||
var itemServ = player.PlayerPawn?.Value?.ItemServices;
|
|
||||||
if (itemServ != null)
|
|
||||||
{
|
|
||||||
var items = new CCSPlayer_ItemServices(itemServ.Handle);
|
|
||||||
items.HasDefuser = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (healthshot)
|
|
||||||
player.GiveNamedItem("weapon_healtshot");
|
|
||||||
|
|
||||||
foreach (var entry in weaponsWithAmmo)
|
|
||||||
{
|
|
||||||
foreach (var ammo in entry.Value)
|
|
||||||
{
|
|
||||||
var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(entry.Key));
|
|
||||||
Server.NextFrame(() =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (newWeapon != null)
|
|
||||||
{
|
|
||||||
newWeapon.Clip1 = ammo.Item1;
|
|
||||||
newWeapon.ReserveAmmo[0] = ammo.Item2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.LogWarning("Error setting weapon properties: " + ex.Message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void RefreshKnife(CCSPlayerController? player)
|
|
||||||
{
|
|
||||||
if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
int playerTeam = player.TeamNum;
|
||||||
|
|
||||||
|
//Dictionary<string, (int, int)> weaponsWithAmmo = new Dictionary<string, (int, int)>();
|
||||||
|
Dictionary<string, List<(int, int)>> weaponsWithAmmo = new Dictionary<string, List<(int, int)>>();
|
||||||
|
|
||||||
|
// Iterate through each weapon
|
||||||
|
foreach (var weapon in weapons)
|
||||||
|
{
|
||||||
|
if (weapon == null || !weapon.IsValid || weapon.Value == null ||
|
||||||
|
!weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
CCSWeaponBaseGun gun = weapon.Value.As<CCSWeaponBaseGun>();
|
||||||
|
|
||||||
|
if (weapon.Value.Entity == null) continue;
|
||||||
|
if (weapon.Value.OwnerEntity == null) continue;
|
||||||
|
if (!weapon.Value.OwnerEntity.IsValid) continue;
|
||||||
|
if (gun == null) continue;
|
||||||
|
if (gun.Entity == null) continue;
|
||||||
|
if (!gun.IsValid) continue;
|
||||||
|
if (!gun.VisibleinPVS) continue;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string? weaponByDefindex = null;
|
||||||
|
|
||||||
|
CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData;
|
||||||
|
|
||||||
|
if (weaponData == null) continue;
|
||||||
|
|
||||||
|
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_RIFLE || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_PISTOL)
|
||||||
|
{
|
||||||
|
if (!WeaponDefindex.TryGetValue(weapon.Value.AttributeManager.Item.ItemDefinitionIndex, out weaponByDefindex))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int clip1 = weapon.Value.Clip1;
|
||||||
|
int reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||||
|
|
||||||
|
if (!weaponsWithAmmo.ContainsKey(weaponByDefindex))
|
||||||
|
{
|
||||||
|
weaponsWithAmmo.Add(weaponByDefindex, new List<(int, int)>());
|
||||||
|
}
|
||||||
|
|
||||||
|
weaponsWithAmmo[weaponByDefindex].Add((clip1, reservedAmmo));
|
||||||
|
|
||||||
|
if (gun == null || gun.VData == null) return;
|
||||||
|
|
||||||
|
weapon.Value.Remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogWarning(ex.Message);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
player.ExecuteClientCommand("slot 3");
|
||||||
|
player.ExecuteClientCommand("slot 3");
|
||||||
|
|
||||||
|
var weapon = player.PlayerPawn.Value.WeaponServices.ActiveWeapon;
|
||||||
|
if (weapon is null || !weapon.IsValid || weapon.Value == null) return;
|
||||||
|
CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData;
|
||||||
|
|
||||||
|
if (weapon.Value.DesignerName.Contains("knife") || weaponData?.GearSlot == gear_slot_t.GEAR_SLOT_KNIFE)
|
||||||
|
{
|
||||||
|
CCSWeaponBaseGun gun = weapon.Value.As<CCSWeaponBaseGun>();
|
||||||
|
|
||||||
|
AddTimer(0.3f, () =>
|
||||||
|
{
|
||||||
|
if (player.TeamNum != playerTeam) return;
|
||||||
|
|
||||||
|
player.ExecuteClientCommand("slot 3");
|
||||||
|
gun = weapon.Value.As<CCSWeaponBaseGun>();
|
||||||
|
player.DropActiveWeapon();
|
||||||
|
|
||||||
|
AddTimer(0.7f, () =>
|
||||||
|
{
|
||||||
|
if (player.TeamNum != playerTeam) return;
|
||||||
|
|
||||||
|
if (gun == null || !gun.IsValid || gun.State != CSWeaponState_t.WEAPON_NOT_CARRIED) return;
|
||||||
|
|
||||||
|
gun.Remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
GiveKnifeToPlayer(player);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogWarning($"Cannot remove knife: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
AddTimer(0.6f, () =>
|
||||||
|
{
|
||||||
|
if (!g_bCommandsAllowed) return;
|
||||||
|
|
||||||
|
foreach (var entry in weaponsWithAmmo)
|
||||||
|
{
|
||||||
|
foreach (var ammo in entry.Value)
|
||||||
|
{
|
||||||
|
var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(entry.Key));
|
||||||
|
Server.NextFrame(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (newWeapon != null)
|
||||||
|
{
|
||||||
|
newWeapon.Clip1 = ammo.Item1;
|
||||||
|
newWeapon.ReserveAmmo[0] = ammo.Item2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogWarning("Error setting weapon properties: " + ex.Message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, TimerFlags.STOP_ON_MAPCHANGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
internal void RefreshKnife(CCSPlayerController? player)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
if (player == null || !player.IsValid || player.PlayerPawn?.Value == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (player.PlayerPawn.Value.WeaponServices == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||||
if (weapons != null && weapons.Count > 0)
|
if (weapons != null && weapons.Count > 0)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
player.ExecuteClientCommand("slot 3");
|
||||||
|
player.ExecuteClientCommand("slot 3");
|
||||||
|
|
||||||
|
var weapon = player.PlayerPawn.Value.WeaponServices.ActiveWeapon;
|
||||||
|
if (weapon is null || !weapon.IsValid || weapon.Value == null) return;
|
||||||
|
CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData;
|
||||||
|
|
||||||
|
if (weapon.Value.DesignerName.Contains("knife") || weaponData?.GearSlot == gear_slot_t.GEAR_SLOT_KNIFE)
|
||||||
|
{
|
||||||
|
AddTimer(0.2f, () =>
|
||||||
|
{
|
||||||
|
player.ExecuteClientCommand("slot 3");
|
||||||
|
player.DropActiveWeapon();
|
||||||
|
|
||||||
|
AddTimer(0.6f, () =>
|
||||||
|
{
|
||||||
|
if (weapon.IsValid)
|
||||||
|
weapon.Value.Remove();
|
||||||
|
GiveKnifeToPlayer(player);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogWarning($"Cannot remove knife: {ex.Message}");
|
||||||
|
}
|
||||||
|
return;
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid && weapon.Index > 0)
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid && weapon.Index > 0)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData;
|
|
||||||
|
|
||||||
if (weapon.Value.DesignerName.Contains("knife") || weaponData?.GearSlot == gear_slot_t.GEAR_SLOT_KNIFE)
|
|
||||||
{
|
|
||||||
RefreshWeapons(player);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.LogWarning($"Cannot remove knife: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static void RefreshGloves(CCSPlayerController player)
|
||||||
|
{
|
||||||
|
if (!Utility.IsPlayerValid(player) || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE) return;
|
||||||
|
|
||||||
|
CCSPlayerPawn? pawn = player.PlayerPawn.Value;
|
||||||
|
if (pawn == null || !pawn.IsValid || pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string model = pawn.CBodyComponent?.SceneNode?.GetSkeletonInstance()?.ModelState.ModelName ?? string.Empty;
|
||||||
|
if (!string.IsNullOrEmpty(model))
|
||||||
|
{
|
||||||
|
pawn.SetModel("characters/models/tm_jumpsuit/tm_jumpsuit_varianta.vmdl");
|
||||||
|
pawn.SetModel(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
Instance.AddTimer(0.06f, () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (player == null || !player.IsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (pawn == null || !pawn.IsValid || pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (g_playersGlove.TryGetValue(player.Slot, out var gloveInfo) && gloveInfo != 0)
|
||||||
|
{
|
||||||
|
CCSPlayerPawn? pawn = player.PlayerPawn.Value;
|
||||||
|
if (pawn == null || !pawn.IsValid || pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
WeaponInfo weaponInfo = gPlayerWeaponsInfo[player.Slot][gloveInfo];
|
||||||
|
|
||||||
|
CEconItemView item = pawn.EconGloves;
|
||||||
|
item.ItemDefinitionIndex = gloveInfo;
|
||||||
|
item.ItemIDLow = 16384 & 0xFFFFFFFF;
|
||||||
|
item.ItemIDHigh = 16384;
|
||||||
|
|
||||||
|
CAttributeList_SetOrAddAttributeValueByName.Invoke(item.NetworkedDynamicAttributes.Handle, "set item texture prefab", weaponInfo.Paint);
|
||||||
|
CAttributeList_SetOrAddAttributeValueByName.Invoke(item.NetworkedDynamicAttributes.Handle, "set item texture seed", weaponInfo.Seed);
|
||||||
|
CAttributeList_SetOrAddAttributeValueByName.Invoke(item.NetworkedDynamicAttributes.Handle, "set item texture wear", weaponInfo.Wear);
|
||||||
|
|
||||||
|
item.Initialized = true;
|
||||||
|
|
||||||
|
CBaseModelEntity_SetBodygroup.Invoke(pawn, "default_gloves", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
}, TimerFlags.STOP_ON_MAPCHANGE);
|
||||||
|
}
|
||||||
|
|
||||||
private static int GetRandomPaint(int defindex)
|
private static int GetRandomPaint(int defindex)
|
||||||
{
|
{
|
||||||
@@ -369,24 +475,30 @@ namespace WeaponPaints
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SubclassChange(CBasePlayerWeapon weapon, ushort itemD)
|
||||||
|
{
|
||||||
|
var SubclassChangeFunc = VirtualFunction.Create<nint, string, int>(
|
||||||
|
GameData.GetSignature("ChangeSubclass")
|
||||||
|
);
|
||||||
|
|
||||||
|
SubclassChangeFunc(weapon.Handle, itemD.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CCSPlayerController? GetPlayerFromItemServices(CCSPlayer_ItemServices itemServices)
|
||||||
|
{
|
||||||
|
var pawn = itemServices.Pawn.Value;
|
||||||
|
if (pawn == null || !pawn.IsValid || !pawn.Controller.IsValid || pawn.Controller.Value == null) return null;
|
||||||
|
var player = new CCSPlayerController(pawn.Controller.Value.Handle);
|
||||||
|
if (!Utility.IsPlayerValid(player)) return null;
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
private static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
private static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
||||||
{
|
{
|
||||||
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
||||||
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetOrAddAttributeValueByName(CAttributeList attr, string name, float f)
|
|
||||||
{
|
|
||||||
var SetAttr = VirtualFunction.Create<IntPtr, string, float, int>("\\x55\\x48\\x89\\xE5\\x41\\x57\\x41\\x56\\x49\\x89\\xFE\\x41\\x55\\x41\\x54\\x49\\x89\\xF4\\x53\\x48\\x83\\xEC\\x78");
|
|
||||||
SetAttr(attr.Handle, name, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetPlayerBody(CCSPlayerController player, string model, int i)
|
|
||||||
{
|
|
||||||
var SetBody = VirtualFunction.Create<IntPtr, string, int, int>("\\x55\\x48\\x89\\xE5\\x41\\x56\\x49\\x89\\xF6\\x41\\x55\\x41\\x89\\xD5\\x41\\x54\\x49\\x89\\xFC\\x48\\x83\\xEC\\x08");
|
|
||||||
SetBody(player.PlayerPawn.Value!.Handle, model, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static unsafe CHandle<CBaseViewModel>[]? GetPlayerViewModels(CCSPlayerController player)
|
private static unsafe CHandle<CBaseViewModel>[]? GetPlayerViewModels(CCSPlayerController player)
|
||||||
{
|
{
|
||||||
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.ViewModelServices == null) return null;
|
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.ViewModelServices == null) return null;
|
||||||
@@ -397,7 +509,7 @@ namespace WeaponPaints
|
|||||||
public static unsafe T[] GetFixedArray<T>(nint pointer, string @class, string member, int length) where T : CHandle<CBaseViewModel>
|
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);
|
nint ptr = pointer + Schema.GetSchemaOffset(@class, member);
|
||||||
Span<nint> references = MemoryMarshal.CreateSpan<nint>(ref ptr, length);
|
Span<nint> references = MemoryMarshal.CreateSpan(ref ptr, length);
|
||||||
T[] values = new T[length];
|
T[] values = new T[length];
|
||||||
|
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
public class WeaponInfo
|
public class WeaponInfo
|
||||||
{
|
{
|
||||||
public int Paint { get; set; }
|
public int Paint { get; set; }
|
||||||
public int Seed { get; set; }
|
public int Seed { get; set; } = 0;
|
||||||
public float Wear { get; set; }
|
public float Wear { get; set; } = 0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
114
WeaponPaints.cs
114
WeaponPaints.cs
@@ -1,7 +1,7 @@
|
|||||||
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.Cvars;
|
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
@@ -10,9 +10,11 @@ using System.Collections.Concurrent;
|
|||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
|
|
||||||
[MinimumApiVersion(167)]
|
[MinimumApiVersion(178)]
|
||||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
|
internal static WeaponPaints Instance { get; private set; } = new();
|
||||||
|
|
||||||
internal static readonly Dictionary<string, string> weaponList = new()
|
internal static readonly Dictionary<string, string> weaponList = new()
|
||||||
{
|
{
|
||||||
{"weapon_deagle", "Desert Eagle"},
|
{"weapon_deagle", "Desert Eagle"},
|
||||||
@@ -77,19 +79,20 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
internal static IStringLocalizer? _localizer;
|
internal static IStringLocalizer? _localizer;
|
||||||
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
||||||
internal static ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>();
|
internal static ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>();
|
||||||
internal static ConcurrentDictionary<uint, (ushort Definition, int Paint)> g_playersGlove = new ConcurrentDictionary<uint, (ushort Definition, int Paint)>();
|
internal static ConcurrentDictionary<int, ushort> g_playersGlove = new ConcurrentDictionary<int, ushort>();
|
||||||
internal static ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>>();
|
internal static ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>>();
|
||||||
internal static List<JObject> skinsList = new List<JObject>();
|
internal static List<JObject> skinsList = new List<JObject>();
|
||||||
internal static List<JObject> glovesList = new List<JObject>();
|
internal static List<JObject> glovesList = new List<JObject>();
|
||||||
internal static WeaponSynchronization? weaponSync;
|
internal static WeaponSynchronization? weaponSync;
|
||||||
internal bool g_bCommandsAllowed = true;
|
public static bool g_bCommandsAllowed = true;
|
||||||
internal Dictionary<int, string> PlayerWeaponImage = new();
|
internal Dictionary<int, string> PlayerWeaponImage = new();
|
||||||
|
|
||||||
internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php");
|
|
||||||
internal int GlobalShareServerId = 0;
|
|
||||||
internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
|
internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
|
||||||
internal static Database? _database;
|
internal static Database? _database;
|
||||||
|
|
||||||
|
internal static MemoryFunctionVoid<nint, string, float> CAttributeList_SetOrAddAttributeValueByName = new(GameData.GetSignature("CAttributeList_SetOrAddAttributeValueByName"));
|
||||||
|
internal static MemoryFunctionVoid<CBaseModelEntity, string, UInt64> CBaseModelEntity_SetBodygroup = new(GameData.GetSignature("CBaseModelEntity_SetBodygroup"));
|
||||||
|
|
||||||
public static Dictionary<int, string> WeaponDefindex { get; } = new Dictionary<int, string>
|
public static Dictionary<int, string> WeaponDefindex { get; } = new Dictionary<int, string>
|
||||||
{
|
{
|
||||||
{ 1, "weapon_deagle" },
|
{ 1, "weapon_deagle" },
|
||||||
@@ -153,7 +156,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
public override string ModuleDescription => "Skin, gloves and knife selector, standalone and web-based";
|
public override string ModuleDescription => "Skin, gloves and knife selector, standalone and web-based";
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
public override string ModuleVersion => "1.8a";
|
public override string ModuleVersion => "2.0a";
|
||||||
|
|
||||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||||
{
|
{
|
||||||
@@ -162,6 +165,8 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
|
Instance = this;
|
||||||
|
|
||||||
if (hotReload)
|
if (hotReload)
|
||||||
{
|
{
|
||||||
OnMapStart(string.Empty);
|
OnMapStart(string.Empty);
|
||||||
@@ -172,25 +177,32 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected)
|
player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
g_knifePickupCount[(int)player.Index] = 0;
|
g_knifePickupCount[(int)player.Slot] = 0;
|
||||||
gPlayerWeaponsInfo.TryRemove((int)player.Index, out _);
|
gPlayerWeaponsInfo.TryRemove((int)player.Slot, out _);
|
||||||
g_playersKnife.TryRemove((int)player.Index, out _);
|
g_playersKnife.TryRemove((int)player.Slot, out _);
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
Index = (int)player.Index,
|
Slot = player.Slot,
|
||||||
|
Index = (int)player.Slot,
|
||||||
SteamId = player?.SteamID.ToString(),
|
SteamId = player?.SteamID.ToString(),
|
||||||
Name = player?.PlayerName,
|
Name = player?.PlayerName,
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
_ = weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
{
|
||||||
|
Task.Run(() => weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||||
|
}
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
_ = weaponSync.GetKnifeFromDatabase(playerInfo);
|
{
|
||||||
|
Task.Run(() => weaponSync.GetKnifeFromDatabase(playerInfo));
|
||||||
|
}
|
||||||
if (Config.Additional.GloveEnabled)
|
if (Config.Additional.GloveEnabled)
|
||||||
_ = weaponSync.GetGloveFromDatabase(playerInfo);
|
{
|
||||||
|
Task.Run(() => weaponSync.GetGloveFromDatabase(playerInfo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,29 +222,26 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
|
|
||||||
public void OnConfigParsed(WeaponPaintsConfig config)
|
public void OnConfigParsed(WeaponPaintsConfig config)
|
||||||
{
|
{
|
||||||
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)
|
Logger.LogError("You need to setup Database credentials in config!");
|
||||||
{
|
throw new Exception("[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!");
|
|
||||||
}
|
|
||||||
|
|
||||||
var builder = new MySqlConnectionStringBuilder
|
|
||||||
{
|
|
||||||
Server = config.DatabaseHost,
|
|
||||||
UserID = config.DatabaseUser,
|
|
||||||
Password = config.DatabasePassword,
|
|
||||||
Database = config.DatabaseName,
|
|
||||||
Port = (uint)config.DatabasePort,
|
|
||||||
Pooling = true
|
|
||||||
};
|
|
||||||
|
|
||||||
_database = new(builder.ConnectionString);
|
|
||||||
|
|
||||||
_ = Utility.CheckDatabaseTables();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var builder = new MySqlConnectionStringBuilder
|
||||||
|
{
|
||||||
|
Server = config.DatabaseHost,
|
||||||
|
UserID = config.DatabaseUser,
|
||||||
|
Password = config.DatabasePassword,
|
||||||
|
Database = config.DatabaseName,
|
||||||
|
Port = (uint)config.DatabasePort,
|
||||||
|
Pooling = true
|
||||||
|
};
|
||||||
|
|
||||||
|
_database = new(builder.ConnectionString);
|
||||||
|
|
||||||
|
_ = Utility.CheckDatabaseTables();
|
||||||
|
|
||||||
Config = config;
|
Config = config;
|
||||||
_config = config;
|
_config = config;
|
||||||
_localizer = Localizer;
|
_localizer = Localizer;
|
||||||
@@ -246,41 +255,4 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
{
|
{
|
||||||
base.Unload(hotReload);
|
base.Unload(hotReload);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GlobalShareConnect()
|
|
||||||
{
|
|
||||||
if (!Config.GlobalShare) return;
|
|
||||||
|
|
||||||
var values = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "server_address", $"{ConVar.Find("ip")!.StringValue}:{ConVar.Find("hostport")!.GetPrimitiveValue<int>().ToString()}" },
|
|
||||||
{ "server_hostname", ConVar.Find("hostname")!.StringValue }
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var httpClient = new HttpClient())
|
|
||||||
{
|
|
||||||
httpClient.BaseAddress = GlobalShareApi;
|
|
||||||
var formContent = new FormUrlEncodedContent(values);
|
|
||||||
|
|
||||||
Task<HttpResponseMessage> responseTask = httpClient.PostAsync("", formContent);
|
|
||||||
responseTask.Wait();
|
|
||||||
HttpResponseMessage response = responseTask.Result;
|
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
Task<string> responseBodyTask = response.Content.ReadAsStringAsync();
|
|
||||||
responseBodyTask.Wait();
|
|
||||||
string responseBody = responseBodyTask.Result;
|
|
||||||
GlobalShareServerId = int.Parse(responseBody);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.168" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.179" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.28" />
|
<PackageReference Include="Dapper" Version="2.1.28" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.5" />
|
<PackageReference Include="MySqlConnector" Version="2.3.5" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
@@ -18,4 +18,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
|
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="gamedata\*.*" CopyToOutputDirectory="PreserveNewest" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
@@ -8,60 +7,19 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
private readonly WeaponPaintsConfig _config;
|
private readonly WeaponPaintsConfig _config;
|
||||||
private readonly Database _database;
|
private readonly Database _database;
|
||||||
private readonly Uri _globalShareApi;
|
|
||||||
private readonly int _globalShareServerId;
|
|
||||||
|
|
||||||
internal WeaponSynchronization(Database database, WeaponPaintsConfig config, Uri globalShareApi, int globalShareServerId)
|
internal WeaponSynchronization(Database database, WeaponPaintsConfig config)
|
||||||
{
|
{
|
||||||
_database = database;
|
_database = database;
|
||||||
_config = config;
|
_config = config;
|
||||||
_globalShareApi = globalShareApi;
|
|
||||||
_globalShareServerId = globalShareServerId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task GetKnifeFromDatabase(PlayerInfo player)
|
public async Task GetKnifeFromDatabase(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return;
|
|
||||||
if (player.SteamId == null || player.Index == 0) return;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_config.GlobalShare)
|
if (!_config.Additional.KnifeEnabled || string.IsNullOrEmpty(player?.SteamId))
|
||||||
{
|
|
||||||
var values = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "server_id", _globalShareServerId.ToString() },
|
|
||||||
{ "steamid", player.SteamId },
|
|
||||||
{ "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;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
||||||
@@ -69,129 +27,81 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (!string.IsNullOrEmpty(playerKnife))
|
if (!string.IsNullOrEmpty(playerKnife))
|
||||||
{
|
{
|
||||||
WeaponPaints.g_playersKnife[player.Index] = playerKnife;
|
WeaponPaints.g_playersKnife[player.Slot] = playerKnife;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Utility.Log(e.Message);
|
Utility.Log($"An error occurred in GetKnifeFromDatabase: {ex.Message}");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task GetGloveFromDatabase(PlayerInfo player)
|
public async Task GetGloveFromDatabase(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.GloveEnabled) return;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (!_config.Additional.GloveEnabled || string.IsNullOrEmpty(player?.SteamId))
|
||||||
|
return;
|
||||||
|
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
string query = "SELECT `weapon_defindex`, `paint` FROM `wp_player_gloves` WHERE `steamid` = @steamid";
|
string query = "SELECT `weapon_defindex` FROM `wp_player_gloves` WHERE `steamid` = @steamid";
|
||||||
var gloveData = await connection.QueryFirstOrDefaultAsync<(ushort Definition, int Paint)>(query, new { steamid = player.SteamId });
|
ushort? gloveData = await connection.QueryFirstOrDefaultAsync<ushort?>(query, new { steamid = player.SteamId });
|
||||||
|
|
||||||
if (gloveData != default)
|
if (gloveData != null)
|
||||||
{
|
{
|
||||||
WeaponPaints.g_playersGlove[(uint)player.Index] = gloveData;
|
WeaponPaints.g_playersGlove[player.Slot] = gloveData.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Utility.Log(e.Message);
|
Utility.Log($"An error occurred in GetGloveFromDatabase: {ex.Message}");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
public async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.SkinEnabled) return;
|
|
||||||
|
|
||||||
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
|
|
||||||
{
|
|
||||||
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new ConcurrentDictionary<int, WeaponInfo>();
|
|
||||||
}
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_config.GlobalShare)
|
if (!_config.Additional.SkinEnabled || player == null || string.IsNullOrEmpty(player.SteamId))
|
||||||
{
|
return;
|
||||||
var values = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "server_id", _globalShareServerId.ToString() },
|
|
||||||
{ "steamid", player.SteamId },
|
|
||||||
{ "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)
|
|
||||||
{
|
|
||||||
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>();
|
|
||||||
|
|
||||||
if (weaponDefIndex != null && weaponPaintId != null && weaponWear != null && weaponSeed != null)
|
|
||||||
{
|
|
||||||
WeaponInfo weaponInfo = new WeaponInfo
|
|
||||||
{
|
|
||||||
Paint = weaponPaintId.Value,
|
|
||||||
Seed = weaponSeed.Value,
|
|
||||||
Wear = weaponWear.Value
|
|
||||||
};
|
|
||||||
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex.Value] = weaponInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||||
var playerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });
|
var playerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });
|
||||||
|
|
||||||
|
if (playerSkins == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var weaponInfos = new ConcurrentDictionary<int, WeaponInfo>();
|
||||||
|
|
||||||
foreach (var row in playerSkins)
|
foreach (var row in playerSkins)
|
||||||
{
|
{
|
||||||
int? weaponDefIndex = row.weapon_defindex;
|
int weaponDefIndex = row?.weapon_defindex ?? 0;
|
||||||
int? weaponPaintId = row.weapon_paint_id;
|
int weaponPaintId = row?.weapon_paint_id ?? 0;
|
||||||
float? weaponWear = row.weapon_wear;
|
float weaponWear = row?.weapon_wear ?? 0f;
|
||||||
int? weaponSeed = row.weapon_seed;
|
int weaponSeed = row?.weapon_seed ?? 0;
|
||||||
|
|
||||||
WeaponInfo weaponInfo = new WeaponInfo
|
WeaponInfo weaponInfo = new WeaponInfo
|
||||||
{
|
{
|
||||||
Paint = weaponPaintId.HasValue ? weaponPaintId.Value : 0,
|
Paint = weaponPaintId,
|
||||||
Seed = weaponSeed.HasValue ? weaponSeed.Value : 0,
|
Seed = weaponSeed,
|
||||||
Wear = weaponWear.HasValue ? weaponWear.Value : 0f
|
Wear = weaponWear
|
||||||
};
|
};
|
||||||
|
|
||||||
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex.GetValueOrDefault()] = weaponInfo;
|
weaponInfos[weaponDefIndex] = weaponInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WeaponPaints.gPlayerWeaponsInfo[player.Slot] = weaponInfos;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Utility.Log(e.Message);
|
Utility.Log($"An error occurred in GetWeaponPaintsFromDatabase: {ex.Message}");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task SyncKnifeToDatabase(PlayerInfo player, string knife)
|
internal async Task SyncKnifeToDatabase(PlayerInfo player, string knife)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return;
|
if (!_config.Additional.KnifeEnabled || player == null || string.IsNullOrEmpty(player.SteamId) || string.IsNullOrEmpty(knife)) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -201,52 +111,68 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Utility.Log(e.Message);
|
Utility.Log($"Error syncing knife to database: {e.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task SyncGloveToDatabase(PlayerInfo player, ushort defindex, int paint)
|
internal async Task SyncGloveToDatabase(PlayerInfo player, int defindex)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.GloveEnabled) return;
|
if (!_config.Additional.GloveEnabled || player == null || string.IsNullOrEmpty(player.SteamId)) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
string query = "INSERT INTO `wp_player_gloves` (`steamid`, `weapon_defindex`, `paint`) VALUES(@steamid, @weapon_defindex, @paint) ON DUPLICATE KEY UPDATE `weapon_defindex` = @weapon_defindex, `paint` = @paint";
|
string query = "INSERT INTO `wp_player_gloves` (`steamid`, `weapon_defindex`) VALUES(@steamid, @weapon_defindex) ON DUPLICATE KEY UPDATE `weapon_defindex` = @weapon_defindex";
|
||||||
await connection.ExecuteAsync(query, new { steamid = player.SteamId, weapon_defindex = defindex, paint });
|
await connection.ExecuteAsync(query, new { steamid = player.SteamId, weapon_defindex = defindex });
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Utility.Log(e.Message);
|
Utility.Log($"Error syncing glove to database: {e.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task SyncWeaponPaintsToDatabase(PlayerInfo player)
|
internal async Task SyncWeaponPaintsToDatabase(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (player == null || player.Index <= 0 || player.SteamId == null) return;
|
if (player == null || string.IsNullOrEmpty(player.SteamId) || !WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Slot, out var weaponsInfo))
|
||||||
|
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
|
||||||
|
|
||||||
if (!WeaponPaints.gPlayerWeaponsInfo.ContainsKey(player.Index))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var weaponInfoPair in WeaponPaints.gPlayerWeaponsInfo[player.Index])
|
try
|
||||||
{
|
{
|
||||||
int weaponDefIndex = weaponInfoPair.Key;
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
WeaponInfo weaponInfo = weaponInfoPair.Value;
|
|
||||||
|
|
||||||
int paintId = weaponInfo.Paint;
|
foreach (var weaponInfoPair in weaponsInfo)
|
||||||
float wear = weaponInfo.Wear;
|
{
|
||||||
int seed = weaponInfo.Seed;
|
int weaponDefIndex = weaponInfoPair.Key;
|
||||||
|
WeaponInfo weaponInfo = weaponInfoPair.Value;
|
||||||
|
|
||||||
string updateSql = "INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, " +
|
int paintId = weaponInfo.Paint;
|
||||||
"`weapon_paint_id`, `weapon_wear`, `weapon_seed`) " +
|
float wear = weaponInfo.Wear;
|
||||||
"VALUES (@steamid, @weaponDefIndex, @paintId, @wear, @seed) " +
|
int seed = weaponInfo.Seed;
|
||||||
"ON DUPLICATE KEY UPDATE `weapon_paint_id` = @paintId, " +
|
|
||||||
"`weapon_wear` = @wear, `weapon_seed` = @seed";
|
|
||||||
|
|
||||||
var updateParams = new { steamid = player.SteamId, weaponDefIndex, paintId, wear, seed };
|
string queryCheckExistence = "SELECT COUNT(*) FROM `wp_player_skins` WHERE `steamid` = @steamid AND `weapon_defindex` = @weaponDefIndex";
|
||||||
await connection.ExecuteAsync(updateSql, updateParams);
|
|
||||||
|
int existingRecordCount = await connection.ExecuteScalarAsync<int>(queryCheckExistence, new { steamid = player.SteamId, weaponDefIndex });
|
||||||
|
|
||||||
|
string query;
|
||||||
|
object parameters;
|
||||||
|
if (existingRecordCount > 0)
|
||||||
|
{
|
||||||
|
query = "UPDATE `wp_player_skins` SET `weapon_paint_id` = @paintId, `weapon_wear` = @wear, `weapon_seed` = @seed WHERE `steamid` = @steamid AND `weapon_defindex` = @weaponDefIndex";
|
||||||
|
parameters = new { steamid = player.SteamId, weaponDefIndex, paintId, wear, seed };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
query = "INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed`) " +
|
||||||
|
"VALUES (@steamid, @weaponDefIndex, @paintId, @wear, @seed)";
|
||||||
|
parameters = new { steamid = player.SteamId, weaponDefIndex, paintId, wear, seed };
|
||||||
|
}
|
||||||
|
|
||||||
|
await connection.ExecuteAsync(query, parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utility.Log($"Error syncing weapon paints to database: {e.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
gamedata/weaponpaints.json
Normal file
23
gamedata/weaponpaints.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"ChangeSubclass": {
|
||||||
|
"signatures": {
|
||||||
|
"library": "server",
|
||||||
|
"windows": "\\x48\\x89\\x5C\\x24\\x08\\x57\\x48\\x83\\xEC\\x20\\x48\\x8B\\xDA\\x48\\x8B\\xF9\\xE8\\x2A\\x2A\\x2A\\x2A\\x84\\xC0\\x74\\x2A\\x41\\xB0\\x01",
|
||||||
|
"linux": "\\x55\\x48\\x89\\xE5\\x41\\x57\\x41\\x56\\x41\\x55\\x49\\x89\\xF5\\x41\\x54\\x49\\x89\\xFC\\x53\\x48\\x81\\xEC\\xA8\\x00\\x00\\x00"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"CAttributeList_SetOrAddAttributeValueByName": {
|
||||||
|
"signatures": {
|
||||||
|
"library": "server",
|
||||||
|
"windows": "\\x40\\x53\\x41\\x56\\x41\\x57\\x48\\x81\\xEC\\x90\\x00\\x00\\x00\\x0F\\x29\\x74\\x24\\x70",
|
||||||
|
"linux": "\\x55\\x48\\x89\\xE5\\x41\\x57\\x41\\x56\\x49\\x89\\xFE\\x41\\x55\\x41\\x54\\x49\\x89\\xF4\\x53\\x48\\x83\\xEC\\x78"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"CBaseModelEntity_SetBodygroup": {
|
||||||
|
"signatures": {
|
||||||
|
"library": "server",
|
||||||
|
"windows": "\\x48\\x89\\x5C\\x24\\x08\\x48\\x89\\x74\\x24\\x10\\x57\\x48\\x83\\xEC\\x20\\x41\\x8B\\xF8\\x48\\x8B\\xF2\\x48\\x8B\\xD9\\xE8\\x2A\\x2A\\x2A\\x2A",
|
||||||
|
"linux": "\\x55\\x48\\x89\\xE5\\x41\\x56\\x49\\x89\\xF6\\x41\\x55\\x41\\x89\\xD5\\x41\\x54\\x49\\x89\\xFC\\x48\\x83\\xEC\\x08"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
"wp_command_cooldown": "{lightred}Nie możesz teraz odświeżyć skórek broni",
|
"wp_command_cooldown": "{lightred}Nie możesz teraz odświeżyć skórek broni",
|
||||||
"wp_command_refresh_done": "{lime}Odświeżanie skórek broni",
|
"wp_command_refresh_done": "{lime}Odświeżanie skórek broni",
|
||||||
"wp_knife_menu_select": "Wybrałeś {lime}{0}{default} jako swój nóż",
|
"wp_knife_menu_select": "Wybrałeś {lime}{0}{default} jako swój nóż",
|
||||||
"wp_knife_menu_kill": "",
|
"wp_knife_menu_kill": "{lime}Wybrane skiny będą ustawione dopiero po ponownym wejściu na serwer lub wpisaniu komendy {orange}!kill",
|
||||||
"wp_knife_menu_title": "Menu Noży",
|
"wp_knife_menu_title": "Menu Noży",
|
||||||
"wp_glove_menu_select": "Wybrałeś {lime}{0}{default} jako swoje rękawiczki",
|
"wp_glove_menu_select": "Wybrałeś {lime}{0}{default} jako swoje rękawiczki",
|
||||||
"wp_glove_menu_title": "Menu Rękawiczek",
|
"wp_glove_menu_title": "Menu Rękawiczek",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user