Decompiled source of SkeegMainMenu v1.0.0

SkeegMainMenu.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("SkeegMainMenu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Replaces the main menu and lobby menu enviornments with a stupid lookin cat.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e3a959f7029d03c47b5d9b575415b45835c97e6a")]
[assembly: AssemblyProduct("Skeeg main menu")]
[assembly: AssemblyTitle("SkeegMainMenu")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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;
		}
	}
}
namespace SkeegMainMenu
{
	public class EegSpinner : MonoBehaviour
	{
		public float eegspinning = -90f;

		private void Update()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.Rotate(new Vector3(0f, eegspinning * Time.deltaTime, 0f));
		}
	}
	[BepInPlugin("SkeegMainMenu", "Skeeg main menu", "1.0.0")]
	public class SkeegMainMenu : BaseUnityPlugin
	{
		public static SkeegMainMenu Instance;

		internal static ManualLogSource Logger;

		public Harmony Harmoneeg;

		public AssetBundle eegs;

		public GameObject skeegAsset;

		public AudioClip eegNoises;

		public string assetBundleName = "skeeg";

		public string gameobjectName = "Eegvil skeeg.";

		public Vector3 assetPosition = Vector3.zero;

		public float cameraFov = 95f;

		public Vector3 playerParentPosition = Vector3.zero;

		public Vector3 playerParentRotation = Vector3.zero;

		public Vector3 playerPosition = new Vector3(0f, 1.4f, -8f);

		public Vector3 playerEulerAngles = new Vector3(-25f, 0f, 0f);

		public Color backgroundColor = Color.black;

		public float playerSpeenSpeed = -30f;

		public float skeegahedronSpeenSpeed = 45f;

		private void Awake()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			if ((Object)(object)Instance != (Object)null)
			{
				Object.Destroy((Object)(object)this);
				return;
			}
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Loading SkeegMainMenu.");
			Harmoneeg = new Harmony("at.kibbyc.SkeegMainMenu");
			try
			{
				LoadAssetBundle(Path.Join(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location).AsSpan(), assetBundleName.AsSpan()));
				LoadAssetsFromBundle();
			}
			catch (Exception ex)
			{
				Logger.LogError((object)"Asset loading failed, Canceling loading mod.");
				Logger.LogError((object)ex);
				return;
			}
			Logger.LogInfo((object)"Patching..");
			Harmoneeg.PatchAll(typeof(SkeegMainMenu));
			Logger.LogInfo((object)"Plugin SkeegMainMenu is loaded!");
		}

		private void LoadAssetBundle(string bundlePath)
		{
			Logger.LogInfo((object)("Loading AssetBundle from " + bundlePath + ".."));
			eegs = AssetBundle.LoadFromFile(bundlePath);
			Logger.LogInfo((object)"AssetBundle loaded!");
			Logger.LogInfo((object)$"found {eegs.GetAllAssetNames().Length} assets");
			Logger.LogInfo((object)("\n" + string.Join("\n", eegs.GetAllAssetNames())));
		}

		private void LoadAssetsFromBundle()
		{
			Logger.LogInfo((object)"Loading assets");
			skeegAsset = eegs.LoadAsset<GameObject>("Skeeg");
			eegNoises = eegs.LoadAsset<AudioClip>("SkeegMusic");
			Logger.LogInfo((object)"Loaded assets");
		}

		[HarmonyPatch(typeof(TruckMenuAnimated), "Start")]
		[HarmonyPrefix]
		private static bool No____Dont___DoThat(TruckMenuAnimated __instance)
		{
			((MonoBehaviour)Instance).StartCoroutine(Instance.KeegRoutine(((Component)__instance).transform.parent.parent));
			((Component)__instance).gameObject.SetActive(false);
			return false;
		}

		private IEnumerator KeegRoutine(Transform startRoom)
		{
			if (!Object.op_Implicit((Object)(object)LevelGenerator.Instance))
			{
				Logger.LogError((object)"Level generator is null, cant safely disable lobby.");
				yield break;
			}
			while (!LevelGenerator.Instance.Generated)
			{
				yield return null;
			}
			InitializeSkeegs(startRoom);
		}

		private static void InitializeSkeegs(Transform startRoom)
		{
			Logger.LogInfo((object)"Initializing skeeg (and lobotomizing the truck animator)!!");
			StartRoom val = default(StartRoom);
			if (!((Component)startRoom).gameObject.TryGetComponent<StartRoom>(ref val))
			{
				Logger.LogWarning((object)"Startroom doesnt have startroom component");
			}
			LoadSkeegModel(Instance.skeegAsset, startRoom);
			DoSkeegMusic(Instance.eegNoises);
			DoCameraOverrides();
			SetEnviornmentColor();
			((Component)startRoom.Find("Lobby Landscape")).gameObject.SetActive(false);
		}

		private static void LoadSkeegModel(GameObject skeeger, Transform startRoom)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(skeeger, startRoom);
			obj.transform.position = Instance.assetPosition;
			((Object)obj).name = Instance.gameobjectName;
			Logger.LogInfo((object)"Skeeg initialized.");
			TrySpinNestedSpeener(obj);
		}

		private static void TrySpinNestedSpeener(GameObject skeeg)
		{
			try
			{
				((Component)skeeg.transform.Find("Keedge").Find("Speener")).gameObject.AddComponent<EegSpinner>().eegspinning = Instance.skeegahedronSpeenSpeed;
			}
			catch (Exception ex)
			{
				Logger.LogWarning((object)"You've changed the keeg assetbundle without keeping the spinner at \"asset/Keedge/Speener\"! this resulted in failing to put a eegspinner onto the speener element.");
				Logger.LogWarning((object)ex);
			}
		}

		public static void DoCameraOverrides()
		{
			//IL_0057: 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_007c: 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)
			Logger.LogInfo((object)"Setting camera info");
			if (!Object.op_Implicit((Object)(object)CameraNoPlayerTarget.instance))
			{
				Logger.LogError((object)"There's no mock camera in the menu scene, somethings wrong! cant do camera overrides.");
				return;
			}
			CameraNoPlayerTarget instance = CameraNoPlayerTarget.instance;
			((Component)instance).GetComponent<Camera>().fieldOfView = Instance.cameraFov;
			Transform parent = ((Component)instance).transform.parent;
			parent.localPosition = Instance.playerParentPosition;
			parent.localEulerAngles = Instance.playerParentRotation;
			Transform transform = ((Component)instance).transform;
			transform.position = Instance.playerPosition;
			transform.localEulerAngles = Instance.playerEulerAngles;
			((Component)parent).gameObject.AddComponent<EegSpinner>().eegspinning = Instance.playerSpeenSpeed;
		}

		public static void SetEnviornmentColor()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			Logger.LogInfo((object)"Doing enviornment overrides.");
			if (!Object.op_Implicit((Object)(object)EnvironmentDirector.Instance))
			{
				Logger.LogError((object)"Level generator instance was null, cant do environment overrides.");
			}
			else
			{
				AccessTools.FieldRefAccess<EnvironmentDirector, Color>("FogColor").Invoke(EnvironmentDirector.Instance) = Instance.backgroundColor;
			}
		}

		private static void DoSkeegMusic(AudioClip skeegMusic = null)
		{
			if (skeegMusic == null)
			{
				skeegMusic = Instance.eegNoises;
			}
			Logger.LogInfo((object)"Setting skeeg music");
			if (!Object.op_Implicit((Object)(object)ConstantMusic.instance))
			{
				Logger.LogError((object)"Constant music instance was null, cant do music overrides.");
				return;
			}
			AccessTools.FieldRefAccess<ConstantMusic, AudioClip>("clip").Invoke(ConstantMusic.instance) = skeegMusic;
			AccessTools.FieldRefAccess<ConstantMusic, bool>("setup").Invoke(ConstantMusic.instance) = false;
		}

		[HarmonyPatch(typeof(CameraMainMenu), "Awake")]
		[HarmonyPostfix]
		private static void DisableMainMenuAnimation(CameraMainMenu __instance)
		{
			__instance.introLerp = 1f;
		}

		[HarmonyPatch(typeof(MenuPageMain), "ButtonSocialMarketing")]
		[HarmonyPrefix]
		private static bool No____Dont___DoThat3()
		{
			Application.OpenURL("https://www.youtube.com/watch?v=wE4YL4Ehqhg");
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SkeegMainMenu";

		public const string PLUGIN_NAME = "Skeeg main menu";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}