Decompiled source of TomNookBracken v1.0.0

TomNookLC.dll

Decompiled 4 months ago
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Video;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TomNookLC")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TomNookLC")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4b9edb4f-bb7b-4d86-854b-bc0fcfbdd691")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TomNookFlowerman
{
	[BepInPlugin("TomNook", "TomNook", "1.0.0")]
	public class TomNookBracken : BaseUnityPlugin
	{
		public static GameObject TNVisuals;

		public static VideoClip TNVIdeo;

		internal static TomNookBracken Instance;

		public static AudioClip TomNookAngered;

		public static AssetBundle AssetBundle { get; private set; }

		private static string AssemblyName => Assembly.GetExecutingAssembly().FullName.Split(new char[1] { ',' })[0];

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin TomNook is loaded!");
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			if ((Object)(object)AssetBundle != (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Attempted to load the asset bundle but the bundle was not null!");
				return;
			}
			AssetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "tommynook"));
			TNVisuals = AssetBundle.LoadAsset<GameObject>("assets/Mods/Nook.prefab");
			TomNookAngered = AssetBundle.LoadAsset<AudioClip>("assets/Mods/tomNook.ogg");
			Renderer[] componentsInChildren = TNVisuals.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				((Component)val).gameObject.layer = LayerMask.NameToLayer("Enemies");
			}
		}

		internal static void LogInfo(object message)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)("[TomNook-BRACKEN]" + message));
		}

		internal static void LogWarning(object message)
		{
			((BaseUnityPlugin)Instance).Logger.LogWarning((object)("[TomNook-BRACKEN]" + message));
		}

		internal static void LogError(object message)
		{
			((BaseUnityPlugin)Instance).Logger.LogError((object)("[TomNook-BRACKEN]" + message));
		}
	}
}
namespace TomNookFlowerman.Patches
{
	[HarmonyPatch(typeof(FlowermanAI), "Start")]
	internal class FlowermanPatch
	{
		private static void Postfix(FlowermanAI __instance)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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)
			Transform val = ((Component)__instance).transform.Find("FlowermanModel");
			Transform val2 = (((Object)(object)val != (Object)null) ? val.Find("LOD1") : null);
			SkinnedMeshRenderer val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<SkinnedMeshRenderer>() : null);
			Transform val4;
			if ((Object)(object)val == (Object)null)
			{
				val4 = null;
			}
			else
			{
				Transform val5 = val.Find("AnimContainer");
				val4 = (((Object)(object)val5 != (Object)null) ? val5.Find("metarig") : null);
			}
			Transform val6 = val4;
			((Renderer)val3).enabled = false;
			Renderer[] componentsInChildren = ((Component)val6).gameObject.GetComponentsInChildren<Renderer>();
			foreach (Renderer val7 in componentsInChildren)
			{
				val7.enabled = false;
			}
			GameObject val8 = Object.Instantiate<GameObject>(TomNookBracken.TNVisuals);
			val8.transform.SetParent(val);
			((EnemyAI)__instance).creatureAnimator = val8.GetComponent<Animator>();
			val8.AddComponent<TomNookAI>();
			val8.transform.localPosition = Vector3.zero;
			val8.transform.localScale = Vector3.one * 0.6f;
			__instance.creatureAngerVoice.clip = TomNookBracken.TomNookAngered;
		}
	}
	public class TomNookAI : MonoBehaviour
	{
		[SerializeField]
		private Transform defaultEye;

		[SerializeField]
		private Transform closingEye;

		[SerializeField]
		private Transform closedEye;

		private void Start()
		{
			defaultEye = RecursiveFindChild(((Component)this).transform, "Body__mEye (default)");
			closingEye = RecursiveFindChild(((Component)this).transform, "Body__mEye (closing)");
			closedEye = RecursiveFindChild(((Component)this).transform, "Body__mEye (closed)");
			((MonoBehaviour)this).StartCoroutine(Blink());
		}

		private Transform RecursiveFindChild(Transform parent, string childName)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			foreach (Transform item in parent)
			{
				Transform val = item;
				if (((Object)val).name == childName)
				{
					return val;
				}
				Transform val2 = RecursiveFindChild(val, childName);
				if ((Object)(object)val2 != (Object)null)
				{
					return val2;
				}
			}
			return null;
		}

		public void ChangeFace(bool open, bool closing, bool closed)
		{
			((Component)defaultEye).gameObject.SetActive(open);
			((Component)closingEye).gameObject.SetActive(closing);
			((Component)closedEye).gameObject.SetActive(closed);
		}

		private IEnumerator Blink()
		{
			ChangeFace(open: true, closing: false, closed: false);
			yield return (object)new WaitForSeconds(Random.Range(2f, 4f));
			ChangeFace(open: false, closing: true, closed: false);
			yield return (object)new WaitForSeconds(0.03f);
			ChangeFace(open: false, closing: false, closed: true);
			yield return (object)new WaitForSeconds(0.03f);
			ChangeFace(open: false, closing: true, closed: false);
			yield return (object)new WaitForSeconds(0.03f);
			ChangeFace(open: true, closing: false, closed: false);
			((MonoBehaviour)this).StartCoroutine(Blink());
		}
	}
	[HarmonyPatch(typeof(Terminal), "Awake")]
	internal class TerminalPatch
	{
		private static void PostFix(Terminal __instance)
		{
			__instance.enemyFiles[1].creatureName = "Tom Nook";
			__instance.enemyFiles[1].displayText = "Tom is noted to be very work-driven, and many years ago he left behind his friends, most importantly Sable, to travel to the big city. His dreams of success are quickly broken by the harsh life there.\nAfter making nothing of himself, he is now wandering the moons to sell enough scrap to set up his store.\n";
			__instance.terminalNodes.allKeywords[36].word = "tom nook";
		}
	}
}