Decompiled source of SnowyHolidayDropship v1.0.3

SnowyHolidayDropship.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SnowyHolidayDropship")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Brings back the holiday dropship on snowy moons.")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("SnowyHolidayDropship")]
[assembly: AssemblyTitle("SnowyHolidayDropship")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SnowyHolidayDropship
{
	internal static class DropshipDecorator
	{
		private static ItemDropship shipScript;

		private static AudioClip music;

		private static AudioClip musicFar;

		private static AudioClip musicJolly;

		private static AudioClip musicFarJolly;

		private static AudioClip musicOld;

		private static AudioClip musicFarOld;

		private static Mesh ship;

		private static Mesh shipJolly;

		private static GameObject star;

		private static GameObject shipObject;

		private static MeshFilter shipComponent;

		private static AudioSource musicComponent;

		private static AudioSource musicFarComponent;

		private static Random rand = new Random();

		private static bool initialized;

		private static bool landed;

		private static bool seeded;

		internal static void Init(ItemDropship itemDropship)
		{
			initialized = false;
			shipScript = itemDropship;
			try
			{
				Transform transform = ((Component)shipScript).transform;
				star = ((Component)transform.Find("Star")).gameObject;
				shipObject = ((Component)transform.Find("ItemShip")).gameObject;
				shipComponent = shipObject.GetComponent<MeshFilter>();
				Transform obj = transform.Find("Music");
				musicComponent = ((Component)obj).GetComponent<AudioSource>();
				musicFarComponent = ((Component)obj.Find("Music (1)")).GetComponent<AudioSource>();
				Plugin.Logger.LogInfo((object)"Successfully cached all dropship object references");
				shipJolly = shipComponent.sharedMesh;
				music = musicComponent.clip;
				musicFar = musicFarComponent.clip;
				Plugin.Logger.LogInfo((object)"Successfully cached all pre-existing asset references");
				if ((Object)(object)musicJolly == (Object)null || (Object)(object)musicFarJolly == (Object)null || (Object)(object)ship == (Object)null || (Object)(object)musicOld == (Object)null)
				{
					AssetBundle obj2 = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "snowyholidaydropship"));
					musicJolly = obj2.LoadAsset<AudioClip>("IcecreamTruckV2Christmas");
					musicFarJolly = obj2.LoadAsset<AudioClip>("IcecreamTruckV2ChristmasFar");
					musicOld = obj2.LoadAsset<AudioClip>("IcecreamTruck");
					musicFarOld = obj2.LoadAsset<AudioClip>("IcecreamTruckV1Far");
					ship = obj2.LoadAsset<Mesh>("MainShipPart");
					obj2.Unload(false);
					Plugin.Logger.LogInfo((object)"Successfully cached all asset bundle references");
				}
				initialized = true;
				landed = false;
				seeded = false;
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)"Failed to capture references to all the dropship objects - are you playing on a modded moon?");
				Plugin.Logger.LogError((object)"Please send the information below to the developer, and mention what moon this error occurred on");
				Plugin.Logger.LogError((object)ex.Message);
			}
		}

		internal static void RedecorateDropship()
		{
			if (!initialized || landed)
			{
				return;
			}
			landed = true;
			if (!seeded)
			{
				rand = new Random(StartOfRound.Instance.randomMapSeed);
				Plugin.Logger.LogInfo((object)$"RNG initialized (Seed: {StartOfRound.Instance.randomMapSeed})");
				seeded = true;
			}
			Plugin.Logger.LogInfo((object)"Roll chance for holiday");
			bool num = RandomChance(StartOfRound.Instance.currentLevel.levelIncludesSnowFootprints ? ((double)Plugin.configSnowyChance.Value) : ((double)Plugin.configNormalChance.Value));
			Plugin.Logger.LogInfo((object)"Roll chance for old music");
			bool flag = RandomChance(Plugin.configLegacyChance.Value);
			if (num)
			{
				shipComponent.mesh = shipJolly;
				musicComponent.clip = musicJolly;
				musicFarComponent.clip = musicFarJolly;
				star.SetActive(true);
				Plugin.Logger.LogInfo((object)"Dropship: Holiday");
				return;
			}
			shipComponent.mesh = ship;
			if (flag)
			{
				musicComponent.clip = musicOld;
				musicFarComponent.clip = musicFarOld;
				Plugin.Logger.LogInfo((object)"Dropship: Normal (old music)");
			}
			else
			{
				musicComponent.clip = music;
				musicFarComponent.clip = musicFar;
				Plugin.Logger.LogInfo((object)"Dropship: Normal");
			}
			star.SetActive(false);
		}

		internal static void DropshipLeave()
		{
			landed = false;
			if (initialized && star.activeSelf)
			{
				((MonoBehaviour)shipScript).StartCoroutine(DisableStarInSky());
			}
		}

		internal static IEnumerator DisableStarInSky()
		{
			float start = Time.time;
			Plugin.Logger.LogInfo((object)"Holiday: Upon reaching orbit, disable star");
			while (shipObject.activeSelf)
			{
				yield return null;
			}
			star.SetActive(false);
			Plugin.Logger.LogInfo((object)$"Holiday: Star disabled after {Time.time - start}s");
		}

		private static bool RandomChance(double chance)
		{
			double num = rand.NextDouble();
			Plugin.Logger.LogInfo((object)$"RNG: {num} < {chance}");
			if (!(chance >= 1.0))
			{
				if (chance > 0.0)
				{
					return num < chance;
				}
				return false;
			}
			return true;
		}
	}
	[BepInPlugin("butterystancakes.lethalcompany.snowyholidaydropship", "Snowy Holiday Dropship", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "butterystancakes.lethalcompany.snowyholidaydropship";

		private const string PLUGIN_NAME = "Snowy Holiday Dropship";

		private const string PLUGIN_VERSION = "1.0.3";

		public static ConfigEntry<float> configSnowyChance;

		public static ConfigEntry<float> configNormalChance;

		public static ConfigEntry<float> configLegacyChance;

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			AcceptableValueRange<float> val = new AcceptableValueRange<float>(0f, 1f);
			string text = " (0 = never, 1 = guaranteed, or anything in between - 0.5 = 50% chance)";
			configSnowyChance = ((BaseUnityPlugin)this).Config.Bind<float>("Random", "SnowyChance", 1f, new ConfigDescription("The percentage chance for the dropship to be holiday-themed on snowy moons." + text, (AcceptableValueBase)(object)val, Array.Empty<object>()));
			configNormalChance = ((BaseUnityPlugin)this).Config.Bind<float>("Random", "NormalChance", 0f, new ConfigDescription("The percentage chance for the dropship to be holiday-themed on normal moons." + text, (AcceptableValueBase)(object)val, Array.Empty<object>()));
			configLegacyChance = ((BaseUnityPlugin)this).Config.Bind<float>("Random", "LegacyChance", 0f, new ConfigDescription("The percentage chance for the normal dropship to use the old music, showcased in an early teaser video." + text, (AcceptableValueBase)(object)val, Array.Empty<object>()));
			new Harmony("butterystancakes.lethalcompany.snowyholidaydropship").PatchAll();
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Snowy Holiday Dropship v1.0.3 loaded");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SnowyHolidayDropship";

		public const string PLUGIN_NAME = "SnowyHolidayDropship";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}
namespace SnowyHolidayDropship.Patches
{
	[HarmonyPatch]
	internal class SnowyHolidayDropshipPatches
	{
		[HarmonyPatch(typeof(ItemDropship), "Start")]
		[HarmonyPostfix]
		public static void ItemDropshipPostStart(ItemDropship __instance)
		{
			DropshipDecorator.Init(__instance);
		}

		[HarmonyPatch(typeof(ItemDropship), "LandShipClientRpc")]
		[HarmonyPostfix]
		public static void PostLandShipClientRpc()
		{
			DropshipDecorator.RedecorateDropship();
		}

		[HarmonyPatch(typeof(ItemDropship), "ShipLeave")]
		[HarmonyPostfix]
		public static void ItemDropshipPostShipLeave()
		{
			DropshipDecorator.DropshipLeave();
		}
	}
}