2021-02-07 11:09:05 +00:00
|
|
|
|
using Harmony;
|
|
|
|
|
using QSB.Events;
|
2020-12-14 19:31:31 +00:00
|
|
|
|
using QSB.Patches;
|
2021-02-07 11:09:05 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-12-14 21:20:53 +00:00
|
|
|
|
using System.Linq;
|
2021-02-07 11:09:05 +00:00
|
|
|
|
using System.Reflection.Emit;
|
2020-08-13 19:46:16 +00:00
|
|
|
|
|
2020-12-31 12:10:55 +00:00
|
|
|
|
namespace QSB.DeathSync.Patches
|
2020-08-13 19:46:16 +00:00
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class DeathPatches : QSBPatch
|
|
|
|
|
{
|
|
|
|
|
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
|
2020-11-03 21:11:10 +00:00
|
|
|
|
|
2021-02-07 11:09:05 +00:00
|
|
|
|
public override void DoPatches()
|
|
|
|
|
{
|
|
|
|
|
QSBCore.Helper.HarmonyHelper.AddPrefix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(PreFinishDeathSequence));
|
|
|
|
|
QSBCore.Helper.HarmonyHelper.AddPostfix<DeathManager>("KillPlayer", typeof(DeathPatches), nameof(BroadcastDeath));
|
|
|
|
|
QSBCore.Helper.HarmonyHelper.Transpile<ShipDetachableLeg>("Detach", typeof(DeathPatches), nameof(ReturnNull));
|
|
|
|
|
QSBCore.Helper.HarmonyHelper.Transpile<ShipDetachableModule>("Detach", typeof(DeathPatches), nameof(ReturnNull));
|
|
|
|
|
QSBCore.Helper.HarmonyHelper.EmptyMethod<ShipEjectionSystem>("OnPressInteract");
|
|
|
|
|
QSBCore.Helper.HarmonyHelper.AddPostfix<ShipDamageController>("Awake", typeof(DeathPatches), nameof(DamageController_Exploded));
|
2021-02-07 11:26:13 +00:00
|
|
|
|
QSBCore.Helper.HarmonyHelper.AddPrefix<DestructionVolume>("VanishShip", typeof(DeathPatches), nameof(DestructionVolume_VanishShip));
|
2021-02-07 11:09:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public static bool PreFinishDeathSequence(DeathType deathType)
|
|
|
|
|
{
|
2020-12-19 18:49:46 +00:00
|
|
|
|
if (RespawnOnDeath.Instance == null)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
if (RespawnOnDeath.Instance.AllowedDeathTypes.Contains(deathType))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-08-13 19:46:16 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
RespawnOnDeath.Instance.ResetShip();
|
|
|
|
|
RespawnOnDeath.Instance.ResetPlayer();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-08-13 19:46:16 +00:00
|
|
|
|
|
2021-02-09 09:11:35 +00:00
|
|
|
|
public static void BroadcastDeath(DeathType deathType)
|
2021-02-07 11:09:05 +00:00
|
|
|
|
=> GlobalMessenger<DeathType>.FireEvent(EventNames.QSBPlayerDeath, deathType);
|
2020-08-23 13:51:45 +00:00
|
|
|
|
|
2021-02-09 09:11:35 +00:00
|
|
|
|
public static void DamageController_Exploded(ref bool ____exploded)
|
|
|
|
|
=> ____exploded = true;
|
2021-02-07 11:09:05 +00:00
|
|
|
|
|
|
|
|
|
public static IEnumerable<CodeInstruction> ReturnNull(IEnumerable<CodeInstruction> instructions)
|
|
|
|
|
{
|
|
|
|
|
return new List<CodeInstruction>
|
|
|
|
|
{
|
|
|
|
|
new CodeInstruction(OpCodes.Ldnull),
|
|
|
|
|
new CodeInstruction(OpCodes.Ret)
|
|
|
|
|
};
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2021-02-07 11:26:13 +00:00
|
|
|
|
|
|
|
|
|
public static bool DestructionVolume_VanishShip(DeathType ____deathType)
|
|
|
|
|
{
|
2021-02-07 12:51:35 +00:00
|
|
|
|
if (RespawnOnDeath.Instance == null)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-07 11:26:13 +00:00
|
|
|
|
if (PlayerState.IsInsideShip() || PlayerState.UsingShipComputer() || PlayerState.AtFlightConsole())
|
|
|
|
|
{
|
|
|
|
|
Locator.GetDeathManager().KillPlayer(____deathType);
|
|
|
|
|
}
|
2021-02-07 12:51:35 +00:00
|
|
|
|
// Ship is being destroyed, but player isn't in it.
|
|
|
|
|
RespawnOnDeath.Instance.ResetShip();
|
2021-02-07 11:26:13 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2020-08-13 19:46:16 +00:00
|
|
|
|
}
|