Decompiled source of AmogusModels v1.1.0

BepInEx/plugins/AmogusModels.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AmogusModels.Utils;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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: AssemblyCompany("AmogusModels")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Increase the max players in Lethal Company")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("AmogusModels")]
[assembly: AssemblyTitle("AmogusModels")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 AmogusModels
{
	public class AmogusController : MonoBehaviour
	{
		private GameObject amogusObj = null;

		private void Start()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Expected O, but got Unknown
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Expected O, but got Unknown
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Expected O, but got Unknown
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Expected O, but got Unknown
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).gameObject.GetComponentInChildren<LODGroup>().enabled = false;
			SkinnedMeshRenderer[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
			SkinnedMeshRenderer[] array = componentsInChildren;
			foreach (SkinnedMeshRenderer val in array)
			{
				((Renderer)val).enabled = false;
			}
			GameObject val2 = Object.Instantiate<GameObject>(Plugin.amogus);
			val2.transform.localScale = new Vector3(5f, 5f, 5f);
			Transform val3 = ((Component)this).gameObject.transform.Find("ScavengerModel").Find("metarig");
			Transform parent = val3.Find("spine").Find("spine.001");
			val2.transform.SetParent(parent);
			val2.transform.localPosition = new Vector3(0f, -1.3f, 0f);
			val2.transform.localEulerAngles = Vector3.zero;
			SkinnedMeshRenderer thisPlayerModel = ((Component)this).gameObject.GetComponent<PlayerControllerB>().thisPlayerModel;
			Shader shader = ((Renderer)thisPlayerModel).material.shader;
			SkinnedMeshRenderer componentInChildren = val2.GetComponentInChildren<SkinnedMeshRenderer>();
			SkinnedMeshRenderer componentInChildren2 = Plugin.amogusNoHands.GetComponentInChildren<SkinnedMeshRenderer>();
			((Renderer)componentInChildren).materials[0].shader = ((Renderer)componentInChildren2).materials[0].shader;
			((Renderer)componentInChildren).materials[0].color = new Color(0f, 0f, 0f);
			((Renderer)componentInChildren).materials[1].shader = shader;
			((Renderer)componentInChildren).materials[1].color = new Color(0.6f, 0.6f, 1f);
			((Renderer)componentInChildren).materials[2].shader = shader;
			((Renderer)componentInChildren).materials[2].color = new Color(1f, 0f, 0f);
			Animator componentInChildren3 = val2.GetComponentInChildren<Animator>();
			componentInChildren3.runtimeAnimatorController = Plugin.animController;
			IKController iKController = val2.AddComponent<IKController>();
			Transform val4 = val3.Find("spine").Find("thigh.L");
			Transform val5 = val3.Find("spine").Find("thigh.R");
			Transform val6 = val4.Find("shin.L");
			Transform val7 = val5.Find("shin.R");
			Transform val8 = val6.Find("foot.L");
			Transform val9 = val7.Find("foot.R");
			Transform val10 = val3.Find("spine").Find("spine.001").Find("spine.002")
				.Find("spine.003");
			Transform val11 = val10.Find("shoulder.L");
			Transform val12 = val10.Find("shoulder.R");
			Transform val13 = val11.Find("arm.L_upper");
			Transform val14 = val12.Find("arm.R_upper");
			Transform val15 = val13.Find("arm.L_lower");
			Transform val16 = val14.Find("arm.R_lower");
			Transform val17 = val15.Find("hand.L");
			Transform val18 = val16.Find("hand.R");
			GameObject val19 = new GameObject("IK Offset");
			val19.transform.SetParent(val8, false);
			val19.transform.localPosition = new Vector3(0f, -0.2327f, 0f);
			GameObject val20 = new GameObject("IK Offset");
			val20.transform.SetParent(val9, false);
			val20.transform.localPosition = new Vector3(0f, 0f, 0.2549f);
			GameObject val21 = new GameObject("IK Offset");
			val21.transform.SetParent(val17, false);
			val21.transform.localPosition = new Vector3(0.2093f, 0.0783f, 0.3309f);
			GameObject val22 = new GameObject("IK Offset");
			val22.transform.SetParent(val18, false);
			val22.transform.localPosition = new Vector3(-0.2343f, 0.0456f, 0.2964f);
			iKController.leftLegTarget = val19.transform;
			iKController.rightLegTarget = val20.transform;
			iKController.leftHandTarget = val21.transform;
			iKController.rightHandTarget = val22.transform;
			iKController.ikActive = true;
			amogusObj = val2;
		}

		private void LateUpdate()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)amogusObj != (Object)null)
			{
				amogusObj.transform.localPosition = new Vector3(0f, -0.45f, 0f);
				Transform val = ((Component)this).gameObject.transform.Find("ScavengerModel").Find("metarig");
				Transform val2 = val.Find("spine").Find("spine.001").Find("spine.002")
					.Find("spine.003");
				amogusObj.transform.Find("Armature").Find("Hips").Find("Spine")
					.Find("Chest")
					.localEulerAngles = val2.localEulerAngles;
			}
		}
	}
	public class IKController : MonoBehaviour
	{
		protected Animator animator;

		public bool ikActive = false;

		public Transform leftLegTarget = null;

		public Transform rightLegTarget = null;

		public Transform leftHandTarget = null;

		public Transform rightHandTarget = null;

		private void Start()
		{
			animator = ((Component)this).GetComponent<Animator>();
		}

		private void OnAnimatorIK()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)animator))
			{
				return;
			}
			if (ikActive)
			{
				if ((Object)(object)leftLegTarget != (Object)null)
				{
					animator.SetIKPositionWeight((AvatarIKGoal)0, 1f);
					animator.SetIKPosition((AvatarIKGoal)0, leftLegTarget.position);
					animator.SetIKRotation((AvatarIKGoal)0, leftLegTarget.rotation);
				}
				if ((Object)(object)rightLegTarget != (Object)null)
				{
					animator.SetIKPositionWeight((AvatarIKGoal)1, 1f);
					animator.SetIKPosition((AvatarIKGoal)1, rightLegTarget.position);
					animator.SetIKRotation((AvatarIKGoal)1, rightLegTarget.rotation);
				}
				if ((Object)(object)leftHandTarget != (Object)null)
				{
					animator.SetIKPositionWeight((AvatarIKGoal)2, 1f);
					animator.SetIKPosition((AvatarIKGoal)2, leftHandTarget.position);
					animator.SetIKRotation((AvatarIKGoal)2, leftHandTarget.rotation);
				}
				if ((Object)(object)rightHandTarget != (Object)null)
				{
					animator.SetIKPositionWeight((AvatarIKGoal)3, 1f);
					animator.SetIKPosition((AvatarIKGoal)3, rightHandTarget.position);
					animator.SetIKRotation((AvatarIKGoal)3, rightHandTarget.rotation);
				}
			}
			else
			{
				animator.SetIKPositionWeight((AvatarIKGoal)0, 0f);
				animator.SetIKRotationWeight((AvatarIKGoal)0, 0f);
				animator.SetIKPositionWeight((AvatarIKGoal)1, 0f);
				animator.SetIKRotationWeight((AvatarIKGoal)1, 0f);
				animator.SetIKPositionWeight((AvatarIKGoal)2, 0f);
				animator.SetIKRotationWeight((AvatarIKGoal)2, 0f);
				animator.SetIKPositionWeight((AvatarIKGoal)3, 0f);
				animator.SetIKRotationWeight((AvatarIKGoal)3, 0f);
			}
		}
	}
	[BepInPlugin("AmogusModels", "AmogusModels", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public static AssetBundle bundle;

		public static GameObject amogusNoHands;

		public static GameObject amogus;

		public static RuntimeAnimatorController animController;

		public static Harmony _harmony;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_harmony = new Harmony("AmogusModels");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Amogus 1");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"AmogusModels loaded");
			bundle = BundleUtilities.LoadBundleFromInternalAssembly("amogus");
			amogusNoHands = bundle.LoadPersistentAsset<GameObject>("Assets/Original/astronaut VRC 3.0.fbx");
			amogus = bundle.LoadPersistentAsset<GameObject>("Assets/amogus.fbx");
			animController = bundle.LoadPersistentAsset<RuntimeAnimatorController>("Assets/CrewmateController.controller");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Model 1: " + (((Object)(object)amogusNoHands == (Object)null) ? "null" : "not null")));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Model 2: " + (((Object)(object)amogus == (Object)null) ? "null" : "not null")));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Anim Controller: " + (((Object)(object)animController == (Object)null) ? "null" : "not null")));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "AmogusModels";

		public const string PLUGIN_NAME = "AmogusModels";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace AmogusModels.Utils
{
	public class BundleUtilities
	{
		public static byte[] GetResourceBytes(string filename)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			foreach (string text in manifestResourceNames)
			{
				if (!text.Contains(filename))
				{
					continue;
				}
				using Stream stream = executingAssembly.GetManifestResourceStream(text);
				if (stream == null)
				{
					return null;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				return array;
			}
			return null;
		}

		public static AssetBundle LoadBundleFromInternalAssembly(string filename)
		{
			return AssetBundle.LoadFromMemory(GetResourceBytes(filename));
		}
	}
	public static class AssetBundleExtension
	{
		public static T LoadPersistentAsset<T>(this AssetBundle bundle, string name) where T : Object
		{
			Object val = bundle.LoadAsset(name);
			if (val != (Object)null)
			{
				val.hideFlags = (HideFlags)32;
				return (T)(object)val;
			}
			return default(T);
		}
	}
}
namespace AmogusModels.Patches
{
	[HarmonyPatch]
	internal class PlayerObjects
	{
		public static void InitModels()
		{
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			Debug.Log((object)((Object)((Component)localPlayerController).gameObject).name);
			PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>();
			PlayerControllerB[] array2 = array;
			foreach (PlayerControllerB val in array2)
			{
				if (!((Object)(object)val == (Object)(object)localPlayerController))
				{
					((Component)val).gameObject.AddComponent<AmogusController>();
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "SpawnPlayerAnimation")]
		[HarmonyPostfix]
		public static void InitModel(ref PlayerControllerB __instance)
		{
			InitModels();
		}

		[HarmonyPatch(typeof(PlayerControllerB), "DisablePlayerModel")]
		[HarmonyPostfix]
		public static void DisablePlayerModel(ref PlayerControllerB __instance, GameObject playerObject)
		{
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)playerObject == (Object)(object)localPlayerController)
			{
				return;
			}
			playerObject.gameObject.GetComponentInChildren<LODGroup>().enabled = false;
			SkinnedMeshRenderer[] componentsInChildren = playerObject.gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
			SkinnedMeshRenderer[] array = componentsInChildren;
			foreach (SkinnedMeshRenderer val in array)
			{
				if (!(((Object)val).name == "Body"))
				{
					((Renderer)val).enabled = false;
				}
			}
		}
	}
}