make sure detachable isnt recursive

This commit is contained in:
JohnCorby 2022-05-19 15:31:05 -07:00
parent 8f797a22ab
commit db69f220eb
6 changed files with 58 additions and 40 deletions

View File

@ -29,7 +29,6 @@ public class PlayerJoinMessage : QSBMessage
FirstIncompatibleMod = "";
#if RELEASE
foreach (var mod in allEnabledMods)
{
if (QSBCore.IncompatibleMods.Contains(mod.ModHelper.Manifest.UniqueName))
@ -37,7 +36,6 @@ public class PlayerJoinMessage : QSBMessage
FirstIncompatibleMod = mod.ModHelper.Manifest.UniqueName;
}
}
#endif
AddonHashes = QSBCore.Addons.Keys
.Select(x => x.GetStableHashCode())

View File

@ -0,0 +1,11 @@
using QSB.Messaging;
using QSB.Patches;
using QSB.ShipSync.WorldObjects;
namespace QSB.ShipSync.Messages;
internal class LegDetachMessage : QSBWorldObjectMessage<QSBShipDetachableLeg>
{
public override void OnReceiveRemote() =>
QSBPatch.RemoteCall(WorldObject.AttachedObject.Detach);
}

View File

@ -1,17 +1,11 @@
using QSB.Messaging;
using QSB.Patches;
using QSB.ShipSync.WorldObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QSB.ShipSync.Messages;
internal class ModuleDetachMessage : QSBWorldObjectMessage<QSBShipDetachableModule>
{
public override void OnReceiveRemote()
{
WorldObject.AttachedObject.Detach();
}
public override void OnReceiveRemote() =>
QSBPatch.RemoteCall(WorldObject.AttachedObject.Detach);
}

View File

@ -3,9 +3,7 @@ using QSB.Messaging;
using QSB.Patches;
using QSB.ShipSync.Messages;
using QSB.ShipSync.WorldObjects;
using QSB.Utility;
using QSB.WorldSync;
using UnityEngine;
namespace QSB.ShipSync.Patches;
@ -14,10 +12,47 @@ internal class ShipDetachableModulePatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPostfix]
[HarmonyPrefix]
[HarmonyPatch(nameof(ShipDetachableModule.Detach))]
public static void Detach(ShipDetachableModule __instance)
{
if (Remote)
{
return;
}
if (__instance.isDetached)
{
return;
}
if (!QSBWorldSync.AllObjectsReady)
{
return;
}
__instance.GetWorldObject<QSBShipDetachableModule>().SendMessage(new ModuleDetachMessage());
}
[HarmonyPrefix]
[HarmonyPatch(nameof(ShipDetachableLeg.Detach))]
public static void Detach(ShipDetachableLeg __instance)
{
if (Remote)
{
return;
}
if (__instance.isDetached)
{
return;
}
if (!QSBWorldSync.AllObjectsReady)
{
return;
}
__instance.GetWorldObject<QSBShipDetachableLeg>().SendMessage(new LegDetachMessage());
}
}

View File

@ -13,12 +13,12 @@ internal class ShipLegTransformSync : SectoredRigidbodySync, ILinkedNetworkBehav
/// </summary>
protected override bool CheckValid()
=> AttachedTransform
&& base.CheckValid();
&& base.CheckValid();
protected override bool CheckReady()
=> _qsbModule != null
&& _qsbModule.AttachedObject.isDetached
&& base.CheckReady();
&& _qsbModule.AttachedObject.isDetached
&& base.CheckReady();
protected override bool UseInterpolation => true;
protected override float DistanceChangeThreshold => 1f;
@ -32,14 +32,4 @@ internal class ShipLegTransformSync : SectoredRigidbodySync, ILinkedNetworkBehav
SectorDetector.Init(owRigidbody.transform.Find("DetectorVolume").GetComponent<SectorDetector>());
return owRigidbody;
}
protected override void ApplyToAttached()
{
if (!_qsbModule.AttachedObject.isDetached)
{
return;
}
base.ApplyToAttached();
}
}

View File

@ -13,12 +13,12 @@ internal class ShipModuleTransformSync : SectoredRigidbodySync, ILinkedNetworkBe
/// </summary>
protected override bool CheckValid()
=> AttachedTransform
&& base.CheckValid();
&& base.CheckValid();
protected override bool CheckReady()
=> _qsbModule != null
&& _qsbModule.AttachedObject.isDetached
&& base.CheckReady();
&& _qsbModule.AttachedObject.isDetached
&& base.CheckReady();
protected override bool UseInterpolation => true;
protected override float DistanceChangeThreshold => 1f;
@ -32,14 +32,4 @@ internal class ShipModuleTransformSync : SectoredRigidbodySync, ILinkedNetworkBe
SectorDetector.Init(owRigidbody.transform.Find("DetectorVolume").GetComponent<SectorDetector>());
return owRigidbody;
}
protected override void ApplyToAttached()
{
if (!_qsbModule.AttachedObject.isDetached)
{
return;
}
base.ApplyToAttached();
}
}