Decompiled source of PlaytimeBunny ModelReplacement v0.1.2

PlaytimeBunnyModelReplacement.dll

Decompiled 2 months ago
using System;
using System.Collections;
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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Dissonance;
using GameNetcodeStuff;
using HarmonyLib;
using ModelReplacement;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ModelReplacementAPI")]
[assembly: AssemblyCompany("PlaytimeBunnyModelReplacement")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PlaytimeBunnyModelReplacement")]
[assembly: AssemblyTitle("PlaytimeBunnyModelReplacement")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public class ExpressionManager : MonoBehaviour
{
	private enum BlinkShapes
	{
		Blink = 15,
		Scream = 32
	}

	private enum SpeakShapes
	{
		Mouth = 20
	}

	private enum voicestate
	{
		Closed,
		Talking,
		Screaming
	}

	private SkinnedMeshRenderer body;

	private IEnumerator blinkingInstance;

	private IEnumerator speakingInstance;

	private bool isblinking;

	private GameObject parent;

	private PlayerControllerB plrCntrB;

	public BodyReplacementBase bodyReplacementB;

	private bool isScreaming;

	private voicestate currentVoiceState;

	private bool eyeOpen = true;

	public bool died = false;

	private VoicePlayerState vps;

	private float requiredVolume;

	private IEnumerator currentBlinkState;

	private IEnumerator currentSpeakState;

	public void SetBodyReplacementB(Transform tofind)
	{
		BodyReplacementBase component = ((Component)tofind).GetComponent<BodyReplacementBase>();
		bodyReplacementB = component;
		Awake();
	}

	private void Awake()
	{
		if (!((Object)(object)bodyReplacementB == (Object)null))
		{
			plrCntrB = bodyReplacementB.controller;
			body = ((Component)this).gameObject.GetComponent<SkinnedMeshRenderer>();
			parent = ((Component)((Component)this).gameObject.transform.parent).gameObject;
			if (!plrCntrB.isPlayerDead && died)
			{
				died = false;
				OnRespawn();
			}
			requiredVolume = 70f;
		}
	}

	private void OnEnable()
	{
		if ((Object)(object)bodyReplacementB == (Object)null)
		{
			return;
		}
		requiredVolume = 70f;
		plrCntrB = bodyReplacementB.controller;
		if (!plrCntrB.isPlayerDead)
		{
			if (died)
			{
				died = false;
				OnRespawn();
			}
			if (blinkingInstance != null)
			{
				((MonoBehaviour)this).StopCoroutine(blinkingInstance);
			}
			if (speakingInstance != null)
			{
				((MonoBehaviour)this).StopCoroutine(speakingInstance);
			}
			body.SetBlendShapeWeight(15, 0f);
			body.SetBlendShapeWeight(32, 0f);
			body.SetBlendShapeWeight(20, 0f);
			eyeOpen = true;
			isblinking = false;
			isScreaming = false;
		}
		else if (died)
		{
			OnDeath();
		}
		StartOfRound.Instance.RefreshPlayerVoicePlaybackObjects();
		vps = plrCntrB.voicePlayerState;
		if (vps == null && (Object)(object)plrCntrB == (Object)(object)StartOfRound.Instance.localPlayerController)
		{
			vps = StartOfRound.Instance.voiceChatModule.FindPlayer(StartOfRound.Instance.voiceChatModule.LocalPlayerName);
		}
	}

	private void Update()
	{
		if ((Object)(object)plrCntrB == (Object)null)
		{
			plrCntrB = bodyReplacementB.controller;
		}
		if (!isblinking && (Object)(object)body != (Object)null && !died && !isScreaming)
		{
			isblinking = true;
			if (blinkingInstance != null)
			{
				((MonoBehaviour)this).StopCoroutine(blinkingInstance);
			}
			eyeOpen = !eyeOpen;
			blinkingInstance = changeBlinkState(BlinkShapes.Blink, EyeStateVal(eyeOpen), blinkingInstance);
			((MonoBehaviour)this).StartCoroutine(blinkingInstance);
		}
		if (plrCntrB.voicePlayerState != null)
		{
			vps = plrCntrB.voicePlayerState;
			if (vps.IsSpeaking)
			{
				if (voiceAmp() > requiredVolume && !isScreaming)
				{
					((MonoBehaviour)this).StartCoroutine(ChangeScreamState(screaming: true));
				}
				if (voiceAmp() < requiredVolume && isScreaming)
				{
					((MonoBehaviour)this).StartCoroutine(ChangeScreamState(screaming: false));
				}
				if (voiceAmp() > 5f && currentVoiceState != voicestate.Talking)
				{
					currentVoiceState = voicestate.Talking;
					if (speakingInstance != null)
					{
						((MonoBehaviour)this).StopCoroutine(speakingInstance);
					}
					speakingInstance = changeSpeakState(SpeakShapes.Mouth, 50, speakingInstance);
					((MonoBehaviour)this).StartCoroutine(speakingInstance);
				}
				if (voiceAmp() < 5f && currentVoiceState != 0)
				{
					currentVoiceState = voicestate.Closed;
					if (speakingInstance != null)
					{
						((MonoBehaviour)this).StopCoroutine(speakingInstance);
					}
					speakingInstance = changeSpeakState(SpeakShapes.Mouth, 0, speakingInstance);
					((MonoBehaviour)this).StartCoroutine(speakingInstance);
				}
			}
		}
		if (plrCntrB.isPlayerDead && !died)
		{
			died = true;
		}
		else if (!plrCntrB.isPlayerDead && died)
		{
			died = false;
			OnRespawn();
			if (blinkingInstance != null)
			{
				((MonoBehaviour)this).StopCoroutine(blinkingInstance);
			}
			if (speakingInstance != null)
			{
				((MonoBehaviour)this).StopCoroutine(speakingInstance);
			}
			body.SetBlendShapeWeight(15, 0f);
			body.SetBlendShapeWeight(32, 0f);
			body.SetBlendShapeWeight(20, 0f);
			eyeOpen = true;
			isblinking = false;
			isScreaming = false;
		}
	}

	public void OnDeath()
	{
		((MonoBehaviour)this).StopAllCoroutines();
		GameObject replacementDeadBody = bodyReplacementB.replacementDeadBody;
		Plugin.Logger.LogInfo((object)replacementDeadBody);
		SkinnedMeshRenderer val = (from x in replacementDeadBody.GetComponentsInChildren<SkinnedMeshRenderer>()
			where ((Object)x).name.Contains("Body")
			select x).FirstOrDefault();
		((Behaviour)((Component)this).gameObject.GetComponent<ExpressionManager>()).enabled = false;
		val.SetBlendShapeWeight(15, 100f);
		val.SetBlendShapeWeight(19, 100f);
	}

	private void OnRespawn()
	{
		isblinking = false;
		body.SetBlendShapeWeight(15, 0f);
		body.SetBlendShapeWeight(19, 0f);
	}

	private IEnumerator ChangeScreamState(bool screaming)
	{
		isblinking = true;
		isScreaming = screaming;
		body.SetBlendShapeWeight(15, 0f);
		if (blinkingInstance != null)
		{
			((MonoBehaviour)this).StopCoroutine(blinkingInstance);
		}
		blinkingInstance = changeBlinkState(BlinkShapes.Scream, EyeStateVal(!isScreaming), blinkingInstance, 0.03f);
		yield return ((MonoBehaviour)this).StartCoroutine(blinkingInstance);
		if (!isScreaming)
		{
			isblinking = false;
		}
	}

	private IEnumerator changeBlinkState(BlinkShapes state, int value, IEnumerator instance, float speed = 0.1f)
	{
		if (died)
		{
			yield break;
		}
		if (currentBlinkState != null)
		{
			((MonoBehaviour)this).StopCoroutine(currentBlinkState);
		}
		currentBlinkState = instance;
		float elapsedTime = 0f;
		while (body.GetBlendShapeWeight((int)state) != (float)value)
		{
			elapsedTime += Time.deltaTime;
			float percComplete = elapsedTime / speed;
			float blendKey = Mathf.Lerp(body.GetBlendShapeWeight((int)state), (float)value, percComplete);
			body.SetBlendShapeWeight((int)state, blendKey);
			yield return (object)new WaitForSeconds(0.01f);
		}
		body.SetBlendShapeWeight((int)state, (float)value);
		yield return (object)new WaitForSeconds(0.25f);
		currentBlinkState = null;
		if (state == BlinkShapes.Blink)
		{
			if ((float)value == 0f)
			{
				yield return (object)new WaitForSeconds(Random.Range(1f, 4f));
				isblinking = false;
			}
			else
			{
				isblinking = false;
			}
		}
	}

	private IEnumerator changeSpeakState(SpeakShapes state, int value, IEnumerator instance, float speed = 0.035f)
	{
		if (!died)
		{
			if (currentSpeakState != null)
			{
				((MonoBehaviour)this).StopCoroutine(currentSpeakState);
			}
			currentSpeakState = instance;
			float elapsedTime = 0f;
			while (body.GetBlendShapeWeight((int)state) != (float)value)
			{
				elapsedTime += Time.deltaTime;
				float percComplete = elapsedTime / speed;
				float blendKey = Mathf.Lerp(body.GetBlendShapeWeight((int)state), (float)value, percComplete);
				body.SetBlendShapeWeight((int)state, blendKey);
				yield return (object)new WaitForSeconds(0.01f);
			}
			body.SetBlendShapeWeight((int)state, (float)value);
			currentSpeakState = null;
		}
	}

	private int EyeStateVal(bool state)
	{
		if (state)
		{
			return 0;
		}
		return 100;
	}

	private float voiceAmp()
	{
		return vps.Amplitude * 6.5f * 100f;
	}
}
public class UIReplacementManager : MonoBehaviour
{
	public GameObject PlayerHud_Self;

	public Image selfOut;

	public Image selfFill;

	private Sprite cachedImgFill;

	private Sprite cachedImgOut;

	private bool setNew = false;

	private void Awake()
	{
		PlayerHud_Self = GameObject.Find("IngamePlayerHUD/TopLeftCorner");
		selfFill = ((Component)PlayerHud_Self.transform.Find("SelfRed")).GetComponent<Image>();
		selfOut = ((Component)PlayerHud_Self.transform.Find("Self")).GetComponent<Image>();
		setNew = false;
	}

	private void OnEnable()
	{
		if (!setNew)
		{
			cachedImgFill = selfFill.sprite;
			cachedImgOut = selfOut.sprite;
			selfOut.sprite = Assets.MainAssetBundle.LoadAsset<Sprite>("BunBoyFillOut.png");
			selfFill.sprite = Assets.MainAssetBundle.LoadAsset<Sprite>("BunBoyFillIn.png");
			setNew = true;
		}
	}

	private void OnDisable()
	{
		setNew = false;
		selfOut.sprite = cachedImgOut;
		selfFill.sprite = cachedImgFill;
	}
}
namespace ModelReplacement
{
	public class MRPLAYTIMEBUNNYALL : BodyReplacementBase
	{
		private ExpressionManager EM;

		public override GameObject LoadAssetsAndReturnModel()
		{
			string text = "PlaytimeBunnyAll";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}

		public override void AddModelScripts()
		{
			PlayerControllerB component = ((Component)this).gameObject.GetComponent<PlayerControllerB>();
			Transform val = ((IEnumerable<Transform>)base.replacementModel.GetComponentsInChildren<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform x) => ((Object)x).name.Contains("Body")));
			if (!Object.op_Implicit((Object)(object)((Component)val).gameObject.GetComponent<ExpressionManager>()) != Object.op_Implicit((Object)null))
			{
				ExpressionManager expressionManager = ((Component)val).gameObject.AddComponent<ExpressionManager>();
				expressionManager.SetBodyReplacementB(((Component)this).gameObject.transform);
				EM = expressionManager;
			}
			if ((Object)(object)component == (Object)(object)StartOfRound.Instance.localPlayerController && (Object)(object)((Component)val.parent).GetComponent<UIReplacementManager>() == (Object)null && ((NetworkBehaviour)component).IsOwner)
			{
				UIReplacementManager uIReplacementManager = ((Component)val.parent).gameObject.AddComponent<UIReplacementManager>();
			}
		}
	}
	public class MRPLAYTIMEBUNNYMAKEUPNOACC : BodyReplacementBase
	{
		private ExpressionManager EM;

		public override GameObject LoadAssetsAndReturnModel()
		{
			string text = "PlaytimeBunnyMakeUpNoAcc";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}

		public override void AddModelScripts()
		{
			PlayerControllerB component = ((Component)this).gameObject.GetComponent<PlayerControllerB>();
			Transform val = ((IEnumerable<Transform>)base.replacementModel.GetComponentsInChildren<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform x) => ((Object)x).name.Contains("Body")));
			if (!Object.op_Implicit((Object)(object)((Component)val).gameObject.GetComponent<ExpressionManager>()) != Object.op_Implicit((Object)null))
			{
				ExpressionManager expressionManager = ((Component)val).gameObject.AddComponent<ExpressionManager>();
				expressionManager.SetBodyReplacementB(((Component)this).gameObject.transform);
				EM = expressionManager;
			}
			if ((Object)(object)component == (Object)(object)StartOfRound.Instance.localPlayerController && (Object)(object)((Component)val.parent).GetComponent<UIReplacementManager>() == (Object)null && ((NetworkBehaviour)component).IsOwner)
			{
				UIReplacementManager uIReplacementManager = ((Component)val.parent).gameObject.AddComponent<UIReplacementManager>();
			}
		}
	}
	public class MRPLAYTIMEBUNNYACCNOMAKEUP : BodyReplacementBase
	{
		private ExpressionManager EM;

		public override GameObject LoadAssetsAndReturnModel()
		{
			string text = "PlaytimeBunnyAccNoMakeUp";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}

		public override void AddModelScripts()
		{
			PlayerControllerB component = ((Component)this).gameObject.GetComponent<PlayerControllerB>();
			Transform val = ((IEnumerable<Transform>)base.replacementModel.GetComponentsInChildren<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform x) => ((Object)x).name.Contains("Body")));
			if (!Object.op_Implicit((Object)(object)((Component)val).gameObject.GetComponent<ExpressionManager>()) != Object.op_Implicit((Object)null))
			{
				ExpressionManager expressionManager = ((Component)val).gameObject.AddComponent<ExpressionManager>();
				expressionManager.SetBodyReplacementB(((Component)this).gameObject.transform);
				EM = expressionManager;
			}
			if ((Object)(object)component == (Object)(object)StartOfRound.Instance.localPlayerController && (Object)(object)((Component)val.parent).GetComponent<UIReplacementManager>() == (Object)null && ((NetworkBehaviour)component).IsOwner)
			{
				UIReplacementManager uIReplacementManager = ((Component)val.parent).gameObject.AddComponent<UIReplacementManager>();
			}
		}
	}
	public class MRPLAYTIMEBUNNYNOACCNOMAKEUP : BodyReplacementBase
	{
		private ExpressionManager EM;

		public override GameObject LoadAssetsAndReturnModel()
		{
			string text = "PlaytimeBunnyNoAccNoMakeup";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}

		public override void AddModelScripts()
		{
			PlayerControllerB component = ((Component)this).gameObject.GetComponent<PlayerControllerB>();
			Transform val = ((IEnumerable<Transform>)base.replacementModel.GetComponentsInChildren<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform x) => ((Object)x).name.Contains("Body")));
			if (!Object.op_Implicit((Object)(object)((Component)val).gameObject.GetComponent<ExpressionManager>()) != Object.op_Implicit((Object)null))
			{
				ExpressionManager expressionManager = ((Component)val).gameObject.AddComponent<ExpressionManager>();
				expressionManager.SetBodyReplacementB(((Component)this).gameObject.transform);
				EM = expressionManager;
			}
			if ((Object)(object)component == (Object)(object)StartOfRound.Instance.localPlayerController && (Object)(object)((Component)val.parent).GetComponent<UIReplacementManager>() == (Object)null && ((NetworkBehaviour)component).IsOwner)
			{
				UIReplacementManager uIReplacementManager = ((Component)val.parent).gameObject.AddComponent<UIReplacementManager>();
			}
		}
	}
	[BepInPlugin("com.local.moddingcompany.playtimebunnymodelreplacement", "PlaytimeBunny_ModelReplacement", "0.1.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			Assets.PopulateAssets();
			ModelReplacementAPI.RegisterSuitModelReplacement("PlaytimeBunnyAccNoMakeUp", typeof(MRPLAYTIMEBUNNYACCNOMAKEUP));
			ModelReplacementAPI.RegisterSuitModelReplacement("PlaytimeBunnyAll", typeof(MRPLAYTIMEBUNNYALL));
			ModelReplacementAPI.RegisterSuitModelReplacement("PlaytimeBunnyMakeUpNoAcc", typeof(MRPLAYTIMEBUNNYMAKEUPNOACC));
			ModelReplacementAPI.RegisterSuitModelReplacement("PlaytimeBunnyNoAccNoMakeUp", typeof(MRPLAYTIMEBUNNYNOACCNOMAKEUP));
			Harmony val = new Harmony("com.local.moddingcompany.playtimebunnymodelreplacement");
			val.PatchAll();
			Logger.LogInfo((object)"Plugin com.local.moddingcompany.playtimebunnymodelreplacement is loaded!");
		}
	}
	public static class Assets
	{
		public static string mainAssetBundleName = "playtimebunnyassets";

		public static AssetBundle MainAssetBundle = null;

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

		public static void PopulateAssets()
		{
			if ((Object)(object)MainAssetBundle == (Object)null)
			{
				Console.WriteLine(GetAssemblyName() + "." + mainAssetBundleName);
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + mainAssetBundleName);
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}