1

我正在尝试从我不久前编写的 C++ 程序中重写我的一些代码,但我不确定是否/如何正确写入字节数组,或者我是否应该使用其他东西。我试图更改为 C# .NET 的代码如下。

unsigned char pData[1400];
bf_write g_ReplyInfo("SVC_ReplyInfo", &pData, 1400);

void PlayerManager::BuildReplyInfo()
{   
    // Delete the old packet
    g_ReplyInfo.Reset();

    g_ReplyInfo.WriteLong(-1);
    g_ReplyInfo.WriteByte(73);
    g_ReplyInfo.WriteByte(g_ProtocolVersion.GetInt());
    g_ReplyInfo.WriteString(iserver->GetName());
    g_ReplyInfo.WriteString(iserver->GetMapName());
}
4

1 回答 1

0

BinaryWriter可能会起作用,尽管字符串是用前面的 7 位编码长度编写的,我怀疑客户端将无法处理。您可能必须将字符串转换为字节,然后添加一个长度字或 0 终止它。

无需手动将数字转换为字节。如果你有一个long你想写成的 a byte,只需转换它。也就是说,如果你的BinaryWriteris bw,那么你可以写bw.Write((byte)longval);。写-1为长:bw.Write((long)(-1))

于 2011-03-12T07:11:29.817 回答