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

43 lines
1.2 KiB
C#
Raw Normal View History

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