Decompiled source of RandomRouteOnly v1.1.1

Index154.RandomRouteOnly.dll

Decompiled 2 weeks 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.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[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("Index154.RandomRouteOnly")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+be17a210467ab24765beaf6414f8dfb4f41071c3")]
[assembly: AssemblyProduct("RandomRouteOnly")]
[assembly: AssemblyTitle("Index154.RandomRouteOnly")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 RandomRouteOnly
{
	internal class Rerolls : MonoBehaviour
	{
		public int rerolls = RandomRouteOnly.configManager.rerollsPerPlayer.Value;
	}
	public class ConfigManager
	{
		internal ConfigEntry<int> rerollsPerPlayer = null;

		internal ConfigEntry<bool> allowCompany = null;

		internal void Setup(ConfigFile configFile)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			rerollsPerPlayer = configFile.Bind<int>("General", "Rerolls per player per quota", 1, new ConfigDescription("How many rerolls each player gets on every quota", (AcceptableValueBase)null, Array.Empty<object>()));
			allowCompany = configFile.Bind<bool>("General", "Allow manually routing to Company", false, new ConfigDescription("If true, allows you to always route to the Company. Although it's quite tedious, this basically lets you reroll your moon as often as you want which is why it's not on by default. Can be nice to have though if you're sure that nobody will abuse it", (AcceptableValueBase)null, Array.Empty<object>()));
		}
	}
	public class Helper
	{
		private static IEnumerator DelayStartGame(float delay)
		{
			yield return (object)new WaitForSeconds(delay);
			StartMatchLever lever = Object.FindObjectOfType<StartMatchLever>();
			lever.StartGame();
		}

		public static void FlyToLevel(ref StartOfRound __instance, bool randomLevel, bool autoLand)
		{
			if (!((NetworkBehaviour)__instance).NetworkManager.IsHost)
			{
				return;
			}
			bool flag = __instance.gameStats.daysSpent == 0;
			SelectableLevel[] levels = __instance.levels;
			List<SelectableLevel> list = new List<SelectableLevel>();
			int num = 3;
			if (randomLevel)
			{
				SelectableLevel[] array = levels;
				foreach (SelectableLevel val in array)
				{
					if (val.levelID != 3 && val.levelID != 11 && (val.levelID != __instance.currentLevel.levelID || flag))
					{
						list.Add(val);
					}
				}
				num = list[Random.Range(0, list.Count)].levelID;
			}
			if (__instance.CanChangeLevels() && num != __instance.currentLevel.levelID)
			{
				__instance.ChangeLevelServerRpc(num, Object.FindObjectOfType<Terminal>().groupCredits);
				if (!randomLevel && autoLand)
				{
					((MonoBehaviour)__instance).StartCoroutine(DelayStartGame(8f));
				}
			}
		}
	}
	[BepInPlugin("Index154.RandomRouteOnly", "RandomRouteOnly", "1.1.1")]
	public class RandomRouteOnly : BaseUnityPlugin
	{
		internal static ConfigManager configManager;

		public static RandomRouteOnly Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			configManager = new ConfigManager();
			configManager.Setup(((BaseUnityPlugin)this).Config);
			Patch();
			Logger.LogInfo((object)"Index154.RandomRouteOnly v1.1.1 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Index154.RandomRouteOnly");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Index154.RandomRouteOnly";

		public const string PLUGIN_NAME = "RandomRouteOnly";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}
namespace RandomRouteOnly.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	public class PlayerControllerBPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AddRerollValue(PlayerControllerB __instance)
		{
			Rerolls rerolls = ((Component)__instance).gameObject.AddComponent<Rerolls>();
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void AutoRouteRandomDayOne(ref StartOfRound __instance)
		{
			if (TimeOfDay.Instance.daysUntilDeadline == 0)
			{
				Helper.FlyToLevel(ref __instance, randomLevel: false, autoLand: false);
			}
			else if ((__instance.gameStats.daysSpent == 0 && __instance.currentLevel.levelID == 0) || __instance.currentLevel.levelID == 3)
			{
				Helper.FlyToLevel(ref __instance, randomLevel: true, autoLand: false);
			}
		}

		[HarmonyPatch("SetShipReadyToLand")]
		[HarmonyPostfix]
		private static void AutoRouteRandomNewDay(ref StartOfRound __instance)
		{
			if (TimeOfDay.Instance.daysUntilDeadline != 0)
			{
				Helper.FlyToLevel(ref __instance, randomLevel: true, autoLand: false);
				return;
			}
			PlayerControllerB[] allPlayerScripts = __instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				Rerolls component = ((Component)val).gameObject.GetComponent<Rerolls>();
				component.rerolls = RandomRouteOnly.configManager.rerollsPerPlayer.Value;
			}
			Helper.FlyToLevel(ref __instance, randomLevel: false, autoLand: true);
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	public class TerminalPatch
	{
		private static readonly TerminalNode noReroll = new TerminalNode
		{
			name = "noReroll",
			displayText = "\nYou have no rerolls left for this quota!\nLand the ship or let somebody else use the command.\n\nYour rerolls will be set to " + RandomRouteOnly.configManager.rerollsPerPlayer.Value + " at the start of the next quota\n\n\n",
			clearPreviousText = true
		};

		private static readonly TerminalNode noManualRoutesAllowed = new TerminalNode
		{
			name = "noManualRoutesAllowed",
			displayText = "\nYou are not allowed to manually fly to this moon!\nLand the ship or use the command 'random'\n\n\n",
			clearPreviousText = true
		};

		[HarmonyPatch("ParsePlayerSentence")]
		[HarmonyPostfix]
		private static TerminalNode RestrictRouteUsage(TerminalNode __result)
		{
			if (((Object)__result).name == "routeRandom" || ((Object)__result).name == "routeRandomFilterWeather")
			{
				Rerolls component = ((Component)GameNetworkManager.Instance.localPlayerController).gameObject.GetComponent<Rerolls>();
				if (component.rerolls < 1)
				{
					return noReroll;
				}
				component.rerolls--;
			}
			else if (((Object)__result).name.ToLowerInvariant().Contains("route") && (!((Object)__result).name.Contains("Company") || !RandomRouteOnly.configManager.allowCompany.Value))
			{
				return noManualRoutesAllowed;
			}
			return __result;
		}

		[HarmonyPatch("TextPostProcess")]
		[HarmonyPostfix]
		private static string AddRemainingRerollsText(string modifiedDisplayText, TerminalNode node, ref string __result)
		{
			if (__result.Contains("Routing autopilot to"))
			{
				Rerolls component = ((Component)GameNetworkManager.Instance.localPlayerController).gameObject.GetComponent<Rerolls>();
				string text = "s";
				if (component.rerolls == 1)
				{
					text = "";
				}
				__result = __result + "You have " + component.rerolls + " reroll" + text + " left for this quota\n\n\n";
			}
			return __result;
		}
	}
}