- 注册时间
- 2011-3-6
- 最后登录
- 1970-1-1
该用户从未签到
|
主要是在处理参数时需要格式化成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);
} |
|