Decompiled source of ThisIsScrapbookSkulls v1.0.0

SkullReplacer.dll

Decompiled 4 hours 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.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SkullReplacer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SkullReplacer")]
[assembly: AssemblyTitle("SkullReplacer")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("NoobWithFedora.ThisIsScrapbookSkulls", "ThisIsScrapbookSkulls", "1.0.0")]
public class SkullReplacer : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <ReplaceLoop>d__5 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public SkullReplacer <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ReplaceLoop>d__5(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			int num = <>1__state;
			SkullReplacer skullReplacer = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(3f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				break;
			case 2:
				<>1__state = -1;
				break;
			}
			skullReplacer.ReplaceObjects();
			<>2__current = (object)new WaitForSeconds(3f);
			<>1__state = 2;
			return true;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private AssetBundle _bundle;

	private GameObject _replacementPrefab;

	private static ManualLogSource Logger;

	private void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		string text = Path.Combine(Paths.PluginPath, "ThisIsScrapbookSkulls", "skullnplush_replace");
		_bundle = AssetBundle.LoadFromFile(text);
		if ((Object)(object)_bundle == (Object)null)
		{
			Logger.LogError((object)"Failed to load AssetBundle! Make sure skullnplush_replace is in the ThisIsScrapbookSkulls plugin folder.");
			return;
		}
		_replacementPrefab = _bundle.LoadAsset<GameObject>("assets/sbookplush.fbx");
		if ((Object)(object)_replacementPrefab == (Object)null)
		{
			Logger.LogError((object)"Failed to load prefab from AssetBundle! Check the prefab name.");
			return;
		}
		Logger.LogInfo((object)"Skull Replacer loaded successfully!");
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		((MonoBehaviour)this).StartCoroutine(ReplaceLoop());
	}

	[IteratorStateMachine(typeof(<ReplaceLoop>d__5))]
	private IEnumerator ReplaceLoop()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ReplaceLoop>d__5(0)
		{
			<>4__this = this
		};
	}

	private void ReplaceObjects()
	{
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		Skull[] array = Object.FindObjectsOfType<Skull>(true);
		foreach (Skull val in array)
		{
			if (!((Object)(object)((Component)val).gameObject.GetComponent<ReplacedMarker>() != (Object)null))
			{
				((Component)val).gameObject.AddComponent<ReplacedMarker>();
				Transform val2 = ((Component)val).transform.Find("NewSkull");
				if ((Object)(object)val2 == (Object)null)
				{
					Logger.LogWarning((object)"NewSkull not found");
					continue;
				}
				((Component)val2).gameObject.SetActive(false);
				GameObject obj = Object.Instantiate<GameObject>(_replacementPrefab, ((Component)val).transform);
				obj.transform.localPosition = new Vector3(0f, 0f, -0.2f);
				obj.transform.localRotation = val2.localRotation * Quaternion.Euler(90f, 0f, 0f);
				obj.transform.localScale = new Vector3(0.45f, 0.45f, 0.45f);
				Logger.LogInfo((object)("Replaced skull: " + ((Object)((Component)val).gameObject).name));
			}
		}
	}

	private void OnDestroy()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
		AssetBundle bundle = _bundle;
		if (bundle != null)
		{
			bundle.Unload(false);
		}
	}
}
public class ReplacedMarker : MonoBehaviour
{
}