【发布时间】:2020-08-20 02:02:23
【问题描述】:
使用NetworkInfo2SecurityParameter 函数,我试图将固定大小的缓冲区unkRandom 从LdnNetworkInfo 结构中的NetworkInfo 结构复制到SecurityParameter 结构的缓冲区。
基本上我正在制作一种转换这两种类型的方法,并且我想将这两个数组复制到另一个数组。此代码具有所有相关的结构。
Buffer.MemoryCopy() 函数发生错误。错误是“您不能使用包含在未固定表达式中的固定大小缓冲区。尝试使用 'fixed' 语句”
unsafe void NetworkInfo2SecurityParameter(NetworkInfo info, out SecurityParameter output)
{
output = new SecurityParameter();
output.sessionId = info.networkId.sessionId;
Buffer.MemoryCopy(output.unkRandom, info.ldn.unkRandom, 16, 16);
}
struct SecurityParameter {
public unsafe fixed byte unkRandom[16];// = new byte[16];
public SessionId sessionId;
};
struct NetworkInfo : /sf::/LargeData {
public NetworkId networkId;
public CommonNetworkInfo common;
public LdnNetworkInfo ldn;
};
struct LdnNetworkInfo {
public unsafe fixed byte unkRandom[16];// = new byte[16];
public ushort securityMode;
public byte stationAcceptPolicy;
public unsafe fixed byte _unk1[3];// = new byte[3];
public byte nodeCountMax;
public byte nodeCount;
//TODO non primitive array,,
private unsafe fixed byte _nodes[sizeof(NodeInfo)*NodeCountMax]; //Needs to be fixed array, and needs to be casted to NodeInfo span, so thats why its size is this
public unsafe fixed Span<NodeInfo> nodes => MemoryMarshal.Cast<byte, NodeInfo>(MemoryMarshal.CreateSpan(ref _nodes[0], 128));
public ushort _unk2;
public ushort advertiseDataSize;
public unsafe fixed byte advertiseData[AdvertiseDataSizeMax];// = new byte[AdvertiseDataSizeMax];
public unsafe fixed byte _unk3[148];// = new byte[148];
};
【问题讨论】:
-
错误是什么?
-
您不能使用包含在未固定表达式中的固定大小的缓冲区。尝试使用“固定”语句
-
嗯,显而易见的问题是,您是否尝试过使用
fixed语句? -
如果数组只有 16 个字节,你能把一个指向数组的指针转换成一个 int64 指针,然后复制成两个 64 位的块吗?
-
@HereticMonkey 在哪里?