2021-07-07 13:36:25 +02:00
|
|
|
|
using System;
|
2022-04-02 18:11:30 +02:00
|
|
|
|
using System.Linq;
|
2021-08-21 16:52:17 +02:00
|
|
|
|
using System.Collections.Generic;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-27 10:15:52 +01:00
|
|
|
|
using CoopClient.Entities.Player;
|
|
|
|
|
using CoopClient.Entities.NPC;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
using Lidgren.Network;
|
|
|
|
|
|
|
|
|
|
using GTA;
|
|
|
|
|
using GTA.Native;
|
|
|
|
|
|
|
|
|
|
namespace CoopClient
|
|
|
|
|
{
|
2022-03-28 15:08:30 +02:00
|
|
|
|
internal class Networking
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-03-28 15:08:30 +02:00
|
|
|
|
public NetClient Client;
|
|
|
|
|
public float Latency = 0;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2022-03-28 15:08:30 +02:00
|
|
|
|
public bool ShowNetworkInfo = false;
|
2021-08-18 11:47:59 +02:00
|
|
|
|
|
2022-03-28 15:08:30 +02:00
|
|
|
|
public int BytesReceived = 0;
|
|
|
|
|
public int BytesSend = 0;
|
2021-08-18 11:47:59 +02:00
|
|
|
|
|
2022-03-28 15:08:30 +02:00
|
|
|
|
public void DisConnectFromServer(string address)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
if (IsOnServer())
|
|
|
|
|
{
|
2021-07-07 18:05:08 +02:00
|
|
|
|
Client.Disconnect("Bye!");
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-04-06 02:18:24 +02:00
|
|
|
|
// 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP
|
|
|
|
|
NetPeerConfiguration config = new NetPeerConfiguration("623c92c287cc392406e7aaaac1c0f3b0")
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
AutoFlushSendQueue = false
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-16 12:31:49 +02:00
|
|
|
|
config.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated);
|
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
Client = new NetClient(config);
|
|
|
|
|
|
|
|
|
|
Client.Start();
|
|
|
|
|
|
2021-12-07 08:18:29 +01:00
|
|
|
|
string[] ip = new string[2];
|
|
|
|
|
|
|
|
|
|
int idx = address.LastIndexOf(':');
|
|
|
|
|
if (idx != -1)
|
|
|
|
|
{
|
|
|
|
|
ip[0] = address.Substring(0, idx);
|
|
|
|
|
ip[1] = address.Substring(idx + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ip.Length != 2)
|
2021-11-19 17:05:57 -07:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Malformed URL");
|
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
// Send HandshakePacket
|
|
|
|
|
NetOutgoingMessage outgoingMessage = Client.CreateMessage();
|
2022-01-01 03:07:18 +01:00
|
|
|
|
new Packets.Handshake()
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-14 22:39:15 +01:00
|
|
|
|
NetHandle = 0,
|
2021-07-07 13:36:25 +02:00
|
|
|
|
Username = Main.MainSettings.Username,
|
2021-09-28 16:51:16 +02:00
|
|
|
|
ModVersion = Main.CurrentVersion,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
NPCsAllowed = false
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}.PacketToNetOutGoingMessage(outgoingMessage);
|
|
|
|
|
|
|
|
|
|
Client.Connect(ip[0], short.Parse(ip[1]), outgoingMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 15:08:30 +02:00
|
|
|
|
public bool IsOnServer()
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
return Client?.ConnectionStatus == NetConnectionStatus.Connected;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 15:08:30 +02:00
|
|
|
|
public void ReceiveMessages()
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
if (Client == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetIncomingMessage message;
|
|
|
|
|
|
|
|
|
|
while ((message = Client.ReadMessage()) != null)
|
|
|
|
|
{
|
2021-08-18 11:47:59 +02:00
|
|
|
|
BytesReceived += message.LengthBytes;
|
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
switch (message.MessageType)
|
|
|
|
|
{
|
|
|
|
|
case NetIncomingMessageType.StatusChanged:
|
|
|
|
|
NetConnectionStatus status = (NetConnectionStatus)message.ReadByte();
|
|
|
|
|
|
|
|
|
|
string reason = message.ReadString();
|
|
|
|
|
|
|
|
|
|
switch (status)
|
|
|
|
|
{
|
|
|
|
|
case NetConnectionStatus.InitiatedConnect:
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#if !NON_INTERACTIVE
|
|
|
|
|
Main.MainMenu.InitiateConnectionMenuSetting();
|
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
GTA.UI.Notification.Show("~y~Trying to connect...");
|
|
|
|
|
break;
|
|
|
|
|
case NetConnectionStatus.Connected:
|
2022-01-01 03:07:18 +01:00
|
|
|
|
if (message.SenderConnection.RemoteHailMessage.ReadByte() != (byte)PacketTypes.Handshake)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
Client.Disconnect("Wrong packet!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
int len = message.SenderConnection.RemoteHailMessage.ReadInt32();
|
|
|
|
|
byte[] data = message.SenderConnection.RemoteHailMessage.ReadBytes(len);
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.Handshake handshakePacket = new Packets.Handshake();
|
2021-12-23 22:03:01 +01:00
|
|
|
|
handshakePacket.NetIncomingMessageToPacket(data);
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-14 22:39:15 +01:00
|
|
|
|
Main.LocalNetHandle = handshakePacket.NetHandle;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Main.NPCsAllowed = handshakePacket.NPCsAllowed;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
Main.MainChat.Init();
|
2022-03-28 14:49:26 +02:00
|
|
|
|
Main.MainPlayerList = new PlayerList();
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#if !NON_INTERACTIVE
|
|
|
|
|
Main.MainMenu.ConnectedMenuSetting();
|
|
|
|
|
#endif
|
2021-09-27 22:40:18 +02:00
|
|
|
|
|
2021-11-27 22:44:00 +01:00
|
|
|
|
COOPAPI.Connected();
|
2021-09-27 22:40:18 +02:00
|
|
|
|
GTA.UI.Notification.Show("~g~Connected!");
|
2022-03-25 21:51:29 +01:00
|
|
|
|
|
|
|
|
|
JavascriptHook.LoadAll();
|
2022-03-29 00:28:57 +02:00
|
|
|
|
Logger.Write(">> Connected <<", Logger.LogLevel.Server);
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NetConnectionStatus.Disconnected:
|
2022-04-06 05:10:29 +02:00
|
|
|
|
DownloadManager.Cleanup();
|
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
// Reset all values
|
2021-12-24 15:33:27 +01:00
|
|
|
|
Latency = 0;
|
2021-08-16 12:31:49 +02:00
|
|
|
|
LastPlayerFullSync = 0;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-26 03:25:00 +01:00
|
|
|
|
Main.CleanUpWorld();
|
|
|
|
|
|
2021-12-14 22:39:15 +01:00
|
|
|
|
Main.NPCsAllowed = false;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
if (Main.MainChat.Focused)
|
|
|
|
|
{
|
|
|
|
|
Main.MainChat.Focused = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 14:49:26 +02:00
|
|
|
|
Main.MainPlayerList = null;
|
2021-08-06 12:31:25 +02:00
|
|
|
|
Main.CleanUp();
|
2021-11-28 22:57:39 +01:00
|
|
|
|
|
2021-09-26 20:52:23 -06:00
|
|
|
|
#if !NON_INTERACTIVE
|
|
|
|
|
Main.MainMenu.DisconnectedMenuSetting();
|
|
|
|
|
#endif
|
2021-09-27 22:40:18 +02:00
|
|
|
|
|
2021-11-27 22:44:00 +01:00
|
|
|
|
COOPAPI.Disconnected(reason);
|
2021-09-27 22:40:18 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~Disconnected: " + reason);
|
2022-03-25 21:51:29 +01:00
|
|
|
|
|
|
|
|
|
JavascriptHook.StopAll();
|
2022-03-29 00:28:57 +02:00
|
|
|
|
|
|
|
|
|
Logger.Write($">> Disconnected << reason: {reason}", Logger.LogLevel.Server);
|
2021-07-07 13:36:25 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NetIncomingMessageType.Data:
|
|
|
|
|
byte packetType = message.ReadByte();
|
|
|
|
|
|
|
|
|
|
switch (packetType)
|
|
|
|
|
{
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.CleanUpWorld:
|
2021-12-26 03:25:00 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Main.CleanUpWorld();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-26 03:25:00 +01:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.PlayerConnect:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.PlayerConnect packet = new Packets.PlayerConnect();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
PlayerConnect(packet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.PlayerDisconnect:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.PlayerDisconnect packet = new Packets.PlayerDisconnect();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
PlayerDisconnect(packet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.FullSyncPlayer:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.FullSyncPlayer packet = new Packets.FullSyncPlayer();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
FullSyncPlayer(packet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.FullSyncPlayerVeh:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.FullSyncPlayerVeh packet = new Packets.FullSyncPlayerVeh();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
FullSyncPlayerVeh(packet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.LightSyncPlayer:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.LightSyncPlayer packet = new Packets.LightSyncPlayer();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
LightSyncPlayer(packet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.LightSyncPlayerVeh:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.LightSyncPlayerVeh packet = new Packets.LightSyncPlayerVeh();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
LightSyncPlayerVeh(packet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.SuperLightSync:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.SuperLightSync packet = new Packets.SuperLightSync();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
if (Main.Players.ContainsKey(packet.NetHandle))
|
|
|
|
|
{
|
|
|
|
|
EntitiesPlayer player = Main.Players[packet.NetHandle];
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
player.Position = packet.Position.ToVector();
|
|
|
|
|
player.Latency = packet.Latency.HasValue ? packet.Latency.Value : 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-12 05:00:48 +02:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.FullSyncNpc:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.FullSyncNpc packet = new Packets.FullSyncNpc();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
FullSyncNpc(packet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
2021-07-12 05:00:48 +02:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.FullSyncNpcVeh:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.FullSyncNpcVeh packet = new Packets.FullSyncNpcVeh();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
FullSyncNpcVeh(packet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
2021-08-26 17:01:32 +02:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.ChatMessage:
|
2021-09-27 20:28:27 +02:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.ChatMessage packet = new Packets.ChatMessage();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
if (!COOPAPI.ChatMessageReceived(packet.Username, packet.Message))
|
|
|
|
|
{
|
|
|
|
|
Main.MainChat.AddMessage(packet.Username, packet.Message);
|
|
|
|
|
}
|
2022-03-26 17:50:34 +01:00
|
|
|
|
|
|
|
|
|
JavascriptHook.InvokeChatMessage(packet.Username, packet.Message);
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
2021-09-27 20:28:27 +02:00
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.NativeCall:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.NativeCall packet = new Packets.NativeCall();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 02:27:30 +01:00
|
|
|
|
DecodeNativeCall(packet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
2021-08-20 17:28:13 +02:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.NativeResponse:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.NativeResponse packet = new Packets.NativeResponse();
|
2021-12-23 22:03:01 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
|
|
|
|
|
|
|
|
|
DecodeNativeResponse(packet);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-10 13:38:03 +01:00
|
|
|
|
break;
|
2022-01-01 03:07:18 +01:00
|
|
|
|
case (byte)PacketTypes.Mod:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
{
|
2022-01-01 02:27:30 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Packets.Mod packet = new Packets.Mod();
|
2022-01-01 02:27:30 +01:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
2022-01-01 03:07:18 +01:00
|
|
|
|
COOPAPI.ModPacketReceived(packet.NetHandle, packet.Name, packet.CustomPacketID, packet.Bytes);
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-03-29 00:28:57 +02:00
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
2022-01-01 02:27:30 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
}
|
2021-09-29 14:34:22 +02:00
|
|
|
|
break;
|
2022-04-02 18:11:30 +02:00
|
|
|
|
case (byte)PacketTypes.FileTransferRequest:
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
2022-04-03 19:28:25 +02:00
|
|
|
|
Packets.FileTransferRequest packet = new Packets.FileTransferRequest();
|
2022-04-02 18:11:30 +02:00
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
|
|
|
|
|
2022-04-06 05:10:29 +02:00
|
|
|
|
DownloadManager.AddFile(packet.ID, (Packets.DataFileType)packet.FileType, packet.FileName, packet.FileLength);
|
2022-04-02 18:11:30 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case (byte)PacketTypes.FileTransferTick:
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int len = message.ReadInt32();
|
|
|
|
|
byte[] data = message.ReadBytes(len);
|
|
|
|
|
Packets.FileTransferTick packet = new Packets.FileTransferTick();
|
|
|
|
|
packet.NetIncomingMessageToPacket(data);
|
|
|
|
|
|
2022-04-06 05:10:29 +02:00
|
|
|
|
DownloadManager.Write(packet.ID, packet.FileChunk);
|
2022-04-02 18:11:30 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
2022-04-06 05:10:29 +02:00
|
|
|
|
Logger.Write($"[{packetType}] {ex.Source}", Logger.LogLevel.Server);
|
|
|
|
|
Logger.Write($"[{packetType}] {ex.StackTrace}", Logger.LogLevel.Server);
|
2022-04-02 18:11:30 +02:00
|
|
|
|
Client.Disconnect($"Packet Error [{packetType}]");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
2021-08-16 12:31:49 +02:00
|
|
|
|
case NetIncomingMessageType.ConnectionLatencyUpdated:
|
|
|
|
|
Latency = message.ReadFloat();
|
|
|
|
|
break;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
case NetIncomingMessageType.DebugMessage:
|
|
|
|
|
case NetIncomingMessageType.ErrorMessage:
|
|
|
|
|
case NetIncomingMessageType.WarningMessage:
|
|
|
|
|
case NetIncomingMessageType.VerboseDebugMessage:
|
2021-11-28 22:57:39 +01:00
|
|
|
|
#if DEBUG
|
|
|
|
|
// TODO?
|
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Client.Recycle(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#region -- GET --
|
|
|
|
|
#region -- PLAYER --
|
2022-01-01 03:07:18 +01:00
|
|
|
|
private void PlayerConnect(Packets.PlayerConnect packet)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-17 23:58:32 +01:00
|
|
|
|
EntitiesPlayer player = new EntitiesPlayer() { Username = packet.Username };
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-14 22:39:15 +01:00
|
|
|
|
Main.Players.Add(packet.NetHandle, player);
|
|
|
|
|
COOPAPI.Connected(packet.NetHandle);
|
2022-03-26 17:50:34 +01:00
|
|
|
|
JavascriptHook.InvokePlayerConnect(packet.Username, packet.NetHandle);
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
private void PlayerDisconnect(Packets.PlayerDisconnect packet)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-14 22:39:15 +01:00
|
|
|
|
if (Main.Players.ContainsKey(packet.NetHandle))
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-14 22:39:15 +01:00
|
|
|
|
EntitiesPlayer player = Main.Players[packet.NetHandle];
|
2021-07-08 21:57:21 +02:00
|
|
|
|
if (player.Character != null && player.Character.Exists())
|
|
|
|
|
{
|
|
|
|
|
player.Character.Kill();
|
|
|
|
|
player.Character.Delete();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 00:20:09 +02:00
|
|
|
|
player.PedBlip?.Delete();
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-14 22:39:15 +01:00
|
|
|
|
COOPAPI.Disconnected(packet.NetHandle);
|
2022-03-26 17:50:34 +01:00
|
|
|
|
JavascriptHook.InvokePlayerDisonnect(player.Username, packet.NetHandle);
|
2021-12-14 22:39:15 +01:00
|
|
|
|
Main.Players.Remove(packet.NetHandle);
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
private void FullSyncPlayer(Packets.FullSyncPlayer packet)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
if (Main.Players.ContainsKey(packet.NetHandle))
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
EntitiesPlayer player = Main.Players[packet.NetHandle];
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
player.ModelHash = packet.ModelHash;
|
2021-12-16 22:05:40 +01:00
|
|
|
|
player.Clothes = packet.Clothes;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.Health = packet.Health;
|
|
|
|
|
player.Position = packet.Position.ToVector();
|
2021-07-07 13:36:25 +02:00
|
|
|
|
player.Rotation = packet.Rotation.ToVector();
|
|
|
|
|
player.Velocity = packet.Velocity.ToVector();
|
|
|
|
|
player.Speed = packet.Speed;
|
2021-07-08 21:57:21 +02:00
|
|
|
|
player.CurrentWeaponHash = packet.CurrentWeaponHash;
|
2021-12-15 01:25:16 +01:00
|
|
|
|
player.WeaponComponents = packet.WeaponComponents;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
player.AimCoords = packet.AimCoords.ToVector();
|
2021-12-28 19:14:51 +01:00
|
|
|
|
player.IsAiming = (packet.Flag.Value & (ushort)PedDataFlags.IsAiming) > 0;
|
|
|
|
|
player.IsShooting = (packet.Flag.Value & (ushort)PedDataFlags.IsShooting) > 0;
|
|
|
|
|
player.IsReloading = (packet.Flag.Value & (ushort)PedDataFlags.IsReloading) > 0;
|
|
|
|
|
player.IsJumping = (packet.Flag.Value & (ushort)PedDataFlags.IsJumping) > 0;
|
|
|
|
|
player.IsRagdoll = (packet.Flag.Value & (ushort)PedDataFlags.IsRagdoll) > 0;
|
|
|
|
|
player.IsOnFire = (packet.Flag.Value & (ushort)PedDataFlags.IsOnFire) > 0;
|
|
|
|
|
player.IsInParachuteFreeFall = (packet.Flag.Value & (ushort)PedDataFlags.IsInParachuteFreeFall) > 0;
|
2022-01-01 04:16:24 +01:00
|
|
|
|
player.IsParachuteOpen = (packet.Flag.Value & (ushort)PedDataFlags.IsParachuteOpen) > 0;
|
2021-12-28 19:14:51 +01:00
|
|
|
|
player.IsOnLadder = (packet.Flag.Value & (ushort)PedDataFlags.IsOnLadder) > 0;
|
|
|
|
|
player.IsVaulting = (packet.Flag.Value & (ushort)PedDataFlags.IsVaulting) > 0;
|
2021-11-19 09:24:06 +01:00
|
|
|
|
player.IsInVehicle = false;
|
2021-12-14 19:33:52 +01:00
|
|
|
|
player.LastSyncWasFull = true;
|
2021-08-26 17:01:32 +02:00
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.Latency = packet.Latency.Value;
|
2021-11-19 22:08:15 +01:00
|
|
|
|
player.LastUpdateReceived = Util.GetTickCount64();
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
private void FullSyncPlayerVeh(Packets.FullSyncPlayerVeh packet)
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
if (Main.Players.ContainsKey(packet.NetHandle))
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
EntitiesPlayer player = Main.Players[packet.NetHandle];
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2021-07-12 05:00:48 +02:00
|
|
|
|
player.ModelHash = packet.ModelHash;
|
2021-12-16 22:05:40 +01:00
|
|
|
|
player.Clothes = packet.Clothes;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.Health = packet.Health;
|
2021-07-12 05:00:48 +02:00
|
|
|
|
player.VehicleModelHash = packet.VehModelHash;
|
|
|
|
|
player.VehicleSeatIndex = packet.VehSeatIndex;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.Position = packet.Position.ToVector();
|
2021-07-12 05:00:48 +02:00
|
|
|
|
player.VehicleRotation = packet.VehRotation.ToQuaternion();
|
2021-08-16 16:51:33 +02:00
|
|
|
|
player.VehicleEngineHealth = packet.VehEngineHealth;
|
2021-11-19 08:45:20 +01:00
|
|
|
|
player.VehRPM = packet.VehRPM;
|
2022-03-20 09:21:41 +01:00
|
|
|
|
player.Velocity = packet.VehVelocity.ToVector();
|
2021-07-12 05:00:48 +02:00
|
|
|
|
player.VehicleSpeed = packet.VehSpeed;
|
2021-07-13 16:30:33 +02:00
|
|
|
|
player.VehicleSteeringAngle = packet.VehSteeringAngle;
|
2021-12-06 00:56:08 +01:00
|
|
|
|
player.AimCoords = packet.VehAimCoords.ToVector();
|
2021-08-13 15:52:30 +02:00
|
|
|
|
player.VehicleColors = packet.VehColors;
|
2021-08-22 13:59:15 +02:00
|
|
|
|
player.VehicleMods = packet.VehMods;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.VehDamageModel = packet.VehDamageModel;
|
2021-12-14 14:46:10 +01:00
|
|
|
|
player.VehLandingGear = packet.VehLandingGear;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.VehIsEngineRunning = (packet.Flag.Value & (ushort)VehicleDataFlags.IsEngineRunning) > 0;
|
|
|
|
|
player.VehAreLightsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreLightsOn) > 0;
|
2022-01-01 19:24:57 +01:00
|
|
|
|
player.VehAreBrakeLightsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreBrakeLightsOn) > 0;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.VehAreHighBeamsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreHighBeamsOn) > 0;
|
|
|
|
|
player.VehIsSireneActive = (packet.Flag.Value & (ushort)VehicleDataFlags.IsSirenActive) > 0;
|
|
|
|
|
player.VehicleDead = (packet.Flag.Value & (ushort)VehicleDataFlags.IsDead) > 0;
|
|
|
|
|
player.IsHornActive = (packet.Flag.Value & (ushort)VehicleDataFlags.IsHornActive) > 0;
|
|
|
|
|
player.Transformed = (packet.Flag.Value & (ushort)VehicleDataFlags.IsTransformed) > 0;
|
|
|
|
|
player.VehRoofOpened = (packet.Flag.Value & (ushort)VehicleDataFlags.RoofOpened) > 0;
|
2021-12-13 23:18:15 +01:00
|
|
|
|
player.IsInVehicle = true;
|
2021-12-14 19:33:52 +01:00
|
|
|
|
player.LastSyncWasFull = true;
|
2021-08-26 17:01:32 +02:00
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.Latency = packet.Latency.Value;
|
2021-11-19 22:08:15 +01:00
|
|
|
|
player.LastUpdateReceived = Util.GetTickCount64();
|
2021-07-12 05:00:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
private void LightSyncPlayer(Packets.LightSyncPlayer packet)
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
if (Main.Players.ContainsKey(packet.NetHandle))
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
EntitiesPlayer player = Main.Players[packet.NetHandle];
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.Health = packet.Health;
|
|
|
|
|
player.Position = packet.Position.ToVector();
|
2021-07-12 05:00:48 +02:00
|
|
|
|
player.Rotation = packet.Rotation.ToVector();
|
|
|
|
|
player.Velocity = packet.Velocity.ToVector();
|
|
|
|
|
player.Speed = packet.Speed;
|
|
|
|
|
player.CurrentWeaponHash = packet.CurrentWeaponHash;
|
|
|
|
|
player.AimCoords = packet.AimCoords.ToVector();
|
2021-12-28 19:14:51 +01:00
|
|
|
|
player.IsAiming = (packet.Flag.Value & (ushort)PedDataFlags.IsAiming) > 0;
|
|
|
|
|
player.IsShooting = (packet.Flag.Value & (ushort)PedDataFlags.IsShooting) > 0;
|
|
|
|
|
player.IsReloading = (packet.Flag.Value & (ushort)PedDataFlags.IsReloading) > 0;
|
|
|
|
|
player.IsJumping = (packet.Flag.Value & (ushort)PedDataFlags.IsJumping) > 0;
|
|
|
|
|
player.IsRagdoll = (packet.Flag.Value & (ushort)PedDataFlags.IsRagdoll) > 0;
|
|
|
|
|
player.IsOnFire = (packet.Flag.Value & (ushort)PedDataFlags.IsOnFire) > 0;
|
|
|
|
|
player.IsInParachuteFreeFall = (packet.Flag.Value & (ushort)PedDataFlags.IsInParachuteFreeFall) > 0;
|
2022-01-01 04:16:24 +01:00
|
|
|
|
player.IsParachuteOpen = (packet.Flag.Value & (ushort)PedDataFlags.IsParachuteOpen) > 0;
|
2021-12-28 19:14:51 +01:00
|
|
|
|
player.IsOnLadder = (packet.Flag.Value & (ushort)PedDataFlags.IsOnLadder) > 0;
|
|
|
|
|
player.IsVaulting = (packet.Flag.Value & (ushort)PedDataFlags.IsVaulting) > 0;
|
2021-11-19 09:24:06 +01:00
|
|
|
|
player.IsInVehicle = false;
|
2021-12-13 23:18:15 +01:00
|
|
|
|
player.LastSyncWasFull = false;
|
2021-08-26 17:01:32 +02:00
|
|
|
|
|
2021-12-24 15:33:27 +01:00
|
|
|
|
player.Latency = packet.Latency.Value;
|
2021-11-19 22:08:15 +01:00
|
|
|
|
player.LastUpdateReceived = Util.GetTickCount64();
|
2021-07-12 05:00:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
private void LightSyncPlayerVeh(Packets.LightSyncPlayerVeh packet)
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
if (Main.Players.ContainsKey(packet.NetHandle))
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
EntitiesPlayer player = Main.Players[packet.NetHandle];
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.Health = packet.Health;
|
2021-07-12 05:00:48 +02:00
|
|
|
|
player.VehicleModelHash = packet.VehModelHash;
|
|
|
|
|
player.VehicleSeatIndex = packet.VehSeatIndex;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.Position = packet.Position.ToVector();
|
2021-07-12 05:00:48 +02:00
|
|
|
|
player.VehicleRotation = packet.VehRotation.ToQuaternion();
|
2022-03-20 09:21:41 +01:00
|
|
|
|
player.Velocity = packet.VehVelocity.ToVector();
|
2021-07-12 05:00:48 +02:00
|
|
|
|
player.VehicleSpeed = packet.VehSpeed;
|
2021-07-13 16:30:33 +02:00
|
|
|
|
player.VehicleSteeringAngle = packet.VehSteeringAngle;
|
2021-12-24 05:20:32 +01:00
|
|
|
|
player.AimCoords = packet.AimCoords.ToVector();
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.VehIsEngineRunning = (packet.Flag.Value & (ushort)VehicleDataFlags.IsEngineRunning) > 0;
|
|
|
|
|
player.VehAreLightsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreLightsOn) > 0;
|
2022-01-01 19:24:57 +01:00
|
|
|
|
player.VehAreBrakeLightsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreBrakeLightsOn) > 0;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.VehAreHighBeamsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreHighBeamsOn) > 0;
|
|
|
|
|
player.VehIsSireneActive = (packet.Flag.Value & (ushort)VehicleDataFlags.IsSirenActive) > 0;
|
|
|
|
|
player.VehicleDead = (packet.Flag.Value & (ushort)VehicleDataFlags.IsDead) > 0;
|
|
|
|
|
player.IsHornActive = (packet.Flag.Value & (ushort)VehicleDataFlags.IsHornActive) > 0;
|
|
|
|
|
player.Transformed = (packet.Flag.Value & (ushort)VehicleDataFlags.IsTransformed) > 0;
|
|
|
|
|
player.VehRoofOpened = (packet.Flag.Value & (ushort)VehicleDataFlags.RoofOpened) > 0;
|
2021-12-13 23:18:15 +01:00
|
|
|
|
player.IsInVehicle = true;
|
|
|
|
|
player.LastSyncWasFull = false;
|
2021-08-26 17:01:32 +02:00
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
player.Latency = packet.Latency.Value;
|
2021-11-19 22:08:15 +01:00
|
|
|
|
player.LastUpdateReceived = Util.GetTickCount64();
|
2021-07-12 05:00:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-20 17:28:13 +02:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
private void DecodeNativeCall(Packets.NativeCall packet)
|
2021-08-20 17:28:13 +02:00
|
|
|
|
{
|
|
|
|
|
List<InputArgument> arguments = new List<InputArgument>();
|
|
|
|
|
|
2021-12-10 15:55:45 +01:00
|
|
|
|
if (packet.Args != null && packet.Args.Count > 0)
|
2021-08-20 17:28:13 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
packet.Args.ForEach(x =>
|
2021-08-21 16:52:17 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Type type = x.GetType();
|
2021-12-10 15:55:45 +01:00
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
if (type == typeof(int))
|
2021-12-10 15:55:45 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
arguments.Add((int)x);
|
2021-12-10 15:55:45 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
else if (type == typeof(bool))
|
2021-12-10 15:55:45 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
arguments.Add((bool)x);
|
2021-12-10 15:55:45 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
else if (type == typeof(float))
|
2021-12-10 15:55:45 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
arguments.Add((float)x);
|
2021-12-10 15:55:45 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
else if (type == typeof(string))
|
2021-12-10 15:55:45 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
arguments.Add((string)x);
|
2021-12-10 15:55:45 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
else if (type == typeof(LVector3))
|
2021-12-10 15:55:45 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
LVector3 vector = (LVector3)x;
|
|
|
|
|
arguments.Add((float)vector.X);
|
|
|
|
|
arguments.Add((float)vector.Y);
|
|
|
|
|
arguments.Add((float)vector.Z);
|
2021-12-10 15:55:45 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GTA.UI.Notification.Show("[DecodeNativeCall][" + packet.Hash + "]: Type of argument not found!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-08-20 17:28:13 +02:00
|
|
|
|
|
|
|
|
|
Function.Call((Hash)packet.Hash, arguments.ToArray());
|
|
|
|
|
}
|
2021-12-10 13:38:03 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
private void DecodeNativeResponse(Packets.NativeResponse packet)
|
2021-12-10 13:38:03 +01:00
|
|
|
|
{
|
|
|
|
|
List<InputArgument> arguments = new List<InputArgument>();
|
|
|
|
|
Type typeOf = null;
|
|
|
|
|
|
2021-12-10 15:55:45 +01:00
|
|
|
|
if (packet.Args != null && packet.Args.Count > 0)
|
2021-12-10 13:38:03 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
packet.Args.ForEach(x =>
|
2021-12-10 13:38:03 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
typeOf = x.GetType();
|
2021-12-10 15:55:45 +01:00
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
if (typeOf == typeof(int))
|
2021-12-10 15:55:45 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
arguments.Add((int)x);
|
2021-12-10 15:55:45 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
else if (typeOf == typeof(bool))
|
2021-12-10 15:55:45 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
arguments.Add((bool)x);
|
2021-12-10 15:55:45 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
else if (typeOf == typeof(float))
|
2021-12-10 15:55:45 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
arguments.Add((float)x);
|
2021-12-10 15:55:45 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
else if (typeOf == typeof(string))
|
2021-12-10 15:55:45 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
arguments.Add((string)x);
|
2021-12-10 15:55:45 +01:00
|
|
|
|
}
|
2021-12-23 22:03:01 +01:00
|
|
|
|
else if (typeOf == typeof(LVector3))
|
2021-12-10 15:55:45 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
LVector3 vector = (LVector3)x;
|
|
|
|
|
arguments.Add((float)vector.X);
|
|
|
|
|
arguments.Add((float)vector.Y);
|
|
|
|
|
arguments.Add((float)vector.Z);
|
2021-12-10 15:55:45 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
GTA.UI.Notification.Show("[DecodeNativeResponse][" + packet.Hash + "]: Type of argument not found!");
|
2021-12-10 15:55:45 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-12-10 13:38:03 +01:00
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
object result;
|
|
|
|
|
switch (packet.ResultType.Value)
|
2021-12-10 13:38:03 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
case 0x00: // int
|
|
|
|
|
result = Function.Call<int>((Hash)packet.Hash, arguments.ToArray());
|
|
|
|
|
break;
|
|
|
|
|
case 0x01: // bool
|
|
|
|
|
result = Function.Call<bool>((Hash)packet.Hash, arguments.ToArray());
|
|
|
|
|
break;
|
|
|
|
|
case 0x02: // float
|
|
|
|
|
result = Function.Call<float>((Hash)packet.Hash, arguments.ToArray());
|
|
|
|
|
break;
|
|
|
|
|
case 0x03: // string
|
|
|
|
|
result = Function.Call<string>((Hash)packet.Hash, arguments.ToArray());
|
|
|
|
|
break;
|
|
|
|
|
case 0x04: // vector3
|
|
|
|
|
result = Function.Call<GTA.Math.Vector3>((Hash)packet.Hash, arguments.ToArray()).ToLVector();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
GTA.UI.Notification.Show("[DecodeNativeResponse][" + packet.Hash + "]: Type of return not found!");
|
|
|
|
|
return;
|
2021-12-10 13:38:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 03:25:00 +01:00
|
|
|
|
if (Main.CheckNativeHash.ContainsKey(packet.Hash))
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<ulong, byte> hash in Main.CheckNativeHash)
|
|
|
|
|
{
|
|
|
|
|
if (hash.Key == packet.Hash)
|
|
|
|
|
{
|
2021-12-26 23:19:12 +01:00
|
|
|
|
lock (Main.ServerItems)
|
|
|
|
|
{
|
|
|
|
|
Main.ServerItems.Add((int)result, hash.Value);
|
|
|
|
|
}
|
2021-12-26 03:25:00 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 13:38:03 +01:00
|
|
|
|
NetOutgoingMessage outgoingMessage = Client.CreateMessage();
|
2022-01-01 03:07:18 +01:00
|
|
|
|
new Packets.NativeResponse()
|
2021-12-10 13:38:03 +01:00
|
|
|
|
{
|
|
|
|
|
Hash = 0,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Args = new List<object>() { result },
|
|
|
|
|
ID = packet.ID
|
2021-12-10 13:38:03 +01:00
|
|
|
|
}.PacketToNetOutGoingMessage(outgoingMessage);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Client.SendMessage(outgoingMessage, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.Native);
|
2021-12-10 13:38:03 +01:00
|
|
|
|
Client.FlushSendQueue();
|
|
|
|
|
}
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#endregion // -- PLAYER --
|
2021-07-12 05:00:48 +02:00
|
|
|
|
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#region -- NPC --
|
2022-01-01 03:07:18 +01:00
|
|
|
|
private void FullSyncNpc(Packets.FullSyncNpc packet)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-14 14:20:41 +01:00
|
|
|
|
lock (Main.NPCs)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-14 22:39:15 +01:00
|
|
|
|
if (Main.NPCs.ContainsKey(packet.NetHandle))
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-12-27 10:15:52 +01:00
|
|
|
|
EntitiesNPC npc = Main.NPCs[packet.NetHandle];
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2021-12-14 19:33:52 +01:00
|
|
|
|
// "if" this NPC has left a vehicle
|
2021-12-27 10:15:52 +01:00
|
|
|
|
npc.PlayerVehicleHandle = 0;
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2021-07-13 07:56:32 +02:00
|
|
|
|
npc.ModelHash = packet.ModelHash;
|
2021-12-16 22:05:40 +01:00
|
|
|
|
npc.Clothes = packet.Clothes;
|
2021-07-13 07:56:32 +02:00
|
|
|
|
npc.Health = packet.Health;
|
|
|
|
|
npc.Position = packet.Position.ToVector();
|
|
|
|
|
npc.Rotation = packet.Rotation.ToVector();
|
|
|
|
|
npc.Velocity = packet.Velocity.ToVector();
|
|
|
|
|
npc.Speed = packet.Speed;
|
|
|
|
|
npc.CurrentWeaponHash = packet.CurrentWeaponHash;
|
|
|
|
|
npc.AimCoords = packet.AimCoords.ToVector();
|
2021-12-28 19:14:51 +01:00
|
|
|
|
npc.IsAiming = (packet.Flag.Value & (ushort)PedDataFlags.IsAiming) > 0;
|
|
|
|
|
npc.IsShooting = (packet.Flag.Value & (ushort)PedDataFlags.IsShooting) > 0;
|
|
|
|
|
npc.IsReloading = (packet.Flag.Value & (ushort)PedDataFlags.IsReloading) > 0;
|
|
|
|
|
npc.IsJumping = (packet.Flag.Value & (ushort)PedDataFlags.IsJumping) > 0;
|
|
|
|
|
npc.IsRagdoll = (packet.Flag.Value & (ushort)PedDataFlags.IsRagdoll) > 0;
|
|
|
|
|
npc.IsOnFire = (packet.Flag.Value & (ushort)PedDataFlags.IsOnFire) > 0;
|
2021-11-19 09:24:06 +01:00
|
|
|
|
npc.IsInVehicle = false;
|
2021-12-13 23:18:15 +01:00
|
|
|
|
npc.LastSyncWasFull = true;
|
2021-12-14 19:33:52 +01:00
|
|
|
|
|
|
|
|
|
npc.LastUpdateReceived = Util.GetTickCount64();
|
2021-07-13 07:56:32 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-27 10:15:52 +01:00
|
|
|
|
Main.NPCs.Add(packet.NetHandle, new EntitiesNPC()
|
2021-07-13 07:56:32 +02:00
|
|
|
|
{
|
|
|
|
|
ModelHash = packet.ModelHash,
|
2021-12-16 22:05:40 +01:00
|
|
|
|
Clothes = packet.Clothes,
|
2021-07-13 07:56:32 +02:00
|
|
|
|
Health = packet.Health,
|
|
|
|
|
Position = packet.Position.ToVector(),
|
|
|
|
|
Rotation = packet.Rotation.ToVector(),
|
|
|
|
|
Velocity = packet.Velocity.ToVector(),
|
|
|
|
|
Speed = packet.Speed,
|
|
|
|
|
CurrentWeaponHash = packet.CurrentWeaponHash,
|
|
|
|
|
AimCoords = packet.AimCoords.ToVector(),
|
2021-12-28 19:14:51 +01:00
|
|
|
|
IsAiming = (packet.Flag.Value & (ushort)PedDataFlags.IsAiming) > 0,
|
|
|
|
|
IsShooting = (packet.Flag.Value & (ushort)PedDataFlags.IsShooting) > 0,
|
|
|
|
|
IsReloading = (packet.Flag.Value & (ushort)PedDataFlags.IsReloading) > 0,
|
|
|
|
|
IsJumping = (packet.Flag.Value & (ushort)PedDataFlags.IsJumping) > 0,
|
|
|
|
|
IsRagdoll = (packet.Flag.Value & (ushort)PedDataFlags.IsRagdoll) > 0,
|
|
|
|
|
IsOnFire = (packet.Flag.Value & (ushort)PedDataFlags.IsOnFire) > 0,
|
2021-12-13 23:18:15 +01:00
|
|
|
|
IsInVehicle = false,
|
2021-12-14 19:33:52 +01:00
|
|
|
|
LastSyncWasFull = true,
|
|
|
|
|
|
|
|
|
|
LastUpdateReceived = Util.GetTickCount64()
|
2021-07-13 07:56:32 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
private void FullSyncNpcVeh(Packets.FullSyncNpcVeh packet)
|
2021-07-10 09:41:17 +02:00
|
|
|
|
{
|
2021-12-14 14:20:41 +01:00
|
|
|
|
lock (Main.NPCs)
|
2021-07-10 09:41:17 +02:00
|
|
|
|
{
|
2021-12-14 22:39:15 +01:00
|
|
|
|
if (Main.NPCs.ContainsKey(packet.NetHandle))
|
2021-07-10 09:41:17 +02:00
|
|
|
|
{
|
2021-12-27 10:15:52 +01:00
|
|
|
|
EntitiesNPC npc = Main.NPCs[packet.NetHandle];
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2021-12-27 10:15:52 +01:00
|
|
|
|
npc.PlayerVehicleHandle = packet.VehHandle;
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2021-07-13 07:56:32 +02:00
|
|
|
|
npc.ModelHash = packet.ModelHash;
|
2021-12-16 22:05:40 +01:00
|
|
|
|
npc.Clothes = packet.Clothes;
|
2021-07-13 07:56:32 +02:00
|
|
|
|
npc.Health = packet.Health;
|
|
|
|
|
npc.VehicleModelHash = packet.VehModelHash;
|
|
|
|
|
npc.VehicleSeatIndex = packet.VehSeatIndex;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
npc.Position = packet.Position.ToVector();
|
2021-07-13 07:56:32 +02:00
|
|
|
|
npc.VehicleRotation = packet.VehRotation.ToQuaternion();
|
2021-08-16 16:51:33 +02:00
|
|
|
|
npc.VehicleEngineHealth = packet.VehEngineHealth;
|
2021-11-19 08:45:20 +01:00
|
|
|
|
npc.VehRPM = packet.VehRPM;
|
2022-03-20 09:21:41 +01:00
|
|
|
|
npc.Velocity = packet.VehVelocity.ToVector();
|
2021-07-13 07:56:32 +02:00
|
|
|
|
npc.VehicleSpeed = packet.VehSpeed;
|
2021-07-13 16:30:33 +02:00
|
|
|
|
npc.VehicleSteeringAngle = packet.VehSteeringAngle;
|
2021-08-13 15:52:30 +02:00
|
|
|
|
npc.VehicleColors = packet.VehColors;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
npc.VehDamageModel = packet.VehDamageModel;
|
2021-12-14 14:46:10 +01:00
|
|
|
|
npc.VehLandingGear = packet.VehLandingGear;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
npc.VehIsEngineRunning = (packet.Flag.Value & (ushort)VehicleDataFlags.IsEngineRunning) > 0;
|
|
|
|
|
npc.VehAreLightsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreLightsOn) > 0;
|
2022-01-01 19:24:57 +01:00
|
|
|
|
npc.VehAreBrakeLightsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreBrakeLightsOn) > 0;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
npc.VehAreHighBeamsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreHighBeamsOn) > 0;
|
|
|
|
|
npc.VehIsSireneActive = (packet.Flag.Value & (ushort)VehicleDataFlags.IsSirenActive) > 0;
|
|
|
|
|
npc.VehicleDead = (packet.Flag.Value & (ushort)VehicleDataFlags.IsDead) > 0;
|
|
|
|
|
npc.IsHornActive = (packet.Flag.Value & (ushort)VehicleDataFlags.IsHornActive) > 0;
|
|
|
|
|
npc.Transformed = (packet.Flag.Value & (ushort)VehicleDataFlags.IsTransformed) > 0;
|
|
|
|
|
npc.VehRoofOpened = (packet.Flag.Value & (ushort)VehicleDataFlags.RoofOpened) > 0;
|
2021-12-13 23:18:15 +01:00
|
|
|
|
npc.IsInVehicle = true;
|
|
|
|
|
npc.LastSyncWasFull = true;
|
2021-12-14 19:33:52 +01:00
|
|
|
|
|
|
|
|
|
npc.LastUpdateReceived = Util.GetTickCount64();
|
2021-07-13 07:56:32 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-27 10:15:52 +01:00
|
|
|
|
Main.NPCs.Add(packet.NetHandle, new EntitiesNPC()
|
2021-07-13 07:56:32 +02:00
|
|
|
|
{
|
2021-12-27 10:15:52 +01:00
|
|
|
|
PlayerVehicleHandle = packet.VehHandle,
|
2021-08-13 15:20:26 +02:00
|
|
|
|
|
2021-07-13 07:56:32 +02:00
|
|
|
|
ModelHash = packet.ModelHash,
|
2021-12-16 22:05:40 +01:00
|
|
|
|
Clothes = packet.Clothes,
|
2021-07-13 07:56:32 +02:00
|
|
|
|
Health = packet.Health,
|
|
|
|
|
VehicleModelHash = packet.VehModelHash,
|
|
|
|
|
VehicleSeatIndex = packet.VehSeatIndex,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Position = packet.Position.ToVector(),
|
2021-07-13 07:56:32 +02:00
|
|
|
|
VehicleRotation = packet.VehRotation.ToQuaternion(),
|
2021-08-16 16:51:33 +02:00
|
|
|
|
VehicleEngineHealth = packet.VehEngineHealth,
|
2021-11-19 08:45:20 +01:00
|
|
|
|
VehRPM = packet.VehRPM,
|
2022-03-20 09:21:41 +01:00
|
|
|
|
Velocity = packet.VehVelocity.ToVector(),
|
2021-07-13 07:56:32 +02:00
|
|
|
|
VehicleSpeed = packet.VehSpeed,
|
2021-07-13 16:30:33 +02:00
|
|
|
|
VehicleSteeringAngle = packet.VehSteeringAngle,
|
2021-08-13 15:52:30 +02:00
|
|
|
|
VehicleColors = packet.VehColors,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
VehDamageModel = packet.VehDamageModel,
|
2021-12-14 14:46:10 +01:00
|
|
|
|
VehLandingGear = packet.VehLandingGear,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
VehIsEngineRunning = (packet.Flag.Value & (ushort)VehicleDataFlags.IsEngineRunning) > 0,
|
|
|
|
|
VehAreLightsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreLightsOn) > 0,
|
2022-01-01 19:24:57 +01:00
|
|
|
|
VehAreBrakeLightsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreBrakeLightsOn) > 0,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
VehAreHighBeamsOn = (packet.Flag.Value & (ushort)VehicleDataFlags.AreHighBeamsOn) > 0,
|
|
|
|
|
VehIsSireneActive = (packet.Flag.Value & (ushort)VehicleDataFlags.IsSirenActive) > 0,
|
|
|
|
|
VehicleDead = (packet.Flag.Value & (ushort)VehicleDataFlags.IsDead) > 0,
|
|
|
|
|
IsHornActive = (packet.Flag.Value & (ushort)VehicleDataFlags.IsHornActive) > 0,
|
|
|
|
|
Transformed = (packet.Flag.Value & (ushort)VehicleDataFlags.IsTransformed) > 0,
|
|
|
|
|
VehRoofOpened = (packet.Flag.Value & (ushort)VehicleDataFlags.RoofOpened) > 0,
|
2021-12-13 23:18:15 +01:00
|
|
|
|
IsInVehicle = true,
|
2021-12-14 19:33:52 +01:00
|
|
|
|
LastSyncWasFull = true,
|
|
|
|
|
|
|
|
|
|
LastUpdateReceived = Util.GetTickCount64()
|
2021-07-13 07:56:32 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
2021-07-10 09:41:17 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#endregion // -- NPC --
|
|
|
|
|
#endregion
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#region -- SEND --
|
2021-11-19 22:08:15 +01:00
|
|
|
|
private ulong LastPlayerFullSync = 0;
|
2022-03-28 15:08:30 +02:00
|
|
|
|
public void SendPlayerData()
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
Ped player = Game.Player.Character;
|
|
|
|
|
|
|
|
|
|
NetOutgoingMessage outgoingMessage = Client.CreateMessage();
|
2021-08-15 13:58:56 +02:00
|
|
|
|
NetDeliveryMethod messageType;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
int connectionChannel = 0;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-11-19 22:08:15 +01:00
|
|
|
|
if ((Util.GetTickCount64() - LastPlayerFullSync) > 500)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-08-15 13:58:56 +02:00
|
|
|
|
messageType = NetDeliveryMethod.UnreliableSequenced;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
connectionChannel = (byte)ConnectionChannel.PlayerFull;
|
2021-08-15 13:58:56 +02:00
|
|
|
|
|
2021-12-13 20:25:31 +01:00
|
|
|
|
if (player.IsInVehicle())
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-12-13 20:25:31 +01:00
|
|
|
|
Vehicle veh = player.CurrentVehicle;
|
2021-08-13 15:52:30 +02:00
|
|
|
|
|
2021-12-16 22:05:40 +01:00
|
|
|
|
byte primaryColor = 0;
|
|
|
|
|
byte secondaryColor = 0;
|
2021-12-13 20:25:31 +01:00
|
|
|
|
unsafe
|
2021-08-13 15:52:30 +02:00
|
|
|
|
{
|
2021-12-16 22:05:40 +01:00
|
|
|
|
Function.Call<byte>(Hash.GET_VEHICLE_COLOURS, veh, &primaryColor, &secondaryColor);
|
2021-08-13 15:52:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
new Packets.FullSyncPlayerVeh()
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
NetHandle = Main.LocalNetHandle,
|
2021-12-26 03:25:00 +01:00
|
|
|
|
PedHandle = player.Handle,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Health = player.Health,
|
2021-12-26 03:25:00 +01:00
|
|
|
|
VehicleHandle = veh.Handle,
|
2021-07-12 05:00:48 +02:00
|
|
|
|
ModelHash = player.Model.Hash,
|
2021-12-16 22:05:40 +01:00
|
|
|
|
Clothes = player.GetPedClothes(),
|
2021-11-19 10:44:16 +01:00
|
|
|
|
VehModelHash = veh.Model.Hash,
|
2021-12-16 22:05:40 +01:00
|
|
|
|
VehSeatIndex = (short)player.SeatIndex,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Position = veh.Position.ToLVector(),
|
2021-12-13 20:25:31 +01:00
|
|
|
|
VehRotation = veh.Quaternion.ToLQuaternion(),
|
|
|
|
|
VehEngineHealth = veh.EngineHealth,
|
|
|
|
|
VehRPM = veh.CurrentRPM,
|
|
|
|
|
VehVelocity = veh.Velocity.ToLVector(),
|
|
|
|
|
VehSpeed = veh.Speed,
|
|
|
|
|
VehSteeringAngle = veh.SteeringAngle,
|
2021-12-06 00:56:08 +01:00
|
|
|
|
VehAimCoords = veh.IsTurretSeat((int)player.SeatIndex) ? Util.GetVehicleAimCoords().ToLVector() : new LVector3(),
|
2021-12-16 22:05:40 +01:00
|
|
|
|
VehColors = new byte[] { primaryColor, secondaryColor },
|
2021-12-13 20:25:31 +01:00
|
|
|
|
VehMods = veh.Mods.GetVehicleMods(),
|
2021-12-23 22:03:01 +01:00
|
|
|
|
VehDamageModel = veh.GetVehicleDamageModel(),
|
2021-12-14 14:46:10 +01:00
|
|
|
|
VehLandingGear = veh.IsPlane ? (byte)veh.LandingGearState : (byte)0,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Flag = player.GetVehicleFlags(veh)
|
2021-07-12 05:00:48 +02:00
|
|
|
|
}.PacketToNetOutGoingMessage(outgoingMessage);
|
|
|
|
|
}
|
2021-11-19 10:44:16 +01:00
|
|
|
|
else
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-01-01 03:07:18 +01:00
|
|
|
|
new Packets.FullSyncPlayer()
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
NetHandle = Main.LocalNetHandle,
|
2021-12-26 03:25:00 +01:00
|
|
|
|
PedHandle = player.Handle,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Health = player.Health,
|
2021-11-19 10:44:16 +01:00
|
|
|
|
ModelHash = player.Model.Hash,
|
2021-12-16 22:05:40 +01:00
|
|
|
|
Clothes = player.GetPedClothes(),
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Position = player.Position.ToLVector(),
|
2021-07-12 05:00:48 +02:00
|
|
|
|
Rotation = player.Rotation.ToLVector(),
|
|
|
|
|
Velocity = player.Velocity.ToLVector(),
|
2021-11-19 08:40:40 +01:00
|
|
|
|
Speed = player.GetPedSpeed(),
|
|
|
|
|
AimCoords = player.GetPedAimCoords(false).ToLVector(),
|
2021-12-15 03:31:57 +01:00
|
|
|
|
CurrentWeaponHash = (uint)player.Weapons.Current.Hash,
|
2021-12-15 01:25:16 +01:00
|
|
|
|
WeaponComponents = player.Weapons.Current.GetWeaponComponents(),
|
2021-12-13 23:18:15 +01:00
|
|
|
|
Flag = player.GetPedFlags(true)
|
2021-07-12 05:00:48 +02:00
|
|
|
|
}.PacketToNetOutGoingMessage(outgoingMessage);
|
|
|
|
|
}
|
2021-11-19 10:44:16 +01:00
|
|
|
|
|
2021-11-19 22:08:15 +01:00
|
|
|
|
LastPlayerFullSync = Util.GetTickCount64();
|
2021-11-19 10:44:16 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
messageType = NetDeliveryMethod.ReliableSequenced;
|
2021-12-23 22:03:01 +01:00
|
|
|
|
connectionChannel = (byte)ConnectionChannel.PlayerLight;
|
2021-11-19 10:44:16 +01:00
|
|
|
|
|
|
|
|
|
if (player.IsInVehicle())
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-11-19 10:44:16 +01:00
|
|
|
|
Vehicle veh = player.CurrentVehicle;
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
new Packets.LightSyncPlayerVeh()
|
2021-07-12 05:00:48 +02:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
NetHandle = Main.LocalNetHandle,
|
|
|
|
|
Health = player.Health,
|
2021-11-19 10:44:16 +01:00
|
|
|
|
VehModelHash = veh.Model.Hash,
|
2021-12-16 22:05:40 +01:00
|
|
|
|
VehSeatIndex = (short)player.SeatIndex,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Position = veh.Position.ToLVector(),
|
2021-12-13 20:25:31 +01:00
|
|
|
|
VehRotation = veh.Quaternion.ToLQuaternion(),
|
|
|
|
|
VehVelocity = veh.Velocity.ToLVector(),
|
|
|
|
|
VehSpeed = veh.Speed,
|
|
|
|
|
VehSteeringAngle = veh.SteeringAngle,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Flag = player.GetVehicleFlags(veh)
|
2021-11-19 10:44:16 +01:00
|
|
|
|
}.PacketToNetOutGoingMessage(outgoingMessage);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-01-01 03:07:18 +01:00
|
|
|
|
new Packets.LightSyncPlayer()
|
2021-11-19 10:44:16 +01:00
|
|
|
|
{
|
2021-12-23 22:03:01 +01:00
|
|
|
|
NetHandle = Main.LocalNetHandle,
|
|
|
|
|
Health = player.Health,
|
|
|
|
|
Position = player.Position.ToLVector(),
|
2021-11-19 10:44:16 +01:00
|
|
|
|
Rotation = player.Rotation.ToLVector(),
|
|
|
|
|
Velocity = player.Velocity.ToLVector(),
|
|
|
|
|
Speed = player.GetPedSpeed(),
|
|
|
|
|
AimCoords = player.GetPedAimCoords(false).ToLVector(),
|
2021-12-15 03:31:57 +01:00
|
|
|
|
CurrentWeaponHash = (uint)player.Weapons.Current.Hash,
|
2021-12-13 23:18:15 +01:00
|
|
|
|
Flag = player.GetPedFlags(true)
|
2021-07-12 05:00:48 +02:00
|
|
|
|
}.PacketToNetOutGoingMessage(outgoingMessage);
|
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Client.SendMessage(outgoingMessage, messageType, connectionChannel);
|
2021-07-07 13:36:25 +02:00
|
|
|
|
Client.FlushSendQueue();
|
2021-08-18 11:47:59 +02:00
|
|
|
|
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#if DEBUG
|
2021-08-18 11:47:59 +02:00
|
|
|
|
if (ShowNetworkInfo)
|
|
|
|
|
{
|
|
|
|
|
BytesSend += outgoingMessage.LengthBytes;
|
|
|
|
|
}
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 15:08:30 +02:00
|
|
|
|
public void SendNpcData(Ped npc)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
NetOutgoingMessage outgoingMessage = Client.CreateMessage();
|
|
|
|
|
|
2021-12-13 20:25:31 +01:00
|
|
|
|
if (npc.IsInVehicle())
|
2021-07-10 09:41:17 +02:00
|
|
|
|
{
|
2021-12-13 20:25:31 +01:00
|
|
|
|
Vehicle veh = npc.CurrentVehicle;
|
2021-08-13 15:52:30 +02:00
|
|
|
|
|
2021-12-16 22:05:40 +01:00
|
|
|
|
byte primaryColor = 0;
|
|
|
|
|
byte secondaryColor = 0;
|
2021-12-13 20:25:31 +01:00
|
|
|
|
unsafe
|
2021-08-13 15:52:30 +02:00
|
|
|
|
{
|
2021-12-16 22:05:40 +01:00
|
|
|
|
Function.Call<byte>(Hash.GET_VEHICLE_COLOURS, npc.CurrentVehicle, &primaryColor, &secondaryColor);
|
2021-08-13 15:52:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
new Packets.FullSyncNpcVeh()
|
2021-07-10 09:41:17 +02:00
|
|
|
|
{
|
2021-12-14 22:39:15 +01:00
|
|
|
|
NetHandle = Main.LocalNetHandle + npc.Handle,
|
|
|
|
|
VehHandle = Main.LocalNetHandle + veh.Handle,
|
2021-07-10 09:41:17 +02:00
|
|
|
|
ModelHash = npc.Model.Hash,
|
2021-12-16 22:05:40 +01:00
|
|
|
|
Clothes = npc.GetPedClothes(),
|
2021-07-10 09:41:17 +02:00
|
|
|
|
Health = npc.Health,
|
2021-11-19 10:44:16 +01:00
|
|
|
|
VehModelHash = veh.Model.Hash,
|
2021-12-16 22:05:40 +01:00
|
|
|
|
VehSeatIndex = (short)npc.SeatIndex,
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Position = veh.Position.ToLVector(),
|
2021-12-13 20:25:31 +01:00
|
|
|
|
VehRotation = veh.Quaternion.ToLQuaternion(),
|
|
|
|
|
VehEngineHealth = veh.EngineHealth,
|
|
|
|
|
VehRPM = veh.CurrentRPM,
|
|
|
|
|
VehVelocity = veh.Velocity.ToLVector(),
|
|
|
|
|
VehSpeed = veh.Speed,
|
|
|
|
|
VehSteeringAngle = veh.SteeringAngle,
|
2021-12-16 22:05:40 +01:00
|
|
|
|
VehColors = new byte[] { primaryColor, secondaryColor },
|
2021-12-13 20:25:31 +01:00
|
|
|
|
VehMods = veh.Mods.GetVehicleMods(),
|
2021-12-23 22:03:01 +01:00
|
|
|
|
VehDamageModel = veh.GetVehicleDamageModel(),
|
2021-12-14 14:46:10 +01:00
|
|
|
|
VehLandingGear = veh.IsPlane ? (byte)veh.LandingGearState : (byte)0,
|
2021-12-27 01:26:36 +01:00
|
|
|
|
Flag = npc.GetVehicleFlags(veh)
|
2021-11-19 10:44:16 +01:00
|
|
|
|
}.PacketToNetOutGoingMessage(outgoingMessage);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-01-01 03:07:18 +01:00
|
|
|
|
new Packets.FullSyncNpc()
|
2021-11-19 10:44:16 +01:00
|
|
|
|
{
|
2021-12-14 22:39:15 +01:00
|
|
|
|
NetHandle = Main.LocalNetHandle + npc.Handle,
|
2021-11-19 10:44:16 +01:00
|
|
|
|
ModelHash = npc.Model.Hash,
|
2021-12-16 22:05:40 +01:00
|
|
|
|
Clothes = npc.GetPedClothes(),
|
2021-11-19 10:44:16 +01:00
|
|
|
|
Health = npc.Health,
|
|
|
|
|
Position = npc.Position.ToLVector(),
|
|
|
|
|
Rotation = npc.Rotation.ToLVector(),
|
|
|
|
|
Velocity = npc.Velocity.ToLVector(),
|
|
|
|
|
Speed = npc.GetPedSpeed(),
|
|
|
|
|
AimCoords = npc.GetPedAimCoords(true).ToLVector(),
|
2021-12-15 03:31:57 +01:00
|
|
|
|
CurrentWeaponHash = (uint)npc.Weapons.Current.Hash,
|
2021-12-27 01:26:36 +01:00
|
|
|
|
Flag = npc.GetPedFlags(true)
|
2021-07-10 09:41:17 +02:00
|
|
|
|
}.PacketToNetOutGoingMessage(outgoingMessage);
|
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Client.SendMessage(outgoingMessage, NetDeliveryMethod.Unreliable, (byte)ConnectionChannel.NPCFull);
|
2021-07-07 13:36:25 +02:00
|
|
|
|
Client.FlushSendQueue();
|
2021-08-18 11:47:59 +02:00
|
|
|
|
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#if DEBUG
|
2021-08-18 11:47:59 +02:00
|
|
|
|
if (ShowNetworkInfo)
|
|
|
|
|
{
|
|
|
|
|
BytesSend += outgoingMessage.LengthBytes;
|
|
|
|
|
}
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 15:08:30 +02:00
|
|
|
|
public void SendChatMessage(string message)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
NetOutgoingMessage outgoingMessage = Client.CreateMessage();
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
2022-01-01 03:07:18 +01:00
|
|
|
|
new Packets.ChatMessage() { Username = Main.MainSettings.Username, Message = message }.PacketToNetOutGoingMessage(outgoingMessage);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
|
|
|
|
|
Client.SendMessage(outgoingMessage, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.Chat);
|
2021-07-07 13:36:25 +02:00
|
|
|
|
Client.FlushSendQueue();
|
2021-08-18 11:47:59 +02:00
|
|
|
|
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#if DEBUG
|
2021-08-18 11:47:59 +02:00
|
|
|
|
if (ShowNetworkInfo)
|
|
|
|
|
{
|
|
|
|
|
BytesSend += outgoingMessage.LengthBytes;
|
|
|
|
|
}
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 15:08:30 +02:00
|
|
|
|
public void SendModData(long target, string modName, byte customID, byte[] bytes)
|
2021-09-29 14:34:22 +02:00
|
|
|
|
{
|
|
|
|
|
NetOutgoingMessage outgoingMessage = Client.CreateMessage();
|
2022-01-01 03:07:18 +01:00
|
|
|
|
new Packets.Mod()
|
2021-09-29 14:34:22 +02:00
|
|
|
|
{
|
2021-12-14 22:39:15 +01:00
|
|
|
|
NetHandle = Main.LocalNetHandle,
|
2021-09-30 23:35:42 +02:00
|
|
|
|
Target = target,
|
2022-01-01 03:07:18 +01:00
|
|
|
|
Name = modName,
|
2021-12-14 22:39:15 +01:00
|
|
|
|
CustomPacketID = customID,
|
2021-09-29 14:34:22 +02:00
|
|
|
|
Bytes = bytes
|
|
|
|
|
}.PacketToNetOutGoingMessage(outgoingMessage);
|
2021-12-23 22:03:01 +01:00
|
|
|
|
Client.SendMessage(outgoingMessage, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.Mod);
|
2021-09-29 14:34:22 +02:00
|
|
|
|
Client.FlushSendQueue();
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
if (ShowNetworkInfo)
|
|
|
|
|
{
|
|
|
|
|
BytesSend += outgoingMessage.LengthBytes;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2022-04-02 18:11:30 +02:00
|
|
|
|
|
|
|
|
|
public void SendDownloadFinish(byte id)
|
|
|
|
|
{
|
|
|
|
|
NetOutgoingMessage outgoingMessage = Client.CreateMessage();
|
|
|
|
|
|
|
|
|
|
new Packets.FileTransferComplete() { ID = id }.PacketToNetOutGoingMessage(outgoingMessage);
|
|
|
|
|
|
|
|
|
|
Client.SendMessage(outgoingMessage, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.File);
|
|
|
|
|
Client.FlushSendQueue();
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
if (ShowNetworkInfo)
|
|
|
|
|
{
|
|
|
|
|
BytesSend += outgoingMessage.LengthBytes;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2021-09-29 14:34:22 +02:00
|
|
|
|
#endregion
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|