Decompiled source of AlexElLaeon v1.0.0

BepInEx\plugins\AlexElLaeon\AlexElLaeon.dll

Decompiled 5 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using ModelReplacement.AvatarBodyUpdater;
using ModelReplacement.Scripts.Player;
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("AlexElLaeon")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AlexElLaeon")]
[assembly: AssemblyTitle("AlexElLaeon")]
[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.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]
	[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;
		}
	}
	[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 AlexElLaeon
{
	[BepInPlugin("JLeonL.AlexElLaeon", "Alex el Laeon", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class AlexElLaeonPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "JLeonL.AlexElLaeon";

		public const string PluginName = "Alex el Laeon";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static AssetBundle Bundle;

		internal static GameObject AlexPrefab;

		internal static ConfigEntry<float> FirstPersonHandScale;

		internal static ConfigEntry<float> ModelVerticalOffset;

		private ConfigEntry<bool> replaceEveryPlayer;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			replaceEveryPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("Testing", "ReplaceEveryPlayer", false, "Replace every player with Alex el Laeon. Leave disabled to use the selectable suit.");
			FirstPersonHandScale = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "FirstPersonHandScale", 0.5f, "Scale applied only to Alex's hands in first person. Does not change the full model.");
			ModelVerticalOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "ModelVerticalOffset", -0.35f, "Vertical offset for Alex's full body. Negative values lower the model without moving the camera or collider.");
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "alexellaeonassets");
			Bundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)Bundle == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not load Alex el Laeon AssetBundle: " + text));
				return;
			}
			AlexPrefab = Bundle.LoadAsset<GameObject>("AlexElLaeonModel");
			if ((Object)(object)AlexPrefab == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"AssetBundle did not contain AlexElLaeonModel.");
				return;
			}
			PreparePrefab(AlexPrefab);
			if (replaceEveryPlayer.Value)
			{
				ModelReplacementAPI.RegisterModelReplacementOverride(typeof(AlexElLaeonBodyReplacement));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered Alex el Laeon as the global player model replacement for testing.");
			}
			else
			{
				ModelReplacementAPI.RegisterSuitModelReplacement("Alex el Laeon", typeof(AlexElLaeonBodyReplacement));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered Alex el Laeon for the suit named Alex el Laeon.");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Alex el Laeon 1.0.0 loaded.");
		}

		private static void PreparePrefab(GameObject prefab)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			Animator componentInChildren = prefab.GetComponentInChildren<Animator>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				throw new InvalidOperationException("AlexElLaeonModel has no Animator.");
			}
			if ((Object)(object)componentInChildren.avatar == (Object)null || !componentInChildren.avatar.isValid || !componentInChildren.avatar.isHuman)
			{
				throw new InvalidOperationException("AlexElLaeonModel does not contain a valid humanoid Avatar.");
			}
			OffsetBuilder obj = ((Component)componentInChildren).GetComponent<OffsetBuilder>() ?? ((Component)componentInChildren).gameObject.AddComponent<OffsetBuilder>();
			float num = Mathf.Clamp(ModelVerticalOffset.Value, -0.8f, 0.1f);
			obj.rootPositionOffset = new Vector3(0f, num, 0f);
			obj.rootScale = Vector3.one;
			obj.itemPositonOffset = Vector3.zero;
			obj.itemRotationOffset = Quaternion.identity;
			obj.UseNoPostProcessing = false;
			obj.GenerateViewModel = true;
			obj.RemoveHelmet = true;
			Log.LogInfo((object)("Prepared Alex el Laeon humanoid prefab. " + $"Renderers={prefab.GetComponentsInChildren<Renderer>(true).Length}; " + $"avatar={((Object)componentInChildren.avatar).name}; verticalOffset={num:0.000}"));
		}
	}
	public sealed class AlexElLaeonBodyReplacement : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			if ((Object)(object)AlexElLaeonPlugin.AlexPrefab == (Object)null)
			{
				throw new InvalidOperationException("Alex el Laeon prefab is not loaded.");
			}
			return AlexElLaeonPlugin.AlexPrefab;
		}

		protected override ViewModelUpdater GetViewModelUpdater()
		{
			return (ViewModelUpdater)(object)new AlexElLaeonViewModelUpdater();
		}
	}
	public sealed class AlexElLaeonViewModelUpdater : ViewModelUpdater
	{
		public override void AssignViewModelReplacement(GameObject player, GameObject replacementViewModel)
		{
			((ViewModelUpdater)this).AssignViewModelReplacement(player, replacementViewModel);
			float num = Mathf.Clamp(AlexElLaeonPlugin.FirstPersonHandScale.Value, 0.2f, 1f);
			ScaleHand(((ViewModelUpdater)this).GetViewModelTransformFromBoneName("hand.L"), num);
			ScaleHand(((ViewModelUpdater)this).GetViewModelTransformFromBoneName("hand.R"), num);
			AlexElLaeonPlugin.Log.LogInfo((object)$"Applied first-person hand scale: {num:0.00}");
		}

		private static void ScaleHand(Transform hand, float scale)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)hand != (Object)null)
			{
				hand.localScale = Vector3.one * scale;
			}
		}
	}
}