mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 10:43:22 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3453f4c505 | ||
|
|
25b466422b | ||
|
|
6baa59dd9b | ||
|
|
10afe7ce1e | ||
|
|
5eeb0c5fec | ||
|
|
e53ee27b39 | ||
|
|
75112b02fe | ||
|
|
8e92635231 | ||
|
|
6923295cb6 |
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@@ -30,9 +30,10 @@ jobs:
|
|||||||
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:
|
publish:
|
||||||
|
if: github.event_name == 'push'
|
||||||
permissions: write-all
|
permissions: write-all
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup .NET
|
- name: Setup .NET
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
386
WeaponPaints.cs
386
WeaponPaints.cs
@@ -1,7 +1,6 @@
|
|||||||
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;
|
||||||
@@ -11,20 +10,26 @@ using MySqlConnector;
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using CounterStrikeSharp.API.Modules.Cvars;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
[MinimumApiVersion(54)]
|
[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();
|
||||||
|
|
||||||
private string DatabaseConnectionString = string.Empty;
|
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,28 +62,49 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
};
|
};
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
base.Load(hotReload);
|
SetGlobalExceptionHandler();
|
||||||
|
if (!Config.GlobalShare)
|
||||||
|
{
|
||||||
BuildDatabaseConnectionString();
|
BuildDatabaseConnectionString();
|
||||||
TestDatabaseConnection();
|
TestDatabaseConnection();
|
||||||
SetGlobalExceptionHandler();
|
}
|
||||||
//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);
|
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;
|
||||||
}
|
}
|
||||||
@@ -123,7 +139,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
{
|
{
|
||||||
throw new Exception("Unknown mysql exception! " + ex.Message);
|
throw new Exception("Unknown mysql exception! " + ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckDatabaseTables();
|
CheckDatabaseTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,15 +172,15 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
throw new Exception("Unknown mysql exception! " + ex.Message);
|
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)
|
||||||
{
|
{
|
||||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
public override void Unload(bool hotReload)
|
public override void Unload(bool hotReload)
|
||||||
{
|
{
|
||||||
RemoveGlobalExceptionHandler();
|
RemoveGlobalExceptionHandler();
|
||||||
base.Unload(hotReload);
|
base.Unload(hotReload);
|
||||||
@@ -182,28 +197,78 @@ public override void Unload(bool hotReload)
|
|||||||
{
|
{
|
||||||
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) => {
|
{
|
||||||
if(player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
AddCommand($"css_{Config.Additional.CommandKill}", "kill yourself", (player, info) =>
|
||||||
|
{
|
||||||
|
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
player.PlayerPawn.Value.CommitSuicide(true, false);
|
player.PlayerPawn.Value.CommitSuicide(true, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
@@ -221,9 +286,9 @@ public override void Unload(bool hotReload)
|
|||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
if (!player.IsValid || player.IsBot) return;
|
if (!player.IsValid || player.IsBot) return;
|
||||||
|
// 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)
|
if (Config.Additional.SkinEnabled)
|
||||||
gPlayerWeaponPaints.Remove(new SteamID(player.SteamID).SteamId64);
|
gPlayerWeaponPaints.Remove(new SteamID(player.SteamID).SteamId64);
|
||||||
}
|
}
|
||||||
@@ -236,19 +301,42 @@ public override void Unload(bool hotReload)
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -263,7 +351,8 @@ public override void Unload(bool hotReload)
|
|||||||
}
|
}
|
||||||
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;
|
||||||
@@ -294,12 +383,14 @@ public override void Unload(bool hotReload)
|
|||||||
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))
|
||||||
{
|
{
|
||||||
@@ -319,8 +410,9 @@ public override void Unload(bool hotReload)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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)
|
||||||
{
|
{
|
||||||
@@ -335,69 +427,31 @@ public override void Unload(bool hotReload)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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.2f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
|
||||||
AddTimer(0.32f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
AddTimer(0.3f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
||||||
AddTimer(0.42f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
|
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;
|
||||||
}
|
}
|
||||||
@@ -426,11 +480,13 @@ public override void Unload(bool hotReload)
|
|||||||
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));
|
||||||
}
|
}
|
||||||
@@ -452,19 +508,25 @@ public override void Unload(bool hotReload)
|
|||||||
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));
|
||||||
}
|
}
|
||||||
@@ -477,16 +539,19 @@ public override void Unload(bool hotReload)
|
|||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
@@ -499,12 +564,61 @@ public override void Unload(bool hotReload)
|
|||||||
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 || player.IsBot) return;
|
if (player == null || !player.IsValid || player.IsBot) return;
|
||||||
var steamId = new SteamID(player.SteamID);
|
var steamId = new SteamID(player.SteamID);
|
||||||
|
|
||||||
|
if (Config.GlobalShare)
|
||||||
|
{
|
||||||
|
var values = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "server_id", GlobalShareServerId.ToString() },
|
||||||
|
{ "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)}"));
|
||||||
|
|
||||||
|
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>();
|
||||||
|
gPlayerWeaponWear[steamId.SteamId64] = new Dictionary<nint, float>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
using (var connection = new MySqlConnection(DatabaseConnectionString))
|
using (var connection = new MySqlConnection(DatabaseConnectionString))
|
||||||
{
|
{
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
@@ -552,6 +666,44 @@ public override void Unload(bool hotReload)
|
|||||||
if (player == null || !player.IsValid || player.IsBot) return;
|
if (player == null || !player.IsValid || player.IsBot) return;
|
||||||
var steamId = new SteamID(player.SteamID);
|
var steamId = new SteamID(player.SteamID);
|
||||||
|
|
||||||
|
if (Config.GlobalShare)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
using (var connection = new MySqlConnection(DatabaseConnectionString))
|
using (var connection = new MySqlConnection(DatabaseConnectionString))
|
||||||
{
|
{
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.21" />
|
<PackageReference Include="Dapper" Version="2.1.21" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user