Decompiled source of Spoods Express Delivery v1.0.3

plugins/Spood.LethalCompany.ExpressDelivery/Spood.LethalCompany.ExpressDelivery.dll

Decompiled 10 months ago
using System;
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 HarmonyLib;
using LethalLib.Modules;
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("Spood.LethalCompany.ExpressDelivery")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds express delivery option for the drop ship")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Spood.LethalCompany.ExpressDelivery")]
[assembly: AssemblyTitle("Spood.LethalCompany.ExpressDelivery")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Spood.LethalCompany.ExpressDelivery
{
	[BepInPlugin("Spood.LethalCompany.ExpressDelivery", "Spood's Express Delivery", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "Spood.LethalCompany.ExpressDelivery";

		public const string PLUGIN_NAME = "Spood's Express Delivery";

		public const string PLUGIN_VERSION = "1.0.3";

		public static AssetBundle bundle;

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "spood.lethalcompany.expressdelivery");
			bundle = AssetBundle.LoadFromFile(text);
			Harmony val = new Harmony("Spood.LethalCompany.ExpressDelivery");
			val.PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Spood.LethalCompany.ExpressDelivery is loaded!");
			RegisterExpressDelivery();
		}

		private void RegisterExpressDelivery()
		{
			Item val = bundle.LoadAsset<Item>("Assets/Spood.LethalCompany.ExpressDelivery/ExpressDelivery/ExpressDeliveryItem.asset");
			Utilities.FixMixerGroups(val.spawnPrefab);
			TerminalNode val2 = ScriptableObject.CreateInstance<TerminalNode>();
			val2.clearPreviousText = true;
			val2.displayText = "Receive items faster!\n\n";
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterShopItem(val, (TerminalNode)null, (TerminalNode)null, val2, 50);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Spood.LethalCompany.ExpressDelivery";

		public const string PLUGIN_NAME = "Spood.LethalCompany.ExpressDelivery";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Spood.LethalCompany.ExpressDelivery.Patches
{
	[HarmonyPatch(typeof(ItemDropship), "OpenShipDoorsOnServer")]
	internal class ItemDropshipPatchOpenShipDoorOnServerMethod
	{
		private static bool Prefix(ref ItemDropship __instance, ref bool ___shipDoorsOpened, ref float ___shipTimer)
		{
			___shipTimer = 25f;
			return true;
		}
	}
	[HarmonyPatch(typeof(ItemDropship), "ShipLeave")]
	internal class ItemDropshipPatchShipLeaveMethod
	{
		public static bool Prefix(ref float ___shipTimer)
		{
			___shipTimer = 0f;
			return true;
		}
	}
	[HarmonyPatch(typeof(ItemDropship), "Update")]
	internal class ItemDropshipPatchUpdateMethod
	{
		private static int expressDeliveryIndex = -1;

		private static float timerTarget = 0f;

		private static bool Prefix(ref ItemDropship __instance, ref bool ___deliveringOrder, ref Terminal ___terminalScript, ref StartOfRound ___playersManager, ref float ___shipTimer, ref bool ___playersFirstOrder, ref bool ___shipLanded, ref float ___noiseInterval, ref int ___timesPlayedWithoutTurningOff, ref bool ___shipDoorsOpened)
		{
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return false;
			}
			if (!___deliveringOrder)
			{
				if (___terminalScript.orderedItemsFromTerminal.Count > 0)
				{
					___shipTimer += Time.deltaTime;
					Debug.Log((object)("ship timer:" + ___shipTimer));
					if (expressDeliveryIndex == -1)
					{
						expressDeliveryIndex = FindExpressDeliveryIndex(___terminalScript);
					}
					if (___terminalScript.orderedItemsFromTerminal.Contains(expressDeliveryIndex) | ___playersFirstOrder)
					{
						BuyExpress(___playersManager, ref __instance);
					}
					else
					{
						BuyRegular(___playersManager, ref __instance);
					}
					if (___shipTimer > timerTarget)
					{
						Debug.Log((object)("target timer:" + timerTarget));
						___shipTimer = 0f;
						MethodInfo methodInfo = AccessTools.Method(typeof(ItemDropship), "LandShipOnServer", (Type[])null, (Type[])null);
						methodInfo.Invoke(__instance, null);
					}
				}
			}
			else if (___shipLanded)
			{
				___shipTimer += Time.deltaTime;
				if (___shipTimer > 30f)
				{
					___timesPlayedWithoutTurningOff = 0;
					___shipLanded = false;
					MethodInfo methodInfo2 = AccessTools.Method(typeof(ItemDropship), "ShipLeaveClientRpc", (Type[])null, (Type[])null);
					methodInfo2.Invoke(__instance, null);
				}
				if (___noiseInterval <= 0f)
				{
					___noiseInterval = 1f;
					___timesPlayedWithoutTurningOff++;
					RoundManager.Instance.PlayAudibleNoise(((Component)__instance).transform.position, 60f, 1.3f, ___timesPlayedWithoutTurningOff, false, 94);
				}
				else
				{
					___noiseInterval -= Time.deltaTime;
				}
			}
			return false;
		}

		private static int FindExpressDeliveryIndex(Terminal terminal)
		{
			return Array.FindIndex(terminal.buyableItemsList, (Item x) => ((Object)x).name == "ExpressDeliveryItem");
		}

		private static void BuyExpress(StartOfRound playersManager, ref ItemDropship instance)
		{
			if (!playersManager.shipHasLanded)
			{
				timerTarget = 12f;
			}
			else
			{
				timerTarget = 5f;
			}
		}

		private static void BuyRegular(StartOfRound playersManager, ref ItemDropship instance)
		{
			if (!playersManager.shipHasLanded)
			{
				timerTarget = 60f;
			}
			else
			{
				timerTarget = 40f;
			}
		}
	}
}