Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified References/SmashTools.dll
Binary file not shown.
Binary file modified References/Vehicles.dll
Binary file not shown.
42 changes: 39 additions & 3 deletions Source/Mods/VanillaVehiclesExpanded.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using System.Reflection;
using HarmonyLib;
using Multiplayer.API;
using Verse;

Expand All @@ -9,10 +10,13 @@ namespace Multiplayer.Compat
[MpCompatFor("OskarPotocki.VanillaVehiclesExpanded")]
public class VanillaVehiclesExpanded
{
// handbrakeDealsDamage is a per-player mod setting that causes desync
// when it differs between host and client (Messages.Message consumes unique ID)
private static FieldInfo handbrakeDealsDamageField;
private static bool savedHandbrakeValue;

public VanillaVehiclesExpanded(ModContentPack mod)
{
MpSyncWorkers.Requires<Designation>();

var type = AccessTools.TypeByName("VanillaVehiclesExpanded.GarageDoor");

// Open (0), close (2), and cancel (1, 3)
Expand All @@ -36,6 +40,38 @@ public VanillaVehiclesExpanded(ModContentPack mod)
type = AccessTools.TypeByName("VanillaVehiclesExpanded.CompVehicleWreck");
// Restore (0)/cancel (1)
MpCompat.RegisterLambdaDelegate(type, nameof(ThingComp.CompGetGizmosExtra), 0, 1);

// Force handbrakeDealsDamage to consistent value in MP.
// This per-player setting controls whether Messages.Message is called
// during vehicle slowdown, which consumes a unique ID and causes desync.
var settingsType = AccessTools.TypeByName("VanillaVehiclesExpanded.VanillaVehiclesExpandedSettings");
handbrakeDealsDamageField = AccessTools.Field(settingsType, "handbrakeDealsDamage");

var slowdownMethod = AccessTools.DeclaredMethod(
AccessTools.TypeByName("VanillaVehiclesExpanded.CompVehicleMovementController"), "Slowdown");
if (slowdownMethod != null && handbrakeDealsDamageField != null)
{
MpCompat.harmony.Patch(slowdownMethod,
prefix: new HarmonyMethod(typeof(VanillaVehiclesExpanded), nameof(PreSlowdown)),
postfix: new HarmonyMethod(typeof(VanillaVehiclesExpanded), nameof(PostSlowdown)));
}
}

private static void PreSlowdown()
{
if (!MP.IsInMultiplayer)
return;

savedHandbrakeValue = (bool)handbrakeDealsDamageField.GetValue(null);
handbrakeDealsDamageField.SetValue(null, true); // Force default (true) for consistency
}

private static void PostSlowdown()
{
if (!MP.IsInMultiplayer)
return;

handbrakeDealsDamageField.SetValue(null, savedHandbrakeValue);
}
}
}
1 change: 1 addition & 0 deletions Source_Referenced/Multiplayer_Compat_Referenced.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

<ItemGroup>
<Publicize Include="Assembly-CSharp" />
<Publicize Include="Vehicles" />
<Publicize Include="VFEC" />
<Publicize Include="VFEEmpire" />
</ItemGroup>
Expand Down
Loading