Decompiled source of PlayerDogModel Plus v2.0.4

PlayerDogModel_Plus.dll

Decompiled 2 days 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 BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using MoreCompany;
using MoreCompany.Cosmetics;
using PlayerDogModel_Plus.Source.Config;
using PlayerDogModel_Plus.Source.Model;
using PlayerDogModel_Plus.Source.Networking;
using PlayerDogModel_Plus.Source.Patches.Core;
using PlayerDogModel_Plus.Source.Patches.Optional;
using PlayerDogModel_Plus.Source.Util;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;
using _3rdPerson;
using _3rdPerson.Helper;

[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("PlayerDogModel_Plus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("It's a doggie-dog world! Updated version of the original mod by MonAmiral!")]
[assembly: AssemblyFileVersion("2.0.4.0")]
[assembly: AssemblyInformationalVersion("2.0.4+668fc2ad226d0cd54f1cd5957ee47ac5474cd8c9")]
[assembly: AssemblyProduct("PlayerDogModel_Plus")]
[assembly: AssemblyTitle("PlayerDogModel_Plus")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.4.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_Plus
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "PlayerDogModel_Plus";

		public const string PLUGIN_NAME = "PlayerDogModel_Plus";

		public const string PLUGIN_VERSION = "2.0.4";
	}
}
namespace PlayerDogModel_Plus.Source
{
	[BepInPlugin("PlayerDogModel_Plus", "PlayerDogModel_Plus", "2.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Harmony harmony;

		internal static ManualLogSource logger;

		internal static bool isMoreCompanyLoaded;

		internal static bool isThirdPersonLoaded;

		internal static bool isMirageLoaded;

		internal static PluginConfig config { get; private set; }

		internal static AssetBundle assetBundle { get; private set; }

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			logger = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("PlayerDogModel_Plus");
			harmony.PatchAll(typeof(JetpackPatch));
			harmony.PatchAll(typeof(SnareFleaPatch));
			harmony.PatchAll(typeof(SpectateCameraPatch));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(UnlockableSuitPatch));
			harmony.PatchAll(typeof(DeadBodyPatch));
			harmony.PatchAll(typeof(BeltBagPatch));
			harmony.PatchAll(typeof(HauntedMaskPatch));
			harmony.PatchAll(typeof(MaskedPlayerEnemyPatch));
			harmony.PatchAll(typeof(FlowerSnakeEnemyPatch));
			logger.LogInfo((object)"loaded core patches...");
			if (Chainloader.PluginInfos.ContainsKey("me.swipez.melonloader.morecompany"))
			{
				isMoreCompanyLoaded = true;
				harmony.PatchAll(typeof(MoreCompanyPatch));
				logger.LogInfo((object)"loaded MoreCompany patches...");
			}
			if (Chainloader.PluginInfos.ContainsKey("verity.3rdperson"))
			{
				isThirdPersonLoaded = true;
				harmony.PatchAll(typeof(ThirdPersonPatch));
				logger.LogInfo((object)"loaded 3rdPerson patches...");
			}
			if (Chainloader.PluginInfos.ContainsKey("Mirage"))
			{
				logger.LogDebug((object)"detected Mirage...");
				isMirageLoaded = true;
			}
			logger.LogInfo((object)"PlayerDogModel_Plus loaded successfully! Woof!");
			config = new PluginConfig(((BaseUnityPlugin)this).Config);
			MessageHandler.Initialize();
			assetBundle = AssetBundle.LoadFromFile(GetAssemblyFullPath("playerdog"));
		}

		private static string GetAssemblyFullPath(string additionalPath)
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			return Path.GetFullPath((additionalPath != null) ? Path.Combine(directoryName, ".\\" + additionalPath) : directoryName);
		}
	}
}
namespace PlayerDogModel_Plus.Source.Util
{
	internal class DogModelConstraints
	{
		internal PositionConstraint torso;

		internal RotationConstraint head;

		internal RotationConstraint armL;

		internal RotationConstraint armR;

		internal RotationConstraint legL;

		internal RotationConstraint legR;
	}
	internal class DogModelMapper
	{
		internal static readonly string dogModelKey = "DogModel";

		internal static readonly string dogRagdollKey = "DogRagdoll";

		public static DogModelConstraints MapDogModelToHumanModel(GameObject dogGameObject, Transform humanModel)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			((Object)dogGameObject).name = dogModelKey;
			dogGameObject.transform.position = humanModel.position;
			dogGameObject.transform.eulerAngles = humanModel.eulerAngles;
			Transform transform = dogGameObject.transform;
			transform.localScale *= 2f;
			Transform val = dogGameObject.transform.Find("Armature").Find("torso");
			Transform val2 = val.Find("head");
			Transform val3 = val.Find("arm.L");
			Transform val4 = val.Find("arm.R");
			Transform val5 = val.Find("butt").Find("leg.L");
			Transform val6 = val.Find("butt").Find("leg.R");
			Transform val7 = humanModel.Find("ScavengerModel").Find("metarig").Find("spine");
			Transform humanSource = val7.Find("spine.001").Find("spine.002").Find("spine.003")
				.Find("spine.004");
			Transform humanSource2 = val7.Find("thigh.L");
			Transform humanSource3 = val7.Find("thigh.R");
			PositionConstraint val8 = ((Component)val).gameObject.AddComponent<PositionConstraint>();
			MapPositionConstraintToSource(val8, val7, val.localPosition, val.InverseTransformPoint(val7.position), 1f);
			RotationConstraint val9 = ((Component)val2).gameObject.AddComponent<RotationConstraint>();
			MapRotationConstraintToSource(val9, humanSource, val2.localEulerAngles, 1f);
			RotationConstraint val10 = ((Component)val3).gameObject.AddComponent<RotationConstraint>();
			MapRotationConstraintToSource(val10, humanSource3, val3.localEulerAngles, 1f);
			RotationConstraint val11 = ((Component)val4).gameObject.AddComponent<RotationConstraint>();
			MapRotationConstraintToSource(val11, humanSource2, val4.localEulerAngles, 1f);
			RotationConstraint val12 = ((Component)val5).gameObject.AddComponent<RotationConstraint>();
			MapRotationConstraintToSource(val12, humanSource2, val5.localEulerAngles, 1f);
			RotationConstraint val13 = ((Component)val6).gameObject.AddComponent<RotationConstraint>();
			MapRotationConstraintToSource(val13, humanSource3, val6.localEulerAngles, 1f);
			return new DogModelConstraints
			{
				torso = val8,
				head = val9,
				armL = val10,
				armR = val11,
				legL = val12,
				legR = val13
			};
		}

		public static void MapDogRagdollToHumanRagdoll(GameObject dogGameObject, Transform humanRagdoll)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			((Object)dogGameObject).name = dogRagdollKey;
			dogGameObject.transform.position = humanRagdoll.position;
			dogGameObject.transform.eulerAngles = humanRagdoll.eulerAngles;
			Transform transform = dogGameObject.transform;
			transform.localScale *= 1.8f;
			Transform val = dogGameObject.transform.Find("Armature").Find("torso");
			Transform val2 = val.Find("head");
			Transform val3 = val.Find("arm.L");
			Transform val4 = val.Find("arm.R");
			Transform val5 = val.Find("butt").Find("leg.L");
			Transform val6 = val.Find("butt").Find("leg.R");
			Transform val7 = humanRagdoll.Find("spine.001");
			Transform humanSource = val7.Find("spine.002").Find("spine.003").Find("spine.004");
			Transform humanSource2 = val7.Find("spine.002").Find("spine.003").Find("shoulder.L")
				.Find("arm.L_upper");
			Transform humanSource3 = val7.Find("spine.002").Find("spine.003").Find("shoulder.R")
				.Find("arm.R_upper");
			MapRotationConstraintToSource(((Component)val).gameObject.AddComponent<RotationConstraint>(), val7, val.localEulerAngles, 0.5f);
			MapRotationConstraintToSource(((Component)val2).gameObject.AddComponent<RotationConstraint>(), humanSource, val2.localEulerAngles, 0.5f);
			MapRotationConstraintToSource(((Component)val3).gameObject.AddComponent<RotationConstraint>(), humanSource3, val3.localEulerAngles, 0.5f);
			MapRotationConstraintToSource(((Component)val4).gameObject.AddComponent<RotationConstraint>(), humanSource2, val4.localEulerAngles, 0.5f);
			MapRotationConstraintToSource(((Component)val5).gameObject.AddComponent<RotationConstraint>(), humanSource2, val5.localEulerAngles, 0.5f);
			MapRotationConstraintToSource(((Component)val6).gameObject.AddComponent<RotationConstraint>(), humanSource3, val6.localEulerAngles, 0.5f);
		}

		private static void MapPositionConstraintToSource(PositionConstraint dogConstraint, Transform humanSource, Vector3 translationAtRest, Vector3 translationOffset, float weight)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			ConstraintSource val = default(ConstraintSource);
			((ConstraintSource)(ref val)).sourceTransform = humanSource;
			((ConstraintSource)(ref val)).weight = weight;
			dogConstraint.AddSource(val);
			dogConstraint.translationAtRest = translationAtRest;
			dogConstraint.translationOffset = translationOffset;
			dogConstraint.constraintActive = true;
			dogConstraint.locked = true;
		}

		private static void MapRotationConstraintToSource(RotationConstraint dogConstraint, Transform humanSource, Vector3 rotationAtRest, float weight)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			ConstraintSource val = default(ConstraintSource);
			((ConstraintSource)(ref val)).sourceTransform = humanSource;
			((ConstraintSource)(ref val)).weight = weight;
			dogConstraint.AddSource(val);
			dogConstraint.rotationAtRest = rotationAtRest;
			dogConstraint.constraintActive = true;
			dogConstraint.locked = true;
		}
	}
	internal sealed class ModelReplacerRetriever
	{
		internal static PlayerModelReplacer GetModelReplacerFromClientId(ulong clientId)
		{
			PlayerModelReplacer result = default(PlayerModelReplacer);
			if (((Component)PlayerRetriever.GetPlayerFromClientId(clientId)).TryGetComponent<PlayerModelReplacer>(ref result))
			{
				return result;
			}
			Plugin.logger.LogDebug((object)$"Couldn't find replacer with for player with clientId={clientId}!");
			return null;
		}
	}
	internal class PlayerRetriever
	{
		internal static PlayerControllerB GetPlayerFromClientId(ulong clientId)
		{
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (val.playerClientId == clientId)
				{
					return val;
				}
			}
			Plugin.logger.LogWarning((object)$"Couldn't find player with clientId={clientId}!");
			return null;
		}
	}
}
namespace PlayerDogModel_Plus.Source.Patches.Optional
{
	[HarmonyPatch(typeof(CosmeticPatches))]
	internal class MoreCompanyPatch
	{
		[HarmonyPatch("CloneCosmeticsToNonPlayer")]
		[HarmonyPrefix]
		public static bool CloneCosmeticsToNonPlayerPrefix(Transform cosmeticRoot, int playerClientId)
		{
			PlayerModelReplacer modelReplacerFromClientId = ModelReplacerRetriever.GetModelReplacerFromClientId((ulong)playerClientId);
			if ((Object)(object)modelReplacerFromClientId == (Object)null || !modelReplacerFromClientId.IsDog)
			{
				return true;
			}
			return false;
		}

		public static void HideCosmeticsForPlayer(PlayerControllerB playerController)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			CosmeticApplication componentInChildren = ((Component)playerController.meshContainer).GetComponentInChildren<CosmeticApplication>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return;
			}
			componentInChildren.ClearCosmetics();
			foreach (string item in MainClass.playerIdsAndCosmetics[(int)playerController.playerClientId])
			{
				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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			CosmeticApplication componentInChildren = ((Component)playerController.meshContainer).GetComponentInChildren<CosmeticApplication>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return;
			}
			componentInChildren.ClearCosmetics();
			foreach (string item in MainClass.playerIdsAndCosmetics[(int)playerController.playerClientId])
			{
				componentInChildren.ApplyCosmetic(item, true);
			}
			componentInChildren.RefreshAllCosmeticPositions();
			foreach (CosmeticInstance spawnedCosmetic in componentInChildren.spawnedCosmetics)
			{
				Transform transform = ((Component)spawnedCosmetic).transform;
				transform.localScale *= 0.38f;
			}
		}
	}
	[HarmonyPatch(typeof(ThirdPersonCamera))]
	internal class ThirdPersonPatch
	{
		[HarmonyPatch("ThirdPersonUpdate")]
		[HarmonyPrefix]
		private static bool ThirdPersonUpdatePrefix(ref Camera ____camera)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00b9: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.config.thirdPersonConfigOverride.Value)
			{
				return true;
			}
			PlayerControllerB controller = LocalPlayer.GetController();
			Camera gameplayCamera = controller.gameplayCamera;
			PlayerModelReplacer component = ((Component)controller).GetComponent<PlayerModelReplacer>();
			if ((Object)(object)component == (Object)null || !component.IsDog)
			{
				return true;
			}
			Vector3 val = ((Component)gameplayCamera).transform.forward * -1f;
			Vector3 val2 = ((Component)gameplayCamera).transform.TransformDirection(Vector3.right) * Plugin.config.thirdPersonRightOffset.Value;
			Vector3 val3 = Vector3.up * Plugin.config.thirdPersonUpOffset.Value;
			float value = Plugin.config.thirdPersonDistance.Value;
			((Component)____camera).transform.position = ((Component)gameplayCamera).transform.position + val * value + val2 + val3;
			((Component)____camera).transform.rotation = Quaternion.LookRotation(((Component)gameplayCamera).transform.forward);
			return false;
		}

		[HarmonyPatch("ThirdPersonOrbitUpdate")]
		[HarmonyPrefix]
		private static bool ThirdPersonOrbitUpdatePrefix(ref Camera ____camera)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.config.thirdPersonConfigOverride.Value)
			{
				return true;
			}
			PlayerControllerB controller = LocalPlayer.GetController();
			_ = controller.gameplayCamera;
			PlayerModelReplacer component = ((Component)controller).GetComponent<PlayerModelReplacer>();
			if ((Object)(object)component == (Object)null || !component.IsDog)
			{
				return true;
			}
			MovementActions movement = controller.playerActions.Movement;
			Vector2 val = ((MovementActions)(ref movement)).Look.ReadValue<Vector2>() * (0.008f * (float)IngamePlayerSettings.Instance.settings.lookSensitivity);
			if (IngamePlayerSettings.Instance.settings.invertYAxis)
			{
				val.y *= -1f;
			}
			((Component)____camera).transform.Rotate(Vector3.right, val.y * Plugin.OrbitSpeedEntry.Value * Time.deltaTime);
			((Component)____camera).transform.RotateAround(((Component)controller.gameplayCamera).transform.position, Vector3.up, val.x * Plugin.OrbitSpeedEntry.Value * Time.deltaTime);
			float value = Plugin.config.thirdPersonDistance.Value;
			((Component)____camera).transform.position = ((Component)controller.gameplayCamera).transform.position - ((Component)____camera).transform.forward * value;
			return false;
		}
	}
}
namespace PlayerDogModel_Plus.Source.Patches.Core
{
	[HarmonyPatch(typeof(BeltBagItem))]
	internal class BeltBagPatch
	{
		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		public static void LateUpdatePostfix(ref BeltBagItem __instance, PlayerControllerB ___playerHeldBy, bool ___isHeld, bool ___isPocketed)
		{
			//IL_0084: 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)
			//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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)___playerHeldBy != (Object)null && ___isHeld))
			{
				return;
			}
			PlayerModelReplacer component = ((Component)___playerHeldBy).GetComponent<PlayerModelReplacer>();
			if (!((Object)(object)component == (Object)null) && component.IsDog)
			{
				if (!___isPocketed)
				{
					((Component)__instance).transform.position = component.itemAnchor.position + component.itemAnchor.forward * 0.1f;
					return;
				}
				Transform val = component.GetDogGameObject().transform.Find("Armature").Find("torso");
				((Component)__instance).transform.position = val.position + val.forward * 0.1f + val.up * 0.9f;
				((Component)__instance).transform.Rotate(25f, 0f, 0f);
			}
		}
	}
	[HarmonyPatch(typeof(DeadBodyInfo))]
	internal class DeadBodyPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPostfix(ref DeadBodyInfo __instance)
		{
			if (((Component)__instance.playerScript).GetComponent<PlayerModelReplacer>().IsDog)
			{
				SkinnedMeshRenderer component = ((Component)__instance).GetComponent<SkinnedMeshRenderer>();
				((Renderer)component).enabled = false;
				Material material = ((Renderer)component).material;
				GameObject val = Object.Instantiate<GameObject>(Plugin.assetBundle.LoadAsset<GameObject>("assets/DogRagdoll.fbx"), ((Component)__instance).transform);
				SkinnedMeshRenderer[] componentsInChildren = val.GetComponentsInChildren<SkinnedMeshRenderer>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Renderer)componentsInChildren[i]).material = material;
				}
				DogModelMapper.MapDogRagdollToHumanRagdoll(val, ((Component)__instance).transform);
			}
		}
	}
	[HarmonyPatch(typeof(FlowerSnakeEnemy))]
	internal class FlowerSnakeEnemyPatch
	{
		[HarmonyPatch("SetClingingAnimationPosition")]
		[HarmonyPostfix]
		public static void SetClingingAnimationPositionPostfix(ref FlowerSnakeEnemy __instance, PlayerControllerB ___clingingToPlayer, int ___clingPosition, float ___spinePositionUpOffset, float ___spinePositionRightOffset)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)___clingingToPlayer != (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				PlayerModelReplacer component = ((Component)___clingingToPlayer).GetComponent<PlayerModelReplacer>();
				if (!((Object)(object)component == (Object)null) && component.IsDog)
				{
					((Component)__instance).transform.position = ((Component)___clingingToPlayer.gameplayCamera).transform.position;
					Transform transform = ((Component)__instance).transform;
					transform.position += ((Component)__instance).transform.up * -0.172f;
					Transform transform2 = ((Component)__instance).transform;
					transform2.position += ((Component)__instance).transform.right * -0.013f;
					((Component)__instance).transform.rotation = ((Component)___clingingToPlayer.gameplayCamera).transform.rotation;
				}
			}
		}
	}
	[HarmonyPatch(typeof(HauntedMaskItem))]
	internal class HauntedMaskPatch
	{
		[HarmonyPatch("PositionHeadMaskWithOffset")]
		[HarmonyPostfix]
		public static void PositionHeadMaskWithOffsetPostfix(HauntedMaskItem __instance, Transform ___currentHeadMask, PlayerControllerB ___previousPlayerHeldBy, Vector3 ___headRotationOffset, Vector3 ___headPositionOffset)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_006a: 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_0075: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)__instance).IsOwner)
			{
				PlayerModelReplacer component = ((Component)___previousPlayerHeldBy).GetComponent<PlayerModelReplacer>();
				if (!((Object)(object)component == (Object)null) && component.IsDog)
				{
					Transform val = component.GetDogGameObject().transform.Find("Armature").Find("torso").Find("head");
					___currentHeadMask.rotation = val.rotation;
					___currentHeadMask.position = val.position + val.forward * 0.5f + val.up * 0.2f;
					___currentHeadMask.Rotate(-35f, 0f, 0f);
				}
			}
		}

		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		public static void LateUpdatePostfix(ref HauntedMaskItem __instance, PlayerControllerB ___playerHeldBy, bool ___isHeld)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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)
			if ((Object)(object)___playerHeldBy != (Object)null && ___isHeld)
			{
				PlayerModelReplacer component = ((Component)___playerHeldBy).GetComponent<PlayerModelReplacer>();
				if (!((Object)(object)component == (Object)null) && component.IsDog)
				{
					((Component)__instance).transform.position = component.itemAnchor.position + component.itemAnchor.forward * 0.1f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(JetpackItem))]
	internal class JetpackPatch
	{
		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		public static void LateUpdatePostfix(JetpackItem __instance, PlayerControllerB ___playerHeldBy, bool ___isHeld)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)___playerHeldBy != (Object)null && ___isHeld)
			{
				PlayerModelReplacer component = ((Component)___playerHeldBy).GetComponent<PlayerModelReplacer>();
				if (!((Object)(object)component == (Object)null) && component.IsDog)
				{
					Transform val = component.GetDogGameObject().transform.Find("Armature").Find("torso");
					((Component)__instance).transform.position = val.Find("head").Find("serverItem").position;
					__instance.backPart.position = val.position + val.up * 1f + val.right * -0.03f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(MaskedPlayerEnemy))]
	internal class MaskedPlayerEnemyPatch
	{
		[HarmonyPatch("SetEnemyOutside")]
		[HarmonyPostfix]
		public static void SetEnemyOutsidePostfix(ref MaskedPlayerEnemy __instance)
		{
			if (RenderMaskedDog(ref __instance))
			{
				MaskedDogData maskedDogData = new MaskedDogData
				{
					maskedEnemyNetworkId = ((NetworkBehaviour)__instance).NetworkObjectId,
					mimickingClientId = LethalNetworkExtensions.GetClientId(__instance.mimickingPlayer)
				};
				string text = JsonUtility.ToJson((object)maskedDogData);
				LNetworkMessage<string>.Connect("maskeddogspawn", (Action<string, ulong>)null, (Action<string>)null, (Action<string, ulong>)null).SendOtherClients(text);
				Plugin.logger.LogDebug((object)("Sent json=" + text + " for a masked dog spawn event " + $"maskedEnemyNetworkId={maskedDogData.maskedEnemyNetworkId}, " + $"mimickingClientId={maskedDogData.mimickingClientId}"));
			}
		}

		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		public static void LateUpdatePostfix(ref MaskedPlayerEnemy __instance)
		{
			//IL_0088: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance.mimickingPlayer == (Object)null)
			{
				return;
			}
			Transform val = ((Component)__instance).transform.Find(DogModelMapper.dogModelKey);
			if (!((Object)(object)val == (Object)null))
			{
				GameObject val2 = __instance.maskTypes[__instance.maskTypeIndex];
				if (Plugin.isMirageLoaded || Plugin.config.alwaysHideMasksOnDogs.Value)
				{
					val2.gameObject.SetActive(false);
					return;
				}
				Transform val3 = val.Find("Armature").Find("torso").Find("head");
				val2.transform.rotation = val3.rotation;
				val2.transform.position = val3.position + val3.forward * 0.5f + val3.up * 0.2f;
				val2.transform.Rotate(-37f, 0f, 0f);
				val2.gameObject.SetActive(true);
			}
		}

		internal static bool RenderMaskedDog(ref MaskedPlayerEnemy mimic)
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mimic.mimickingPlayer == (Object)null)
			{
				return false;
			}
			PlayerModelReplacer component = ((Component)mimic.mimickingPlayer).GetComponent<PlayerModelReplacer>();
			if ((Object)(object)component == (Object)null || !component.IsDog || (Object)(object)((Component)mimic).transform.Find(DogModelMapper.dogModelKey) != (Object)null)
			{
				return false;
			}
			DisableMaskedRenderers(mimic);
			GameObject val = Object.Instantiate<GameObject>(Plugin.assetBundle.LoadAsset<GameObject>("assets/Dog.fbx"), ((Component)mimic).transform);
			SkinnedMeshRenderer[] componentsInChildren = val.GetComponentsInChildren<SkinnedMeshRenderer>();
			Material suitMaterial = StartOfRound.Instance.unlockablesList.unlockables[mimic.mimickingPlayer.currentSuitID].suitMaterial;
			SkinnedMeshRenderer[] array = componentsInChildren;
			for (int i = 0; i < array.Length; i++)
			{
				((Renderer)array[i]).material = suitMaterial;
			}
			DogModelMapper.MapDogModelToHumanModel(val, ((Component)mimic).transform);
			for (int j = 0; j < mimic.maskTypes.Length; j++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(mimic.maskTypes[j]);
				Transform transform = val2.transform;
				transform.localScale *= 1.5f;
				mimic.maskTypes[j] = val2;
			}
			return true;
		}

		private static void DisableMaskedRenderers(MaskedPlayerEnemy mimic)
		{
			if (((EnemyAI)mimic).skinnedMeshRenderers.Length == 0)
			{
				((EnemyAI)mimic).skinnedMeshRenderers = ((Component)mimic).gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
			}
			if (((EnemyAI)mimic).meshRenderers.Length == 0)
			{
				((EnemyAI)mimic).meshRenderers = ((Component)mimic).gameObject.GetComponentsInChildren<MeshRenderer>();
			}
			SkinnedMeshRenderer[] skinnedMeshRenderers = ((EnemyAI)mimic).skinnedMeshRenderers;
			for (int i = 0; i < skinnedMeshRenderers.Length; i++)
			{
				((Renderer)skinnedMeshRenderers[i]).enabled = false;
			}
			MeshRenderer[] meshRenderers = ((EnemyAI)mimic).meshRenderers;
			for (int i = 0; i < meshRenderers.Length; i++)
			{
				((Renderer)meshRenderers[i]).enabled = false;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("SpawnPlayerAnimation")]
		[HarmonyPostfix]
		public static void SpawnPlayerAnimationPatchPostfix(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>();
				}
			}
			LNetworkMessage<string>.Connect("modelinfo", (Action<string, ulong>)null, (Action<string>)null, (Action<string, ulong>)null).SendOtherClients("");
		}

		[HarmonyPatch("SetItemInElevator")]
		[HarmonyPostfix]
		public static void SetItemInElevatorPostfix(ref PlayerControllerB __instance, ref GrabbableObject gObject, bool droppedInShipRoom)
		{
			if (!droppedInShipRoom)
			{
				return;
			}
			GrabbableObject obj = gObject;
			RagdollGrabbableObject val = (RagdollGrabbableObject)(object)((obj is RagdollGrabbableObject) ? obj : null);
			if (!((Object)(object)val == (Object)null))
			{
				PlayerModelReplacer component = ((Component)val.ragdoll.playerScript).GetComponent<PlayerModelReplacer>();
				if (!((Object)(object)component == (Object)null) && component.IsDog)
				{
					Item val2 = Object.Instantiate<Item>(gObject.itemProperties);
					val2.spawnPrefab = Plugin.assetBundle.LoadAsset<GameObject>("assets/DogRagdoll.fbx");
					gObject.itemProperties = val2;
				}
			}
		}
	}
	[HarmonyPatch(typeof(CentipedeAI))]
	internal class SnareFleaPatch
	{
		[HarmonyPatch("UpdatePositionToClingingPlayerHead")]
		[HarmonyPostfix]
		public static void UpdatePositionToClingingPlayerHeadPostfix(CentipedeAI __instance, bool ___clingingToLocalClient, ref PlayerControllerB ___clingingToPlayer)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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)
			if (!___clingingToLocalClient)
			{
				PlayerModelReplacer component = ((Component)___clingingToPlayer).GetComponent<PlayerModelReplacer>();
				if (!((Object)(object)component == (Object)null) && component.IsDog && !((Object)(object)component.GetDogGameObject() == (Object)null))
				{
					Transform val = component.GetDogGameObject().transform.Find("Armature").Find("torso").Find("head");
					((Component)__instance).transform.position = val.position + val.up * 0.38f;
					((Component)__instance).transform.eulerAngles = val.eulerAngles;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class SpectateCameraPatch
	{
		[HarmonyPatch("RaycastSpectateCameraAroundPivot")]
		[HarmonyPrefix]
		public static void RaycastSpectateCameraAroundPivotPrefix(ref Transform ___spectateCameraPivot, PlayerControllerB ___spectatedPlayerScript)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				PlayerModelReplacer component = ((Component)___spectatedPlayerScript).GetComponent<PlayerModelReplacer>();
				if (!((Object)(object)component == (Object)null) && component.IsDog)
				{
					___spectateCameraPivot.position = component.GetDogTorso().position + Vector3.up * 0.5f;
				}
			}
			catch (Exception ex)
			{
				if (!Plugin.config.suppressExceptions.Value)
				{
					throw ex;
				}
			}
		}

		[HarmonyPatch("RaycastSpectateCameraAroundPivot")]
		[HarmonyPostfix]
		public static void RaycastSpectateCameraAroundPivotPostfix(ref Transform ___spectateCameraPivot, PlayerControllerB ___spectatedPlayerScript)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				PlayerModelReplacer playerModelReplacer = null;
				GameObject[] allPlayerObjects = StartOfRound.Instance.allPlayerObjects;
				for (int i = 0; i < allPlayerObjects.Length; i++)
				{
					PlayerModelReplacer component = allPlayerObjects[i].GetComponent<PlayerModelReplacer>();
					if ((Object)(object)component != (Object)null && component.PlayerClientId == ___spectatedPlayerScript.playerClientId)
					{
						playerModelReplacer = component;
						break;
					}
				}
				if (!((Object)(object)playerModelReplacer == (Object)null) && playerModelReplacer.IsDog)
				{
					((Component)((Component)___spectateCameraPivot).GetComponentInChildren<Camera>()).transform.localPosition = Vector3.back * 1.8f;
				}
			}
			catch (Exception ex)
			{
				if (!Plugin.config.suppressExceptions.Value)
				{
					throw ex;
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("PositionSuitsOnRack")]
		[HarmonyPostfix]
		public static void PositionSuitsOnRackPostfix(ref StartOfRound __instance)
		{
			if (!Object.op_Implicit((Object)(object)Object.FindObjectOfType<PlayerModelSwitcher>()))
			{
				GameObject.Find("NurbsPath.002").AddComponent<PlayerModelSwitcher>();
			}
		}
	}
	[HarmonyPatch(typeof(UnlockableSuit))]
	internal class UnlockableSuitPatch
	{
		[HarmonyPatch("SwitchSuitForPlayer")]
		[HarmonyPostfix]
		public static void SwitchSuitForPlayerPostfix(PlayerControllerB player, int suitID, bool playAudio = true)
		{
			PlayerModelReplacer component = ((Component)player).GetComponent<PlayerModelReplacer>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.UpdateMaterial();
			}
			if ((Object)(object)component != (Object)null && component.IsDog)
			{
				if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)(object)player)
				{
					UnlockableSuit.ChangePlayerCostumeElement(player.headCostumeContainer, (GameObject)null);
				}
				else
				{
					UnlockableSuit.ChangePlayerCostumeElement(player.headCostumeContainerLocal, (GameObject)null);
				}
			}
		}
	}
}
namespace PlayerDogModel_Plus.Source.Networking
{
	[Serializable]
	internal class MaskedDogData
	{
		public ulong maskedEnemyNetworkId;

		public ulong mimickingClientId;
	}
	internal static class MessageHandler
	{
		public const string ModelSwitchMessageName = "modelswitch";

		public const string ModelInfoMessageName = "modelinfo";

		public const string MaskedDogSpawnMessageName = "maskeddogspawn";

		public static void Initialize()
		{
			LNetworkMessage<string>.Connect("modelswitch", (Action<string, ulong>)null, (Action<string>)null, (Action<string, ulong>)null).OnClientReceivedFromClient += HandleModelSwitchMessage;
			LNetworkMessage<string>.Connect("maskeddogspawn", (Action<string, ulong>)null, (Action<string>)null, (Action<string, ulong>)null).OnClientReceivedFromClient += HandleMaskedDogSpawnMessage;
			LNetworkMessage<string>.Connect("modelinfo", (Action<string, ulong>)null, (Action<string>)null, (Action<string, ulong>)null).OnClientReceivedFromClient += HandleModelInfoMessage;
		}

		internal static void HandleModelSwitchMessage(string modelToggleJson, ulong senderId)
		{
			ModelToggleData modelToggleData = JsonUtility.FromJson<ModelToggleData>(modelToggleJson);
			Plugin.logger.LogDebug((object)string.Format("Got {0} network message from {1} with json={2}", "modelswitch", senderId, modelToggleJson));
			PlayerModelReplacer component = ((Component)PlayerRetriever.GetPlayerFromClientId(modelToggleData.clientId)).GetComponent<PlayerModelReplacer>();
			if ((Object)(object)component == (Object)null)
			{
				Plugin.logger.LogWarning((object)string.Format("{0} message from client {1} will be ignored because replacer with this ID is not registered", "modelswitch", modelToggleData.clientId));
			}
			else if (!component.IsValid)
			{
				Plugin.logger.LogError((object)"Dog encountered an error when it was initialized and it can't be toggled. Check the log for more info.");
			}
			else
			{
				component.ReceiveBroadcastAndToggle(playAudio: false, modelToggleData.isDog);
			}
		}

		internal static void HandleModelInfoMessage(string nothing, ulong senderId)
		{
			Plugin.logger.LogDebug((object)string.Format("Got {0} network message from {1}", "modelinfo", senderId));
			PlayerModelReplacer component = ((Component)GameNetworkManager.Instance.localPlayerController).GetComponent<PlayerModelReplacer>();
			if (!((Object)(object)component != (Object)null))
			{
				return;
			}
			try
			{
				component.BroadcastSelectedModel(playAudio: false);
			}
			catch (Exception ex)
			{
				Plugin.logger.LogDebug((object)$"Couldn't broadcast model for senderId={senderId} for some reason!");
				if (!Plugin.config.suppressExceptions.Value)
				{
					throw ex;
				}
			}
		}

		internal static void HandleMaskedDogSpawnMessage(string maskedDogJson, ulong senderId)
		{
			Plugin.logger.LogDebug((object)string.Format("Got {0} network message from {1} with json={2}", "maskeddogspawn", senderId, maskedDogJson));
			MaskedDogData maskedDogData = JsonUtility.FromJson<MaskedDogData>(maskedDogJson);
			if (!NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(maskedDogData.maskedEnemyNetworkId, out var value))
			{
				Plugin.logger.LogWarning((object)$"Couldn't find networkObjectId={maskedDogData.maskedEnemyNetworkId}");
				return;
			}
			MaskedPlayerEnemy mimic = ((Component)value).GetComponent<MaskedPlayerEnemy>();
			if ((Object)(object)mimic == (Object)null)
			{
				Plugin.logger.LogWarning((object)$"Couldn't find a MaskedPlayerEnemy for networkObjectId={maskedDogData.maskedEnemyNetworkId}");
				return;
			}
			if ((Object)(object)mimic.mimickingPlayer == (Object)null || LethalNetworkExtensions.GetClientId(mimic.mimickingPlayer) != maskedDogData.mimickingClientId)
			{
				mimic.mimickingPlayer = PlayerRetriever.GetPlayerFromClientId(maskedDogData.mimickingClientId);
			}
			MaskedPlayerEnemyPatch.RenderMaskedDog(ref mimic);
		}
	}
}
namespace PlayerDogModel_Plus.Source.Model
{
	[DefaultExecutionOrder(-1)]
	public class PlayerModelReplacer : MonoBehaviour
	{
		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;

		public Transform itemAnchor;

		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
		{
			get
			{
				if (!((Object)(object)playerController != (Object)null))
				{
					return ulong.MaxValue;
				}
				return playerController.playerClientId;
			}
		}

		public string PlayerUsername
		{
			get
			{
				if (!((Object)(object)playerController != (Object)null))
				{
					return "";
				}
				return playerController.playerUsername;
			}
		}

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

		public bool IsDog => isDogActive;

		public Transform GetDogTorso()
		{
			return dogTorso;
		}

		public GameObject GetDogGameObject()
		{
			return dogGameObject;
		}

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

		private void Start()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			playerController = ((Component)this).GetComponent<PlayerControllerB>();
			humanCameraPosition = ((Component)playerController.gameplayCamera).transform.localPosition;
			SpawnDogModel();
			EnableHumanModel(playAudio: false);
			if (((NetworkBehaviour)playerController).IsOwner)
			{
				LocalReplacer = this;
				BroadcastSelectedModel(playAudio: false);
			}
		}

		private void Update()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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)
			if (!string.IsNullOrEmpty(exceptionMessage))
			{
				return;
			}
			Vector3 val = humanCameraPosition;
			if (isDogActive && !playerController.inTerminalMenu && !playerController.inSpecialInteractAnimation)
			{
				if (!playerController.isCrouching)
				{
					((Vector3)(ref val))..ctor(0f, -0.8f, 0.3f);
				}
				else
				{
					((Vector3)(ref val))..ctor(0f, -0.1f, 0.3f);
				}
			}
			((Component)playerController.gameplayCamera).transform.localPosition = Vector3.MoveTowards(((Component)playerController.gameplayCamera).transform.localPosition, val, Time.deltaTime * 2f);
			torsoConstraint.weight = Mathf.MoveTowards(torsoConstraint.weight, 0.5f, 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0043: 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)
			if (!((Object)(object)itemAnchor == (Object)null))
			{
				if (isDogActive)
				{
					playerController.localItemHolder.position = itemAnchor.position;
					playerController.serverItemHolder.position = itemAnchor.position;
				}
				if (((Renderer)dogRenderers[0]).shadowCastingMode != ((Renderer)playerController.thisPlayerModel).shadowCastingMode)
				{
					((Renderer)dogRenderers[0]).shadowCastingMode = ((Renderer)playerController.thisPlayerModel).shadowCastingMode;
				}
				if (((Component)dogRenderers[0]).gameObject.layer != ((Component)playerController.thisPlayerModel).gameObject.layer)
				{
					((Component)dogRenderers[0]).gameObject.layer = ((Component)playerController.thisPlayerModel).gameObject.layer;
				}
			}
		}

		private void SpawnDogModel()
		{
			//IL_0070: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GameObject val = Plugin.assetBundle.LoadAsset<GameObject>("assets/Dog.fbx");
				dogGameObject = Object.Instantiate<GameObject>(val, ((Component)this).transform);
			}
			catch (Exception ex)
			{
				exceptionMessage = "Failed to spawn dog model.";
				exception = ex;
				Plugin.logger.LogError((object)exceptionMessage);
			}
			dogRenderers = dogGameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
			UpdateMaterial();
			try
			{
				LODGroup val2 = dogGameObject.AddComponent<LODGroup>();
				val2.fadeMode = (LODFadeMode)0;
				LOD val3 = default(LOD);
				val3.screenRelativeTransitionHeight = 0.4564583f;
				val3.renderers = (Renderer[])(object)new Renderer[1] { (Renderer)dogRenderers[0] };
				val3.fadeTransitionWidth = 0f;
				LOD val4 = val3;
				val3 = default(LOD);
				val3.screenRelativeTransitionHeight = 0.1795709f;
				val3.renderers = (Renderer[])(object)new Renderer[1] { (Renderer)dogRenderers[1] };
				val3.fadeTransitionWidth = 0f;
				LOD val5 = val3;
				val3 = default(LOD);
				val3.screenRelativeTransitionHeight = 0.009000001f;
				val3.renderers = (Renderer[])(object)new Renderer[1] { (Renderer)dogRenderers[2] };
				val3.fadeTransitionWidth = 0.435f;
				LOD val6 = val3;
				val2.SetLODs((LOD[])(object)new LOD[3] { val4, val5, val6 });
			}
			catch (Exception ex2)
			{
				exceptionMessage = "Failed to set up the LOD.";
				exception = ex2;
				Plugin.logger.LogError((object)exceptionMessage);
			}
			try
			{
				DogModelConstraints dogModelConstraints = DogModelMapper.MapDogModelToHumanModel(dogGameObject, ((Component)this).transform);
				torsoConstraint = dogModelConstraints.torso;
				dogTorso = dogGameObject.transform.Find("Armature").Find("torso");
				itemAnchor = dogTorso.Find("head").Find("serverItem");
			}
			catch (Exception ex3)
			{
				exceptionMessage = "Failed to retrieve bones. What the hell?";
				exception = ex3;
				Plugin.logger.LogError((object)exceptionMessage);
			}
			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)
		{
			isDogActive = false;
			dogGameObject.SetActive(false);
			GameObject[] array = humanGameObjects;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].SetActive(true);
			}
			if (playAudio)
			{
				playerController.movementAudio.PlayOneShot(humanClip);
			}
			if (((NetworkBehaviour)playerController).IsOwner && Object.op_Implicit((Object)(object)healthFill))
			{
				healthFill.sprite = humanFill;
				healthOutline.sprite = humanOutline;
			}
			UnlockableSuit.SwitchSuitForPlayer(playerController, playerController.currentSuitID, false);
		}

		public void EnableDogModel(bool playAudio)
		{
			//IL_0026: 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;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].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;
			}
			UnlockableSuit.SwitchSuitForPlayer(playerController, playerController.currentSuitID, false);
		}

		public void UpdateMaterial()
		{
			if (dogRenderers == null)
			{
				Plugin.logger.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)array[i]).material = ((Renderer)playerController.thisPlayerModel).material;
			}
		}

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

		public void ReceiveBroadcastAndToggle(bool playAudio, bool isDog)
		{
			if (isDog)
			{
				EnableDogModel(playAudio);
				if (Plugin.isMoreCompanyLoaded)
				{
					MoreCompanyPatch.HideCosmeticsForPlayer(playerController);
				}
				return;
			}
			EnableHumanModel(playAudio);
			if (((NetworkBehaviour)playerController).IsOwner)
			{
				if (Plugin.isMoreCompanyLoaded)
				{
					MoreCompanyPatch.HideCosmeticsForPlayer(playerController);
				}
			}
			else if (Plugin.isMoreCompanyLoaded)
			{
				MoreCompanyPatch.ShowCosmeticsForPlayer(playerController);
			}
		}

		public void BroadcastSelectedModel(bool playAudio)
		{
			string text = JsonUtility.ToJson((object)new ModelToggleData
			{
				isDog = isDogActive,
				clientId = playerController.playerClientId
			});
			LNetworkMessage<string>.Connect("modelswitch", (Action<string, ulong>)null, (Action<string>)null, (Action<string, ulong>)null).SendOtherClients(text);
			Plugin.logger.LogDebug((object)$"Sent json={text} for {playerController.playerClientId} ({playerController.playerUsername})");
		}

		private static void LoadImageResources()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Texture2D val = Plugin.assetBundle.LoadAsset<Texture2D>("assets/TPoseFilled.png");
				dogFill = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				Texture2D val2 = Plugin.assetBundle.LoadAsset<Texture2D>("assets/TPoseOutline.png");
				dogOutline = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f), 100f);
			}
			catch (Exception ex)
			{
				exceptionMessage = "Failed to retrieve images.";
				exception = ex;
				Plugin.logger.LogError((object)exceptionMessage);
			}
		}

		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);
			return Path.GetFullPath((additionalPath != null) ? Path.Combine(directoryName, ".\\" + additionalPath) : directoryName);
		}
	}
	public class PlayerModelSwitcher : MonoBehaviour
	{
		private void Start()
		{
			//IL_0020: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(Plugin.assetBundle.LoadAsset<GameObject>("assets/Helmets.fbx"), ((Component)this).transform);
			obj.transform.localPosition = Vector3.zero;
			obj.transform.localRotation = Quaternion.identity;
			obj.transform.localScale = Vector3.one * 0.75f;
			Renderer component = obj.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 obj2 = Object.Instantiate<InteractTrigger>(((Component)GameObject.Find("SpeakerAudio").transform.parent).GetComponentInChildren<InteractTrigger>());
			((Component)obj2).transform.position = ((Component)this).transform.TransformPoint(new Vector3(0.75f, 0f, 0.9f));
			((Component)obj2).transform.localScale = new Vector3(0.3f, 0.7f, 0.3f);
			obj2.hoverTip = "Switch model";
			obj2.interactable = true;
			obj2.cooldownTime = 1f;
			((UnityEventBase)obj2.onCancelAnimation).RemoveAllListeners();
			((UnityEventBase)obj2.onInteractEarly).RemoveAllListeners();
			((UnityEventBase)obj2.onStopInteract).RemoveAllListeners();
			((UnityEventBase)obj2.onInteract).RemoveAllListeners();
			((UnityEvent<PlayerControllerB>)(object)obj2.onInteract).AddListener((UnityAction<PlayerControllerB>)Interacted);
		}

		private void Interacted(PlayerControllerB player)
		{
			((Component)player).GetComponent<PlayerModelReplacer>().ToggleAndBroadcast(playAudio: true);
		}
	}
	[Serializable]
	internal class ModelToggleData
	{
		public bool isDog;

		public ulong clientId;
	}
}
namespace PlayerDogModel_Plus.Source.Config
{
	public class PluginConfig
	{
		public readonly ConfigEntry<bool> suppressExceptions;

		public readonly ConfigEntry<bool> thirdPersonConfigOverride;

		public readonly ConfigEntry<float> thirdPersonDistance;

		public readonly ConfigEntry<float> thirdPersonRightOffset;

		public readonly ConfigEntry<float> thirdPersonUpOffset;

		public readonly ConfigEntry<bool> alwaysHideMasksOnDogs;

		public PluginConfig(ConfigFile config)
		{
			config.SaveOnConfigSet = false;
			suppressExceptions = config.Bind<bool>("Developer Tools", "SuppressExceptions", true, "Non-fatal exceptions will be suppressed.");
			thirdPersonConfigOverride = config.Bind<bool>("Verity-3rdPerson Config Overrides", "Override", true, "Enables overriding Verity-3rdPerson config settings with custom ones (distance, right-offset, and up-offset) for dog mode.");
			thirdPersonDistance = config.Bind<float>("Verity-3rdPerson Config Overrides", "Distance", 3f, "Distance of the camera from the player when using dog mode.");
			thirdPersonRightOffset = config.Bind<float>("Verity-3rdPerson Config Overrides", "Right-Offset", 0f, "Offset of the camera to the right from the player when using dog mode.");
			thirdPersonUpOffset = config.Bind<float>("Verity-3rdPerson Config Overrides", "Up-Offset", 0.1f, "Offset of the camera upwards from the player when using dog mode.");
			alwaysHideMasksOnDogs = config.Bind<bool>("Masked Enemies", "AlwaysHideMasksOnDogs", false, "Disables masks on all masked enemies spawned from dogs. Default has masks visible for masked enemies spawned by possession.");
			ClearOrphanedEntries(config);
			config.Save();
			config.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile config)
		{
			((Dictionary<ConfigDefinition, string>)AccessTools.Property(typeof(ConfigFile), "OrphanedEntries").GetValue(config)).Clear();
		}
	}
}