Decompiled source of MySix ModsNotCheating v1.0.0

MySix.ModsNotCheating.dll

Decompiled 2 days 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 BepInEx;
using HarmonyLib;
using MySix.Core;

[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: AssemblyVersion("0.0.0.0")]
namespace MySix
{
	internal static class ModVersion
	{
		public const string Value = "1.0.0";
	}
}
namespace MySix.ModsNotCheating
{
	[HarmonyPatch(typeof(Achievements), "IsCheatedAtAll")]
	internal static class ModdedCheck
	{
		internal static Setting<bool> Enabled;

		private static readonly FieldInfo IsModded = AccessTools.Field(typeof(Game), "isModded");

		public static bool ModdedCountsAsCheating()
		{
			if (Enabled == null || !Enabled.Value)
			{
				return Game.isModded;
			}
			return false;
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			List<int> list2 = (from x in list.Select((CodeInstruction c, int i) => new { c, i })
				where x.c.opcode == OpCodes.Ldsfld && object.Equals(x.c.operand, IsModded)
				select x.i).ToList();
			if (list2.Count != 1)
			{
				CorePlugin.Log.LogError((object)("MySix Mods Not Cheating: expected one read of " + $"Game.isModded in Achievements.IsCheatedAtAll, found {list2.Count}. Not patching: " + "mods will count as cheating as in the unmodded game."));
				return list;
			}
			CodeInstruction val = list[list2[0]];
			list[list2[0]] = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ModdedCheck), "ModdedCountsAsCheating", (Type[])null, (Type[])null))
			{
				labels = val.labels,
				blocks = val.blocks
			};
			return list;
		}
	}
	[BepInPlugin("com.mysix.modsnotcheating", "MySix Mods Not Cheating", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ModsNotCheatingPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.mysix.modsnotcheating";

		public const string PluginName = "MySix Mods Not Cheating";

		public const string PluginVersion = "1.0.0";

		private const int RequiredCoreApi = 1;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			if (CorePlugin.RequireApi("MySix Mods Not Cheating", 1))
			{
				ModdedCheck.Enabled = Settings.Register<bool>("MySix Mods Not Cheating", ((BaseUnityPlugin)this).Config.Bind<bool>("ModsNotCheating", "Enabled", true, "Having mods installed does not stop achievements. Using dev commands, carrying spawned items, or playing a world with cheat modifiers still does, exactly as in the unmodded game."), (Scope)1, (string)null);
				_harmony = new Harmony("com.mysix.modsnotcheating");
				_harmony.PatchAll(typeof(ModsNotCheatingPlugin).Assembly);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"MySix Mods Not Cheating 1.0.0 loaded");
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}