mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6d4108ca7 | ||
|
|
7b45169d8d | ||
|
|
42bd45c3f0 | ||
|
|
5262739c3d | ||
|
|
c82a0c0d26 | ||
|
|
9ad7f9fc83 | ||
|
|
9e2dac52e5 | ||
|
|
118931f44d | ||
|
|
843ae34e31 | ||
|
|
46a720ff83 | ||
|
|
63d059b607 | ||
|
|
005ef18338 | ||
|
|
c0c1fe2566 | ||
|
|
c4ad17a7ed | ||
|
|
99fde6ec52 | ||
|
|
ca2c3eb212 | ||
|
|
b5a4577af1 | ||
|
|
ba93e4a3aa | ||
|
|
7d435da9d1 |
7
.github/workflows/build.yml
vendored
7
.github/workflows/build.yml
vendored
@@ -34,13 +34,16 @@ jobs:
|
||||
${{ env.OUTPUT_PATH }}/CounterStrikeSharp.API.dll \
|
||||
${{ env.OUTPUT_PATH }}/McMaster.NETCore.Plugins.dll \
|
||||
${{ env.OUTPUT_PATH }}/Microsoft.DotNet.PlatformAbstractions.dll \
|
||||
${{ env.OUTPUT_PATH }}/Microsoft.Extensions.DependencyModel.dll
|
||||
${{ env.OUTPUT_PATH }}/Microsoft.Extensions.DependencyModel.dll \
|
||||
- name: Zip
|
||||
uses: thedoctor0/zip-release@0.7.5
|
||||
with:
|
||||
type: 'zip'
|
||||
filename: '${{ env.PROJECT_NAME }}.zip'
|
||||
path: ${{ env.OUTPUT_PATH }}
|
||||
- name: Clean files Website
|
||||
run: |
|
||||
rm -rf website/img/
|
||||
- name: Zip
|
||||
uses: thedoctor0/zip-release@0.7.5
|
||||
with:
|
||||
@@ -54,4 +57,4 @@ jobs:
|
||||
name: "Build ${{ env.BUILD_NUMBER }}"
|
||||
tag: "build-${{ env.BUILD_NUMBER }}"
|
||||
body: |
|
||||
Place the plugin in game/csgo/addons/counterstrikesharp/plugins/WeaponPaints
|
||||
Place the plugin in game/csgo/addons/counterstrikesharp/plugins/WeaponPaints
|
||||
|
||||
40
Config.cs
40
Config.cs
@@ -17,13 +17,48 @@ 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.";
|
||||
}
|
||||
|
||||
public class Additional
|
||||
{
|
||||
[JsonPropertyName("SkinVisibilityFix")]
|
||||
public bool SkinVisibilityFix { get; set; } = true;
|
||||
|
||||
[JsonPropertyName("KnifeEnabled")]
|
||||
public bool KnifeEnabled { get; set; } = true;
|
||||
|
||||
[JsonPropertyName("SkinEnabled")]
|
||||
public bool SkinEnabled { get; set; } = true;
|
||||
|
||||
[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; } = 2;
|
||||
public override int Version { get; set; } = 4;
|
||||
|
||||
[JsonPropertyName("DatabaseHost")]
|
||||
public string DatabaseHost { get; set; } = "";
|
||||
@@ -51,6 +86,9 @@ namespace WeaponPaints
|
||||
|
||||
[JsonPropertyName("Messages")]
|
||||
public Messages Messages { get; set; } = new Messages();
|
||||
|
||||
[JsonPropertyName("Additional")]
|
||||
public Additional Additional { get; set; } = new Additional();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
16
README.md
16
README.md
@@ -1,13 +1,13 @@
|
||||
# cs2-WeaponPaints
|
||||
|
||||
[](https://ko-fi.com/E1E2G0P2O) or [Donate on Steam](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
|
||||
|
||||
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
|
||||
|
||||
### Description
|
||||
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for [CSSharp](https://docs.cssharp.dev/).
|
||||
There will be a lot of frequent changes which may break functionality or compatibility. You have been warned!
|
||||
|
||||
### Created [Discord server](https://discord.gg/mwEQppJ5AT) where you can discus about plugin.
|
||||
## Created [Discord server](https://discord.gg/mwEQppJ5AT) where you can discus about plugin.
|
||||
|
||||
### Consider to donate instead of buying from unknown sources.
|
||||
[](https://ko-fi.com/E1E2G0P2O) or [Donate on Steam](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
|
||||
|
||||
### Features
|
||||
- changes only paint, seed and wear on weapons and knives
|
||||
@@ -24,12 +24,14 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
||||
- in `addons/counterstrikesharp/configs/core.json` set **FollowCS2ServerGuidelines** to **false**
|
||||
|
||||
### Web install:
|
||||
- requires PHP (tested on php ver `8.2.3` and nginx webserver)
|
||||
- copy website to web server
|
||||
- requires PHP min v7.3 (tested on php ver `8.2.3` and nginx webserver)
|
||||
- copy website to web server (img folder not needed)
|
||||
- import `database.sql` to mysql
|
||||
- get steam api key [https://steamcommunity.com/dev/apikey](https://steamcommunity.com/dev/apikey)
|
||||
- fill in database credentials and api key in `class/config.php`
|
||||
- visit website and login via steam
|
||||
|
||||
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
|
||||
|
||||
### Preview
|
||||

|
||||
|
||||
227
WeaponPaints.cs
227
WeaponPaints.cs
@@ -1,5 +1,6 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
@@ -13,12 +14,13 @@ using System.Reflection;
|
||||
|
||||
|
||||
namespace WeaponPaints;
|
||||
[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();
|
||||
|
||||
@@ -74,7 +76,10 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||
//RegisterEventHandler<EventRoundPrestart>(OnRoundPreStart);
|
||||
SetupMenus();
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
SetupMenus();
|
||||
|
||||
RegisterCommands();
|
||||
}
|
||||
public void OnConfigParsed(WeaponPaintsConfig config)
|
||||
{
|
||||
@@ -110,8 +115,22 @@ 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;
|
||||
// TODO
|
||||
// needed for now
|
||||
base.AddTimer(2.0f, () => {
|
||||
@@ -124,15 +143,18 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
int playerIndex = playerSlot + 1;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await GetKnifeFromDatabase(playerIndex);
|
||||
{
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
await GetKnifeFromDatabase(playerIndex);
|
||||
if (Config.Additional.SkinEnabled)
|
||||
await GetWeaponPaintsFromDatabase(playerIndex);
|
||||
});
|
||||
}
|
||||
private void OnClientDisconnect(int playerSlot)
|
||||
{
|
||||
// TODO: Clean up after player
|
||||
g_playersKnife.Remove(playerSlot+1);
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
g_playersKnife.Remove(playerSlot+1);
|
||||
}
|
||||
|
||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||
@@ -143,17 +165,25 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
GiveKnifeToPlayer(player);
|
||||
if (Config.Additional.KnifeEnabled) {
|
||||
GiveKnifeToPlayer(player);
|
||||
|
||||
// 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.1f, () => RefreshPlayerKnife(player));
|
||||
}
|
||||
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
{
|
||||
// Check the best slot and set it. Weird solution but works xD
|
||||
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;
|
||||
}
|
||||
private void OnEntitySpawned(CEntityInstance entity)
|
||||
{
|
||||
if (!Config.Additional.SkinEnabled) return;
|
||||
var designerName = entity.DesignerName;
|
||||
if (!weaponList.Contains(designerName)) return;
|
||||
bool isKnife = false;
|
||||
@@ -165,51 +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 (player.IsBot)
|
||||
{
|
||||
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
||||
return;
|
||||
}
|
||||
if (!Config.Additional.KnifeEnabled) 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
|
||||
{
|
||||
@@ -219,7 +253,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
}
|
||||
public void RemoveKnifeFromPlayer(CCSPlayerController player)
|
||||
{
|
||||
if (!g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)) return;
|
||||
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
@@ -229,14 +262,76 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
if (weapon.Value.DesignerName.Contains("knife"))
|
||||
{
|
||||
weapon.Value.Remove();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static bool PlayerHasKnife(CCSPlayerController player)
|
||||
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 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)
|
||||
@@ -251,30 +346,37 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
}
|
||||
private void SetupMenus()
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
var giveItemMenu = new ChatMenu(ReplaceTags(Config.Messages.KnifeMenuTitle));
|
||||
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
||||
{
|
||||
string temp = "";
|
||||
if (knifeTypes.TryGetValue(option.Text, out var knife))
|
||||
{
|
||||
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;
|
||||
if (player == null) return;
|
||||
string temp = "";
|
||||
int playerIndex = (int)player.EntityIndex!.Value.Value;
|
||||
@@ -282,6 +384,8 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex));
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
Task.Run(async () => await GetKnifeFromDatabase(playerIndex));
|
||||
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand)) {
|
||||
temp = $"{Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
||||
player.PrintToChat(ReplaceTags(temp));
|
||||
@@ -293,9 +397,10 @@ 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;
|
||||
if (player == null) return;
|
||||
|
||||
string temp = "";
|
||||
@@ -308,6 +413,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
temp = $"{Config.Prefix} {Config.Messages.SynchronizeMessageCommand}";
|
||||
player.PrintToChat(ReplaceTags(temp));
|
||||
}
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand)) {
|
||||
temp = $"{Config.Prefix} {Config.Messages.KnifeMessageCommand}";
|
||||
player.PrintToChat(ReplaceTags(temp));
|
||||
@@ -320,6 +426,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
}
|
||||
private async Task GetWeaponPaintsFromDatabase(int playerIndex)
|
||||
{
|
||||
if (!Config.Additional.SkinEnabled) return;
|
||||
try
|
||||
{
|
||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
@@ -364,6 +471,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
}
|
||||
private async Task GetKnifeFromDatabase(int playerIndex)
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
try
|
||||
{
|
||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
@@ -395,6 +503,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
}
|
||||
private async Task SyncKnifeToDatabase(int playerIndex, string knife)
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
try
|
||||
{
|
||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
|
||||
@@ -7,7 +7,8 @@ class UtilsClass
|
||||
$json = json_decode(file_get_contents(__DIR__ . "/../data/skins.json"), true);
|
||||
|
||||
foreach ($json as $skin) {
|
||||
$skins[(int)$skin['weapon_defindex']][(int)$skin['paint']] = [
|
||||
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = [
|
||||
'weapon_name' => $skin['weapon_name'],
|
||||
'paint_name' => $skin['paint_name'],
|
||||
'image_url' => $skin['image'],
|
||||
];
|
||||
@@ -21,11 +22,12 @@ class UtilsClass
|
||||
$weapons = [];
|
||||
$temp = self::skinsFromJson();
|
||||
|
||||
foreach ($temp as $key => $value)
|
||||
{
|
||||
if (key_exists($key, $weapons)) continue;
|
||||
foreach ($temp as $key => $value) {
|
||||
if (key_exists($key, $weapons))
|
||||
continue;
|
||||
|
||||
$weapons[$key] = [
|
||||
'weapon_name' => $value[0]['weapon_name'],
|
||||
'paint_name' => $value[0]['paint_name'],
|
||||
'image_url' => $value[0]['image_url'],
|
||||
];
|
||||
@@ -34,15 +36,61 @@ class UtilsClass
|
||||
return $weapons;
|
||||
}
|
||||
|
||||
public static function getKnifeTypes()
|
||||
{
|
||||
$knifes = [];
|
||||
$temp = self::getWeaponsFromArray();
|
||||
|
||||
foreach ($temp as $key => $weapon) {
|
||||
if (
|
||||
!in_array($key, [
|
||||
500,
|
||||
503,
|
||||
505,
|
||||
506,
|
||||
507,
|
||||
508,
|
||||
509,
|
||||
512,
|
||||
514,
|
||||
515,
|
||||
516,
|
||||
517,
|
||||
518,
|
||||
519,
|
||||
520,
|
||||
521,
|
||||
522,
|
||||
523,
|
||||
525
|
||||
])
|
||||
)
|
||||
continue;
|
||||
|
||||
$knifes[$key] = [
|
||||
'weapon_name' => $weapon['weapon_name'],
|
||||
'paint_name' => rtrim(explode("|", $weapon['paint_name'])[0]),
|
||||
'image_url' => $weapon['image_url'],
|
||||
];
|
||||
$knifes[0] = [
|
||||
'weapon_name' => "weapon_knife",
|
||||
'paint_name' => "Default knife",
|
||||
'image_url' => "https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/website/img/skins/weapon_knife.png",
|
||||
];
|
||||
}
|
||||
|
||||
ksort($knifes);
|
||||
return $knifes;
|
||||
}
|
||||
|
||||
public static function getSelectedSkins(array $temp)
|
||||
{
|
||||
$selected = [];
|
||||
|
||||
foreach ($temp as $weapon)
|
||||
{
|
||||
foreach ($temp as $weapon) {
|
||||
$selected[$weapon['weapon_defindex']] = $weapon['weapon_paint_id'];
|
||||
}
|
||||
|
||||
return $selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
website/img/skins/weapon_knife.png
Normal file
BIN
website/img/skins/weapon_knife.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -15,18 +15,24 @@ if (isset($_SESSION['steamid'])) {
|
||||
$skins = UtilsClass::skinsFromJson();
|
||||
$querySelected = $query3 = $db->select("SELECT `weapon_defindex`, `weapon_paint_id` FROM `wp_player_skins` WHERE `wp_player_skins`.`steamid` = :steamid", ["steamid" => $steamid]);
|
||||
$selectedSkins = UtilsClass::getSelectedSkins($querySelected);
|
||||
$selectedKnife = $db->select("SELECT * FROM `wp_player_knife` WHERE `wp_player_knife`.`steamid` = :steamid", ["steamid" => $steamid])[0];
|
||||
$knifes = UtilsClass::getKnifeTypes();
|
||||
|
||||
if (isset($_POST['forma'])) {
|
||||
$ex = explode("-", $_POST['forma']);
|
||||
|
||||
if (array_key_exists($ex[1], $skins[$ex[0]])) {
|
||||
if (array_key_exists($ex[0], $selectedSkins)) {
|
||||
$db->query("UPDATE wp_player_skins SET weapon_paint_id = :weapon_paint_id WHERE steamid = :steamid AND weapon_defindex = :weapon_defindex", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1]]);
|
||||
} else {
|
||||
$db->query("INSERT INTO wp_player_skins (`steamid`, `weapon_defindex`, `weapon_paint_id`) VALUES (:steamid, :weapon_defindex, :weapon_paint_id)", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1]]);
|
||||
if ($ex[0] == "knife") {
|
||||
$db->query("INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(:steamid, :knife) ON DUPLICATE KEY UPDATE `knife` = :knife", ["steamid" => $steamid, "knife" => $knifes[$ex[1]]['weapon_name']]);
|
||||
} else {
|
||||
if (array_key_exists($ex[1], $skins[$ex[0]])) {
|
||||
if (array_key_exists($ex[0], $selectedSkins)) {
|
||||
$db->query("UPDATE wp_player_skins SET weapon_paint_id = :weapon_paint_id WHERE steamid = :steamid AND weapon_defindex = :weapon_defindex", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1]]);
|
||||
} else {
|
||||
$db->query("INSERT INTO wp_player_skins (`steamid`, `weapon_defindex`, `weapon_paint_id`) VALUES (:steamid, :weapon_defindex, :weapon_paint_id)", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1]]);
|
||||
}
|
||||
}
|
||||
header("Location: index.php");
|
||||
}
|
||||
header("Location: index.php");
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -54,7 +60,47 @@ if (isset($_SESSION['steamid'])) {
|
||||
echo "</h2></div>";
|
||||
} else {
|
||||
echo "<div class='bg-primary'>Your current weapon skin loadout<form action='' method='get'><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form></div>";
|
||||
echo "<div class='card-group'>";
|
||||
echo "<div class='card-group mt-2'>";
|
||||
?>
|
||||
|
||||
<div class="col-sm-2">
|
||||
<div class="card text-center mb-3 border border-primary">
|
||||
<div class="card-body">
|
||||
<?php
|
||||
$actualKnife = $knifes[0];
|
||||
foreach ($knifes as $knife) {
|
||||
if ($selectedKnife['knife'] == $knife['weapon_name']) {
|
||||
$actualKnife = $knife;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h6 class='card-title item-name'>Knife type</h6>";
|
||||
echo "<h5 class='card-title item-name'>{$actualKnife["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$actualKnife["image_url"]}' class='skin-image'>";
|
||||
?>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<form action="" method="POST">
|
||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||
<option>Select knife</option>
|
||||
<?php
|
||||
foreach ($knifes as $knifeKey => $knife) {
|
||||
if ($selectedKnife['knife'] == $knife['weapon_name'])
|
||||
echo "<option selected value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||
else
|
||||
echo "<option value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
foreach ($weapons as $defindex => $default) { ?>
|
||||
<div class="col-sm-2">
|
||||
<div class="card text-center mb-3">
|
||||
@@ -64,7 +110,7 @@ if (isset($_SESSION['steamid'])) {
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]]["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]]['image_url']}' class='skin-image' >";
|
||||
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]]['image_url']}' class='skin-image'>";
|
||||
} else {
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
||||
|
||||
Reference in New Issue
Block a user