Decompiled source of Tiruri v1.0.0

BepInEx\plugins\Tiruri\Tiruri.dll

Decompiled 7 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("Tiruri")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+bab747c202975323513eca2a8176e911d8bf262f")]
[assembly: AssemblyProduct("Tiruri")]
[assembly: AssemblyTitle("Tiruri")]
[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 Tiruri
{
	[BepInPlugin("JLeonL.Tiruri", "Tiruri", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class TiruriPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "JLeonL.Tiruri";

		public const string PluginName = "Tiruri";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static AssetBundle Bundle;

		internal static GameObject TiruriPrefab;

		internal static ConfigEntry<float> FirstPersonClawScale;

		private ConfigEntry<bool> replaceEveryPlayer;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			replaceEveryPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("Testing", "ReplaceEveryPlayer", false, "Replace every player with Tiruri. Leave disabled to use the selectable Tiruri suit.");
			FirstPersonClawScale = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "FirstPersonClawScale", 0.45f, "Scale applied only to Tiruri's claws in first person. Does not change the full third-person model.");
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "tiruriassets");
			Bundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)Bundle == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not load Tiruri AssetBundle: " + text));
				return;
			}
			TiruriPrefab = Bundle.LoadAsset<GameObject>("TiruriModel");
			if ((Object)(object)TiruriPrefab == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"AssetBundle did not contain a GameObject named TiruriModel.");
				return;
			}
			PreparePrefab(TiruriPrefab);
			if (replaceEveryPlayer.Value)
			{
				ModelReplacementAPI.RegisterModelReplacementOverride(typeof(TiruriBodyReplacement));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered Tiruri as the global player model replacement for testing.");
			}
			else
			{
				ModelReplacementAPI.RegisterSuitModelReplacement("Tiruri", typeof(TiruriBodyReplacement));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered Tiruri for the suit named Tiruri.");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Tiruri 1.0.0 loaded.");
		}

		private static void PreparePrefab(GameObject prefab)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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("TiruriModel has no Animator.");
			}
			if ((Object)(object)componentInChildren.avatar == (Object)null || !componentInChildren.avatar.isValid || !componentInChildren.avatar.isHuman)
			{
				throw new InvalidOperationException("TiruriModel does not contain a valid humanoid Avatar.");
			}
			OffsetBuilder obj = ((Component)componentInChildren).GetComponent<OffsetBuilder>() ?? ((Component)componentInChildren).gameObject.AddComponent<OffsetBuilder>();
			obj.rootPositionOffset = Vector3.zero;
			obj.rootScale = Vector3.one;
			obj.itemPositonOffset = Vector3.zero;
			obj.itemRotationOffset = Quaternion.identity;
			obj.UseNoPostProcessing = false;
			obj.GenerateViewModel = true;
			obj.RemoveHelmet = true;
			LoggerSafe($"Prepared Tiruri humanoid prefab. Renderers={prefab.GetComponentsInChildren<Renderer>(true).Length}; " + "avatar=" + ((Object)componentInChildren.avatar).name);
		}

		private static void LoggerSafe(string message)
		{
			if (Log != null)
			{
				Log.LogInfo((object)message);
			}
		}
	}
	public sealed class TiruriBodyReplacement : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			if ((Object)(object)TiruriPlugin.TiruriPrefab == (Object)null)
			{
				throw new InvalidOperationException("Tiruri prefab is not loaded.");
			}
			return TiruriPlugin.TiruriPrefab;
		}

		protected override ViewModelUpdater GetViewModelUpdater()
		{
			return (ViewModelUpdater)(object)new TiruriViewModelUpdater();
		}
	}
	public sealed class TiruriViewModelUpdater : ViewModelUpdater
	{
		public override void AssignViewModelReplacement(GameObject player, GameObject replacementViewModel)
		{
			((ViewModelUpdater)this).AssignViewModelReplacement(player, replacementViewModel);
			float num = Mathf.Clamp(TiruriPlugin.FirstPersonClawScale.Value, 0.2f, 1f);
			ScaleHand(((ViewModelUpdater)this).GetViewModelTransformFromBoneName("hand.L"), num);
			ScaleHand(((ViewModelUpdater)this).GetViewModelTransformFromBoneName("hand.R"), num);
			TiruriPlugin.Log.LogInfo((object)$"Applied first-person claw 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;
			}
		}
	}
}