Decompiled source of FuturamaItems v2.1.0

plugins/FuturamaItems/FuturamaItems.dll

Decompiled 6 months 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.Logging;
using FuturamaItems.Modules;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Audio;

[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("FuturamaItems")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A collection of items from Futurama")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+f1a48ee6c50ac11f233aaf85fa9aecc516ed8737")]
[assembly: AssemblyProduct("FuturamaItems")]
[assembly: AssemblyTitle("FuturamaItems")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.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 FuturamaItems
{
	[BepInPlugin("csalex.futuramaItems", "Futurama Items", "2.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class FuturamaItemModBase : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "csalex.futuramaItems";

		private const string PLUGIN_NAME = "Futurama Items";

		private const string PLUGIN_VERSION = "2.1.0";

		public static FuturamaItemModBase Instance;

		internal ManualLogSource mls = Logger.CreateLogSource("csalex.futuramaItems");

		internal AssetBundle futuramaBundle;

		internal Item bender;

		internal BenderUtilities benderUtilities;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls.LogInfo((object)"Plugin csalex.futuramaItems is loaded!");
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "benderbundle");
			futuramaBundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)futuramaBundle == (Object)null)
			{
				mls.LogError((object)"Failed to load custom assets.");
				return;
			}
			benderUtilities = new BenderUtilities();
			benderUtilities.SetupBenderItem();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "csalex.futuramaItems");
			mls.LogInfo((object)"Patched Futurama Items Mod");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FuturamaItems";

		public const string PLUGIN_NAME = "FuturamaItems";

		public const string PLUGIN_VERSION = "2.0.0";
	}
}
namespace FuturamaItems.Patches
{
	[HarmonyPatch(typeof(BoomboxItem))]
	internal class BoomBoxItemPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Start_Patch(BoomboxItem __instance)
		{
			AudioClip val = FuturamaItemModBase.Instance.futuramaBundle.LoadAsset<AudioClip>("Assets/FuturamaItems/futuramatheme_chopped_and_chewed.mp3");
			AudioClip val2 = FuturamaItemModBase.Instance.futuramaBundle.LoadAsset<AudioClip>("Assets/FuturamaItems/robothell.mp3");
			AudioClip val3 = FuturamaItemModBase.Instance.futuramaBundle.LoadAsset<AudioClip>("Assets/FuturamaItems/hewantsabrain.mp3");
			AudioClip[] musicAudios = __instance.musicAudios;
			AudioClip[] array = (AudioClip[])(object)new AudioClip[3] { val, val2, val3 };
			__instance.musicAudios = musicAudios.Concat(array).ToArray();
			FuturamaItemModBase.Instance.mls.LogInfo((object)$"Patched {__instance} with {array.Length} new music tracks!");
		}
	}
}
namespace FuturamaItems.Modules
{
	public class BenderUtilities
	{
		public static BenderUtilities Instance;

		public BenderUtilities()
		{
			if (Instance == null)
			{
				Instance = this;
			}
			Init();
		}

		private static void Init()
		{
			Instance.LoadBenderAsset(ref FuturamaItemModBase.Instance.bender, ref FuturamaItemModBase.Instance.futuramaBundle);
		}

		private void LoadBenderAsset(ref Item bender, ref AssetBundle futuramaBundle)
		{
			bender = futuramaBundle.LoadAsset<Item>("Assets/FuturamaItems/BenderFigurine.asset");
		}

		private void UpdateBenderIcon(ref Item bender, ref AssetBundle futuramaBundle)
		{
			if ((Object)(object)bender.itemIcon == (Object)null)
			{
				FuturamaItemModBase.Instance.mls.LogError((object)"For some reason Bender doesn't have any icon attached");
				Sprite itemIcon = futuramaBundle.LoadAsset<Sprite>("Assets/FuturamaItems/benderbyjordandiazandres.png");
				bender.itemIcon = itemIcon;
			}
		}

		private void UpdateBenderSFX(ref Item bender, ref AssetBundle futuramaBundle)
		{
			if ((Object)(object)bender.dropSFX == (Object)null || (Object)(object)bender.grabSFX == (Object)null || (Object)(object)bender.pocketSFX == (Object)null || (Object)(object)bender.throwSFX == (Object)null)
			{
				FuturamaItemModBase.Instance.mls.LogError((object)"For some reason Bender doesn't have any sound effects attached");
				AudioClip grabSFX = futuramaBundle.LoadAsset<AudioClip>("Assets/FuturamaItems/bender_heywhatsthis.mp3");
				AudioClip pocketSFX = futuramaBundle.LoadAsset<AudioClip>("Assets/FuturamaItems/bender_youstupid.mp3");
				AudioClip dropSFX = futuramaBundle.LoadAsset<AudioClip>("Assets/FuturamaItems/bender_heyfleshies.mp3");
				AudioClip throwSFX = futuramaBundle.LoadAsset<AudioClip>("Assets/FuturamaItems/bender_doaflip.mp3");
				bender.dropSFX = dropSFX;
				bender.grabSFX = grabSFX;
				bender.pocketSFX = pocketSFX;
				bender.throwSFX = throwSFX;
			}
		}

		private void UpdateBenderComponents(ref Item bender, ref AssetBundle futuramaBundle)
		{
			if ((Object)(object)bender.spawnPrefab.GetComponent<PhysicsProp>() == (Object)null)
			{
				FuturamaItemModBase.Instance.mls.LogError((object)"There's no physics prop on this for some reason");
				bender.spawnPrefab.AddComponent<PhysicsProp>();
				PhysicsProp component = bender.spawnPrefab.GetComponent<PhysicsProp>();
				((GrabbableObject)component).grabbableToEnemies = true;
				((GrabbableObject)component).grabbable = true;
				((GrabbableObject)component).itemProperties = bender;
			}
			if ((Object)(object)bender.spawnPrefab.GetComponent<GrabbableObject>() == (Object)null)
			{
				FuturamaItemModBase.Instance.mls.LogError((object)"There's nothing grabbable on this for some reason");
			}
			if ((Object)(object)bender.spawnPrefab.GetComponent<AudioSource>() == (Object)null)
			{
				FuturamaItemModBase.Instance.mls.LogError((object)"We don't have an audio source on this?");
				bender.spawnPrefab.AddComponent<AudioSource>();
				AudioSource component2 = bender.spawnPrefab.GetComponent<AudioSource>();
				if ((Object)(object)component2.outputAudioMixerGroup == (Object)null)
				{
					FuturamaItemModBase.Instance.mls.LogError((object)"We don't have an audio mixer group on this either?");
					AudioMixerGroup outputAudioMixerGroup = futuramaBundle.LoadAsset<AudioMixerGroup>("Assets/FuturamaItems/DiageticMixer.mixer");
					component2.outputAudioMixerGroup = outputAudioMixerGroup;
					component2.playOnAwake = false;
					component2.volume = 1f;
					component2.minDistance = 1f;
					component2.maxDistance = 25f;
				}
			}
			if ((Object)(object)bender.spawnPrefab.GetComponentInChildren<ScanNodeProperties>() == (Object)null)
			{
				FuturamaItemModBase.Instance.mls.LogError((object)"For some reason there is no scan node properties script on this");
				bender.spawnPrefab.AddComponent<ScanNodeProperties>();
				ScanNodeProperties component3 = bender.spawnPrefab.GetComponent<ScanNodeProperties>();
				component3.maxRange = 13;
				component3.minRange = 1;
				component3.scrapValue = 50;
				component3.headerText = "Bender Figurine";
				component3.subText = "Value: ";
				component3.creatureScanID = -1;
				component3.nodeType = 2;
				component3.requiresLineOfSight = true;
			}
		}

		private void RegisterItem(ref Item bender)
		{
			NetworkPrefabs.RegisterNetworkPrefab(bender.spawnPrefab);
			Utilities.FixMixerGroups(bender.spawnPrefab);
			Items.RegisterScrap(bender, 300, (LevelTypes)(-1));
			FuturamaItemModBase.Instance.mls.LogInfo((object)$"Patched {FuturamaItemModBase.Instance} with additional item: Bender Figurine");
		}

		public void SetupBenderItem()
		{
			LoadBenderAsset(ref FuturamaItemModBase.Instance.bender, ref FuturamaItemModBase.Instance.futuramaBundle);
			UpdateBenderIcon(ref FuturamaItemModBase.Instance.bender, ref FuturamaItemModBase.Instance.futuramaBundle);
			UpdateBenderSFX(ref FuturamaItemModBase.Instance.bender, ref FuturamaItemModBase.Instance.futuramaBundle);
			UpdateBenderComponents(ref FuturamaItemModBase.Instance.bender, ref FuturamaItemModBase.Instance.futuramaBundle);
			RegisterItem(ref FuturamaItemModBase.Instance.bender);
		}
	}
}