Decompiled source of SelectiveRadarEdits v1.0.3

BepInEx/plugins/SelectiveRadarEdits.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 LobbyCompatibility.Attributes;
using Microsoft.CodeAnalysis;
using SelectiveRadarEdits.Patches;
using UnityEngine;
using UnityEngine.Rendering;

[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: AssemblyCompany("SelectiveRadarEdits")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+29f51c968163c2c392a9588a1eee762bc1518b03")]
[assembly: AssemblyProduct("SelectiveRadarEdits")]
[assembly: AssemblyTitle("SelectiveRadarEdits")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 SelectiveRadarEdits
{
	[BepInPlugin("SelectiveRadarEdits", "SelectiveRadarEdits", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[LobbyCompatibility(/*Could not decode attribute arguments.*/)]
	public class SelectiveRadarEdits : BaseUnityPlugin
	{
		private static readonly Dictionary<string, ConfigEntry<bool>> _interiorConfigs = new Dictionary<string, ConfigEntry<bool>>();

		private static readonly Dictionary<string, string> _dungeonNameToFlowName = new Dictionary<string, string>();

		private static bool _hasLethalLevelLoader = false;

		private static bool _configInitialized = false;

		private static string _lastCheckedInterior = "";

		private static bool _loggedBlockingForCurrentInterior = false;

		public static SelectiveRadarEdits Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		public static ConfigEntry<bool> EnableFisheyeCorrection { get; private set; } = null;


		private void Awake()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			EnableFisheyeCorrection = ((BaseUnityPlugin)this).Config.Bind<bool>("Visual Fixes", "Enable Fisheye Correction", true, "Forces the radar's fisheye lens effect to be restored. Disable if you prefer the effect off or if another mod manages it.");
			Harmony = new Harmony("SelectiveRadarEdits");
			bool flag = false;
			try
			{
				Harmony.PatchAll(typeof(RestoreVanillaFishEye));
				Logger.LogInfo((object)"Fisheye fix applied");
				flag = PatchRadarEditMethods();
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Error during patching: " + ex.Message));
			}
			if (flag)
			{
				Logger.LogInfo((object)"SelectiveRadarEdits v1.0.3 loaded successfully");
			}
			else
			{
				Logger.LogError((object)"SelectiveRadarEdits v1.0.3 loaded with errors - RadarEdit integration failed");
			}
		}

		private bool PatchRadarEditMethods()
		{
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			(Type, string)[] array = new(Type, string)[4]
			{
				(typeof(BlockRadarEditfix), "BlockRadarEditfix"),
				(typeof(BlockRadarEditfix2), "BlockRadarEditfix2"),
				(typeof(BlockRadarEditfix3), "BlockRadarEditfix3"),
				(typeof(BlockScenefix), "BlockScenefix")
			};
			int num = 0;
			List<string> list = new List<string>();
			(Type, string)[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				var (type, text) = array2[i];
				try
				{
					MethodInfo method = type.GetMethod("TargetMethod", BindingFlags.Static | BindingFlags.Public);
					if (method == null)
					{
						list.Add(text);
						continue;
					}
					MethodBase methodBase = method.Invoke(null, null) as MethodBase;
					if (methodBase == null)
					{
						list.Add(text);
						continue;
					}
					MethodInfo method2 = type.GetMethod("Prefix", BindingFlags.Static | BindingFlags.Public);
					MethodInfo method3 = type.GetMethod("Postfix", BindingFlags.Static | BindingFlags.Public);
					if (method2 != null && Harmony != null)
					{
						Harmony.Patch(methodBase, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
					if (method3 != null && Harmony != null)
					{
						Harmony.Patch(methodBase, (HarmonyMethod)null, new HarmonyMethod(method3), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
					num++;
				}
				catch (Exception ex)
				{
					list.Add(text);
					Logger.LogError((object)("Failed to patch " + text + ": " + ex.Message));
				}
			}
			if (num == 0)
			{
				Logger.LogError((object)"No RadarEdit patches were successful. The mod cannot function properly.");
				Logger.LogError((object)"Make sure RadarEdit is installed correctly and is a compatible version.");
				return false;
			}
			if (list.Count > 0)
			{
				Logger.LogError((object)("Some RadarEdit patches failed: " + string.Join(", ", list)));
				Logger.LogError((object)"The mod may not function correctly.");
				return false;
			}
			Logger.LogInfo((object)$"All RadarEdit patches applied successfully ({num}/{array.Length})");
			return true;
		}

		private static void EnsureConfigInitialized()
		{
			if (!_configInitialized)
			{
				Logger.LogInfo((object)"Initializing interior configuration...");
				InitializeVanillaInteriors();
				_hasLethalLevelLoader = CheckForLethalLevelLoader();
				if (_hasLethalLevelLoader)
				{
					AddLLLCustomInteriors();
				}
				_configInitialized = true;
				Logger.LogInfo((object)$"Configuration initialized with {_interiorConfigs.Count} interiors");
			}
		}

		private static bool CheckForLethalLevelLoader()
		{
			try
			{
				Type type = Type.GetType("LethalLevelLoader.PatchedContent, LethalLevelLoader");
				return type != null;
			}
			catch
			{
				return false;
			}
		}

		private static void InitializeVanillaInteriors()
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>
			{
				{ "Facility", "Level1Flow" },
				{ "Facility (Extra Large)", "Level1FlowExtraLarge" },
				{ "Facility (3 Exits)", "Level1Flow3Exits" },
				{ "Haunted Mansion", "Level2Flow" },
				{ "Mineshaft", "Level3Flow" }
			};
			foreach (KeyValuePair<string, string> item in dictionary)
			{
				CreateConfigEntry(item.Key, item.Value);
			}
		}

		private static void AddLLLCustomInteriors()
		{
			try
			{
				PropertyInfo propertyInfo = Type.GetType("LethalLevelLoader.PatchedContent, LethalLevelLoader")?.GetProperty("ExtendedDungeonFlows");
				if (!(propertyInfo != null) || !(propertyInfo.GetValue(null) is IList list) || list.Count <= 0)
				{
					return;
				}
				Logger.LogInfo((object)$"Found {list.Count} custom interiors from LethalLevelLoader");
				foreach (object item in list)
				{
					try
					{
						PropertyInfo property = item.GetType().GetProperty("DungeonName");
						PropertyInfo property2 = item.GetType().GetProperty("DungeonFlow");
						if (property != null && property2 != null)
						{
							string text = property.GetValue(item) as string;
							object value = property2.GetValue(item);
							string text2 = value?.GetType().GetProperty("name")?.GetValue(value) as string;
							if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2) && !_dungeonNameToFlowName.Values.Contains(text2))
							{
								CreateConfigEntry(text, text2);
							}
						}
					}
					catch (Exception ex)
					{
						Logger.LogWarning((object)("Failed to process ExtendedDungeonFlow: " + ex.Message));
					}
				}
			}
			catch (Exception ex2)
			{
				Logger.LogError((object)("Error accessing LethalLevelLoader data: " + ex2.Message));
			}
		}

		private static void CreateConfigEntry(string displayName, string flowName)
		{
			if (!_interiorConfigs.ContainsKey(displayName))
			{
				ConfigEntry<bool> value = ((BaseUnityPlugin)Instance).Config.Bind<bool>("Interior Settings", "Enable RadarEdit for " + displayName, false, "Whether RadarEdits should be enabled for " + displayName + " interior. When disabled, the vanilla radar will be used instead.");
				_interiorConfigs[displayName] = value;
				_dungeonNameToFlowName[displayName] = flowName;
			}
		}

		internal static void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		public static bool ShouldBlockRadarEditForCurrentInterior()
		{
			try
			{
				EnsureConfigInitialized();
				if ((Object)(object)RoundManager.Instance?.dungeonGenerator?.Generator?.DungeonFlow == (Object)null)
				{
					return false;
				}
				string name = ((Object)RoundManager.Instance.dungeonGenerator.Generator.DungeonFlow).name;
				if (_lastCheckedInterior != name)
				{
					_lastCheckedInterior = name;
					_loggedBlockingForCurrentInterior = false;
				}
				string text = null;
				foreach (KeyValuePair<string, string> item in _dungeonNameToFlowName)
				{
					if (item.Value == name)
					{
						text = item.Key;
						break;
					}
				}
				if (text != null && _interiorConfigs.TryGetValue(text, out ConfigEntry<bool> value))
				{
					bool value2 = value.Value;
					bool flag = !value2;
					if (!_loggedBlockingForCurrentInterior)
					{
						string text2 = (flag ? "RadarEdits DISABLED (using vanilla radar)" : "RadarEdits ENABLED");
						Logger.LogInfo((object)("Interior: " + text + " - " + text2));
						_loggedBlockingForCurrentInterior = true;
					}
					return flag;
				}
				if (!_loggedBlockingForCurrentInterior)
				{
					Logger.LogInfo((object)("Interior: " + name + " - No config found, defaulting to RadarEdits DISABLED"));
					_loggedBlockingForCurrentInterior = false;
				}
				return false;
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Error in ShouldBlockRadarEditForCurrentInterior: " + ex.Message));
				return false;
			}
		}

		public static string GetCurrentInteriorName()
		{
			try
			{
				if ((Object)(object)RoundManager.Instance?.dungeonGenerator?.Generator?.DungeonFlow == (Object)null)
				{
					return "Unknown (not loaded)";
				}
				return ((Object)RoundManager.Instance.dungeonGenerator.Generator.DungeonFlow).name;
			}
			catch
			{
				return "Unknown (error)";
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SelectiveRadarEdits";

		public const string PLUGIN_NAME = "SelectiveRadarEdits";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}
namespace SelectiveRadarEdits.Patches
{
	public static class RadarEditsTargets
	{
		private static Type? _nestedRadarEditsType;

		private static bool _typeSearchAttempted = false;

		private static readonly object _lock = new object();

		public static Type? GetNestedRadarEditsTypeSafe()
		{
			if (_typeSearchAttempted)
			{
				return _nestedRadarEditsType;
			}
			lock (_lock)
			{
				if (_typeSearchAttempted)
				{
					return _nestedRadarEditsType;
				}
				_typeSearchAttempted = true;
				try
				{
					Type type = null;
					try
					{
						type = Type.GetType("huluoboRadarEdit.huluoboRadarEdits, RadarEdit");
					}
					catch
					{
					}
					if (type == null)
					{
						Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
						foreach (Assembly assembly in assemblies)
						{
							try
							{
								if (assembly.GetName().Name == "RadarEdit")
								{
									type = assembly.GetType("huluoboRadarEdit.huluoboRadarEdits");
									if (type != null)
									{
										break;
									}
								}
							}
							catch
							{
							}
						}
					}
					if (type != null)
					{
						try
						{
							_nestedRadarEditsType = AccessTools.Inner(type, "RadarEdits");
							if (_nestedRadarEditsType == null)
							{
								ManualLogSource logger = SelectiveRadarEdits.Logger;
								if (logger != null)
								{
									logger.LogError((object)"Found RadarEdit mod but internal structure has changed - RadarEdits nested type not found");
								}
							}
						}
						catch (Exception ex)
						{
							ManualLogSource logger2 = SelectiveRadarEdits.Logger;
							if (logger2 != null)
							{
								logger2.LogError((object)("Error accessing RadarEdit internal types: " + ex.Message));
							}
						}
					}
					else
					{
						ManualLogSource logger3 = SelectiveRadarEdits.Logger;
						if (logger3 != null)
						{
							logger3.LogError((object)"RadarEdit mod structure not recognised");
						}
					}
				}
				catch (Exception ex2)
				{
					ManualLogSource logger4 = SelectiveRadarEdits.Logger;
					if (logger4 != null)
					{
						logger4.LogError((object)("Error during RadarEdit type discovery: " + ex2.Message));
					}
				}
				return _nestedRadarEditsType;
			}
		}
	}
	public static class VanillaRadarValues
	{
		public const float OrthographicSize = 19.7f;

		public const float NearClipPlane = -2.47f;

		public const float FarClipPlane = 7.52f;
	}
	internal class BlockRadarEditfix
	{
		public static MethodBase? TargetMethod()
		{
			try
			{
				Type nestedRadarEditsTypeSafe = RadarEditsTargets.GetNestedRadarEditsTypeSafe();
				if (nestedRadarEditsTypeSafe == null)
				{
					return null;
				}
				return AccessTools.Method(nestedRadarEditsTypeSafe, "RadarEditfix", new Type[1] { typeof(ManualCameraRenderer) }, (Type[])null);
			}
			catch
			{
				return null;
			}
		}

		public static bool Prefix(ManualCameraRenderer __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return true;
			}
			try
			{
				if ((Object)(object)StartOfRound.Instance?.mapScreen == (Object)(object)__instance)
				{
					goto IL_0051;
				}
				GameObject gameObject = ((Component)__instance).gameObject;
				if (((gameObject != null) ? ((Object)gameObject).name : null) == "TerminalScript")
				{
					goto IL_0051;
				}
				goto end_IL_0014;
				IL_0051:
				if (SelectiveRadarEdits.ShouldBlockRadarEditForCurrentInterior())
				{
					SetupVanillaRadar(__instance);
					return false;
				}
				end_IL_0014:;
			}
			catch (Exception ex)
			{
				ManualLogSource logger = SelectiveRadarEdits.Logger;
				if (logger != null)
				{
					logger.LogError((object)("Error in BlockRadarEditfix.Prefix: " + ex.Message));
				}
			}
			return true;
		}

		public static void Postfix(ManualCameraRenderer __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			try
			{
				if (!((Object)(object)StartOfRound.Instance?.mapScreen == (Object)(object)__instance))
				{
					GameObject gameObject = ((Component)__instance).gameObject;
					if (!(((gameObject != null) ? ((Object)gameObject).name : null) == "TerminalScript"))
					{
						return;
					}
				}
				RestoreVolumeWeightsForFishEye(__instance);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = SelectiveRadarEdits.Logger;
				if (logger != null)
				{
					logger.LogError((object)("Error in BlockRadarEditfix.Postfix: " + ex.Message));
				}
			}
		}

		private static void RestoreVolumeWeightsForFishEye(ManualCameraRenderer __instance)
		{
			try
			{
				Camera cam = __instance.cam;
				object obj;
				if (cam == null)
				{
					obj = null;
				}
				else
				{
					Transform transform = ((Component)cam).transform;
					if (transform == null)
					{
						obj = null;
					}
					else
					{
						Transform obj2 = transform.Find("VolumeMain (1)");
						obj = ((obj2 != null) ? ((Component)obj2).GetComponent<Volume>() : null);
					}
				}
				Volume val = (Volume)obj;
				if ((Object)(object)val != (Object)null && val.weight != 1f)
				{
					val.weight = 1f;
				}
				Camera cam2 = __instance.cam;
				object obj3;
				if (cam2 == null)
				{
					obj3 = null;
				}
				else
				{
					Transform transform2 = ((Component)cam2).transform;
					obj3 = ((transform2 != null) ? transform2.Find("VolumeMain (2)") : null);
				}
				Transform val2 = (Transform)obj3;
				if ((Object)(object)val2 != (Object)null)
				{
					if (!((Component)val2).gameObject.activeInHierarchy)
					{
						((Component)val2).gameObject.SetActive(true);
					}
					Volume component = ((Component)val2).GetComponent<Volume>();
					if ((Object)(object)component != (Object)null && component.weight != 1f)
					{
						component.weight = 1f;
					}
				}
			}
			catch (Exception arg)
			{
				ManualLogSource logger = SelectiveRadarEdits.Logger;
				if (logger != null)
				{
					logger.LogError((object)$"Error in RestoreVolumeWeightsForFishEye: {arg}");
				}
			}
		}

		private static void SetupVanillaRadar(ManualCameraRenderer __instance)
		{
			try
			{
				if ((Object)(object)__instance?.cam == (Object)null)
				{
					return;
				}
				int mask = LayerMask.GetMask(new string[1] { "MapRadar" });
				__instance.cam.cullingMask = mask;
				__instance.cam.orthographicSize = 19.7f;
				__instance.cameraNearPlane = -2.47f;
				__instance.cameraFarPlane = 7.52f;
				__instance.cam.nearClipPlane = __instance.cameraNearPlane;
				__instance.cam.farClipPlane = __instance.cameraFarPlane;
				if ((Object)(object)__instance.mapCamera != (Object)null && (Object)(object)__instance.mapCamera != (Object)(object)__instance.cam)
				{
					__instance.mapCamera.nearClipPlane = __instance.cameraNearPlane;
					__instance.mapCamera.farClipPlane = __instance.cameraFarPlane;
					__instance.mapCamera.cullingMask = mask;
					__instance.mapCamera.orthographicSize = 19.7f;
				}
				Transform transform = ((Component)__instance.cam).transform;
				object obj;
				if (transform == null)
				{
					obj = null;
				}
				else
				{
					Transform obj2 = transform.Find("VolumeMain (1)");
					obj = ((obj2 != null) ? ((Component)obj2).GetComponent<Volume>() : null);
				}
				Volume val = (Volume)obj;
				if ((Object)(object)val != (Object)null)
				{
					val.weight = 1f;
				}
				Transform transform2 = ((Component)__instance.cam).transform;
				Transform val2 = ((transform2 != null) ? transform2.Find("VolumeMain (2)") : null);
				if ((Object)(object)val2 != (Object)null)
				{
					((Component)val2).gameObject.SetActive(true);
					Volume component = ((Component)val2).GetComponent<Volume>();
					if ((Object)(object)component != (Object)null)
					{
						component.weight = 1f;
					}
				}
			}
			catch (Exception arg)
			{
				ManualLogSource logger = SelectiveRadarEdits.Logger;
				if (logger != null)
				{
					logger.LogError((object)$"Error in SetupVanillaRadar: {arg}");
				}
			}
		}
	}
	internal class BlockRadarEditfix2
	{
		public static MethodBase? TargetMethod()
		{
			try
			{
				Type nestedRadarEditsTypeSafe = RadarEditsTargets.GetNestedRadarEditsTypeSafe();
				if (nestedRadarEditsTypeSafe == null)
				{
					return null;
				}
				return AccessTools.Method(nestedRadarEditsTypeSafe, "RadarEditfix2", new Type[2]
				{
					typeof(ManualCameraRenderer),
					typeof(Vector3).MakeByRefType()
				}, (Type[])null);
			}
			catch
			{
				return null;
			}
		}

		public static bool Prefix(ManualCameraRenderer __instance, ref Vector3 pos)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null)
			{
				return true;
			}
			try
			{
				if (SelectiveRadarEdits.ShouldBlockRadarEditForCurrentInterior())
				{
					if ((Object)(object)GameNetworkManager.Instance?.localPlayerController != (Object)null)
					{
						Vector3 position = __instance.radarTargets[__instance.targetTransformIndex].transform.position;
						if ((Object)(object)__instance.targetedPlayer != (Object)null && __instance.targetedPlayer.isInHangarShipRoom)
						{
							__instance.mapCamera.nearClipPlane = -0.96f;
							__instance.mapCamera.farClipPlane = 7.52f;
							StartOfRound.Instance.radarCanvas.planeDistance = -0.93f;
						}
						else
						{
							__instance.mapCamera.nearClipPlane = -2.47f;
							__instance.mapCamera.farClipPlane = 7.52f;
							StartOfRound.Instance.radarCanvas.planeDistance = -0.93f;
						}
						((Component)__instance.mapCamera).transform.position = new Vector3(pos.x, pos.y + 3.636f, pos.z);
					}
					return false;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = SelectiveRadarEdits.Logger;
				if (logger != null)
				{
					logger.LogError((object)("Error in BlockRadarEditfix2.Prefix: " + ex.Message));
				}
			}
			return true;
		}
	}
	internal class BlockRadarEditfix3
	{
		public static MethodBase? TargetMethod()
		{
			try
			{
				Type nestedRadarEditsTypeSafe = RadarEditsTargets.GetNestedRadarEditsTypeSafe();
				if (nestedRadarEditsTypeSafe == null)
				{
					return null;
				}
				return AccessTools.Method(nestedRadarEditsTypeSafe, "RadarEditfix3", new Type[1] { typeof(ManualCameraRenderer) }, (Type[])null);
			}
			catch
			{
				return null;
			}
		}

		public static bool Prefix(ManualCameraRenderer __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return true;
			}
			try
			{
				if (SelectiveRadarEdits.ShouldBlockRadarEditForCurrentInterior())
				{
					return false;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = SelectiveRadarEdits.Logger;
				if (logger != null)
				{
					logger.LogError((object)("Error in BlockRadarEditfix3.Prefix: " + ex.Message));
				}
			}
			return true;
		}
	}
	internal class BlockScenefix
	{
		public static MethodBase? TargetMethod()
		{
			try
			{
				Type nestedRadarEditsTypeSafe = RadarEditsTargets.GetNestedRadarEditsTypeSafe();
				if (nestedRadarEditsTypeSafe == null)
				{
					return null;
				}
				return AccessTools.Method(nestedRadarEditsTypeSafe, "Scenefix", (Type[])null, (Type[])null);
			}
			catch
			{
				return null;
			}
		}

		public static bool Prefix()
		{
			try
			{
				if (SelectiveRadarEdits.ShouldBlockRadarEditForCurrentInterior())
				{
					return false;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = SelectiveRadarEdits.Logger;
				if (logger != null)
				{
					logger.LogError((object)("Error in BlockScenefix.Prefix: " + ex.Message));
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ManualCameraRenderer), "Update")]
	[HarmonyPriority(0)]
	internal class RestoreVanillaFishEye
	{
		private static void Postfix(ManualCameraRenderer __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			try
			{
				if (!((Object)(object)StartOfRound.Instance?.mapScreen == (Object)(object)__instance))
				{
					GameObject gameObject = ((Component)__instance).gameObject;
					if (!(((gameObject != null) ? ((Object)gameObject).name : null) == "TerminalScript"))
					{
						return;
					}
				}
				if (SelectiveRadarEdits.EnableFisheyeCorrection.Value)
				{
					EnsureProperVolumeWeights(__instance);
				}
				if (SelectiveRadarEdits.ShouldBlockRadarEditForCurrentInterior())
				{
					int mask = LayerMask.GetMask(new string[1] { "MapRadar" });
					if (__instance.cam.cullingMask != mask)
					{
						__instance.cam.cullingMask = mask;
					}
					if (Math.Abs(__instance.cam.orthographicSize - 19.7f) > 0.01f)
					{
						__instance.cam.orthographicSize = 19.7f;
					}
					if (Math.Abs(__instance.cam.nearClipPlane - -2.47f) > 0.01f || Math.Abs(__instance.cam.farClipPlane - 7.52f) > 0.01f)
					{
						__instance.cam.nearClipPlane = -2.47f;
						__instance.cam.farClipPlane = 7.52f;
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = SelectiveRadarEdits.Logger;
				if (logger != null)
				{
					logger.LogError((object)("Error in RestoreVanillaFishEye.Postfix: " + ex.Message));
				}
			}
		}

		private static void EnsureProperVolumeWeights(ManualCameraRenderer __instance)
		{
			try
			{
				if (!((Object)(object)__instance?.lensDistortionVolume != (Object)null) || !(__instance.lensDistortionVolume.weight > 0f))
				{
					return;
				}
				Camera cam = __instance.cam;
				object obj;
				if (cam == null)
				{
					obj = null;
				}
				else
				{
					Transform transform = ((Component)cam).transform;
					if (transform == null)
					{
						obj = null;
					}
					else
					{
						Transform obj2 = transform.Find("VolumeMain (1)");
						obj = ((obj2 != null) ? ((Component)obj2).GetComponent<Volume>() : null);
					}
				}
				Volume val = (Volume)obj;
				if ((Object)(object)val != (Object)null && val.weight != 1f)
				{
					val.weight = 1f;
				}
				Camera cam2 = __instance.cam;
				object obj3;
				if (cam2 == null)
				{
					obj3 = null;
				}
				else
				{
					Transform transform2 = ((Component)cam2).transform;
					obj3 = ((transform2 != null) ? transform2.Find("VolumeMain (2)") : null);
				}
				Transform val2 = (Transform)obj3;
				if ((Object)(object)val2 != (Object)null)
				{
					if (!((Component)val2).gameObject.activeInHierarchy)
					{
						((Component)val2).gameObject.SetActive(true);
					}
					Volume component = ((Component)val2).GetComponent<Volume>();
					if ((Object)(object)component != (Object)null && component.weight != 1f)
					{
						component.weight = 1f;
					}
				}
			}
			catch (Exception arg)
			{
				ManualLogSource logger = SelectiveRadarEdits.Logger;
				if (logger != null)
				{
					logger.LogError((object)$"Error in EnsureProperVolumeWeights: {arg}");
				}
			}
		}
	}
}