Decompiled source of BetterSkinwalkers v0.2.1

BetterSkinwalkers.dll

Decompiled 4 months 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using SkinwalkerMod;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("SkinwalkerMod")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("BetterSkinwalkers")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Changes certain mechanics of Skinwalkers for better gameplay")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+f800603fe4ece0a922bb91102f80b84c67ac543f")]
[assembly: AssemblyProduct("BetterSkinwalkers")]
[assembly: AssemblyTitle("BetterSkinwalkers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BetterSkinwalkers
{
	[BepInPlugin("xyz.exverge.betterskinwalkers", "BetterSkinWalkers", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("xyz.exverge.betterskinwalkers");

		internal static Plugin Instance;

		internal ConfigEntry<bool> OnlyHauntedHearsGirl;

		private void Awake()
		{
			Instance = this;
			OnlyHauntedHearsGirl = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "OnlyHauntedHearsGirl", false, "Changes whether or not everyone can hear ghost girl or if only the haunted person can.");
			SkinwalkerMod.player_clips_map = new Dictionary<string, List<int>>();
			harmony.PatchAll(typeof(SkinwalkerBehavior));
			harmony.PatchAll(typeof(SkinwalkerMod));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"BetterSkinWalkers has loaded!");
		}
	}
	public class SkinwalkerBehavior
	{
		[HarmonyPatch(typeof(SkinwalkerBehaviour), "SetNextTime")]
		[HarmonyPrefix]
		public static bool SetNextTime(ref SkinwalkerBehaviour __instance)
		{
			if (SkinwalkerNetworkManager.Instance.VoiceLineFrequency.Value <= 0f)
			{
				__instance.nextTimeToPlayAudio = float.MaxValue;
			}
			else if (__instance.ai is MaskedPlayerEnemy)
			{
				__instance.nextTimeToPlayAudio = Time.time + Random.Range(3f, 10f) / SkinwalkerNetworkManager.Instance.VoiceLineFrequency.Value;
			}
			else
			{
				__instance.nextTimeToPlayAudio = Time.time + Random.Range(15f, 40f) / SkinwalkerNetworkManager.Instance.VoiceLineFrequency.Value;
			}
			return false;
		}

		[HarmonyPatch(typeof(SkinwalkerBehaviour), "AttemptPlaySound")]
		[HarmonyPrefix]
		public static bool AttemptPlaySound(ref SkinwalkerBehaviour __instance)
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)__instance.ai) && !__instance.ai.isEnemyDead)
			{
				if (((Object)((Component)__instance.ai).gameObject).name == "DressGirl(Clone)" && Plugin.Instance.OnlyHauntedHearsGirl.Value)
				{
					DressGirlAI val = (DressGirlAI)__instance.ai;
					if ((Object)(object)val.hauntingPlayer != (Object)(object)StartOfRound.Instance.localPlayerController)
					{
						SkinwalkerLogger.Log((object)(((Object)__instance).name + " played voice line no (not haunted) EnemyAI: " + (object)__instance.ai));
						return false;
					}
					if (!val.staringInHaunt && !((EnemyAI)val).moveTowardsDestination)
					{
						SkinwalkerLogger.Log((object)(((Object)__instance).name + " played voice line no (not visible) EnemyAI: " + (object)__instance.ai));
						return false;
					}
				}
				Vector3 val2 = (StartOfRound.Instance.localPlayerController.isPlayerDead ? ((Component)StartOfRound.Instance.spectateCamera).transform.position : ((Component)StartOfRound.Instance.localPlayerController).transform.position);
				float num;
				if ((Object)(object)StartOfRound.Instance == (Object)null || (Object)(object)StartOfRound.Instance.localPlayerController == (Object)null || (double)(num = Vector3.Distance(val2, ((Component)__instance).transform.position)) < 100.0)
				{
					EnemyAI ai = __instance.ai;
					MaskedPlayerEnemy val3 = (MaskedPlayerEnemy)(object)((ai is MaskedPlayerEnemy) ? ai : null);
					AudioClip val4 = ((val3 != null) ? SkinwalkerMod.GetPlayerSpecificSample(val3.mimickingPlayer.voicePlayerState.Name) : SkinwalkerModPersistent.Instance.GetSample());
					if (Object.op_Implicit((Object)(object)val4))
					{
						SkinwalkerLogger.Log((object)(((Object)__instance).name + " played voice line 1"));
						__instance.audioSource.PlayOneShot(val4);
					}
					else
					{
						SkinwalkerLogger.Log((object)(((Object)__instance).name + " played voice line 0"));
					}
				}
				else
				{
					SkinwalkerLogger.Log((object)(((Object)__instance).name + " played voice line no (too far away) " + num));
				}
			}
			else
			{
				SkinwalkerLogger.Log((object)(((Object)__instance).name + " played voice line no (dead) EnemyAI: " + (object)__instance.ai));
			}
			return false;
		}
	}
	public class SkinwalkerMod
	{
		public static Dictionary<string, List<int>> player_clips_map;

		[HarmonyPatch(typeof(SkinwalkerModPersistent), "GetSample")]
		[HarmonyPrefix]
		public static bool GetSample(ref SkinwalkerModPersistent __instance, ref AudioClip __result)
		{
			while (__instance.cachedAudio.Count > 200)
			{
				__instance.cachedAudio.RemoveAt(Random.Range(0, __instance.cachedAudio.Count - 125));
			}
			if (__instance.cachedAudio.Count == 0)
			{
				__result = null;
				return false;
			}
			int index = Random.Range(0, __instance.cachedAudio.Count - 1);
			AudioClip val = (__result = __instance.cachedAudio[index]);
			__instance.cachedAudio.RemoveAt(index);
			foreach (List<int> value in player_clips_map.Values)
			{
				if (value.Remove(((Object)val).GetInstanceID()))
				{
					return false;
				}
			}
			return false;
		}

		internal static AudioClip GetPlayerSpecificSample(string player)
		{
			SkinwalkerModPersistent instance = SkinwalkerModPersistent.Instance;
			while (instance.cachedAudio.Count > 200)
			{
				instance.cachedAudio.RemoveAt(Random.Range(0, instance.cachedAudio.Count - 125));
			}
			if (instance.cachedAudio.Count == 0 || !player_clips_map.ContainsKey(player))
			{
				return null;
			}
			List<int> valueSafe = GeneralExtensions.GetValueSafe<string, List<int>>(player_clips_map, player);
			int index = Random.Range(0, valueSafe.Count - 1);
			int num = valueSafe[index];
			AudioClip val = null;
			foreach (AudioClip item in instance.cachedAudio)
			{
				if (((Object)item).GetInstanceID() == num)
				{
					val = item;
					break;
				}
			}
			instance.cachedAudio.Remove(val);
			valueSafe.RemoveAt(index);
			return val;
		}

		[HarmonyPatch(typeof(SkinwalkerModPersistent), "Update")]
		[HarmonyPrefix]
		internal static bool Update(ref SkinwalkerModPersistent __instance)
		{
			if ((double)Time.realtimeSinceStartup > (double)__instance.nextTimeToCheckFolder)
			{
				__instance.nextTimeToCheckFolder = Time.realtimeSinceStartup + 8f;
				if (!Directory.Exists(__instance.audioFolder))
				{
					SkinwalkerLogger.Log((object)("Audio folder not present. Don't worry about it, it will be created automatically when you play with friends. (" + __instance.audioFolder + ")"));
					return false;
				}
				string[] files = Directory.GetFiles(__instance.audioFolder);
				SkinwalkerLogger.Log((object)$"Got audio file paths ({files.Length})");
				string[] array = files;
				foreach (string path in array)
				{
					((MonoBehaviour)__instance).StartCoroutine(__instance.LoadWavFile(path, (Action<AudioClip>)delegate(AudioClip audioClip)
					{
						SkinwalkerModPersistent.Instance.cachedAudio.Add(audioClip);
						string text = path.Split(new string[1] { "Dissonance_Diagnostics\\Output_" }, StringSplitOptions.None)[1].Split('_')[0];
						if (!player_clips_map.ContainsKey(text))
						{
							player_clips_map.Add(text, new List<int>());
						}
						GeneralExtensions.GetValueSafe<string, List<int>>(player_clips_map, text).Add(((Object)audioClip).GetInstanceID());
					}));
				}
			}
			if ((double)Time.realtimeSinceStartup <= (double)__instance.nextTimeToCheckEnemies)
			{
				return false;
			}
			__instance.nextTimeToCheckEnemies = Time.realtimeSinceStartup + 5f;
			EnemyAI[] array2 = Object.FindObjectsOfType<EnemyAI>(true);
			SkinwalkerBehaviour val2 = default(SkinwalkerBehaviour);
			foreach (EnemyAI val in array2)
			{
				try
				{
					SkinwalkerLogger.Log((object)("IsEnemyEnabled " + ((Object)val).name + " " + __instance.IsEnemyEnabled(val)));
					if (__instance.IsEnemyEnabled(val) && !((Component)val).TryGetComponent<SkinwalkerBehaviour>(ref val2))
					{
						((Component)val).gameObject.AddComponent<SkinwalkerBehaviour>().Initialize(val);
					}
				}
				catch (NullReferenceException ex)
				{
					SkinwalkerLogger.LogError((object)("BetterSkinWalkers: An error has occurred checking an invalid EnemyAI for " + ((Object)val).name + " that is missing a game object."));
					SkinwalkerLogger.LogWarning((object)"BetterSkinwalkers: If this is a modded enemy, it is most likely an issue with that mod");
					SkinwalkerLogger.LogWarning((object)"BetterSkinwalkers: Otherwise, please report this to BetterSkinwalkers.");
					SkinwalkerLogger.LogError((object)ex);
				}
			}
			return false;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BetterSkinwalkers";

		public const string PLUGIN_NAME = "BetterSkinwalkers";

		public const string PLUGIN_VERSION = "0.2.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}