Decompiled source of UltraUnlock v1.0.1

UltraUnlock.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.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;
		}
	}
}
[BepInPlugin("silentsmilee.ultraunlock", "UltraUnlock", "1.0.1")]
public sealed class UltraUnlock : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <Run>d__7 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public UltraUnlock <>4__this;

		private MainMenuAgony <m>5__2;

		private int <i>5__3;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <Run>d__7(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<m>5__2 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			int num = <>1__state;
			UltraUnlock ultraUnlock = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<m>5__2 = null;
				<i>5__3 = 0;
				goto IL_008e;
			case 1:
				<>1__state = -1;
				<i>5__3++;
				goto IL_008e;
			case 2:
				<>1__state = -1;
				<i>5__3++;
				goto IL_00da;
			case 3:
				{
					<>1__state = -1;
					<i>5__3++;
					break;
				}
				IL_008e:
				if (<i>5__3 < 3000)
				{
					<m>5__2 = Object.FindObjectOfType<MainMenuAgony>();
					if (!Object.op_Implicit((Object)(object)<m>5__2) || !((Component)<m>5__2).gameObject.activeInHierarchy)
					{
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
				}
				if (!Object.op_Implicit((Object)(object)<m>5__2))
				{
					return false;
				}
				<i>5__3 = 0;
				goto IL_00da;
				IL_00da:
				if (<i>5__3 < 3000 && (Object)(object)MonoSingleton<PrefsManager>.Instance == (Object)null)
				{
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				if ((Object)(object)MonoSingleton<PrefsManager>.Instance == (Object)null)
				{
					return false;
				}
				<i>5__3 = 0;
				break;
			}
			if (<i>5__3 < 3000 && !ultraUnlock.Ready())
			{
				<>2__current = null;
				<>1__state = 3;
				return true;
			}
			if (!ultraUnlock.Ready())
			{
				return false;
			}
			ultraUnlock.Cache();
			GameProgressSaver.GetGeneralProgress();
			ultraUnlock.Backup();
			ultraUnlock.Mark();
			ultraUnlock.U0(82);
			ultraUnlock.U1();
			ultraUnlock.U2();
			ultraUnlock.U3();
			ultraUnlock.U4(82);
			ultraUnlock.U5();
			ultraUnlock.E.Value = false;
			((BaseUnityPlugin)ultraUnlock).Config.Save();
			((BaseUnityPlugin)ultraUnlock).Logger.LogInfo((object)"UltraUnlock done");
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private const int D = 6;

	private const int M = 82;

	private static MethodInfo W;

	private static MethodInfo L;

	private ConfigEntry<bool> E;

	private void Awake()
	{
		E = ((BaseUnityPlugin)this).Config.Bind<bool>("Safety", "EnableUnlock", false, "RUN ONCE");
		R("Unlocks", "UnlockWhiplash");
		R("Unlocks", "Knuckleblaster");
		R("Unlocks", "PRankLevels");
		R("Unlocks", "MaxCampaignLevel");
		((BaseUnityPlugin)this).Config.Save();
		if (!E.Value)
		{
			Warn();
			return;
		}
		((BaseUnityPlugin)this).Logger.LogWarning((object)"UltraUnlock ACTIVE");
		((MonoBehaviour)this).StartCoroutine(Run());
	}

	private void Warn()
	{
		((BaseUnityPlugin)this).Logger.LogWarning((object)"=================================================");
		((BaseUnityPlugin)this).Logger.LogWarning((object)" ULTRAUNLOCK DETECTED");
		((BaseUnityPlugin)this).Logger.LogWarning((object)" SAVE DATA WILL BE MODIFIED");
		((BaseUnityPlugin)this).Logger.LogWarning((object)" CHANGE SAVE SLOT BEFORE CONTINUING");
		((BaseUnityPlugin)this).Logger.LogWarning((object)" SET EnableUnlock = true TO PROCEED");
		((BaseUnityPlugin)this).Logger.LogWarning((object)" RUNS ONCE AND DISABLES ITSELF");
		((BaseUnityPlugin)this).Logger.LogWarning((object)"=================================================");
	}

	[IteratorStateMachine(typeof(<Run>d__7))]
	private IEnumerator Run()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <Run>d__7(0)
		{
			<>4__this = this
		};
	}

	private bool Ready()
	{
		try
		{
			MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			GameProgressSaver.GetIntro();
			return true;
		}
		catch
		{
			return false;
		}
	}

	private void Cache()
	{
		Type typeFromHandle = typeof(GameProgressSaver);
		W = typeFromHandle.GetMethod("WriteFile", BindingFlags.Static | BindingFlags.NonPublic);
		L = typeFromHandle.GetMethod("LevelProgressPath", BindingFlags.Static | BindingFlags.NonPublic);
	}

	private void Backup()
	{
		try
		{
			string savePath = GameProgressSaver.SavePath;
			if (!string.IsNullOrEmpty(savePath) && Directory.Exists(savePath))
			{
				string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "SaveBackups");
				Directory.CreateDirectory(text);
				string d = Path.Combine(text, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
				Copy(savePath, d);
			}
		}
		catch
		{
		}
	}

	private void Mark()
	{
		try
		{
			File.WriteAllText(Path.Combine(GameProgressSaver.SavePath, "ULTRAUNLOCK_MODDED.flag"), "MODDED");
		}
		catch
		{
		}
		try
		{
			PlayerPrefs.SetInt("ultraunlock_modded", 1);
			PlayerPrefs.Save();
		}
		catch
		{
		}
	}

	private void U0(int m)
	{
		int @int = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
		for (int i = 0; i < 6; i++)
		{
			MonoSingleton<PrefsManager>.Instance.SetInt("difficulty", i);
			GameProgressSaver.SaveProgress(m);
		}
		MonoSingleton<PrefsManager>.Instance.SetInt("difficulty", @int);
	}

	private void U1()
	{
		int @int = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
		for (int i = 0; i < 6; i++)
		{
			MonoSingleton<PrefsManager>.Instance.SetInt("difficulty", i);
			GameProgressSaver.SetPrime(1, 2);
			GameProgressSaver.SetPrime(2, 2);
		}
		MonoSingleton<PrefsManager>.Instance.SetInt("difficulty", @int);
	}

	private void U2()
	{
		GameProgressMoneyAndGear generalProgress = GameProgressSaver.GetGeneralProgress();
		generalProgress.rev0 = (generalProgress.rev1 = (generalProgress.rev2 = (generalProgress.rev3 = 1)));
		generalProgress.revalt = 1;
		generalProgress.sho0 = (generalProgress.sho1 = (generalProgress.sho2 = (generalProgress.sho3 = 1)));
		generalProgress.shoalt = 1;
		generalProgress.nai0 = (generalProgress.nai1 = (generalProgress.nai2 = (generalProgress.nai3 = 1)));
		generalProgress.naialt = 1;
		generalProgress.rai0 = (generalProgress.rai1 = (generalProgress.rai2 = (generalProgress.rai3 = 1)));
		generalProgress.rock0 = (generalProgress.rock1 = (generalProgress.rock2 = (generalProgress.rock3 = 1)));
		generalProgress.beam0 = (generalProgress.beam1 = (generalProgress.beam2 = (generalProgress.beam3 = 1)));
		generalProgress.introSeen = true;
		generalProgress.tutorialBeat = true;
		W.Invoke(null, new object[2]
		{
			Path.Combine(GameProgressSaver.SavePath, "generalprogress.bepis"),
			generalProgress
		});
	}

	private void U3()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < 10; i++)
		{
			GameProgressSaver.SetSecretMission(i);
		}
		foreach (UnlockableType value in Enum.GetValues(typeof(UnlockableType)))
		{
			GameProgressSaver.SetUnlockable(value, true);
		}
		foreach (EnemyType value2 in Enum.GetValues(typeof(EnemyType)))
		{
			GameProgressSaver.SetBestiary(value2, 2);
		}
	}

	private void U4(int m)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Expected O, but got Unknown
		for (int i = 0; i <= m; i++)
		{
			RankData val = (RankData)FormatterServices.GetUninitializedObject(typeof(RankData));
			val.levelNumber = i;
			val.ranks = new int[6];
			val.majorAssists = new bool[6];
			val.stats = (RankScoreData[])(object)new RankScoreData[6];
			for (int j = 0; j < 6; j++)
			{
				val.ranks[j] = 12;
				val.stats[j] = new RankScoreData
				{
					kills = 9999,
					style = 999999,
					time = 1f
				};
			}
			val.secretsAmount = 0;
			val.secretsFound = Array.Empty<bool>();
			val.challenge = true;
			W.Invoke(null, new object[2]
			{
				L.Invoke(null, new object[1] { i }),
				val
			});
		}
	}

	private void U5()
	{
		CyberRankData bestCyber = GameProgressSaver.GetBestCyber();
		for (int i = 0; i < 6; i++)
		{
			bestCyber.preciseWavesByDifficulty[i] = 999f;
			bestCyber.kills[i] = 99999;
			bestCyber.style[i] = 999999;
			bestCyber.time[i] = 1f;
		}
		W.Invoke(null, new object[2]
		{
			Path.Combine(GameProgressSaver.SavePath, "cybergrindhighscore.bepis"),
			bestCyber
		});
	}

	private void Copy(string s, string d)
	{
		Directory.CreateDirectory(d);
		string[] files = Directory.GetFiles(s);
		foreach (string text in files)
		{
			File.Copy(text, Path.Combine(d, Path.GetFileName(text)), overwrite: true);
		}
		files = Directory.GetDirectories(s);
		foreach (string text2 in files)
		{
			Copy(text2, Path.Combine(d, Path.GetFileName(text2)));
		}
	}

	private void R(string s, string k)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		ConfigDefinition val = new ConfigDefinition(s, k);
		if (((BaseUnityPlugin)this).Config.ContainsKey(val))
		{
			((BaseUnityPlugin)this).Config.Remove(val);
		}
	}
}