Skip to content

Commit

Permalink
Merge pull request #187 from daffyyyy/main
Browse files Browse the repository at this point in the history
2.1a
  • Loading branch information
daffyyyy authored Mar 4, 2024
2 parents 09d9de2 + 485dd1e commit ee12598
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 228 deletions.
82 changes: 29 additions & 53 deletions Events.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;

namespace WeaponPaints
Expand Down Expand Up @@ -105,6 +104,8 @@ private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon

if (isKnife && !g_playersKnife.ContainsKey(player.Slot) || isKnife && g_playersKnife[player.Slot] == "weapon_knife") return;

int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 };

if (isKnife)
{
var newDefIndex = WeaponDefindex.FirstOrDefault(x => x.Value == g_playersKnife[player.Slot]);
Expand Down Expand Up @@ -139,41 +140,18 @@ private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon
if (fallbackPaintKit == 0)
return;

var foundSkin = skinsList.FirstOrDefault(skin =>
((int?)skin?["weapon_defindex"] ?? 0) == weaponDefIndex &&
((int?)skin?["paint"] ?? 0) == fallbackPaintKit &&
skin?["paint_name"] != null
);

if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
if (!isKnife)
{
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);

int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 };

if (newPaints.Contains(fallbackPaintKit))
{
skeleton.ModelState.MeshGroupMask = 1;
UpdatePlayerWeaponMeshGroupMask(player, weapon, false);
}
else
{
if (skeleton.ModelState.MeshGroupMask != 2)
{
skeleton.ModelState.MeshGroupMask = 2;
}
UpdatePlayerWeaponMeshGroupMask(player, weapon, true);
}
}

var viewModels = GetPlayerViewModels(player);
if (viewModels == null || viewModels.Length == 0)
return;

var viewModel = viewModels[0];
if (viewModel == null || viewModel.Value == null || viewModel.Value.Weapon == null || viewModel.Value.Weapon.Value == null)
return;

Utilities.SetStateChanged(viewModel.Value, "CBaseEntity", "m_CBodyComponent");

return;
}

Expand All @@ -193,38 +171,17 @@ private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon
if (fallbackPaintKit == 0)
return;

var foundSkin1 = skinsList.FirstOrDefault(skin =>
((int?)skin?["weapon_defindex"] ?? 0) == weaponDefIndex &&
((int?)skin?["paint"] ?? 0) == fallbackPaintKit &&
skin?["paint_name"] != null
);

if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
if (!isKnife)
{
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 };
if (newPaints.Contains(fallbackPaintKit))
{
skeleton.ModelState.MeshGroupMask = 1;
UpdatePlayerWeaponMeshGroupMask(player, weapon, false);
}
else
{
if (skeleton.ModelState.MeshGroupMask != 2)
{
skeleton.ModelState.MeshGroupMask = 2;
}
UpdatePlayerWeaponMeshGroupMask(player, weapon, true);
}
}

var viewModels1 = GetPlayerViewModels(player);
if (viewModels1 == null || viewModels1.Length == 0)
return;

var viewModel1 = viewModels1[0];
if (viewModel1 == null || viewModel1.Value == null || viewModel1.Value.Weapon == null || viewModel1.Value.Weapon.Value == null)
return;

Utilities.SetStateChanged(viewModel1.Value, "CBaseEntity", "m_CBodyComponent");
}

private void OnMapStart(string mapName)
Expand Down Expand Up @@ -306,15 +263,34 @@ public HookResult OnGiveNamedItemPost(DynamicHook hook)
return HookResult.Continue;
}

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

if (designerName.Contains("weapon"))
{
Server.NextFrame(() =>
{
var weapon = new CBasePlayerWeapon(entity.Handle);
if (!weapon.IsValid) return;
var player = Utilities.GetPlayerFromSteamId(weapon.OriginalOwnerXuidLow);
if (player == null || !Utility.IsPlayerValid(player)) return;
GivePlayerWeaponSkin(player, weapon);
});
}
}

private void RegisterListeners()
{
RegisterListener<Listeners.OnMapStart>(OnMapStart);

RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);

VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
//VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);

//HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup);
}
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
- Steam login/logout
- Change knife, paint, seed and wear

## Known issues
- Issue on Windows servers, no knives are given.
- You can't change knife if it's equpied in cs2 inventory
- Can cause incompatibility with plugins/maps which manipulates weapons and knives

## Troubleshooting
<details>
**Skins are not changing:**
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0a
2.1a
Loading

0 comments on commit ee12598

Please sign in to comment.