Decompiled source of LegoYoda3DModel v1.0.0

Lego Yoda.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModConfig;
using ModelReplacement;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("Lego Yoda")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Lego Yoda")]
[assembly: AssemblyTitle("Lego Yoda")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ModConfig
{
	internal class ConfigClass
	{
		public readonly ConfigEntry<KeyboardShortcut> KeybindForYodaSaber;

		public ConfigClass(ConfigFile config)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			config.SaveOnConfigSet = false;
			KeybindForYodaSaber = config.Bind<KeyboardShortcut>("General", "KeybindForYodaSaber", new KeyboardShortcut((KeyCode)121, Array.Empty<KeyCode>()), "");
			ClearOrphanedEntries(config);
			config.Save();
			config.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
			dictionary.Clear();
		}
	}
}
namespace LegoYoda
{
	public class MRLEGOYODAFULL : BodyReplacementBase
	{
		public class SaberLogic : MonoBehaviour
		{
			[CompilerGenerated]
			private sealed class <AnimateSaber>d__6 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public float targetValue;

				public SaberLogic <>4__this;

				private float <currentValue>5__1;

				private float <elapsed>5__2;

				private float <duration>5__3;

				private float <weight>5__4;

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

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

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

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

				private bool MoveNext()
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<>4__this.isAnimating = true;
						<currentValue>5__1 = <>4__this.SableLaser.GetBlendShapeWeight(0);
						<elapsed>5__2 = 0f;
						<duration>5__3 = 0.2f;
						break;
					case 1:
						<>1__state = -1;
						break;
					}
					if (<elapsed>5__2 < <duration>5__3)
					{
						<elapsed>5__2 += Time.deltaTime;
						<weight>5__4 = Mathf.Lerp(<currentValue>5__1, targetValue, <elapsed>5__2 / <duration>5__3);
						<>4__this.SableLaser.SetBlendShapeWeight(0, <weight>5__4);
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
					<>4__this.SableLaser.SetBlendShapeWeight(0, targetValue);
					<>4__this.isAnimating = false;
					return false;
				}

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

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

			public PlayerControllerB playerController;

			private SkinnedMeshRenderer SableLaser;

			public bool isOpen = true;

			private bool isAnimating = false;

			private void Start()
			{
				SableLaser = ((IEnumerable<SkinnedMeshRenderer>)((Component)this).GetComponentsInChildren<SkinnedMeshRenderer>(true)).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer smr) => ((Object)((Component)smr).gameObject).name == "Lightsaber.001"));
				if ((Object)(object)SableLaser != (Object)null)
				{
					SableLaser.SetBlendShapeWeight(0, 0f);
				}
			}

			private void Update()
			{
				//IL_0023: 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_0075: Unknown result type (might be due to invalid IL or missing references)
				if (Plugin.config == null || Keyboard.current == null)
				{
					return;
				}
				KeyboardShortcut value = Plugin.config.KeybindForYodaSaber.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					if ((Object)(object)SableLaser != (Object)null && !isAnimating)
					{
						isOpen = !isOpen;
						SaberSound(((Component)playerController).transform.position);
						float targetValue = (isOpen ? 0f : 100f);
						((MonoBehaviour)this).StartCoroutine(AnimateSaber(targetValue));
					}
					else if ((Object)(object)SableLaser == (Object)null)
					{
						Debug.LogError((object)"Lightsaber not found (wtf bro)");
					}
				}
			}

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

			public void SaberSound(Vector3 position)
			{
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Expected O, but got Unknown
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)SaberOnSound == (Object)null) && !((Object)(object)SaberOffSound == (Object)null))
				{
					GameObject val = null;
					val = ((!isOpen) ? new GameObject("LightsaberOff") : new GameObject("LightsaberOn"));
					val.transform.position = position;
					AudioSource val2 = val.AddComponent<AudioSource>();
					if (isOpen)
					{
						val2.clip = SaberOnSound;
					}
					else
					{
						val2.clip = SaberOffSound;
					}
					val2.playOnAwake = false;
					val2.spatialBlend = 1f;
					val2.minDistance = 5f;
					val2.maxDistance = 30f;
					val2.rolloffMode = (AudioRolloffMode)0;
					GameObject obj = GameObject.Find("IngameAudio");
					object obj2;
					if (obj == null)
					{
						obj2 = null;
					}
					else
					{
						AudioSource component = obj.GetComponent<AudioSource>();
						obj2 = ((component != null) ? component.outputAudioMixerGroup : null);
					}
					AudioMixerGroup val3 = (AudioMixerGroup)obj2;
					if ((Object)(object)val3 != (Object)null)
					{
						val2.outputAudioMixerGroup = val3;
					}
					val2.Play();
					if (isOpen)
					{
						Object.Destroy((Object)(object)val, SaberOnSound.length + 0.5f);
					}
					else
					{
						Object.Destroy((Object)(object)val, SaberOffSound.length + 0.5f);
					}
				}
			}
		}

		private static AudioClip deathSound;

		private static AudioClip SaberOnSound;

		private static AudioClip SaberOffSound;

		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "LegoYodaFull";
			GameObject val = Assets.MainAssetBundle.LoadAsset<GameObject>(text);
			if ((Object)(object)deathSound == (Object)null)
			{
				deathSound = Assets.MainAssetBundle.LoadAsset<AudioClip>("Lego yoda death sound");
				SaberOnSound = Assets.MainAssetBundle.LoadAsset<AudioClip>("LightsaberOn");
				SaberOffSound = Assets.MainAssetBundle.LoadAsset<AudioClip>("LightsaberOff");
			}
			if ((Object)(object)val != (Object)null)
			{
				SaberLogic saberLogic = val.GetComponent<SaberLogic>();
				if ((Object)(object)saberLogic == (Object)null)
				{
					saberLogic = val.AddComponent<SaberLogic>();
				}
				saberLogic.playerController = ((BodyReplacementBase)this).controller;
			}
			return val;
		}

		protected override void OnDeath()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (((BodyReplacementBase)this).controller.isPlayerDead)
			{
				PlayDeathSound(((Component)((BodyReplacementBase)this).controller).transform.position);
			}
		}

		private void PlayDeathSound(Vector3 position)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)deathSound == (Object)null))
			{
				GameObject val = new GameObject("Lego yoda death sound");
				val.transform.position = position;
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.clip = deathSound;
				val2.playOnAwake = false;
				val2.spatialBlend = 1f;
				val2.minDistance = 5f;
				val2.maxDistance = 30f;
				val2.rolloffMode = (AudioRolloffMode)0;
				GameObject obj = GameObject.Find("IngameAudio");
				object obj2;
				if (obj == null)
				{
					obj2 = null;
				}
				else
				{
					AudioSource component = obj.GetComponent<AudioSource>();
					obj2 = ((component != null) ? component.outputAudioMixerGroup : null);
				}
				AudioMixerGroup val3 = (AudioMixerGroup)obj2;
				if ((Object)(object)val3 != (Object)null)
				{
					val2.outputAudioMixerGroup = val3;
				}
				val2.Play();
				Object.Destroy((Object)(object)val, deathSound.length + 0.5f);
			}
		}
	}
	public class MRLEGOYODACONCAPAYCAPUCHA : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "LegoYodaConCapaYCapucha";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	public class MRLEGOYODACONCAPA : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "LegoYodaConCapa";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	public class MRLEGOYODATIESO : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "LegoYodaTieso";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	[BepInPlugin("nicolengo1.LegoYoda", "LegoYoda", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ConfigClass config { get; private set; }

		private void Awake()
		{
			//IL_0022: 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)
			//IL_0097: Expected O, but got Unknown
			config = new ConfigClass(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Logger.LogInfo((object)config.KeybindForYodaSaber.Value);
			Assets.PopulateAssets();
			ModelReplacementAPI.RegisterSuitModelReplacement("Yoda Full Stacked", typeof(MRLEGOYODAFULL));
			ModelReplacementAPI.RegisterSuitModelReplacement("Yoda with cape and hood", typeof(MRLEGOYODACONCAPAYCAPUCHA));
			ModelReplacementAPI.RegisterSuitModelReplacement("Yoda with cape", typeof(MRLEGOYODACONCAPA));
			ModelReplacementAPI.RegisterSuitModelReplacement("Yoda", typeof(MRLEGOYODATIESO));
			Harmony val = new Harmony("nicolengo1.LegoYoda");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin nicolengo1.LegoYoda is loaded!");
		}
	}
	public static class Assets
	{
		public static string mainAssetBundleName = "LegoYodaAsset";

		public static AssetBundle MainAssetBundle = null;

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().GetName().Name.Replace(" ", "_");
		}

		public static void PopulateAssets()
		{
			if ((Object)(object)MainAssetBundle == (Object)null)
			{
				Console.WriteLine(GetAssemblyName() + "." + mainAssetBundleName);
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + mainAssetBundleName);
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}