Decompiled source of FreakhoundUpdate v0.1.1

FreakhoundUptade.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 Dissonance;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("FreakhoundUptade")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FreakhoundUptade")]
[assembly: AssemblyTitle("FreakhoundUptade")]
[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 ModelReplacement
{
	public class MRFREAKHOUND123 : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "freakhound123";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}

		protected override void AddModelScripts()
		{
			Transform val = base.replacementModel.transform.Find("Armature/hips/spine/chest/neck/head/jaw");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"[MRFREAKHOUND123] Jaw bone not found! Check the path: Armature/hips/spine/chest/neck/head/jaw");
				return;
			}
			GameObject gameObject = ((Component)val).gameObject;
			JawSync jawSync = gameObject.AddComponent<JawSync>();
			jawSync.player = ((BodyReplacementBase)this).controller;
			Debug.Log((object)("[MRFREAKHOUND123] JawSync added for player: " + ((BodyReplacementBase)this).controller.playerUsername));
		}
	}
	public class JawSync : MonoBehaviour
	{
		public PlayerControllerB player;

		public float closedJawAngle = 0f;

		public float openJawAngle = 25f;

		public float sensitivityMultiplier = 2f;

		public float smoothTime = 0.05f;

		private Vector3 startingLocalRotation;

		private VoicePlayerState voice;

		private float currentJawAngle;

		private float smoothVelocity;

		private bool initialized = false;

		private float initTimer = 0f;

		private DissonanceComms dissonanceComms;

		private float sensitivity
		{
			get
			{
				if (Plugin.voiceSensitivity != null)
				{
					return Plugin.voiceSensitivity.Value;
				}
				return 15f;
			}
		}

		private void Start()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			startingLocalRotation = ((Component)this).transform.localEulerAngles;
			closedJawAngle = startingLocalRotation.x;
			currentJawAngle = closedJawAngle;
			dissonanceComms = Object.FindObjectOfType<DissonanceComms>();
		}

		private void Update()
		{
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			if (!initialized)
			{
				initTimer += Time.deltaTime;
				if (initTimer > 0.5f)
				{
					Init();
					initialized = true;
				}
			}
			else
			{
				if ((Object)(object)StartOfRound.Instance == (Object)null || (Object)(object)player == (Object)null)
				{
					return;
				}
				if (voice == null)
				{
					Init();
					if (voice == null)
					{
						return;
					}
				}
				if (voice.IsSpeaking && !player.isPlayerDead)
				{
					float num = Mathf.Clamp01(voice.Amplitude * sensitivity * sensitivityMultiplier * 0.1f);
					float num2 = Mathf.Pow(num, 0.7f);
					float num3 = Mathf.Lerp(closedJawAngle, openJawAngle, num2);
					currentJawAngle = Mathf.SmoothDamp(currentJawAngle, num3, ref smoothVelocity, smoothTime);
				}
				else
				{
					currentJawAngle = Mathf.SmoothDamp(currentJawAngle, closedJawAngle, ref smoothVelocity, smoothTime * 1.5f);
				}
				Vector3 val = startingLocalRotation;
				val.x = currentJawAngle;
				((Component)this).transform.localRotation = Quaternion.Euler(val);
			}
		}

		public void Init()
		{
			if ((Object)(object)player == (Object)null)
			{
				Debug.LogError((object)"[JawSync] Player is null!");
				return;
			}
			voice = player.voicePlayerState;
			if (voice == null && (Object)(object)StartOfRound.Instance != (Object)null)
			{
				DissonanceComms voiceChatModule = StartOfRound.Instance.voiceChatModule;
				if ((Object)(object)voiceChatModule != (Object)null)
				{
					voice = voiceChatModule.FindPlayer(player.playerUsername);
				}
			}
			if (voice == null && (Object)(object)dissonanceComms != (Object)null)
			{
				voice = dissonanceComms.FindPlayer(player.playerUsername);
			}
			if (voice == null && (Object)(object)player == (Object)(object)StartOfRound.Instance?.localPlayerController)
			{
				DissonanceComms val = StartOfRound.Instance?.voiceChatModule;
				if ((Object)(object)val != (Object)null)
				{
					voice = val.FindPlayer(val.LocalPlayerName);
				}
			}
			if (voice != null)
			{
				Debug.Log((object)("[JawSync] Successfully initialized voice for player: " + player.playerUsername));
			}
		}
	}
	[BepInPlugin("com.freakhound.update", "FreakhoundUpdated", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<float> voiceSensitivity;

		public static ConfigEntry<bool> enableModelForAllSuits;

		public static ConfigEntry<float> jawOpenAngle;

		public static ConfigEntry<float> jawSensitivityMultiplier;

		private void Awake()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			InitConfig();
			Assets.PopulateAssets();
			if (enableModelForAllSuits.Value)
			{
				ModelReplacementAPI.RegisterModelReplacementOverride(typeof(MRFREAKHOUND123));
			}
			Harmony val = new Harmony("com.freakhound.update");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin FreakHoundUpdate is loaded!");
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Voice sensitivity: {voiceSensitivity.Value}");
		}

		private void InitConfig()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			enableModelForAllSuits = ((BaseUnityPlugin)this).Config.Bind<bool>("Model Settings", "Enable for all suits", true, "Enable model replacement for every suit. Set to false to specify suits manually.");
			voiceSensitivity = ((BaseUnityPlugin)this).Config.Bind<float>("Voice Settings", "Sensitivity", 15f, new ConfigDescription("Voice sensitivity for jaw movement (higher = more sensitive)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 50f), Array.Empty<object>()));
			jawOpenAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Voice Settings", "Jaw open angle", 25f, new ConfigDescription("Maximum jaw opening angle in degrees", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 60f), Array.Empty<object>()));
			jawSensitivityMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Voice Settings", "Sensitivity multiplier", 2f, new ConfigDescription("Additional sensitivity multiplier", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
		}
	}
	public static class Assets
	{
		public static string mainAssetBundleName = "FreakhoundUpdate";

		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))
			{
				return;
			}
			string text = GetAssemblyName() + "." + mainAssetBundleName;
			Debug.Log((object)("[Assets] Loading AssetBundle: " + text));
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text);
			if (stream == null)
			{
				Debug.LogError((object)("[Assets] Could not find resource: " + text));
				return;
			}
			MainAssetBundle = AssetBundle.LoadFromStream(stream);
			Debug.Log((object)"[Assets] AssetBundle loaded successfully!");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}