Decompiled source of TikkaMasala v1.0.0

BepInEx/plugins/TikkaMasala/TikkaMasala.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using LethalLib.Modules;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace TikkaMasala;

[BepInPlugin("tikkamasala.mod", "TikkaMasala", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "tikkamasala.mod";

	public const string NAME = "TikkaMasala";

	public const string VERSION = "1.0.0";

	internal static ManualLogSource Log;

	internal static AudioClip VoreClip;

	internal static AudioClip VomitClip;

	internal static Item TikkaItem;

	internal static ConfigEntry<int> Price;

	internal static ConfigEntry<int> VoreRepeats;

	internal static ConfigEntry<float> VoreInterval;

	internal static ConfigEntry<float> Volume;

	internal static ConfigEntry<float> LaunchForce;

	internal static ConfigEntry<float> LaunchUpward;

	internal static ConfigEntry<int> PlayerDamage;

	internal static ConfigEntry<int> SelfDamage;

	internal static ConfigEntry<bool> KillEnemies;

	internal static ConfigEntry<float> Range;

	internal static ConfigEntry<float> ConeAngle;

	internal static ConfigEntry<float> SprayDuration;

	internal static ConfigEntry<float> SplatLifetime;

	internal static ConfigEntry<int> MaxSplats;

	internal static ConfigEntry<Vector3> HoldPosition;

	internal static ConfigEntry<Vector3> HoldRotation;

	private void Awake()
	{
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Price = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Price", 10, "Store price in credits. Must match on all players (host value is what counts for buying).");
		VoreRepeats = ((BaseUnityPlugin)this).Config.Bind<int>("Eating", "SoundRepeats", 3, "How many times the eating sound plays before the vomit.");
		VoreInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Eating", "SoundInterval", 0.35f, "Seconds between each eating sound.");
		Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Eating", "Volume", 1f, "Volume of the mod's sounds (0-1).");
		LaunchForce = ((BaseUnityPlugin)this).Config.Bind<float>("Vomit", "LaunchForce", 80f, "How hard the eater is thrown backwards. Landmines are roughly in the tens; raise for more violence.");
		LaunchUpward = ((BaseUnityPlugin)this).Config.Bind<float>("Vomit", "LaunchUpward", 0.35f, "Upward tilt added to the launch direction (0 = straight back).");
		PlayerDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Vomit", "PlayerDamage", 25, "Damage dealt to other players hit by the vomit.");
		SelfDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Vomit", "SelfDamage", 0, "Damage dealt to the eater (on top of any fall damage from the launch).");
		KillEnemies = ((BaseUnityPlugin)this).Config.Bind<bool>("Vomit", "KillEnemies", true, "Vomit instantly kills any enemy it hits (unkillable ones are removed).");
		Range = ((BaseUnityPlugin)this).Config.Bind<float>("Vomit", "Range", 7f, "Reach of the vomit in metres.");
		ConeAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Vomit", "ConeAngle", 30f, "Half-angle of the vomit cone in degrees.");
		SprayDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Vomit", "SprayDuration", 1.6f, "How long the stream lasts in seconds.");
		SplatLifetime = ((BaseUnityPlugin)this).Config.Bind<float>("Vomit", "SplatLifetime", 180f, "Seconds a floor splat stays before disappearing.");
		MaxSplats = ((BaseUnityPlugin)this).Config.Bind<int>("Vomit", "MaxSplats", 250, "Maximum splats kept at once (oldest are removed first).");
		HoldPosition = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Holding", "PositionOffset", new Vector3(0.05f, 0.1f, -0.05f), "Bowl position in the hand. Tweak if it sits oddly.");
		HoldRotation = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Holding", "RotationOffset", new Vector3(-90f, 0f, 0f), "Bowl rotation in the hand. Tweak if it sits oddly.");
		VoreClip = WavLoader.LoadEmbedded("vore.wav", "TikkaVore");
		VomitClip = WavLoader.LoadEmbedded("vomit.wav", "TikkaVomit");
		CreateItem();
		Log.LogInfo((object)"TikkaMasala 1.0.0 loaded. Bon appetit.");
	}

	private void CreateItem()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = NetworkPrefabs.CreateNetworkPrefab("TikkaMasalaItem");
		val.layer = 6;
		val.tag = "PhysicsProp";
		NetworkObject component = val.GetComponent<NetworkObject>();
		component.AutoObjectParentSync = false;
		component.DontDestroyWithOwner = true;
		BoxCollider obj = val.AddComponent<BoxCollider>();
		obj.center = new Vector3(0f, 0.02f, 0f);
		obj.size = new Vector3(0.26f, 0.12f, 0.26f);
		AudioSource obj2 = val.AddComponent<AudioSource>();
		obj2.playOnAwake = false;
		obj2.spatialBlend = 1f;
		obj2.rolloffMode = (AudioRolloffMode)1;
		obj2.minDistance = 1f;
		obj2.maxDistance = 15f;
		Item val2 = ScriptableObject.CreateInstance<Item>();
		((Object)val2).name = "TikkaMasala";
		val2.itemName = "Tikka Masala";
		val2.itemId = 694201;
		val2.spawnPrefab = val;
		val2.itemIcon = MakeIcon();
		val2.weight = 1f;
		val2.creditsWorth = Mathf.Max(0, Price.Value);
		val2.highestSalePercentage = 80;
		val2.isScrap = false;
		val2.twoHanded = false;
		val2.requiresBattery = false;
		val2.isConductiveMetal = false;
		val2.holdButtonUse = false;
		val2.syncUseFunction = true;
		val2.syncGrabFunction = false;
		val2.syncDiscardFunction = false;
		val2.syncInteractLRFunction = false;
		val2.saveItemVariable = false;
		val2.itemSpawnsOnGround = true;
		val2.canBeGrabbedBeforeGameStart = true;
		val2.allowDroppingAheadOfPlayer = true;
		val2.grabAnim = "";
		val2.useAnim = "";
		val2.pocketAnim = "";
		val2.throwAnim = "";
		val2.toolTips = new string[1] { "Eat tikka masala : [LMB]" };
		val2.positionOffset = HoldPosition.Value;
		val2.rotationOffset = HoldRotation.Value;
		val2.restingRotation = Vector3.zero;
		val2.verticalOffset = 0.05f;
		val2.spawnPositionTypes = new List<ItemGroup>();
		val2.meshVariants = (Mesh[])(object)new Mesh[0];
		val2.materialVariants = (Material[])(object)new Material[0];
		TikkaItem = val2;
		TikkaMasalaItem tikkaMasalaItem = val.AddComponent<TikkaMasalaItem>();
		((GrabbableObject)tikkaMasalaItem).itemProperties = val2;
		((GrabbableObject)tikkaMasalaItem).grabbable = true;
		((GrabbableObject)tikkaMasalaItem).grabbableToEnemies = true;
		GameObject val3 = new GameObject("ScanNode");
		val3.transform.SetParent(val.transform, false);
		val3.layer = 22;
		val3.AddComponent<BoxCollider>().size = new Vector3(0.3f, 0.3f, 0.3f);
		ScanNodeProperties obj3 = val3.AddComponent<ScanNodeProperties>();
		obj3.headerText = "Tikka Masala";
		obj3.subText = "Smells dangerous";
		obj3.nodeType = 0;
		obj3.minRange = 1;
		obj3.maxRange = 13;
		obj3.requiresLineOfSight = true;
		obj3.creatureScanID = -1;
		Items.RegisterShopItem(val2, (TerminalNode)null, (TerminalNode)null, (TerminalNode)null, Mathf.Max(0, Price.Value));
	}

	private static Sprite MakeIcon()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
		((Object)val).name = "TikkaMasalaIcon";
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
		Color val3 = default(Color);
		((Color)(ref val3))..ctor(0.95f, 0.95f, 0.92f, 1f);
		Color val4 = default(Color);
		((Color)(ref val4))..ctor(0.88f, 0.36f, 0.08f, 1f);
		Color val5 = default(Color);
		((Color)(ref val5))..ctor(0.8f, 0.55f, 0.28f, 1f);
		Vector2 val6 = default(Vector2);
		((Vector2)(ref val6))..ctor(32f, 32f);
		Vector2[] array = (Vector2[])(object)new Vector2[5]
		{
			new Vector2(24f, 38f),
			new Vector2(40f, 40f),
			new Vector2(33f, 26f),
			new Vector2(22f, 26f),
			new Vector2(42f, 28f)
		};
		Vector2 val7 = default(Vector2);
		for (int i = 0; i < 64; i++)
		{
			for (int j = 0; j < 64; j++)
			{
				((Vector2)(ref val7))..ctor((float)j + 0.5f, (float)i + 0.5f);
				float num = Vector2.Distance(val7, val6);
				Color val8 = val2;
				if (num < 29f)
				{
					val8 = val3;
				}
				if (num < 23f)
				{
					val8 = val4;
				}
				for (int k = 0; k < array.Length; k++)
				{
					if (Vector2.Distance(val7, array[k]) < 4.2f)
					{
						val8 = val5;
					}
				}
				val.SetPixel(j, i, val8);
			}
		}
		val.Apply();
		Object.DontDestroyOnLoad((Object)(object)val);
		Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
		((Object)obj).name = "TikkaMasalaIcon";
		Object.DontDestroyOnLoad((Object)(object)obj);
		return obj;
	}
}
internal static class WavLoader
{
	internal static AudioClip LoadEmbedded(string resourceName, string clipName)
	{
		try
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				throw new FileNotFoundException("Embedded resource missing: " + resourceName);
			}
			byte[] array = new byte[stream.Length];
			int num;
			for (int i = 0; i < array.Length; i += num)
			{
				num = stream.Read(array, i, array.Length - i);
				if (num <= 0)
				{
					break;
				}
			}
			return Parse(array, clipName);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Could not load sound " + resourceName + ": " + ex));
			return null;
		}
	}

	private static AudioClip Parse(byte[] b, string clipName)
	{
		int num = 1;
		int num2 = 44100;
		int num3 = 16;
		int num4 = -1;
		int num5 = 0;
		int num6 = 12;
		while (num6 + 8 <= b.Length)
		{
			string text = Encoding.ASCII.GetString(b, num6, 4);
			int num7 = BitConverter.ToInt32(b, num6 + 4);
			int num8 = num6 + 8;
			if (text == "fmt ")
			{
				num = BitConverter.ToInt16(b, num8 + 2);
				num2 = BitConverter.ToInt32(b, num8 + 4);
				num3 = BitConverter.ToInt16(b, num8 + 14);
			}
			else if (text == "data")
			{
				num4 = num8;
				num5 = Math.Min(num7, b.Length - num8);
				break;
			}
			num6 = num8 + num7 + (num7 & 1);
		}
		if (num4 < 0 || num3 != 16)
		{
			throw new InvalidDataException("Expected 16-bit PCM WAV");
		}
		int num9 = num5 / 2;
		float[] array = new float[num9];
		for (int i = 0; i < num9; i++)
		{
			array[i] = (float)BitConverter.ToInt16(b, num4 + i * 2) / 32768f;
		}
		AudioClip obj = AudioClip.Create(clipName, num9 / num, num, num2, false);
		obj.SetData(array, 0);
		Object.DontDestroyOnLoad((Object)(object)obj);
		return obj;
	}
}
public class TikkaMasalaItem : GrabbableObject
{
	private bool eaten;

	private bool visualBuilt;

	public override void Start()
	{
		BuildVisual();
		BorrowVanillaSounds();
		((GrabbableObject)this).Start();
	}

	public override void ItemActivate(bool used, bool buttonDown = true)
	{
		((GrabbableObject)this).ItemActivate(used, buttonDown);
		if (!eaten && !((Object)(object)base.playerHeldBy == (Object)null))
		{
			eaten = true;
			VomitRunner.Begin(base.playerHeldBy, this);
		}
	}

	internal void HideBowl()
	{
		try
		{
			((GrabbableObject)this).EnableItemMeshes(false);
		}
		catch (Exception)
		{
		}
	}

	private void BuildVisual()
	{
		//IL_0015: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		if (visualBuilt)
		{
			return;
		}
		visualBuilt = true;
		try
		{
			Transform transform = new GameObject("Model").transform;
			transform.SetParent(((Component)this).transform, false);
			Part(transform, (PrimitiveType)2, new Vector3(0f, 0f, 0f), new Vector3(0.24f, 0.035f, 0.24f), Quaternion.identity, Mats.Bowl);
			Part(transform, (PrimitiveType)2, new Vector3(0f, -0.03f, 0f), new Vector3(0.14f, 0.02f, 0.14f), Quaternion.identity, Mats.Bowl);
			Part(transform, (PrimitiveType)0, new Vector3(0f, 0.03f, 0f), new Vector3(0.215f, 0.06f, 0.215f), Quaternion.identity, Mats.Sauce);
			Vector3[] array = (Vector3[])(object)new Vector3[5]
			{
				new Vector3(0.045f, 0.058f, 0.02f),
				new Vector3(-0.04f, 0.056f, 0.045f),
				new Vector3(-0.03f, 0.058f, -0.045f),
				new Vector3(0.05f, 0.054f, -0.05f),
				new Vector3(0f, 0.062f, 0f)
			};
			for (int i = 0; i < array.Length; i++)
			{
				Part(transform, (PrimitiveType)3, array[i], Vector3.one * 0.042f, Quaternion.Euler(20f * (float)i, 47f * (float)i, 13f * (float)i), Mats.Chunk);
			}
			Part(transform, (PrimitiveType)0, new Vector3(0.015f, 0.064f, 0.05f), new Vector3(0.03f, 0.006f, 0.018f), Quaternion.Euler(0f, 30f, 0f), Mats.Herb);
			Part(transform, (PrimitiveType)0, new Vector3(-0.055f, 0.06f, 0f), new Vector3(0.028f, 0.006f, 0.016f), Quaternion.Euler(0f, 110f, 0f), Mats.Herb);
			Part(transform, (PrimitiveType)0, new Vector3(0.02f, 0.064f, -0.03f), new Vector3(0.026f, 0.006f, 0.016f), Quaternion.Euler(0f, 200f, 0f), Mats.Herb);
			base.mainObjectRenderer = ((Component)transform).GetComponentInChildren<MeshRenderer>();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Failed to build tikka masala model: " + ex));
		}
	}

	private static void Part(Transform parent, PrimitiveType type, Vector3 pos, Vector3 scale, Quaternion rot, Material mat)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = GameObject.CreatePrimitive(type);
		Collider component = obj.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component);
		}
		obj.layer = 6;
		obj.transform.SetParent(parent, false);
		obj.transform.localPosition = pos;
		obj.transform.localRotation = rot;
		obj.transform.localScale = scale;
		((Renderer)obj.GetComponent<MeshRenderer>()).sharedMaterial = mat;
	}

	private void BorrowVanillaSounds()
	{
		try
		{
			Item itemProperties = base.itemProperties;
			if ((Object)(object)itemProperties == (Object)null || (Object)(object)itemProperties.grabSFX != (Object)null || (Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			foreach (Item items in StartOfRound.Instance.allItemsList.itemsList)
			{
				if (!((Object)(object)items == (Object)null) && !((Object)(object)items == (Object)(object)itemProperties) && !items.twoHanded && !((Object)(object)items.grabSFX == (Object)null) && !((Object)(object)items.dropSFX == (Object)null))
				{
					itemProperties.grabSFX = items.grabSFX;
					itemProperties.dropSFX = items.dropSFX;
					itemProperties.pocketSFX = items.pocketSFX;
					break;
				}
			}
		}
		catch (Exception)
		{
		}
	}
}
internal static class Mats
{
	private static Material bowl;

	private static Material sauce;

	private static Material chunk;

	private static Material herb;

	internal static Material Bowl
	{
		get
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)bowl != (Object)null))
			{
				return bowl = Make(new Color(0.93f, 0.93f, 0.9f), 0.7f);
			}
			return bowl;
		}
	}

	internal static Material Sauce
	{
		get
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)sauce != (Object)null))
			{
				return sauce = Make(new Color(0.86f, 0.33f, 0.06f), 0.75f);
			}
			return sauce;
		}
	}

	internal static Material Chunk
	{
		get
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)chunk != (Object)null))
			{
				return chunk = Make(new Color(0.78f, 0.5f, 0.24f), 0.4f);
			}
			return chunk;
		}
	}

	internal static Material Herb
	{
		get
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)herb != (Object)null))
			{
				return herb = Make(new Color(0.16f, 0.5f, 0.12f), 0.3f);
			}
			return herb;
		}
	}

	private static Material Make(Color color, float smoothness)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Expected O, but got Unknown
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected O, but got Unknown
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		Material val = null;
		Shader val2 = Shader.Find("HDRP/Lit");
		if ((Object)(object)val2 != (Object)null)
		{
			val = new Material(val2);
		}
		else
		{
			MeshRenderer val3 = Object.FindObjectOfType<MeshRenderer>();
			if ((Object)(object)val3 != (Object)null && (Object)(object)((Renderer)val3).sharedMaterial != (Object)null)
			{
				val = new Material(((Renderer)val3).sharedMaterial);
				if (val.HasProperty("_BaseColorMap"))
				{
					val.SetTexture("_BaseColorMap", (Texture)null);
				}
				if (val.HasProperty("_MainTex"))
				{
					val.SetTexture("_MainTex", (Texture)null);
				}
				if (val.HasProperty("_NormalMap"))
				{
					val.SetTexture("_NormalMap", (Texture)null);
				}
			}
			else
			{
				val = new Material(Shader.Find("Standard"));
			}
			Plugin.Log.LogWarning((object)"HDRP/Lit shader not found, using fallback material.");
		}
		((Object)val).name = "TikkaMasalaMat";
		if (val.HasProperty("_BaseColor"))
		{
			val.SetColor("_BaseColor", color);
		}
		if (val.HasProperty("_Color"))
		{
			val.SetColor("_Color", color);
		}
		if (val.HasProperty("_Smoothness"))
		{
			val.SetFloat("_Smoothness", smoothness);
		}
		if (val.HasProperty("_Metallic"))
		{
			val.SetFloat("_Metallic", 0f);
		}
		((Object)val).hideFlags = (HideFlags)32;
		return val;
	}
}
internal class VomitRunner : MonoBehaviour
{
	private static VomitRunner instance;

	private static readonly Queue<GameObject> splats = new Queue<GameObject>();

	internal static void Begin(PlayerControllerB player, TikkaMasalaItem item)
	{
		//IL_0012: 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_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		if ((Object)(object)instance == (Object)null)
		{
			GameObject val = new GameObject("TikkaMasalaRunner")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			instance = val.AddComponent<VomitRunner>();
		}
		((MonoBehaviour)instance).StartCoroutine(instance.Sequence(player, item));
	}

	private static bool Alive(PlayerControllerB p)
	{
		if ((Object)(object)p != (Object)null && (Object)(object)StartOfRound.Instance != (Object)null && p.isPlayerControlled)
		{
			return !p.isPlayerDead;
		}
		return false;
	}

	private IEnumerator Sequence(PlayerControllerB player, TikkaMasalaItem item)
	{
		PlayerControllerB local = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
		bool isEater = (Object)(object)player == (Object)(object)local;
		int repeats = Mathf.Clamp(Plugin.VoreRepeats.Value, 0, 20);
		float interval = Mathf.Max(0.05f, Plugin.VoreInterval.Value);
		for (int i = 0; i < repeats; i++)
		{
			if (!Alive(player))
			{
				yield break;
			}
			PlayOn(player, Plugin.VoreClip, 1f + 0.06f * (float)i);
			yield return (object)new WaitForSeconds(interval);
		}
		yield return (object)new WaitForSeconds(0.2f);
		if (!Alive(player))
		{
			yield break;
		}
		if ((Object)(object)item != (Object)null)
		{
			item.HideBowl();
		}
		PlayOn(player, Plugin.VomitClip, 1f);
		try
		{
			RoundManager.Instance.PlayAudibleNoise(((Component)player).transform.position, 30f, 0.9f, 0, false, 0);
		}
		catch (Exception)
		{
		}
		if (isEater)
		{
			Launch(player);
			ConsumeItem(player, item);
			if (Plugin.SelfDamage.Value > 0)
			{
				try
				{
					player.DamagePlayer(Plugin.SelfDamage.Value, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				}
				catch (Exception ex2)
				{
					Plugin.Log.LogError((object)ex2);
				}
			}
		}
		bool isHost = (Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.IsServer;
		bool localHit = false;
		HashSet<EnemyAI> killed = new HashSet<EnemyAI>();
		float duration = Mathf.Max(0.1f, Plugin.SprayDuration.Value);
		float elapsed = 0f;
		float toEmit = 0f;
		while (elapsed < duration && Alive(player))
		{
			Transform val = (((Object)(object)player.gameplayCamera != (Object)null) ? ((Component)player.gameplayCamera).transform : ((Component)player).transform);
			Vector3 forward = val.forward;
			Vector3 val2 = val.position + forward * 0.35f - val.up * 0.12f;
			float num = 1f - 0.6f * (elapsed / duration);
			toEmit += 70f * num * Time.deltaTime;
			while (toEmit >= 1f)
			{
				toEmit -= 1f;
				VomitBlob.Spawn(val2, forward, val);
			}
			if (!localHit && !isEater && Alive(local) && Plugin.PlayerDamage.Value > 0)
			{
				Vector3 target = (((Object)(object)local.gameplayCamera != (Object)null) ? ((Component)local.gameplayCamera).transform.position : (((Component)local).transform.position + Vector3.up * 1.6f));
				if (InCone(val2, forward, target) || InCone(val2, forward, ((Component)local).transform.position + Vector3.up * 0.9f))
				{
					localHit = true;
					try
					{
						local.DamagePlayer(Plugin.PlayerDamage.Value, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
					}
					catch (Exception ex3)
					{
						Plugin.Log.LogError((object)ex3);
					}
				}
			}
			if (isHost && Plugin.KillEnemies.Value)
			{
				KillEnemiesInCone(val2, forward, killed);
			}
			elapsed += Time.deltaTime;
			yield return null;
		}
		if (!isHost)
		{
			yield break;
		}
		yield return (object)new WaitForSeconds(1.5f);
		try
		{
			if ((Object)(object)item != (Object)null && (Object)(object)((NetworkBehaviour)item).NetworkObject != (Object)null && ((NetworkBehaviour)item).NetworkObject.IsSpawned)
			{
				((NetworkBehaviour)item).NetworkObject.Despawn(true);
			}
		}
		catch (Exception)
		{
		}
	}

	private static void Launch(PlayerControllerB player)
	{
		//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_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_004f: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Vector3 val = -(((Object)(object)player.gameplayCamera != (Object)null) ? ((Component)player.gameplayCamera).transform : ((Component)player).transform).forward + Vector3.up * Plugin.LaunchUpward.Value;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			player.externalForceAutoFade += normalized * Plugin.LaunchForce.Value;
			if ((Object)(object)HUDManager.Instance != (Object)null)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)3);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Launch failed: " + ex));
		}
	}

	private static void ConsumeItem(PlayerControllerB player, TikkaMasalaItem item)
	{
		try
		{
			if ((Object)(object)item == (Object)null)
			{
				return;
			}
			if ((Object)(object)player.currentlyHeldObjectServer == (Object)(object)item)
			{
				player.DespawnHeldObject();
				return;
			}
			int num = Array.IndexOf(player.ItemSlots, (GrabbableObject)(object)item);
			if (num >= 0)
			{
				player.DestroyItemInSlotAndSync(num);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Could not remove eaten bowl: " + ex));
		}
	}

	private static bool InCone(Vector3 origin, Vector3 dir, Vector3 target)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//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)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = target - origin;
		float magnitude = ((Vector3)(ref val)).magnitude;
		if (magnitude > Plugin.Range.Value)
		{
			return false;
		}
		if (magnitude > 1.2f && Vector3.Angle(dir, val) > Plugin.ConeAngle.Value)
		{
			return false;
		}
		if (magnitude <= 1.2f && Vector3.Dot(dir, val) < -0.2f)
		{
			return false;
		}
		return !Physics.Linecast(origin, target, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1);
	}

	private static void KillEnemiesInCone(Vector3 origin, Vector3 dir, HashSet<EnemyAI> killed)
	{
		//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_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if ((Object)(object)RoundManager.Instance == (Object)null || RoundManager.Instance.SpawnedEnemies == null)
			{
				return;
			}
			EnemyAI[] array = RoundManager.Instance.SpawnedEnemies.ToArray();
			foreach (EnemyAI val in array)
			{
				if (!((Object)(object)val == (Object)null) && !val.isEnemyDead && !killed.Contains(val) && (InCone(origin, dir, ((Component)val).transform.position + Vector3.up * 0.6f) || ((Object)(object)val.eye != (Object)null && InCone(origin, dir, val.eye.position))))
				{
					killed.Add(val);
					Kill(val);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Enemy check failed: " + ex));
		}
	}

	private static void Kill(EnemyAI enemy)
	{
		bool flag = (Object)(object)enemy.enemyType == (Object)null || !enemy.enemyType.canDie;
		try
		{
			if (flag)
			{
				enemy.KillEnemy(true);
			}
			else
			{
				enemy.KillEnemyServerRpc(false);
				if ((Object)(object)enemy != (Object)null && !enemy.isEnemyDead)
				{
					enemy.KillEnemyClientRpc(false);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Kill failed for " + ((Object)enemy).name + ": " + ex));
		}
		try
		{
			if (flag && (Object)(object)enemy != (Object)null && (Object)(object)((NetworkBehaviour)enemy).NetworkObject != (Object)null && ((NetworkBehaviour)enemy).NetworkObject.IsSpawned)
			{
				((NetworkBehaviour)enemy).NetworkObject.Despawn(true);
			}
		}
		catch (Exception ex2)
		{
			Plugin.Log.LogError((object)("Despawn failed: " + ex2));
		}
	}

	private static void PlayOn(PlayerControllerB player, AudioClip clip, float pitch)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_00ed: Expected O, but got Unknown
		if (!((Object)(object)clip == (Object)null) && !((Object)(object)player == (Object)null))
		{
			GameObject val = new GameObject("TikkaMasalaSfx");
			val.transform.SetParent(((Component)player).transform, false);
			val.transform.localPosition = new Vector3(0f, 1.6f, 0f);
			AudioSource val2 = val.AddComponent<AudioSource>();
			val2.clip = clip;
			val2.volume = Mathf.Clamp01(Plugin.Volume.Value);
			val2.pitch = pitch;
			val2.spatialBlend = 1f;
			val2.dopplerLevel = 0f;
			val2.rolloffMode = (AudioRolloffMode)1;
			val2.minDistance = 3f;
			val2.maxDistance = 35f;
			if ((Object)(object)player.movementAudio != (Object)null)
			{
				val2.outputAudioMixerGroup = player.movementAudio.outputAudioMixerGroup;
			}
			val2.Play();
			Object.Destroy((Object)val, clip.length / Mathf.Max(0.1f, pitch) + 0.5f);
		}
	}

	internal static void AddSplat(Vector3 point, Vector3 normal)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
		Collider component = val.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component);
		}
		((Object)val).name = "TikkaMasalaSplat";
		float num = Random.Range(0.25f, 0.7f);
		val.transform.position = point + normal * 0.008f;
		val.transform.rotation = Quaternion.FromToRotation(Vector3.up, normal) * Quaternion.Euler(0f, Random.Range(0f, 360f), 0f);
		val.transform.localScale = new Vector3(num * Random.Range(0.6f, 1.3f), 0.012f, num);
		MeshRenderer component2 = val.GetComponent<MeshRenderer>();
		((Renderer)component2).sharedMaterial = ((Random.value < 0.8f) ? Mats.Sauce : Mats.Chunk);
		((Renderer)component2).shadowCastingMode = (ShadowCastingMode)0;
		try
		{
			StartOfRound val2 = StartOfRound.Instance;
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2.shipInnerRoomBounds != (Object)null)
			{
				Bounds bounds = val2.shipInnerRoomBounds.bounds;
				if (((Bounds)(ref bounds)).Contains(point))
				{
					val.transform.SetParent(val2.elevatorTransform, true);
				}
			}
		}
		catch (Exception)
		{
		}
		splats.Enqueue(val);
		Object.Destroy((Object)(object)val, Mathf.Max(1f, Plugin.SplatLifetime.Value));
		int num2 = Mathf.Max(1, Plugin.MaxSplats.Value);
		while (splats.Count > num2)
		{
			GameObject val3 = splats.Dequeue();
			if ((Object)(object)val3 != (Object)null)
			{
				Object.Destroy((Object)(object)val3);
			}
		}
	}
}
internal class VomitBlob : MonoBehaviour
{
	private Vector3 velocity;

	private float life = 5f;

	private int mask;

	internal static void Spawn(Vector3 mouth, Vector3 dir, Transform cam)
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: 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)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		bool flag = Random.value < 0.2f;
		GameObject obj = GameObject.CreatePrimitive((PrimitiveType)(flag ? 3 : 0));
		Collider component = obj.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component);
		}
		((Object)obj).name = "TikkaMasalaBlob";
		obj.transform.position = mouth + cam.right * Random.Range(-0.05f, 0.05f) + cam.up * Random.Range(-0.05f, 0.05f);
		obj.transform.rotation = Random.rotation;
		obj.transform.localScale = Vector3.one * (flag ? Random.Range(0.05f, 0.09f) : Random.Range(0.07f, 0.2f));
		MeshRenderer component2 = obj.GetComponent<MeshRenderer>();
		((Renderer)component2).sharedMaterial = (flag ? Mats.Chunk : Mats.Sauce);
		((Renderer)component2).shadowCastingMode = (ShadowCastingMode)0;
		VomitBlob vomitBlob = obj.AddComponent<VomitBlob>();
		Vector3 val = cam.right * Random.Range(-0.22f, 0.22f) + cam.up * Random.Range(-0.16f, 0.22f);
		Vector3 val2 = dir + val;
		vomitBlob.velocity = ((Vector3)(ref val2)).normalized * Random.Range(7f, 14f);
		vomitBlob.mask = ((!((Object)(object)StartOfRound.Instance != (Object)null)) ? 1 : StartOfRound.Instance.collidersAndRoomMaskAndDefault);
	}

	private void Update()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		float deltaTime = Time.deltaTime;
		velocity += Vector3.down * 16f * deltaTime;
		Vector3 val = velocity * deltaTime;
		float magnitude = ((Vector3)(ref val)).magnitude;
		RaycastHit val2 = default(RaycastHit);
		if (magnitude > 0f && Physics.Raycast(((Component)this).transform.position, val / magnitude, ref val2, magnitude + 0.06f, mask, (QueryTriggerInteraction)1))
		{
			try
			{
				VomitRunner.AddSplat(((RaycastHit)(ref val2)).point, ((RaycastHit)(ref val2)).normal);
			}
			catch (Exception)
			{
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		Transform transform = ((Component)this).transform;
		transform.position += val;
		life -= deltaTime;
		if (life <= 0f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
}