Decompiled source of ShyGal Playermodels v1.2.0

ShyGalPlayermodelsMod.dll

Decompiled 2 weeks ago
using System;
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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using ShyGalModelReplacement.Expression;
using TooManyEmotes;
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("ShyGalPlayermodelsMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ab2f28d14ab8cd4dad3aa3b27c081b2d34874754")]
[assembly: AssemblyProduct("ShyGalPlayermodelsMod")]
[assembly: AssemblyTitle("ShyGalPlayermodelsMod")]
[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;
		}
	}
}
namespace ShyGalModelReplacement
{
	public class SHYGALBASE : BodyReplacementBase
	{
		private int danceID = 0;

		private int previousDanceID = 0;

		protected string model_name;

		protected FaceExpression defaultExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

		protected FaceExpression happyExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0);

		protected FaceExpression happyEyesClosedExpression = new FaceExpression(0, 0, 0, 0, 0, 75, 0, 0, 0, 0, 65, 0, 0, 0, 0);

		protected FaceExpression surprisedExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0);

		protected FaceExpression closedEyesExpression = new FaceExpression(0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

		protected FaceExpression deadExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 25, 0, 0, 50, 0);

		protected Tweener tweenManager;

		protected override GameObject LoadAssetsAndReturnModel()
		{
			model_name = "Shygal";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(model_name);
		}

		protected virtual void OnEmote(int emoteId)
		{
			if (Plugin.enableEmoteExpressions.Value)
			{
				switch (emoteId)
				{
				case -302:
				case -194:
				case -129:
				case -52:
				case -18:
				case 1:
					tweenManager.CreateTweenAndRun(happyExpression, 0.1f);
					break;
				case -155:
				case 2:
					tweenManager.CreateTweenAndRun(surprisedExpression, 0.1f);
					break;
				case -89:
				case -3:
					tweenManager.CreateTweenAndRun(closedEyesExpression, 0.1f);
					break;
				case -219:
				case -170:
				case -133:
				case -46:
				case -36:
					tweenManager.CreateTweenAndRun(happyEyesClosedExpression, 0.1f);
					break;
				default:
					tweenManager.CreateTweenAndRun(defaultExpression, 0.1f);
					break;
				}
			}
		}

		protected override void OnDeath()
		{
			if (Plugin.enableDeathExpressions.Value)
			{
				deadExpression.setExpression(base.replacementDeadBody.GetComponentInChildren<SkinnedMeshRenderer>());
			}
		}

		protected override void Awake()
		{
			((BodyReplacementBase)this).Awake();
			tweenManager = new Tweener(base.replacementModel.GetComponentInChildren<SkinnedMeshRenderer>());
		}

		public override void LateUpdate()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			((BodyReplacementBase)this).LateUpdate();
			previousDanceID = danceID;
			AnimatorStateInfo currentAnimatorStateInfo = ((BodyReplacementBase)this).controller.playerBodyAnimator.GetCurrentAnimatorStateInfo(1);
			int fullPathHash = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash;
			if (((BodyReplacementBase)this).controller.performingEmote)
			{
				switch (fullPathHash)
				{
				case -462656950:
					danceID = 1;
					break;
				case 2103786480:
					danceID = 2;
					break;
				default:
					danceID = 3;
					break;
				}
			}
			else
			{
				danceID = 0;
			}
			if (ModelReplacementAPI.tooManyEmotesPresent)
			{
				danceID = getEmoteIDWithTME(danceID);
			}
			if (previousDanceID != danceID)
			{
				OnEmote(danceID);
			}
			tweenManager.LateUpdate();
		}

		private int getEmoteIDWithTME(int emoteID)
		{
			if (EmoteControllerPlayer.allPlayerEmoteControllers.TryGetValue(((BodyReplacementBase)this).controller, out var value) && ((EmoteController)value).IsPerformingCustomEmote())
			{
				return ((EmoteController)value).performingEmote.emoteId * -1 - 1;
			}
			return emoteID;
		}

		protected override void OnHitEnemy(bool dead)
		{
		}

		protected override void OnHitAlly(PlayerControllerB ally, bool dead)
		{
		}

		protected override void OnDamageTaken(bool dead)
		{
		}

		protected override void OnDamageTakenByAlly(PlayerControllerB ally, bool dead)
		{
		}

		protected override void OnEmoteStart(int emoteId)
		{
		}

		protected override void OnEmoteEnd()
		{
		}
	}
	public class SHYGALRED : SHYGALBASE
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			model_name = "Shygal Red";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(model_name);
		}
	}
	public class SHYGALBLUE : SHYGALBASE
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			model_name = "Shygal Blue";
			defaultExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0);
			happyExpression = happyEyesClosedExpression;
			return Assets.MainAssetBundle.LoadAsset<GameObject>(model_name);
		}
	}
	public class SHYGALBLACK : SHYGALBASE
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			model_name = "Shygal Black";
			defaultExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0);
			happyExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 100, 0, 0, 0, 0);
			surprisedExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 0);
			deadExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 100, 10, 0, 0, 0, 0, 0, 0);
			return Assets.MainAssetBundle.LoadAsset<GameObject>(model_name);
		}
	}
	public class SHYGALGREEN : SHYGALBASE
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			model_name = "Shygal Green";
			defaultExpression = new FaceExpression(0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
			happyExpression = new FaceExpression(0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0);
			surprisedExpression = new FaceExpression(0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
			deadExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 100, 25, 0, 0, 0, 0, 25, 0);
			return Assets.MainAssetBundle.LoadAsset<GameObject>(model_name);
		}
	}
	public class SHYGALYELLOW : SHYGALBASE
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			model_name = "Shygal Yellow";
			deadExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 50, 30);
			return Assets.MainAssetBundle.LoadAsset<GameObject>(model_name);
		}
	}
	public class SHYGALWHITE : SHYGALBASE
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			model_name = "Shygal White";
			defaultExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0);
			happyExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 100, 0, 0, 0, 0);
			deadExpression = new FaceExpression(0, 0, 0, 0, 20, 0, 0, 100, 65, 0, 0, 0, 0, 50, 0);
			return Assets.MainAssetBundle.LoadAsset<GameObject>(model_name);
		}
	}
	public class SHYGALPURPLE : SHYGALBASE
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			model_name = "Shygal Purple";
			defaultExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0);
			happyExpression = new FaceExpression(0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 70, 0, 0, 0, 0);
			return Assets.MainAssetBundle.LoadAsset<GameObject>(model_name);
		}
	}
	public class SHYGALPINK : SHYGALBASE
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			model_name = "Shygal Pink";
			defaultExpression = new FaceExpression(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0);
			happyExpression = new FaceExpression(100, 0, 0, 0, 0, 75, 0, 0, 0, 0, 65, 0, 0, 0, 0);
			surprisedExpression = new FaceExpression(0, 0, 100, 0, 0, 0, 0, 20, 0, 0, 100, 0, 0, 0, 0);
			deadExpression = new FaceExpression(0, 0, 0, 0, 95, 0, 0, 100, 50, 0, 30, 0, 30, 0, 30);
			return Assets.MainAssetBundle.LoadAsset<GameObject>(model_name);
		}

		protected override void OnEmote(int emoteId)
		{
			base.OnEmote(emoteId);
			if (emoteId == -18)
			{
				tweenManager.CreateTweenAndRun(surprisedExpression, 0.1f);
			}
		}
	}
	public class SHYGALORANGE : SHYGALBASE
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			model_name = "Shygal Orange";
			happyExpression = happyEyesClosedExpression;
			return Assets.MainAssetBundle.LoadAsset<GameObject>(model_name);
		}
	}
	[BepInPlugin("com.cydern.shygalplayermodels", "ShyGal Playermodels", "1.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigFile config;

		public static ConfigEntry<bool> enableEmoteExpressions { get; private set; }

		public static ConfigEntry<bool> enableDeathExpressions { get; private set; }

		private static void InitConfig()
		{
			enableEmoteExpressions = config.Bind<bool>("Expressions (Client-Sided)", "Enable Expressions on Emote", true, "When enabled, ShyGals will change expressions when emoting.");
			enableDeathExpressions = config.Bind<bool>("Expressions (Client-Sided)", "Enable Expressions on Death", true, "When enabled, ShyGals will change expressions on death");
		}

		private void Awake()
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			config = ((BaseUnityPlugin)this).Config;
			InitConfig();
			Assets.PopulateAssets();
			ModelReplacementAPI.RegisterSuitModelReplacement("Shygal Red", typeof(SHYGALRED));
			ModelReplacementAPI.RegisterSuitModelReplacement("Shygal Blue", typeof(SHYGALBLUE));
			ModelReplacementAPI.RegisterSuitModelReplacement("Shygal Black", typeof(SHYGALBLACK));
			ModelReplacementAPI.RegisterSuitModelReplacement("Shygal Green", typeof(SHYGALGREEN));
			ModelReplacementAPI.RegisterSuitModelReplacement("Shygal Yellow", typeof(SHYGALYELLOW));
			ModelReplacementAPI.RegisterSuitModelReplacement("Shygal White", typeof(SHYGALWHITE));
			ModelReplacementAPI.RegisterSuitModelReplacement("Shygal Purple", typeof(SHYGALPURPLE));
			ModelReplacementAPI.RegisterSuitModelReplacement("Shygal Pink", typeof(SHYGALPINK));
			ModelReplacementAPI.RegisterSuitModelReplacement("Shygal Orange", typeof(SHYGALORANGE));
			Harmony val = new Harmony("com.cydern.shygalplayermodels");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.cydern.shygalplayermodels is loaded!");
		}
	}
	public static class Assets
	{
		public static string mainAssetBundleName = "ShyGalPlayermodels";

		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 ShyGalModelReplacement.Expression
{
	public class FaceExpression
	{
		public short[] faceBlendshapes { get; private set; }

		public FaceExpression(short blush, short tribal, short heartEyes, short eyesHalfClosed, short eyesClosed, short eyesClosedHappy, short eyesAngry, short eyesSurprised, short eyesSad, short eyesConfused, short eyesHappy, short eyesSmug, short a, short o, short ch)
		{
			faceBlendshapes = new short[15]
			{
				blush, tribal, heartEyes, eyesHalfClosed, eyesClosed, eyesClosedHappy, eyesAngry, eyesSurprised, eyesSad, eyesConfused,
				eyesHappy, eyesSmug, a, o, ch
			};
		}

		public FaceExpression(short[] blendshapes)
		{
			faceBlendshapes = blendshapes;
		}

		public void setExpression(SkinnedMeshRenderer mask, float tweenTime = 0f)
		{
			for (int i = 0; i < faceBlendshapes.Length; i++)
			{
				mask.SetBlendShapeWeight(i, (float)faceBlendshapes[i]);
			}
		}
	}
	public class Tweener : MonoBehaviour
	{
		private SkinnedMeshRenderer mesh;

		private Tween activeTween;

		private float currentTweenTimeElapsed;

		private float currentTweenCompletion;

		private FaceExpression previousFaceExpression;

		private short[] beforeValues;

		private short[] afterValues;

		public Tweener(SkinnedMeshRenderer mesh)
		{
			this.mesh = mesh;
			beforeValues = new short[15];
			afterValues = new short[15];
		}

		public void LateUpdate()
		{
			if (currentTweenCompletion >= 1f)
			{
				activeTween = null;
				currentTweenTimeElapsed = 0f;
				currentTweenCompletion = 0f;
			}
			if (activeTween == null)
			{
				return;
			}
			currentTweenTimeElapsed += Time.deltaTime;
			currentTweenCompletion = currentTweenTimeElapsed / activeTween.tweenTime;
			if (currentTweenCompletion >= 1f)
			{
				activeTween.exitExpression.setExpression(mesh);
				return;
			}
			beforeValues = previousFaceExpression.faceBlendshapes;
			afterValues = activeTween.exitExpression.faceBlendshapes;
			for (int i = 0; i < beforeValues.Length; i++)
			{
				mesh.SetBlendShapeWeight(i, (float)(afterValues[i] - beforeValues[i]) * currentTweenCompletion + (float)beforeValues[i]);
			}
		}

		public void CreateTweenAndRun(FaceExpression face, float tweenTime, int weight = 0, bool queue = false)
		{
			activeTween = new Tween(face, tweenTime);
			currentTweenTimeElapsed = 0f;
			currentTweenCompletion = 0f;
			FillNewPreviousFaceExpression();
		}

		private void FillNewPreviousFaceExpression()
		{
			short[] array = new short[15];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = (short)mesh.GetBlendShapeWeight(i);
			}
			previousFaceExpression = new FaceExpression(array);
		}
	}
	public class Tween
	{
		public FaceExpression exitExpression;

		public float tweenTime;

		public Tween(FaceExpression exitExpression, float tweenTime)
		{
			this.exitExpression = exitExpression;
			this.tweenTime = tweenTime;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}