using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using EmergencyTakeoff.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RadiationIsCool")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RadiationIsCool")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8ee335db-0cbe-470c-8fbc-69263f01b35a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace EmergencyTakeoff
{
[BepInPlugin("Piggy.EmergencyTakeoff", "EmergencyTakeoff", "1.0.0")]
public class EmergencyTakeoffModBase : BaseUnityPlugin
{
private const string modGUID = "Piggy.EmergencyTakeoff";
private const string modName = "EmergencyTakeoff";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("Piggy.EmergencyTakeoff");
private static EmergencyTakeoffModBase Instance;
public static ManualLogSource mls;
public static int EventProbability;
public static float maxProbability;
public static float minProbability;
public static bool showMessage;
public static bool showTimer;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("Piggy.EmergencyTakeoff");
mls.LogInfo((object)"Emergency Takeoff is loaded");
EventProbability = ((BaseUnityPlugin)this).Config.Bind<int>("General", "EventProbability", 10, "Chance of emergency return occurring (Probability and numbers are inversely proportional. If set to 1, it will always occur.)").Value;
maxProbability = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaximumProbabilityIncrease", 0.5f, "This is the maximum value at which the probability increases continuously. Must be higher than the minimum.").Value;
minProbability = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MinimumProbabilityIncrease", 0.3f, "It is the minimum value at which the probability increases continuously. It must be lower than the maximum.").Value;
showMessage = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowTipMessage", false, "If enabled, displays a message after landing if the probability of an event occurring exists.").Value;
showTimer = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowTimer", true, "Shows the departure timer in the lower left corner.").Value;
StartOfRoundPatch.eventProbability = EventProbability;
TimeOfDayPatch.minimumIncrease = minProbability;
TimeOfDayPatch.maximumIncrease = maxProbability;
StartOfRoundPatch.messageEnabled = showMessage;
HUDManagerPatch.isTimerEnabled = showTimer;
harmony.PatchAll(typeof(EmergencyTakeoffModBase));
harmony.PatchAll(typeof(TimeOfDayPatch));
harmony.PatchAll(typeof(StartOfRoundPatch));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(HUDManagerPatch));
harmony.PatchAll(typeof(WalkieTalkiePatch));
harmony.PatchAll(typeof(GameNetworkManagerPatch));
harmony.PatchAll(typeof(EmergencyActivatedBool));
harmony.PatchAll(typeof(EmergencyBool));
}
}
}
namespace EmergencyTakeoff.Patches
{
public static class EmergencyActivatedBool
{
public static bool leavingActivated;
}
[HarmonyPatch(typeof(HUDManager))]
internal class HUDManagerPatch
{
public static TextMeshProUGUI TimerTextGUI;
public static bool isTimerActivated;
public static bool isTimerEnabled = EmergencyTakeoffModBase.showTimer;
public static HUDManager hudManager;
[HarmonyPostfix]
[HarmonyPatch("Awake")]
private static void Awake_Postfix(ref HUDManager __instance)
{
hudManager = __instance;
if (GameNetworkManager.Instance.isHostingGame)
{
SetupHUDTimerRPC();
}
}
[ClientRpc]
public static void SetupHUDTimerRPC()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_004b: 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_007c: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("TimerText");
val.AddComponent<RectTransform>();
TimerTextGUI = val.AddComponent<TextMeshProUGUI>();
RectTransform rectTransform = ((TMP_Text)TimerTextGUI).rectTransform;
((Transform)rectTransform).SetParent(GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD").transform, false);
rectTransform.sizeDelta = new Vector2(600f, 200f);
rectTransform.anchoredPosition = new Vector2(-60f, -200f);
((Transform)rectTransform).rotation = Quaternion.Euler(19.4f, -11.7f, 0f);
((TMP_Text)TimerTextGUI).alignment = (TextAlignmentOptions)513;
((TMP_Text)TimerTextGUI).font = ((TMP_Text)hudManager.controlTipLines[0]).font;
((TMP_Text)TimerTextGUI).fontSize = 30f;
}
[HarmonyPrefix]
[HarmonyPatch("Update")]
private static void Update_Prefix()
{
if (!isTimerActivated || !isTimerEnabled)
{
((TMP_Text)TimerTextGUI).text = "";
}
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
[HarmonyPrefix]
[HarmonyPatch("LeaveCurrentSteamLobby")]
private static void LeaveCurrentSteamLobby_PreFix()
{
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
HUDManagerPatch.isTimerActivated = false;
EmergencyActivatedBool.leavingActivated = false;
EmergencyBool.canBeLeave = false;
PlayerControllerBPatch.timerFloat = 60f;
PlayerControllerBPatch.timerString = "";
PlayerControllerBPatch.textFlickered = false;
TimeOfDayPatch.randomTriggerTimer = 0f;
TimeOfDayPatch.randomTriggerPercentage = 0f;
TimeOfDayPatch.randomTriggerCurrentPercentage = 100f;
TimeOfDayPatch.isMessaged = false;
TimeOfDayPatch.isNotCalled = true;
TimeOfDayPatch.normalizedTimeOfDayB = 0f;
TimeOfDayPatch.shipLeaveAutomaticallyTimeB = 0f;
((Graphic)GameObject.Find("SprintMeter").GetComponent<Image>()).color = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)118, (byte)0, byte.MaxValue));
if ((Object)(object)Object.FindAnyObjectByType<ShipTeleporter>() != (Object)null)
{
ShipTeleporter[] array = Object.FindObjectsOfType<ShipTeleporter>();
ShipTeleporter[] array2 = array;
foreach (ShipTeleporter val in array2)
{
val.buttonTrigger.interactable = true;
}
}
}
}
[HarmonyPatch(typeof(WalkieTalkie))]
internal class WalkieTalkiePatch
{
[HarmonyPrefix]
[HarmonyPatch("TimeAllAudioSources")]
private static void TimeAllAudioSources_PreFix()
{
if (!EmergencyActivatedBool.leavingActivated)
{
}
}
[HarmonyPostfix]
[HarmonyPatch("Update")]
private static void Update_PostFix(ref AudioClip ___playerDieOnWalkieTalkieSFX, ref AudioSource ___thisAudio, ref bool ___isBeingUsed)
{
if (!EmergencyActivatedBool.leavingActivated)
{
return;
}
if (___isBeingUsed)
{
___thisAudio.clip = ___playerDieOnWalkieTalkieSFX;
___thisAudio.loop = true;
if (!___thisAudio.isPlaying)
{
___thisAudio.Play();
}
}
else
{
___thisAudio.loop = false;
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch : MonoBehaviour
{
public static float timerFloat;
public static string timerString;
public static bool textFlickered;
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void Start_PostFix()
{
timerFloat = 60f;
}
[HarmonyPrefix]
[HarmonyPatch("Update")]
private static void Update_PreFix(ref float ___sprintMeter)
{
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
if (EmergencyActivatedBool.leavingActivated)
{
((Component)Object.FindObjectOfType<ShipLights>()).GetComponent<ShipLights>().areLightsOn = false;
((Component)Object.FindObjectOfType<ShipLights>()).GetComponent<ShipLights>().shipLightsAnimator.SetBool("lightsOn", false);
___sprintMeter = 1f;
if (timerFloat > 0f)
{
timerFloat -= Time.deltaTime / 4f;
}
if (timerFloat < 0f && !textFlickered)
{
timerFloat = 0f;
((TMP_Text)HUDManagerPatch.TimerTextGUI).text = "<color=red>00:00</color>";
textFlickered = true;
}
else
{
timerString = (Mathf.Floor(timerFloat * 100f) / 100f).ToString();
}
if (timerFloat >= 10f)
{
((TMP_Text)HUDManagerPatch.TimerTextGUI).text = timerString;
}
else if (!textFlickered && timerFloat > 0f && timerFloat < 10f)
{
((TMP_Text)HUDManagerPatch.TimerTextGUI).text = "<color=red>0" + timerString + "</color>";
}
if (timerFloat <= 0f)
{
}
((Graphic)GameObject.Find("SprintMeter").GetComponent<Image>()).color = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue));
}
else
{
((Graphic)GameObject.Find("SprintMeter").GetComponent<Image>()).color = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)118, (byte)0, byte.MaxValue));
}
}
}
public static class EmergencyBool
{
public static bool canBeLeave;
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
public static int eventProbability = EmergencyTakeoffModBase.EventProbability;
public static bool messageEnabled = EmergencyTakeoffModBase.showMessage;
[HarmonyPrefix]
[HarmonyPatch("OnShipLandedMiscEvents")]
private static void OnShipLandedMiscEvents_Patch()
{
if (Random.Range(0, eventProbability) == 0)
{
EmergencyBool.canBeLeave = true;
EmergencyTakeoffModBase.mls.LogInfo((object)$"canbeleave");
}
else
{
EmergencyBool.canBeLeave = false;
EmergencyTakeoffModBase.mls.LogInfo((object)$"cannotbeleave");
}
if (EmergencyBool.canBeLeave && GameNetworkManager.Instance.isHostingGame && messageEnabled)
{
ShipEmergencyTextRPC();
}
}
public static void ShipEmergencyText()
{
HUDManager.Instance.DisplayTip("???", "Something feels different today.", false, false, "LC_WhatIsThisThingy");
}
[ClientRpc]
public static void ShipEmergencyTextRPC()
{
ShipEmergencyText();
}
[HarmonyPrefix]
[HarmonyPatch("ShipHasLeft")]
private static void ShipHasLeft_Patch()
{
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
HUDManagerPatch.isTimerActivated = false;
EmergencyActivatedBool.leavingActivated = false;
EmergencyBool.canBeLeave = false;
PlayerControllerBPatch.timerFloat = 60f;
PlayerControllerBPatch.timerString = "";
PlayerControllerBPatch.textFlickered = false;
TimeOfDayPatch.randomTriggerTimer = 0f;
TimeOfDayPatch.randomTriggerPercentage = 0f;
TimeOfDayPatch.randomTriggerCurrentPercentage = 100f;
TimeOfDayPatch.isMessaged = false;
TimeOfDayPatch.isNotCalled = true;
TimeOfDayPatch.normalizedTimeOfDayB = 0f;
TimeOfDayPatch.shipLeaveAutomaticallyTimeB = 0f;
((Graphic)GameObject.Find("SprintMeter").GetComponent<Image>()).color = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)118, (byte)0, byte.MaxValue));
if ((Object)(object)Object.FindAnyObjectByType<ShipTeleporter>() != (Object)null)
{
ShipTeleporter[] array = Object.FindObjectsOfType<ShipTeleporter>();
ShipTeleporter[] array2 = array;
foreach (ShipTeleporter val in array2)
{
val.buttonTrigger.interactable = true;
}
}
}
}
[HarmonyPatch(typeof(TimeOfDay))]
internal class TimeOfDayPatch
{
public static bool isWeathed;
public static float randomTriggerTimer;
public static float randomTriggerPercentage;
public static float randomTriggerCurrentPercentage = 100f;
public static bool isMessaged;
public static bool isNotCalled;
public static float normalizedTimeOfDayB;
public static float shipLeaveAutomaticallyTimeB;
public static DialogueSegment[] shipLeavingEarlyDialogueB;
public static float minimumIncrease = EmergencyTakeoffModBase.minProbability;
public static float maximumIncrease = EmergencyTakeoffModBase.maxProbability;
[HarmonyPrefix]
[HarmonyPatch("Awake")]
private static void Awake_Patch()
{
randomTriggerPercentage = 0f;
randomTriggerCurrentPercentage = 100f;
isNotCalled = true;
}
[HarmonyPrefix]
[HarmonyPatch("Start")]
private static void Start_Patch(ref DialogueSegment[] ___shipLeavingEarlyDialogue)
{
___shipLeavingEarlyDialogue[0].speakerText = "PILOT COMPUTER";
___shipLeavingEarlyDialogue[0].bodyText = "WARNING!!! A major disaster is expected in the area, and the ship will leave automatically in a moment.\nThe suit has activated emergency mode. Escape immediately.";
}
[HarmonyPostfix]
[HarmonyPatch("Update")]
private static void Update_PostFix(ref float ___normalizedTimeOfDay, ref float ___shipLeaveAutomaticallyTime, ref DialogueSegment[] ___shipLeavingEarlyDialogue)
{
if (___normalizedTimeOfDay >= 0.3355214f && !isMessaged && EmergencyBool.canBeLeave)
{
randomTriggerTimer += Time.deltaTime;
}
if (randomTriggerTimer >= 5f && GameNetworkManager.Instance.isHostingGame)
{
randomTriggerPercentage += Random.Range(minimumIncrease, maximumIncrease);
randomTriggerCurrentPercentage = Random.Range(2f, 100f);
EmergencyTakeoffModBase.mls.LogInfo((object)string.Format("new emergency percentage: " + randomTriggerPercentage));
EmergencyTakeoffModBase.mls.LogInfo((object)string.Format("emergency percentage now: " + randomTriggerCurrentPercentage));
if (randomTriggerCurrentPercentage >= randomTriggerPercentage && !isMessaged)
{
EmergencyTakeoffModBase.mls.LogInfo((object)$"emergency leave failed");
}
randomTriggerTimer = 0f;
if (randomTriggerCurrentPercentage < randomTriggerPercentage && !isMessaged && GameNetworkManager.Instance.isHostingGame)
{
ShipEmergencyLeaveRPC();
}
}
normalizedTimeOfDayB = ___normalizedTimeOfDay;
shipLeaveAutomaticallyTimeB = ___shipLeaveAutomaticallyTime;
shipLeavingEarlyDialogueB = ___shipLeavingEarlyDialogue;
if (isNotCalled)
{
___shipLeaveAutomaticallyTime = ___normalizedTimeOfDay + 0.0777f;
isNotCalled = false;
}
}
[ClientRpc]
public static void ShipEmergencyLeaveRPC()
{
HUDManager.Instance.ReadDialogue(shipLeavingEarlyDialogueB);
EmergencyActivatedBool.leavingActivated = true;
isMessaged = true;
isNotCalled = true;
if (HUDManagerPatch.isTimerEnabled)
{
HUDManagerPatch.isTimerActivated = true;
}
if ((Object)(object)Object.FindAnyObjectByType<ShipTeleporter>() != (Object)null)
{
ShipTeleporter[] array = Object.FindObjectsOfType<ShipTeleporter>();
ShipTeleporter[] array2 = array;
foreach (ShipTeleporter val in array2)
{
val.buttonTrigger.interactable = false;
}
}
((Component)Object.FindObjectOfType<ShipLights>()).GetComponent<ShipLights>().areLightsOn = false;
}
}
}