mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-22 19:54:27 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e92635231 | ||
|
|
6923295cb6 | ||
|
|
e5f98077f3 | ||
|
|
3296055841 | ||
|
|
89de192c20 | ||
|
|
a1297b9cbe | ||
|
|
99af078b32 | ||
|
|
b0bef746cd | ||
|
|
117a95e99c |
17
.github/workflows/build.yml
vendored
17
.github/workflows/build.yml
vendored
@@ -28,6 +28,21 @@ 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:
|
||||||
|
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 \
|
||||||
@@ -57,4 +72,4 @@ jobs:
|
|||||||
name: "Build ${{ env.BUILD_NUMBER }}"
|
name: "Build ${{ env.BUILD_NUMBER }}"
|
||||||
tag: "build-${{ env.BUILD_NUMBER }}"
|
tag: "build-${{ env.BUILD_NUMBER }}"
|
||||||
body: |
|
body: |
|
||||||
Place the plugin in game/csgo/addons/counterstrikesharp/plugins/WeaponPaints
|
Place the plugin in game/csgo/addons/counterstrikesharp/plugins/WeaponPaints
|
||||||
341
WeaponPaints.cs
341
WeaponPaints.cs
@@ -7,14 +7,14 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
[MinimumApiVersion(50)]
|
[MinimumApiVersion(54)]
|
||||||
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
@@ -24,7 +24,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
|
|
||||||
public WeaponPaintsConfig Config { get; set; } = new();
|
public WeaponPaintsConfig Config { get; set; } = new();
|
||||||
|
|
||||||
MySqlDb? MySql = null;
|
private string DatabaseConnectionString = string.Empty;
|
||||||
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 +32,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,19 +57,32 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
};
|
};
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
base.Load(hotReload);
|
BuildDatabaseConnectionString();
|
||||||
|
TestDatabaseConnection();
|
||||||
SetGlobalExceptionHandler();
|
SetGlobalExceptionHandler();
|
||||||
MySql = new MySqlDb(Config.DatabaseHost, Config.DatabaseUser, Config.DatabasePassword, Config.DatabaseName!, Config.DatabasePort);
|
//MySql = new MySqlDb(Config.DatabaseHost, Config.DatabaseUser, Config.DatabasePassword, Config.DatabaseName!, Config.DatabasePort);
|
||||||
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);
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
SetupMenus();
|
SetupMenus();
|
||||||
|
|
||||||
RegisterCommands();
|
RegisterCommands();
|
||||||
|
if (hotReload)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void OnConfigParsed(WeaponPaintsConfig config)
|
public void OnConfigParsed(WeaponPaintsConfig config)
|
||||||
{
|
{
|
||||||
@@ -90,15 +93,80 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
|
|
||||||
Config = config;
|
Config = config;
|
||||||
}
|
}
|
||||||
// TODO: fix for map which change mp_t_default_melee
|
|
||||||
/*private HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
|
private void BuildDatabaseConnectionString()
|
||||||
{
|
{
|
||||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
var builder = new MySqlConnectionStringBuilder
|
||||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
{
|
||||||
return HookResult.Continue;
|
Server = Config.DatabaseHost,
|
||||||
|
UserID = Config.DatabaseUser,
|
||||||
|
Password = Config.DatabasePassword,
|
||||||
|
Database = Config.DatabaseName,
|
||||||
|
Port = (uint)Config.DatabasePort,
|
||||||
|
};
|
||||||
|
|
||||||
|
DatabaseConnectionString = builder.ConnectionString;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
public override void Unload(bool hotReload)
|
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
|
||||||
|
/*private HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||||
|
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public override void Unload(bool hotReload)
|
||||||
{
|
{
|
||||||
RemoveGlobalExceptionHandler();
|
RemoveGlobalExceptionHandler();
|
||||||
base.Unload(hotReload);
|
base.Unload(hotReload);
|
||||||
@@ -152,12 +220,16 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
}
|
}
|
||||||
private void OnClientDisconnect(int playerSlot)
|
private void OnClientDisconnect(int playerSlot)
|
||||||
{
|
{
|
||||||
// TODO: Clean up after player
|
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (!player.IsValid || player.IsBot) return;
|
||||||
g_playersKnife.Remove(playerSlot+1);
|
|
||||||
}
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
g_playersKnife.Remove(playerSlot+1);
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
var player = @event.Userid;
|
var player = @event.Userid;
|
||||||
if (!player.IsValid || !player.PlayerPawn.IsValid)
|
if (!player.IsValid || !player.PlayerPawn.IsValid)
|
||||||
@@ -174,9 +246,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
if (Config.Additional.SkinVisibilityFix)
|
if (Config.Additional.SkinVisibilityFix)
|
||||||
{
|
{
|
||||||
// Check the best slot and set it. Weird solution but works xD
|
// Check the best slot and set it. Weird solution but works xD
|
||||||
AddTimer(0.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;
|
||||||
@@ -271,57 +340,61 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
{
|
{
|
||||||
if (!player.IsValid || !player.PawnIsAlive) return;
|
if (!player.IsValid || !player.PawnIsAlive) return;
|
||||||
if (!PlayerHasKnife(player))
|
if (!PlayerHasKnife(player))
|
||||||
GiveKnifeToPlayer(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))
|
AddTimer(0.2f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
|
||||||
// // player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
AddTimer(0.32f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
||||||
|
AddTimer(0.42f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
|
||||||
// var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
}
|
||||||
// foreach (var weapon in weapons)
|
// Unused method, only for testing
|
||||||
// {
|
// public void RefreshPlayerKnife(CCSPlayerController player)
|
||||||
// if (weapon.IsValid && weapon.Value.IsValid)
|
// {
|
||||||
// {
|
// if (!Config.Additional.KnifeEnabled) return;
|
||||||
// //if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
// // if (!g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)) return;
|
||||||
// if (weapon.Value.DesignerName.Contains("knife"))
|
|
||||||
// {
|
|
||||||
// weapon.Value.Remove();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
// // if (!PlayerHasKnife(player))
|
||||||
// foreach (var weapon in weapons)
|
// // player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
||||||
// {
|
|
||||||
// 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)
|
// 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;
|
||||||
|
|
||||||
@@ -430,38 +503,40 @@ 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()
|
using (var connection = new MySqlConnection(DatabaseConnectionString))
|
||||||
.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");
|
await connection.OpenAsync();
|
||||||
int PaintId = result.Get<int>(pair.Key, "weapon_paint_id");
|
|
||||||
float Wear = result.Get<float>(pair.Key, "weapon_wear");
|
|
||||||
int Seed = result.Get<int>(pair.Key, "weapon_seed");
|
|
||||||
|
|
||||||
if (!gPlayerWeaponPaints.ContainsKey(steamId.SteamId64))
|
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||||
{
|
|
||||||
gPlayerWeaponPaints[steamId.SteamId64] = new Dictionary<nint, int>();
|
|
||||||
}
|
|
||||||
if (!gPlayerWeaponWear.ContainsKey(steamId.SteamId64))
|
|
||||||
{
|
|
||||||
gPlayerWeaponWear[steamId.SteamId64] = new Dictionary<nint, float>();
|
|
||||||
}
|
|
||||||
if (!gPlayerWeaponSeed.ContainsKey(steamId.SteamId64))
|
|
||||||
{
|
|
||||||
gPlayerWeaponSeed[steamId.SteamId64] = new Dictionary<nint, int>();
|
|
||||||
}
|
|
||||||
|
|
||||||
gPlayerWeaponPaints[steamId.SteamId64][WeaponDefIndex] = PaintId;
|
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = steamId.SteamId64.ToString() });
|
||||||
gPlayerWeaponWear[steamId.SteamId64][WeaponDefIndex] = Wear;
|
|
||||||
gPlayerWeaponSeed[steamId.SteamId64][WeaponDefIndex] = Seed;
|
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)
|
||||||
{
|
{
|
||||||
@@ -475,23 +550,23 @@ 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();
|
using (var connection = new MySqlConnection(DatabaseConnectionString))
|
||||||
|
|
||||||
if (result.Rows < 1)
|
|
||||||
{
|
{
|
||||||
//g_playersKnife[playerIndex] = "weapon_knife";
|
await connection.OpenAsync();
|
||||||
return;
|
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
||||||
}
|
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = steamId.SteamId64.ToString() });
|
||||||
|
|
||||||
string knife = result.Get<string>(0, "knife");
|
if (PlayerKnife != null)
|
||||||
if (knife != null)
|
{
|
||||||
{
|
g_playersKnife[playerIndex] = PlayerKnife;
|
||||||
g_playersKnife[playerIndex] = knife;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Log($"{player.PlayerName} has this knife -> {g_playersKnife[playerIndex]}");
|
//Log($"{player.PlayerName} has this knife -> {g_playersKnife[playerIndex]}");
|
||||||
}
|
}
|
||||||
@@ -509,7 +584,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,8 @@
|
|||||||
|
|
||||||
<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" />
|
||||||
</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;
|
|
||||||
Reference in New Issue
Block a user