mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +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.";
|
||||
[JsonPropertyName("ChosenKnifeMenu")]
|
||||
public string ChosenKnifeMenu { get; set; } = "You have chosen {KNIFE} as your knife.";
|
||||
[JsonPropertyName("ChosenKnifeMenuKill")]
|
||||
public string ChosenKnifeMenuKill { get; set; } = "To correctly apply skin for knife, you need to type !kill.";
|
||||
[JsonPropertyName("KnifeMenuTitle")]
|
||||
public string KnifeMenuTitle { get; set; } = "Knife Menu.";
|
||||
}
|
||||
@@ -34,11 +36,29 @@ namespace WeaponPaints
|
||||
|
||||
[JsonPropertyName("CommandWpEnabled")]
|
||||
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 override int Version { get; set; } = 3;
|
||||
public override int Version { get; set; } = 4;
|
||||
|
||||
[JsonPropertyName("DatabaseHost")]
|
||||
public string DatabaseHost { get; set; } = "";
|
||||
|
||||
198
WeaponPaints.cs
198
WeaponPaints.cs
@@ -14,13 +14,13 @@ using System.Reflection;
|
||||
|
||||
|
||||
namespace WeaponPaints;
|
||||
[MinimumApiVersion(52)]
|
||||
[MinimumApiVersion(50)]
|
||||
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
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 ModuleVersion => "0.8";
|
||||
public override string ModuleVersion => "0.9";
|
||||
|
||||
public WeaponPaintsConfig Config { get; set; } = new();
|
||||
|
||||
@@ -78,6 +78,8 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
//RegisterEventHandler<EventRoundPrestart>(OnRoundPreStart);
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
SetupMenus();
|
||||
|
||||
RegisterCommands();
|
||||
}
|
||||
public void OnConfigParsed(WeaponPaintsConfig config)
|
||||
{
|
||||
@@ -113,6 +115,19 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
@@ -131,6 +146,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
await GetKnifeFromDatabase(playerIndex);
|
||||
if (Config.Additional.SkinEnabled)
|
||||
await GetWeaponPaintsFromDatabase(playerIndex);
|
||||
});
|
||||
}
|
||||
@@ -149,15 +165,18 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
if (Config.Additional.KnifeEnabled) {
|
||||
GiveKnifeToPlayer(player);
|
||||
|
||||
AddTimer(0.1f, () => RefreshPlayerKnife(player));
|
||||
}
|
||||
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
{
|
||||
// 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.25f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
||||
AddTimer(0.35f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
|
||||
AddTimer(0.2f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
|
||||
AddTimer(0.32f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
||||
AddTimer(0.42f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
@@ -176,52 +195,55 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
}
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (!weapon.IsValid) return;
|
||||
if (weapon.OwnerEntity.Value == null) return;
|
||||
if (!weapon.OwnerEntity.Value.EntityIndex.HasValue) return;
|
||||
int weaponOwner = (int)weapon.OwnerEntity.Value.EntityIndex.Value.Value;
|
||||
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
||||
if (!pawn.IsValid) return;
|
||||
var playerIndex = (int)pawn.Controller.Value.EntityIndex!.Value.Value;
|
||||
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
if (player == null || !player.IsValid || player.IsBot) return;
|
||||
// TODO: Remove knife crashes here, needs another solution
|
||||
/*if (isKnife && g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59))
|
||||
{
|
||||
RemoveKnifeFromPlayer(player);
|
||||
return;
|
||||
}*/
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
if (!gPlayerWeaponPaints.ContainsKey(steamId.SteamId64)) return;
|
||||
if (!gPlayerWeaponPaints[steamId.SteamId64].ContainsKey(weapon.AttributeManager.Item.ItemDefinitionIndex)) return;
|
||||
//Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
|
||||
weapon.AttributeManager.Item.ItemID = 16384;
|
||||
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
|
||||
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
|
||||
weapon.FallbackPaintKit = gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
||||
weapon.FallbackSeed = gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
||||
weapon.FallbackWear = gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||
{
|
||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||
skeleton.ModelState.MeshGroupMask = 2;
|
||||
}
|
||||
});
|
||||
try {
|
||||
if (!weapon.IsValid) return;
|
||||
if (weapon.OwnerEntity.Value == null) return;
|
||||
if (!weapon.OwnerEntity.Value.EntityIndex.HasValue) return;
|
||||
int weaponOwner = (int)weapon.OwnerEntity.Value.EntityIndex.Value.Value;
|
||||
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
||||
if (!pawn.IsValid) return;
|
||||
var playerIndex = (int)pawn.Controller.Value.EntityIndex!.Value.Value;
|
||||
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
if (player == null || !player.IsValid || player.IsBot) return;
|
||||
// TODO: Remove knife crashes here, needs another solution
|
||||
/*if (isKnife && g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59))
|
||||
{
|
||||
RemoveKnifeFromPlayer(player);
|
||||
return;
|
||||
}*/
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
if (!gPlayerWeaponPaints.ContainsKey(steamId.SteamId64)) return;
|
||||
if (!gPlayerWeaponPaints[steamId.SteamId64].ContainsKey(weapon.AttributeManager.Item.ItemDefinitionIndex)) return;
|
||||
//Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
|
||||
weapon.AttributeManager.Item.ItemID = 16384;
|
||||
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
|
||||
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
|
||||
weapon.FallbackPaintKit = gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
||||
weapon.FallbackSeed = gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
||||
weapon.FallbackWear = gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||
{
|
||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||
skeleton.ModelState.MeshGroupMask = 2;
|
||||
}
|
||||
} catch(Exception) {}
|
||||
});
|
||||
}
|
||||
public void GiveKnifeToPlayer(CCSPlayerController player)
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
if (player.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);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Config.Additional.GiveRandomKnife)
|
||||
{
|
||||
player.GiveNamedItem(knife);
|
||||
Random random = new Random();
|
||||
int index = random.Next(knifeTypes.Count);
|
||||
player.GiveNamedItem(knifeTypes.Values.ElementAt(index));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -231,8 +253,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
}
|
||||
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;
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
@@ -242,15 +262,76 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
if (weapon.Value.DesignerName.Contains("knife"))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
if (weapons == null) return false;
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
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 handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
||||
{
|
||||
string temp = "";
|
||||
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];
|
||||
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));
|
||||
}
|
||||
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);
|
||||
GiveKnifeToPlayer(player);
|
||||
AddTimer(0.1f, () => GiveKnifeToPlayer(player));
|
||||
}
|
||||
};
|
||||
foreach (var knife in knifeTypes)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled) return;
|
||||
@@ -311,7 +397,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
player.PrintToChat(ReplaceTags(temp));
|
||||
}
|
||||
}
|
||||
[ConsoleCommand("css_ws", "weaponskins")]
|
||||
// [ConsoleCommand($"css_{Config.Additional.CommandSkin}", "weaponskins")]
|
||||
public void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (!Config.Additional.SkinEnabled) return;
|
||||
|
||||
Reference in New Issue
Block a user