mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 18:49:21 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6d4108ca7 | ||
|
|
7b45169d8d | ||
|
|
42bd45c3f0 | ||
|
|
5262739c3d | ||
|
|
c82a0c0d26 | ||
|
|
9ad7f9fc83 | ||
|
|
9e2dac52e5 |
22
Config.cs
22
Config.cs
@@ -17,6 +17,8 @@ namespace WeaponPaints
|
|||||||
public string SuccessRefreshCommand { get; set; } = "Refreshing weapon paints.";
|
public string SuccessRefreshCommand { get; set; } = "Refreshing weapon paints.";
|
||||||
[JsonPropertyName("ChosenKnifeMenu")]
|
[JsonPropertyName("ChosenKnifeMenu")]
|
||||||
public string ChosenKnifeMenu { get; set; } = "You have chosen {KNIFE} as your knife.";
|
public string ChosenKnifeMenu { get; set; } = "You have chosen {KNIFE} as your knife.";
|
||||||
|
[JsonPropertyName("ChosenKnifeMenuKill")]
|
||||||
|
public string ChosenKnifeMenuKill { get; set; } = "To correctly apply skin for knife, you need to type !kill.";
|
||||||
[JsonPropertyName("KnifeMenuTitle")]
|
[JsonPropertyName("KnifeMenuTitle")]
|
||||||
public string KnifeMenuTitle { get; set; } = "Knife Menu.";
|
public string KnifeMenuTitle { get; set; } = "Knife Menu.";
|
||||||
}
|
}
|
||||||
@@ -34,11 +36,29 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
[JsonPropertyName("CommandWpEnabled")]
|
[JsonPropertyName("CommandWpEnabled")]
|
||||||
public bool CommandWpEnabled { get; set; } = true;
|
public bool CommandWpEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
[JsonPropertyName("CommandKillEnabled")]
|
||||||
|
public bool CommandKillEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
[JsonPropertyName("CommandKnife")]
|
||||||
|
public string CommandKnife { get; set; } = "knife";
|
||||||
|
|
||||||
|
[JsonPropertyName("CommandSkin")]
|
||||||
|
public string CommandSkin { get; set; } = "ws";
|
||||||
|
|
||||||
|
[JsonPropertyName("CommandRefresh")]
|
||||||
|
public string CommandRefresh { get; set; } = "wp";
|
||||||
|
|
||||||
|
[JsonPropertyName("CommandKill")]
|
||||||
|
public string CommandKill { get; set; } = "kill";
|
||||||
|
|
||||||
|
[JsonPropertyName("GiveRandomKnife")]
|
||||||
|
public bool GiveRandomKnife { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WeaponPaintsConfig : BasePluginConfig
|
public class WeaponPaintsConfig : BasePluginConfig
|
||||||
{
|
{
|
||||||
public override int Version { get; set; } = 3;
|
public override int Version { get; set; } = 4;
|
||||||
|
|
||||||
[JsonPropertyName("DatabaseHost")]
|
[JsonPropertyName("DatabaseHost")]
|
||||||
public string DatabaseHost { get; set; } = "";
|
public string DatabaseHost { get; set; } = "";
|
||||||
|
|||||||
134
WeaponPaints.cs
134
WeaponPaints.cs
@@ -14,13 +14,13 @@ using System.Reflection;
|
|||||||
|
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
[MinimumApiVersion(52)]
|
[MinimumApiVersion(50)]
|
||||||
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
public override string ModuleDescription => "Connector for web-based player chosen wepaon paints.";
|
public override string ModuleDescription => "Connector for web-based player chosen wepaon paints, and standalone for knife.";
|
||||||
public override string ModuleAuthor => "Nereziel";
|
public override string ModuleAuthor => "Nereziel";
|
||||||
public override string ModuleVersion => "0.8";
|
public override string ModuleVersion => "0.9";
|
||||||
|
|
||||||
public WeaponPaintsConfig Config { get; set; } = new();
|
public WeaponPaintsConfig Config { get; set; } = new();
|
||||||
|
|
||||||
@@ -78,6 +78,8 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
//RegisterEventHandler<EventRoundPrestart>(OnRoundPreStart);
|
//RegisterEventHandler<EventRoundPrestart>(OnRoundPreStart);
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
SetupMenus();
|
SetupMenus();
|
||||||
|
|
||||||
|
RegisterCommands();
|
||||||
}
|
}
|
||||||
public void OnConfigParsed(WeaponPaintsConfig config)
|
public void OnConfigParsed(WeaponPaintsConfig config)
|
||||||
{
|
{
|
||||||
@@ -113,6 +115,19 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
{
|
{
|
||||||
AppDomain.CurrentDomain.FirstChanceException -= this.GlobalExceptionHandler;
|
AppDomain.CurrentDomain.FirstChanceException -= this.GlobalExceptionHandler;
|
||||||
}
|
}
|
||||||
|
public void RegisterCommands()
|
||||||
|
{
|
||||||
|
AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) => { if (player == null) return; OnCommandWS(player, info); });
|
||||||
|
AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) => { if (player == null) return; OnCommandRefresh(player, info); });
|
||||||
|
if (Config.Additional.CommandKillEnabled) {
|
||||||
|
AddCommand($"css_{Config.Additional.CommandKill}", "kill yourself", (player, info) => {
|
||||||
|
if(player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
player.PlayerPawn.Value.CommitSuicide(true, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
private void OnMapStart(string mapName)
|
private void OnMapStart(string mapName)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
if (!Config.Additional.KnifeEnabled) return;
|
||||||
@@ -131,6 +146,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
{
|
{
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
await GetKnifeFromDatabase(playerIndex);
|
await GetKnifeFromDatabase(playerIndex);
|
||||||
|
if (Config.Additional.SkinEnabled)
|
||||||
await GetWeaponPaintsFromDatabase(playerIndex);
|
await GetWeaponPaintsFromDatabase(playerIndex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -149,15 +165,18 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled) {
|
||||||
GiveKnifeToPlayer(player);
|
GiveKnifeToPlayer(player);
|
||||||
|
|
||||||
|
AddTimer(0.1f, () => RefreshPlayerKnife(player));
|
||||||
|
}
|
||||||
|
|
||||||
if (Config.Additional.SkinVisibilityFix)
|
if (Config.Additional.SkinVisibilityFix)
|
||||||
{
|
{
|
||||||
// Check the best slot and set it. Weird solution but works xD
|
// Check the best slot and set it. Weird solution but works xD
|
||||||
AddTimer(0.1f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
|
AddTimer(0.2f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
|
||||||
AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
AddTimer(0.32f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
||||||
AddTimer(0.35f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
|
AddTimer(0.42f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
@@ -176,6 +195,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
}
|
}
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
if (!weapon.IsValid) return;
|
if (!weapon.IsValid) return;
|
||||||
if (weapon.OwnerEntity.Value == null) return;
|
if (weapon.OwnerEntity.Value == null) return;
|
||||||
if (!weapon.OwnerEntity.Value.EntityIndex.HasValue) return;
|
if (!weapon.OwnerEntity.Value.EntityIndex.HasValue) return;
|
||||||
@@ -206,24 +226,26 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||||
skeleton.ModelState.MeshGroupMask = 2;
|
skeleton.ModelState.MeshGroupMask = 2;
|
||||||
}
|
}
|
||||||
|
} catch(Exception) {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void GiveKnifeToPlayer(CCSPlayerController player)
|
public void GiveKnifeToPlayer(CCSPlayerController player)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
if (!Config.Additional.KnifeEnabled) return;
|
||||||
if (player.IsBot)
|
|
||||||
{
|
|
||||||
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PlayerHasKnife(player))
|
|
||||||
{
|
|
||||||
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
|
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
|
||||||
{
|
{
|
||||||
player.GiveNamedItem(knife);
|
player.GiveNamedItem(knife);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (Config.Additional.GiveRandomKnife)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
int index = random.Next(knifeTypes.Count);
|
||||||
|
player.GiveNamedItem(knifeTypes.Values.ElementAt(index));
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
||||||
}
|
}
|
||||||
@@ -231,8 +253,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
}
|
}
|
||||||
public void RemoveKnifeFromPlayer(CCSPlayerController player)
|
public void RemoveKnifeFromPlayer(CCSPlayerController player)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
|
||||||
if (!g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)) return;
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
@@ -242,15 +262,76 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
if (weapon.Value.DesignerName.Contains("knife"))
|
if (weapon.Value.DesignerName.Contains("knife"))
|
||||||
{
|
{
|
||||||
weapon.Value.Remove();
|
weapon.Value.Remove();
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void RefreshPlayerKnife(CCSPlayerController player)
|
||||||
|
{
|
||||||
|
if (!player.IsValid || !player.PawnIsAlive) return;
|
||||||
|
if (!PlayerHasKnife(player))
|
||||||
|
GiveKnifeToPlayer(player);
|
||||||
|
}
|
||||||
|
// Unused method, only for testing
|
||||||
|
// public void RefreshPlayerKnife(CCSPlayerController player)
|
||||||
|
// {
|
||||||
|
// if (!Config.Additional.KnifeEnabled) return;
|
||||||
|
// // if (!g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)) return;
|
||||||
|
|
||||||
|
// // if (!PlayerHasKnife(player))
|
||||||
|
// // player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
||||||
|
|
||||||
|
// var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
||||||
|
// foreach (var weapon in weapons)
|
||||||
|
// {
|
||||||
|
// if (weapon.IsValid && weapon.Value.IsValid)
|
||||||
|
// {
|
||||||
|
// //if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||||
|
// if (weapon.Value.DesignerName.Contains("knife"))
|
||||||
|
// {
|
||||||
|
// weapon.Value.Remove();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
||||||
|
// foreach (var weapon in weapons)
|
||||||
|
// {
|
||||||
|
// if (weapon.IsValid && weapon.Value.IsValid)
|
||||||
|
// {
|
||||||
|
// //if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||||
|
// if (weapon.Value.DesignerName.Contains("knife"))
|
||||||
|
// {
|
||||||
|
// var temp = weapon.Value;
|
||||||
|
// var steamId = new SteamID(player.SteamID);
|
||||||
|
// if (!gPlayerWeaponPaints.ContainsKey(steamId.SteamId64)) return;
|
||||||
|
// if (!gPlayerWeaponPaints[steamId.SteamId64].ContainsKey(temp.AttributeManager.Item.ItemDefinitionIndex)) return;
|
||||||
|
// //Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
|
||||||
|
// temp.AttributeManager.Item.ItemID = 16384;
|
||||||
|
// temp.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
|
||||||
|
// temp.AttributeManager.Item.ItemIDHigh = temp.AttributeManager.Item.ItemIDLow >> 32;
|
||||||
|
// temp.FallbackPaintKit = gPlayerWeaponPaints[steamId.SteamId64][temp.AttributeManager.Item.ItemDefinitionIndex];
|
||||||
|
// temp.FallbackSeed = gPlayerWeaponSeed[steamId.SteamId64][temp.AttributeManager.Item.ItemDefinitionIndex];
|
||||||
|
// temp.FallbackWear = gPlayerWeaponWear[steamId.SteamId64][temp.AttributeManager.Item.ItemDefinitionIndex];
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
public bool PlayerHasKnife(CCSPlayerController player)
|
public bool PlayerHasKnife(CCSPlayerController player)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return true;
|
if (!Config.Additional.KnifeEnabled) return false;
|
||||||
|
|
||||||
|
if (!player.IsValid || !player.PawnIsAlive)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
||||||
|
if (weapons == null) return false;
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
if (weapon.IsValid && weapon.Value.IsValid)
|
if (weapon.IsValid && weapon.Value.IsValid)
|
||||||
@@ -269,25 +350,30 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
var giveItemMenu = new ChatMenu(ReplaceTags(Config.Messages.KnifeMenuTitle));
|
var giveItemMenu = new ChatMenu(ReplaceTags(Config.Messages.KnifeMenuTitle));
|
||||||
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
||||||
{
|
{
|
||||||
|
string temp = "";
|
||||||
if (knifeTypes.TryGetValue(option.Text, out var knife))
|
if (knifeTypes.TryGetValue(option.Text, out var knife))
|
||||||
{
|
{
|
||||||
Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knife));
|
|
||||||
g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text];
|
g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text];
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenu)) {
|
if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenu)) {
|
||||||
string temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenu}".Replace("{KNIFE}", option.Text);
|
temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenu}".Replace("{KNIFE}", option.Text);
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenuKill) && Config.Additional.CommandKillEnabled) {
|
||||||
|
temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenuKill}";
|
||||||
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
|
}
|
||||||
|
Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knife));
|
||||||
RemoveKnifeFromPlayer(player);
|
RemoveKnifeFromPlayer(player);
|
||||||
GiveKnifeToPlayer(player);
|
AddTimer(0.1f, () => GiveKnifeToPlayer(player));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
foreach (var knife in knifeTypes)
|
foreach (var knife in knifeTypes)
|
||||||
{
|
{
|
||||||
giveItemMenu.AddMenuOption(knife.Key, handleGive);
|
giveItemMenu.AddMenuOption(knife.Key, handleGive);
|
||||||
}
|
}
|
||||||
AddCommand("css_knife", "Knife Menu", (player, info) => { if (player == null) return; ChatMenus.OpenMenu(player, giveItemMenu); });
|
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) => { if (player == null) return; ChatMenus.OpenMenu(player, giveItemMenu); });
|
||||||
}
|
}
|
||||||
[ConsoleCommand("css_wp", "refreshskins")]
|
// [ConsoleCommand($"css_{Config.Additional.CommandRefresh}", "refreshskins")]
|
||||||
public void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
public void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled) return;
|
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled) return;
|
||||||
@@ -311,7 +397,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
player.PrintToChat(ReplaceTags(temp));
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[ConsoleCommand("css_ws", "weaponskins")]
|
// [ConsoleCommand($"css_{Config.Additional.CommandSkin}", "weaponskins")]
|
||||||
public void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
public void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
if (!Config.Additional.SkinEnabled) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user