Decompiled source of LCLocalFixes v0.0.2

LCLocalFixes.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LCLocalFixes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyInformationalVersion("0.0.2")]
[assembly: AssemblyProduct("LCLocalFixes")]
[assembly: AssemblyTitle("LCLocalFixes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.2.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LCLocalFixes
{
	public class Configs
	{
		public static ConfigEntry<bool> editorTimeToggle;

		public static ConfigEntry<bool> hazardAudioLogLandmine;

		public static ConfigEntry<bool> hazardAudioLogSpikes;

		public static ConfigEntry<bool> animatedObjectTrigger;

		public static ConfigEntry<bool> elevatorNavigation;

		public static ConfigEntry<bool> artifice;

		public static ConfigEntry<bool> timeOfDayMusic;

		public static ConfigEntry<bool> mythra;

		public static ConfigEntry<bool> spectateFlashlight;

		public Configs(ConfigFile cfg)
		{
			timeOfDayMusic = cfg.Bind<bool>("General", "Music Playing Once", true, "Allows ambient music to play multiple times during a run by circumventing a check that normally only allows it to play once.");
			elevatorNavigation = cfg.Bind<bool>("General", "Navigation In Mineshaft", true, "The ship monitor looking at players underground in mineshafts will draw a line directly to the elevator button, instead of the above-ground main entrance.");
			artifice = cfg.Bind<bool>("General", "Artifice Ship Lag", true, "Turns off a certain check near Artifice's ship landing location that tries to play audio every frame but can't, which could possibly cause frame drops in this area.");
			animatedObjectTrigger = cfg.Bind<bool>("General", "Animated Object Error", true, "So-called AnimatedObjectTriggers will get new code injected that should fix an error that prevents sound from playing and the animation from syncing. Most prominent on Experimentation's sliding garage door.");
			editorTimeToggle = cfg.Bind<bool>("Development", "Editor Time Toggle", false, "When playing with a mod that turns on development mode such LethalDevMode, press the button to store furniture while the menu is open to toggle the time from standing still to moving normally.\nBy default turned off to prevent desyncing between players and cheating.");
			hazardAudioLogLandmine = cfg.Bind<bool>("Development", "Landmine Audio Log", true, "The landmines' debug logs of 'Audio Spatializer failed to...' will be hidden by creating a duplicate AudioSource that will not print these errors.");
			hazardAudioLogSpikes = cfg.Bind<bool>("Development", "Spike Trap Audio Log", true, "The Spike Traps' debug logs of 'PlayOneShot was called with a null AudioClip' will be hidden by making the AudioClip it tries to call a silent sound file.");
			mythra = cfg.Bind<bool>("Mods", "ModelReplacementAPI Model Stuttering", false, "ModelReplacementAPI's first-person models should no longer stutter or lag behind your current location when on objects that move you, such as the ship or the mineshaft elevator.\nBy default turned off since ModelReplacementAPI should have fixed this since this mod's initial release.");
			spectateFlashlight = cfg.Bind<bool>("Mods", "SpectateEnemies Flashlight Errors", true, "Removes the cookie of the spectate camera, which could throw errors every frame and prevent other flashlights from turning on.\nAlthough this flashlight is present in the vanilla game, it is not accessible unless playing with SpectateEnemies or other mods enabling it.");
		}

		public static void DisplayConfigs()
		{
			ManualLogSource logger = Plugin.Logger;
			if (timeOfDayMusic.Value)
			{
				logger.LogInfo((object)"Config [Music Playing Once] is set to TRUE. Ambient music can reset and playing again on consecutive days.");
			}
			else
			{
				logger.LogInfo((object)"Config [Music Playing Once] is set to FALSE. Ambient music will likely only play once per play session.");
			}
			if (elevatorNavigation.Value)
			{
				logger.LogInfo((object)"Config [Navigation In Mineshaft] is set to TRUE. The code for ManualCameraRenderers will be patched using a HarmonyTranspiler to overwrite the value to draw a line towards to be the elevator button.");
			}
			else
			{
				logger.LogInfo((object)"Config [Navigation In Mineshaft] is set to FALSE. The code for ManualCameraRenderers will stay untouched.");
			}
			if (artifice.Value)
			{
				logger.LogInfo((object)"Config [Artifice Ship Lag] is set to TRUE. Frames will try to be saved near Artifice's ship landing location by turning off a once-per-frame check.");
			}
			else
			{
				logger.LogInfo((object)"Config [Artifice Ship Lag] is set to FALSE. Artifice's ship landing location will stay untouched.");
			}
			if (animatedObjectTrigger.Value)
			{
				logger.LogInfo((object)"Config [Animated Object Error] is set to TRUE. The code for AnimatedObjectTriggers will be patched using a HarmonyTranspiler to account for a NullReferenceException.");
			}
			else
			{
				logger.LogInfo((object)"Config [Animated Object Error] is set to FALSE. The code for AnimatedObjectTriggers will stay untouched.");
			}
			if (editorTimeToggle.Value)
			{
				logger.LogInfo((object)"Config [Editor Time Toggle] is set to TRUE. When playing in editor-mode, press the button to store furniture while the menu is open to turn the flow of time off and on.");
			}
			else
			{
				logger.LogInfo((object)"Config [Editor Time Toggle] is set to FALSE. The flow of time cannot be touched through this mod.");
			}
			if (hazardAudioLogLandmine.Value)
			{
				logger.LogInfo((object)"Config [Landmine Audio Log] is set to TRUE. Landmines will no longer print repeated warning messages to the debug log by using a new AudioSource.");
			}
			else
			{
				logger.LogInfo((object)"Config [Landmine Audio Log] is set to FALSE. Landmines will not be patched to prevent their repeated debug logs.");
			}
			if (hazardAudioLogSpikes.Value)
			{
				logger.LogInfo((object)"Config [Spike Trap Audio Log] is set to TRUE. Spike Traps will no longer print repeated null AudioClip warning to the debug log by using a new, silent AudioClip.");
			}
			else
			{
				logger.LogInfo((object)"Config [Spike Trap Audio Log] is set to FALSE. Spike Traps will not be patched to prevent their repeated debug logs.");
			}
			if (mythra.Value)
			{
				logger.LogInfo((object)"Config [ModelReplacementAPI Model Stuttering] is set to TRUE. ModelReplacementAPI's first-person arm-models should no longer jitter when standing on objects that move you around.");
			}
			else
			{
				logger.LogInfo((object)"Config [ModelReplacementAPI Model Stuttering] is set to FALSE. ModelReplacementAPI's models will not be touched.");
			}
			if (spectateFlashlight.Value)
			{
				logger.LogInfo((object)"Config [SpectateEnemies Flashlight Errors] is set to TRUE. The spectate camera's flashlight available through SpectateEnemies will not get a cookie anymore and should stop causing errors.");
			}
			else
			{
				logger.LogInfo((object)"Config [SpectateEnemies Flashlight Errors] is set to FALSE. The spectate camera's flashlight will not be touched.");
			}
		}
	}
	public class EditorTimeToggle
	{
		[HarmonyPatch(typeof(ShipBuildModeManager), "StoreObject_performed")]
		public class NewShipBuildModeManager
		{
			[HarmonyPostfix]
			public static void ToggleTimeMultiplier()
			{
				if (!Configs.editorTimeToggle.Value)
				{
					Logger.LogWarning((object)"Configs.editorTimeToggle is false yet patch still executed, returning");
					return;
				}
				lastTimeStoreObject = Time.realtimeSinceStartup;
				if (!(Time.realtimeSinceStartup - lastTimeStoreObject < 1f))
				{
					return;
				}
				Logger.LogDebug((object)"StoreObject performed");
				if (!Application.isEditor)
				{
					Logger.LogDebug((object)"EditorTimeToggle.ToggleTime(): !isEditor");
					return;
				}
				TimeOfDay val = Object.FindAnyObjectByType<TimeOfDay>();
				if ((Object)(object)val == (Object)null)
				{
					Logger.LogDebug((object)"EditorTimeToggle.ToggleTime(): timeScript");
					return;
				}
				QuickMenuManager val2 = Object.FindAnyObjectByType<QuickMenuManager>();
				if ((Object)(object)val2 == (Object)null || val2.isMenuOpen)
				{
					if (val.globalTimeSpeedMultiplier != 0f)
					{
						lastSavedTimeMultiplier = val.globalTimeSpeedMultiplier;
						val.globalTimeSpeedMultiplier = 0f;
					}
					else
					{
						val.globalTimeSpeedMultiplier = lastSavedTimeMultiplier;
					}
					HUDManager.Instance.DisplayTip("TIME TOGGLE!!!", $"Set time to: {val.globalTimeSpeedMultiplier}", false, false, "LC_Tip1");
					Logger.LogDebug((object)$"Successfully finished EditorTimeToggle.ToggleTimeMultiplier with: {val.globalTimeSpeedMultiplier}");
				}
			}
		}

		[HarmonyPatch(typeof(TimeOfDay), "UpdateProfitQuotaCurrentTime")]
		public class NewTimeOfDay
		{
			[HarmonyPostfix]
			public static void UpdateProfitQuotaPostfix(TimeOfDay __instance)
			{
				if (__instance.globalTimeSpeedMultiplier == 0f)
				{
					Logger.LogDebug((object)"UpdateProfitQuotaPostfix caught time standing still, trying to undo day change!");
					__instance.daysUntilDeadline++;
				}
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;

		private static float lastTimeStoreObject;

		private static float lastSavedTimeMultiplier;
	}
	public class HazardAudioLog
	{
		[HarmonyPatch(typeof(Landmine), "Start")]
		public class NewLandmine
		{
			[HarmonyPostfix]
			public static void StartPostfix(Landmine __instance)
			{
				if (!Configs.hazardAudioLogLandmine.Value)
				{
					Logger.LogWarning((object)"Configs.hazardAudioLogLandmine is false yet patch still executed, returning");
				}
				else
				{
					PatchLandmine(__instance);
				}
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;

		private static void PatchLandmine(Landmine __instance)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)Plugin.assetBundle == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchLandmine: null");
				return;
			}
			Logger.LogDebug((object)$"Patching Landmine #{((NetworkBehaviour)__instance).NetworkObjectId}");
			GameObject val = Plugin.assetBundle.LoadAsset<GameObject>("Assets/LandminePatch (audioSource).prefab");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchLandmine: asset");
				return;
			}
			PlayAudioAnimationEvent component = ((Component)__instance).GetComponent<PlayAudioAnimationEvent>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchLandmine: playAudioAnimationEvent");
				return;
			}
			AudioSource component2 = Object.Instantiate<GameObject>(val, ((Component)__instance).transform).GetComponent<AudioSource>();
			if ((Object)(object)component.audioToPlay == (Object)null || (Object)(object)component.audioToPlay.outputAudioMixerGroup == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchLandmine: outputAudioMixerGroup");
			}
			else
			{
				component2.outputAudioMixerGroup = component.audioToPlay.outputAudioMixerGroup;
			}
			__instance.mineAudio = component2;
			component.audioToPlay = component2;
			Logger.LogDebug((object)"Successfully patched this Landmine");
		}

		public static void StartSpikeTrapPatch(StartOfRound __instance)
		{
			if (!Configs.hazardAudioLogSpikes.Value)
			{
				Logger.LogWarning((object)"Configs.hazardAudioLogSpikes is false yet patch still executed, returning");
				return;
			}
			Logger.LogDebug((object)"Starting HazardAudioLog.StartSpikeTrapPatch()");
			if ((Object)(object)__instance == (Object)null || (Object)(object)Plugin.assetBundle == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.StartSpikeTrapPatch(): null");
				return;
			}
			SelectableLevel val = null;
			if (__instance.levels == null || __instance.levels.Length <= 1 || (Object)(object)__instance.levels[1] == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.StartSpikeTrapPatch(): level");
				return;
			}
			val = __instance.levels[1];
			GameObject val2 = null;
			if (val.spawnableMapObjects == null || val.spawnableMapObjects.Length <= 2 || val.spawnableMapObjects[2] == null || (Object)(object)val.spawnableMapObjects[2].prefabToSpawn == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.StartSpikeTrapPatch(): spawnableMapObject");
				return;
			}
			val2 = val.spawnableMapObjects[2].prefabToSpawn;
			PatchSpikeTrap(val2.GetComponentInChildren<SpikeRoofTrap>());
		}

		private static void PatchSpikeTrap(SpikeRoofTrap __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchSpikeTrap(): null");
				return;
			}
			if ((Object)(object)((Component)__instance).transform.parent == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchSpikeTrap(): transform");
				return;
			}
			PlayAudioAnimationEvent component = ((Component)((Component)__instance).transform.parent).GetComponent<PlayAudioAnimationEvent>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchSpikeTrap(): playAudioAnimationEvent");
				return;
			}
			AudioClip val = Plugin.assetBundle.LoadAsset<AudioClip>("Assets/SpikeRoofTrapPatch (silence).ogg");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchSpikeTrap(): asset");
				return;
			}
			component.audioClip2 = val;
			Logger.LogDebug((object)"Successfully patched SpikeRoofTrap");
		}

		public static void PatchFlashlight(StartOfRound __instance)
		{
			if (!Configs.spectateFlashlight.Value)
			{
				Logger.LogWarning((object)"Configs.spectateFlashlight is false yet patch still executed, returning");
				return;
			}
			Logger.LogDebug((object)"Starting HazardAudioLog.PatchFlashlight()");
			if ((Object)(object)__instance == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchFlashlight(): __instance");
				return;
			}
			if ((Object)(object)__instance.spectateCamera == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchFlashlight(): spectateCamera");
				return;
			}
			Light component = ((Component)__instance.spectateCamera).GetComponent<Light>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchFlashlight(): cameraLight");
				return;
			}
			component.cookie = null;
			Logger.LogDebug((object)"Successfully patched SpectateFlashlight");
		}
	}
	public class LevelBugs
	{
		[HarmonyPatch(typeof(AnimatedObjectTrigger), "PlayAudio")]
		public class NewAnimatedObjectTrigger
		{
			[HarmonyTranspiler]
			public static IEnumerable<CodeInstruction> PatchExperimentationParticles(IEnumerable<CodeInstruction> instructions)
			{
				Logger.LogDebug((object)"Starting LevelBugs.PatchExperimentationParticles()");
				CodeInstruction item = Transpilers.EmitDelegate<Action<ParticleSystem>>((Action<ParticleSystem>)delegate(ParticleSystem particles)
				{
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					//IL_002f: Unknown result type (might be due to invalid IL or missing references)
					if ((Object)(object)particles != (Object)null)
					{
						particles.Play(true);
						if (Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)particles).transform.position) < 14f)
						{
							HUDManager.Instance.ShakeCamera((ScreenShakeType)2);
						}
					}
				});
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				if (!Configs.animatedObjectTrigger.Value)
				{
					Logger.LogWarning((object)"Configs.animatedObjectTrigger is false yet transpiler still executed, returning");
					return list;
				}
				int num = -1;
				for (int i = 0; i < list.Count - 1; i++)
				{
					CodeInstruction val = list[i];
					if (val.opcode == OpCodes.Ldfld && ((FieldInfo)val.operand).Name == "playParticle")
					{
						num = i;
						break;
					}
				}
				if (num == -1)
				{
					Logger.LogWarning((object)"LevelBugs.PatchExperimentationParticles(): codeInstruction");
					return list;
				}
				list.RemoveRange(num + 1, 13);
				list.Insert(num + 1, item);
				Logger.LogDebug((object)"Reached end of LevelBugs.PatchExperimentationParticles()");
				return list;
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "openingDoorsSequence")]
		public class NewStartOfRound
		{
			[HarmonyPostfix]
			public static void openingDoorsSequencePostfix(StartOfRound __instance)
			{
				if (!Configs.artifice.Value)
				{
					Logger.LogWarning((object)"Configs.artifice is false yet patch still executed, returning");
				}
				else if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.currentLevel == (Object)null)
				{
					Logger.LogWarning((object)"LevelBugs: null");
				}
				else if (((Object)__instance.currentLevel).name == "ArtificeLevel")
				{
					PatchArtifice();
				}
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;

		private static void PatchArtifice()
		{
			Logger.LogDebug((object)"Starting LevelBugs.PatchArtifice()");
			AudioReverbPresets val = Object.FindAnyObjectByType<AudioReverbPresets>();
			if ((Object)(object)val == (Object)null || val.audioPresets == null || val.audioPresets.Length <= 3 || (Object)(object)val.audioPresets[3] == (Object)null)
			{
				Logger.LogWarning((object)"LevelBugs.PatchArtifice(): presets");
				return;
			}
			AudioReverbTrigger val2 = val.audioPresets[3];
			if (val2.audioChanges == null || val2.audioChanges.Length <= 1 || val2.audioChanges[1] == null)
			{
				Logger.LogWarning((object)"LevelBugs.PatchArtifice(): trigger");
				return;
			}
			switchToAudio val3 = val2.audioChanges[1];
			if ((Object)(object)val3.audio == (Object)null || ((Object)val3.audio).name != "BlizzardAmbience")
			{
				Logger.LogWarning((object)"LevelBugs.PatchArtifice(): audio");
				return;
			}
			val3.changeAudioVolume = true;
			Logger.LogDebug((object)"Successfully reached end of LevelBugs.PatchArtifice()");
		}
	}
	internal class MineshaftOddities
	{
		[HarmonyPatch(typeof(NetworkManager), "SetSingleton")]
		public class NewNetworkManagerSetSingleton
		{
			[HarmonyPostfix]
			public static void SetSingletonPostfix()
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				Logger.LogDebug((object)"NetworkManager.SetSingleton started!");
				Scene val = default(Scene);
				Logger.LogInfo((object)SceneManager.sceneCountInBuildSettings);
				for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++)
				{
					Scene sceneAt = SceneManager.GetSceneAt(i);
					if (sceneAt == default(Scene))
					{
						continue;
					}
					string text = ((Scene)(ref sceneAt)).name;
					if (text.Contains("Assets/Scenes/"))
					{
						text = text.Replace("Assets/Scenes/", "");
					}
					if (text.Contains(".unity"))
					{
						text = text.Replace(".unity", "");
					}
					Logger.LogError((object)text);
					if (text == "SampleSceneRelay")
					{
						val = SceneManager.GetSceneByName(text);
						Logger.LogWarning((object)$"{text} | {val}");
						GameObject[] rootGameObjects = ((Scene)(ref val)).GetRootGameObjects();
						for (int j = 0; j < rootGameObjects.Length; j++)
						{
							GameObject arg = rootGameObjects[j];
							Logger.LogDebug((object)$"scenePrefab [{j}]: {arg}");
						}
					}
				}
			}
		}

		[HarmonyPatch(typeof(RoundManager), "Awake")]
		public class NewRoundManagerAwake
		{
			[HarmonyPostfix]
			public static void AwakePostfix(RoundManager __instance)
			{
				if ((Object)(object)__instance == (Object)null || alreadyAddedNetworkPrefab)
				{
					return;
				}
				alreadyAddedNetworkPrefab = true;
				SpawnSyncedObject[] array = null;
				try
				{
					array = __instance.dungeonFlowTypes[4].dungeonFlow.Lines[1].DungeonArchetypes[0].TileSets[0].TileWeights.Weights[0].Value.GetComponentsInChildren<SpawnSyncedObject>();
				}
				catch (Exception arg)
				{
					Logger.LogWarning((object)$"ERROR in VentCaveNetworkManager: {arg}");
				}
				if (array == null)
				{
					return;
				}
				for (int i = 0; i < array.Length; i++)
				{
					SpawnSyncedObject val = array[i];
					if (!((Object)(object)val == (Object)null) && !((Object)(object)val.spawnPrefab == (Object)null))
					{
						Logger.LogDebug((object)$"[{i}] name = {((Object)val).name} | spawnPrefab = {val.spawnPrefab}");
						if (((Object)val.spawnPrefab).name == "VentEntranceCave")
						{
							Logger.LogInfo((object)"FOUND IT! trying to register");
							NetworkManager.Singleton.AddNetworkPrefab(val.spawnPrefab);
						}
					}
				}
			}
		}

		[HarmonyPatch(typeof(ManualCameraRenderer), "SetLineToExitFromRadarTarget")]
		public class NewManualCameraRenderer
		{
			[HarmonyTranspiler]
			public static IEnumerable<CodeInstruction> PatchCameraLineRenderer(IEnumerable<CodeInstruction> instructions)
			{
				Logger.LogDebug((object)"Starting MineshaftOddities.PatchCameraLineRenderer()");
				CodeInstruction item = Transpilers.EmitDelegate<Action<Vector3>>((Action<Vector3>)delegate(Vector3 entrancePos)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_002a: Unknown result type (might be due to invalid IL or missing references)
					//IL_002f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0039: Unknown result type (might be due to invalid IL or missing references)
					//IL_003e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0043: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
					//IL_0096: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
					//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
					//IL_0070: Unknown result type (might be due to invalid IL or missing references)
					//IL_0076: Unknown result type (might be due to invalid IL or missing references)
					if (!(entrancePos == Vector3.zero))
					{
						Vector3 val2 = ((Component)StartOfRound.Instance.mapScreen.mapCamera).transform.position - Vector3.up * 3.75f;
						if ((Object)(object)RoundManager.Instance != (Object)null && RoundManager.Instance.currentDungeonType == 4 && (Object)(object)RoundManager.Instance.currentMineshaftElevator != (Object)null && val2.y < entrancePos.y - 3f)
						{
							Logger.LogDebug((object)$"overwriting entrancePos {entrancePos} to elevatorBottomPoint {RoundManager.Instance.currentMineshaftElevator.elevatorBottomPoint.position}");
							entrancePos = RoundManager.Instance.currentMineshaftElevator.elevatorBottomPoint.position;
						}
						if (!NavMesh.CalculatePath(val2, entrancePos, -1, StartOfRound.Instance.mapScreen.path1))
						{
							Debug.Log((object)"Path to exit could not be calculated");
						}
					}
				});
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				if (!Configs.elevatorNavigation.Value)
				{
					Logger.LogWarning((object)"Configs.elevatorNavigation is false yet transpiler still executed, returning");
					return list;
				}
				int num = -1;
				for (int i = 0; i < list.Count - 1; i++)
				{
					CodeInstruction val = list[i];
					if (val.opcode == OpCodes.Call && ((MethodInfo)val.operand).Name == "FindMainEntrancePosition")
					{
						num = i;
						break;
					}
				}
				if (num == -1)
				{
					Logger.LogWarning((object)"MineshaftOddities.PatchCameraLineRenderer(): codeInstruction");
					return list;
				}
				int index = num + 1;
				int count = 23;
				list.RemoveRange(index, count);
				list.Insert(index, item);
				Logger.LogDebug((object)"Reached end of MineshaftOddities.PatchCameraLineRenderer()");
				return list;
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;

		private static bool alreadyAddedNetworkPrefab = false;
	}
	public class Mythra : MonoBehaviour
	{
		[HarmonyPatch(typeof(BodyReplacementBase), "Awake")]
		public class NewBodyReplacementBase
		{
			[HarmonyPostfix]
			public static void AwakePostfix(BodyReplacementBase __instance)
			{
				if (!Configs.mythra.Value)
				{
					Logger.LogWarning((object)"Configs.mythra is false yet patch still executed, returning");
				}
				else if ((Object)(object)__instance == (Object)null)
				{
					Logger.LogWarning((object)"Mythra.AwakePostfix(): null");
				}
				else if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
				{
					Logger.LogWarning((object)"Mythra.AwakePostfix(): GameNetworkManager");
				}
				else if ((Object)(object)__instance.controller == (Object)null || (Object)(object)__instance.replacementViewModel == (Object)null)
				{
					Logger.LogWarning((object)"Mythra.AwakePostfix(): __instance");
				}
				else if ((Object)(object)__instance.controller == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					localViewModel = __instance.replacementViewModel;
					timer = checkInterval;
					doUpdate = true;
				}
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;

		private static GameObject localViewModel;

		private static bool doUpdate = false;

		private static float checkInterval = 0.5f;

		private static float timer;

		private void Update()
		{
			if (doUpdate)
			{
				if (timer >= checkInterval)
				{
					DoUpdateCheck();
					timer = 0f;
				}
				else
				{
					timer += Time.deltaTime;
				}
			}
		}

		private void DoUpdateCheck()
		{
			if ((Object)(object)localViewModel == (Object)null)
			{
				doUpdate = false;
				Logger.LogDebug((object)$"doUpdate: {doUpdate}");
				return;
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localViewModel.transform.parent != (Object)(object)((Component)localPlayerController).transform.parent)
			{
				Logger.LogDebug((object)$"Caught discrepancy between {((Object)localViewModel).name} and {localPlayerController.playerUsername}. Reparenting to {((Component)localPlayerController).transform.parent}");
				localViewModel.transform.SetParent(((Component)localPlayerController).transform.parent, true);
			}
		}
	}
	[BepInPlugin("local.SimonTendo.LCLocalFixes", "LCLocalFixes", "0.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		public class NewStartOfRound
		{
			[HarmonyPostfix]
			public static void StartPostfix(StartOfRound __instance)
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Expected O, but got Unknown
				if (Configs.hazardAudioLogSpikes.Value)
				{
					HazardAudioLog.StartSpikeTrapPatch(__instance);
				}
				if (Configs.mythra.Value && foundModelReplacement)
				{
					managerObject = new GameObject("LCLocalFixes");
					managerObject.transform.SetParent(SearchForObject("SimonTendoManagers", ((Component)__instance).transform.parent).transform);
					managerObject.AddComponent<Mythra>();
				}
				if (Configs.spectateFlashlight.Value)
				{
					HazardAudioLog.PatchFlashlight(__instance);
				}
			}
		}

		internal static ManualLogSource Logger;

		public static Harmony harmony;

		public static AssetBundle assetBundle;

		public static GameObject managerObject;

		public static bool foundModelReplacement;

		public static Configs MyConfig { get; internal set; }

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Expected O, but got Unknown
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Expected O, but got Unknown
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Expected O, but got Unknown
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Expected O, but got Unknown
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin LCLocalFixes is loaded!");
			harmony = new Harmony("LCLocalFixes");
			assetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "localfixesassetbundle"));
			if ((Object)(object)assetBundle == (Object)null)
			{
				Logger.LogError((object)"failed to load localfixesassetbundle");
				return;
			}
			Logger.LogDebug((object)"successfully loaded localfixesassetbundle");
			MyConfig = new Configs(((BaseUnityPlugin)this).Config);
			Configs.DisplayConfigs();
			harmony.Patch((MethodBase)typeof(StartOfRound).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, new HarmonyMethod(typeof(NewStartOfRound).GetMethod("StartPostfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			if (Configs.editorTimeToggle.Value)
			{
				harmony.Patch((MethodBase)typeof(ShipBuildModeManager).GetMethod("StoreObject_performed", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, new HarmonyMethod(typeof(EditorTimeToggle.NewShipBuildModeManager).GetMethod("ToggleTimeMultiplier")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (Configs.hazardAudioLogLandmine.Value)
			{
				harmony.Patch((MethodBase)typeof(Landmine).GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, new HarmonyMethod(typeof(HazardAudioLog.NewLandmine).GetMethod("StartPostfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (Configs.animatedObjectTrigger.Value)
			{
				harmony.Patch((MethodBase)typeof(AnimatedObjectTrigger).GetMethod("PlayAudio", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(LevelBugs.NewAnimatedObjectTrigger).GetMethod("PatchExperimentationParticles")), (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (Configs.artifice.Value)
			{
				harmony.Patch((MethodBase)typeof(StartOfRound).GetMethod("openingDoorsSequence"), (HarmonyMethod)null, new HarmonyMethod(typeof(LevelBugs.NewStartOfRound).GetMethod("openingDoorsSequencePostfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (Configs.timeOfDayMusic.Value)
			{
				harmony.Patch((MethodBase)typeof(TimeOfDay).GetMethod("PlayTimeMusicDelayed"), new HarmonyMethod(typeof(TimeOfDayMusic.NewTimeOfDay).GetMethod("PlayTimeMusicDelayedPrefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (Configs.elevatorNavigation.Value)
			{
				harmony.Patch((MethodBase)typeof(ManualCameraRenderer).GetMethod("SetLineToExitFromRadarTarget", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(MineshaftOddities.NewManualCameraRenderer).GetMethod("PatchCameraLineRenderer")), (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (Configs.mythra.Value)
			{
				foundModelReplacement = CheckForPlugin("ModelReplacementAPI");
				if (foundModelReplacement)
				{
					PatchBodyReplacement();
				}
			}
			if (CheckForPlugin("LethalConfig"))
			{
				AddToLethalConfig();
			}
		}

		private static void PatchBodyReplacement()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			harmony.Patch((MethodBase)typeof(BodyReplacementBase).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, new HarmonyMethod(typeof(Mythra.NewBodyReplacementBase).GetMethod("AwakePostfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static bool CheckForPlugin(string pluginName, bool printDebug = true)
		{
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				if (value.Metadata.Name == pluginName)
				{
					if (printDebug)
					{
						Logger.LogDebug((object)("Successfully found " + pluginName));
					}
					return true;
				}
			}
			if (printDebug)
			{
				Logger.LogDebug((object)("Failed to find " + pluginName));
			}
			return false;
		}

		public static GameObject SearchForObject(string name, Transform parentTransform = null)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			Logger.LogDebug((object)("Starting search for " + name));
			GameObject[] array = Object.FindObjectsByType<GameObject>((FindObjectsSortMode)0);
			GameObject[] array2 = array;
			GameObject result;
			foreach (GameObject val in array2)
			{
				if (((Object)val).name == name)
				{
					result = val;
					Logger.LogDebug((object)("Found existing " + ((Object)val).name + ", using as parent."));
					return result;
				}
			}
			result = new GameObject(name);
			if ((Object)(object)parentTransform != (Object)null)
			{
				result.transform.SetParent(parentTransform, false);
			}
			Logger.LogDebug((object)("Did not find existing " + name + ", instantiating new " + ((Object)result).name));
			return result;
		}

		private static void AddToLethalConfig()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			LethalConfigManager.SetModIcon(assetBundle.LoadAsset<Sprite>("Assets/icon1.png"));
			LethalConfigManager.SetModDescription("Tweaks to oddities in the vanilla game or in other mods that bothered me.");
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Configs.editorTimeToggle, true));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Configs.hazardAudioLogLandmine, true));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Configs.hazardAudioLogSpikes, true));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Configs.timeOfDayMusic, true));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Configs.elevatorNavigation, true));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Configs.artifice, true));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Configs.animatedObjectTrigger, true));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Configs.mythra, true));
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Configs.spectateFlashlight, true));
		}
	}
	public class TimeOfDayMusic
	{
		[HarmonyPatch(typeof(TimeOfDay), "PlayTimeMusicDelayed")]
		public class NewTimeOfDay
		{
			[HarmonyPrefix]
			public static void PlayTimeMusicDelayedPrefix()
			{
				if (!Configs.timeOfDayMusic.Value)
				{
					Logger.LogWarning((object)"Configs.timeOfDayMusic is false yet patch still executed, returning");
					return;
				}
				if ((Object)(object)TimeOfDay.Instance == (Object)null || (Object)(object)StartOfRound.Instance == (Object)null)
				{
					Logger.LogWarning((object)"TimeOfDayMusic.PlayTimeMusicDelayedPrefix(): null");
					return;
				}
				float num = Mathf.Pow(0.75f, (float)StartOfRound.Instance.connectedPlayersAmount);
				float num2 = Random.Range(0f, 1f);
				Logger.LogDebug((object)$"Resetting TimeOfDay.Instance.playDelayedMusicCoroutine ({num2} <= {num} = {num2 <= num})");
				if (num2 <= num)
				{
					TimeOfDay.Instance.playDelayedMusicCoroutine = null;
				}
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LCLocalFixes";

		public const string PLUGIN_NAME = "LCLocalFixes";

		public const string PLUGIN_VERSION = "0.0.2";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}