Decompiled source of PlayerDogModel v1.1.0

PlayerDogModel.dll

Decompiled 2 years ago
using System;
using System.Collections;
using System.Collections.Generic;
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 BepInEx;
using BepInEx.Bootstrap;
using GameNetcodeStuff;
using HarmonyLib;
using LC_API.BundleAPI;
using LC_API.Networking;
using Microsoft.CodeAnalysis;
using MoreCompany;
using MoreCompany.Cosmetics;
using Newtonsoft.Json;
using PlayerDogModel.Patches;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;

[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("PlayerDogModel")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod to replace Player models with a dog for Lethal Company")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+5631379053541318a351f425fcd289d14042a223")]
[assembly: AssemblyProduct("PlayerDogModel")]
[assembly: AssemblyTitle("PlayerDogModel")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.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 PlayerDogModel
{
	internal static class Networking
	{
		public const string ModelSwitchMessageName = "modelswitch";

		public const string ModelInfoMessageName = "modelinfo";

		public static void Initialize()
		{
			Network.RegisterMessage<PlayerModelReplacer.ToggleData>("modelswitch", false, (Action<ulong, PlayerModelReplacer.ToggleData>)HandleModelSwitchMessage);
			Network.RegisterMessage("modelinfo", false, (Action<ulong>)HandleModelInfoMessage);
		}

		private static void HandleModelSwitchMessage(ulong senderId, PlayerModelReplacer.ToggleData toggleData)
		{
			Debug.Log((object)(string.Format("Got {0} network message from {1}: {{ ", "modelswitch", senderId) + string.Format("{0} = {1}, ", "playerClientId", toggleData.playerClientId) + string.Format("{0} = {1}, ", "playAudio", toggleData.playAudio) + string.Format("{0} = {1} ", "isDog", toggleData.isDog) + "}}"));
			PlayerModelReplacer playerModelReplacer = null;
			GameObject[] allPlayerObjects = StartOfRound.Instance.allPlayerObjects;
			foreach (GameObject val in allPlayerObjects)
			{
				PlayerModelReplacer component = val.GetComponent<PlayerModelReplacer>();
				if ((Object)(object)component != (Object)null && component.PlayerClientId == toggleData.playerClientId)
				{
					playerModelReplacer = component;
					break;
				}
			}
			if ((Object)(object)playerModelReplacer == (Object)null)
			{
				Debug.LogWarning((object)string.Format("{0} message from client {1} will be ignored because replacer with this ID is not registered", "modelswitch", senderId));
				return;
			}
			if (!playerModelReplacer.IsValid)
			{
				Debug.LogError((object)"Dog encountered an error when it was initialized and it can't be toggled. Check the log for more info.");
				return;
			}
			Debug.Log((object)$"Received dog={toggleData.isDog} for {playerModelReplacer.PlayerClientId} ({playerModelReplacer.PlayerUsername}).");
			if (toggleData.isDog)
			{
				playerModelReplacer.EnableDogModel(toggleData.playAudio);
			}
			else
			{
				playerModelReplacer.EnableHumanModel(toggleData.playAudio);
			}
		}

		private static void HandleModelInfoMessage(ulong senderId)
		{
			Debug.Log((object)string.Format("Got {0} network message from {1}", "modelinfo", senderId));
			GameObject[] allPlayerObjects = StartOfRound.Instance.allPlayerObjects;
			foreach (GameObject val in allPlayerObjects)
			{
				PlayerModelReplacer component = val.GetComponent<PlayerModelReplacer>();
				if ((Object)(object)component != (Object)null)
				{
					component.BroadcastSelectedModel(playAudio: false);
				}
			}
		}
	}
	[DefaultExecutionOrder(-1)]
	public class PlayerModelReplacer : MonoBehaviour
	{
		[JsonObject]
		internal class ToggleData
		{
			[JsonProperty]
			public ulong playerClientId { get; set; }

			[JsonProperty]
			public bool isDog { get; set; }

			[JsonProperty]
			public bool playAudio { get; set; }
		}

		public static PlayerModelReplacer LocalReplacer;

		private static bool loaded;

		private static string exceptionMessage;

		private static Exception exception;

		private PlayerControllerB playerController;

		private GameObject dogGameObject;

		private GameObject[] humanGameObjects;

		private SkinnedMeshRenderer[] dogRenderers;

		private Transform dogTorso;

		private PositionConstraint torsoConstraint;

		private static AudioClip humanClip;

		private static AudioClip dogClip;

		private Vector3 humanCameraPosition;

		private Transform localItemAnchor;

		private Transform serverItemAnchor;

		private static Image healthFill;

		private static Image healthOutline;

		private static Sprite humanFill;

		private static Sprite humanOutline;

		private static Sprite dogFill;

		private static Sprite dogOutline;

		private bool isDogActive;

		public ulong PlayerClientId => ((Object)(object)playerController != (Object)null) ? playerController.playerClientId : ulong.MaxValue;

		public string PlayerUsername => ((Object)(object)playerController != (Object)null) ? playerController.playerUsername : "";

		public bool IsValid => (Object)(object)dogGameObject != (Object)null;

		public bool IsDog => isDogActive;

		private void Awake()
		{
			if (!loaded)
			{
				loaded = true;
				LoadImageResources();
				((MonoBehaviour)this).StartCoroutine(LoadAudioResources());
			}
		}

		private void Start()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			playerController = ((Component)this).GetComponent<PlayerControllerB>();
			if (((NetworkBehaviour)playerController).IsOwner)
			{
				LocalReplacer = this;
			}
			humanCameraPosition = ((Component)playerController.gameplayCamera).transform.localPosition;
			Debug.Log((object)$"Adding PlayerModelReplacer on {playerController.playerUsername} ({((NetworkBehaviour)playerController).IsOwner})");
			SpawnDogModel();
			EnableHumanModel(playAudio: false);
		}

		private void Update()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			if (!string.IsNullOrEmpty(exceptionMessage))
			{
				return;
			}
			Vector3 val = humanCameraPosition;
			if (isDogActive && !playerController.inTerminalMenu && !playerController.inSpecialInteractAnimation)
			{
				if (!playerController.isCrouching)
				{
					((Vector3)(ref val))..ctor(0f, -1.1f, 0.3f);
				}
				else
				{
					((Vector3)(ref val))..ctor(0f, -0.5f, 0.3f);
				}
			}
			((Component)playerController.gameplayCamera).transform.localPosition = Vector3.MoveTowards(((Component)playerController.gameplayCamera).transform.localPosition, val, Time.deltaTime * 2f);
			if (playerController.isCrouching)
			{
				torsoConstraint.weight = Mathf.MoveTowards(torsoConstraint.weight, 0.5f, Time.deltaTime * 3f);
			}
			else
			{
				torsoConstraint.weight = Mathf.MoveTowards(torsoConstraint.weight, 1f, Time.deltaTime * 3f);
			}
			if (playerController.isClimbingLadder)
			{
				dogTorso.localRotation = Quaternion.RotateTowards(dogTorso.localRotation, Quaternion.Euler(90f, 0f, 0f), Time.deltaTime * 360f);
			}
			else
			{
				dogTorso.localRotation = Quaternion.RotateTowards(dogTorso.localRotation, Quaternion.Euler(180f, 0f, 0f), Time.deltaTime * 360f);
			}
		}

		private void LateUpdate()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)localItemAnchor == (Object)null) && !((Object)(object)serverItemAnchor == (Object)null))
			{
				if (isDogActive)
				{
					playerController.localItemHolder.position = localItemAnchor.position;
					playerController.serverItemHolder.position = serverItemAnchor.position;
				}
				if (((Renderer)dogRenderers[0]).shadowCastingMode != ((Renderer)playerController.thisPlayerModel).shadowCastingMode)
				{
					Debug.Log((object)$"Dog model is on the wrong shadow casting mode. ({((Renderer)dogRenderers[0]).shadowCastingMode} instead of {((Renderer)playerController.thisPlayerModel).shadowCastingMode})");
					((Renderer)dogRenderers[0]).shadowCastingMode = ((Renderer)playerController.thisPlayerModel).shadowCastingMode;
				}
				if (((Component)dogRenderers[0]).gameObject.layer != ((Component)playerController.thisPlayerModel).gameObject.layer)
				{
					Debug.Log((object)("Dog model is on the wrong layer. (" + LayerMask.LayerToName(((Component)dogRenderers[0]).gameObject.layer) + " instead of " + LayerMask.LayerToName(((Component)playerController.thisPlayerModel).gameObject.layer) + ")"));
					((Component)dogRenderers[0]).gameObject.layer = ((Component)playerController.thisPlayerModel).gameObject.layer;
				}
			}
		}

		private void SpawnDogModel()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_045e: Unknown result type (might be due to invalid IL or missing references)
			//IL_048d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0502: Unknown result type (might be due to invalid IL or missing references)
			//IL_050e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GameObject loadedAsset = BundleLoader.GetLoadedAsset<GameObject>("assets/Dog.fbx");
				dogGameObject = Object.Instantiate<GameObject>(loadedAsset, ((Component)this).transform);
				dogGameObject.transform.position = ((Component)this).transform.position;
				dogGameObject.transform.eulerAngles = ((Component)this).transform.eulerAngles;
				Transform transform = dogGameObject.transform;
				transform.localScale *= 2f;
			}
			catch (Exception ex)
			{
				exceptionMessage = "Failed to spawn dog model.";
				exception = ex;
				Debug.LogError((object)exceptionMessage);
				Debug.LogException(exception);
			}
			dogRenderers = dogGameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
			UpdateMaterial();
			try
			{
				LODGroup val = dogGameObject.AddComponent<LODGroup>();
				val.fadeMode = (LODFadeMode)0;
				LOD val2 = default(LOD);
				val2.screenRelativeTransitionHeight = 0.4564583f;
				val2.renderers = (Renderer[])(object)new Renderer[1] { (Renderer)dogRenderers[0] };
				val2.fadeTransitionWidth = 0f;
				LOD val3 = val2;
				val2 = default(LOD);
				val2.screenRelativeTransitionHeight = 0.1795709f;
				val2.renderers = (Renderer[])(object)new Renderer[1] { (Renderer)dogRenderers[1] };
				val2.fadeTransitionWidth = 0f;
				LOD val4 = val2;
				val2 = default(LOD);
				val2.screenRelativeTransitionHeight = 0.009000001f;
				val2.renderers = (Renderer[])(object)new Renderer[1] { (Renderer)dogRenderers[2] };
				val2.fadeTransitionWidth = 0.435f;
				LOD val5 = val2;
				val.SetLODs((LOD[])(object)new LOD[3] { val3, val4, val5 });
			}
			catch (Exception ex2)
			{
				exceptionMessage = "Failed to set up the LOD.";
				exception = ex2;
				Debug.LogError((object)exceptionMessage);
				Debug.LogException(exception);
			}
			try
			{
				dogTorso = dogGameObject.transform.Find("Armature").Find("torso");
				Transform val6 = dogTorso.Find("head");
				Transform val7 = dogTorso.Find("arm.L");
				Transform val8 = dogTorso.Find("arm.R");
				Transform val9 = dogTorso.Find("butt").Find("leg.L");
				Transform val10 = dogTorso.Find("butt").Find("leg.R");
				Transform val11 = ((Component)this).transform.Find("ScavengerModel").Find("metarig").Find("spine");
				Transform sourceTransform = val11.Find("spine.001").Find("spine.002").Find("spine.003")
					.Find("spine.004");
				Transform sourceTransform2 = val11.Find("thigh.L");
				Transform sourceTransform3 = val11.Find("thigh.R");
				try
				{
					torsoConstraint = ((Component)dogTorso).gameObject.AddComponent<PositionConstraint>();
					PositionConstraint obj = torsoConstraint;
					ConstraintSource val12 = default(ConstraintSource);
					((ConstraintSource)(ref val12)).sourceTransform = val11;
					((ConstraintSource)(ref val12)).weight = 1f;
					obj.AddSource(val12);
					torsoConstraint.translationAtRest = dogTorso.localPosition;
					torsoConstraint.translationOffset = dogTorso.InverseTransformPoint(val11.position);
					torsoConstraint.constraintActive = true;
					torsoConstraint.locked = true;
					RotationConstraint val13 = ((Component)val6).gameObject.AddComponent<RotationConstraint>();
					val12 = default(ConstraintSource);
					((ConstraintSource)(ref val12)).sourceTransform = sourceTransform;
					((ConstraintSource)(ref val12)).weight = 1f;
					val13.AddSource(val12);
					val13.rotationAtRest = val6.localEulerAngles;
					val13.constraintActive = true;
					val13.locked = true;
					RotationConstraint val14 = ((Component)val7).gameObject.AddComponent<RotationConstraint>();
					val12 = default(ConstraintSource);
					((ConstraintSource)(ref val12)).sourceTransform = sourceTransform3;
					((ConstraintSource)(ref val12)).weight = 1f;
					val14.AddSource(val12);
					val14.rotationAtRest = val7.localEulerAngles;
					val14.constraintActive = true;
					val14.locked = true;
					RotationConstraint val15 = ((Component)val8).gameObject.AddComponent<RotationConstraint>();
					val12 = default(ConstraintSource);
					((ConstraintSource)(ref val12)).sourceTransform = sourceTransform2;
					((ConstraintSource)(ref val12)).weight = 1f;
					val15.AddSource(val12);
					val15.rotationAtRest = val8.localEulerAngles;
					val15.constraintActive = true;
					val15.locked = true;
					RotationConstraint val16 = ((Component)val9).gameObject.AddComponent<RotationConstraint>();
					val12 = default(ConstraintSource);
					((ConstraintSource)(ref val12)).sourceTransform = sourceTransform2;
					((ConstraintSource)(ref val12)).weight = 1f;
					val16.AddSource(val12);
					val16.rotationAtRest = val9.localEulerAngles;
					val16.constraintActive = true;
					val16.locked = true;
					RotationConstraint val17 = ((Component)val10).gameObject.AddComponent<RotationConstraint>();
					val12 = default(ConstraintSource);
					((ConstraintSource)(ref val12)).sourceTransform = sourceTransform3;
					((ConstraintSource)(ref val12)).weight = 1f;
					val17.AddSource(val12);
					val17.rotationAtRest = val10.localEulerAngles;
					val17.constraintActive = true;
					val17.locked = true;
				}
				catch (Exception ex3)
				{
					exceptionMessage = "Failed to set up the constraints.";
					exception = ex3;
					Debug.LogError((object)exceptionMessage);
					Debug.LogException(exception);
				}
				serverItemAnchor = val6.Find("serverItem");
				localItemAnchor = val6.Find("localItem");
			}
			catch (Exception ex4)
			{
				exceptionMessage = "Failed to retrieve bones. What the hell?";
				exception = ex4;
				Debug.LogError((object)exceptionMessage);
				Debug.LogException(exception);
			}
			humanGameObjects = (GameObject[])(object)new GameObject[6];
			humanGameObjects[0] = ((Component)playerController.thisPlayerModel).gameObject;
			humanGameObjects[1] = ((Component)playerController.thisPlayerModelLOD1).gameObject;
			humanGameObjects[2] = ((Component)playerController.thisPlayerModelLOD2).gameObject;
			humanGameObjects[3] = ((Component)playerController.thisPlayerModelArms).gameObject;
			humanGameObjects[4] = ((Component)playerController.playerBetaBadgeMesh).gameObject;
			humanGameObjects[5] = ((Component)((Component)playerController.playerBetaBadgeMesh).transform.parent.Find("LevelSticker")).gameObject;
		}

		public void EnableHumanModel(bool playAudio = true)
		{
			isDogActive = false;
			dogGameObject.SetActive(false);
			GameObject[] array = humanGameObjects;
			foreach (GameObject val in array)
			{
				val.SetActive(true);
			}
			if (playAudio)
			{
				playerController.movementAudio.PlayOneShot(humanClip);
			}
			if (((NetworkBehaviour)playerController).IsOwner && Object.op_Implicit((Object)(object)healthFill))
			{
				healthFill.sprite = humanFill;
				healthOutline.sprite = humanOutline;
			}
			if (Chainloader.PluginInfos.ContainsKey("me.swipez.melonloader.morecompany"))
			{
				MoreCompanyPatch.ShowCosmeticsForPlayer(playerController);
			}
		}

		public void EnableDogModel(bool playAudio = true)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			isDogActive = true;
			dogGameObject.SetActive(true);
			((Renderer)dogRenderers[0]).shadowCastingMode = ((Renderer)playerController.thisPlayerModel).shadowCastingMode;
			GameObject[] array = humanGameObjects;
			foreach (GameObject val in array)
			{
				val.SetActive(false);
			}
			if (playAudio)
			{
				playerController.movementAudio.PlayOneShot(dogClip);
			}
			if (((NetworkBehaviour)playerController).IsOwner)
			{
				if (!Object.op_Implicit((Object)(object)healthFill))
				{
					healthFill = ((Component)HUDManager.Instance.selfRedCanvasGroup).GetComponent<Image>();
					healthOutline = ((Component)((Component)HUDManager.Instance.selfRedCanvasGroup).transform.parent.Find("Self")).GetComponent<Image>();
					humanFill = healthFill.sprite;
					humanOutline = healthOutline.sprite;
				}
				healthFill.sprite = dogFill;
				healthOutline.sprite = dogOutline;
			}
			if (Chainloader.PluginInfos.ContainsKey("me.swipez.melonloader.morecompany"))
			{
				MoreCompanyPatch.HideCosmeticsForPlayer(playerController);
			}
		}

		public void UpdateMaterial()
		{
			if (dogRenderers == null)
			{
				Debug.LogWarning((object)"Skipping material replacement on dog because there was an error earlier.");
				return;
			}
			SkinnedMeshRenderer[] array = dogRenderers;
			for (int i = 0; i < array.Length; i++)
			{
				Renderer val = (Renderer)(object)array[i];
				val.material = ((Renderer)playerController.thisPlayerModel).material;
			}
		}

		public void ToggleAndBroadcast(bool playAudio = true)
		{
			if (isDogActive)
			{
				EnableHumanModel();
			}
			else
			{
				EnableDogModel();
			}
			BroadcastSelectedModel(playAudio);
		}

		public void BroadcastSelectedModel(bool playAudio)
		{
			Debug.Log((object)$"Sent dog={isDogActive} on {playerController.playerClientId} ({playerController.playerUsername}).");
			ToggleData toggleData = new ToggleData
			{
				playerClientId = PlayerClientId,
				isDog = isDogActive,
				playAudio = playAudio
			};
			Network.Broadcast<ToggleData>("modelswitch", toggleData);
		}

		public static void RequestSelectedModelBroadcast()
		{
			Network.Broadcast("modelinfo");
		}

		private static void LoadImageResources()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			try
			{
				Texture2D loadedAsset = BundleLoader.GetLoadedAsset<Texture2D>("assets/TPoseFilled.png");
				dogFill = Sprite.Create(loadedAsset, new Rect(0f, 0f, (float)((Texture)loadedAsset).width, (float)((Texture)loadedAsset).height), new Vector2(0.5f, 0.5f), 100f);
				Texture2D loadedAsset2 = BundleLoader.GetLoadedAsset<Texture2D>("assets/TPoseOutline.png");
				dogOutline = Sprite.Create(loadedAsset2, new Rect(0f, 0f, (float)((Texture)loadedAsset2).width, (float)((Texture)loadedAsset2).height), new Vector2(0.5f, 0.5f), 100f);
			}
			catch (Exception ex)
			{
				exceptionMessage = "Failed to retrieve images.";
				exception = ex;
				Debug.LogError((object)exceptionMessage);
				Debug.LogException(exception);
			}
		}

		private static IEnumerator LoadAudioResources()
		{
			string fullPath2 = GetAssemblyFullPath("ChangeSuitToHuman.wav");
			UnityWebRequest request2 = UnityWebRequestMultimedia.GetAudioClip(fullPath2, (AudioType)20);
			yield return request2.SendWebRequest();
			if (request2.error == null)
			{
				humanClip = DownloadHandlerAudioClip.GetContent(request2);
				((Object)humanClip).name = Path.GetFileName(fullPath2);
			}
			fullPath2 = GetAssemblyFullPath("ChangeSuitToDog.wav");
			request2 = UnityWebRequestMultimedia.GetAudioClip(fullPath2, (AudioType)20);
			yield return request2.SendWebRequest();
			if (request2.error == null)
			{
				dogClip = DownloadHandlerAudioClip.GetContent(request2);
				((Object)dogClip).name = Path.GetFileName(fullPath2);
			}
		}

		private static string GetAssemblyFullPath(string additionalPath)
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string path = ((additionalPath != null) ? Path.Combine(directoryName, ".\\" + additionalPath) : directoryName);
			return Path.GetFullPath(path);
		}
	}
	public class PlayerModelSwitcher : MonoBehaviour
	{
		private void Start()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			GameObject loadedAsset = BundleLoader.GetLoadedAsset<GameObject>("assets/Helmets.fbx");
			GameObject val = Object.Instantiate<GameObject>(loadedAsset, ((Component)this).transform);
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one * 0.75f;
			Renderer component = val.GetComponent<Renderer>();
			Material[] materials = component.materials;
			for (int i = 0; i < StartOfRound.Instance.unlockablesList.unlockables.Count; i++)
			{
				if (Object.op_Implicit((Object)(object)StartOfRound.Instance.unlockablesList.unlockables[0].suitMaterial))
				{
					materials[0] = StartOfRound.Instance.unlockablesList.unlockables[0].suitMaterial;
					break;
				}
			}
			materials[1] = ((Component)this).GetComponent<Renderer>().material;
			component.materials = materials;
			GameObject gameObject = ((Component)Object.Instantiate<ScanNodeProperties>(Object.FindObjectOfType<ScanNodeProperties>())).gameObject;
			gameObject.transform.parent = ((Component)this).transform;
			gameObject.transform.localPosition = new Vector3(0.75f, 0f, 0.8f);
			ScanNodeProperties component2 = gameObject.GetComponent<ScanNodeProperties>();
			component2.headerText = "Dog equipment";
			component2.subText = "Switch to the dog model here.";
			InteractTrigger componentInChildren = ((Component)GameObject.Find("SpeakerAudio").transform.parent).GetComponentInChildren<InteractTrigger>();
			InteractTrigger val2 = Object.Instantiate<InteractTrigger>(componentInChildren);
			((Component)val2).transform.position = ((Component)this).transform.TransformPoint(new Vector3(0.75f, 0f, 0.9f));
			((Component)val2).transform.localScale = new Vector3(0.3f, 0.7f, 0.3f);
			val2.hoverTip = "Switch model";
			val2.interactable = true;
			val2.cooldownTime = 1f;
			((UnityEventBase)val2.onCancelAnimation).RemoveAllListeners();
			((UnityEventBase)val2.onInteractEarly).RemoveAllListeners();
			((UnityEventBase)val2.onStopInteract).RemoveAllListeners();
			((UnityEventBase)val2.onInteract).RemoveAllListeners();
			((UnityEvent<PlayerControllerB>)(object)val2.onInteract).AddListener((UnityAction<PlayerControllerB>)Interacted);
		}

		private void Interacted(PlayerControllerB player)
		{
			((Component)player).GetComponentInChildren<PlayerModelReplacer>().ToggleAndBroadcast();
		}
	}
	[BepInPlugin("PlayerDogModel", "PlayerDogModel", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PlayerControllerB))]
		internal class PlayerControllerBPatch
		{
			[HarmonyPatch("SpawnPlayerAnimation")]
			[HarmonyPostfix]
			public static void SpawnPlayerAnimationPatch(ref PlayerControllerB __instance)
			{
				GameObject[] allPlayerObjects = StartOfRound.Instance.allPlayerObjects;
				foreach (GameObject val in allPlayerObjects)
				{
					if (!Object.op_Implicit((Object)(object)val.GetComponent<PlayerModelReplacer>()))
					{
						val.gameObject.AddComponent<PlayerModelReplacer>();
					}
				}
				PlayerModelReplacer.RequestSelectedModelBroadcast();
			}
		}

		[HarmonyPatch(typeof(StartOfRound))]
		internal class StartOfRoundPatch
		{
			[HarmonyPatch("PositionSuitsOnRack")]
			[HarmonyPostfix]
			public static void PositionSuitsOnRackPatch(ref StartOfRound __instance)
			{
				PlayerModelSwitcher playerModelSwitcher = Object.FindObjectOfType<PlayerModelSwitcher>();
				if (!Object.op_Implicit((Object)(object)playerModelSwitcher))
				{
					GameObject val = GameObject.Find("NurbsPath.002");
					val.AddComponent<PlayerModelSwitcher>();
				}
			}
		}

		[HarmonyPatch(typeof(UnlockableSuit))]
		internal class UnlockableSuitPatch
		{
			[HarmonyPatch("SwitchSuitForPlayer")]
			[HarmonyPostfix]
			public static void SwitchSuitForPlayerPatch(PlayerControllerB player, int suitID, bool playAudio = true)
			{
				PlayerModelReplacer component = ((Component)player).GetComponent<PlayerModelReplacer>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.UpdateMaterial();
				}
			}
		}

		[HarmonyPatch(typeof(DeadBodyInfo))]
		internal class DeadBodyPatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPostfix]
			public static void StartPatch(ref DeadBodyInfo __instance)
			{
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0130: Unknown result type (might be due to invalid IL or missing references)
				//IL_013a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0201: Unknown result type (might be due to invalid IL or missing references)
				//IL_021d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0229: Unknown result type (might be due to invalid IL or missing references)
				//IL_0258: Unknown result type (might be due to invalid IL or missing references)
				//IL_0275: Unknown result type (might be due to invalid IL or missing references)
				//IL_0281: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0308: Unknown result type (might be due to invalid IL or missing references)
				//IL_0325: Unknown result type (might be due to invalid IL or missing references)
				//IL_0331: 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_037d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0389: Unknown result type (might be due to invalid IL or missing references)
				if (((Component)__instance.playerScript).GetComponent<PlayerModelReplacer>().IsDog)
				{
					SkinnedMeshRenderer component = ((Component)__instance).GetComponent<SkinnedMeshRenderer>();
					((Renderer)component).enabled = false;
					Material material = ((Renderer)component).material;
					Transform val = ((Component)__instance).transform.Find("spine.001");
					Transform sourceTransform = val.Find("spine.002").Find("spine.003").Find("spine.004");
					Transform sourceTransform2 = val.Find("spine.002").Find("spine.003").Find("shoulder.L")
						.Find("arm.L_upper");
					Transform sourceTransform3 = val.Find("spine.002").Find("spine.003").Find("shoulder.R")
						.Find("arm.R_upper");
					Transform sourceTransform4 = val.Find("thigh.L");
					Transform sourceTransform5 = val.Find("thigh.R");
					GameObject loadedAsset = BundleLoader.GetLoadedAsset<GameObject>("assets/DogRagdoll.fbx");
					GameObject val2 = Object.Instantiate<GameObject>(loadedAsset, ((Component)__instance).transform);
					val2.transform.position = ((Component)__instance).transform.position;
					val2.transform.eulerAngles = ((Component)__instance).transform.eulerAngles;
					Transform transform = val2.transform;
					transform.localScale *= 1.8f;
					SkinnedMeshRenderer[] componentsInChildren = val2.GetComponentsInChildren<SkinnedMeshRenderer>();
					SkinnedMeshRenderer[] array = componentsInChildren;
					foreach (SkinnedMeshRenderer val3 in array)
					{
						((Renderer)val3).material = material;
					}
					Transform val4 = val2.transform.Find("Armature").Find("torso");
					Transform val5 = val4.Find("head");
					Transform val6 = val4.Find("arm.L");
					Transform val7 = val4.Find("arm.R");
					Transform val8 = val4.Find("butt").Find("leg.L");
					Transform val9 = val4.Find("butt").Find("leg.R");
					RotationConstraint val10 = ((Component)val5).gameObject.AddComponent<RotationConstraint>();
					ConstraintSource val11 = default(ConstraintSource);
					((ConstraintSource)(ref val11)).sourceTransform = sourceTransform;
					((ConstraintSource)(ref val11)).weight = 1f;
					val10.AddSource(val11);
					val10.rotationAtRest = val5.localEulerAngles;
					val10.constraintActive = true;
					val10.locked = true;
					RotationConstraint val12 = ((Component)val6).gameObject.AddComponent<RotationConstraint>();
					val11 = default(ConstraintSource);
					((ConstraintSource)(ref val11)).sourceTransform = sourceTransform3;
					((ConstraintSource)(ref val11)).weight = 1f;
					val12.AddSource(val11);
					val12.rotationAtRest = val6.localEulerAngles;
					val12.constraintActive = true;
					val12.locked = true;
					RotationConstraint val13 = ((Component)val7).gameObject.AddComponent<RotationConstraint>();
					val11 = default(ConstraintSource);
					((ConstraintSource)(ref val11)).sourceTransform = sourceTransform2;
					((ConstraintSource)(ref val11)).weight = 1f;
					val13.AddSource(val11);
					val13.rotationAtRest = val7.localEulerAngles;
					val13.constraintActive = true;
					val13.locked = true;
					RotationConstraint val14 = ((Component)val8).gameObject.AddComponent<RotationConstraint>();
					val11 = default(ConstraintSource);
					((ConstraintSource)(ref val11)).sourceTransform = sourceTransform4;
					((ConstraintSource)(ref val11)).weight = 1f;
					val14.AddSource(val11);
					val14.rotationAtRest = val8.localEulerAngles;
					val14.constraintActive = true;
					val14.locked = true;
					RotationConstraint val15 = ((Component)val9).gameObject.AddComponent<RotationConstraint>();
					val11 = default(ConstraintSource);
					((ConstraintSource)(ref val11)).sourceTransform = sourceTransform5;
					((ConstraintSource)(ref val11)).weight = 1f;
					val15.AddSource(val11);
					val15.rotationAtRest = val9.localEulerAngles;
					val15.constraintActive = true;
					val15.locked = true;
				}
			}
		}

		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("PlayerDogModel");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PlayerDogModel loaded");
			Networking.Initialize();
			BundleLoader.LoadAssetBundle(GetAssemblyFullPath("playerdog"), true);
		}

		private static string GetAssemblyFullPath(string additionalPath)
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string path = ((additionalPath != null) ? Path.Combine(directoryName, ".\\" + additionalPath) : directoryName);
			return Path.GetFullPath(path);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "PlayerDogModel";

		public const string PLUGIN_NAME = "PlayerDogModel";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace PlayerDogModel.Patches
{
	public static class MoreCompanyPatch
	{
		public static void HideCosmeticsForPlayer(PlayerControllerB playerController)
		{
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			CosmeticApplication componentInChildren = ((Component)playerController.meshContainer).GetComponentInChildren<CosmeticApplication>();
			Debug.Log((object)string.Format("{0}: {1}'s cosmetic application's instance ID was {2}", "PlayerDogModel", playerController.playerUsername, ((Object)componentInChildren).GetInstanceID()));
			if ((Object)(object)componentInChildren == (Object)null)
			{
				Debug.Log((object)("PlayerDogModel: " + playerController.playerUsername + "'s cosmetic application's instance was null!"));
				return;
			}
			componentInChildren.ClearCosmetics();
			List<string> list = MainClass.playerIdsAndCosmetics[(int)playerController.playerClientId];
			foreach (string item in list)
			{
				Debug.Log((object)("PlayerDogModel: Disabling " + playerController.playerUsername + "'s " + item + "..."));
				componentInChildren.ApplyCosmetic(item, false);
			}
			componentInChildren.RefreshAllCosmeticPositions();
			foreach (CosmeticInstance spawnedCosmetic in componentInChildren.spawnedCosmetics)
			{
				Transform transform = ((Component)spawnedCosmetic).transform;
				transform.localScale *= 0.38f;
			}
		}

		public static void ShowCosmeticsForPlayer(PlayerControllerB playerController)
		{
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			CosmeticApplication componentInChildren = ((Component)playerController.meshContainer).GetComponentInChildren<CosmeticApplication>();
			Debug.Log((object)string.Format("{0}: {1}'s cosmetic application's instance ID was {2}", "PlayerDogModel", playerController.playerUsername, ((Object)componentInChildren).GetInstanceID()));
			if ((Object)(object)componentInChildren == (Object)null)
			{
				Debug.Log((object)("PlayerDogModel: " + playerController.playerUsername + "'s cosmetic application's instance was null!"));
				return;
			}
			componentInChildren.ClearCosmetics();
			List<string> list = MainClass.playerIdsAndCosmetics[(int)playerController.playerClientId];
			foreach (string item in list)
			{
				Debug.Log((object)("PlayerDogModel: Enabling " + playerController.playerUsername + "'s " + item + "..."));
				componentInChildren.ApplyCosmetic(item, true);
			}
			componentInChildren.RefreshAllCosmeticPositions();
			foreach (CosmeticInstance spawnedCosmetic in componentInChildren.spawnedCosmetics)
			{
				Transform transform = ((Component)spawnedCosmetic).transform;
				transform.localScale *= 0.38f;
			}
		}
	}
}