Files
hjha-server/ServerCore/Core/ByteHelper.cs
xiaoou e9616125ce feat: initial commit - HJHA game server full source
6 major server modules (PdkFriendServer/GlobalSever/ServerCore/GameModule/GameNetModule) +
game logic (GameFix/GameDAL/ServerData) +
network layer (NetWorkMessage) +
data layer (ObjectModel) +
utilities (MrWu/Core/Config/CloudAPI/dll) +
adapters (zyxAdapter/base)

.NET 8.0 C# solution, 16 projects, 958 source files
2026-07-07 12:02:15 +08:00

71 lines
2.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Diagnostics;
using System.IO;
using System.Text;
using ActorCore;
namespace Server.Core
{
public static class ByteHelper
{
public static ActorId ReadActorId(this byte[] bytes, int offset)
{
return new ActorId(bytes[offset], bytes[offset + 1], bytes[offset + 2]);
}
public static void WriteTo(this byte[] bytes, int offset, ActorId actorId)
{
bytes[offset] = actorId.ModuleId;
bytes[offset + 1] = actorId.NodeNum;
bytes[offset + 2] = actorId.ActorTypeId;
}
public static void WriteTo(this byte[] bytes, int offset, short num)
{
bytes[offset] = (byte)(num & 0xff);
bytes[offset + 1] = (byte)((num & 0xff00) >> 8);
}
public static void WriteTo(this byte[] bytes, int offset, ushort num)
{
bytes[offset] = (byte)(num & 0xff);
bytes[offset + 1] = (byte)((num & 0xff00) >> 8);
}
public static unsafe void WriteTo(this byte[] bytes, int offset, long num)
{
byte* bPoint = (byte*)#
for (int i = 0; i < sizeof(long); ++i)
{
bytes[offset + i] = bPoint[i];
}
}
public static void WriteTo(this byte[] bytes, int offset, int num)
{
//跟这个意思是一样的把num解析为byte 拷贝到bytes中
//BitConverter.GetBytes(num);
bytes[offset] = (byte)(num & 0xff);
bytes[offset + 1] = (byte)((num & 0xff00) >> 8);
bytes[offset + 2] = (byte)((num & 0xff0000) >> 16);
bytes[offset + 3] = (byte)((num & 0xff000000) >> 24);
}
public static void WriteTo(this byte[] bytes, int offset, uint num)
{
bytes[offset] = (byte)(num & 0xff);
bytes[offset + 1] = (byte)((num & 0xff00) >> 8);
bytes[offset + 2] = (byte)((num & 0xff0000) >> 16);
bytes[offset + 3] = (byte)((num & 0xff000000) >> 24);
}
public static void WriteInt(this MemoryStream memoryStream, int num)
{
memoryStream.WriteByte((byte)(num & 0xff));
memoryStream.WriteByte( (byte)((num & 0xff00) >> 8));
memoryStream.WriteByte((byte)((num & 0xff0000) >> 16));
memoryStream.WriteByte((byte)((num & 0xff000000) >> 24));
}
}
}