using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API; using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; namespace Porning; class SkinsManager { private readonly BasePlugin plugin; private static readonly ulong SpawnedWeaponId = 16384; // Randomly chosen private static readonly MemoryFunctionVoid 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) { this.plugin = plugin; plugin.RegisterListener((entity) => { OnEntitySpawned(entity); }); plugin.RegisterListener((entity, parent) => { OnEntityParentChanged(entity, parent); }); plugin.RegisterEventHandler(OnItemEquip); } public void OnEntitySpawned(CEntityInstance entity) { } 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"); } }