Decompiled source of UltraAchievements Revamped v1.0.0

plugins/UltraAchievements-Revamped/UltraAchievements_Revamped.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using GameConsole;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UltraAchievements_Lib;
using UltraAchievements_Revamped.Achievements;
using UnityEngine;
using UnityEngine.AddressableAssets;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("UltraAchievements_Revamped")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b51b8f330dc686a9d942e9e0c329b37904f19d5f")]
[assembly: AssemblyProduct("UltraAchievements_Revamped")]
[assembly: AssemblyTitle("UltraAchievements_Revamped")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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;
		}
	}
}
namespace UltraAchievements_Revamped
{
	[AttributeUsage(AttributeTargets.Class)]
	[HarmonyPatch]
	public class RegisterCommandAttribute : Attribute
	{
		[HarmonyPatch(typeof(Console), "Awake")]
		[HarmonyPostfix]
		private static void RegisterAll(Console __instance)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			foreach (TypeInfo definedType in Assembly.GetExecutingAssembly().DefinedTypes)
			{
				if (definedType.GetCustomAttribute<RegisterCommandAttribute>() != null)
				{
					__instance.RegisterCommand((ICommand)Activator.CreateInstance(definedType));
				}
			}
		}
	}
	[BepInPlugin("protract.ultrakill.ultra_achievements_revamped", "UltraAchievements", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private static AssetBundle _modBundle;

		internal static Sprite QuestionMark;

		private static GameObject _terminalTemplate;

		internal static AchievementInfo CurrentInfo;

		internal static string ModFolder => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("Protract.UltraAchievementsRevamped");
			val.PatchAll();
		}

		private void Start()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			_modBundle = AssetBundle.LoadFromFile(Path.Combine(ModFolder, "assets"));
			_terminalTemplate = _modBundle.LoadAsset<GameObject>("Achievements Terminal.prefab");
			AchievementInfo[] array = _modBundle.LoadAllAssets<AchievementInfo>();
			_modBundle.LoadAllAssets();
			AchievementManager.RegisterAchievementInfos((IEnumerable<AchievementInfo>)array);
			AchievementManager.RegisterAllAchievements(typeof(Plugin).Assembly);
			QuestionMark = Addressables.LoadAssetAsync<Sprite>((object)"Assets/Textures/UI/questionMark.png").WaitForCompletion();
			SceneManager.activeSceneChanged += OnSceneChange;
		}

		private void Update()
		{
			OneinMillion.Check();
			Florp.FlorpCheck();
		}

		private void OnSceneChange(Scene current, Scene next)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			AllPRanks.CheckRanks();
			FirstRoomPrefab val = Object.FindObjectOfType<FirstRoomPrefab>();
			if (!((Object)(object)val == (Object)null))
			{
				GameObject gameObject = ((Component)((Component)val).transform.GetChild(0)).gameObject;
				if (!((Object)(object)gameObject == (Object)null))
				{
					GameObject val2 = Object.Instantiate<GameObject>(_terminalTemplate, gameObject.transform);
					val2.transform.localPosition = new Vector3(10f, 2f, 32f);
					val2.transform.rotation = new Quaternion(0f, 0f, 0f, 0f);
				}
			}
		}
	}
}
namespace UltraAchievements_Revamped.UI
{
	public class AchievementButton : MonoBehaviour
	{
		public AchievementInfo info;
	}
	[HarmonyPatch(typeof(ShopButton), "OnPointerClick")]
	public static class ShopButtonPatch
	{
		public static void Prefix(ShopButton __instance)
		{
			AchievementButton achievementButton = default(AchievementButton);
			if (((Component)__instance).TryGetComponent<AchievementButton>(ref achievementButton))
			{
				Plugin.CurrentInfo = achievementButton.info;
			}
		}
	}
	public class AchievementDisplay : MonoBehaviour
	{
		public Image icon;

		public GameObject description;

		public GameObject title;

		private void OnEnable()
		{
			icon.sprite = ((!Plugin.CurrentInfo.isCompleted) ? Plugin.QuestionMark : Plugin.CurrentInfo.icon);
			description.GetComponent<Text>().text = Plugin.CurrentInfo.description;
			title.GetComponent<Text>().text = ((Object)Plugin.CurrentInfo).name;
		}
	}
	public class AchievementStatManager : MonoBehaviour
	{
		public Text completedAchievements;

		public Text totalAchievements;

		public Text miniGameScore;

		private void Start()
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			foreach (AchievementInfo value in AchievementManager.IdToAchInfo.Values)
			{
				if (value.isCompleted)
				{
					num2++;
				}
				num++;
			}
			totalAchievements.text = $"<color=orange>{num}</color> - TOTAL ACHIEVEMENTS";
			completedAchievements.text = $"<color=orange>{num2}</color> - COMPLETED ACHIEVEMENTS";
		}
	}
	public class AchievementUIGenerator : MonoBehaviour
	{
		public GameObject template;

		private void Start()
		{
			foreach (AchievementInfo value in AchievementManager.IdToAchInfo.Values)
			{
				int num = 0;
				int num2 = 0;
				GameObject val = Object.Instantiate<GameObject>(template, ((Component)this).transform);
				ShopButton componentInChildren = val.GetComponentInChildren<ShopButton>();
				if (!value.isHidden)
				{
					val.SetActive(true);
				}
				((Component)val.transform.GetChild(1)).GetComponent<Image>().sprite = value.icon;
				((Component)componentInChildren).gameObject.AddComponent<AchievementButton>().info = value;
				if (!value.isCompleted)
				{
					((Component)val.transform.GetChild(1)).GetComponent<Image>().sprite = Plugin.QuestionMark;
				}
				else
				{
					val.SetActive(true);
				}
			}
		}
	}
}
namespace UltraAchievements_Revamped.Achievements
{
	[RegisterAchievement("ultraAchievements.allprank")]
	public class AllPRanks
	{
		private static List<int> _levelInts = new List<int>(31)
		{
			1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
			11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
			21, 22, 23, 24, 25, 26, 27, 28, 29, 666,
			667
		};

		public static void CheckRanks()
		{
			foreach (int levelInt in _levelInts)
			{
				RankData rank = GameProgressSaver.GetRank(levelInt, false);
				if (!rank.ranks.Contains(12))
				{
					return;
				}
			}
			AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(AllPRanks)));
		}
	}
	[HarmonyPatch(typeof(StyleHUD), "AddPoints")]
	[RegisterAchievement("ultraAchievements.catapulted")]
	public class Catapulted
	{
		public static void Postfix(string pointID)
		{
			if (pointID == "ultrakill.catapulted")
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(Catapulted)));
			}
		}
	}
	[RegisterAchievement("ultraAchievements.cerbkill")]
	[HarmonyPatch]
	public class CerbDoubleKill : MonoBehaviour
	{
		private static int _kills;

		private static bool _timerActive;

		private static float _timer;

		[HarmonyPatch(typeof(EnemyIdentifier), "Death", new Type[] { typeof(bool) })]
		public static void Prefix(EnemyIdentifier __instance)
		{
			StatueBoss val = default(StatueBoss);
			if (((Component)__instance).gameObject.TryGetComponent<StatueBoss>(ref val))
			{
				if (!__instance.dead)
				{
					_kills++;
				}
				if (_kills >= 2 && _timer < 3f)
				{
					AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(CerbDoubleKill)));
				}
				else
				{
					SetTimerActive();
				}
			}
		}

		[HarmonyPatch(typeof(NewMovement), "Start")]
		[HarmonyPostfix]
		public static void AddTimer()
		{
			((Component)MonoSingleton<NewMovement>.Instance).gameObject.AddComponent<CerbDoubleKill>();
		}

		private static void SetTimerActive()
		{
			_timerActive = true;
			_timer = 0f;
		}

		private void Update()
		{
			if (_timerActive)
			{
				_timer += Time.deltaTime;
			}
			if (_timer > 3f)
			{
				_timerActive = false;
				_timer = 0f;
				_kills = 0;
			}
		}
	}
	[HarmonyPatch(typeof(StyleHUD), "AddPoints")]
	[RegisterAchievement("ultraAchievements.chargeback")]
	public class ChargeBack
	{
		public static void Postfix(string pointID)
		{
			if (pointID == "ultrakill.chargeback")
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(ChargeBack)));
			}
		}
	}
	[HarmonyPatch(typeof(StyleHUD), "AddPoints")]
	[RegisterAchievement("ultraAchievements.compressed")]
	public class Compressed
	{
		public static void Postfix(string pointID)
		{
			if (pointID == "ultrakill.compressed")
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(Compressed)));
			}
		}
	}
	[RegisterAchievement("ultraAchievements.death")]
	[HarmonyPatch(typeof(NewMovement), "Respawn")]
	public class DeathSimulator
	{
		public static int Deaths;

		[HarmonyPostfix]
		public static void DeathPatch()
		{
			Deaths++;
			if (Deaths >= 100)
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(DeathSimulator)));
			}
		}
	}
	[HarmonyPatch(typeof(SaveSlotMenu), "ConfirmWipe")]
	[RegisterAchievement("ultraAchievements.deletesave")]
	public class DeleteSave
	{
		public static void Prefix()
		{
			AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(DeleteSave)));
		}
	}
	[RegisterAchievement("ultraAchievements.florp")]
	public class Florp
	{
		public static void FlorpCheck()
		{
			if ((Object)(object)MonoSingleton<NewMovement>.Instance != (Object)null)
			{
				ItemIdentifier heldObject = ((Component)MonoSingleton<NewMovement>.Instance).GetComponentInChildren<FistControl>().heldObject;
				if ((Object)(object)heldObject != (Object)null && ((Object)heldObject).name == "Florp")
				{
					AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(Florp)));
				}
			}
		}
	}
	[HarmonyPatch(typeof(Breakable), "Break")]
	[RegisterAchievement("ultraAchievements.killfish")]
	public class KillFish
	{
		public static void Prefix(Breakable __instance)
		{
			FishGhost val = default(FishGhost);
			if (((Component)__instance).gameObject.TryGetComponent<FishGhost>(ref val))
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(KillFish)));
			}
		}
	}
	[RegisterAchievement("ultraAchievements.mindflayerkill")]
	[HarmonyPatch]
	public class MindflayerQuickKill
	{
		[HarmonyPatch(typeof(Mindflayer), "Death")]
		[HarmonyPrefix]
		public static void Prefix(Mindflayer __instance)
		{
			if (((Component)__instance).gameObject.GetComponent<MindflayerTimer>().timeSinceSpawn < 3.5f)
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(MindflayerQuickKill)));
			}
		}

		[HarmonyPatch(typeof(Mindflayer), "Start")]
		[HarmonyPostfix]
		public static void Postfix(Mindflayer __instance)
		{
			((Component)__instance).gameObject.AddComponent<MindflayerTimer>();
		}
	}
	public class MindflayerTimer : MonoBehaviour
	{
		public float timeSinceSpawn = 0f;

		private void Update()
		{
			timeSinceSpawn += Time.deltaTime;
		}
	}
	[RegisterAchievement("ultraAchievements.minotaursky")]
	[HarmonyPatch(typeof(Minotaur), "Start")]
	public class MinotaurSky
	{
		private static List<int> _levels = new List<int>(1) { 13 };

		[HarmonyPrefix]
		public static void LevelCheck()
		{
			if (_levels.Contains(SceneHelper.CurrentLevelNumber))
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(MinotaurSky)));
			}
		}
	}
	[RegisterAchievement("ultraAchievements.oneinmillion")]
	public class OneinMillion
	{
		public static void Check()
		{
			int num = Random.Range(0, 1000000);
			if (num == 1)
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(OneinMillion)));
			}
		}
	}
	[HarmonyPatch(typeof(HudMessage), "PlayMessage")]
	[RegisterAchievement("ultraAchievements.pipeclip")]
	public class PipeClip
	{
		public static void Postfix(HudMessage __instance)
		{
			if (__instance.message.Contains("PIPE CLIP"))
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(PipeClip)));
			}
		}
	}
	[RegisterAchievement("ultraAchievements.sandbox")]
	[HarmonyPatch(typeof(NewMovement), "Start")]
	public class SandboxAddict : MonoBehaviour
	{
		private static float _timeSpent = -2f;

		private static AchievementInfo Info => AchievementManager.GetAchievementInfo(typeof(SandboxAddict));

		private void Update()
		{
			if (_timeSpent <= -1f)
			{
				_timeSpent = Info.progress;
			}
			if (SceneHelper.CurrentScene == "uk_construct")
			{
				_timeSpent += Time.deltaTime;
				Info.progress = (int)_timeSpent;
			}
			if (_timeSpent > (float)Info.maxProgress)
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(SandboxAddict)));
			}
		}

		[HarmonyPostfix]
		private static void StartPatch()
		{
			((Component)MonoSingleton<NewMovement>.Instance).gameObject.AddComponent<SandboxAddict>();
		}
	}
	[HarmonyPatch(typeof(NewMovement), "Update")]
	[RegisterAchievement("ultraAchievements.speed125")]
	public class Speeding
	{
		private static Rigidbody _movement;

		public static void Postfix()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_movement == (Object)null)
			{
				_movement = ((Component)MonoSingleton<NewMovement>.Instance).GetComponent<Rigidbody>();
			}
			if (Math.Abs(_movement.velocity.x) > 125f || Math.Abs(_movement.velocity.z) > 125f)
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(Speeding)));
			}
		}
	}
	[HarmonyPatch(typeof(NewMovement), "Start")]
	[RegisterAchievement("ultraAchievements.startgame")]
	public class StartGame
	{
		[HarmonyPostfix]
		private static void StartPatch()
		{
			AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(StartGame)));
		}
	}
	[RegisterAchievement("ultraAchievements.suicide")]
	[HarmonyPatch(typeof(DeathZone), "GotHit")]
	public class Suicide
	{
		[HarmonyPrefix]
		private static void SuicideCheck(Collider other)
		{
			if (((Component)other).gameObject.CompareTag("Player") && MonoSingleton<NewMovement>.Instance.hp == 1)
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(Suicide)));
			}
		}
	}
	[RegisterAchievement("ultraAchievements.ultracrypt")]
	[RegisterCommand]
	public class UltracryptReference : ICommand
	{
		private readonly string _lines = File.ReadAllText(Path.Combine(Plugin.ModFolder, "CryptASCII.txt"));

		public string Name => "Ultracrypt Reference";

		public string Description => "Activates Ultracrypt ARG (WIP)";

		public string Command => "uar_ultracrypt";

		public void Execute(Console con, string[] args)
		{
			Debug.Log((object)_lines);
			AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(UltracryptReference)));
		}
	}
	[HarmonyPatch(typeof(V2), "Die")]
	[RegisterAchievement("ultraAchievements.v2kill")]
	public class V2IntroKill
	{
		public static void Prefix(V2 __instance)
		{
			if (__instance.inIntro)
			{
				AchievementManager.MarkAchievementComplete(AchievementManager.GetAchievementInfo(typeof(V2IntroKill)));
			}
		}
	}
}