Decompiled source of ModdedWithAchievements v1.0.0

ModdedWithAchievements.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[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: AssemblyCompany("ModdedWithAchievements")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d62f9afcc841247c9ad067751d8ea94fad9ecc44")]
[assembly: AssemblyProduct("ModdedWithAchievements")]
[assembly: AssemblyTitle("ModdedWithAchievements")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ModdedWithAchievements
{
	internal static class CheatCheckBypass
	{
		public static void Apply()
		{
			if (!PlayerProfile.s_bypassCheatChecks)
			{
				PlayerProfile.s_bypassCheatChecks = true;
				Plugin.Log.LogInfo((object)"Contaminacao por itens de trapaca desligada. Conquistas reabilitadas.");
			}
		}
	}
	[BepInPlugin("moddedwithachievements", "ModdedWithAchievements", "1.0.0")]
	[BepInProcess("valheim.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "moddedwithachievements";

		public const string PluginName = "ModdedWithAchievements";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> HideCheatTag;

		internal static ConfigEntry<bool> DisableCheatContamination;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			HideCheatTag = ((BaseUnityPlugin)this).Config.Bind<bool>("Tooltip", "HideCheatTag", true, "Remove a marcacao de item trapaceado do tooltip. Afeta apenas o texto exibido.");
			DisableCheatContamination = ((BaseUnityPlugin)this).Config.Bind<bool>("CheatChecks", "DisableCheatContamination", true, "Impede que itens de trapaca marquem outros itens, drops e objetos. Reabilita as conquistas Steam com o jogo modificado, porque o jogo usa o mesmo interruptor para as duas coisas.");
			if (DisableCheatContamination.Value)
			{
				CheatCheckBypass.Apply();
			}
			_harmony = new Harmony("moddedwithachievements");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"ModdedWithAchievements 1.0.0 carregado.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			_harmony = null;
		}
	}
}
namespace ModdedWithAchievements.Patches
{
	[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[]
	{
		typeof(ItemData),
		typeof(int),
		typeof(bool),
		typeof(float),
		typeof(int),
		typeof(bool)
	})]
	internal static class CheatTagTooltipPatch
	{
		private const string CheatToken = "$achievements_cheated_item_inventory";

		private const string MarkupPrefix = "\n<color=#808080><i>";

		private const string MarkupSuffix = "</i></color>";

		private static bool _warnedAboutFallback;

		private static void Postfix(ItemData item, ref string __result)
		{
			if (!Plugin.HideCheatTag.Value || item == null || !item.m_cheated || string.IsNullOrEmpty(__result))
			{
				return;
			}
			Localization instance = Localization.instance;
			string text = ((instance != null) ? instance.Localize("$achievements_cheated_item_inventory") : null);
			if (string.IsNullOrEmpty(text))
			{
				return;
			}
			string text2 = "\n<color=#808080><i>" + text + "</i></color>";
			int num = __result.IndexOf(text2, StringComparison.Ordinal);
			if (num >= 0)
			{
				__result = __result.Remove(num, text2.Length);
				return;
			}
			num = __result.IndexOf(text, StringComparison.Ordinal);
			if (num >= 0)
			{
				__result = __result.Remove(num, text.Length);
				if (!_warnedAboutFallback)
				{
					_warnedAboutFallback = true;
					Plugin.Log.LogWarning((object)"Markup da tag de trapaca mudou no jogo. Removido apenas o texto; pode sobrar uma linha vazia no tooltip. Vale revisar o patch.");
				}
			}
		}
	}
}