using Harmony; using OWML.ModHelper.Events; using System.Collections.Generic; using System.Reflection.Emit; using UnityEngine; namespace QSB.DeathSync { public class PreventShipDestruction : MonoBehaviour { public void Awake() { QSBCore.Helper.HarmonyHelper.Transpile("Detach", typeof(Patch), nameof(Patch.ReturnNull)); QSBCore.Helper.HarmonyHelper.Transpile("Detach", typeof(Patch), nameof(Patch.ReturnNull)); QSBCore.Helper.HarmonyHelper.EmptyMethod("OnPressInteract"); QSBCore.Helper.Events.Subscribe(OWML.Common.Events.AfterAwake); QSBCore.Helper.Events.Event += OnEvent; } private void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev) { if (behaviour is ShipDamageController shipDamageController && ev == OWML.Common.Events.AfterAwake) { shipDamageController.SetValue("_exploded", true); } } private static class Patch { public static IEnumerable ReturnNull(IEnumerable instructions) { return new List { new CodeInstruction(OpCodes.Ldnull), new CodeInstruction(OpCodes.Ret) }; } } } }