quantum-space-buddies/QSB/DeathSync/PreventShipDestruction.cs

44 lines
1.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Reflection.Emit;
using Harmony;
using OWML.ModHelper.Events;
using UnityEngine;
2020-08-13 21:46:16 +02:00
namespace QSB.DeathSync
{
public class PreventShipDestruction : MonoBehaviour
{
private void Awake()
{
2020-08-10 18:17:54 +02:00
QSB.Helper.HarmonyHelper.Transpile<ShipDetachableLeg>("Detach", typeof(Patch), nameof(Patch.ReturnNull));
QSB.Helper.HarmonyHelper.Transpile<ShipDetachableModule>("Detach", typeof(Patch), nameof(Patch.ReturnNull));
QSB.Helper.HarmonyHelper.EmptyMethod<ShipEjectionSystem>("OnPressInteract");
QSB.Helper.Events.Subscribe<ShipDamageController>(OWML.Common.Events.AfterAwake);
2020-08-10 18:17:54 +02:00
QSB.Helper.Events.Event += OnEvent;
}
private void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
{
2020-07-28 15:59:24 +02:00
if (behaviour is ShipDamageController shipDamageController &&
ev == OWML.Common.Events.AfterAwake)
{
2020-07-28 15:59:24 +02:00
shipDamageController.SetValue("_exploded", true);
}
}
private static class Patch
{
public static IEnumerable<CodeInstruction> ReturnNull(IEnumerable<CodeInstruction> instructions)
{
return new List<CodeInstruction>
{
new CodeInstruction(OpCodes.Ldnull),
new CodeInstruction(OpCodes.Ret)
};
}
}
}
}