Decompiled source of OopsAllFlooded v0.1.3

OopsAllFlooded.dll

Decompiled 11 months ago
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
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("OopsAllFlooded")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OopsAllFlooded")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d65fecec-c069-4fb6-ae35-a20c8084f5e9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace OopsAllFlooded
{
	[BepInPlugin("squirrelboy.OopsAllFlooded", "Oops! All Flooded", "0.1.3")]
	public class TestClass : BaseUnityPlugin
	{
		private static TestClass instance;

		private const string modGUID = "squirrelboy.OopsAllFlooded";

		private const string modName = "Oops! All Flooded";

		private const string modVersion = "0.1.3";

		private readonly Harmony harmony = new Harmony("squirrelboy.OopsAllFlooded");

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("squirrelboy.OopsAllFlooded");
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "oxymod");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			Item val2 = val.LoadAsset<Item>("Assets/OxyMod/OxyItem.asset");
			NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
			Utilities.FixMixerGroups(val2.spawnPrefab);
			TerminalNode val3 = ScriptableObject.CreateInstance<TerminalNode>();
			val3.clearPreviousText = true;
			val3.displayText = "Limited air supply, useful for flooded facilities.";
			Items.RegisterShopItem(val2, (TerminalNode)null, (TerminalNode)null, val3, 25);
			mls.LogInfo((object)"Watch out for floods.");
			harmony.PatchAll();
		}
	}
}
namespace OopsAllFlooded.Patches
{
	internal class OxyCanisterItem : TetraChemicalItem
	{
		public IEnumerator UseTZPAnimation()
		{
			base.thisAudioSource.PlayOneShot(base.holdCanSFX);
			WalkieTalkie.TransmitOneShotAudio(base.previousPlayerHeldBy.itemAudio, base.holdCanSFX, 1f);
			yield return (object)new WaitForSeconds(0.75f);
			base.emittingGas = true;
			if (((NetworkBehaviour)this).IsOwner)
			{
				base.localHelmetSFX.Play();
				base.localHelmetSFX.PlayOneShot(base.twistCanSFX);
			}
			else
			{
				base.thisAudioSource.clip = base.releaseGasSFX;
				base.thisAudioSource.Play();
				base.thisAudioSource.PlayOneShot(base.twistCanSFX);
			}
		}

		public override void Update()
		{
			if ((Object)(object)base.previousPlayerHeldBy != (Object)null)
			{
				float drunknessInertia = base.previousPlayerHeldBy.drunknessInertia;
				((TetraChemicalItem)this).Update();
				base.previousPlayerHeldBy.drunknessInertia = drunknessInertia;
				base.previousPlayerHeldBy.increasingDrunknessThisFrame = false;
			}
			else
			{
				((TetraChemicalItem)this).Update();
			}
			if (!base.emittingGas || !((Object)(object)base.previousPlayerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController))
			{
				return;
			}
			float drowningTimer = StartOfRound.Instance.drowningTimer;
			StartOfRound.Instance.drowningTimer = Mathf.Clamp(StartOfRound.Instance.drowningTimer + Time.deltaTime / 2f, 0f, 1f);
			if (drowningTimer <= 0.3f && StartOfRound.Instance.drowningTimer > 0.3f)
			{
				StartOfRound.Instance.playedDrowningSFX = false;
			}
			if (base.previousPlayerHeldBy.isUnderwater)
			{
				base.previousPlayerHeldBy.sprintMeter = Mathf.Clamp(base.previousPlayerHeldBy.sprintMeter + Time.deltaTime * 0.1f, 0f, 1.25f);
				if (base.previousPlayerHeldBy.sprintMeter > 0.2f)
				{
					base.previousPlayerHeldBy.isExhausted = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class RoundPatch
	{
		public static FloodWeather facilityFlood;

		public static QuicksandTrigger facilityTrigger;

		[HarmonyPatch("OnShipLandedMiscEvents")]
		[HarmonyPostfix]
		private static void FloodSpawnPatch()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Invalid comparison between Unknown and I4
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Invalid comparison between Unknown and I4
			Debug.Log((object)"StartOfRound injection successful.");
			FloodWeather val = Object.FindObjectOfType<FloodWeather>(true);
			LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
			int randomMapSeed = StartOfRound.Instance.randomMapSeed;
			Debug.Log((object)("Seed = " + randomMapSeed));
			Vector3 val2 = RoundManager.FindMainEntrancePosition(true, false);
			FloodPatch.baseFlood = -225f;
			bool flag = true;
			Debug.Log((object)("Found the main entrance at y = " + val2.y));
			float num = val2.y - 6f;
			if (num < FloodPatch.baseFlood)
			{
				FloodPatch.baseFlood = num;
			}
			FloodPatch.baseFlood += Mathf.Clamp(TimeOfDay.Instance.currentWeatherVariable, -10f, -3f);
			if ((Object)(object)val != (Object)null)
			{
				GameObject gameObject = ((Component)val).gameObject;
				GameObject val3 = Object.Instantiate<GameObject>(gameObject);
				((Object)val3).name = "Flooding (Facility)";
				facilityFlood = val3.GetComponent<FloodWeather>();
				((Component)facilityFlood).transform.parent = ((Component)val).transform.parent;
				((Component)facilityFlood).transform.position = new Vector3(0f, FloodPatch.baseFlood, 0f);
				Debug.Log((object)((Component)facilityFlood).transform.position);
				facilityTrigger = ((Component)facilityFlood).GetComponentInChildren<QuicksandTrigger>();
				if (((int)currentLevelWeather == 1 || (int)currentLevelWeather == 2) && randomMapSeed % 5 == 0)
				{
					Debug.Log((object)"Randomly flooding the interior!");
					((Component)facilityFlood).gameObject.SetActive(true);
				}
			}
			else
			{
				Debug.Log((object)"Flood hasn't spawned yet :(");
			}
		}

		[HarmonyPatch("ShipHasLeft")]
		[HarmonyPrefix]
		private static void FloodDisable()
		{
			if ((Object)(object)facilityFlood != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)facilityFlood).gameObject);
			}
		}
	}
	[HarmonyPatch(typeof(FloodWeather))]
	internal class FloodPatch
	{
		public static float baseFlood;

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static bool FloodLevelPatch(ref FloodWeather __instance)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)(object)RoundPatch.facilityFlood)
			{
				float num = Mathf.Clamp(__instance.floodLevelOffset, 2f, 5f);
				float num2 = baseFlood + num * 4f;
				num2 = Mathf.Clamp(num2, -225f, -212f);
				((Component)__instance).transform.position = Vector3.MoveTowards(((Component)__instance).transform.position, new Vector3(0f, num2, 0f), 0.5f * Time.deltaTime);
				if ((Object)(object)__instance.waterAudio != (Object)null)
				{
					((Component)__instance.waterAudio).transform.position = new Vector3(((Component)GameNetworkManager.Instance.localPlayerController).transform.position.x, ((Component)__instance).transform.position.y + 1f, ((Component)GameNetworkManager.Instance.localPlayerController).transform.position.z);
					float num3 = Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)__instance.waterAudio).transform.position);
					__instance.waterAudio.volume = Mathf.Lerp(__instance.waterAudio.volume, (5f - num3) / 20f, 0.1f);
				}
				return false;
			}
			return true;
		}

		[HarmonyPatch("OnEnable")]
		[HarmonyPostfix]
		private static void FloodLevelStart(ref FloodWeather __instance)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)(object)RoundPatch.facilityFlood)
			{
				((Component)__instance).transform.position = new Vector3(0f, baseFlood, 0f);
			}
		}
	}
	[HarmonyPatch(typeof(QuicksandTrigger))]
	internal class QuicksandPatch
	{
		[HarmonyPatch("OnTriggerStay")]
		[HarmonyPrefix]
		private static void FacilityQuicksand(Collider other, ref QuicksandTrigger __instance)
		{
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)(object)RoundPatch.facilityTrigger))
			{
				return;
			}
			if (__instance.isWater)
			{
				if (!((Component)other).gameObject.CompareTag("Player"))
				{
					return;
				}
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController && (Object)(object)component != (Object)null && (Object)(object)component.underwaterCollider != (Object)(object)__instance)
				{
					component.underwaterCollider = ((Component)__instance).gameObject.GetComponent<Collider>();
					return;
				}
			}
			if (!GameNetworkManager.Instance.localPlayerController.isInsideFactory || GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom || (!__instance.isWater && !((Component)other).gameObject.CompareTag("Player")))
			{
				return;
			}
			PlayerControllerB component2 = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)component2 != (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				return;
			}
			if (__instance.isWater && !component2.isUnderwater)
			{
				component2.underwaterCollider = ((Component)__instance).gameObject.GetComponent<Collider>();
				component2.isUnderwater = true;
			}
			component2.statusEffectAudioIndex = __instance.audioClipIndex;
			if (component2.isUnderwater)
			{
				Bounds bounds = component2.underwaterCollider.bounds;
				if (!((Bounds)(ref bounds)).Contains(((Component)component2.gameplayCamera).transform.position))
				{
					component2.statusEffectAudio.volume = component2.statusEffectAudio.volume * 0.25f;
				}
			}
			if (component2.isSinking)
			{
				return;
			}
			if (__instance.sinkingLocalPlayer)
			{
				if (!component2.CheckConditionsForSinkingInQuicksand())
				{
					__instance.StopSinkingLocalPlayer(component2);
				}
			}
			else if (component2.CheckConditionsForSinkingInQuicksand())
			{
				Debug.Log((object)"Set local player to sinking!");
				__instance.sinkingLocalPlayer = true;
				component2.sourcesCausingSinking++;
				component2.isMovementHindered++;
				component2.hinderedMultiplier *= __instance.movementHinderance;
				if (__instance.isWater)
				{
					component2.sinkingSpeedMultiplier = 0f;
				}
				else
				{
					component2.sinkingSpeedMultiplier = __instance.sinkingSpeedMultiplier;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerPatch
	{
		private static int footstepSurfaceStorage;

		[HarmonyPatch("CheckConditionsForSinkingInQuicksand")]
		[HarmonyPrefix]
		private static void CheckPrefix(ref PlayerControllerB __instance)
		{
			if (GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				footstepSurfaceStorage = __instance.currentFootstepSurfaceIndex;
				__instance.currentFootstepSurfaceIndex = 1;
			}
		}

		[HarmonyPatch("CheckConditionsForSinkingInQuicksand")]
		[HarmonyPostfix]
		private static void CheckPostfix(ref PlayerControllerB __instance)
		{
			if (GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				__instance.currentFootstepSurfaceIndex = footstepSurfaceStorage;
			}
		}
	}
}