using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Lethal_Doors.Patches;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Lethal_Doors")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Lethal_Doors")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1ea0c483-aa76-456d-a6d6-bec546f69e11")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Lethal_Doors.Patches
{
[HarmonyPatch(typeof(HangarShipDoor))]
internal class DoorInteractionPatch
{
private static readonly Vector3 doorPosition = new Vector3(-5.72f, 0.305f, -14.1f);
private static float doorClosingTimer = -1f;
private static readonly float doorClosingDuration = 0.3f;
private static readonly HashSet<int> affectedPlayers = new HashSet<int>();
[HarmonyPostfix]
[HarmonyPatch("Update")]
private static void PostfixUpdate(HangarShipDoor __instance)
{
string text = DoorState(__instance.shipDoorsAnimator);
if (IsDoorClosing(__instance))
{
if (doorClosingTimer < 0f)
{
doorClosingTimer = 0f;
if (!IsDoorClosed(__instance.shipDoorsAnimator))
{
affectedPlayers.Clear();
}
}
if (doorClosingTimer < doorClosingDuration && IsDoorClosed(__instance.shipDoorsAnimator))
{
CheckForPlayersAndApplyDamage();
CheckForMouthDogsAndApplyDamage();
}
else
{
affectedPlayers.Clear();
}
doorClosingTimer += Time.deltaTime;
}
else
{
doorClosingTimer = -1f;
}
}
private static bool IsDoorClosing(HangarShipDoor door)
{
return door.doorPower < 1f;
}
private static void CheckForPlayersAndApplyDamage()
{
Debug.Log((object)"[Lethal Doors] Checking for players to apply damage");
if (!((Object)(object)StartOfRound.Instance != (Object)null) || StartOfRound.Instance.allPlayerScripts == null)
{
return;
}
PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
foreach (PlayerControllerB val in allPlayerScripts)
{
if ((Object)(object)val != (Object)null && IsPlayerInDangerZone(val))
{
int item = (int)val.playerClientId;
if (!affectedPlayers.Contains(item))
{
Debug.Log((object)("[Lethal Doors] Player " + val.playerUsername + " is in danger zone"));
ApplyLethalDamageOrInjurePlayer(val);
affectedPlayers.Add(item);
Debug.Log((object)"[Lethal Doors] Added to affected list added");
}
}
}
}
private static bool IsPlayerInDangerZone(PlayerControllerB player)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
float num = 1f;
return Vector3.Distance(((Component)player).transform.position, doorPosition) < num;
}
private static bool IsEnemyInDangerZone(EnemyAI enemy)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
float num = 2f;
return Vector3.Distance(((Component)enemy).transform.position, doorPosition) < num;
}
private static void ApplyLethalDamageOrInjurePlayer(PlayerControllerB player)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)$"[Lethal Doors] {player.playerUsername} in danger zone, Position:{((Component)player).transform.position} ");
Debug.Log((object)("[Lethal Doors] Applying lethal damange to player " + player.playerUsername));
if (player.criticallyInjured || Random.Range(0, 2) == 0)
{
player.DamagePlayer(110, true, true, (CauseOfDeath)8, 0, false, default(Vector3));
Debug.Log((object)$"[Lethal Doors] Heads: kill player ClientID:{(int)player.playerClientId} ");
return;
}
Debug.Log((object)$"[Lethal Doors] Tails: injure player ClientID:{(int)player.playerClientId} ");
player.DamagePlayer(90, true, true, (CauseOfDeath)8, 0, false, default(Vector3));
player.AddBloodToBody();
player.MakeCriticallyInjuredServerRpc();
affectedPlayers.Add((int)player.playerClientId);
}
private static bool IsDoorClosed(Animator animator)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
AnimatorStateInfo currentAnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(0);
return ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("ShipDoorClose");
}
private static string DoorState(Animator animator)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
AnimatorStateInfo currentAnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(0);
return ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("ShipDoorOpen") ? "ShipDoorOpen" : (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("ShipDoorClose") ? "ShipDoorClose" : "Unknown");
}
private static void CheckForMouthDogsAndApplyDamage()
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
RoundManager val = Object.FindObjectOfType<RoundManager>();
if (!((Object)(object)val != (Object)null) || val.SpawnedEnemies == null)
{
return;
}
foreach (EnemyAI spawnedEnemy in val.SpawnedEnemies)
{
if ((Object)(object)spawnedEnemy != (Object)null && IsEnemyInDangerZone(spawnedEnemy))
{
Debug.Log((object)$"[Lethal Doors] {((Object)spawnedEnemy).name} is in danger zone at position {((Component)spawnedEnemy).transform.position}");
spawnedEnemy.HitEnemy(999, (PlayerControllerB)null, false);
spawnedEnemy.KillEnemy(false);
Debug.Log((object)("[Lethal Doors] " + ((Object)spawnedEnemy).name + " killed"));
}
}
}
private static void LogEnemyPositions()
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
RoundManager val = Object.FindObjectOfType<RoundManager>();
if (!((Object)(object)val != (Object)null) || val.SpawnedEnemies == null)
{
return;
}
foreach (EnemyAI spawnedEnemy in val.SpawnedEnemies)
{
if ((Object)(object)spawnedEnemy != (Object)null && ((Object)((Component)spawnedEnemy).gameObject).name == "MouthDog(Clone)")
{
Debug.Log((object)$"{((Object)spawnedEnemy).name}: {((Component)spawnedEnemy).transform.position}");
}
}
}
[ServerRpc(RequireOwnership = false)]
private static void KillPlayerServerRpc(int playerId)
{
NetworkManager singleton = NetworkManager.Singleton;
if ((Object)(object)singleton != (Object)null && singleton.IsListening)
{
KillPlayerClientRpc(playerId);
}
}
[ClientRpc]
private static void KillPlayerClientRpc(int playerId)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
NetworkManager singleton = NetworkManager.Singleton;
if ((Object)(object)singleton != (Object)null && singleton.IsListening)
{
PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerId];
if ((Object)(object)val != (Object)null)
{
val.KillPlayer(Vector3.zero, true, (CauseOfDeath)8, 0);
}
}
}
private static void LogDoorAnimationDuration(HangarShipDoor door)
{
if ((Object)(object)door == (Object)null || (Object)(object)door.shipDoorsAnimator == (Object)null)
{
Debug.LogError((object)"Door component not found!");
return;
}
string text = "ShipDoorClose";
float animationDuration = GetAnimationDuration(door.shipDoorsAnimator, text);
if (animationDuration >= 0f)
{
Debug.Log((object)$"Duration of {text}: {animationDuration} seconds");
}
else
{
Debug.LogError((object)("Animation " + text + " not found!"));
}
}
private static float GetAnimationDuration(Animator animator, string animationName)
{
RuntimeAnimatorController runtimeAnimatorController = animator.runtimeAnimatorController;
AnimationClip[] animationClips = runtimeAnimatorController.animationClips;
foreach (AnimationClip val in animationClips)
{
if (((Object)val).name == animationName)
{
return val.length;
}
}
return -1f;
}
private static void LogAllAnimationNames(HangarShipDoor door)
{
if ((Object)(object)door == (Object)null || (Object)(object)door.shipDoorsAnimator == (Object)null)
{
Debug.LogError((object)"Door or Animator component not found!");
return;
}
RuntimeAnimatorController runtimeAnimatorController = door.shipDoorsAnimator.runtimeAnimatorController;
Debug.Log((object)"Logging all animation names:");
AnimationClip[] animationClips = runtimeAnimatorController.animationClips;
foreach (AnimationClip val in animationClips)
{
Debug.Log((object)((Object)val).name);
}
}
}
}
namespace LethalDoors
{
[BepInPlugin("saintk.LethalDoors", "Lethal Doors", "1.0.0.0")]
public class LethalDoors : BaseUnityPlugin
{
private const string modGUID = "saintk.LethalDoors";
private const string modName = "Lethal Doors";
private const string modVersion = "1.0.0.0";
private readonly Harmony harmony = new Harmony("saintk.LethalDoors");
internal ManualLogSource mls;
public static LethalDoors Instance { get; private set; }
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("saintk.LethalDoors");
mls.LogInfo((object)"saintkendrick's Lethal Doors Mod");
harmony.PatchAll(typeof(DoorInteractionPatch));
mls.LogInfo((object)"saintkendrick's Door Patch");
}
public static void Log(string message)
{
if ((Object)(object)Instance != (Object)null)
{
Instance.mls.LogInfo((object)message);
}
}
}
}