quantum-space-buddies/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs

59 lines
1.1 KiB
C#
Raw Normal View History

2022-05-14 11:18:48 +00:00
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;
2022-05-19 22:31:05 +00:00
[HarmonyPrefix]
2022-05-14 11:18:48 +00:00
[HarmonyPatch(nameof(ShipDetachableModule.Detach))]
public static void Detach(ShipDetachableModule __instance)
{
2022-05-19 22:31:05 +00:00
if (Remote)
{
return;
}
if (__instance.isDetached)
{
return;
}
if (!QSBWorldSync.AllObjectsReady)
{
return;
}
2022-05-14 11:18:48 +00:00
__instance.GetWorldObject<QSBShipDetachableModule>().SendMessage(new ModuleDetachMessage());
}
2022-05-19 22:31:05 +00:00
[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());
}
2022-05-14 11:18:48 +00:00
}