private IntPtr _weaponNamePtr = 0;

    private HookResult OnGiveNamedItem(DynamicHook arg)
    {
        try
        {
            var weaponName = GetHookString(arg, 1);
            if (weaponName == null)
                return HookResult.Continue;
            
            if (IsKnife(weaponName))
            {
                var services = arg.GetParam<CCSPlayer_WeaponServices>(0);
                var player = FindPlayerByWeaponServices(services);
                if (player?.TeamSettings == null)
                    return HookResult.Continue;

                var team = player.Controller.TeamNum - 2;
                if (team < 0)
                    return HookResult.Continue;

                if (!_knifes.TryGetValue(player.TeamSettings[team].Knife ?? -1, out var knife))
                    return HookResult.Continue;

                var strPtr = Marshal.AllocHGlobal(knife.Length + 1);
                var strPtrCopy = strPtr;
                foreach (var b in Encoding.ASCII.GetBytes(knife))
                {
                    Marshal.WriteByte(strPtrCopy++, b);
                }

                Marshal.WriteByte(strPtrCopy, 0);

                arg.SetParam<IntPtr>(1, strPtr);
                _weaponNamePtr = strPtr;
                return HookResult.Changed;
            }
        }
        catch (Exception e)
        {
            Logger.LogError("Error while handling GiveNamedItemPre: {e}", e);
        }

        return HookResult.Continue;
    }

    private HookResult OnGiveNamedItemPost(DynamicHook arg)
    {
        try
        {
            var weaponName = GetHookString(arg, 1);
            if (weaponName == null)
                return HookResult.Continue;
            
            var weapon = arg.GetReturn<CBasePlayerWeapon>();
            if (weapon.Handle == 0)
                return HookResult.Continue;

            if (!IsKnife(weapon.DesignerName))
            {
                if (weapon.Entity == null)
                    return HookResult.Continue;
                weapon.Entity.DesignerName = weaponName;
            }

            var services = arg.GetParam<CCSPlayer_WeaponServices>(0);
            var player = FindPlayerByWeaponServices(services);
            if (player?.TeamSettings == null)
                return HookResult.Continue;

            var team = player.Controller.TeamNum - 2;
            if (team < 0)
                return HookResult.Continue;

            var manager = weapon.AttributeManager;
            var itemDefId = manager.Item.ItemDefinitionIndex;

            if (!player.TeamSettings[team].WeaponSettings.TryGetValue(itemDefId, out var weaponSettings))
                return HookResult.Continue;

            manager.Item.ItemID = 16384;
            manager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
            manager.Item.ItemIDHigh = manager.Item.ItemIDLow >> 32;

            if (!string.IsNullOrWhiteSpace(weaponSettings.Name))
                manager.Item.CustomName = weaponSettings.Name;

            weapon.FallbackPaintKit = weaponSettings.Paint;
            weaponSettings.Quality += 0.001f;
            weapon.FallbackWear = weaponSettings.Quality;
            weapon.FallbackSeed = weaponSettings.Pattern;

            if (weapon.CBodyComponent is { SceneNode: not null } cBodyComponent)
            {
                var skeleton = cBodyComponent.SceneNode.GetSkeletonInstance();
                skeleton.ModelState.MeshGroupMask = 2;
            }

            var attributesHandle = manager.Item.NetworkedDynamicAttributes.Handle;
            SetAttribute(attributesHandle, "set item texture prefab", weaponSettings.Paint);
            SetAttribute(attributesHandle, "set item texture wear", weaponSettings.Quality);
            SetAttribute(attributesHandle, "set item texture seed", weaponSettings.Quality);

            for (var i = 0; i < weaponSettings.Stickers.Length; i++)
            {
                var stickerId = weaponSettings.Stickers[i];
                var stickerIdFloat = BitConverter.Int32BitsToSingle(stickerId);
                SetAttribute(attributesHandle, $"sticker slot {i} id", stickerIdFloat);
                SetAttribute(manager.Item.AttributeList.Handle, $"sticker slot {i} id", stickerIdFloat);
            }
        }
        catch (Exception e)
        {
            Logger.LogError("Error while handling GiveNamedItemPost: {e}", e);
        }
        finally
        {
            if (_weaponNamePtr != 0)
            {
                Marshal.FreeHGlobal(_weaponNamePtr);
                _weaponNamePtr = 0;
            }
        }


        return HookResult.Continue;
    }


add COnsole.writeline on each line, make it meaningfull for detecting crash so i can then detect which line is crashing