quantum-space-buddies/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs
2022-05-19 15:31:05 -07:00

59 lines
1.1 KiB
C#

using HarmonyLib;
using QSB.Messaging;
using QSB.Patches;
using QSB.ShipSync.Messages;
using QSB.ShipSync.WorldObjects;
using QSB.WorldSync;
namespace QSB.ShipSync.Patches;
[HarmonyPatch(typeof(ShipDetachableModule))]
internal class ShipDetachableModulePatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[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());
}
}