Decompiled source of RevealAchievements v1.1.0

RevealAchievements.dll

Decompiled 5 days ago
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RevealAchievements;

[BepInPlugin("com.custom.revealachievements", "Reveal Achievements", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private static FieldInfo f_usedCheats = AccessTools.Field(typeof(PlayerProfile), "m_usedCheats");

	private static FieldInfo f_itemCheated = AccessTools.Field(typeof(ItemData), "m_cheated");

	private float timer;

	private void Awake()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Reveal Achievements: all items visible, achievements always enabled");
		new Harmony("com.custom.revealachievements").PatchAll();
		Enforce();
	}

	private void Update()
	{
		timer += Time.unscaledDeltaTime;
		if (!(timer < 2f))
		{
			timer = 0f;
			Enforce();
		}
	}

	private static void Enforce()
	{
		Game instance = Game.instance;
		if ((Object)(object)instance != (Object)null)
		{
			PlayerProfile playerProfile = instance.GetPlayerProfile();
			if (playerProfile != null && f_usedCheats != null)
			{
				f_usedCheats.SetValue(playerProfile, false);
			}
		}
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer != (Object)null) || !(f_itemCheated != null))
		{
			return;
		}
		Inventory inventory = ((Humanoid)localPlayer).GetInventory();
		if (inventory == null)
		{
			return;
		}
		List<ItemData> allItems = inventory.GetAllItems();
		for (int i = 0; i < allItems.Count; i++)
		{
			if (allItems[i] != null && (bool)f_itemCheated.GetValue(allItems[i]))
			{
				f_itemCheated.SetValue(allItems[i], false);
			}
		}
	}
}
[HarmonyPatch(typeof(Achievements), "Start")]
internal static class PatchAchievementsStart
{
	private static void Postfix(Achievements __instance)
	{
		foreach (AchievementList achievementList in __instance.m_achievementLists)
		{
			foreach (Achievement achievement in achievementList.m_achievements)
			{
				achievement.m_isSecret = false;
			}
		}
	}
}
[HarmonyPatch(typeof(AchievementsGui), "CreateStatRow")]
internal static class PatchCreateStatRow
{
	private static float realAmount;

	private static bool wasHidden;

	private static FieldInfo f_root = AccessTools.Field(typeof(AchievementsGui), "m_achievementDetailsListRoot");

	private static FieldInfo f_statName = AccessTools.Field(typeof(AchievementDetailUnlockCondition), "m_statName");

	private static FieldInfo f_progress = AccessTools.Field(typeof(AchievementDetailUnlockCondition), "m_progress");

	private static void Prefix(ref float currentAmount, float totalAmount)
	{
		wasHidden = currentAmount < totalAmount;
		if (wasHidden)
		{
			realAmount = currentAmount;
			currentAmount = totalAmount;
		}
	}

	private static void Postfix(AchievementsGui __instance, float totalAmount)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		if (!wasHidden)
		{
			return;
		}
		Transform val = (Transform)f_root.GetValue(__instance);
		if (val.childCount != 0)
		{
			Transform child = val.GetChild(val.childCount - 1);
			AchievementDetailUnlockCondition component = ((Component)child).GetComponent<AchievementDetailUnlockCondition>();
			if (!((Object)(object)component == (Object)null))
			{
				object value = f_statName.GetValue(component);
				object value2 = f_progress.GetValue(component);
				PropertyInfo property = value.GetType().GetProperty("color");
				PropertyInfo property2 = value.GetType().GetProperty("text");
				property.SetValue(value, Color.white, null);
				property.SetValue(value2, Color.white, null);
				property2.SetValue(value2, $"{realAmount} / {totalAmount}", null);
				wasHidden = false;
			}
		}
	}
}
[HarmonyPatch(typeof(Achievements), "CanGetAchievements")]
internal static class PatchCanGetAchievements
{
	private static void Postfix(ref bool __result)
	{
		__result = true;
	}
}
[HarmonyPatch(typeof(PlayerProfile), "get_s_bypassCheatChecks")]
internal static class PatchBypassCheatChecks
{
	private static void Postfix(ref bool __result)
	{
		__result = true;
	}
}
[HarmonyPatch(typeof(Achievements), "IsCheatedAtAll")]
internal static class PatchIsCheatedAtAll
{
	private static bool Prefix(ref bool __result)
	{
		__result = true;
		return false;
	}
}
[HarmonyPatch(typeof(Achievements), "IsWorldCheated")]
internal static class PatchIsWorldCheated
{
	private static bool Prefix(ref bool __result)
	{
		__result = false;
		return false;
	}
}
[HarmonyPatch(typeof(Inventory), "AnyCheatedItem")]
internal static class PatchAnyCheatedItem
{
	private static void Postfix(ref bool __result)
	{
		__result = false;
	}
}
[HarmonyPatch(typeof(Inventory), "CheatedDamagingItemEquipped")]
internal static class PatchCheatedDamagingItemEquipped
{
	private static void Postfix(ref bool __result)
	{
		__result = false;
	}
}