Decompiled source of SkittyMayuPlayermodel v1.0.1

schizofennecModelReplacement.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Dissonance;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SchizofennecModelReplacement
{
	public class MRSCHIZOFENNEC : BodyReplacementBase
	{
		private static Texture2D eyeGlow;

		private SkinnedMeshRenderer face;

		private int aa = -1;

		private int oh = -1;

		private int ou = -1;

		private int ee = -1;

		private int ih = -1;

		private VoicePlayerState localVoice;

		private float open;

		private float phase;

		protected override GameObject LoadAssetsAndReturnModel()
		{
			if ((Object)(object)Plugin.Bundle == (Object)null)
			{
				return null;
			}
			return Plugin.Bundle.LoadAsset<GameObject>("Schizofennec");
		}

		protected override void AddModelScripts()
		{
			FixMaterials();
		}

		private void FixMaterials()
		{
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)eyeGlow == (Object)null && (Object)(object)Plugin.Bundle != (Object)null)
			{
				eyeGlow = Plugin.Bundle.LoadAsset<Texture2D>("SchizofennecEyeGlow");
			}
			SkinnedMeshRenderer val = ((IEnumerable<SkinnedMeshRenderer>)base.replacementModel.GetComponentsInChildren<SkinnedMeshRenderer>(true)).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer s) => ((Object)s).name == "Body"));
			Material val2 = (((Object)(object)val != (Object)null && ((Renderer)val).sharedMaterials.Length != 0) ? ((Renderer)val).sharedMaterials[0] : null);
			Renderer[] componentsInChildren = base.replacementModel.GetComponentsInChildren<Renderer>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				Material[] sharedMaterials = componentsInChildren[num].sharedMaterials;
				foreach (Material val3 in sharedMaterials)
				{
					if (!((Object)(object)val3 == (Object)null) && ((Object)val3.shader).name.StartsWith("HDRP/"))
					{
						if (val3.HasProperty("_MaskMap"))
						{
							val3.SetTexture("_MaskMap", (Texture)null);
						}
						if (val3.HasProperty("_NormalMap"))
						{
							val3.SetTexture("_NormalMap", (Texture)null);
						}
						if (val3.HasProperty("_EmissiveColorMap"))
						{
							val3.SetTexture("_EmissiveColorMap", (Texture)null);
						}
						if (val3.HasProperty("_Metallic"))
						{
							val3.SetFloat("_Metallic", 0f);
						}
						if (val3.HasProperty("_Smoothness"))
						{
							val3.SetFloat("_Smoothness", 0.2f);
						}
						SetEmission(val3, Color.black);
						if (val3.HasProperty("_DoubleSidedEnable"))
						{
							val3.SetFloat("_DoubleSidedEnable", 0f);
						}
						if (val3.HasProperty("_CullMode"))
						{
							val3.SetFloat("_CullMode", 2f);
						}
						if (val3.HasProperty("_CullModeForward"))
						{
							val3.SetFloat("_CullModeForward", 2f);
						}
						if ((Object)(object)val3 == (Object)(object)val2 && (Object)(object)eyeGlow != (Object)null)
						{
							val3.SetTexture("_EmissiveColorMap", (Texture)(object)eyeGlow);
							SetEmission(val3, Color.white * 1f);
						}
						HDMaterial.ValidateMaterial(val3);
					}
				}
			}
		}

		private static void SetEmission(Material mat, Color color)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (mat.HasProperty("_UseEmissiveIntensity"))
			{
				mat.SetFloat("_UseEmissiveIntensity", 0f);
			}
			if (mat.HasProperty("_EmissiveColorLDR"))
			{
				mat.SetColor("_EmissiveColorLDR", color);
			}
			if (mat.HasProperty("_EmissiveColor"))
			{
				mat.SetColor("_EmissiveColor", color);
			}
		}

		public override void LateUpdate()
		{
			((BodyReplacementBase)this).LateUpdate();
			if ((Object)(object)base.replacementModel == (Object)null)
			{
				return;
			}
			if ((Object)(object)face == (Object)null)
			{
				face = ((IEnumerable<SkinnedMeshRenderer>)base.replacementModel.GetComponentsInChildren<SkinnedMeshRenderer>(true)).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer s) => ((Object)s).name == "Body"));
				if ((Object)(object)face == (Object)null)
				{
					return;
				}
				Mesh sharedMesh = face.sharedMesh;
				aa = sharedMesh.GetBlendShapeIndex("vrc.v_aa");
				oh = sharedMesh.GetBlendShapeIndex("vrc.v_oh");
				ou = sharedMesh.GetBlendShapeIndex("vrc.v_ou");
				ee = sharedMesh.GetBlendShapeIndex("vrc.v_E");
				ih = sharedMesh.GetBlendShapeIndex("vrc.v_ih");
			}
			float num = 0f;
			VoicePlayerState voice = GetVoice();
			if (voice != null && voice.IsSpeaking && !((BodyReplacementBase)this).controller.isPlayerDead)
			{
				num = Mathf.Clamp01(voice.Amplitude * 10f);
			}
			float deltaTime = Time.deltaTime;
			float num2 = ((num > open) ? 28f : 14f);
			open = Mathf.Lerp(open, num, 1f - Mathf.Exp((0f - num2) * deltaTime));
			phase += deltaTime * (5f + 6f * open);
			float num3 = Mathf.PerlinNoise(phase, 0.3f);
			float num4 = Mathf.PerlinNoise(0.7f, phase * 1.3f);
			float num5 = Mathf.PerlinNoise(phase * 0.8f, 2.1f);
			float num6 = open * 100f;
			Set(aa, num6 * (0.45f + 0.55f * num3));
			Set(oh, num6 * 0.6f * num4);
			Set(ou, num6 * 0.35f * (1f - num3) * num5);
			Set(ee, num6 * 0.4f * (1f - num4));
			Set(ih, num6 * 0.3f * num5);
		}

		private void Set(int index, float weight)
		{
			if (index >= 0)
			{
				face.SetBlendShapeWeight(index, weight);
			}
		}

		private VoicePlayerState GetVoice()
		{
			if (((BodyReplacementBase)this).controller.voicePlayerState != null)
			{
				return ((BodyReplacementBase)this).controller.voicePlayerState;
			}
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.voiceChatModule == (Object)null)
			{
				return null;
			}
			if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)((BodyReplacementBase)this).controller != (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				return null;
			}
			if (localVoice == null)
			{
				localVoice = instance.voiceChatModule.FindPlayer(instance.voiceChatModule.LocalPlayerName);
			}
			return localVoice;
		}
	}
	[BepInPlugin("schizofennec.schizofennecModelReplacement", "schizofennecModelReplacement", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal const string BundleResource = "schizofennec_bundle";

		internal const string SuitResource = "Schizofennec.png";

		internal const string PrefabName = "Schizofennec";

		internal const string SuitName = "Skitty";

		private const string PreviousSuitName = "Schizofennec";

		internal const float LipSyncSensitivity = 10f;

		internal const float EyeGlow = 1f;

		internal static ManualLogSource Log;

		public static AssetBundle Bundle { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			WriteSuitTexture();
			LoadBundle();
			ModelReplacementAPI.RegisterSuitModelReplacement("Skitty", typeof(MRSCHIZOFENNEC));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"schizofennecModelReplacement 1.0.0 loaded");
		}

		private void WriteSuitTexture()
		{
			try
			{
				byte[] array = ReadResource("Schizofennec.png");
				if (array != null)
				{
					string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "moresuits");
					string path = Path.Combine(text, "Skitty.png");
					Directory.CreateDirectory(text);
					if (!File.Exists(path) || !File.ReadAllBytes(path).SequenceEqual(array))
					{
						File.WriteAllBytes(path, array);
					}
					string path2 = Path.Combine(text, "Schizofennec.png");
					if (File.Exists(path2) && File.ReadAllBytes(path2).SequenceEqual(array))
					{
						File.Delete(path2);
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not write the suit texture: " + ex.Message));
			}
		}

		private void LoadBundle()
		{
			byte[] array = ReadResource("schizofennec_bundle");
			if (array == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Embedded asset bundle not found. The mod was built without it.");
				return;
			}
			Bundle = AssetBundle.LoadFromMemory(array);
			if ((Object)(object)Bundle == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Could not load the embedded asset bundle (is another copy of this mod installed?).");
			}
		}

		private static byte[] ReadResource(string name)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string n) => n.EndsWith(name, StringComparison.Ordinal));
			if (text == null)
			{
				return null;
			}
			using Stream stream = executingAssembly.GetManifestResourceStream(text);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}
	}
	internal static class PluginInfo
	{
		public const string GUID = "schizofennec.schizofennecModelReplacement";

		public const string NAME = "schizofennecModelReplacement";

		public const string VERSION = "1.0.0";
	}
}