2024-06-28 18:08:25 +08:00
|
|
|
|
using AxibugEmuOnline.Client.ClientCore;
|
|
|
|
|
using AxibugEmuOnline.Client.Common;
|
|
|
|
|
using AxibugEmuOnline.Client.Network;
|
|
|
|
|
using AxibugProtobuf;
|
|
|
|
|
using Google.Protobuf;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace AxibugEmuOnline.Client.Manager
|
|
|
|
|
{
|
2024-07-03 14:43:11 +08:00
|
|
|
|
public class AppNetGame
|
2024-06-28 18:08:25 +08:00
|
|
|
|
{
|
2024-07-04 17:39:47 +08:00
|
|
|
|
int CurrRoomID;
|
|
|
|
|
int[] _palette;
|
|
|
|
|
public int[] _renderbuffer { private set; get; }
|
2024-07-03 14:43:11 +08:00
|
|
|
|
public AppNetGame()
|
2024-06-28 18:08:25 +08:00
|
|
|
|
{
|
|
|
|
|
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdScreen, OnScreen);
|
|
|
|
|
}
|
2024-07-04 17:39:47 +08:00
|
|
|
|
|
2024-06-28 18:08:25 +08:00
|
|
|
|
Protobuf_Screnn_Frame _Protobuf_Screnn_Frame = new Protobuf_Screnn_Frame();
|
|
|
|
|
|
2024-07-04 17:39:47 +08:00
|
|
|
|
public void SendScreen(byte[] RenderBuffer)
|
2024-06-28 18:08:25 +08:00
|
|
|
|
{
|
2024-07-04 17:39:47 +08:00
|
|
|
|
byte[] comData = CompressByteArray(RenderBuffer);
|
2024-06-28 18:08:25 +08:00
|
|
|
|
_Protobuf_Screnn_Frame.FrameID = 0;
|
|
|
|
|
_Protobuf_Screnn_Frame.RawBitmap = ByteString.CopyFrom(comData);
|
|
|
|
|
AppAxibugEmuOnline.networkHelper.SendToServer((int)CommandID.CmdScreen, ProtoBufHelper.Serizlize(_Protobuf_Screnn_Frame));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnScreen(byte[] reqData)
|
|
|
|
|
{
|
|
|
|
|
Protobuf_Screnn_Frame msg = ProtoBufHelper.DeSerizlize<Protobuf_Screnn_Frame>(reqData);
|
2024-07-04 17:39:47 +08:00
|
|
|
|
lock (_renderbuffer)
|
|
|
|
|
{
|
|
|
|
|
byte[] data = DecompressByteArray(msg.RawBitmap.ToArray());
|
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
_renderbuffer[i] = _palette[data[i]];
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-28 18:08:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static byte[] CompressByteArray(byte[] bytesToCompress)
|
|
|
|
|
{
|
|
|
|
|
using (var compressedMemoryStream = new MemoryStream())
|
|
|
|
|
using (var gzipStream = new GZipStream(compressedMemoryStream, CompressionMode.Compress))
|
|
|
|
|
{
|
|
|
|
|
gzipStream.Write(bytesToCompress, 0, bytesToCompress.Length);
|
|
|
|
|
gzipStream.Close();
|
|
|
|
|
return compressedMemoryStream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static byte[] DecompressByteArray(byte[] compressedBytes)
|
|
|
|
|
{
|
|
|
|
|
using (var compressedMemoryStream = new MemoryStream(compressedBytes))
|
|
|
|
|
using (var gzipStream = new GZipStream(compressedMemoryStream, CompressionMode.Decompress))
|
|
|
|
|
using (var resultMemoryStream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
gzipStream.CopyTo(resultMemoryStream);
|
|
|
|
|
return resultMemoryStream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|