Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.3b #222

Merged
merged 2 commits into from
Mar 21, 2024
Merged

2.3b #222

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 48 additions & 46 deletions Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,60 +471,62 @@ private void SetupAgentsMenu()
if (!Utility.IsPlayerValid(player) || player is null) return;

string selectedPaintName = option.Text;
var selectedAgent = agentsList.FirstOrDefault(g =>
g.ContainsKey("agent_name") &&
g["agent_name"] != null && g["agent_name"]!.ToString() == selectedPaintName &&
g["team"] != null && (int)(g["team"]!) == player.TeamNum);

var selectedAgent = agentsList.FirstOrDefault(g => g.ContainsKey("agent_name") && g["agent_name"]?.ToString() == selectedPaintName);
if (selectedAgent != null)
if (selectedAgent == null) return;

if (
selectedAgent != null &&
selectedAgent.ContainsKey("model")
)
{
if (
selectedAgent != null &&
selectedAgent.ContainsKey("model")
)
PlayerInfo playerInfo = new PlayerInfo
{
PlayerInfo playerInfo = new PlayerInfo
{
UserId = player.UserId,
Slot = player.Slot,
Index = (int)player.Index,
SteamId = player.SteamID.ToString(),
Name = player.PlayerName,
IpAddress = player.IpAddress?.Split(":")[0]
};
UserId = player.UserId,
Slot = player.Slot,
Index = (int)player.Index,
SteamId = player.SteamID.ToString(),
Name = player.PlayerName,
IpAddress = player.IpAddress?.Split(":")[0]
};

if (Config.Additional.ShowSkinImage)
{
string image = selectedAgent["image"]?.ToString() ?? "";
PlayerWeaponImage[player.Slot] = image;
AddTimer(2.0f, () => PlayerWeaponImage.Remove(player.Slot), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
if (Config.Additional.ShowSkinImage)
{
string image = selectedAgent["image"]?.ToString() ?? "";
PlayerWeaponImage[player.Slot] = image;
AddTimer(2.0f, () => PlayerWeaponImage.Remove(player.Slot), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}

if (!string.IsNullOrEmpty(Localizer["wp_agent_menu_select"]))
{
player!.Print(Localizer["wp_agent_menu_select", selectedPaintName]);
}
if (!string.IsNullOrEmpty(Localizer["wp_agent_menu_select"]))
{
player!.Print(Localizer["wp_agent_menu_select", selectedPaintName]);
}

if (player.TeamNum == 3)
{
g_playersAgent.AddOrUpdate(player.Slot,
key => (selectedAgent["model"]!.ToString().Equals("null") ? null : selectedAgent["model"]!.ToString(), null),
(key, oldValue) => (selectedAgent["model"]!.ToString().Equals("null") ? null : selectedAgent["model"]!.ToString(), oldValue.T));
}
else
{
g_playersAgent.AddOrUpdate(player.Slot,
key => (null, selectedAgent["model"]!.ToString().Equals("null") ? null : selectedAgent["model"]!.ToString()),
(key, oldValue) => (oldValue.CT, selectedAgent["model"]!.ToString().Equals("null") ? null : selectedAgent["model"]!.ToString())
);
}
if (player.TeamNum == 3)
{
g_playersAgent.AddOrUpdate(player.Slot,
key => (selectedAgent["model"]!.ToString().Equals("null") ? null : selectedAgent["model"]!.ToString(), null),
(key, oldValue) => (selectedAgent["model"]!.ToString().Equals("null") ? null : selectedAgent["model"]!.ToString(), oldValue.T));
}
else
{
g_playersAgent.AddOrUpdate(player.Slot,
key => (null, selectedAgent["model"]!.ToString().Equals("null") ? null : selectedAgent["model"]!.ToString()),
(key, oldValue) => (oldValue.CT, selectedAgent["model"]!.ToString().Equals("null") ? null : selectedAgent["model"]!.ToString())
);
}

if (weaponSync != null)
if (weaponSync != null)
{
_ = Task.Run(async () =>
{
_ = Task.Run(async () =>
{
await weaponSync.SyncAgentToDatabase(playerInfo);
});
}
};
}
await weaponSync.SyncAgentToDatabase(playerInfo);
});
}
};
};

// Command to open the weapon selection menu for players
Expand Down
8 changes: 4 additions & 4 deletions Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon
return;
}

if (!gPlayerWeaponsInfo[player.Slot].ContainsKey(weaponDefIndex) || gPlayerWeaponsInfo[player.Slot][weaponDefIndex].Paint == 0) return;
if (!gPlayerWeaponsInfo[player.Slot].TryGetValue(weaponDefIndex, out WeaponInfo? value) || value.Paint == 0) return;

WeaponInfo weaponInfo = gPlayerWeaponsInfo[player.Slot][weaponDefIndex];
WeaponInfo weaponInfo = value;
//Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
weapon.AttributeManager.Item.ItemID = 16384;
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
Expand Down Expand Up @@ -257,7 +257,7 @@ public HookResult OnGiveNamedItemPost(DynamicHook hook)
}
*/

public void OnEntityCreated(CEntityInstance entity)
public void OnEntitySpawned(CEntityInstance entity)
{
var designerName = entity.DesignerName;

Expand Down Expand Up @@ -326,7 +326,7 @@ private void RegisterListeners()
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
RegisterListener<Listeners.OnTick>(OnTick);
//VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
}
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3a
2.3b
7 changes: 4 additions & 3 deletions WeaponAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ internal void RefreshWeapons(CCSPlayerController? player)
int clip1 = weapon.Value.Clip1;
int reservedAmmo = weapon.Value.ReserveAmmo[0];

if (!weaponsWithAmmo.ContainsKey(weaponByDefindex))
if (!weaponsWithAmmo.TryGetValue(weaponByDefindex, out List<(int, int)>? value))
{
weaponsWithAmmo.Add(weaponByDefindex, new List<(int, int)>());
value = new List<(int, int)>();
weaponsWithAmmo.Add(weaponByDefindex, value);
}

weaponsWithAmmo[weaponByDefindex].Add((clip1, reservedAmmo));
value.Add((clip1, reservedAmmo));

if (gun == null || gun.VData == null) return;

Expand Down
33 changes: 18 additions & 15 deletions WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace WeaponPaints;

[MinimumApiVersion(191)]
[MinimumApiVersion(195)]
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
{
internal static WeaponPaints Instance { get; private set; } = new();
Expand Down Expand Up @@ -75,23 +75,23 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
{ "weapon_knife_kukri", "Kukri Knife" }
};

internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
internal static WeaponPaintsConfig _config = new();
internal static IStringLocalizer? _localizer;
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
internal static ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>();
internal static ConcurrentDictionary<int, ushort> g_playersGlove = new ConcurrentDictionary<int, ushort>();
internal static ConcurrentDictionary<int, ushort> g_playersMusic = new ConcurrentDictionary<int, ushort>();
internal static ConcurrentDictionary<int, (string? CT, string? T)> g_playersAgent = new ConcurrentDictionary<int, (string?, string?)>();
internal static ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>>();
internal static List<JObject> skinsList = new List<JObject>();
internal static List<JObject> glovesList = new List<JObject>();
internal static List<JObject> agentsList = new List<JObject>();
internal static List<JObject> musicList = new List<JObject>();
internal static Dictionary<int, int> g_knifePickupCount = new();
internal static ConcurrentDictionary<int, string> g_playersKnife = new();
internal static ConcurrentDictionary<int, ushort> g_playersGlove = new();
internal static ConcurrentDictionary<int, ushort> g_playersMusic = new();
internal static ConcurrentDictionary<int, (string? CT, string? T)> g_playersAgent = new();
internal static ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new();
internal static List<JObject> skinsList = new();
internal static List<JObject> glovesList = new();
internal static List<JObject> agentsList = new();
internal static List<JObject> musicList = new();
internal static WeaponSynchronization? weaponSync;
public static bool g_bCommandsAllowed = true;
internal Dictionary<int, string> PlayerWeaponImage = new();

internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
internal static Dictionary<int, DateTime> commandsCooldown = new();
internal static Database? _database;

internal static MemoryFunctionVoid<nint, string, float> CAttributeList_SetOrAddAttributeValueByName = new(GameData.GetSignature("CAttributeList_SetOrAddAttributeValueByName"));
Expand Down Expand Up @@ -160,7 +160,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
public override string ModuleAuthor => "Nereziel & daffyy";
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
public override string ModuleName => "WeaponPaints";
public override string ModuleVersion => "2.3a";
public override string ModuleVersion => "2.3b";

public static WeaponPaintsConfig GetWeaponPaintsConfig()
{
Expand All @@ -177,7 +177,10 @@ public override void Load(bool hotReload)

foreach (var player in Utilities.GetPlayers())
{
if (weaponSync == null || player is null || !player.IsValid || player.SteamID.ToString().Length != 17 || player.IsBot ||
if (weaponSync == null)
break;

if (player is null || !player.IsValid || player.SteamID.ToString().Length != 17 || string.IsNullOrEmpty(player.IpAddress) || player.IsBot ||
player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected)
continue;

Expand Down
Loading