Decompiled source of SavageDifficulty v0.1.1

SavageDifficulty.dll

Decompiled 12 hours 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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SavageDifficulty.Patches;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SavageDifficulty")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A custom difficulty mod that aims to be harder than Brutal, within reason.")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+7c0fd636a1014ccc028a20ba8982c568a1cd9bc4")]
[assembly: AssemblyProduct("SavageDifficulty")]
[assembly: AssemblyTitle("SavageDifficulty")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SavageDifficulty
{
	[BepInPlugin("com.whyis2plus2.SavageDifficulty", "SavageDifficulty", "0.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.whyis2plus2.SavageDifficulty";

		public const string PLUGIN_NAME = "SavageDifficulty";

		public const string PLUGIN_VERSION = "0.1.1";

		public const string DIF_NAME = "Savage";

		public static Plugin instance;

		public GameObject difficultyButton = null;

		public GameObject difficultyInfo = null;

		public readonly Harmony harmony = new Harmony("com.whyis2plus2.SavageDifficulty");

		public GameObject homingProjectile;

		public GameObject providenceProjectile;

		public GameObject virtueInsignia;

		private static bool addressablesInit;

		public Transform interactables { get; private set; }

		public Transform canvas { get; private set; }

		public ManualLogSource logger => ((BaseUnityPlugin)this).Logger;

		private T LoadAsset<T>(string path)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!addressablesInit)
			{
				Addressables.InitializeAsync().WaitForCompletion();
				addressablesInit = true;
			}
			return Addressables.LoadAssetAsync<T>((object)path).WaitForCompletion();
		}

		private void Awake()
		{
			instance = this;
			SceneManager.activeSceneChanged += delegate
			{
				OnSceneChange();
			};
			homingProjectile = LoadAsset<GameObject>("Assets/Prefabs/Attacks and Projectiles/Projectile Homing.prefab");
			providenceProjectile = LoadAsset<GameObject>("Assets/Prefabs/Attacks and Projectiles/Projectile Providence.prefab");
			virtueInsignia = LoadAsset<GameObject>("f53d12327d16b8c4cb8c0ddd759db126");
			harmony.PatchAll(typeof(PresenceControllerPatch));
			harmony.PatchAll(typeof(DifficultyTitlePatch));
			harmony.PatchAll(typeof(PrefsManagerPatch));
			harmony.PatchAll(typeof(RankDataPatch));
			harmony.PatchAll(typeof(GameProgressSaverPatch));
			harmony.PatchAll(typeof(LevelSelectPanelPatch));
			harmony.PatchAll(typeof(EndlessHighScorePatch));
			harmony.PatchAll(typeof(EnemyPatch));
			harmony.PatchAll(typeof(ProvidencePatch));
			harmony.PatchAll(typeof(SentryPatch));
			harmony.PatchAll(typeof(EarthmoverTimerFix));
			logger.LogInfo((object)"Loaded SavageDifficulty");
		}

		private void OnSceneChange()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (!(SceneHelper.CurrentScene != "Main Menu"))
			{
				Scene activeScene = SceneManager.GetActiveScene();
				canvas = (from obj in ((Scene)(ref activeScene)).GetRootGameObjects()
					where ((Object)obj).name == "Canvas"
					select obj).First().transform;
				interactables = canvas.Find("Difficulty Select (1)/Interactables");
				AddInfo();
				AddButton();
			}
		}

		private void AddButton()
		{
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			logger.LogInfo((object)"Adding difficulty button...");
			Dictionary<string, GameObject> dictionary = new Dictionary<string, GameObject>(new <>z__ReadOnlyArray<KeyValuePair<string, GameObject>>(new KeyValuePair<string, GameObject>[6]
			{
				FindElem("Casual Easy"),
				FindElem("Casual Hard"),
				FindElem("Standard"),
				FindElem("Violent"),
				FindElem("Brutal"),
				FindElem("V1 Must Die")
			}));
			Dictionary<string, GameObject> infos = new Dictionary<string, GameObject>(new <>z__ReadOnlyArray<KeyValuePair<string, GameObject>>(new KeyValuePair<string, GameObject>[5]
			{
				FindElem("Harmless Info"),
				FindElem("Lenient Info"),
				FindElem("Standard Info"),
				FindElem("Violent Info"),
				FindElem("Brutal Info")
			}));
			difficultyButton = Object.Instantiate<GameObject>(GeneralExtensions.GetValueSafe<string, GameObject>(dictionary, "Brutal"), interactables);
			difficultyButton.GetComponent<DifficultySelectButton>().difficulty = 12;
			((Component)difficultyButton.transform.Find("Name")).GetComponent<TMP_Text>().text = "Savage".ToUpper();
			difficultyButton.transform.position = GeneralExtensions.GetValueSafe<string, GameObject>(dictionary, "V1 Must Die").transform.position;
			difficultyButton.transform.position = new Vector3(difficultyButton.transform.position.x + 600f, difficultyButton.transform.position.y, difficultyButton.transform.position.z);
			((Object)difficultyButton).name = "Savage";
			GeneralExtensions.GetValueSafe<string, GameObject>(dictionary, "V1 Must Die").gameObject.SetActive(false);
			EventTrigger component = difficultyButton.GetComponent<EventTrigger>();
			component.triggers.Clear();
			if (!Object.op_Implicit((Object)(object)difficultyInfo))
			{
				AddInfo();
			}
			foreach (GameObject value in dictionary.Values)
			{
				EventTrigger component2 = value.GetComponent<EventTrigger>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					component2.triggers.Add(Tools.CreateTriggerEntry((EventTriggerType)0, delegate
					{
						difficultyInfo.SetActive(false);
					}));
				}
			}
			component.triggers.AddRange(new <>z__ReadOnlyArray<Entry>((Entry[])(object)new Entry[3]
			{
				Tools.CreateTriggerEntry((EventTriggerType)0, delegate
				{
					difficultyInfo.SetActive(true);
					foreach (GameObject value2 in infos.Values)
					{
						value2.SetActive(false);
					}
				}),
				Tools.CreateTriggerEntry((EventTriggerType)1, delegate
				{
					difficultyInfo.SetActive(false);
				}),
				Tools.CreateTriggerEntry((EventTriggerType)4, delegate
				{
					MonoSingleton<PrefsManager>.Instance.SetInt("difficulty", 12);
					difficultyInfo.SetActive(false);
				})
			}));
			ObjectActivateInSequence component3 = ((Component)interactables).GetComponent<ObjectActivateInSequence>();
			component3.objectsToActivate = CollectionExtensions.AddItem<GameObject>((IEnumerable<GameObject>)component3.objectsToActivate, difficultyButton).ToArray();
			logger.LogInfo((object)"Added difficulty button");
			KeyValuePair<string, GameObject> FindElem(string name)
			{
				return new KeyValuePair<string, GameObject>(name, ((Component)interactables.Find(name)).gameObject);
			}
		}

		private void AddInfo()
		{
			logger.LogInfo((object)"Adding difficulty Info...");
			difficultyInfo = Object.Instantiate<GameObject>(((Component)interactables.Find("Brutal Info")).gameObject, interactables);
			((Object)difficultyInfo).name = "Savage Info";
			TMP_Text component = ((Component)difficultyInfo.transform.Find("Title (1)")).GetComponent<TMP_Text>();
			component.text = "--" + "Savage".ToUpper() + "--";
			((Component)difficultyInfo.transform.Find("Text")).GetComponent<TMP_Text>().text = "<color=white>Extremely agressive enemies and higher damage than brutal.\r\n\r\nA full arsenal and extensive knowledge of the game are expected. Every small mistake could be a fatal error.</color>\r\n\r\n<b>Recommended for those who are used to the difficulty of brutal and are looking for a new challenge.</b>";
			logger.LogInfo((object)"Added difficulty Info");
		}
	}
	public static class Tools
	{
		public static Entry CreateTriggerEntry(EventTriggerType id, UnityAction<BaseEventData> call)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			Entry val = new Entry
			{
				eventID = id
			};
			((UnityEvent<BaseEventData>)(object)val.callback).AddListener(call);
			return val;
		}
	}
}
namespace SavageDifficulty.Patches
{
	public static class DifficultyTitlePatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(DifficultyTitle), "Check")]
		public static bool DifficultyTitle_Check_Prefix(ref DifficultyTitle __instance, ref TMP_Text ___txt2)
		{
			int @int = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			if (@int != 12)
			{
				return true;
			}
			string text = "Savage".ToUpper();
			if (__instance.lines)
			{
				text = "-- " + text + " --";
			}
			if (!Object.op_Implicit((Object)(object)___txt2))
			{
				___txt2 = ((Component)__instance).GetComponent<TMP_Text>();
			}
			___txt2.text = text;
			return false;
		}
	}
	public static class EarthmoverTimerFix
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Countdown), "GetCountdownLength")]
		public static bool Coundown_GetCountdownLength_Prefix(ref float __result)
		{
			int @int = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			if (@int != 12)
			{
				return true;
			}
			__result = 40f;
			return false;
		}
	}
	public static class EndlessHighScorePatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(EndlessHighScore), "OnEnable")]
		public static bool EndlessHighScore_OnEnable_Patch()
		{
			return MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0) <= 5;
		}
	}
	public static class EnemyPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(EnemyIdentifier), "UpdateModifiers")]
		public static void StatsScaling(ref EnemyIdentifier __instance)
		{
			//IL_0025: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Invalid comparison between Unknown and I4
			int @int = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			if (@int != 12)
			{
				return;
			}
			EnemyType enemyType = __instance.enemyType;
			bool flag = (((int)enemyType == 21 || (int)enemyType == 39) ? true : false);
			if (flag || __instance.puppet)
			{
				return;
			}
			EnemyIdentifier obj = __instance;
			obj.totalDamageModifier *= 1.2f;
			if ((int)__instance.enemyType != 3)
			{
				EnemyIdentifier obj2 = __instance;
				obj2.totalSpeedModifier *= 1.2f;
				if (__instance.isBoss)
				{
					EnemyIdentifier obj3 = __instance;
					obj3.totalHealthModifier *= 1.25f;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Enemy), "InitializeDifficulty")]
		public static bool ForceDifficultyOverride(ref int __result)
		{
			int @int = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			if (@int != 12)
			{
				return true;
			}
			__result = 4;
			return false;
		}
	}
	public static class GameProgressSaverPatch
	{
		private static MethodInfo GetGameProgressMethodInfoA = typeof(GameProgressSaver).GetMethod("GetGameProgress", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[1] { typeof(int) }, null);

		private static GameProgressData GetGameProgress(int difficulty = -1)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			return (GameProgressData)GetGameProgressMethodInfoA.Invoke(null, new object[1] { difficulty });
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameProgressSaver), "GetProgress")]
		public static bool GameProgressSaver_GetProgress_Prefix(ref int __result, ref int difficulty)
		{
			int num = 1;
			for (int i = difficulty; i < 13; i++)
			{
				GameProgressData gameProgress = GetGameProgress(i);
				if (gameProgress != null && gameProgress.difficulty == i && gameProgress.levelNum > num)
				{
					num = gameProgress.levelNum;
				}
			}
			__result = num;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameProgressSaver), "GetEncoreProgress")]
		public static bool GameProgressSaver_GetEncoreProgress_Prefix(ref int __result, ref int difficulty)
		{
			int num = 0;
			for (int i = difficulty; i < 13; i++)
			{
				GameProgressData gameProgress = GetGameProgress(i);
				if (gameProgress != null && gameProgress.difficulty == i && gameProgress.encores > num)
				{
					num = gameProgress.encores;
				}
			}
			__result = num;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameProgressSaver), "GetPrime")]
		public static bool GameProgressSaver_GetPrime_Prefix(ref int __result, ref int difficulty, ref int level)
		{
			if (SceneHelper.IsPlayingCustom)
			{
				__result = 0;
				return false;
			}
			level--;
			int num = 0;
			for (int i = difficulty; i < 13; i++)
			{
				GameProgressData gameProgress = GetGameProgress(i);
				if (gameProgress != null && gameProgress.difficulty == i && gameProgress.primeLevels != null && gameProgress.primeLevels.Length > level && gameProgress.primeLevels[level] > num)
				{
					if (gameProgress.primeLevels[level] >= 2)
					{
						__result = 2;
						return false;
					}
					num = gameProgress.primeLevels[level];
				}
			}
			__result = num;
			return false;
		}
	}
	public static class LevelSelectPanelPatch
	{
		private static void FakeSetup(ref LevelSelectPanel instance, ref LayerSelect _ls, ref Sprite _origSprite)
		{
			if ((Object)(object)_ls == (Object)null)
			{
				_ls = ((Component)((Component)instance).transform.parent).GetComponent<LayerSelect>();
			}
			if ((Object)(object)_ls == (Object)null && (Object)(object)((Component)instance).transform.parent.parent != (Object)null)
			{
				_ls = ((Component)((Component)instance).transform.parent.parent).GetComponent<LayerSelect>();
			}
			if ((Object)(object)_origSprite == (Object)null)
			{
				_origSprite = ((Component)((Component)instance).transform.Find("Image")).GetComponent<Image>().sprite;
			}
			if ((Object)(object)instance.unfilledPanel == (Object)null && (Object)(object)instance.challengeIcon != (Object)null)
			{
				instance.unfilledPanel = instance.challengeIcon.sprite;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(LevelSelectPanel), "CheckScore")]
		public static bool LevelSelectPanel_CheckScore_Prefix(ref LevelSelectPanel __instance, ref int ___tempInt, ref RectTransform ___rectTransform, ref string ___origName, ref LayerSelect ___ls, ref GameObject ___challengeChecker, ref bool ___allSecrets, ref Color ___defaultColor, ref Sprite ___origSprite)
		{
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba2: Unknown result type (might be due to invalid IL or missing references)
			//IL_070d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c8b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c72: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0995: Unknown result type (might be due to invalid IL or missing references)
			//IL_0857: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b49: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b08: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af7: Unknown result type (might be due to invalid IL or missing references)
			FakeSetup(ref __instance, ref ___ls, ref ___origSprite);
			___rectTransform = ((Component)__instance).GetComponent<RectTransform>();
			if (__instance.levelNumber == 666)
			{
				___tempInt = GameProgressSaver.GetPrime(MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0), __instance.levelNumberInLayer);
			}
			else if (__instance.levelNumber == 100)
			{
				___tempInt = GameProgressSaver.GetEncoreProgress(MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0));
			}
			else
			{
				___tempInt = GameProgressSaver.GetProgress(MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0));
			}
			int num = __instance.levelNumber;
			if (__instance.levelNumber == 666 || __instance.levelNumber == 100)
			{
				num += __instance.levelNumberInLayer - 1;
			}
			___origName = GetMissionName.GetMission(num);
			if ((__instance.levelNumber == 666 && ___tempInt == 0) || (__instance.levelNumber == 100 && ___tempInt < __instance.levelNumberInLayer - 1) || (__instance.levelNumber != 666 && __instance.levelNumber != 100 && ___tempInt < __instance.levelNumber) || __instance.forceOff)
			{
				string text = ___ls.layerNumber.ToString();
				if (___ls.layerNumber == 666)
				{
					text = "P";
				}
				if (___ls.layerNumber == 100)
				{
					((Component)((Component)__instance).transform.Find("Name")).GetComponent<TMP_Text>().text = __instance.levelNumberInLayer - 1 + "-E: ???";
				}
				else
				{
					((Component)((Component)__instance).transform.Find("Name")).GetComponent<TMP_Text>().text = text + "-" + __instance.levelNumberInLayer + ": ???";
				}
				((Component)((Component)__instance).transform.Find("Image")).GetComponent<Image>().sprite = __instance.lockedSprite;
				((Behaviour)((Component)__instance).GetComponent<Button>()).enabled = false;
				___rectTransform.sizeDelta = new Vector2(___rectTransform.sizeDelta.x, __instance.collapsedHeight);
				__instance.leaderboardPanel.SetActive(false);
			}
			else
			{
				bool flag;
				if (___tempInt == __instance.levelNumber || (__instance.levelNumber == 100 && ___tempInt == __instance.levelNumberInLayer - 1) || (__instance.levelNumber == 666 && ___tempInt == 1))
				{
					flag = false;
					((Component)((Component)__instance).transform.Find("Image")).GetComponent<Image>().sprite = __instance.unlockedSprite;
					((Component)((Component)__instance).transform.Find("Name")).GetComponent<TMP_Text>().text = __instance.levelNumberInLayer - 1 + "-E: ???";
				}
				else
				{
					flag = true;
					((Component)((Component)__instance).transform.Find("Image")).GetComponent<Image>().sprite = ___origSprite;
				}
				if (__instance.levelNumber != 100 || ___tempInt != __instance.levelNumberInLayer - 1)
				{
					((Component)((Component)__instance).transform.Find("Name")).GetComponent<TMP_Text>().text = ___origName;
				}
				((Behaviour)((Component)__instance).GetComponent<Button>()).enabled = true;
				if ((Object)(object)__instance.challengeIcon != (Object)null)
				{
					if ((Object)(object)___challengeChecker == (Object)null)
					{
						___challengeChecker = ((Component)((Component)__instance.challengeIcon).transform.Find("EventTrigger")).gameObject;
					}
					if (___tempInt > __instance.levelNumber)
					{
						___challengeChecker.SetActive(true);
					}
				}
				if (LeaderboardController.ShowLevelLeaderboards && flag)
				{
					___rectTransform.sizeDelta = new Vector2(___rectTransform.sizeDelta.x, __instance.expandedHeight);
					__instance.leaderboardPanel.SetActive(true);
				}
				else
				{
					___rectTransform.sizeDelta = new Vector2(___rectTransform.sizeDelta.x, __instance.collapsedHeight);
					__instance.leaderboardPanel.SetActive(false);
				}
			}
			RankData rank = GameProgressSaver.GetRank(num, false);
			if (rank.majorAssists.Length < 13)
			{
				bool[] array = new bool[13];
				for (int i = 0; i < 13; i++)
				{
					if (i < rank.majorAssists.Length)
					{
						array[i] = rank.majorAssists[i];
					}
					else
					{
						array[i] = false;
					}
				}
				rank.majorAssists = array;
			}
			if (rank.ranks.Length < 13)
			{
				int[] array2 = new int[13];
				for (int j = 0; j < 13; j++)
				{
					if (j < rank.ranks.Length)
					{
						array2[j] = rank.ranks[j];
					}
					else
					{
						array2[j] = -1;
					}
				}
				rank.ranks = array2;
			}
			if (rank.stats.Length < 13)
			{
				RankScoreData[] array3 = (RankScoreData[])(object)new RankScoreData[13];
				for (int k = 0; k < rank.stats.Length; k++)
				{
					array3[k] = rank.stats[k];
				}
				rank.stats = array3;
			}
			if (rank == null)
			{
				Debug.Log((object)("Didn't Find Level " + __instance.levelNumber + " Data"));
				Image component = ((Component)((Component)__instance).transform.Find("Stats").Find("Rank")).GetComponent<Image>();
				((Graphic)component).color = Color.white;
				component.sprite = __instance.unfilledPanel;
				((Component)component).GetComponentInChildren<TMP_Text>().text = "";
				___allSecrets = false;
				Image[] secretIcons = __instance.secretIcons;
				foreach (Image val in secretIcons)
				{
					((Behaviour)val).enabled = true;
					val.sprite = __instance.unfilledPanel;
				}
				return false;
			}
			int @int = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			if (rank.levelNumber == __instance.levelNumber || ((__instance.levelNumber == 666 || __instance.levelNumber == 100) && rank.levelNumber == __instance.levelNumber + __instance.levelNumberInLayer - 1))
			{
				TMP_Text componentInChildren = ((Component)((Component)__instance).transform.Find("Stats").Find("Rank")).GetComponentInChildren<TMP_Text>();
				if (rank.ranks[@int] == 12 && (rank.majorAssists == null || !rank.majorAssists[@int]))
				{
					componentInChildren.text = "<color=#FFFFFF>P</color>";
					Image component2 = ((Component)componentInChildren.transform.parent).GetComponent<Image>();
					((Graphic)component2).color = new Color(1f, 0.686f, 0f, 1f);
					component2.sprite = __instance.filledPanel;
					___ls.AddScore(4, true);
				}
				else if (rank.majorAssists != null && rank.majorAssists[@int])
				{
					if (rank.ranks[@int] < 0)
					{
						componentInChildren.text = "";
					}
					else
					{
						switch (rank.ranks[@int])
						{
						case 1:
							componentInChildren.text = "C";
							___ls.AddScore(1, false);
							break;
						case 2:
							componentInChildren.text = "B";
							___ls.AddScore(2, false);
							break;
						case 3:
							componentInChildren.text = "A";
							___ls.AddScore(3, false);
							break;
						case 4:
						case 5:
						case 6:
							___ls.AddScore(4, false);
							componentInChildren.text = "S";
							break;
						default:
							___ls.AddScore(0, false);
							componentInChildren.text = "D";
							break;
						}
						Image component3 = ((Component)componentInChildren.transform.parent).GetComponent<Image>();
						((Graphic)component3).color = new Color(0.3f, 0.6f, 0.9f, 1f);
						component3.sprite = __instance.filledPanel;
					}
				}
				else if (rank.ranks[@int] < 0)
				{
					componentInChildren.text = "";
					Image component4 = ((Component)componentInChildren.transform.parent).GetComponent<Image>();
					((Graphic)component4).color = Color.white;
					component4.sprite = __instance.unfilledPanel;
				}
				else
				{
					switch (rank.ranks[@int])
					{
					case 1:
						componentInChildren.text = "<color=#4CFF00>C</color>";
						___ls.AddScore(1, false);
						break;
					case 2:
						componentInChildren.text = "<color=#FFD800>B</color>";
						___ls.AddScore(2, false);
						break;
					case 3:
						componentInChildren.text = "<color=#FF6A00>A</color>";
						___ls.AddScore(3, false);
						break;
					case 4:
					case 5:
					case 6:
						___ls.AddScore(4, false);
						componentInChildren.text = "<color=#FF0000>S</color>";
						break;
					default:
						___ls.AddScore(0, false);
						componentInChildren.text = "<color=#0094FF>D</color>";
						break;
					}
					Image component5 = ((Component)componentInChildren.transform.parent).GetComponent<Image>();
					((Graphic)component5).color = Color.white;
					component5.sprite = __instance.unfilledPanel;
				}
				if (rank.secretsAmount > 0)
				{
					___allSecrets = true;
					for (int m = 0; m < 5; m++)
					{
						if (m < rank.secretsAmount && rank.secretsFound[m])
						{
							__instance.secretIcons[m].sprite = __instance.filledPanel;
							continue;
						}
						___allSecrets = false;
						__instance.secretIcons[m].sprite = __instance.unfilledPanel;
					}
				}
				else
				{
					Image[] secretIcons2 = __instance.secretIcons;
					for (int n = 0; n < secretIcons2.Length; n++)
					{
						((Behaviour)secretIcons2[n]).enabled = false;
					}
				}
				if (Object.op_Implicit((Object)(object)__instance.challengeIcon))
				{
					if (rank.challenge)
					{
						__instance.challengeIcon.sprite = __instance.filledPanel;
						TMP_Text componentInChildren2 = ((Component)__instance.challengeIcon).GetComponentInChildren<TMP_Text>();
						componentInChildren2.text = "C O M P L E T E";
						if (rank.ranks[@int] == 12 && (___allSecrets || rank.secretsAmount == 0))
						{
							((Graphic)componentInChildren2).color = new Color(0.6f, 0.4f, 0f, 1f);
						}
						else
						{
							((Graphic)componentInChildren2).color = Color.black;
						}
					}
					else
					{
						__instance.challengeIcon.sprite = __instance.unfilledPanel;
						TMP_Text componentInChildren3 = ((Component)__instance.challengeIcon).GetComponentInChildren<TMP_Text>();
						componentInChildren3.text = "C H A L L E N G E";
						((Graphic)componentInChildren3).color = Color.white;
					}
				}
			}
			else
			{
				Debug.Log((object)("Error in finding " + __instance.levelNumber + " Data"));
				Image component6 = ((Component)((Component)__instance).transform.Find("Stats").Find("Rank")).GetComponent<Image>();
				((Graphic)component6).color = Color.white;
				component6.sprite = __instance.unfilledPanel;
				((Component)component6).GetComponentInChildren<TMP_Text>().text = "";
				___allSecrets = false;
				Image[] secretIcons3 = __instance.secretIcons;
				foreach (Image val2 in secretIcons3)
				{
					((Behaviour)val2).enabled = true;
					val2.sprite = __instance.unfilledPanel;
				}
			}
			if ((rank.challenge || !Object.op_Implicit((Object)(object)__instance.challengeIcon)) && rank.ranks[@int] == 12 && (___allSecrets || rank.secretsAmount == 0))
			{
				___ls.Gold();
				((Graphic)((Component)__instance).GetComponent<Image>()).color = new Color(1f, 0.686f, 0f, 0.75f);
				return false;
			}
			((Graphic)((Component)__instance).GetComponent<Image>()).color = ___defaultColor;
			return false;
		}
	}
	public static class PrefsManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void PrefsManager_Ctor_Postfix(ref Dictionary<string, Func<object, object>> ___propertyValidators)
		{
			___propertyValidators.Remove("difficulty");
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PrefsManager), "EnsureValid")]
		public static bool PrefsManager_EnsureValid_Prefix(ref object __result, string __0, object __1)
		{
			__result = __1;
			return false;
		}
	}
	public static class PresenceControllerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(PresenceController), "Start")]
		public static void PresenceController_Start_Postfix(ref PresenceController __instance)
		{
			if (__instance.diffNames.Length < 13)
			{
				string[] array = new string[13];
				for (int i = 0; i < __instance.diffNames.Length; i++)
				{
					array[i] = __instance.diffNames[i];
				}
				array[12] = "Savage".ToUpper();
				__instance.diffNames = array;
			}
		}
	}
	public static class ProvidencePatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Drone), "Shoot")]
		public static void VirtueBeams(ref Drone __instance, ref EnemyIdentifier ___eid)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			int @int = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			if (@int >= 12 && (int)___eid.enemyType == 38)
			{
				GameObject val = Object.Instantiate<GameObject>(Plugin.instance.virtueInsignia);
				VirtueInsignia component = val.GetComponent<VirtueInsignia>();
				component.target = ___eid.target;
				component.parentEnemy = __instance.Enemy;
				component.hadParent = true;
				val.SetActive(true);
			}
		}
	}
	internal class RankDataPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static bool RankData_Ctor_Prefix(ref RankData __instance, ref StatsManager sman)
		{
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Expected O, but got Unknown
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Expected O, but got Unknown
			int @int = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			__instance.levelNumber = sman.levelNumber;
			RankData rank = GameProgressSaver.GetRank(true, -1);
			if (rank != null)
			{
				__instance.ranks = rank.ranks;
				if (rank.majorAssists != null)
				{
					__instance.majorAssists = rank.majorAssists;
				}
				else
				{
					__instance.majorAssists = new bool[13];
				}
				if (rank.stats != null)
				{
					__instance.stats = rank.stats;
				}
				else
				{
					__instance.stats = (RankScoreData[])(object)new RankScoreData[13];
				}
				if (__instance.majorAssists.Length < 13)
				{
					bool[] array = new bool[13];
					for (int i = 0; i < 13; i++)
					{
						if (i < __instance.majorAssists.Length)
						{
							array[i] = __instance.majorAssists[i];
						}
						else
						{
							array[i] = false;
						}
					}
					__instance.majorAssists = array;
				}
				if (__instance.ranks.Length < 13)
				{
					int[] array2 = new int[13];
					for (int j = 0; j < 13; j++)
					{
						if (j < __instance.ranks.Length)
						{
							array2[j] = __instance.ranks[j];
						}
						else
						{
							array2[j] = -1;
						}
					}
					__instance.ranks = array2;
				}
				if (__instance.stats.Length < 13)
				{
					RankScoreData[] array3 = (RankScoreData[])(object)new RankScoreData[13];
					for (int k = 0; k < __instance.stats.Length; k++)
					{
						array3[k] = __instance.stats[k];
					}
					__instance.stats = array3;
				}
				if (rank.majorAssists.Length < 13)
				{
					bool[] array4 = new bool[13];
					for (int l = 0; l < 13; l++)
					{
						if (l < rank.majorAssists.Length)
						{
							array4[l] = rank.majorAssists[l];
						}
						else
						{
							array4[l] = false;
						}
					}
					rank.majorAssists = array4;
				}
				if (rank.ranks.Length < 13)
				{
					int[] array5 = new int[13];
					for (int m = 0; m < 13; m++)
					{
						if (m < rank.ranks.Length)
						{
							array5[m] = rank.ranks[m];
						}
						else
						{
							array5[m] = -1;
						}
					}
					rank.ranks = array5;
				}
				if (rank.stats.Length < 13)
				{
					RankScoreData[] array6 = (RankScoreData[])(object)new RankScoreData[13];
					for (int n = 0; n < rank.stats.Length; n++)
					{
						array6[n] = rank.stats[n];
					}
					rank.stats = array6;
				}
				if ((sman.rankScore >= rank.ranks[@int] && (rank.majorAssists == null || (!sman.majorUsed && rank.majorAssists[@int]))) || sman.rankScore > rank.ranks[@int] || rank.levelNumber != __instance.levelNumber)
				{
					__instance.majorAssists[@int] = sman.majorUsed;
					__instance.ranks[@int] = sman.rankScore;
					if (__instance.stats[@int] == null)
					{
						__instance.stats[@int] = new RankScoreData();
					}
					__instance.stats[@int].kills = sman.kills;
					__instance.stats[@int].style = sman.stylePoints;
					__instance.stats[@int].time = sman.seconds;
				}
				__instance.secretsAmount = sman.secretObjects.Length;
				__instance.secretsFound = new bool[__instance.secretsAmount];
				for (int num = 0; num < __instance.secretsAmount && num < rank.secretsFound.Length; num++)
				{
					if ((Object)(object)sman.secretObjects[num] == (Object)null || rank.secretsFound[num])
					{
						__instance.secretsFound[num] = true;
					}
				}
				__instance.challenge = rank.challenge;
				return false;
			}
			__instance.ranks = new int[13];
			__instance.stats = (RankScoreData[])(object)new RankScoreData[13];
			if (__instance.stats[@int] == null)
			{
				__instance.stats[@int] = new RankScoreData();
			}
			__instance.majorAssists = new bool[13];
			for (int num2 = 0; num2 < __instance.ranks.Length; num2++)
			{
				__instance.ranks[num2] = -1;
			}
			__instance.ranks[@int] = sman.rankScore;
			__instance.majorAssists[@int] = sman.majorUsed;
			__instance.stats[@int].kills = sman.kills;
			__instance.stats[@int].style = sman.stylePoints;
			__instance.stats[@int].time = sman.seconds;
			__instance.secretsAmount = sman.secretObjects.Length;
			__instance.secretsFound = new bool[__instance.secretsAmount];
			for (int num3 = 0; num3 < __instance.secretsAmount; num3++)
			{
				if ((Object)(object)sman.secretObjects[num3] == (Object)null)
				{
					__instance.secretsFound[num3] = true;
				}
			}
			return false;
		}
	}
	public static class SentryPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Turret), "Start")]
		public static void Sentry_Start_Postfix(ref float ___maxAimTime)
		{
			___maxAimTime = 3f;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Turret), "StartAiming")]
		public static void Sentry_StartAiming_Postfix(ref int ___shotsInARow)
		{
			int @int = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			if (@int == 12)
			{
				___shotsInARow = -2;
			}
		}
	}
}
[CompilerGenerated]
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	int ICollection.Count => _items.Length;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => _items.Length;

	T IReadOnlyList<T>.this[int index] => _items[index];

	int ICollection<T>.Count => _items.Length;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlyArray(T[] items)
	{
		_items = items;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return ((IEnumerable)_items).GetEnumerator();
	}

	void ICollection.CopyTo(Array array, int index)
	{
		((ICollection)_items).CopyTo(array, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return ((IList)_items).Contains(value);
	}

	int IList.IndexOf(object value)
	{
		return ((IList)_items).IndexOf(value);
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return ((IEnumerable<T>)_items).GetEnumerator();
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return ((ICollection<T>)_items).Contains(item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		((ICollection<T>)_items).CopyTo(array, arrayIndex);
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return ((IList<T>)_items).IndexOf(item);
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}