Decompiled source of Weekly Selector v1.2.0

BepInEx/plugins/com.binbin.WeeklySelectorMod.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Obeliskial_Essentials;
using WeeklySelectorMod;

[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: AssemblyCompany("com.binbin.WeeklySelectorMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+215c87dcdd74767ce4cc90643de27989a720c645")]
[assembly: AssemblyProduct("WeeklySelectorMod")]
[assembly: AssemblyTitle("com.binbin.WeeklySelectorMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[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;
		}
	}
}
public static class EssentialsCompatibility
{
	private static bool? _enabled;

	public static bool Enabled
	{
		get
		{
			bool valueOrDefault = _enabled == true;
			if (!_enabled.HasValue)
			{
				valueOrDefault = Chainloader.PluginInfos.ContainsKey("com.stiffmeds.obeliskialessentials");
				_enabled = valueOrDefault;
			}
			return _enabled.Value;
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static void EssentialsRegister()
	{
		Essentials.RegisterMod(Plugin.PluginName, "binbin", "Weekly Selector", Plugin.PluginVersion, Plugin.ModDate, "https://github.com/binbinmods/WeeklySelector", (string[])null, "", 100, (string[])null, "", true);
		Plugin.LogInfo(Plugin.PluginGUID + " " + Plugin.PluginVersion + " has loaded with Essentials!");
	}
}
namespace WeeklySelectorMod
{
	[HarmonyPatch]
	public class AntiCheat
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetObeliskScore")]
		public static bool SetObeliskScorePrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetScore")]
		public static bool SetScorePrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetSingularityScore")]
		public static bool SetSingularityScorePrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetObeliskScoreLeaderboard")]
		public static bool SetObeliskScoreLeaderboardPrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetScoreLeaderboard")]
		public static bool SetScoreLeaderboardPrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetSingularityScoreLeaderboard")]
		public static bool SetSingularityScoreLeaderboardPrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetWeeklyScore")]
		public static bool SetWeeklyScorePrefix(ref SteamManager __instance, int score, int week, string nick, string nickgroup, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetWeeklyScoreLeaderboard")]
		public static bool SetWeeklyScoreLeaderboardPrefix(ref SteamManager __instance, int score, int week, string nick, string nickgroup, bool singleplayer = true)
		{
			return false;
		}
	}
	[BepInPlugin("com.binbin.WeeklySelectorMod", "WeeklySelectorMod", "1.2.0")]
	[BepInProcess("AcrossTheObelisk.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public static bool EssentialsInstalled = false;

		public static int ChosenWeeklyNumber = 0;

		internal static int ModDate = int.Parse(DateTime.Today.ToString("yyyyMMdd"));

		private readonly Harmony harmony = new Harmony("com.binbin.WeeklySelectorMod");

		internal static ManualLogSource Log;

		public static string PluginName;

		public static string PluginVersion;

		public static string PluginGUID;

		public static string debugBase = "com.binbin.WeeklySelectorMod ";

		public static ConfigEntry<bool> EnableMod { get; set; }

		public static ConfigEntry<bool> EnableDebugging { get; set; }

		public static ConfigEntry<bool> EnableWeeklyInfo { get; set; }

		public static ConfigEntry<string> ChooseWeekly { get; set; }

		public static ConfigEntry<int> Cycle { get; set; }

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0049: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0076: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00a3: Expected O, but got Unknown
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Expected O, but got Unknown
			//IL_01b0: Expected O, but got Unknown
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_01dd: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"com.binbin.WeeklySelectorMod 1.2.0 has loaded!");
			string text = "WeeklySelectorMod";
			EnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "EnableMod"), true, new ConfigDescription("Enables the mod. If false, the mod will not work then next time you load the game.", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableDebugging = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "EnableDebugging"), false, new ConfigDescription("Enables the debugging", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableWeeklyInfo = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "EnableWeeklyInfo"), true, new ConfigDescription("Enables the extra info about weeklies in the logoutput.", (AcceptableValueBase)null, Array.Empty<object>()));
			AcceptableValueList<string> val = new AcceptableValueList<string>(new string[24]
			{
				"Ylmer1", "Ignidoh1", "Yogger1", "Faeborg1", "Rise1", "Nihr1", "Minotaur1", "Hydra1", "Tulah1", "RustKing1",
				"Ylmer2", "Ignidoh2", "Yogger2", "Faeborg2", "Rise2", "Nihr2", "Minotaur2", "Hydra2", "Tulah2", "RustKing2",
				"Halloween", "Christmas", "Lunar Festival", "None"
			});
			ChooseWeekly = ((BaseUnityPlugin)this).Config.Bind<string>(new ConfigDefinition(text, "ChooseWeekly"), "None", new ConfigDescription("Choose the weekly you would like. Does not require a restart.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			Cycle = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition(text, "Cycle"), 1, new ConfigDescription("Set the cycle for the weeklies. Default is 1, which is the current cycle. Increase this to look further into the future.", (AcceptableValueBase)null, Array.Empty<object>()));
			PluginName = "WeeklySelectorMod";
			PluginVersion = "1.2.0";
			PluginGUID = "com.binbin.WeeklySelectorMod";
			if (EnableMod.Value)
			{
				harmony.PatchAll();
			}
		}

		internal static void LogDebug(string msg, [CallerMemberName] string caller = "")
		{
			if (EnableDebugging.Value)
			{
				Log.LogDebug((object)(debugBase + "- " + caller + " - " + msg));
			}
		}

		internal static void LogInfo(string msg)
		{
			Log.LogInfo((object)(debugBase + msg));
		}

		internal static void LogError(string msg, [CallerMemberName] string caller = "")
		{
			Log.LogError((object)(debugBase + "- " + caller + " - " + msg));
		}

		public static IEnumerator RunAfter(IEnumerator original, Action action)
		{
			while (original.MoveNext())
			{
				yield return original.Current;
			}
			action();
		}
	}
	public class WeeklySelectorModFunctions
	{
		public static int GetWeeklyNumber(string weeklyName, int currentWeekly)
		{
			if (Plugin.ChooseWeekly.Value == "None")
			{
				return 0;
			}
			Dictionary<string, int> dictionary = new Dictionary<string, int>
			{
				{ "Ylmer1", 1 },
				{ "Ignidoh1", 2 },
				{ "Yogger1", 3 },
				{ "Faeborg1", 4 },
				{ "Rise1", 5 },
				{ "Nihr1", 6 },
				{ "Minotaur1", 7 },
				{ "Hydra1", 8 },
				{ "Tulah1", 9 },
				{ "RustKing1", 10 },
				{ "Ylmer2", 11 },
				{ "Ignidoh2", 12 },
				{ "Yogger2", 13 },
				{ "Faeborg2", 14 },
				{ "Rise2", 15 },
				{ "Nihr2", 16 },
				{ "Minotaur2", 17 },
				{ "Hydra2", 18 },
				{ "Tulah2", 19 },
				{ "RustKing2", 20 },
				{ "Halloween", 21 },
				{ "Christmas", 22 },
				{ "Lunar Festival", 23 },
				{ "None", 0 }
			};
			return GetAccurateWeekly(dictionary[weeklyName], currentWeekly);
		}

		public static int GetAccurateWeekly(int targetWeek, int currentWeek)
		{
			int num = Globals.Instance.WeeklyDataSource.Count;
			foreach (KeyValuePair<string, ChallengeData> item in Globals.Instance.WeeklyDataSource)
			{
				if (item.Value.IsDateFixed())
				{
					num--;
				}
			}
			if (num < 1)
			{
				num = 20;
			}
			int num2 = currentWeek % num;
			if (num2 == 0)
			{
				num2 = num;
			}
			return (targetWeek + currentWeek - num2) % num2 + targetWeek * Plugin.Cycle.Value;
		}
	}
	[HarmonyPatch]
	public class WeeklySelectorModPatches
	{
		public static bool devMode;

		public static bool bSelectingPerk;

		public static bool IsHost()
		{
			return GameManager.Instance.IsMultiplayer() && NetworkManager.Instance.IsMaster();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Globals), "GetWeeklyData")]
		public static void GetWeeklyDataPrefix(ref int _week)
		{
			if (WeeklySelectorModFunctions.GetWeeklyNumber(Plugin.ChooseWeekly.Value, _week) != 0 && !(Plugin.ChooseWeekly.Value == "None"))
			{
				Plugin.LogDebug($"GetWeeklyDataPrefix setting weekly to {WeeklySelectorModFunctions.GetWeeklyNumber(Plugin.ChooseWeekly.Value, _week)} from {_week}", "GetWeeklyDataPrefix");
				_week = WeeklySelectorModFunctions.GetWeeklyNumber(Plugin.ChooseWeekly.Value, _week);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(AtOManager), "GetWeeklyName")]
		public static void GetWeeklyNamePrefix(ref int _week)
		{
			if (WeeklySelectorModFunctions.GetWeeklyNumber(Plugin.ChooseWeekly.Value, _week) != 0 && !(Plugin.ChooseWeekly.Value == "None"))
			{
				Plugin.LogDebug($"GetWeeklyNamePrefix setting weekly to {WeeklySelectorModFunctions.GetWeeklyNumber(Plugin.ChooseWeekly.Value, _week)} from  {_week}", "GetWeeklyNamePrefix");
				_week = WeeklySelectorModFunctions.GetWeeklyNumber(Plugin.ChooseWeekly.Value, _week);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(AtOManager), "GetWeekly")]
		public static bool GetWeeklyPrefix(ref int __result)
		{
			if (WeeklySelectorModFunctions.GetWeeklyNumber(Plugin.ChooseWeekly.Value, __result) == 0 || Plugin.ChooseWeekly.Value == "None")
			{
				return true;
			}
			Plugin.LogDebug($"GetWeeklyPrefix setting weekly to {WeeklySelectorModFunctions.GetWeeklyNumber(Plugin.ChooseWeekly.Value, __result)} from  {__result}", "GetWeeklyPrefix");
			__result = WeeklySelectorModFunctions.GetWeeklyNumber(Plugin.ChooseWeekly.Value, __result);
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Globals), "CreateGameContentRoutine")]
		public static void CreateGameContentRoutinePostfix(ref IEnumerator __result)
		{
			if (Plugin.EnableWeeklyInfo.Value)
			{
				Plugin.LogDebug("CreateGameContentRoutinePostfix called", "CreateGameContentRoutinePostfix");
				__result = Plugin.RunAfter(__result, CreateGameContentPostfix);
			}
		}

		public static void CreateGameContentPostfix()
		{
			Plugin.LogDebug("CreateGameContentPostfix called", "CreateGameContentPostfix");
			foreach (KeyValuePair<string, ChallengeData> item in Globals.Instance.WeeklyDataSource)
			{
				string key = item.Key;
				if (item.Value.IsDateFixed())
				{
					Plugin.LogDebug($"WeeklyData key: {item.Key}, value: {item.Value} has a fixed date", "CreateGameContentPostfix");
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.binbin.WeeklySelectorMod";

		public const string PLUGIN_NAME = "WeeklySelectorMod";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}