Decompiled source of CompanyCruiserFix v1.0.5

BepInEx/plugins/CompanyCruiserFix/CompanyCruiserFix.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
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.Logging;
using HarmonyLib;
using LethalLevelLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Pool;

[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("CompanyCruiserFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+2c6be0d63f3cacd1e2294ec0fa9e4f018fb80f40")]
[assembly: AssemblyProduct("CompanyCruiserFix")]
[assembly: AssemblyTitle("CompanyCruiserFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 CompanyCruiserFix
{
	[BepInPlugin("CompanyCruiserFix", "CompanyCruiserFix", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class CompanyCruiserFixPlugin : BaseUnityPlugin
	{
		private Harmony? m_Harmony;

		public static CompanyCruiserFixPlugin Instance { get; private set; }

		public ManualLogSource Logger { get; private set; }

		public GameObject RopesPrefab { get; private set; }

		public GameObject TruckDeliveryMusicPrefab { get; private set; }

		public GameObject TruckPointPrefab { get; private set; }

		public AudioClip CruiserCutRopesAudio { get; private set; }

		public RuntimeAnimatorController ItemShipController { get; private set; }

		private void Awake()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			string directoryName = new FileInfo(((BaseUnityPlugin)this).Info.Location).DirectoryName;
			LoadAssets(directoryName);
			m_Harmony = new Harmony("CompanyCruiserFix");
			m_Harmony.PatchAll(typeof(CompanyCruiserFixPlugin).Assembly);
		}

		private void LoadAssets(string workingDirectory)
		{
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(workingDirectory, "fixitemship.assetbundle"));
			ItemShipController = val.LoadAsset<RuntimeAnimatorController>("Assets/ItemDropship/ItemShip.controller");
			CruiserCutRopesAudio = val.LoadAsset<AudioClip>("Assets/ItemDropship/Cruiser_CutRopes.ogg");
			RopesPrefab = val.LoadAsset<GameObject>("Assets/ItemDropship/Ropes.prefab");
			TruckDeliveryMusicPrefab = val.LoadAsset<GameObject>("Assets/ItemDropship/TruckDeliveryMusic.prefab");
			TruckPointPrefab = val.LoadAsset<GameObject>("Assets/ItemDropship/TruckPoint.prefab");
			val.Unload(false);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CompanyCruiserFix";

		public const string PLUGIN_NAME = "CompanyCruiserFix";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace CompanyCruiserFix.Patches
{
	[HarmonyPatch(typeof(ItemDropship))]
	internal static class Patch_ItemDropship
	{
		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		public static void FixDropship(ItemDropship __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)LevelManager.CurrentExtendedLevel == (Object)null) && (int)((ExtendedContent)LevelManager.CurrentExtendedLevel).ContentType != 0 && (__instance.ropes == null || __instance.ropeDestinations == null || __instance.ropes.Length != __instance.ropeDestinations.Length || !((Object)(object)__instance.deliverVehiclePoint != (Object)null)))
			{
				PlayAudioAnimationEvent component = ((Component)__instance).GetComponent<PlayAudioAnimationEvent>();
				component.audioClip3 = CompanyCruiserFixPlugin.Instance.CruiserCutRopesAudio;
				Transform transform = ((Component)__instance).transform;
				GameObject val = Object.Instantiate<GameObject>(CompanyCruiserFixPlugin.Instance.RopesPrefab, transform);
				GameObject val2 = Object.Instantiate<GameObject>(CompanyCruiserFixPlugin.Instance.TruckDeliveryMusicPrefab, transform);
				Transform transform2 = Object.Instantiate<GameObject>(CompanyCruiserFixPlugin.Instance.TruckPointPrefab, transform).transform;
				((Object)val2).name = "TruckDeliveryMusic";
				((Object)val).name = "Ropes";
				((Object)transform2).name = "TruckPoint";
				__instance.ropes = val.GetComponentsInChildren<LineRenderer>(true);
				__instance.deliverVehiclePoint = transform2;
				Transform[] array = (Transform[])(object)new Transform[transform2.childCount];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = transform2.GetChild(i);
				}
				__instance.ropeDestinations = array;
				__instance.shipAnimator.runtimeAnimatorController = CompanyCruiserFixPlugin.Instance.ItemShipController;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal static class Patch_StartOfRound
	{
		private static bool s_IsAudioMixerFixed;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void FixAudioMixers(StartOfRound __instance)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (s_IsAudioMixerFixed)
			{
				return;
			}
			AudioMixerGroup outputAudioMixerGroup = __instance.shipAmbianceAudio.outputAudioMixerGroup.audioMixer.FindMatchingGroups("Master")[0];
			try
			{
				List<AudioSource> list = default(List<AudioSource>);
				PooledObject<List<AudioSource>> val = CollectionPool<List<AudioSource>, AudioSource>.Get(ref list);
				try
				{
					CompanyCruiserFixPlugin.Instance.TruckDeliveryMusicPrefab.GetComponentsInChildren<AudioSource>(true, list);
					foreach (AudioSource item in list)
					{
						item.outputAudioMixerGroup = outputAudioMixerGroup;
					}
					s_IsAudioMixerFixed = true;
				}
				finally
				{
					((IDisposable)val).Dispose();
				}
			}
			catch (Exception ex)
			{
				CompanyCruiserFixPlugin.Instance.Logger.LogError((object)ex);
			}
		}
	}
}