Decompiled source of RandomMoonFX v1.2.3

RandomMoonFX.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("RandomMoonFX")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RandomMoonFX")]
[assembly: AssemblyTitle("RandomMoonFX")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace RandomMoonFX
{
	internal class Config
	{
		public ConfigEntry<bool> CelestialTintAnimation;

		public ConfigEntry<bool> QuotaCheck;

		public ConfigEntry<bool> RandomizeLastDay;

		public Config(ConfigFile cfg)
		{
			cfg.SaveOnConfigSet = false;
			CelestialTintAnimation = cfg.Bind<bool>("Routing animation", "Celestial_Tint animation", true, "Enable compatibility with Celestial_Tint routing animation (which is a little bit longer than vanilla). Will be automatically false if Celestial_Tint is not installed.");
			QuotaCheck = cfg.Bind<bool>("Last day check", "Quota check", true, "If true, the ship will route to Gordion on the last day if quota has not been met yet. If false, there will be no quota check and the ship will route to Gordion only on the last day.");
			RandomizeLastDay = cfg.Bind<bool>("Last day check", "Randomize last day", false, "Enable this if you don't want to auto route to Gordion on the last day if there is not enough scraps in the ship to meet quota (other players potential dead bodies included), this allows you to randomize a moon on the last day to mess around but you will be fired at the end of the day.");
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("StartGame")]
		public static bool RandomizeMoonPatch()
		{
			if (Plugin.instance.IsStarting)
			{
				Plugin.instance.IsStarting = false;
				return true;
			}
			Plugin.instance.RouteRandomPlanet();
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch("TravelToLevelEffects")]
		public static IEnumerator StartMoonPatch(IEnumerator result)
		{
			while (result.MoveNext())
			{
				yield return result.Current;
			}
			if (Plugin.instance.IsStarting)
			{
				StartMatchLever lever = Object.FindObjectOfType<StartMatchLever>();
				lever.triggerScript.interactable = false;
				yield return (object)new WaitForSeconds(Plugin.instance.AnimationTime);
				lever.triggerScript.interactable = true;
				Plugin.instance.StartRandomPlanet();
			}
		}
	}
	[HarmonyPatch(typeof(StartMatchLever))]
	internal class StartMatchLeverPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("BeginHoldingInteractOnLever")]
		public static bool DisabledLastDayWarningPatch()
		{
			if (StartOfRound.Instance.CanChangeLevels() && Plugin.instance.LastDayOfQuota())
			{
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("BeginHoldingInteractOnLever")]
		public static void DisabledLongHoldTime(ref StartMatchLever __instance)
		{
			if (TimeOfDay.Instance.daysUntilDeadline <= 0 && __instance.playersManager.inShipPhase && StartOfRound.Instance.currentLevel.planetHasTime && Plugin.instance.LastDayOfQuota())
			{
				__instance.triggerScript.timeToHold = 0.7f;
			}
		}
	}
	[BepInPlugin("zigzag.randommoonfx", "RandomMoonFX", "1.2.3")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "zigzag.randommoonfx";

		private const string NAME = "RandomMoonFX";

		private const string VERSION = "1.2.3";

		public static Plugin instance;

		private readonly Harmony harmony = new Harmony("zigzag.randommoonfx");

		private readonly int GordionID = 3;

		public float AnimationTime = 1.5f;

		public bool IsStarting = false;

		internal static Config config { get; private set; }

		private void Awake()
		{
			instance = this;
			SetParameters();
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"RandomMoonFX is loaded !");
		}

		private void SetParameters()
		{
			config = new Config(((BaseUnityPlugin)this).Config);
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			if (config.CelestialTintAnimation.Value && assemblies.Any((Assembly assembly) => assembly.FullName.StartsWith("CelestialTint")))
			{
				AnimationTime = 4f;
			}
		}

		public bool LastDayOfQuota()
		{
			if (Utils.IsLastDayRandom())
			{
				return false;
			}
			if (config.QuotaCheck.Value)
			{
				return TimeOfDay.Instance.daysUntilDeadline == 0 && TimeOfDay.Instance.profitQuota > TimeOfDay.Instance.quotaFulfilled;
			}
			return TimeOfDay.Instance.daysUntilDeadline == 0;
		}

		public void RouteRandomPlanet()
		{
			if (LastDayOfQuota())
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Force navigating to the Company Building");
				StartOfRound.Instance.ChangeLevelServerRpc(GordionID, Object.FindObjectOfType<Terminal>().groupCredits);
			}
			else
			{
				SelectableLevel val = TimeOfDay.Instance.currentLevel;
				while (val.PlanetName == TimeOfDay.Instance.currentLevel.PlanetName)
				{
					val = StartOfRound.Instance.levels[Random.Range(0, StartOfRound.Instance.levels.Length)];
					if (val.PlanetName == "44 Liquidation" || val.PlanetName == "71 Gordion")
					{
						val = TimeOfDay.Instance.currentLevel;
					}
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Navigating to " + val.PlanetName));
				StartOfRound.Instance.ChangeLevelServerRpc(val.levelID, Object.FindObjectOfType<Terminal>().groupCredits);
			}
			IsStarting = true;
		}

		public void StartRandomPlanet()
		{
			StartOfRound.Instance.StartGameServerRpc();
		}
	}
	internal class Utils
	{
		public static bool IsLastDayRandom()
		{
			if (TimeOfDay.Instance.daysUntilDeadline != 0 || !Plugin.config.RandomizeLastDay.Value)
			{
				return false;
			}
			bool? inShip = true;
			int num = 5 * (StartOfRound.Instance.allPlayerObjects.Length - 1);
			int num2 = Object.FindObjectsOfType<GrabbableObject>().Where(delegate(GrabbableObject o)
			{
				int result;
				if (o.itemProperties.isScrap && o.itemProperties.minValue > 0 && !(o is RagdollGrabbableObject))
				{
					StunGrenadeItem val = (StunGrenadeItem)(object)((o is StunGrenadeItem) ? o : null);
					if (val == null || !val.hasExploded || !val.DestroyGrenade)
					{
						result = ((!inShip.HasValue || (o.isInShipRoom == inShip && o.isInElevator == inShip)) ? 1 : 0);
						goto IL_0094;
					}
				}
				result = 0;
				goto IL_0094;
				IL_0094:
				return (byte)result != 0;
			}).ToList()
				.Sum((GrabbableObject s) => s.scrapValue);
			if (num2 + num + TimeOfDay.Instance.quotaFulfilled >= TimeOfDay.Instance.profitQuota)
			{
				return false;
			}
			return true;
		}
	}
}