Skip to content

Commit

Permalink
1.2 Component and data. New controller!
Browse files Browse the repository at this point in the history
prerelease!
  • Loading branch information
werasik2aa authored May 3, 2022
1 parent 97e759b commit 49c852a
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 410 deletions.
3 changes: 1 addition & 2 deletions HMpatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace vehiclemod
[HarmonyPatch(typeof(WheelCollider), "LoadWheelCollider")] /* https://github.com/werasik2aa/BringBackComponents */
public class WheelCollider : Collider
{
public extern WheelCollider(IntPtr Value);
public static Il2CppSystem.Type Il2CppType { get; }
public WheelCollider(IntPtr Value) : base (Value) { }
public float radius;
public bool isGrounded { get; }
public float steerAngle;
Expand Down
13 changes: 7 additions & 6 deletions MenuControll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class MenuControll
public static void menuc()
{
GameObject key1 = GameObject.Instantiate(main.lb[0].LoadAsset<GameObject>("menucars"), Vector3.zero, Quaternion.identity);
//GameManager.m_ActiveSceneIsRegion;
key1.transform.Find("Stat").gameObject.SetActive(false);
key1.transform.Find("Menu").gameObject.SetActive(false);
key1.transform.Find("MenuCar").gameObject.SetActive(false);
Expand Down Expand Up @@ -76,20 +75,22 @@ private static void ADDCARS()
}
public static void Update(int i)
{
if (!GetObj(main.targetcar)) return;
InfoMain gg = GetObj(main.targetcar).GetComponent<VehComponent>().vehicleData;
if (i == 0 && CountCars)
{
CountCars.text = main.vehicles.Count.ToString();
}
if (i == 1 && Speed)
{
Speed.maxValue = VehicleController.maxspeed;
Speed.value = VehicleController.curspeed;
CountSpeed.text = Mathf.RoundToInt(VehicleController.curspeed).ToString();
Speed.maxValue = gg.m_MaxSpeed;
Speed.value = gg.m_CurSpeed;
CountSpeed.text = Mathf.RoundToInt(gg.m_CurSpeed).ToString();
}
if (i == 2 && Fuel)
{
Fuel.maxValue = VehicleController.maxfuel;
Fuel.value = VehicleController.curfuel;
Fuel.maxValue = gg.m_MaxFuel;
Fuel.value = gg.m_CurFuel;
}
}
public static void CarStatScreen(string PlayerName, bool allowsit, bool allowdrive, float fuel)
Expand Down
23 changes: 9 additions & 14 deletions NETHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ namespace vehiclemod
{
public static class NETHost
{
public static void NetPacketStat(bool allowdrive, bool allowsit, float fuel, string name)
public static void NetPacketStat(int carId, bool allowdrive, bool allowsit, bool isdrive, bool sound, bool light, float fuel, string name)
{
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(0011);
packet.Write(carId);
packet.Write(allowdrive);
packet.Write(allowsit);
packet.Write(isdrive);
packet.Write(sound);
packet.Write(light);
packet.Write(Mathf.Round(fuel));
packet.Write(name);
Send(packet);
Expand Down Expand Up @@ -73,27 +77,18 @@ public static void NetSpawnCar(string name, Vector3 Position, Quaternion Rotatio

Send(packet);
}
public static void NetSoundOn(int ID)
public static void NetSound(int ID, bool state)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

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

Send(packet);
}
public static void NetSoundOff(int ID)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1110);
packet.Write(ID);

Send(packet);
}
public static void NetLightOn(int ID, bool state)
public static void NetLight(int ID, bool state)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);
Expand Down
49 changes: 18 additions & 31 deletions PACKETS.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using UnityEngine;
using GameServer;
using SkyCoop;
using static vehiclemod.data;

namespace vehiclemod
{
Expand All @@ -19,7 +20,6 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
{
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from)) VehicleController.PlayerCarMove(ID, Position, Rotation);
}

Expand All @@ -32,34 +32,24 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
{
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from)) main.SpawnCar(from, SkyCoop.MyMod.playersData[from].m_Levelid, name, Position, Rotation);
}
if (packetid == 0011) // UPDATE CAR DATA
{
int carid = _pak.ReadInt();
bool allowdrive = _pak.ReadBool();
bool allowsit = _pak.ReadBool();
bool isdrive = _pak.ReadBool();
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();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from)) data.UpdateCarData(from, allowdrive, allowsit, fuel, name);
}
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 (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from)) data.UpdateDriver(ID, drived);
string plname = SkyCoop.MyMod.playersData[from].m_Name;
if (CheckEnv(from)) UpdateCarData(carid, allowdrive, allowsit, isdrive, sound, light, fuel, plname);
}
if (packetid == 1100) // SEND Sound ON
{
Expand All @@ -68,41 +58,38 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
{
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) VehicleController.EngineSound(ID, 1);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) GetObj(ID).GetComponent<VehComponent>().UpdateSound();
}
if (packetid == 1110) // SEND Sound OFF
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 (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) VehicleController.EngineSound(ID, 0);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) UpdatePassanger(ID, SitID, from);
}
if (packetid == 1111) // SIT SIT POS
if (packetid == 1101) // Turn LIGHT
{
int ID = _pak.ReadInt();
int SitID = _pak.ReadInt();
bool state = _pak.ReadBool();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT)
{
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) data.UpdatePassanger(ID, SitID, from);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) GetObj(ID).GetComponent<VehComponent>().UpdateLight();
}
if (packetid == 1101) // Turn LIGHT
if (packetid == 1010) // SEND Driver
{
int ID = _pak.ReadInt();
bool state = _pak.ReadBool();
bool drived = _pak.ReadBool();

if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT)
{
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) VehicleController.CarLight(ID, state);
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.1.1", "NopirateOnlySteam")]
[assembly: MelonInfo(typeof(vehiclemod.main), "VehicleMod", "1.2", "NopirateOnlySteam")]
[assembly: MelonGame("Hinterland", "TheLongDark")]
[assembly: ComVisible(false)]
[assembly: Guid("b1e85fa5-23d9-48b6-9d96-e9afe7c41d28")]
Expand Down
Loading

0 comments on commit 49c852a

Please sign in to comment.