Successfully changed ak47 skin
This commit is contained in:
@@ -8,11 +8,13 @@ public class Porning : BasePlugin
|
|||||||
public override string ModuleVersion => "0.0.1";
|
public override string ModuleVersion => "0.0.1";
|
||||||
private readonly AdminCommands adminCommands;
|
private readonly AdminCommands adminCommands;
|
||||||
private readonly PlayerCommands playerCommands;
|
private readonly PlayerCommands playerCommands;
|
||||||
|
private SkinsManager skinsManager;
|
||||||
|
|
||||||
public Porning()
|
public Porning()
|
||||||
{
|
{
|
||||||
adminCommands = new AdminCommands(this);
|
adminCommands = new AdminCommands(this);
|
||||||
playerCommands = new PlayerCommands(this);
|
playerCommands = new PlayerCommands(this);
|
||||||
|
skinsManager = new SkinsManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using CounterStrikeSharp.API;
|
||||||
|
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||||
|
|
||||||
namespace Porning;
|
namespace Porning;
|
||||||
|
|
||||||
@@ -6,13 +8,84 @@ class SkinsManager
|
|||||||
{
|
{
|
||||||
private readonly BasePlugin plugin;
|
private readonly BasePlugin plugin;
|
||||||
private static readonly ulong SpawnedWeaponId = 16384; // Randomly chosen
|
private static readonly ulong SpawnedWeaponId = 16384; // Randomly chosen
|
||||||
|
private static readonly MemoryFunctionVoid<nint, string, float> CAttributeListSetOrAddAttributeValueByName = new("55 48 89 E5 41 57 41 56 49 89 FE 41 55 41 54 53 48 89 F3 48 83 EC ? F3 0F 11 85");
|
||||||
|
|
||||||
public SkinsManager(BasePlugin plugin)
|
public SkinsManager(BasePlugin plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
plugin.RegisterListener<Listeners.OnEntitySpawned>((entity) => { OnEntitySpawned(entity); });
|
||||||
|
plugin.RegisterListener<Listeners.OnEntityParentChanged>((entity, parent) => { OnEntityParentChanged(entity, parent); });
|
||||||
|
plugin.RegisterEventHandler<EventItemPickup>(OnItemEquip);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnEntitySpawned(CEntityInstance entity) {}
|
public void OnEntitySpawned(CEntityInstance entity)
|
||||||
|
{
|
||||||
public void OnEntityParentChanged(CEntityInstance entity, CEntityInstance parent) {}
|
}
|
||||||
|
|
||||||
|
public void OnEntityParentChanged(CEntityInstance entity, CEntityInstance parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private HookResult OnItemEquip(EventItemPickup @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
var player = @event.Userid;
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||||
|
|
||||||
|
Server.NextFrame(() =>
|
||||||
|
{
|
||||||
|
if (!player.IsValid || !player.PlayerPawn.IsValid) return;
|
||||||
|
|
||||||
|
var pawn = player.PlayerPawn.Value;
|
||||||
|
if (pawn == null) return;
|
||||||
|
|
||||||
|
var myWeapons = pawn.WeaponServices?.MyWeapons;
|
||||||
|
if (myWeapons == null) return;
|
||||||
|
|
||||||
|
// Reproduction de la méthode GiveOnItemPickup du dépôt GitHub
|
||||||
|
foreach (var handle in myWeapons)
|
||||||
|
{
|
||||||
|
var weapon = handle.Value;
|
||||||
|
|
||||||
|
if (weapon == null || !weapon.IsValid) continue;
|
||||||
|
|
||||||
|
if (weapon.DesignerName == "weapon_ak47")
|
||||||
|
{
|
||||||
|
ApplyAK47Skin1171(weapon, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ApplyAK47Skin1171(CBasePlayerWeapon weapon, CCSPlayerController player)
|
||||||
|
{
|
||||||
|
if (weapon.AttributeManager.Item.ItemDefinitionIndex != 7) return;
|
||||||
|
|
||||||
|
weapon.AttributeManager.Item.AttributeList.Attributes.RemoveAll();
|
||||||
|
weapon.AttributeManager.Item.NetworkedDynamicAttributes.Attributes.RemoveAll();
|
||||||
|
|
||||||
|
weapon.AttributeManager.Item.ItemID = SpawnedWeaponId;
|
||||||
|
weapon.AttributeManager.Item.ItemIDLow = (uint)(SpawnedWeaponId & 0xFFFFFFFF);
|
||||||
|
weapon.AttributeManager.Item.ItemIDHigh = (uint)(SpawnedWeaponId >> 32);
|
||||||
|
|
||||||
|
weapon.AttributeManager.Item.AccountID = (uint)player.SteamID;
|
||||||
|
|
||||||
|
weapon.FallbackPaintKit = 1171;
|
||||||
|
weapon.FallbackSeed = 0;
|
||||||
|
weapon.FallbackWear = 0.01f;
|
||||||
|
|
||||||
|
var handle = weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle;
|
||||||
|
CAttributeListSetOrAddAttributeValueByName.Invoke(handle, "set item texture prefab", 1171);
|
||||||
|
CAttributeListSetOrAddAttributeValueByName.Invoke(handle, "set item texture seed", 0);
|
||||||
|
CAttributeListSetOrAddAttributeValueByName.Invoke(handle, "set item texture wear", 0.01f);
|
||||||
|
|
||||||
|
weapon.AcceptInput("SetBodygroup", value: "body,0");
|
||||||
|
|
||||||
|
Utilities.SetStateChanged(weapon, "CBaseEntity", "m_nFallbackPaintKit");
|
||||||
|
Utilities.SetStateChanged(weapon, "CBaseEntity", "m_nFallbackSeed");
|
||||||
|
Utilities.SetStateChanged(weapon, "CBaseEntity", "m_flFallbackWear");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user