Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
werasik2aa authored May 10, 2022
1 parent 40fdade commit 0c93fc1
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 197 deletions.
3 changes: 2 additions & 1 deletion HMpatch.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using HarmonyLib;
using System;
using UnhollowerBaseLib.Attributes;
using UnityEngine;
namespace vehiclemod
{
[HarmonyPatch(typeof(WheelCollider), "LoadWheelCollider")] /* https://github.com/werasik2aa/BringBackComponents */
public class WheelCollider : Collider
{
public WheelCollider(IntPtr Value) : base(Value) { }
public WheelCollider(IntPtr Value) : base (Value) { }
public float radius;
public bool isGrounded { get; }
public float steerAngle;
Expand Down
1 change: 1 addition & 0 deletions MenuControll.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using static vehiclemod.data;
Expand Down
63 changes: 37 additions & 26 deletions NETHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,86 +5,97 @@ namespace vehiclemod
{
public static class NETHost
{
private static Packet packet;
public static void NETSEND(int CarID, string carName)
{
if (!CHECK()) return;
packet.Write(0110);
packet.Write(CarID);
packet.Write(carName);
Send(packet);
}
public static void NETSIT(int CarID, int SitID)
{
if(!CHECK()) return;
if (!Check()) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1111);
packet.Write(CarID);
packet.Write(SitID);
Send(packet);
}
public static void NetDeleteCar()
public static void NetDeleteCar(int id)
{
if(!CHECK()) return;
if (!Check()) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(0100);
packet.Write(1);
packet.Write(id);

Send(packet);
}
public static void NetSendDriver(int ID, bool drived)
{
if(!CHECK()) return;
if (!Check()) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1010);
packet.Write(ID);
packet.Write(drived);

Send(packet);
}

public static void NetCar(int CarID, Vector3 Position, Quaternion Rotation)
{
if(!CHECK()) return;
if (!Check()) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(0000);
packet.Write(CarID);
packet.Write(Position);
packet.Write(Rotation);

Send(packet);
}
public static void NetSpawnCar(string name, Vector3 Position, Quaternion Rotation)
public static void NetSpawnCar(int i, string name, Vector3 Position, Quaternion Rotation)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE || SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.HOST) return;
if (!Check()) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1000);
packet.Write(i);
packet.Write(name);
packet.Write(Position);
packet.Write(Rotation);

Send(packet);
}
public static void NetSound(int ID, bool state)
{
if(!CHECK()) return;
if (!Check()) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1100);
packet.Write(ID);
packet.Write(state);

Send(packet);
}
public static void NetLight(int ID, bool state)
{
if(!CHECK()) return;
if (!Check()) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1101);
packet.Write(ID);
packet.Write(state);

Send(packet);
}
private static bool CHECK()
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE || !main.hook) return false;
packet = new Packet((int)ClientPackets.CUSTOM);
return true;
}
private static void Send(Packet packet)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.HOST)
SkyCoop.API.SendDataToEveryone(packet, SkyCoop.API.m_MyClientID, true); //Send data to everyone. Host Sender

if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT)
SkyCoop.API.SendToHost(packet); //Send data to everyone. Client sender
SkyCoop.API.SendToHost(packet); //Send data to HOST
}
private static bool Check()
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE || !main.hook) return false;
else return true;
}
}
}
74 changes: 26 additions & 48 deletions PACKETS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,88 +7,66 @@ namespace vehiclemod
[HarmonyLib.HarmonyPatch(typeof(SkyCoop.API), "CustomEventCallback")]
public static class SkyCoop_HandleData
{
static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
public static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
{
int packetid = _pak.ReadInt();
if (packetid == 0110) // CHECK EXIST CAR
{
int CarID = _pak.ReadInt();
string carName = _pak.ReadString();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT)
{
from = _pak.ReadInt();
}
if (CheckEnv(from) && !main.vehicles.ContainsKey(CarID)) main.SpawnCar(CarID, main.MyId, carName, Vector3.one, Quaternion.identity);
}
if
(packetid == 0000) // MOVE CAR
int packetid = _pak.ReadInt(); // WHAT TO GET
if (packetid == 0000) // MOVE CAR
{
int ID = _pak.ReadInt();
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))
{
InfoMain i = GetObj(ID).GetComponent<VehComponent>().vehicleData;
i.m_Position = Position; i.m_Rotation = Rotation;
GetObj(ID).GetComponent<VehComponent>().UpdateCarPosition();
}

if(from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && main.vehicles.ContainsKey(ID) && !(main.allowdrive && main.targetcar == GetObj(ID).GetComponent<VehComponent>().vehicleData.m_OwnerId)) GetObj(ID).GetComponent<VehComponent>().MoveIt(Position, Rotation);
}
if (packetid == 0100) // DELETE CAR
{
int ID = _pak.ReadInt();

if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) { GameObject.Destroy(GetObj(ID)); main.vehicles.Remove(ID); }
}
if (packetid == 1000) // SPAWN CAR
{
int i = _pak.ReadInt();
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.SpawnCar(from, SkyCoop.MyMod.playersData[from].m_Levelid, name, Position, Rotation);

if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && !main.vehicles.ContainsKey(i)) main.SpawnCar(i, SkyCoop.MyMod.playersData[from].m_Levelid, name, Position, Rotation);
}
if (packetid == 1100) // SEND Sound ON
{
int ID = _pak.ReadInt();
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)) GetObj(ID).GetComponent<VehComponent>().UpdateSound(state);
bool lig = _pak.ReadBool();

if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) GetObj(ID).GetComponent<VehComponent>().UpdateSound(lig);
}
if (packetid == 1111) // PASSANGER
{
int ID = _pak.ReadInt();
int SitID = _pak.ReadInt();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT)
{
from = _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
{
int ID = _pak.ReadInt();
bool state = _pak.ReadBool();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT)
{
from = _pak.ReadInt();
}

if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) GetObj(ID).GetComponent<VehComponent>().UpdateLight(state);
}
if (packetid == 1010) // SEND Driver
{
int ID = _pak.ReadInt();
bool drived = _pak.ReadBool();

if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT)
{
from = _pak.ReadInt();
}
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) UpdateDriver(ID, drived);
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT) from = _pak.ReadInt();
if (CheckEnv(from)) UpdateDriver(ID, drived);
}
}
private static bool CheckEnv(int from)
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: MelonInfo(typeof(vehiclemod.main), "VehicleMod", "1.3H", "NopirateOnlySteam")]
[assembly: MelonInfo(typeof(vehiclemod.main), "VehicleMod", "1.35E", "NopirateOnlySteam")]
[assembly: MelonGame("Hinterland", "TheLongDark")]
[assembly: ComVisible(false)]
[assembly: Guid("b1e85fa5-23d9-48b6-9d96-e9afe7c41d28")]
Expand Down
Loading

0 comments on commit 0c93fc1

Please sign in to comment.