看流星社区

 找回密码
 注册账号
查看: 3795|回复: 0

C#写封包挂需要用到的一些函数

[复制链接]

该用户从未签到

发表于 2011-3-23 07:25:48 | 显示全部楼层 |阅读模式
主要是在处理参数时需要格式化成Hex格式,我自己写了2个函数

    private Byte[] GetBytes(Int32 length, params Int32[] args)
        {
            Byte[] data = new Byte[args.Length * length];
            String str = String.Empty;

            for (int i = 0; i < args.Length; i++)
            {
                Byte[] tempData = BitConverter.GetBytes(args);
                for (int j = 0; j < length; j++)
                {
                    data[i * length + j] = tempData[j];
                }
            }

            return data;
        }

        private Byte[] MergeBytes(params Byte[][] args)
        {
            Int32 length = 0;
            for (int i = 0; i < args.Length; i++)
            {
                Byte[] tempByte = args;
                length += tempByte.Length;
            }

            Byte[] bytes = new Byte[length];

            Int32 tempLength = 0;
            for (int i = 0; i < args.Length; i++)
            {
                Byte[] tempByte = args;
                tempByte.CopyTo(bytes, tempLength);
                tempLength += tempByte.Length;
            }

            return bytes;

        }


使用方式:

        public void SkillAttack(Int32 skillID, Int32 monsterID)
        {
            Byte[] headBytes = new Byte[] { 0x29, 0x00};
            Byte[] skillIDBytes = GetBytes(2, skillID);
            Byte[] fixBytes = new Byte[] { 0x00, 0x00, 0x00, 0x01 };
            Byte[] monsterIDBytes = GetBytes(4, monsterID);

            Byte[] data = MergeBytes(headBytes, skillIDBytes,fixBytes, monsterIDBytes);

            SendPackage(data);
        }
点击按钮快速添加回复内容: 支持 高兴 激动 给力 加油 苦寻 生气 回帖 路过 感恩
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

小黑屋|手机版|Archiver|看流星社区 |网站地图

GMT+8, 2024-4-20 00:57

Powered by Kanliuxing X3.4

© 2010-2019 kanliuxing.com

快速回复 返回顶部 返回列表