Decompiled source of Achievement Enabler v1.0.0

AchievementEnabler.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LBoL.Base.Extensions;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.SaveData;
using LBoL.Core.StatusEffects;
using LBoL.Core.Units;
using LBoL.EntityLib.Adventures;
using LBoL.EntityLib.Adventures.Shared23;
using LBoL.EntityLib.Adventures.Stage3;
using LBoL.EntityLib.Cards.Character.Marisa;
using LBoL.EntityLib.Cards.Character.Sakuya;
using LBoL.EntityLib.StatusEffects.Cirno;
using LBoL.EntityLib.StatusEffects.Sakuya;
using LBoL.Presentation;
using LBoL.Presentation.UI.Panels;
using LBoL.Presentation.Units;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("LBoL.Base")]
[assembly: IgnoresAccessChecksTo("LBoL.ConfigData")]
[assembly: IgnoresAccessChecksTo("LBoL.Core")]
[assembly: IgnoresAccessChecksTo("LBoL.EntityLib")]
[assembly: IgnoresAccessChecksTo("LBoL.Presentation")]
[assembly: IgnoresAccessChecksTo("Untitled.ConfigDataBuilder.Base")]
[assembly: AssemblyCompany("AchievementEnabler")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AchievementEnabler")]
[assembly: AssemblyTitle("AchievementEnabler")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace AchievementEnabler
{
	[BepInPlugin("neo.lbol.qol.achievementEnabler", "Achievement Enabler", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("LBoL.exe")]
	public class BepinexPlugin : BaseUnityPlugin
	{
		private static readonly Harmony harmony = PInfo.harmony;

		internal static ManualLogSource log;

		internal static ConfigEntry<bool> isDebugConfig;

		private void Awake()
		{
			log = ((BaseUnityPlugin)this).Logger;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			isDebugConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "CheckAchievementCount", false, (ConfigDescription)null);
			harmony.PatchAll();
			if (isDebugConfig.Value)
			{
				log.LogDebug((object)$"UnlockAchievement calls patched: {DisableJadeboxCheck_Patch.totalACount}, v1.4 + 12 for char clears, + 11 for boss kills, + 1 for clear with jadebox, + 1 for Rumia, total achievements: {Enum.GetNames(typeof(AchievementKey)).Length} ");
			}
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			DisableJadeboxCheck_Patch.totalACount = 0;
		}
	}
	[HarmonyPatch]
	internal class DisableJadeboxCheck_Patch
	{
		public static int totalACount;

		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(UseCardAction).GetNestedTypes(AccessTools.allDeclared).Single((Type t) => t.Name.Contains("DisplayClass16_0")), "<GetPhases>b__4", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(BattleController), "GainMana", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(BattleController), "RecordCardUsage", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Firepower), "CheckAchievement", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Unit), "GainBlockShield", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Unit), "TryAddStatusEffect", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(RinnosukeTrade), "SellExhibit", (Type[])null, (Type[])null);
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(NarumiOfferCard), "OfferDeckCard", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(BackgroundDancers), "ForExhibit", (Type[])null, (Type[])null));
			yield return AccessTools.Method(typeof(PotionAchievementCounter), "Increase", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(KnifeAchievementCounter), "Increase", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Cold), "Stack", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(TimeAuraSe), "CheckAchievement", (Type[])null, (Type[])null);
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(GameMaster), "BattleFlow", (Type[])null, (Type[])null));
			yield return AccessTools.Method(typeof(GameMaster), "SaveProfileWithEndingGameRun", (Type[])null, (Type[])null);
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(GameRunVisualPanel), "ViewGainMoney", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(PlayBoard), "ViewStartPlayerTurn", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(GameDirector), "InternalDieViewer", (Type[])null, (Type[])null));
			yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(GameDirector), "StatisticalTotalDamageViewer", (Type[])null, (Type[])null));
		}

		private static IEnumerable<CodeInstruction> Transpiler(MethodBase original, IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			CodeMatcher matcher = new CodeMatcher(instructions, generator);
			matcher = matcher.MatchForward(true, (CodeMatch[])(object)new CodeMatch[2]
			{
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(GameRunController), "IsAutoSeed"))),
				CodeMatch.op_Implicit(OpCodes.Brfalse)
			});
			Action<CodeMatch[]> action = delegate(CodeMatch[] lookFor)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				matcher = matcher.MatchForward(true, lookFor).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null)
				}).Set(OpCodes.Pop, (object)null);
			};
			CodeMatch[] obj = (CodeMatch[])(object)new CodeMatch[2]
			{
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(GameRunController), "JadeBoxes"))),
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(CollectionsExtensions), "Empty", (Type[])null, (Type[])null).MakeGenericMethod(typeof(JadeBox))))
			};
			CodeMatch[] obj2 = (CodeMatch[])(object)new CodeMatch[2]
			{
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(GameRunRecordSaveData), "JadeBoxes"))),
				CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(CollectionsExtensions), "Empty", (Type[])null, (Type[])null).MakeGenericMethod(typeof(string))))
			};
			try
			{
				if (original == AccessTools.Method(typeof(GameMaster), "SaveProfileWithEndingGameRun", (Type[])null, (Type[])null))
				{
					action(obj2);
				}
				else
				{
					action(obj);
				}
			}
			catch (Exception arg)
			{
				BepinexPlugin.log.LogWarning((object)$"While patching {GeneralExtensions.FullDescription(original)}: {arg}");
			}
			int num = 0;
			bool flag = true;
			if (BepinexPlugin.isDebugConfig.Value)
			{
				while (flag)
				{
					try
					{
						matcher = matcher.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Is(ci, OpCodes.Callvirt, (MemberInfo)AccessTools.Method(typeof(IGameRunAchievementHandler), "UnlockAchievement", (Type[])null, (Type[])null)) || CodeInstructionExtensions.Is(ci, OpCodes.Call, (MemberInfo)AccessTools.Method(typeof(GameMaster), "UnlockAchievement", new Type[1] { typeof(AchievementKey) }, (Type[])null)) || CodeInstructionExtensions.Is(ci, OpCodes.Call, (MemberInfo)AccessTools.Method(typeof(GameMaster), "UnlockAchievement", new Type[1] { typeof(string) }, (Type[])null)))).Advance(1).ThrowIfInvalid("deez");
						num++;
					}
					catch (Exception)
					{
						flag = false;
					}
				}
				BepinexPlugin.log.LogDebug((object)$"{GeneralExtensions.FullDescription(original)} achievement count: {num}");
				totalACount += num;
			}
			return matcher.InstructionEnumeration();
		}
	}
	[HarmonyPatch(typeof(StartGamePanel), "SetNoClearHint")]
	internal class StartGamePanel_Hint_Patch
	{
		private static void Postfix(StartGamePanel __instance)
		{
			((Component)__instance.noClearHint).gameObject.SetActive(__instance._setSeed);
			((TMP_Text)__instance.noClearHint).text = ((TMP_Text)__instance.noClearHint).text.Replace(" or Jade Box", "");
		}
	}
	public static class PInfo
	{
		public const string GUID = "neo.lbol.qol.achievementEnabler";

		public const string Name = "Achievement Enabler";

		public const string version = "1.0.0";

		public static readonly Harmony harmony = new Harmony("neo.lbol.qol.achievementEnabler");
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}