Decompiled source of Triple Baka Items v1.0.0

MikuTetoSkulls.dll

Decompiled 3 hours ago
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace MikuTetoSkulls;

[BepInPlugin("com.Only1Wolf.mikutetoskulls", "Miku Teto Skulls", "1.0")]
[BepInProcess("ULTRAKILL.exe")]
public class Plugin : BaseUnityPlugin
{
	public static AssetBundle skullsBundle;

	public static GameObject mikuPrefab;

	public static GameObject tetoPrefab;

	public static GameObject neruPrefab;

	public static AudioClip mikuSound;

	public static AudioClip tetoSound;

	public static AudioClip neruSound;

	private float scanTimer = 0f;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogWarning((object)"--- INICIANDO MOD VOCALOID ITEMS ---");
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mikuteto_skulls");
		if (File.Exists(text))
		{
			skullsBundle = AssetBundle.LoadFromFile(text);
			tetoPrefab = skullsBundle.LoadAsset<GameObject>("TetoSkull");
			mikuPrefab = skullsBundle.LoadAsset<GameObject>("MikuSkull");
			neruPrefab = skullsBundle.LoadAsset<GameObject>("NeruTorch");
			mikuSound = skullsBundle.LoadAsset<AudioClip>("Miku_Sound");
			tetoSound = skullsBundle.LoadAsset<AudioClip>("Teto_Sound");
			neruSound = skullsBundle.LoadAsset<AudioClip>("Neru_Sound");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"¡AssetBundle cargado exitosamente!");
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("ERROR: No se encontró 'mikuteto_skulls' en: " + text));
		}
	}

	private void Update()
	{
		scanTimer += Time.deltaTime;
		if (scanTimer >= 1f)
		{
			scanTimer = 0f;
			ProcessItemsInScene();
		}
	}

	private void ProcessItemsInScene()
	{
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Invalid comparison between Unknown and I4
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Invalid comparison between Unknown and I4
		//IL_0106: 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_0109: 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_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		ItemIdentifier[] array = Object.FindObjectsOfType<ItemIdentifier>();
		ItemIdentifier[] array2 = array;
		Vector3 customPosition = default(Vector3);
		Vector3 customRotation = default(Vector3);
		Vector3 customPosition2 = default(Vector3);
		Vector3 customRotation2 = default(Vector3);
		foreach (ItemIdentifier val in array2)
		{
			if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).GetComponent<SoundTracker>() != (Object)null)
			{
				continue;
			}
			string text = ((Object)((Component)val).gameObject).name.ToLower();
			((Vector3)(ref customPosition))..ctor(-0.2f, 0f, -0.12f);
			((Vector3)(ref customRotation))..ctor(0f, 105f, 90f);
			((Vector3)(ref customPosition2))..ctor(-0.2f, 0f, -0.15f);
			((Vector3)(ref customRotation2))..ctor(0f, 105f, 90f);
			if ((int)val.itemType == 2 || text.Contains("redskull") || text.Contains("skullred"))
			{
				if ((Object)(object)tetoPrefab != (Object)null)
				{
					ReplaceAndTrackModel(((Component)val).gameObject, tetoPrefab, customPosition, customRotation, Vector3.one, tetoSound, val);
				}
			}
			else if (((int)val.itemType == 1 || text.Contains("blueskull") || text.Contains("skullblue")) && (Object)(object)mikuPrefab != (Object)null)
			{
				ReplaceAndTrackModel(((Component)val).gameObject, mikuPrefab, customPosition2, customRotation2, Vector3.one, mikuSound, val);
			}
		}
		GameObject[] array3 = Object.FindObjectsOfType<GameObject>();
		GameObject[] array4 = array3;
		Vector3 customPosition3 = default(Vector3);
		Vector3 customRotation3 = default(Vector3);
		Vector3 customScale = default(Vector3);
		foreach (GameObject val2 in array4)
		{
			if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.GetComponent<SoundTracker>() != (Object)null))
			{
				string text2 = ((Object)val2).name.ToLower();
				if (text2.Contains("torch") && !text2.Contains("altar") && !text2.Contains("pedestal") && !text2.Contains("spawner") && !text2.Contains("arm") && !text2.Contains("preview") && !((Object)(object)val2.GetComponent<ItemIdentifier>() == (Object)null) && (Object)(object)neruPrefab != (Object)null)
				{
					((Vector3)(ref customPosition3))..ctor(0f, -0.7f, 0f);
					((Vector3)(ref customRotation3))..ctor(0f, 90f, 0f);
					((Vector3)(ref customScale))..ctor(2.2f, 2.2f, 2.2f);
					ReplaceAndTrackTorch(val2, neruPrefab, customPosition3, customRotation3, customScale, neruSound);
				}
			}
		}
	}

	private void ReplaceAndTrackModel(GameObject rootObject, GameObject newPrefab, Vector3 customPosition, Vector3 customRotation, Vector3 customScale, AudioClip clip, ItemIdentifier itemID)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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)
		List<MeshRenderer> list = new List<MeshRenderer>();
		MeshRenderer[] componentsInChildren = rootObject.GetComponentsInChildren<MeshRenderer>();
		MeshRenderer[] array = componentsInChildren;
		foreach (MeshRenderer val in array)
		{
			if (((Object)((Component)val).gameObject).name != "CustomModelPlaced")
			{
				((Renderer)val).enabled = false;
				list.Add(val);
			}
		}
		InstantiateModel(rootObject, newPrefab, customPosition, customRotation, customScale);
		SoundTracker soundTracker = rootObject.AddComponent<SoundTracker>();
		soundTracker.clip = clip;
		soundTracker.itemID = itemID;
		soundTracker.meshesToHide = list.ToArray();
	}

	private void ReplaceAndTrackTorch(GameObject rootObject, GameObject newPrefab, Vector3 customPosition, Vector3 customRotation, Vector3 customScale, AudioClip clip)
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		List<MeshRenderer> list = new List<MeshRenderer>();
		MeshRenderer[] componentsInChildren = rootObject.GetComponentsInChildren<MeshRenderer>();
		MeshRenderer[] array = componentsInChildren;
		foreach (MeshRenderer val in array)
		{
			if (((Object)((Component)val).gameObject).name.ToLower().Contains("cylinder"))
			{
				((Renderer)val).enabled = false;
				list.Add(val);
			}
		}
		InstantiateModel(rootObject, newPrefab, customPosition, customRotation, customScale);
		SoundTracker soundTracker = rootObject.AddComponent<SoundTracker>();
		soundTracker.clip = clip;
		soundTracker.meshesToHide = list.ToArray();
	}

	private void InstantiateModel(GameObject rootObject, GameObject newPrefab, Vector3 pos, Vector3 rot, Vector3 scale)
	{
		//IL_0020: 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_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Object.Instantiate<GameObject>(newPrefab, rootObject.transform);
		((Object)val).name = "CustomModelPlaced";
		val.transform.localPosition = pos;
		val.transform.localRotation = Quaternion.Euler(rot);
		val.transform.localScale = scale;
		SetLayerRecursively(val, rootObject.layer);
	}

	private void SetLayerRecursively(GameObject obj, int newLayer)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		if ((Object)(object)obj == (Object)null)
		{
			return;
		}
		obj.layer = newLayer;
		foreach (Transform item in obj.transform)
		{
			Transform val = item;
			if ((Object)(object)val != (Object)null)
			{
				SetLayerRecursively(((Component)val).gameObject, newLayer);
			}
		}
	}
}
public class SoundTracker : MonoBehaviour
{
	public bool hasPlayed = false;

	public AudioClip clip;

	public ItemIdentifier itemID;

	public MeshRenderer[] meshesToHide;

	private AudioSource source;

	private void Update()
	{
		if (meshesToHide != null)
		{
			for (int i = 0; i < meshesToHide.Length; i++)
			{
				if ((Object)(object)meshesToHide[i] != (Object)null && ((Renderer)meshesToHide[i]).enabled)
				{
					((Renderer)meshesToHide[i]).enabled = false;
				}
			}
		}
		if ((Object)(object)clip != (Object)null)
		{
			bool flag = false;
			flag = ((!((Object)(object)itemID != (Object)null)) ? IsParentHand(((Component)this).transform) : (itemID.pickedUp || IsParentHand(((Component)this).transform)));
			if (flag && !hasPlayed)
			{
				PlaySoundFollow(clip);
				hasPlayed = true;
			}
			else if (!flag)
			{
				hasPlayed = false;
			}
		}
	}

	private bool IsParentHand(Transform t)
	{
		if ((Object)(object)t.parent == (Object)null)
		{
			return false;
		}
		string text = ((Object)t.parent).name.ToLower();
		if (text.Contains("canvas") || text.Contains("menu") || text.Contains("ui"))
		{
			return false;
		}
		return text.Contains("hand") || text.Contains("holder") || text.Contains("player") || text.Contains("arm");
	}

	private void PlaySoundFollow(AudioClip clipToPlay)
	{
		if ((Object)(object)source == (Object)null)
		{
			source = ((Component)this).gameObject.AddComponent<AudioSource>();
			source.spatialBlend = 0f;
			source.playOnAwake = false;
			AudioSource[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<AudioSource>(true);
			AudioSource[] array = componentsInChildren;
			foreach (AudioSource val in array)
			{
				if ((Object)(object)val != (Object)(object)source && (Object)(object)val.outputAudioMixerGroup != (Object)null)
				{
					source.outputAudioMixerGroup = val.outputAudioMixerGroup;
					break;
				}
			}
		}
		source.clip = clipToPlay;
		source.Play();
	}
}