Add toggle mods sync

This commit is contained in:
Sardelka9515 2023-03-23 22:30:39 +08:00
parent e6718cec58
commit 114e59a3bd
6 changed files with 29 additions and 18 deletions

View File

@ -341,6 +341,7 @@ namespace RageCoop.Client
v.DamageModel = packet.DamageModel;
v.EngineHealth = packet.EngineHealth;
v.Mods = packet.Mods;
v.ToggleModsMask = packet.ToggleModsMask;
v.Model = packet.ModelHash;
v.Colors = packet.Colors;
v.LandingGear = packet.LandingGear;

View File

@ -130,7 +130,7 @@ namespace RageCoop.Client
packet.DamageModel = veh.GetVehicleDamageModel();
packet.LandingGear = veh.IsAircraft ? (byte)veh.LandingGearState : (byte)0;
packet.RoofState = (byte)veh.RoofState;
packet.Mods = veh.Mods.GetVehicleMods();
packet.Mods = v.GetVehicleMods(out packet.ToggleModsMask);
packet.ModelHash = veh.Model.Hash;
packet.EngineHealth = veh.EngineHealth;
packet.LockStatus = veh.LockStatus;

View File

@ -32,6 +32,7 @@ namespace RageCoop.Client
internal int Livery { get; set; } = -1;
internal VehicleDataFlags Flags { get; set; }
internal ushort ExtrasMask;
internal byte ToggleModsMask;
#endregion
@ -67,7 +68,7 @@ namespace RageCoop.Client
#endregion
#region PRIVATE
private byte _lastToggleMods;
private (byte, byte) _lastVehicleColors;
private ushort _lastExtras;
private (int, int)[] _lastVehicleMods = Array.Empty<(int, int)>();

View File

@ -131,16 +131,24 @@ namespace RageCoop.Client
_lastVehicleColors = Colors;
}
MainVehicle.EngineHealth = EngineHealth;
if (Mods != null && !Mods.SequenceEqual(_lastVehicleMods))
{
Call(SET_VEHICLE_MOD_KIT, MainVehicle, 0);
foreach (var mod in Mods) MainVehicle.Mods[(VehicleModType)mod.Item1].Index = mod.Item2;
_lastVehicleMods = Mods;
}
if (ToggleModsMask != _lastToggleMods)
{
for (int i = 0; i < 7; i++)
{
Call(TOGGLE_VEHICLE_MOD, MainVehicle.Handle, i + 17, (ToggleModsMask & (1 << i)) != 0);
}
_lastToggleMods = ToggleModsMask;
}
if (Call<string>(GET_VEHICLE_NUMBER_PLATE_TEXT, MainVehicle) != LicensePlate)
Call(SET_VEHICLE_NUMBER_PLATE_TEXT, MainVehicle, LicensePlate);

View File

@ -47,14 +47,22 @@ namespace RageCoop.Client
return flags;
}
public static (int, int)[] GetVehicleMods(this VehicleModCollection mods)
public static (int, int)[] GetVehicleMods(this SyncedVehicle sv, out byte togglesMask)
{
var modsArr = mods.ToArray();
var modsArr = sv.MainVehicle.Mods.ToArray();
var result = new (int, int)[modsArr.Length];
for (int i = 0; i < modsArr.Length; i++)
{
result[i] = ((int)modsArr[i].Type, modsArr[i].Index);
}
togglesMask = 0;
for (int i = 0; i < 6; i++)
{
if (Call<bool>(IS_TOGGLE_MOD_ON, sv.MainVehicle.Handle, i + 17))
{
togglesMask |= (byte)(1 << i);
}
}
return result;
}
@ -154,17 +162,6 @@ namespace RageCoop.Client
veh.IsRightHeadLightBroken = model.RightHeadLightBroken > 0;
}
public static Dictionary<int, int> GetPassengers(this Vehicle veh)
{
var ps = new Dictionary<int, int>();
var d = veh.Driver;
if (d != null && d.IsSittingInVehicle()) ps.Add(-1, d.GetSyncEntity().ID);
foreach (var p in veh.Passengers)
if (p.IsSittingInVehicle())
ps.Add((int)p.SeatIndex, p.GetSyncEntity().ID);
return ps;
}
public static void SetDeluxoHoverState(this Vehicle deluxo, bool hover)
{
Call(SET_SPECIAL_FLIGHT_MODE_TARGET_RATIO, deluxo, hover ? 1f : 0f);

View File

@ -63,7 +63,6 @@ namespace RageCoop.Core
// Write vehicle mods
// Write the count of mods
m.Write((short)Mods.Length);
// Loop the dictionary and add the values
foreach (var mod in Mods)
{
// Write the mod value
@ -71,6 +70,8 @@ namespace RageCoop.Core
m.Write(mod.Item2);
}
m.Write(ToggleModsMask);
if (!DamageModel.Equals(default(VehicleDamageModel)))
{
// Write boolean = true
@ -150,6 +151,8 @@ namespace RageCoop.Core
// Read the mod value
Mods[i] = (m.ReadInt32(), m.ReadInt32());
ToggleModsMask = m.ReadByte();
if (m.ReadBoolean())
// Read vehicle damage model
DamageModel = new VehicleDamageModel
@ -189,6 +192,7 @@ namespace RageCoop.Core
public (int, int)[] Mods { get; set; }
public byte ToggleModsMask;
public VehicleDamageModel DamageModel { get; set; }
public byte LandingGear { get; set; }