Decompiled source of EnableAchievementsFix v1.0.0

EnableAchievementsFix.dll

Decompiled a day ago
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[BepInPlugin("com.andrewluebke.dsp.enableachievementsfix", "EnableAchievementsFix", "1.0.0")]
public class EnableAchievementsFix : BaseUnityPlugin
{
	public const string GUID = "com.andrewluebke.dsp.enableachievementsfix";

	public const string NAME = "EnableAchievementsFix";

	public const string VERSION = "1.0.0";

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		try
		{
			Harmony harmony = new Harmony("com.andrewluebke.dsp.enableachievementsfix");
			Type type = AccessTools.TypeByName("GameAbnormalityData_0925") ?? FindByPrefix("GameAbnormalityData");
			Type type2 = AccessTools.TypeByName("AbnormalityLogic");
			Type type3 = AccessTools.TypeByName("AchievementLogic");
			int num = 0;
			num += PatchIf(harmony, MethodOrFirst(type, "NothingAbnormal"), "ForceTrue", "GameAbnormalityData.NothingAbnormal");
			num += PatchIf(harmony, MethodOrFirst(type, "TriggerAbnormality"), "Skip", "GameAbnormalityData.TriggerAbnormality");
			num += PatchIf(harmony, (!(type3 == null)) ? AccessTools.PropertyGetter(type3, "active") : null, "ForceTrue", "AchievementLogic.active");
			num += PatchIf(harmony, MethodOrFirst(type2, "GameTick"), "Skip", "AbnormalityLogic.GameTick");
			Log.LogInfo((object)("EnableAchievementsFix: " + num + "/4 patches applied (abnormality type: " + ((!(type == null)) ? type.Name : "NOT FOUND") + ")"));
		}
		catch (Exception ex)
		{
			Log.LogError((object)("EnableAchievementsFix failed: " + ex));
		}
	}

	private static Type FindByPrefix(string prefix)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			if (!(assembly.GetName().Name != "Assembly-CSharp"))
			{
				Type[] types;
				try
				{
					types = assembly.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					types = ex.Types;
				}
				return types.FirstOrDefault((Type t) => t != null && !t.IsNested && t.Name.StartsWith(prefix, StringComparison.Ordinal));
			}
		}
		return null;
	}

	private static MethodBase MethodOrFirst(Type type, string name)
	{
		if (type == null)
		{
			return null;
		}
		return AccessTools.Method(type, name, (Type[])null, (Type[])null) ?? AccessTools.FirstMethod(type, (Func<MethodInfo, bool>)((MethodInfo m) => m.Name == name));
	}

	private static int PatchIf(Harmony harmony, MethodBase target, string prefixName, string label)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		if (target == null)
		{
			Log.LogWarning((object)("EnableAchievementsFix: target not found: " + label + " (game update changed it?)"));
			return 0;
		}
		harmony.Patch(target, new HarmonyMethod(typeof(EnableAchievementsFix), prefixName, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return 1;
	}

	public static bool ForceTrue(ref bool __result)
	{
		__result = true;
		return false;
	}

	public static bool Skip()
	{
		return false;
	}
}