mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-03-06 15:26:33 +00:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7bada81eb9 | ||
|
|
2929735429 | ||
|
|
04bb7a2575 | ||
|
|
f00ba48f60 | ||
|
|
08342e4a99 | ||
|
|
29a6041d7a | ||
|
|
c44433766c | ||
|
|
a987ed972a | ||
|
|
50777661c5 | ||
|
|
31fd014f55 | ||
|
|
760429e644 | ||
|
|
304d8501cc | ||
|
|
e9f7db5171 | ||
|
|
648b928b4e | ||
|
|
530a7d64c7 | ||
|
|
3453f4c505 | ||
|
|
25b466422b | ||
|
|
6baa59dd9b | ||
|
|
10afe7ce1e | ||
|
|
5eeb0c5fec | ||
|
|
e53ee27b39 | ||
|
|
75112b02fe | ||
|
|
8e92635231 | ||
|
|
6923295cb6 | ||
|
|
e5f98077f3 | ||
|
|
3296055841 | ||
|
|
89de192c20 | ||
|
|
a1297b9cbe | ||
|
|
99af078b32 | ||
|
|
b0bef746cd | ||
|
|
117a95e99c |
21
.github/workflows/build.yml
vendored
21
.github/workflows/build.yml
vendored
@@ -5,6 +5,10 @@ on:
|
|||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
|
paths-ignore:
|
||||||
|
- 'README.md'
|
||||||
|
- '.gitignore'
|
||||||
|
- 'LICENSE'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
BUILD_NUMBER: ${{ github.run_number }}
|
BUILD_NUMBER: ${{ github.run_number }}
|
||||||
@@ -12,7 +16,6 @@ env:
|
|||||||
PROJECT_NAME: "WeaponPaints"
|
PROJECT_NAME: "WeaponPaints"
|
||||||
OUTPUT_PATH: "./WeaponPaints"
|
OUTPUT_PATH: "./WeaponPaints"
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
permissions: write-all
|
permissions: write-all
|
||||||
@@ -28,6 +31,22 @@ jobs:
|
|||||||
run: dotnet restore
|
run: dotnet restore
|
||||||
- name: Build
|
- name: Build
|
||||||
run: dotnet build ${{ env.PROJECT_PATH }} -c WeaponPaints -o ${{ env.OUTPUT_PATH }}
|
run: dotnet build ${{ env.PROJECT_PATH }} -c WeaponPaints -o ${{ env.OUTPUT_PATH }}
|
||||||
|
|
||||||
|
publish:
|
||||||
|
if: github.event_name == 'push'
|
||||||
|
permissions: write-all
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup .NET
|
||||||
|
uses: actions/setup-dotnet@v3
|
||||||
|
with:
|
||||||
|
dotnet-version: 7.0.x
|
||||||
|
- name: Restore
|
||||||
|
run: dotnet restore
|
||||||
|
- name: Build
|
||||||
|
run: dotnet build ${{ env.PROJECT_PATH }} -c WeaponPaints -o ${{ env.OUTPUT_PATH }}
|
||||||
- name: Clean files
|
- name: Clean files
|
||||||
run: |
|
run: |
|
||||||
rm -f \
|
rm -f \
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ 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;
|
||||||
|
|
||||||
|
|||||||
95
README.md
95
README.md
@@ -1,37 +1,80 @@
|
|||||||
# cs2-WeaponPaints
|
# CS2 Weapon Paints
|
||||||
|
|
||||||
### Description
|
## Description
|
||||||
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for [CSSharp](https://docs.cssharp.dev/).
|
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for **[CSSharp](https://docs.cssharp.dev/)**.
|
||||||
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/EEg6qtNScq) where you can discus about plugin.
|
||||||
|
|
||||||
### Consider to donate instead of buying from unknown sources.
|
### Consider to donate instead of buying from unknown sources.
|
||||||
[](https://ko-fi.com/E1E2G0P2O) or [Donate on Steam](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
|
[](https://ko-fi.com/E1E2G0P2O) or [](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
|
||||||
|
|
||||||
### Features
|
## Features
|
||||||
- changes only paint, seed and wear on weapons and knives
|
- Changes only paint, seed and wear on weapons and knives;
|
||||||
- mysql based
|
- MySQL based or global website at [weaponpaints.fun](https://weaponpaints.fun/), so you dont need MySQL/Website;
|
||||||
- data sync on player connect
|
- Data sync on player connect;
|
||||||
- Added command `!wp` to refresh skins (with cooldown in second can be configured)
|
- Added command **`!wp`** to refresh skins; ***(with cooldown in second can be configured)***
|
||||||
- Added command `!ws` to show website
|
- Added command **`!ws`** to show website;
|
||||||
- Added command `!knife` to show menu with knives
|
- Added command **`!knife`** to show menu with knives;
|
||||||
- Knife change is now limited to have these cvars empty `mp_t_default_melee ""` and `mp_ct_default_melee ""`
|
- Knife change is now limited to have these cvars empty **`mp_t_default_melee ""`** and **`mp_ct_default_melee ""`**;
|
||||||
|
|
||||||
### CS2 server:
|
## CS2 Server
|
||||||
- compile and copy plugin to plugins. Info here [https://docs.cssharp.dev/guides/hello-world-plugin/](https://docs.cssharp.dev/guides/hello-world-plugin/)
|
- Compile and copy plugin to plugins, [more info here](https://docs.cssharp.dev/guides/hello-world-plugin/);
|
||||||
- setup `addons/counterstrikesharp/configs/plugins/WeaponPaints/WeaponPaints.json` with database credentials
|
- Setup **`addons/counterstrikesharp/configs/plugins/WeaponPaints/WeaponPaints.json`** set **`GlobalShare`** to **`true`** for global, or include database credentials;
|
||||||
- in `addons/counterstrikesharp/configs/core.json` set **FollowCS2ServerGuidelines** to **false**
|
- in **`addons/counterstrikesharp/configs/core.json`** set **FollowCS2ServerGuidelines** to **`false`**;
|
||||||
|
|
||||||
### Web install:
|
## Plugin Configuration
|
||||||
- requires PHP min v7.3 (tested on php ver `8.2.3` and nginx webserver)
|
<details>
|
||||||
- copy website to web server (img folder not needed)
|
<summary>Spoiler warning</summary>
|
||||||
- import `database.sql` to mysql
|
<code><pre>{
|
||||||
- get steam api key [https://steamcommunity.com/dev/apikey](https://steamcommunity.com/dev/apikey)
|
"Version": 4, // Don't touch
|
||||||
- fill in database credentials and api key in `class/config.php`
|
"DatabaseHost": "", // MySQL host (required if GlobalShare = false)
|
||||||
- visit website and login via steam
|
"DatabasePort": 3306, // MySQL port (required if GlobalShare = false)
|
||||||
|
"DatabaseUser": "", // MySQL username (required if GlobalShare = false)
|
||||||
|
"DatabasePassword": "", // MySQL user password (required if GlobalShare = false)
|
||||||
|
"DatabaseName": "", // MySQL database name (required if GlobalShare = false)
|
||||||
|
"GlobalShare": false, // Enable or disable GlobalShare, plugin can work without mysql credentials but with shared website at weaponpaints.fun
|
||||||
|
"CmdRefreshCooldownSeconds": 60, // Cooldown time in refreshing skins (!wp command)
|
||||||
|
"Prefix": "[WeaponPaints]", // Prefix every chat message
|
||||||
|
"Website": "example.com/skins", // Website used in WebsiteMessageCommand (!ws command)
|
||||||
|
"Messages": {
|
||||||
|
"WebsiteMessageCommand": "Visit {WEBSITE} where you can change skins.", // Information about website where player can change skins (!ws command) Set to empty to disable
|
||||||
|
"SynchronizeMessageCommand": "Type !wp to synchronize chosen skins.", // Information about skins refreshing (!ws command) Set to empty to disable
|
||||||
|
"KnifeMessageCommand": "Type !knife to open knife menu.", // Information about knife menu (!ws command) Set to empty to disable
|
||||||
|
"CooldownRefreshCommand": "You can\u0027t refresh weapon paints right now.", // Cooldown information (!wp command) Set to empty to disable
|
||||||
|
"SuccessRefreshCommand": "Refreshing weapon paints.", // Information about refreshing skins (!wp command) Set to empty to disable
|
||||||
|
"ChosenKnifeMenu": "You have chosen {KNIFE} as your knife.", // Information about choosen knife (!knife command) Set to empty to disable
|
||||||
|
"ChosenKnifeMenuKill": "To correctly apply skin for knife, you need to type !kill.", // Information about suicide after knife selection (!knife command) Set to empty to disable
|
||||||
|
"KnifeMenuTitle": "Knife Menu." // Menu title (!knife menu)
|
||||||
|
},
|
||||||
|
"Additional": {
|
||||||
|
"SkinVisibilityFix": true, // Enable or disable fix for skin visibility
|
||||||
|
"KnifeEnabled": true, // Enable or disable knife feature
|
||||||
|
"SkinEnabled": true, // Enable or disable skin feature
|
||||||
|
"CommandWpEnabled": true, // Enable or disable refreshing command
|
||||||
|
"CommandKillEnabled": true, // Enable or disable kill command
|
||||||
|
"CommandKnife": "knife", // Name of knife menu command, u can change to for e.g, knives
|
||||||
|
"CommandSkin": "ws", // Name of skin information command, u can change to for e.g, skins
|
||||||
|
"CommandRefresh": "wp", // Name of skin refreshing command, u can change to for e.g, refreshskins
|
||||||
|
"CommandKill": "kill", // Name of kill command, u can change to for e.g, suicide
|
||||||
|
"GiveRandomKnife": false // Give random knife to players if they didn't choose
|
||||||
|
},
|
||||||
|
|
||||||
|
"ConfigVersion": 4 // Don't touch
|
||||||
|
}</pre></code>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
## Web install
|
||||||
|
Disregard if the config is **`GlobalShare = true`**;
|
||||||
|
- Requires PHP >= 7.4; ***(Tested on php ver **`8.2.3`** and nginx webserver)***
|
||||||
|
- Copy website to web server; ***(Folder `img` not needed)***
|
||||||
|
- Get [Steam API Key](https://steamcommunity.com/dev/apikey);
|
||||||
|
- Fill in database credentials and api key in `class/config.php`;
|
||||||
|
- Visit website and login via steam;
|
||||||
|
|
||||||
|
## Known issues
|
||||||
|
- Issue on Windows servers, no knives are given.
|
||||||
|
|
||||||
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
|
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
|
||||||
|
|
||||||
### Preview
|
## Preview
|
||||||

|

|
||||||
|
|||||||
516
WeaponPaints.cs
516
WeaponPaints.cs
@@ -1,30 +1,35 @@
|
|||||||
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.Core.Attributes.Registration;
|
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
using CounterStrikeSharp.API.Modules.Memory;
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
using CounterStrikeSharp.API.Modules.Menu;
|
using CounterStrikeSharp.API.Modules.Menu;
|
||||||
using CounterStrikeSharp.API.Modules.Utils;
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
using Nexd.MySQL;
|
using MySqlConnector;
|
||||||
|
using Dapper;
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
using static CounterStrikeSharp.API.Core.Listeners;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using CounterStrikeSharp.API.Modules.Cvars;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
[MinimumApiVersion(50)]
|
[MinimumApiVersion(55)]
|
||||||
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, and standalone for knife.";
|
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.9";
|
public override string ModuleVersion => "1.0";
|
||||||
|
|
||||||
public WeaponPaintsConfig Config { get; set; } = new();
|
public WeaponPaintsConfig Config { get; set; } = new();
|
||||||
|
|
||||||
MySqlDb? MySql = null;
|
private string DatabaseConnectionString = string.Empty;
|
||||||
|
private Uri GlobalShareApi = new Uri("https://weaponpaints.fun/api.php");
|
||||||
|
|
||||||
|
public bool IsMatchZy = false;
|
||||||
|
public int GlobalShareServerId = 0;
|
||||||
|
|
||||||
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
||||||
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponPaints = new();
|
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponPaints = new();
|
||||||
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponSeed = new();
|
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponSeed = new();
|
||||||
@@ -32,26 +37,16 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
private Dictionary<int, string> g_playersKnife = new();
|
private Dictionary<int, string> g_playersKnife = new();
|
||||||
private static readonly Dictionary<string, string> knifeTypes = new()
|
private static readonly Dictionary<string, string> knifeTypes = new()
|
||||||
{
|
{
|
||||||
{ "m9", "weapon_knife_m9_bayonet" },
|
{ "m9", "weapon_knife_m9_bayonet" }, { "karambit", "weapon_knife_karambit" },
|
||||||
{ "karambit", "weapon_knife_karambit" },
|
{ "bayonet", "weapon_bayonet" }, { "bowie", "weapon_knife_survival_bowie" },
|
||||||
{ "bayonet", "weapon_bayonet" },
|
{ "butterfly", "weapon_knife_butterfly" }, { "falchion", "weapon_knife_falchion" },
|
||||||
{ "bowie", "weapon_knife_survival_bowie" },
|
{ "flip", "weapon_knife_flip" }, { "gut", "weapon_knife_gut" },
|
||||||
{ "butterfly", "weapon_knife_butterfly" },
|
{ "tactical", "weapon_knife_tactical" }, { "shadow", "weapon_knife_push" },
|
||||||
{ "falchion", "weapon_knife_falchion" },
|
{ "navaja", "weapon_knife_gypsy_jackknife" }, { "stiletto", "weapon_knife_stiletto" },
|
||||||
{ "flip", "weapon_knife_flip" },
|
{ "talon", "weapon_knife_widowmaker" }, { "ursus", "weapon_knife_ursus" },
|
||||||
{ "gut", "weapon_knife_gut" },
|
{ "css", "weapon_knife_css" }, { "paracord", "weapon_knife_cord" },
|
||||||
{ "tactical", "weapon_knife_tactical" },
|
{ "survival", "weapon_knife_canis" }, { "nomad", "weapon_knife_outdoor" },
|
||||||
{ "shadow", "weapon_knife_push" },
|
{ "skeleton", "weapon_knife_skeleton" }, { "default", "weapon_knife" }
|
||||||
{ "navaja", "weapon_knife_gypsy_jackknife" },
|
|
||||||
{ "stiletto", "weapon_knife_stiletto" },
|
|
||||||
{ "talon", "weapon_knife_widowmaker" },
|
|
||||||
{ "ursus", "weapon_knife_ursus" },
|
|
||||||
{ "css", "weapon_knife_css" },
|
|
||||||
{ "paracord", "weapon_knife_cord" },
|
|
||||||
{ "survival", "weapon_knife_canis" },
|
|
||||||
{ "nomad", "weapon_knife_outdoor" },
|
|
||||||
{ "skeleton", "weapon_knife_skeleton" },
|
|
||||||
{ "default", "weapon_knife" }
|
|
||||||
};
|
};
|
||||||
private static readonly List<string> weaponList = new()
|
private static readonly List<string> weaponList = new()
|
||||||
{
|
{
|
||||||
@@ -67,29 +62,116 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
};
|
};
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
base.Load(hotReload);
|
|
||||||
SetGlobalExceptionHandler();
|
SetGlobalExceptionHandler();
|
||||||
MySql = new MySqlDb(Config.DatabaseHost, Config.DatabaseUser, Config.DatabasePassword, Config.DatabaseName!, Config.DatabasePort);
|
if (!Config.GlobalShare)
|
||||||
|
{
|
||||||
|
BuildDatabaseConnectionString();
|
||||||
|
TestDatabaseConnection();
|
||||||
|
}
|
||||||
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
||||||
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
|
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
|
||||||
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
||||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||||
//RegisterEventHandler<EventRoundPrestart>(OnRoundPreStart);
|
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||||
|
RegisterEventHandler<EventItemPickup>(OnItemPickup, HookMode.Pre);
|
||||||
|
|
||||||
|
if (hotReload)
|
||||||
|
{
|
||||||
|
OnMapStart(string.Empty);
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
for (int i = 1; i <= Server.MaxPlayers; i++)
|
||||||
|
{
|
||||||
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
await GetKnifeFromDatabase(i);
|
||||||
|
if (Config.Additional.SkinEnabled)
|
||||||
|
await GetWeaponPaintsFromDatabase(i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
SetupMenus();
|
SetupMenus();
|
||||||
|
|
||||||
RegisterCommands();
|
RegisterCommands();
|
||||||
}
|
}
|
||||||
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)
|
||||||
{
|
{
|
||||||
throw new Exception("You need to setup Database credentials in config!");
|
throw new Exception("You need to setup Database credentials in config!");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Config = config;
|
Config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BuildDatabaseConnectionString()
|
||||||
|
{
|
||||||
|
var builder = new MySqlConnectionStringBuilder
|
||||||
|
{
|
||||||
|
Server = Config.DatabaseHost,
|
||||||
|
UserID = Config.DatabaseUser,
|
||||||
|
Password = Config.DatabasePassword,
|
||||||
|
Database = Config.DatabaseName,
|
||||||
|
Port = (uint)Config.DatabasePort,
|
||||||
|
};
|
||||||
|
|
||||||
|
DatabaseConnectionString = builder.ConnectionString;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TestDatabaseConnection()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new MySqlConnection(DatabaseConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
if (connection.State != System.Data.ConnectionState.Open)
|
||||||
|
{
|
||||||
|
throw new Exception("Unable connect to database!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Unknown mysql exception! " + ex.Message);
|
||||||
|
}
|
||||||
|
CheckDatabaseTables();
|
||||||
|
}
|
||||||
|
|
||||||
|
async private void CheckDatabaseTables()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new MySqlConnection(DatabaseConnectionString);
|
||||||
|
await connection.OpenAsync();
|
||||||
|
|
||||||
|
using var transaction = await connection.BeginTransactionAsync();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string createTable1 = "CREATE TABLE IF NOT EXISTS `wp_player_skins` (`steamid` varchar(64) NOT NULL, `weapon_defindex` int(6) NOT NULL, `weapon_paint_id` int(6) NOT NULL, `weapon_wear` float NOT NULL DEFAULT 0.0001, `weapon_seed` int(16) NOT NULL DEFAULT 0) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci";
|
||||||
|
string createTable2 = "CREATE TABLE IF NOT EXISTS `wp_player_knife` (`steamid` varchar(64) NOT NULL, `knife` varchar(64) NOT NULL, UNIQUE (`steamid`)) ENGINE = InnoDB";
|
||||||
|
|
||||||
|
await connection.ExecuteAsync(createTable1, transaction: transaction);
|
||||||
|
await connection.ExecuteAsync(createTable2, transaction: transaction);
|
||||||
|
|
||||||
|
await transaction.CommitAsync();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
await transaction.RollbackAsync();
|
||||||
|
throw new Exception("Unable to create tables!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Unknown mysql exception! " + ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO: fix for map which change mp_t_default_melee
|
// TODO: fix for map which change mp_t_default_melee
|
||||||
/*private HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
|
/*private HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
@@ -115,12 +197,14 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
{
|
{
|
||||||
AppDomain.CurrentDomain.FirstChanceException -= this.GlobalExceptionHandler;
|
AppDomain.CurrentDomain.FirstChanceException -= this.GlobalExceptionHandler;
|
||||||
}
|
}
|
||||||
public void RegisterCommands()
|
private void RegisterCommands()
|
||||||
{
|
{
|
||||||
AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) => { if (player == null) return; OnCommandWS(player, info); });
|
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); });
|
AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) => { if (player == null) return; OnCommandRefresh(player, info); });
|
||||||
if (Config.Additional.CommandKillEnabled) {
|
if (Config.Additional.CommandKillEnabled)
|
||||||
AddCommand($"css_{Config.Additional.CommandKill}", "kill yourself", (player, info) => {
|
{
|
||||||
|
AddCommand($"css_{Config.Additional.CommandKill}", "kill yourself", (player, info) =>
|
||||||
|
{
|
||||||
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -128,15 +212,63 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void IncompatibilityCheck()
|
||||||
|
{
|
||||||
|
// MatchZy
|
||||||
|
if (Directory.Exists(Path.GetDirectoryName(ModuleDirectory) + "/MatchZy"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("[WeaponPaints] Incompatibility found: MatchZy");
|
||||||
|
IsMatchZy = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnMapStart(string mapName)
|
private void OnMapStart(string mapName)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
if (!Config.Additional.KnifeEnabled) return;
|
||||||
// TODO
|
// TODO
|
||||||
// needed for now
|
// needed for now
|
||||||
base.AddTimer(2.0f, () => {
|
AddTimer(2.0f, () =>
|
||||||
|
{
|
||||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||||
|
IncompatibilityCheck();
|
||||||
});
|
});
|
||||||
|
if (Config.GlobalShare)
|
||||||
|
GlobalShareConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = Int32.Parse(responseBody);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Unable to retrieve serverid from GlobalShare!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Console.WriteLine("[WeaponPaints] GlobalShare ONLINE");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClientPutInServer(int playerSlot)
|
private void OnClientPutInServer(int playerSlot)
|
||||||
@@ -152,9 +284,13 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
}
|
}
|
||||||
private void OnClientDisconnect(int playerSlot)
|
private void OnClientDisconnect(int playerSlot)
|
||||||
{
|
{
|
||||||
|
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
|
if (!player.IsValid || player.IsBot) return;
|
||||||
// TODO: Clean up after player
|
// TODO: Clean up after player
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
g_playersKnife.Remove(playerSlot+1);
|
g_playersKnife.Remove((int)player.EntityIndex!.Value.Value);
|
||||||
|
if (Config.Additional.SkinEnabled)
|
||||||
|
gPlayerWeaponPaints.Remove(new SteamID(player.SteamID).SteamId64);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||||
@@ -165,22 +301,42 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
return HookResult.Continue;
|
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
|
GiveKnifeToPlayer(player);
|
||||||
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;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
if (!IsMatchZy) return HookResult.Continue;
|
||||||
|
|
||||||
|
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||||
|
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||||
|
{
|
||||||
|
CCSPlayerController player = @event.Userid;
|
||||||
|
|
||||||
|
if (player.IsValid && !player.IsBot && @event.Item == "knife")
|
||||||
|
{
|
||||||
|
if (g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)
|
||||||
|
&&
|
||||||
|
g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife")
|
||||||
|
{
|
||||||
|
RefreshPlayerKnife(player, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnEntitySpawned(CEntityInstance entity)
|
private void OnEntitySpawned(CEntityInstance entity)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
if (!Config.Additional.SkinEnabled) return;
|
||||||
@@ -195,7 +351,8 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
}
|
}
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
try {
|
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;
|
||||||
@@ -226,12 +383,14 @@ 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) {}
|
}
|
||||||
|
catch (Exception) { }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void GiveKnifeToPlayer(CCSPlayerController player)
|
public void GiveKnifeToPlayer(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
if (!Config.Additional.KnifeEnabled) return;
|
||||||
|
if (player == null || !player.IsValid) return;
|
||||||
|
|
||||||
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
|
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
|
||||||
{
|
{
|
||||||
@@ -251,8 +410,9 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void RemoveKnifeFromPlayer(CCSPlayerController player)
|
public void RemoveKnifeFromPlayer(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
|
if (player == null || !player.IsValid || !player.PawnIsAlive) 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)
|
||||||
{
|
{
|
||||||
@@ -267,65 +427,31 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void RefreshPlayerKnife(CCSPlayerController player)
|
public void RefreshPlayerKnife(CCSPlayerController? player, bool remove = false)
|
||||||
|
{
|
||||||
|
if (player == null || !player.IsValid || !player.PawnIsAlive) return;
|
||||||
|
|
||||||
|
if (remove == true)
|
||||||
|
RemoveKnifeFromPlayer(player);
|
||||||
|
|
||||||
|
AddTimer(0.2f, () =>
|
||||||
{
|
{
|
||||||
if (!player.IsValid || !player.PawnIsAlive) return;
|
|
||||||
if (!PlayerHasKnife(player))
|
if (!PlayerHasKnife(player))
|
||||||
GiveKnifeToPlayer(player);
|
GiveKnifeToPlayer(player);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (Config.Additional.SkinVisibilityFix)
|
||||||
|
{
|
||||||
|
AddTimer(0.2f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
|
||||||
|
AddTimer(0.3f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
||||||
|
AddTimer(0.36f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
|
||||||
}
|
}
|
||||||
// Unused method, only for testing
|
}
|
||||||
// public void RefreshPlayerKnife(CCSPlayerController player)
|
public bool PlayerHasKnife(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 (!Config.Additional.KnifeEnabled) return false;
|
||||||
|
|
||||||
if (!player.IsValid || !player.PawnIsAlive)
|
if (player == null || !player.IsValid || !player.PawnIsAlive)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -354,11 +480,13 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
if (knifeTypes.TryGetValue(option.Text, out var knife))
|
if (knifeTypes.TryGetValue(option.Text, out var 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))
|
||||||
|
{
|
||||||
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) {
|
if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenuKill) && Config.Additional.CommandKillEnabled)
|
||||||
|
{
|
||||||
temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenuKill}";
|
temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenuKill}";
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
@@ -380,19 +508,25 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
string temp = "";
|
string temp = "";
|
||||||
int playerIndex = (int)player.EntityIndex!.Value.Value;
|
int playerIndex = (int)player.EntityIndex!.Value.Value;
|
||||||
if (DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||||
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex));
|
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex));
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
{
|
||||||
Task.Run(async () => await GetKnifeFromDatabase(playerIndex));
|
Task.Run(async () => await GetKnifeFromDatabase(playerIndex));
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand)) {
|
RemoveKnifeFromPlayer(player);
|
||||||
|
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand))
|
||||||
|
{
|
||||||
temp = $"{Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
temp = $"{Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand)) {
|
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand))
|
||||||
|
{
|
||||||
temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
@@ -405,16 +539,19 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
|
|
||||||
string temp = "";
|
string temp = "";
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand)) {
|
if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand))
|
||||||
|
{
|
||||||
temp = $"{Config.Prefix} {Config.Messages.WebsiteMessageCommand}";
|
temp = $"{Config.Prefix} {Config.Messages.WebsiteMessageCommand}";
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand)) {
|
if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand))
|
||||||
|
{
|
||||||
temp = $"{Config.Prefix} {Config.Messages.SynchronizeMessageCommand}";
|
temp = $"{Config.Prefix} {Config.Messages.SynchronizeMessageCommand}";
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
if (!Config.Additional.KnifeEnabled) return;
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand)) {
|
if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand))
|
||||||
|
{
|
||||||
temp = $"{Config.Prefix} {Config.Messages.KnifeMessageCommand}";
|
temp = $"{Config.Prefix} {Config.Messages.KnifeMessageCommand}";
|
||||||
player.PrintToChat(ReplaceTags(temp));
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
@@ -427,42 +564,93 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
private async Task GetWeaponPaintsFromDatabase(int playerIndex)
|
private async Task GetWeaponPaintsFromDatabase(int playerIndex)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
if (!Config.Additional.SkinEnabled) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
if (player == null || !player.IsValid) return;
|
if (player == null || !player.IsValid || player.IsBot) return;
|
||||||
var steamId = new SteamID(player.SteamID);
|
var steamId = new SteamID(player.SteamID);
|
||||||
|
|
||||||
MySqlQueryCondition conditions = new MySqlQueryCondition()
|
if (Config.GlobalShare)
|
||||||
.Add("steamid", "=", steamId.SteamId64.ToString());
|
|
||||||
|
|
||||||
MySqlQueryResult result = await MySql!.Table("wp_player_skins").Where(conditions).SelectAsync();
|
|
||||||
if (result.Rows < 1) return;
|
|
||||||
result.ToList().ForEach(pair =>
|
|
||||||
{
|
{
|
||||||
int WeaponDefIndex = result.Get<int>(pair.Key, "weapon_defindex");
|
var values = new Dictionary<string, string>
|
||||||
int PaintId = result.Get<int>(pair.Key, "weapon_paint_id");
|
{
|
||||||
float Wear = result.Get<float>(pair.Key, "weapon_wear");
|
{ "server_id", GlobalShareServerId.ToString() },
|
||||||
int Seed = result.Get<int>(pair.Key, "weapon_seed");
|
{ "steamid", steamId.SteamId64.ToString() },
|
||||||
|
{ "skins", "1" }
|
||||||
|
};
|
||||||
|
UriBuilder builder = new UriBuilder(GlobalShareApi);
|
||||||
|
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
||||||
|
|
||||||
if (!gPlayerWeaponPaints.ContainsKey(steamId.SteamId64))
|
using (var httpClient = new HttpClient())
|
||||||
|
{
|
||||||
|
httpClient.BaseAddress = GlobalShareApi;
|
||||||
|
var formContent = new FormUrlEncodedContent(values);
|
||||||
|
HttpResponseMessage response = await httpClient.GetAsync(builder.Uri);
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
string responseBody = await response.Content.ReadAsStringAsync();
|
||||||
|
JArray jsonArray = JArray.Parse(responseBody);
|
||||||
|
if (jsonArray.Count > 0)
|
||||||
{
|
{
|
||||||
gPlayerWeaponPaints[steamId.SteamId64] = new Dictionary<nint, int>();
|
gPlayerWeaponPaints[steamId.SteamId64] = new Dictionary<nint, int>();
|
||||||
}
|
|
||||||
if (!gPlayerWeaponWear.ContainsKey(steamId.SteamId64))
|
|
||||||
{
|
|
||||||
gPlayerWeaponWear[steamId.SteamId64] = new Dictionary<nint, float>();
|
gPlayerWeaponWear[steamId.SteamId64] = new Dictionary<nint, float>();
|
||||||
}
|
|
||||||
if (!gPlayerWeaponSeed.ContainsKey(steamId.SteamId64))
|
|
||||||
{
|
|
||||||
gPlayerWeaponSeed[steamId.SteamId64] = new Dictionary<nint, int>();
|
gPlayerWeaponSeed[steamId.SteamId64] = new Dictionary<nint, int>();
|
||||||
|
|
||||||
|
foreach (var weapon in jsonArray)
|
||||||
|
{
|
||||||
|
int weaponDefIndex = weapon["weapon_defindex"].Value<int>();
|
||||||
|
int weaponPaintId = weapon["weapon_paint_id"].Value<int>();
|
||||||
|
float weaponWear = weapon["weapon_wear"].Value<float>();
|
||||||
|
int weaponSeed = weapon["weapon_seed"].Value<int>();
|
||||||
|
|
||||||
|
gPlayerWeaponPaints[steamId.SteamId64][weaponDefIndex] = weaponPaintId;
|
||||||
|
gPlayerWeaponWear[steamId.SteamId64][weaponDefIndex] = weaponWear;
|
||||||
|
gPlayerWeaponSeed[steamId.SteamId64][weaponDefIndex] = weaponSeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gPlayerWeaponPaints[steamId.SteamId64][WeaponDefIndex] = PaintId;
|
using (var connection = new MySqlConnection(DatabaseConnectionString))
|
||||||
gPlayerWeaponWear[steamId.SteamId64][WeaponDefIndex] = Wear;
|
{
|
||||||
gPlayerWeaponSeed[steamId.SteamId64][WeaponDefIndex] = Seed;
|
await connection.OpenAsync();
|
||||||
|
|
||||||
|
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||||
|
|
||||||
|
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = steamId.SteamId64.ToString() });
|
||||||
|
|
||||||
|
if (PlayerSkins != null && PlayerSkins.AsList().Count > 0)
|
||||||
|
{
|
||||||
|
gPlayerWeaponPaints[steamId.SteamId64] = new Dictionary<nint, int>();
|
||||||
|
gPlayerWeaponWear[steamId.SteamId64] = new Dictionary<nint, float>();
|
||||||
|
gPlayerWeaponSeed[steamId.SteamId64] = new Dictionary<nint, int>();
|
||||||
|
|
||||||
|
PlayerSkins.ToList().ForEach(row =>
|
||||||
|
{
|
||||||
|
int weaponDefIndex = row.weapon_defindex ?? default(int);
|
||||||
|
int weaponPaintId = row.weapon_paint_id ?? default(int);
|
||||||
|
float weaponWear = row.weapon_wear ?? default(float);
|
||||||
|
int weaponSeed = row.weapon_seed ?? default(int);
|
||||||
|
|
||||||
|
gPlayerWeaponPaints[steamId.SteamId64][weaponDefIndex] = weaponPaintId;
|
||||||
|
gPlayerWeaponWear[steamId.SteamId64][weaponDefIndex] = weaponWear;
|
||||||
|
gPlayerWeaponSeed[steamId.SteamId64][weaponDefIndex] = weaponSeed;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log(e.Message);
|
Log(e.Message);
|
||||||
@@ -475,23 +663,61 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
if (player == null || !player.IsValid) return;
|
if (player == null || !player.IsValid || player.IsBot) return;
|
||||||
var steamId = new SteamID(player.SteamID);
|
var steamId = new SteamID(player.SteamID);
|
||||||
MySqlQueryCondition conditions = new MySqlQueryCondition()
|
|
||||||
.Add("steamid", "=", steamId.SteamId64.ToString());
|
|
||||||
|
|
||||||
MySqlQueryResult result = await MySql!.Table("wp_player_knife").Where(conditions).SelectAsync();
|
if (Config.GlobalShare)
|
||||||
|
{
|
||||||
if (result.Rows < 1)
|
var values = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "server_id", GlobalShareServerId.ToString() },
|
||||||
|
{ "steamid", steamId.SteamId64.ToString() },
|
||||||
|
{ "knife", "1" }
|
||||||
|
};
|
||||||
|
UriBuilder builder = new UriBuilder(GlobalShareApi);
|
||||||
|
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
||||||
|
|
||||||
|
using (var httpClient = new HttpClient())
|
||||||
|
{
|
||||||
|
httpClient.BaseAddress = GlobalShareApi;
|
||||||
|
var formContent = new FormUrlEncodedContent(values);
|
||||||
|
HttpResponseMessage response = await httpClient.GetAsync(builder.Uri);
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
string result = await response.Content.ReadAsStringAsync();
|
||||||
|
if (!string.IsNullOrEmpty(result))
|
||||||
|
{
|
||||||
|
g_playersKnife[playerIndex] = result;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
//g_playersKnife[playerIndex] = "weapon_knife";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string knife = result.Get<string>(0, "knife");
|
}
|
||||||
if (knife != null)
|
else
|
||||||
{
|
{
|
||||||
g_playersKnife[playerIndex] = knife;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var connection = new MySqlConnection(DatabaseConnectionString))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
||||||
|
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = steamId.SteamId64.ToString() });
|
||||||
|
|
||||||
|
if (PlayerKnife != null)
|
||||||
|
{
|
||||||
|
g_playersKnife[playerIndex] = PlayerKnife;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Log($"{player.PlayerName} has this knife -> {g_playersKnife[playerIndex]}");
|
//Log($"{player.PlayerName} has this knife -> {g_playersKnife[playerIndex]}");
|
||||||
}
|
}
|
||||||
@@ -509,7 +735,11 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
if (player == null || !player.IsValid) return;
|
if (player == null || !player.IsValid) return;
|
||||||
var steamId = new SteamID(player.SteamID);
|
var steamId = new SteamID(player.SteamID);
|
||||||
await MySql!.ExecuteNonQueryAsync($"INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES('{steamId.SteamId64}', '{knife}') ON DUPLICATE KEY UPDATE `knife` = '{knife}';");
|
|
||||||
|
using var connection = new MySqlConnection(DatabaseConnectionString);
|
||||||
|
await connection.OpenAsync();
|
||||||
|
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
||||||
|
await connection.ExecuteAsync(query, new { steamid = steamId.SteamId64.ToString(), newKnife = knife });
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
|
||||||
<PackageReference Include="Nexd.MySQL" Version="1.0.1" />
|
<PackageReference Include="Dapper" Version="2.1.21" />
|
||||||
|
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
-- phpMyAdmin SQL Dump
|
|
||||||
-- version 5.2.1
|
|
||||||
-- https://www.phpmyadmin.net/
|
|
||||||
--
|
|
||||||
-- Host: localhost
|
|
||||||
-- Generation Time: Nov 02, 2023 at 11:12 AM
|
|
||||||
-- Server version: 10.11.2-MariaDB
|
|
||||||
-- PHP Version: 8.2.3
|
|
||||||
|
|
||||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
|
||||||
START TRANSACTION;
|
|
||||||
SET time_zone = "+00:00";
|
|
||||||
|
|
||||||
|
|
||||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
|
||||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
|
||||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
|
||||||
/*!40101 SET NAMES utf8mb4 */;
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Database: `cs2server`
|
|
||||||
--
|
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Table structure for table `wp_player_skins`
|
|
||||||
--
|
|
||||||
|
|
||||||
CREATE TABLE `wp_player_skins` (
|
|
||||||
`steamid` varchar(64) NOT NULL,
|
|
||||||
`weapon_defindex` int(6) NOT NULL,
|
|
||||||
`weapon_paint_id` int(6) NOT NULL,
|
|
||||||
`weapon_wear` float NOT NULL DEFAULT 0.0001,
|
|
||||||
`weapon_seed` int(16) NOT NULL DEFAULT 0
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Table structure for table `wp_player_knife`
|
|
||||||
--
|
|
||||||
|
|
||||||
CREATE TABLE `wp_player_knife` (
|
|
||||||
`steamid` varchar(64) NOT NULL,
|
|
||||||
`knife` varchar(64) NOT NULL,
|
|
||||||
UNIQUE (`steamid`)
|
|
||||||
) ENGINE = InnoDB;
|
|
||||||
@@ -7,9 +7,7 @@ require_once 'class/utils.php';
|
|||||||
|
|
||||||
$db = new DataBase();
|
$db = new DataBase();
|
||||||
if (isset($_SESSION['steamid'])) {
|
if (isset($_SESSION['steamid'])) {
|
||||||
|
$steamid = $_SESSION['steamid'];
|
||||||
include('steamauth/userInfo.php');
|
|
||||||
$steamid = $steamprofile['steamid'];
|
|
||||||
|
|
||||||
$weapons = UtilsClass::getWeaponsFromArray();
|
$weapons = UtilsClass::getWeaponsFromArray();
|
||||||
$skins = UtilsClass::skinsFromJson();
|
$skins = UtilsClass::skinsFromJson();
|
||||||
@@ -24,6 +22,8 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
if ($ex[0] == "knife") {
|
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']]);
|
$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 {
|
} else {
|
||||||
|
if (!is_int($ex[1]))
|
||||||
|
header("Location: index.php");
|
||||||
if (array_key_exists($ex[1], $skins[$ex[0]])) {
|
if (array_key_exists($ex[1], $skins[$ex[0]])) {
|
||||||
if (array_key_exists($ex[0], $selectedSkins)) {
|
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]]);
|
$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]]);
|
||||||
@@ -85,7 +85,7 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<form action="" method="POST">
|
<form action="" method="POST">
|
||||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||||
<option>Select knife</option>
|
<option disabled>Select knife</option>
|
||||||
<?php
|
<?php
|
||||||
foreach ($knifes as $knifeKey => $knife) {
|
foreach ($knifes as $knifeKey => $knife) {
|
||||||
if ($selectedKnife['knife'] == $knife['weapon_name'])
|
if ($selectedKnife['knife'] == $knife['weapon_name'])
|
||||||
@@ -122,7 +122,7 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<form action="" method="POST">
|
<form action="" method="POST">
|
||||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||||
<option>Select skin</option>
|
<option disabled>Select skin</option>
|
||||||
<?php
|
<?php
|
||||||
foreach ($skins[$defindex] as $paintKey => $paint) {
|
foreach ($skins[$defindex] as $paintKey => $paint) {
|
||||||
if (array_key_exists($defindex, $selectedSkins) && $selectedSkins[$defindex] == $paintKey)
|
if (array_key_exists($defindex, $selectedSkins) && $selectedSkins[$defindex] == $paintKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user