Decompiled source of DropshipAyayay v0.1.0

DropshipJDG.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LCSoundTool;
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: IgnoresAccessChecksTo("")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DropshipJDG")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DropshipJDG")]
[assembly: AssemblyTitle("DropshipJDG")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
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 DropshipJDG
{
	public static class ConfigSettings
	{
		public static ConfigEntry<int>? dropshipDeliveryTime;

		public static ConfigEntry<int>? dropshipMaxStayDuration;

		public static ConfigEntry<int>? dropshipLeaveAfterSecondsOpenDoors;

		public static void BindConfigSettings()
		{
			if ((Object)(object)Plugin.instance != (Object)null)
			{
				dropshipDeliveryTime = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("DropshipJDG", "DeliveryTime", 15, "How long it takes (in seconds) for the item dropship to arrive. Modify this setting as desired. ");
				dropshipMaxStayDuration = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("DropshipJDG", "MaxLandDuration", 36, "The max duration (in seconds) the item dropship will stay. Changing this setting is NOT recommended, if you still wish to increase the time, you can choose multiples of 36 (so that the music doesn't stop halfway through), such as 72, 108, ect.");
				dropshipLeaveAfterSecondsOpenDoors = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("DropshipJDG", "LeaveAfterSecondsOpenDoors", 36, "The max duration (in seconds) the item dropship will stay. Changing this setting is NOT recommended, if you still wish to increase the time, you can choose multiples of 36 (so that the music doesn't stop halfway through), such as 72, 108, ect.");
			}
			else
			{
				Debug.LogError((object)"Plugin instance is null. Cannot bind config settings.");
			}
		}
	}
	[BepInPlugin("com.chlabadouf.loadjdgtheme", "DropshipJDG", "1.0.4")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin? instance;

		private Harmony _harmony;

		public Plugin()
		{
			instance = this;
		}

		private void Awake()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			instance = this;
			ConfigSettings.BindConfigSettings();
			_harmony = new Harmony("JDGTheme");
			_harmony.PatchAll();
		}

		public static void Log(string message)
		{
			Plugin? plugin = instance;
			if (plugin != null)
			{
				((BaseUnityPlugin)plugin).Logger.LogInfo((object)message);
			}
		}
	}
	[HarmonyPatch]
	internal class DropshipJDGPatcher
	{
		private static Terminal? terminalScript;

		private static StartOfRound? playersManager;

		private static List<int>? itemsToDeliver;

		private static List<int>? orderedItemsFromTerminal;

		[HarmonyPatch(typeof(ItemDropship), "Start")]
		[HarmonyPrefix]
		public static void InitializeDropship(ItemDropship __instance)
		{
			playersManager = Object.FindObjectOfType<StartOfRound>();
			terminalScript = Object.FindObjectOfType<Terminal>();
			if (itemsToDeliver == null)
			{
				itemsToDeliver = (List<int>)Traverse.Create((object)__instance).Field("itemsToDeliver").GetValue();
			}
		}

		[HarmonyPatch(typeof(Terminal), "Start")]
		[HarmonyPrefix]
		public static void InitializeTerminal(Terminal __instance)
		{
			orderedItemsFromTerminal = __instance.orderedItemsFromTerminal;
		}

		[HarmonyPatch(typeof(ItemDropship), "Update")]
		[HarmonyPrefix]
		public static void DropshipUpdate(ItemDropship __instance)
		{
			if (((NetworkBehaviour)__instance).IsServer && !__instance.deliveringOrder && (Object)(object)terminalScript != (Object)null && terminalScript.orderedItemsFromTerminal != null && terminalScript.orderedItemsFromTerminal.Count > 0 && (Object)(object)playersManager != (Object)null && !playersManager.shipHasLanded)
			{
				__instance.shipTimer += Time.deltaTime;
			}
			if (orderedItemsFromTerminal != null && orderedItemsFromTerminal.Count > 0 && (Object)(object)__instance != (Object)null && __instance.shipDoorsOpened)
			{
				__instance.shipTimer = 99999f;
			}
		}

		[HarmonyPatch(typeof(ItemDropship), "Update")]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (!(list[i].opcode == OpCodes.Ldc_R4))
				{
					continue;
				}
				if ((float)list[i].operand == 20f)
				{
					if (ConfigSettings.dropshipMaxStayDuration != null)
					{
						list[i].operand = (float)ConfigSettings.dropshipMaxStayDuration.Value;
					}
				}
				else if ((float)list[i].operand == 40f)
				{
					if (ConfigSettings.dropshipMaxStayDuration != null && ConfigSettings.dropshipDeliveryTime != null)
					{
						list[i].operand = (float)(ConfigSettings.dropshipMaxStayDuration.Value + ConfigSettings.dropshipDeliveryTime.Value);
					}
				}
				else if ((float)list[i].operand == 30f)
				{
					if (ConfigSettings.dropshipMaxStayDuration != null)
					{
						list[i].operand = (float)ConfigSettings.dropshipMaxStayDuration.Value;
					}
					break;
				}
			}
			return list.AsEnumerable();
		}

		[HarmonyPatch(typeof(ItemDropship), "OpenShipDoorsOnServer")]
		[HarmonyPostfix]
		public static void OnOpenShipDoors(ItemDropship __instance)
		{
			if (((NetworkBehaviour)__instance).IsServer && ConfigSettings.dropshipMaxStayDuration != null && ConfigSettings.dropshipLeaveAfterSecondsOpenDoors != null)
			{
				__instance.shipTimer = Mathf.Max(__instance.shipTimer, (float)(ConfigSettings.dropshipMaxStayDuration.Value - ConfigSettings.dropshipLeaveAfterSecondsOpenDoors.Value));
			}
		}

		[HarmonyPatch(typeof(ItemDropship), "ShipLandedAnimationEvent")]
		[HarmonyPrefix]
		public static void AddLateItemsServer(ItemDropship __instance)
		{
			if (((NetworkBehaviour)__instance).IsServer && !__instance.shipLanded && !__instance.shipDoorsOpened && orderedItemsFromTerminal != null && itemsToDeliver != null)
			{
				while (orderedItemsFromTerminal.Count > 0 && itemsToDeliver.Count < 12)
				{
					itemsToDeliver.Add(orderedItemsFromTerminal[0]);
					orderedItemsFromTerminal.RemoveAt(0);
				}
			}
		}
	}
}
namespace JDGTheme
{
	[BepInPlugin("com.chlabadouf.jdgtheme", "JDG Theme", "1.0.4")]
	public class ServerMod : BaseUnityPlugin
	{
		private static ManualLogSource? logger;

		static ServerMod()
		{
			logger = Logger.CreateLogSource("BepInEx");
		}

		private void Start()
		{
			LoadAudio();
		}

		private void LoadAudio()
		{
			if (logger == null)
			{
				Debug.LogError((object)"Logger is not started.");
				return;
			}
			AudioClip audioClip = SoundTool.GetAudioClip("chlabadouf-DropshipGeneriqueJDG", "IcecreamTruckV2.mp3");
			AudioClip audioClip2 = SoundTool.GetAudioClip("chlabadouf-DropshipGeneriqueJDG", "IcecreamTruckFar.mp3");
			if ((Object)(object)audioClip != (Object)null)
			{
				SoundTool.ReplaceAudioClip("IcecreamTruckV2", audioClip);
				SoundTool.ReplaceAudioClip("IcecreamTruckFar", audioClip2);
				logger.LogInfo((object)"Replaced Dropship Song with JDG Theme");
			}
			else
			{
				logger.LogError((object)"Failed to load JDG Theme... Sadge :/");
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}