Decompiled source of MipaPlayerModel v1.0.0

BepInEx/plugins/Mipa.dll

Decompiled 5 hours ago
using System;
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.Configuration;
using Dissonance;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mipa;
using ModelReplacement;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("Mipa")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Mipa")]
[assembly: AssemblyTitle("Mipa")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
public class MipaSkinInstance
{
	public string m_SkinName = "Default";

	public Texture2D m_EyesDefault = null;

	public Texture2D m_EyesBlink = null;

	public Texture2D m_EyesClosed = null;

	public Texture2D m_MouthDefault = null;

	public Texture2D m_DrunkMouth = null;

	public Texture2D m_DrunkEyes = null;

	public Texture2D m_LowHPMouth = null;

	public List<Texture2D> m_MouthTalking = new List<Texture2D>();

	public Material m_FaceMaterial = null;

	public Material m_BodyMaterial = null;

	public Material m_ChestMaterial = null;

	[ColorUsage(true, true)]
	public Color m_EmmissionColor = Color.white;
}
public class SkinApply : MonoBehaviour
{
	private enum BlinkState
	{
		Open,
		HalfClosed,
		Closesd
	}

	private enum FaceOverrideState
	{
		None,
		LowHealth,
		Hurt,
		Drunk
	}

	public PlayerControllerB m_Player;

	public VoicePlayerState m_VoiceState;

	public string m_SkinName = "None";

	public MipaSkinInstance m_Skin;

	public SkinnedMeshRenderer m_FaceMesh;

	public SkinnedMeshRenderer m_ChestMesh;

	public bool m_IsTalking = false;

	private bool m_IsLastTalking = false;

	public List<SkinnedMeshRenderer> m_Body = new List<SkinnedMeshRenderer>();

	public bool m_ReApplySkin = false;

	public bool m_ForceSkin = false;

	public bool m_IsDead = false;

	private float NextBlinkTime = 0f;

	private float BlinkingPerioud = 10f;

	private float BlinkingAnimationFrameTime = 0.1f;

	private BlinkState CurrentBlinkState = BlinkState.Open;

	private FaceOverrideState CurrentFaceOverrideState = FaceOverrideState.None;

	private int MouthTalkingIndex = 0;

	private float TalkingAnimationFrameTime = 0.2f;

	private float NextTalkTime = 0f;

	private void Start()
	{
		AssignMeshes();
		Default();
	}

	public void AssignMeshes()
	{
		m_FaceMesh = ((Component)((Component)this).transform.GetChild(0).GetChild(1)).GetComponent<SkinnedMeshRenderer>();
		m_ChestMesh = ((Component)((Component)this).transform.GetChild(1).GetChild(7)).GetComponent<SkinnedMeshRenderer>();
		SkinnedMeshRenderer[] componentsInChildren = ((Component)((Component)this).transform).GetComponentsInChildren<SkinnedMeshRenderer>();
		foreach (SkinnedMeshRenderer val in componentsInChildren)
		{
			if ((Object)(object)val != (Object)(object)m_FaceMesh && (Object)(object)val != (Object)(object)m_ChestMesh)
			{
				m_Body.Add(val);
			}
		}
	}

	public void Default()
	{
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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)
		if (m_Skin == null)
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)m_FaceMesh))
		{
			((Renderer)m_FaceMesh).material = m_Skin.m_FaceMaterial;
			((Renderer)m_FaceMesh).material.SetTexture("_Eyes", (Texture)(object)m_Skin.m_EyesDefault);
			((Renderer)m_FaceMesh).material.SetTexture("_Mouth", (Texture)(object)m_Skin.m_MouthDefault);
			((Renderer)m_FaceMesh).material.SetColor("_EmissionColor", m_Skin.m_EmmissionColor);
			if (m_IsDead)
			{
				((Renderer)m_FaceMesh).material = Assets.GetMaterial("MipaFaceDead");
			}
		}
		if (Object.op_Implicit((Object)(object)m_ChestMesh))
		{
			((Renderer)m_ChestMesh).material = m_Skin.m_ChestMaterial;
			((Renderer)m_ChestMesh).material.SetColor("_EmissionColor", m_Skin.m_EmmissionColor);
			if (m_IsDead)
			{
				((Renderer)m_ChestMesh).material = Assets.GetMaterial("Chest_Dead");
			}
		}
		foreach (SkinnedMeshRenderer item in m_Body)
		{
			((Renderer)item).material = m_Skin.m_BodyMaterial;
			if (m_IsDead)
			{
				((Renderer)item).material.SetColor("_EmissiveColor", new Color(0f, 0f, 0f));
			}
		}
	}

	public void SetEyesTexture(Texture2D Tex)
	{
		if (m_Skin != null && Object.op_Implicit((Object)(object)m_FaceMesh))
		{
			((Renderer)m_FaceMesh).material.SetTexture("_Eyes", (Texture)(object)Tex);
		}
	}

	public void SetMouthTexture(Texture2D Tex)
	{
		if (m_Skin != null && Object.op_Implicit((Object)(object)m_FaceMesh))
		{
			((Renderer)m_FaceMesh).material.SetTexture("_Mouth", (Texture)(object)Tex);
		}
	}

	private void UpdateTalking()
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		if (!Object.op_Implicit((Object)(object)m_Player))
		{
			return;
		}
		if (m_VoiceState == null)
		{
			StartOfRound.Instance.RefreshPlayerVoicePlaybackObjects();
			m_VoiceState = m_Player.voicePlayerState;
			if (m_VoiceState == null && (Object)(object)m_Player == (Object)StartOfRound.Instance.localPlayerController)
			{
				m_VoiceState = StartOfRound.Instance.voiceChatModule.FindPlayer(StartOfRound.Instance.voiceChatModule.LocalPlayerName);
			}
		}
		else
		{
			m_IsTalking = m_VoiceState.IsSpeaking;
		}
	}

	private void FixedUpdate()
	{
		if (Object.op_Implicit((Object)(object)m_Player))
		{
			if (m_IsDead != m_Player.isPlayerDead)
			{
				m_IsDead = m_Player.isPlayerDead;
				Default();
			}
			if (!m_IsDead)
			{
				UpdateTalking();
			}
			else
			{
				m_IsTalking = false;
			}
		}
	}

	public void FaceUpdates()
	{
		if (m_Skin == null)
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)m_Player))
		{
			if (m_Player.drunkness > 0f)
			{
				if (CurrentFaceOverrideState != FaceOverrideState.Drunk)
				{
					SetMouthTexture(m_Skin.m_DrunkMouth);
					SetEyesTexture(m_Skin.m_DrunkEyes);
					CurrentFaceOverrideState = FaceOverrideState.Drunk;
				}
			}
			else if (m_Player.health < 20)
			{
				if (CurrentFaceOverrideState != FaceOverrideState.LowHealth)
				{
					SetEyesTexture(m_Skin.m_EyesClosed);
					SetMouthTexture(m_Skin.m_LowHPMouth);
					CurrentFaceOverrideState = FaceOverrideState.LowHealth;
				}
			}
			else if (m_Player.health < 80)
			{
				if (CurrentFaceOverrideState != FaceOverrideState.Hurt)
				{
					SetEyesTexture(m_Skin.m_EyesBlink);
					SetMouthTexture(m_Skin.m_LowHPMouth);
					CurrentFaceOverrideState = FaceOverrideState.Hurt;
				}
			}
			else if (CurrentFaceOverrideState != 0)
			{
				SetEyesTexture(m_Skin.m_EyesDefault);
				SetMouthTexture(m_Skin.m_MouthDefault);
				CurrentFaceOverrideState = FaceOverrideState.None;
			}
		}
		if (m_IsLastTalking != m_IsTalking)
		{
			m_IsLastTalking = m_IsTalking;
			if (!m_IsTalking)
			{
				if (CurrentFaceOverrideState == FaceOverrideState.None)
				{
					SetMouthTexture(m_Skin.m_MouthDefault);
				}
				else if (CurrentFaceOverrideState == FaceOverrideState.Drunk)
				{
					SetMouthTexture(m_Skin.m_DrunkMouth);
				}
				else if (CurrentFaceOverrideState == FaceOverrideState.LowHealth || CurrentFaceOverrideState == FaceOverrideState.Hurt)
				{
					SetMouthTexture(m_Skin.m_LowHPMouth);
				}
			}
		}
		if ((CurrentFaceOverrideState == FaceOverrideState.None || CurrentFaceOverrideState == FaceOverrideState.Hurt) && Time.time > NextBlinkTime)
		{
			if (CurrentBlinkState == BlinkState.Open)
			{
				NextBlinkTime += BlinkingAnimationFrameTime;
				SetEyesTexture(m_Skin.m_EyesBlink);
				CurrentBlinkState = BlinkState.HalfClosed;
			}
			else if (CurrentBlinkState == BlinkState.HalfClosed)
			{
				NextBlinkTime += BlinkingAnimationFrameTime;
				SetEyesTexture(m_Skin.m_EyesClosed);
				CurrentBlinkState = BlinkState.Closesd;
			}
			else if (CurrentBlinkState == BlinkState.Closesd)
			{
				NextBlinkTime += BlinkingPerioud;
				if (CurrentFaceOverrideState == FaceOverrideState.None)
				{
					SetEyesTexture(m_Skin.m_EyesDefault);
					CurrentBlinkState = BlinkState.Open;
				}
				else
				{
					SetEyesTexture(m_Skin.m_EyesBlink);
					CurrentBlinkState = BlinkState.HalfClosed;
				}
			}
		}
		if (!(Time.time > NextTalkTime))
		{
			return;
		}
		if (m_IsTalking)
		{
			SetMouthTexture(m_Skin.m_MouthTalking[MouthTalkingIndex]);
			if (MouthTalkingIndex == m_Skin.m_MouthTalking.Count - 1)
			{
				MouthTalkingIndex = 0;
			}
			else
			{
				MouthTalkingIndex++;
			}
		}
		NextTalkTime += TalkingAnimationFrameTime;
	}

	private void Update()
	{
		if (m_Skin == null && !string.IsNullOrEmpty(m_SkinName))
		{
			m_Skin = MipaSkinManager.GetSkin(m_SkinName);
			if (m_Skin == null)
			{
				m_Skin = MipaSkinManager.GetSkin("Default");
			}
			Default();
		}
		if (!m_IsDead)
		{
			FaceUpdates();
		}
		if (m_ReApplySkin)
		{
			m_ReApplySkin = false;
			Default();
		}
	}
}
namespace Mipa
{
	public class MRMIPA_PLAYER_MODEL : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "MIPA_Player_Model";
			return Assets.GetAssetBundle().LoadAsset<GameObject>(text);
		}

		public virtual string GetSkin()
		{
			return "Default";
		}

		protected override void AddModelScripts()
		{
			MipaSkinInstance skin = MipaSkinManager.GetSkin(GetSkin());
			SkinApply skinApply = base.replacementModel.AddComponent<SkinApply>();
			skinApply.m_Skin = skin;
			skinApply.m_SkinName = GetSkin();
			skinApply.m_Player = ((BodyReplacementBase)this).controller;
		}
	}
	public class MR_MIPA_PLAYER_MODEL_HAZARD : MRMIPA_PLAYER_MODEL
	{
		public override string GetSkin()
		{
			return "Hazard";
		}
	}
	public class MR_MIPA_PLAYER_MODEL_ANOMALY : MRMIPA_PLAYER_MODEL
	{
		public override string GetSkin()
		{
			return "Anomaly";
		}
	}
	public class MR_MIPA_PLAYER_MODEL_PHANTASY : MRMIPA_PLAYER_MODEL
	{
		public override string GetSkin()
		{
			return "Phantasy";
		}
	}
	public class MR_MIPA_PLAYER_MODEL_PLACEHOLDER : MRMIPA_PLAYER_MODEL
	{
		public override string GetSkin()
		{
			return "Placeholder";
		}
	}
	[BepInPlugin("Mipa", "Mipa", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigFile config;

		private static void InitConfig()
		{
		}

		private void Awake()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			config = ((BaseUnityPlugin)this).Config;
			InitConfig();
			Assets.LoadBundle("mipa");
			MipaSkinManager.Init();
			ModelReplacementAPI.RegisterSuitModelReplacement("Mipa", typeof(MRMIPA_PLAYER_MODEL));
			ModelReplacementAPI.RegisterSuitModelReplacement("Mipa_Hazard", typeof(MR_MIPA_PLAYER_MODEL_HAZARD));
			ModelReplacementAPI.RegisterSuitModelReplacement("Mipa_Anomaly", typeof(MR_MIPA_PLAYER_MODEL_ANOMALY));
			ModelReplacementAPI.RegisterSuitModelReplacement("Mipa_Phantasy", typeof(MR_MIPA_PLAYER_MODEL_PHANTASY));
			Harmony val = new Harmony("Mipa");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Mipa is loaded!");
		}
	}
	public class MipaSkinManager
	{
		public static Dictionary<string, MipaSkinInstance> s_Skins = new Dictionary<string, MipaSkinInstance>();

		public static MipaSkinInstance GetSkinTemplate(string NewSkinName)
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			MipaSkinInstance mipaSkinInstance = new MipaSkinInstance();
			mipaSkinInstance.m_SkinName = NewSkinName;
			mipaSkinInstance.m_FaceMaterial = Assets.GetMaterial("MipaFace");
			mipaSkinInstance.m_BodyMaterial = Assets.GetMaterial("Default_Body");
			mipaSkinInstance.m_ChestMaterial = Assets.GetMaterial("Default_Chest");
			mipaSkinInstance.m_EyesDefault = Assets.GetTexture("EyesDefault");
			mipaSkinInstance.m_EyesBlink = Assets.GetTexture("EyesHalfClosed");
			mipaSkinInstance.m_EyesClosed = Assets.GetTexture("EyesClosed");
			mipaSkinInstance.m_DrunkEyes = Assets.GetTexture("EyesDrunk");
			mipaSkinInstance.m_LowHPMouth = Assets.GetTexture("MouthHurt");
			mipaSkinInstance.m_DrunkMouth = Assets.GetTexture("MouthDrunk");
			mipaSkinInstance.m_MouthDefault = Assets.GetTexture("MouthDefault");
			mipaSkinInstance.m_MouthTalking = new List<Texture2D>
			{
				Assets.GetTexture("MouthTalk1"),
				Assets.GetTexture("MouthTalk2")
			};
			mipaSkinInstance.m_EmmissionColor = new Color(0f, 0.5957293f, 0.945426f, 1f);
			return mipaSkinInstance;
		}

		public static void Init()
		{
			//IL_0039: 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_0090: 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_00e7: 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)
			MipaSkinInstance skinTemplate = GetSkinTemplate("Default");
			AddSkin(skinTemplate.m_SkinName, skinTemplate);
			MipaSkinInstance skinTemplate2 = GetSkinTemplate("Anomaly");
			skinTemplate2.m_EmmissionColor = new Color(1f, 0.6954004f, 0f, 1f);
			skinTemplate2.m_BodyMaterial = Assets.GetMaterial("Anomaly_Body");
			skinTemplate2.m_ChestMaterial = Assets.GetMaterial("Anomaly_Chest");
			AddSkin(skinTemplate2.m_SkinName, skinTemplate2);
			MipaSkinInstance skinTemplate3 = GetSkinTemplate("Hazard");
			skinTemplate3.m_EmmissionColor = new Color(1f, 0.9136026f, 0f, 1f);
			skinTemplate3.m_BodyMaterial = Assets.GetMaterial("Hazard_Body");
			skinTemplate3.m_ChestMaterial = Assets.GetMaterial("HazardSkin_Chest");
			AddSkin(skinTemplate3.m_SkinName, skinTemplate3);
			MipaSkinInstance skinTemplate4 = GetSkinTemplate("Phantasy");
			skinTemplate4.m_EmmissionColor = new Color(0.5990566f, 0.9292454f, 1f, 1f);
			skinTemplate4.m_BodyMaterial = Assets.GetMaterial("Phantasy_Body");
			skinTemplate4.m_ChestMaterial = Assets.GetMaterial("Phantasy_Chest");
			AddSkin(skinTemplate4.m_SkinName, skinTemplate4);
			MipaSkinInstance skinTemplate5 = GetSkinTemplate("Placeholder");
			skinTemplate5.m_BodyMaterial = Assets.GetMaterial("Placeholder_Body");
			skinTemplate5.m_ChestMaterial = Assets.GetMaterial("Placeholder_Chest");
			skinTemplate5.m_EyesDefault = Assets.GetTexture("EyesDefaultPlaceholder");
			skinTemplate5.m_EyesBlink = Assets.GetTexture("EyesHalfClosedPlaceholder");
			skinTemplate5.m_EyesClosed = Assets.GetTexture("EyesClosedPlaceholder");
			skinTemplate5.m_MouthDefault = Assets.GetTexture("MouthDefaultPlaceholder");
			skinTemplate5.m_MouthTalking = new List<Texture2D>
			{
				Assets.GetTexture("MouthTalk1Placeholder"),
				Assets.GetTexture("MouthTalk2Placeholder")
			};
			AddSkin(skinTemplate5.m_SkinName, skinTemplate5);
		}

		public static MipaSkinInstance GetSkin(string SkinName)
		{
			if (s_Skins.TryGetValue(SkinName, out MipaSkinInstance value))
			{
				return value;
			}
			return null;
		}

		public static void AddSkin(string SkinName, MipaSkinInstance Instance)
		{
			if (!s_Skins.ContainsKey(SkinName))
			{
				s_Skins.Add(SkinName, Instance);
			}
		}
	}
	public static class Assets
	{
		public static AssetBundle Bundle;

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().GetName().Name.Replace(" ", "_");
		}

		public static Texture2D GetTexture(string TextureName)
		{
			return GetAssetBundle().LoadAsset<Texture2D>(TextureName);
		}

		public static Material GetMaterial(string MaterialName)
		{
			return GetAssetBundle().LoadAsset<Material>(MaterialName);
		}

		public static void LoadBundle(string bundlename)
		{
			if (!((Object)(object)Bundle == (Object)null))
			{
				return;
			}
			Console.WriteLine(GetAssemblyName() + "." + bundlename);
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + bundlename);
			Bundle = AssetBundle.LoadFromStream(stream);
			if (Object.op_Implicit((Object)(object)Bundle))
			{
				Console.WriteLine("--------------------------------------------");
				Console.WriteLine("Loaded asset bundle with name " + bundlename);
				Console.WriteLine("--------------------------------------------");
			}
			else
			{
				Console.WriteLine("--------------------------------------------");
				Console.WriteLine("Wasn't able to locate bundle " + bundlename);
				Console.WriteLine("--------------------------------------------");
			}
		}

		public static AssetBundle GetAssetBundle()
		{
			return Bundle;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}