Decompiled source of TheFloorIsLava v0.1.1

plugins/com.github.KinTheInfinite.TheFloorIsLava.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.KinTheInfinite.TheFloorIsLava")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1")]
[assembly: AssemblyProduct("com.github.KinTheInfinite.TheFloorIsLava")]
[assembly: AssemblyTitle("TheFloorIsLava")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace TheFloorIsLava
{
	public class LavaSyncer : MonoBehaviourPunCallbacks
	{
		public static LavaSyncer instance;

		internal PhotonView photonView;

		public float start_height;

		public float max_height;

		public float speed;

		public float delay;

		public bool started;

		public bool delay_ended;

		private float sync_delay;

		public static float immune_time;

		public static bool lava_enabled;

		private void Awake()
		{
			instance = this;
			photonView = ((Component)this).GetComponent<PhotonView>();
			Plugin.Log.LogInfo((object)"Added Lava Syncer");
		}

		private void FixedUpdate()
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			if (!InGameScene())
			{
				lava_enabled = false;
				immune_time = 10f;
				return;
			}
			immune_time -= Time.fixedDeltaTime;
			if (PhotonNetwork.IsMasterClient && speed != Plugin.config_lava_speed.Value)
			{
				speed = Plugin.config_lava_speed.Value;
				SyncLava(force: true);
			}
			if (!lava_enabled)
			{
				return;
			}
			if ((Object)(object)Singleton<LavaRising>.Instance != (Object)null && (Object)(object)Singleton<LavaRising>.Instance.lava != (Object)null && lava_enabled)
			{
				if ((Object)(object)((Component)Singleton<LavaRising>.Instance).gameObject.transform.parent != (Object)null)
				{
					((Component)Singleton<LavaRising>.Instance).gameObject.transform.SetParent((Transform)null, true);
				}
				Vector3 val = Singleton<LavaRising>.Instance.lava.position + new Vector3(0f, (delay <= 0f) ? speed : 0f, 0f) * Time.fixedDeltaTime;
				if (Singleton<MapHandler>.Instance.currentSegment == 3)
				{
					((Vector3)(ref val))..ctor(0f, -1000f, 0f);
				}
				if (val.y < GetMaxHeight())
				{
					Singleton<LavaRising>.Instance.lava.MovePosition(val);
				}
			}
			if (!PhotonNetwork.IsMasterClient)
			{
				return;
			}
			if (!InGameScene())
			{
				started = false;
			}
			else if (!((Object)(object)Singleton<LavaRising>.Instance == (Object)null) && !((Object)(object)Singleton<LavaRising>.Instance.lava == (Object)null) && !((Object)(object)Character.localCharacter == (Object)null))
			{
				if (!started)
				{
					started = true;
					MoveToStartingPosition(Character.localCharacter.Center - new Vector3(0f, Plugin.config_lava_shore_lowered_height.Value, 0f));
				}
				SyncLava(force: false);
				delay -= Time.fixedDeltaTime;
				if (delay > 0f)
				{
					sync_delay = 0f;
					delay_ended = false;
				}
				else if (!delay_ended)
				{
					delay_ended = true;
					photonView.RPC("RPC_ShowLavaRisingMessage", (RpcTarget)0, Array.Empty<object>());
				}
			}
		}

		private void SyncLava(bool force)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.IsMasterClient && Plugin.config_lava_enabled.Value)
			{
				sync_delay -= Time.deltaTime;
				if (!(sync_delay > 0f) || force)
				{
					sync_delay = 10f;
					photonView.RPC("RPC_SyncCustomLava", (RpcTarget)0, new object[5]
					{
						((Component)Singleton<LavaRising>.Instance.lava).transform.position,
						Plugin.config_lava_shore_lowered_height.Value,
						Plugin.config_lava_max_height.Value,
						Plugin.config_lava_speed.Value,
						delay
					});
				}
			}
		}

		public static void MoveToStartingPosition(Vector3 position)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.IsMasterClient && Plugin.config_lava_enabled.Value)
			{
				((Component)Singleton<LavaRising>.Instance.lava).transform.position = position;
				instance.delay = Plugin.config_lava_delay.Value;
				instance.SyncLava(force: true);
			}
		}

		[PunRPC]
		public void RPC_SyncCustomLava(Vector3 position, float start_height, float max_height, float speed, float delay, PhotonMessageInfo info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			if (info.Sender.IsMasterClient)
			{
				((Component)Singleton<LavaRising>.Instance.lava).transform.position = position;
				((Component)Singleton<LavaRising>.Instance.lava).transform.localScale = new Vector3(50f, 1f, 50f);
				this.start_height = start_height;
				this.max_height = max_height;
				this.speed = speed;
				this.delay = delay;
				lava_enabled = true;
			}
		}

		[PunRPC]
		public void RPC_ShowLavaRisingMessage(PhotonMessageInfo info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (info.Sender.IsMasterClient)
			{
				GUIManager.instance.TheLavaRises();
				GamefeelHandler.instance.AddPerlinShake(5f, 3f, 15f);
			}
		}

		public static GameObject GetCurrentGoalCampfire()
		{
			int currentSegment = Singleton<MapHandler>.Instance.currentSegment;
			return Singleton<MapHandler>.Instance.segments[currentSegment].segmentCampfire;
		}

		public float GetMaxHeight()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			GameObject currentGoalCampfire = GetCurrentGoalCampfire();
			if ((Object)(object)currentGoalCampfire == (Object)null)
			{
				return float.MaxValue;
			}
			return currentGoalCampfire.transform.position.y - max_height;
		}

		public static bool InGameScene()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (name == "Title" || name == "Airport")
			{
				return false;
			}
			return true;
		}
	}
	[BepInPlugin("com.github.KinTheInfinite.TheFloorIsLava", "TheFloorIsLava", "0.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		public class ReplaceLavaSync
		{
			[HarmonyPatch(typeof(GameUtils), "Awake")]
			[HarmonyPostfix]
			public static void AwakePostfix(GameUtils __instance)
			{
				((Component)__instance).gameObject.AddComponent<LavaSyncer>();
			}

			[HarmonyPatch(typeof(GameUtils), "SyncLava")]
			[HarmonyPrefix]
			private static bool SyncLavaPrefix(GameUtils __instance, bool started, bool ended, float time, float timeWaited)
			{
				if (!LavaSyncer.lava_enabled)
				{
					return true;
				}
				return false;
			}

			[HarmonyPatch(typeof(Campfire), "Light_Rpc")]
			[HarmonyPrefix]
			private static bool Light_RpcPrefix(Campfire __instance)
			{
				//IL_0051: 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_0066: Unknown result type (might be due to invalid IL or missing references)
				if (!PhotonNetwork.IsMasterClient || !config_lava_enabled.Value)
				{
					return true;
				}
				float num = config_lava_lowered_height.Value;
				if (Singleton<MapHandler>.Instance.currentSegment == 2)
				{
					num = 500f;
				}
				if (Singleton<MapHandler>.Instance.currentSegment == 3)
				{
					num = config_lava_kiln_lowered_height.Value;
				}
				LavaSyncer.MoveToStartingPosition(((Component)__instance).transform.position - new Vector3(0f, num, 0f));
				return true;
			}

			[HarmonyPatch(typeof(Lava), "OutsideBounds")]
			[HarmonyPrefix]
			private static bool OutsideBoundsPrefix(Lava __instance, Vector3 pos, ref bool __result)
			{
				if (!LavaSyncer.lava_enabled)
				{
					return true;
				}
				if (LavaSyncer.immune_time > 0f)
				{
					__result = true;
					return false;
				}
				__result = false;
				return false;
			}

			[HarmonyPatch(typeof(Lava), "TestSacrificeIdol")]
			[HarmonyPrefix]
			private static bool TestSacrificeIdolPrefix(Lava __instance, Item item, ref bool __result)
			{
				if (LavaSyncer.lava_enabled)
				{
					return true;
				}
				__result = false;
				return false;
			}
		}

		public static Harmony harmony;

		public static ConfigEntry<bool> config_lava_enabled;

		public static ConfigEntry<float> config_lava_shore_lowered_height;

		public static ConfigEntry<float> config_lava_lowered_height;

		public static ConfigEntry<float> config_lava_kiln_lowered_height;

		public static ConfigEntry<float> config_lava_max_height;

		public static ConfigEntry<float> config_lava_speed;

		public static ConfigEntry<float> config_lava_delay;

		public const string Id = "com.github.KinTheInfinite.TheFloorIsLava";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "TheFloorIsLava";

		public static string Version => "0.1.1";

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Expected O, but got Unknown
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			harmony = new Harmony("com.kintheinfinite.thefloorislava");
			harmony.PatchAll(typeof(ReplaceLavaSync));
			config_lava_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "LavaEnabled", true, "Whether or not the mod is enabled.");
			config_lava_shore_lowered_height = ((BaseUnityPlugin)this).Config.Bind<float>("General", "LavaLoweredHeightShore", 3f, new ConfigDescription("Lowered height compared to player starting position, too low of a value can make the game impossible.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), Array.Empty<object>()));
			config_lava_lowered_height = ((BaseUnityPlugin)this).Config.Bind<float>("General", "LavaLoweredHeight", 120f, new ConfigDescription("Lowered height compared to lit campfire position, too low of a value can make the game impossible.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(50f, 200f), Array.Empty<object>()));
			config_lava_kiln_lowered_height = ((BaseUnityPlugin)this).Config.Bind<float>("General", "LavaLoweredHeightKiln", 15f, new ConfigDescription("Lowered height compared to lit campfire position, too low of a value can make the game impossible.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 200f), Array.Empty<object>()));
			config_lava_max_height = ((BaseUnityPlugin)this).Config.Bind<float>("General", "LavaMaxHeight", 25f, new ConfigDescription("Maximum lowered height compared to goal campfire, too high of a value can reach people at the campfire.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-50f, 150f), Array.Empty<object>()));
			config_lava_speed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "LavaSpeed", 0.3f, new ConfigDescription("Speed of the lava, fog default is 0.3.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-100f, 100f), Array.Empty<object>()));
			config_lava_delay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "LavaDelay", 60f, new ConfigDescription("Delay until lava starts after game start and campfires being lit.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 600f), Array.Empty<object>()));
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}