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 5, 2022
1 parent 49c852a commit 1655fdc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 42 deletions.
18 changes: 8 additions & 10 deletions NETHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void NetPacketStat(int carId, bool allowdrive, bool allowsit, bool
}
public static void NETSIT(int CarID, int SitID)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE || SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.HOST) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1111);
Expand All @@ -33,7 +33,7 @@ public static void NETSIT(int CarID, int SitID)
}
public static void NetDeleteCar()
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE || SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.HOST) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(0100);
Expand All @@ -43,7 +43,7 @@ public static void NetDeleteCar()
}
public static void NetSendDriver(int ID, bool drived)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE || SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.HOST) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1010);
Expand All @@ -67,7 +67,7 @@ public static void NetCar(int CarID, Vector3 Position, Quaternion Rotation)
}
public static void NetSpawnCar(string name, Vector3 Position, Quaternion Rotation)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE || SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.HOST) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1000);
Expand All @@ -77,25 +77,23 @@ public static void NetSpawnCar(string name, Vector3 Position, Quaternion Rotatio

Send(packet);
}
public static void NetSound(int ID, bool state)
public static void NetSound(int ID)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE || SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.HOST) 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)
public static void NetLight(int ID)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE || SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.HOST) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

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

Send(packet);
}
Expand Down
8 changes: 4 additions & 4 deletions PACKETS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
{
from = _pak.ReadInt();
}
if (CheckEnv(from)) VehicleController.PlayerCarMove(ID, Position, Rotation);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) VehicleController.PlayerCarMove(ID, Position, Rotation);
}

if (packetid == 1000) // SPAWN CAR
Expand All @@ -43,13 +43,14 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
bool sound = _pak.ReadBool();
bool light = _pak.ReadBool();
float fuel = _pak.ReadFloat();
string name = _pak.ReadString();

if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT)
{
from = _pak.ReadInt();
}
string plname = SkyCoop.MyMod.playersData[from].m_Name;
if (CheckEnv(from)) UpdateCarData(carid, allowdrive, allowsit, isdrive, sound, light, fuel, plname);
if (CheckEnv(from)) UpdateCarData(carid, name, allowdrive, allowsit, isdrive, sound, light, fuel, plname);
}
if (packetid == 1100) // SEND Sound ON
{
Expand All @@ -73,7 +74,6 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int 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();
Expand All @@ -89,7 +89,7 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
{
from = _pak.ReadInt();
}
if (CheckEnv(from)) UpdateDriver(ID, drived);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) UpdateDriver(ID, drived);
}
}
private static bool CheckEnv(int from)
Expand Down
34 changes: 20 additions & 14 deletions VehComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void NEWDATA(int PlayerId, string name, string PlayerName)
vehicleData.m_audio = transform.GetComponent<AudioSource>();
m_Rigidbody = transform.GetComponent<Rigidbody>();
m_Rigidbody.mass = float.Parse(GetInfo(name, "Weight"));
m_Rigidbody.centerOfMass = Vector3.down;
vehicleData.m_Type = int.Parse(GetInfo(name, "Type"));
vehicleData.m_MotorTorque = float.Parse(GetInfo(name, "MotorTorque"));
vehicleData.m_MaxFuel = int.Parse(GetInfo(name, "MaxFuel"));
Expand All @@ -60,10 +61,10 @@ public void NEWDATA(int PlayerId, string name, string PlayerName)
}
if (g.name.StartsWith("Light"))
{
if (!g.GetComponent<Light>())
MelonLogger.Msg("[" + g.name + "] This GameObject doesn't have Light component!");
else
if (g.GetComponent<Light>())
vehicleData.m_Lights.Add(g.GetComponent<Light>());
else
MelonLogger.Msg("[" + g.name + "] This GameObject doesn't have Light component!");
}
if (g.name.StartsWith("Sit")) vehicleData.m_Sits.Add(g);
}
Expand All @@ -88,6 +89,7 @@ public void LateUpdate()
vehicleData.m_CurSpeed = m_Rigidbody.velocity.magnitude;
if (CountPassanger() > 0) foreach (int i in vehicleData.Passangers.Keys) SkyCoop.MyMod.players[i].SetActive(false);
EngineSoundAndLight();
NETHost.NetPacketStat(vehicleData.m_OwnerId, vehicleData.m_AllowDrive, vehicleData.m_AllowSit, vehicleData.m_isDrive, vehicleData.m_SoundPlay, vehicleData.m_Light, vehicleData.m_CurFuel, vehicleData.m_VehicleName);
}
public void FixedUpdate()
{
Expand All @@ -111,22 +113,26 @@ public void Update()
if (vehicleData == null || !enableds || !m_Rigidbody) return;
if (vehicleData.m_Type == 0)
{
float MotorTorque = 1000 * Time.fixedDeltaTime;
if (m_Rigidbody.velocity.magnitude <= 0.05) MotorTorque = 1000 * Time.fixedDeltaTime * vehicleData.m_CurSpeed;
float MotorTorque = 100 * vehicleData.m_MotorTorque * Time.fixedDeltaTime;
if (m_Rigidbody.velocity.magnitude <= 0.05) MotorTorque = 100 * vehicleData.m_MotorTorque * Time.fixedDeltaTime * vehicleData.m_CurSpeed;

for (int i = 0; i != vehicleData.m_Wheels.Count; i++)
{
if (move != 0 && !Input.GetKey(KeyCode.Space))
{
WheelComponent.Set_BrakeTorque(vehicleData.m_Wheels[i], 0);
WheelComponent.Set_MotorTorque(vehicleData.m_Wheels[i], MotorTorque * move);
}
else
if (CountPassanger() == 0 || !vehicleData.m_isDrive) WheelComponent.Set_BrakeTorque(vehicleData.m_Wheels[i], MotorTorque * 3);
if (vehicleData.m_isDrive && main.targetcar == vehicleData.m_OwnerId && main.allowdrive)
{
WheelComponent.Set_MotorTorque(vehicleData.m_Wheels[i], 0);
WheelComponent.Set_BrakeTorque(vehicleData.m_Wheels[i], MotorTorque * 3);
if (move != 0 && !Input.GetKey(KeyCode.Space))
{
WheelComponent.Set_BrakeTorque(vehicleData.m_Wheels[i], 0);
WheelComponent.Set_MotorTorque(vehicleData.m_Wheels[i], MotorTorque * move);
}
else
{
WheelComponent.Set_MotorTorque(vehicleData.m_Wheels[i], 0);
WheelComponent.Set_BrakeTorque(vehicleData.m_Wheels[i], MotorTorque * 3);
}
if (vehicleData.m_Wheels[i].name.StartsWith("WheelMain")) WheelComponent.Set_SteerAngle(vehicleData.m_Wheels[i], Mathf.Clamp(vehicleData.m_CurSpeed * turn + turn * 10, -45, 45));
}
if (vehicleData.m_Wheels[i].name.StartsWith("WheelMain")) WheelComponent.Set_SteerAngle(vehicleData.m_Wheels[i], Mathf.Clamp(vehicleData.m_CurSpeed * turn + turn * 10, -45, 45));
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions VehicleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void MoveDrive(int number)
float dist = Vector3.Distance(GetObj(number).transform.position, GameManager.GetVpFPSPlayer().transform.position);
if (GetObj(number) && !InterfaceManager.m_Panel_Loading.IsLoading() && dist > 2)
{
Transform sit = GetObj(number).transform.Find("SITS/").GetChild(siter - 1);
Transform sit = car.transform.Find("SITS").GetChild(siter);
GetObj(number).transform.position = GameManager.GetVpFPSPlayer().transform.position + GameManager.GetVpFPSPlayer().transform.up * 5f;
foreach (Collider col in GameManager.GetPlayerTransform().GetComponents<Collider>())
{
Expand All @@ -50,7 +50,7 @@ public static void MoveDrive(int number)
}
if (!main.allowdrive)
{
Transform sit = GetObj(number).transform.Find("SITS").GetChild(siter-1);
Transform sit = GetObj(number).transform.Find("SITS").GetChild(siter);
GameManager.GetVpFPSPlayer().transform.parent = sit;
GameManager.GetVpFPSPlayer().transform.position = sit.position;
}
Expand All @@ -65,9 +65,9 @@ public static void PlayerCarMove(int CarID, Vector3 Position, Quaternion Rotatio
public static void SitCar(int number)
{
GameObject car = GetObj(number);
siter = CountPassangers(number) + 1;
if (main.allowdrive) siter = 1;
if (main.isSit) siter = 0;
siter = CountPassangers(number);
if (main.allowdrive) siter = 0;
if (main.isSit) siter = -1;
// PARENT THE LOCAL 3D MODEL TO VEHICLE OR unparent it
if (main.isSit)
{
Expand All @@ -84,14 +84,15 @@ public static void SitCar(int number)
cameracar.SetParent(null);
main.targetcar = -1;
MenuControll.Open(1);
if (CountPassangers(number) == 0 || !isDrive(number)) NETHost.NetSound(number, false);
if (CountPassangers(number) == 0 || !isDrive(number)) NETHost.NetSound(number);
main.isSit = false;
GameManager.GetVpFPSPlayer().transform.SetParent(myparent);
GetObj(number).GetComponent<VehComponent>().UpdateSound();
}
else
{
if (main.allowdrive) {
if (main.allowdrive)
{
UpdateDriver(number, true);
NETHost.NetSendDriver(number, true);
}
Expand All @@ -105,7 +106,7 @@ public static void SitCar(int number)
MenuControll.Open(11);
GameManager.GetVpFPSPlayer().transform.SetParent(sit);
GameManager.GetVpFPSPlayer().transform.position = sit.position;
NETHost.NetSound(number, true);
NETHost.NetSound(number);
if (!GetObj(number).GetComponent<VehComponent>().vehicleData.m_SoundPlay) GetObj(number).GetComponent<VehComponent>().UpdateSound();
}

Expand All @@ -122,7 +123,7 @@ private static void CameraFollow(int CarId)
{
// CAMERA CONTROLLER FOR VEHICLE
GameObject car = GetObj(CarId);
Transform sit = car.transform.Find("SITS/" + siter);
Transform sit = GetObj(CarId).transform.Find("SITS").GetChild(siter);
if (!fps)
{
GameObject player = GetObj(CarId).transform.Find("SITS").GetChild(siter).GetChild(0).gameObject;
Expand Down
9 changes: 6 additions & 3 deletions data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ public static GameObject LoadObject(string name)
}
return i;
}
public static void UpdateCarData(int carid, bool allowdrive, bool allowsit, bool isDrive, bool sound, bool light, float fuel, string playername)
public static void UpdateCarData(int carid, string carname, bool allowdrive, bool allowsit, bool isDrive, bool sound, bool light, float fuel, string playername)
{
GetObj(carid).GetComponent<VehComponent>().UpdateMainCarData(carid, allowdrive, allowsit, isDrive, sound, light, fuel, playername);
if (GetObj(carid))
GetObj(carid).GetComponent<VehComponent>().UpdateMainCarData(carid, allowdrive, allowsit, isDrive, sound, light, fuel, playername);
else
main.SpawnCar(carid, main.levelid, carname, Vector3.zero, Quaternion.identity);
}
public static void UpdateDriver(int CarID, bool state)
{
Expand All @@ -40,7 +43,7 @@ public static int CountPassangers(int CarID)
}
public static void UpdatePassanger(int CarID, int Number, int from)
{
if (Number == 0)
if (Number == -1)
GetObj(CarID).GetComponent<VehComponent>().DeletePassanger(from);
else
GetObj(CarID).GetComponent<VehComponent>().AddPassanger(from, Number);
Expand Down
3 changes: 1 addition & 2 deletions main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public override void OnUpdate()
if (isSit && allowdrive)
{
GetObj(targetcar).GetComponent<VehComponent>().vehicleData.m_Light = !GetObj(targetcar).GetComponent<VehComponent>().vehicleData.m_Light;
NETHost.NetLight(targetcar);
}
}
// SIT EXECUTE
Expand Down Expand Up @@ -145,8 +146,6 @@ public override void OnLateUpdate()
if (vehicles.Count > 0) foreach (var i in vehicles)
{
InfoMain ii = i.Value.GetComponent<VehComponent>().vehicleData;

if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.HOST) NETHost.NetPacketStat(ii.m_OwnerId, ii.m_AllowDrive, ii.m_AllowSit, ii.m_isDrive, ii.m_SoundPlay, ii.m_Light, ii.m_CurFuel, ii.m_VehicleName);
if (!isDrive(ii.m_OwnerId)) NETHost.NetCar(ii.m_OwnerId, i.Value.transform.position, i.Value.transform.rotation);
}

Expand Down

0 comments on commit 1655fdc

Please sign in to comment.