Decompiled source of ScienceBird Tweaks v1.0.1

ScienceBird.ScienceBirdTweaks.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
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("ScienceBird.ScienceBirdTweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScienceBirdTweaks")]
[assembly: AssemblyTitle("ScienceBird.ScienceBirdTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 ScienceBirdTweaks
{
	[BepInPlugin("ScienceBird.ScienceBirdTweaks", "ScienceBirdTweaks", "1.0.0")]
	public class ScienceBirdTweaks : BaseUnityPlugin
	{
		public static AssetBundle TweaksAssets;

		public static ConfigEntry<bool> ConsistentRailingCollision;

		public static ConfigEntry<bool> BigScrew;

		public static ConfigEntry<bool> DustSpaceClouds;

		public static ConfigEntry<bool> DiversityComputerBegone;

		public static ConfigEntry<bool> OldHalloweenElevatorMusic;

		public static ScienceBirdTweaks 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;
			ConsistentRailingCollision = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "Consistent Railing Collision", true, "Ship catwalk has consistent collision outside its railing, so you can always jump and stand on the edge of the catwalk.");
			BigScrew = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "Big Screw", true, "'Big bolt' is accurately renamed to 'Big screw'.");
			DustSpaceClouds = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "Dust (Space) Clouds", true, "Adds a space to the 'DustClouds' weather whenever it's displayed, making it 'Dust Clouds' (only affects modded content which uses it, since it's never explicitly displayed in vanilla).");
			DiversityComputerBegone = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "Diversity Computer Begone", true, "Removes the floppy reader computer from Diversity and any floppy disks that spawn (does nothing if Diversity isn't installed).");
			OldHalloweenElevatorMusic = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "Old Halloween Elevator Music", true, "Restores mineshaft elevator to its old Halloween behaviour, playing a random selection of groovy tracks (disabled if ButteryStancakes' HalloweenElevator is installed).");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			TweaksAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "tweaksassets"));
			Patch();
			Logger.LogInfo((object)"ScienceBird.ScienceBirdTweaks v1.0.0 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("ScienceBird.ScienceBirdTweaks");
			}
			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 = "ScienceBird.ScienceBirdTweaks";

		public const string PLUGIN_NAME = "ScienceBirdTweaks";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ScienceBirdTweaks.Patches
{
	[HarmonyPatch]
	public class BigScrew
	{
		[HarmonyPatch(typeof(RoundManager), "SyncScrapValuesClientRpc")]
		[HarmonyPostfix]
		private static void FindScrews(RoundManager __instance)
		{
			if (ScienceBirdTweaks.BigScrew.Value)
			{
				GameObject[] array = (from obj in Resources.FindObjectsOfTypeAll<GameObject>()
					where ((Object)obj).name == "BigBolt(Clone)"
					select obj).ToArray();
				GameObject[] array2 = array;
				foreach (GameObject val in array2)
				{
					val.GetComponentInChildren<ScanNodeProperties>().headerText = "Big screw";
					val.GetComponentInChildren<GrabbableObject>().itemProperties.itemName = "Big screw";
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "PlayerLoadedClientRpc")]
		[HarmonyPostfix]
		private static void FindScrewsOnLoad(StartOfRound __instance)
		{
			if (ScienceBirdTweaks.BigScrew.Value)
			{
				GameObject[] array = (from obj in Resources.FindObjectsOfTypeAll<GameObject>()
					where ((Object)obj).name == "BigBolt(Clone)"
					select obj).ToArray();
				GameObject[] array2 = array;
				foreach (GameObject val in array2)
				{
					val.GetComponentInChildren<ScanNodeProperties>().headerText = "Big screw";
					val.GetComponentInChildren<GrabbableObject>().itemProperties.itemName = "Big screw";
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "LoadShipGrabbableItems")]
		[HarmonyPostfix]
		private static void FindScrewsShip(StartOfRound __instance)
		{
			if (ScienceBirdTweaks.BigScrew.Value)
			{
				GameObject[] array = (from obj in Resources.FindObjectsOfTypeAll<GameObject>()
					where ((Object)obj).name == "BigBolt(Clone)"
					select obj).ToArray();
				GameObject[] array2 = array;
				foreach (GameObject val in array2)
				{
					val.GetComponentInChildren<ScanNodeProperties>().headerText = "Big screw";
					val.GetComponentInChildren<GrabbableObject>().itemProperties.itemName = "Big screw";
				}
			}
		}

		[HarmonyPatch(typeof(Terminal), "LoadNewNode")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		[HarmonyAfter(new string[] { "mrov.terminalformatter" })]
		private static void AddScrewToTerminal(Terminal __instance)
		{
			if (ScienceBirdTweaks.BigScrew.Value && __instance.currentText.ToLower().Contains("big bolt"))
			{
				__instance.currentText = __instance.currentText.Replace("Big bolt", "Big screw");
				__instance.screenText.text = __instance.currentText;
			}
		}
	}
	[HarmonyPatch]
	public class ConsistentRailingCollision
	{
		[HarmonyPatch(typeof(StartOfRound), "SceneManager_OnLoadComplete1")]
		[HarmonyPostfix]
		private static void ReplaceRailingCollision(StartOfRound __instance, string sceneName)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			if (!ScienceBirdTweaks.ConsistentRailingCollision.Value || !(sceneName != "SampleSceneRelay") || !(sceneName != "MainMenu"))
			{
				return;
			}
			GameObject val = GameObject.Find("CatwalkShip");
			if ((Object)(object)val != (Object)null)
			{
				GameObject val2 = (GameObject)ScienceBirdTweaks.TweaksAssets.LoadAsset("CatwalkShipAltered");
				MeshFilter componentInChildren = val2.GetComponentInChildren<MeshFilter>();
				MeshCollider component = val.GetComponent<MeshCollider>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					component.sharedMesh = componentInChildren.sharedMesh;
				}
			}
			else
			{
				ScienceBirdTweaks.Logger.LogError((object)"Couldn't find catwalk!");
			}
		}
	}
	[HarmonyPatch]
	public class DiversityComputerBegone
	{
		internal static bool isDone = false;

		internal static int checkCount = 0;

		internal static string[] diskNames = new string[11]
		{
			"Never Stopping", "Ex-37", "Ex-43", "Ex-67", "Ex-507", "Sub-12", "Sub-16", "Sub-30", "Sub-66", "Sub-100",
			"Sub-507"
		};

		[HarmonyPatch(typeof(StartOfRound), "SceneManager_OnLoadComplete1")]
		[HarmonyPostfix]
		private static void ResetOnLoad(StartOfRound __instance, string sceneName)
		{
			if (ScienceBirdTweaks.DiversityComputerBegone.Value)
			{
				isDone = false;
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Update")]
		[HarmonyPostfix]
		private static void DestroyComputer(StartOfRound __instance)
		{
			if (!ScienceBirdTweaks.DiversityComputerBegone.Value || isDone)
			{
				return;
			}
			if (!__instance.shipHasLanded)
			{
				GameObject val = GameObject.Find("Floppy Reader(Clone)");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Object.Destroy((Object)(object)val);
				string[] array = diskNames;
				foreach (string text in array)
				{
					GameObject val2 = GameObject.Find(text + "(Clone)");
					if ((Object)(object)val2 != (Object)null)
					{
						Object.Destroy((Object)(object)val2);
					}
				}
				isDone = true;
				checkCount++;
				if (checkCount > 5)
				{
					isDone = true;
				}
			}
			else
			{
				isDone = true;
			}
		}

		[HarmonyPatch(typeof(RoundManager), "SyncScrapValuesClientRpc")]
		[HarmonyPostfix]
		private static void FindDisks(RoundManager __instance)
		{
			if (!ScienceBirdTweaks.DiversityComputerBegone.Value)
			{
				return;
			}
			string[] array = diskNames;
			foreach (string text in array)
			{
				GameObject val = GameObject.Find(text + "(Clone)");
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}
	}
	[HarmonyPatch]
	public class DustSpaceClouds
	{
		[HarmonyPatch(typeof(StartOfRound), "SetMapScreenInfoToCurrentLevel")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void AddSpaceToMapScreen(StartOfRound __instance)
		{
			if (ScienceBirdTweaks.DustSpaceClouds.Value)
			{
				string text = ((TMP_Text)__instance.screenLevelDescription).text;
				if (text.Contains("DustClouds"))
				{
					text = text.Replace("DustClouds", "Dust Clouds");
					((TMP_Text)__instance.screenLevelDescription).text = text;
				}
			}
		}

		[HarmonyPatch(typeof(Terminal), "LoadNewNode")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		[HarmonyAfter(new string[] { "mrov.terminalformatter" })]
		private static void AddSpaceToTerminal(Terminal __instance)
		{
			if (ScienceBirdTweaks.DustSpaceClouds.Value && __instance.currentText.Contains("DustClouds"))
			{
				__instance.currentText = __instance.currentText.Replace("DustClouds", "Dust Clouds");
				__instance.screenText.text = __instance.currentText;
			}
		}
	}
	[HarmonyPatch(typeof(MineshaftElevatorController))]
	public class ElevatorJinglePatch
	{
		internal static Random clipRandom;

		internal static bool butteryPresent;

		[HarmonyPatch(typeof(StartOfRound), "SceneManager_OnLoadComplete1")]
		[HarmonyPostfix]
		private static void CheckButtery(StartOfRound __instance)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (assembly.GetName().Name == "HalloweenElevator")
				{
					butteryPresent = true;
					break;
				}
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static void SetJingleClip(MineshaftElevatorController __instance)
		{
			if (!butteryPresent && ScienceBirdTweaks.OldHalloweenElevatorMusic.Value && __instance.playMusic && !__instance.elevatorJingleMusic.isPlaying)
			{
				int num = clipRandom.Next(0, __instance.elevatorHalloweenClips.Length);
				if (__instance.elevatorMovingDown)
				{
					__instance.elevatorJingleMusic.clip = __instance.elevatorHalloweenClips[num];
				}
				else
				{
					__instance.elevatorJingleMusic.clip = __instance.elevatorHalloweenClipsLoop[num];
				}
			}
		}

		[HarmonyPatch("OnEnable")]
		[HarmonyPrefix]
		private static void SetJingleRandom(MineshaftElevatorController __instance)
		{
			if (!butteryPresent && ScienceBirdTweaks.OldHalloweenElevatorMusic.Value)
			{
				clipRandom = new Random(StartOfRound.Instance.randomMapSeed);
			}
		}
	}
}