Decompiled source of Easter Egg v1.0.0

RepoEgg.dll

Decompiled 12 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RepoEgg")]
[assembly: AssemblyTitle("RepoEgg")]
[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.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;
		}
	}
}
public class EggSqueakItem : MonoBehaviour
{
	private PhotonView photonView;

	private AudioSource audioSource;

	private ParticleScriptExplosion particleScriptExplosion;

	private AudioClip generatedSqueak;

	[Header("Audio Settings")]
	public AudioClip[] squeakClips;

	public AudioClip explosionSound;

	[Header("Visual Settings")]
	public GameObject confettiEffect;

	[Header("Physics Settings")]
	[Tooltip("How hard it must hit to count as a drop (Default: 3.0)")]
	public float squeakThreshold = 3f;

	[Tooltip("Percent chance to trigger Event (Explode or Loot) on drop (0-100).")]
	public float explodeChance = 5f;

	[Header("Loot Settings")]
	public int minLootItems = 1;

	public int maxLootItems = 3;

	private void Awake()
	{
		photonView = ((Component)this).GetComponent<PhotonView>();
		audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
		audioSource.spatialBlend = 1f;
		audioSource.minDistance = 1f;
		audioSource.maxDistance = 15f;
		if (squeakClips == null || squeakClips.Length == 0)
		{
			GenerateSqueakSound();
		}
		particleScriptExplosion = ((Component)this).gameObject.AddComponent<ParticleScriptExplosion>();
		ExplosionPreset[] source = Resources.FindObjectsOfTypeAll<ExplosionPreset>();
		ExplosionPreset val = ((IEnumerable<ExplosionPreset>)source).FirstOrDefault((Func<ExplosionPreset, bool>)((ExplosionPreset p) => ((Object)p).name.Contains("Grenade"))) ?? source.FirstOrDefault();
		if ((Object)(object)val != (Object)null)
		{
			particleScriptExplosion.explosionPreset = val;
		}
	}

	private void OnCollisionEnter(Collision collision)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		Vector3 relativeVelocity = collision.relativeVelocity;
		if (((Vector3)(ref relativeVelocity)).magnitude > squeakThreshold)
		{
			PlaySqueak();
			TryTriggerEvent();
		}
	}

	private void PlaySqueak()
	{
		if ((Object)(object)audioSource != (Object)null)
		{
			audioSource.pitch = Random.Range(0.85f, 1.25f);
			AudioClip val = null;
			val = ((squeakClips == null || squeakClips.Length == 0) ? generatedSqueak : squeakClips[Random.Range(0, squeakClips.Length)]);
			if ((Object)(object)val != (Object)null)
			{
				audioSource.PlayOneShot(val);
			}
		}
	}

	private void TryTriggerEvent()
	{
		if (!PhotonNetwork.IsMasterClient && PhotonNetwork.IsConnected)
		{
			return;
		}
		float num = Random.Range(0f, 100f);
		if (!(num < explodeChance))
		{
			return;
		}
		if (Random.value < 0.5f)
		{
			if (PhotonNetwork.IsConnected)
			{
				photonView.RPC("ExplodeRPC", (RpcTarget)0, Array.Empty<object>());
			}
			else
			{
				ExplodeRPC();
			}
			return;
		}
		SpawnLoot();
		if (PhotonNetwork.IsConnected)
		{
			photonView.RPC("ConfettiRPC", (RpcTarget)0, Array.Empty<object>());
		}
		else
		{
			ConfettiRPC();
		}
		PhotonNetwork.Destroy(((Component)this).gameObject);
	}

	[PunRPC]
	public void ExplodeRPC()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)explosionSound != (Object)null)
		{
			AudioSource.PlayClipAtPoint(explosionSound, ((Component)this).transform.position);
		}
		if ((Object)(object)confettiEffect != (Object)null)
		{
			Object.Instantiate<GameObject>(confettiEffect, ((Component)this).transform.position, Quaternion.identity);
		}
		if ((Object)(object)particleScriptExplosion != (Object)null)
		{
			particleScriptExplosion.Spawn(((Component)this).transform.position, 1.2f, 75, 160, 4f, false, false, 1f);
		}
		if ((PhotonNetwork.IsMasterClient || !PhotonNetwork.IsConnected) && (Object)(object)((Component)this).gameObject != (Object)null)
		{
			PhotonNetwork.Destroy(((Component)this).gameObject);
		}
	}

	[PunRPC]
	public void ConfettiRPC()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)explosionSound != (Object)null)
		{
			AudioSource.PlayClipAtPoint(explosionSound, ((Component)this).transform.position);
		}
		if ((Object)(object)confettiEffect != (Object)null)
		{
			Object.Instantiate<GameObject>(confettiEffect, ((Component)this).transform.position, Quaternion.identity);
		}
	}

	private void SpawnLoot()
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			List<Item> list = BuildItemPool();
			List<PrefabRef> list2 = BuildValuablePool();
			if (list.Count == 0 && list2.Count == 0)
			{
				return;
			}
			int num = Random.Range(minLootItems, maxLootItems + 1);
			Vector3 center = ((Component)this).transform.position + Vector3.up * 0.5f;
			for (int i = 0; i < num; i++)
			{
				bool flag = list.Count > 0;
				bool flag2 = list2.Count > 0;
				if (flag && flag2)
				{
					if (Random.value < 0.5f)
					{
						SpawnSingleItem(list[Random.Range(0, list.Count)], center);
					}
					else
					{
						SpawnSingleValuable(list2[Random.Range(0, list2.Count)], center);
					}
				}
				else if (flag)
				{
					SpawnSingleItem(list[Random.Range(0, list.Count)], center);
				}
				else if (flag2)
				{
					SpawnSingleValuable(list2[Random.Range(0, list2.Count)], center);
				}
			}
		}
		catch
		{
		}
	}

	private void SpawnSingleItem(Item item, Vector3 center)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)item == (Object)null) && item.prefab != null && item.prefab.IsValid())
		{
			Vector3 val = center + Random.insideUnitSphere * 0.4f;
			string resourcePath = item.prefab.ResourcePath;
			if (PhotonNetwork.IsConnected)
			{
				PhotonNetwork.Instantiate(resourcePath, val, Quaternion.identity, (byte)0, (object[])null);
			}
			else
			{
				Object.Instantiate<GameObject>(item.prefab.Prefab, val, Quaternion.identity);
			}
		}
	}

	private void SpawnSingleValuable(PrefabRef v, Vector3 center)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		if (v != null && v.IsValid())
		{
			Vector3 val = center + Random.insideUnitSphere * 0.4f;
			string resourcePath = v.ResourcePath;
			if (PhotonNetwork.IsConnected)
			{
				PhotonNetwork.Instantiate(resourcePath, val, Quaternion.identity, (byte)0, (object[])null);
			}
			else
			{
				Object.Instantiate<GameObject>(v.Prefab, val, Quaternion.identity);
			}
		}
	}

	private List<Item> BuildItemPool()
	{
		try
		{
			List<Item> list = new List<Item>();
			ShopManager instance = ShopManager.instance;
			if ((Object)(object)instance != (Object)null)
			{
				if (instance.potentialItems != null)
				{
					list.AddRange(instance.potentialItems);
				}
				if (instance.potentialItemConsumables != null)
				{
					list.AddRange(instance.potentialItemConsumables);
				}
				if (instance.potentialItemUpgrades != null)
				{
					list.AddRange(instance.potentialItemUpgrades);
				}
			}
			if (list.Count == 0 && (Object)(object)StatsManager.instance != (Object)null && StatsManager.instance.itemDictionary != null)
			{
				list.AddRange(StatsManager.instance.itemDictionary.Values);
			}
			return list.Where((Item i) => (Object)(object)i != (Object)null && i.prefab != null && i.prefab.IsValid()).Distinct().ToList();
		}
		catch
		{
			return new List<Item>();
		}
	}

	private List<PrefabRef> BuildValuablePool()
	{
		try
		{
			List<PrefabRef> list = new List<PrefabRef>();
			LevelGenerator instance = LevelGenerator.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.Level == (Object)null || instance.Level.ValuablePresets == null)
			{
				return list;
			}
			foreach (LevelValuables valuablePreset in instance.Level.ValuablePresets)
			{
				if (!((Object)(object)valuablePreset == (Object)null))
				{
					if (valuablePreset.tiny != null)
					{
						list.AddRange(valuablePreset.tiny);
					}
					if (valuablePreset.small != null)
					{
						list.AddRange(valuablePreset.small);
					}
					if (valuablePreset.medium != null)
					{
						list.AddRange(valuablePreset.medium);
					}
					if (valuablePreset.big != null)
					{
						list.AddRange(valuablePreset.big);
					}
					if (valuablePreset.wide != null)
					{
						list.AddRange(valuablePreset.wide);
					}
					if (valuablePreset.tall != null)
					{
						list.AddRange(valuablePreset.tall);
					}
					if (valuablePreset.veryTall != null)
					{
						list.AddRange(valuablePreset.veryTall);
					}
				}
			}
			return list.Where((PrefabRef v) => v != null && v.IsValid() && ((Object)(object)v.Prefab != (Object)null || !string.IsNullOrEmpty(v.ResourcePath))).Distinct().ToList();
		}
		catch
		{
			return new List<PrefabRef>();
		}
	}

	private void GenerateSqueakSound()
	{
		int num = 44100;
		float num2 = 1200f;
		float num3 = 0.1f;
		int num4 = (int)((float)num * num3);
		float[] array = new float[num4];
		for (int i = 0; i < num4; i++)
		{
			float num5 = (float)i / (float)num;
			float num6 = num2 - num5 * 4000f;
			if (num6 < 100f)
			{
				num6 = 100f;
			}
			array[i] = Mathf.Sin(MathF.PI * 2f * num6 * num5);
			if ((float)i < (float)num4 * 0.2f)
			{
				array[i] *= (float)i / ((float)num4 * 0.2f);
			}
			else if ((float)i > (float)num4 * 0.5f)
			{
				array[i] *= 1f - ((float)i - (float)num4 * 0.5f) / ((float)num4 * 0.5f);
			}
		}
		generatedSqueak = AudioClip.Create("ProceduralSqueak", num4, 1, num, false);
		generatedSqueak.SetData(array, 0);
	}
}
namespace EggSqueakMod
{
	[BepInPlugin("user.egg.squeak", "Egg Squeak Mod", "1.0.0")]
	public class EggSqueakModPlugin : BaseUnityPlugin
	{
		public static EggSqueakModPlugin Instance;

		private void Awake()
		{
			Instance = this;
			Harmony.CreateAndPatchAll(typeof(EggSqueakModPlugin), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Egg Squeak Mod Loaded!");
		}

		[HarmonyPatch(typeof(ValuableEgg), "Start")]
		[HarmonyPostfix]
		private static void AddSqueakToEgg(ValuableEgg __instance)
		{
			if ((Object)(object)((Component)__instance).gameObject.GetComponent<EggSqueakItem>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<EggSqueakItem>();
			}
		}
	}
}