-
Notifications
You must be signed in to change notification settings - Fork 0
/
PACKETS.cs
72 lines (65 loc) · 3.26 KB
/
PACKETS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using UnityEngine;
using GameServer;
using static vehiclemod.data;
using MelonLoader;
namespace vehiclemod
{
[HarmonyLib.HarmonyPatch(typeof(SkyCoop.API), "CustomEventCallback")]
public static class SkyCoop_HandleData
{
public static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
{
int packetid = _pak.ReadInt(); // WHAT TO GET
int ID = _pak.ReadInt();
if (packetid == 0000) // MOVE CAR
{
Vector3 Position = _pak.ReadVector3();
Quaternion Rotation = _pak.ReadQuaternion();
if(from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) UpdateCar(ID, Position, Rotation);
}
if (packetid == 0100) // DELETE CAR
{
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) if(main.deletecar(ID)) MelonLogger.Msg("Deleted NET Vehicle: "+ID);
}
if (packetid == 1000) // SPAWN CAR
{
string name = _pak.ReadString();
Vector3 Position = _pak.ReadVector3();
Quaternion Rotation = _pak.ReadQuaternion();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && !main.vehicles.ContainsKey(ID)) main.SpawnCar(ID, SkyCoop.MyMod.playersData[from].m_Levelid, name, Position, Rotation);
}
if (packetid == 1100) // SEND Sound
{
bool state = _pak.ReadBool();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) UpdateSound(ID, state);
}
if (packetid == 1111) // PASSANGER
{
int SitID = _pak.ReadInt();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) UpdatePassanger(ID, SitID, from);
}
if (packetid == 1101) // Turn LIGHT
{
bool state = _pak.ReadBool();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) UpdateLight(ID, state);
}
if (packetid == 1010) // SEND Driver
{
bool state = _pak.ReadBool();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from)) UpdateDriver(ID, state);
}
}
private static bool CheckEnv(int from)
{
if (from == main.MyId || main.levelid != SkyCoop.MyMod.playersData[from].m_Levelid) return false;
return true;
}
}
}