Decompiled source of Biggest Bird v1.0.3

BiggestBirdPlugin.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BiggestBirdMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Moddy")]
[assembly: AssemblyProduct("BiggestBirdMod")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BiggestBirdMod
{
	[BepInPlugin("com.moddy.biggestbirdmod", "BiggestBirdMod", "1.0.0")]
	internal class BiggestBirdPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.moddy.biggestbirdmod";

		public const string PluginName = "BiggestBirdMod";

		public const string PluginVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("com.moddy.biggestbirdmod");

		public static AudioClip birdClip;

		public static ConfigEntry<int> configBigChance { get; private set; }

		public static ConfigEntry<int> configFeatherFactor { get; private set; }

		public static ConfigEntry<float> configBigDistance { get; private set; }

		private void Awake()
		{
			configBigChance = ((BaseUnityPlugin)this).Config.Bind<int>("Biggest Bird", "Chance", 5, "1-100% chance of a bird becoming The Biggest Bird.");
			configFeatherFactor = ((BaseUnityPlugin)this).Config.Bind<int>("Biggest Bird", "Feather Multiplication Factor", 6, "How many times the feathers are multiplied in the drop table for The Biggest Bird.");
			configBigDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Biggest Bird", "Audio Distance", 850f, "The audio distance of The Biggest Bird music.");
			AssetBundle val = Utils.LoadAssetBundle("biggestbirdassets", Assembly.GetExecutingAssembly());
			if ((Object)(object)val != (Object)null)
			{
				birdClip = val.LoadAsset<AudioClip>("bird");
				harmony.PatchAll();
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogFatal((object)"Error loading assetbundle");
			}
			val.Unload(false);
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
			birdClip.UnloadAudioData();
		}
	}
	internal class Utils
	{
		public static AssetBundle LoadAssetBundle(string bundleName, Assembly resourceAssembly)
		{
			if (resourceAssembly == null)
			{
				throw new ArgumentNullException("Parameter resourceAssembly can not be null.");
			}
			string text = null;
			try
			{
				text = resourceAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(bundleName));
			}
			catch (Exception)
			{
			}
			if (text == null)
			{
				return null;
			}
			using Stream stream = resourceAssembly.GetManifestResourceStream(text);
			return AssetBundle.LoadFromStream(stream);
		}
	}
}
namespace BiggestBirdMod.Patches
{
	[HarmonyPatch(typeof(RandomFlyingBird), "Awake")]
	public class BirdStartPatch
	{
		private static void Prefix(RandomFlyingBird __instance)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			Random random = new Random();
			if (random.Next(0, 101) <= BiggestBirdPlugin.configBigChance.Value)
			{
				AudioSource val = ((Component)__instance).gameObject.AddComponent<AudioSource>();
				val.clip = BiggestBirdPlugin.birdClip;
				val.loop = true;
				val.maxDistance = BiggestBirdPlugin.configBigDistance.Value;
				val.volume = 1f;
				val.spatialBlend = 1f;
				val.spatialize = true;
				val.spatializePostEffects = true;
				val.Play();
				Vector3 localScale = Vector3.one * 10f;
				((Component)__instance).transform.localScale = localScale;
				DropOnDestroyed component = ((Component)__instance).gameObject.GetComponent<DropOnDestroyed>();
				component.m_dropWhenDestroyed.m_dropMax = BiggestBirdPlugin.configFeatherFactor.Value;
				component.m_dropWhenDestroyed.m_dropMin = BiggestBirdPlugin.configFeatherFactor.Value;
			}
		}
	}
}