Decompiled source of HoharderSkin v1.0.3

com.github.zehsteam.HoharderSkin.dll

Decompiled a week 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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using Mirage.Domain.Audio;
using Steamworks;
using UnityEngine;
using UnityEngine.Networking;
using com.github.zehsteam.HoharderSkin.Dependencies;
using com.github.zehsteam.HoharderSkin.Patches;

[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: AssemblyCompany("com.github.zehsteam.HoharderSkin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Reskins the Hoarding Bug to PsychoHypnotic as a potato.")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+7870d29512ef1ad25dc6df30ce02469c1d600bbf")]
[assembly: AssemblyProduct("HoharderSkin")]
[assembly: AssemblyTitle("com.github.zehsteam.HoharderSkin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 com.github.zehsteam.HoharderSkin
{
	internal static class AudioUtils
	{
		public static AudioClip LoadAudioClip(string path, AudioType type)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			string text = "file://" + path;
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(text, type);
			try
			{
				UnityWebRequestAsyncOperation val = audioClip.SendWebRequest();
				try
				{
					while (!((AsyncOperation)val).isDone)
					{
					}
					if ((int)audioClip.result != 1)
					{
						Plugin.Logger.LogError((object)("Failed to load AudioClip from path \"" + path + "\". Error: " + audioClip.error));
						return null;
					}
					AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
					((Object)content).name = Path.GetFileNameWithoutExtension(path);
					Plugin.Instance.LogInfoExtended("Successfully loaded AudioClip \"" + ((Object)content).name + "\" from path \"" + path + "\".");
					return content;
				}
				catch (Exception arg)
				{
					Plugin.Logger.LogError((object)$"Failed to load AudioClip from path \"{path}\". {arg}");
				}
				return null;
			}
			finally
			{
				((IDisposable)audioClip)?.Dispose();
			}
		}

		public static AudioType DetectAudioType(string filePath)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.GetExtension(filePath).ToLower();
			switch (text)
			{
			case ".wav":
				return (AudioType)20;
			case ".ogg":
				return (AudioType)14;
			case ".mp3":
				return (AudioType)13;
			default:
				Plugin.Logger.LogWarning((object)("Unknown audio file extension: " + text + ". Defaulting to WAV."));
				return (AudioType)20;
			}
		}
	}
	internal static class ConfigHelper
	{
		public static void SkipAutoGen()
		{
			if (LethalConfigProxy.Enabled)
			{
				LethalConfigProxy.SkipAutoGen();
			}
		}

		public static void AddButton(string section, string name, string description, string buttonText, Action callback)
		{
			if (LethalConfigProxy.Enabled)
			{
				LethalConfigProxy.AddButton(section, name, description, buttonText, callback);
			}
		}

		public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, bool requiresRestart, string description, AcceptableValueBase acceptableValues = null, Action<T> settingChanged = null, ConfigFile configFile = null)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if (configFile == null)
			{
				configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
			}
			ConfigEntry<T> configEntry = ((acceptableValues == null) ? configFile.Bind<T>(section, key, defaultValue, description) : configFile.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, Array.Empty<object>())));
			if (settingChanged != null)
			{
				configEntry.SettingChanged += delegate
				{
					settingChanged?.Invoke(configEntry.Value);
				};
			}
			if (LethalConfigProxy.Enabled)
			{
				LethalConfigProxy.AddConfig<T>(configEntry, requiresRestart);
			}
			return configEntry;
		}

		public static Dictionary<ConfigDefinition, string> GetOrphanedConfigEntries(ConfigFile configFile = null)
		{
			if (configFile == null)
			{
				configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
			}
			PropertyInfo property = ((object)configFile).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			return (Dictionary<ConfigDefinition, string>)property.GetValue(configFile, null);
		}

		public static void SetConfigEntryValue<T>(ConfigEntry<T> configEntry, string value)
		{
			if (typeof(T) == typeof(int) && int.TryParse(value, out var result))
			{
				configEntry.Value = (T)(object)result;
				return;
			}
			if (typeof(T) == typeof(float) && float.TryParse(value, out var result2))
			{
				configEntry.Value = (T)(object)result2;
				return;
			}
			if (typeof(T) == typeof(double) && double.TryParse(value, out var result3))
			{
				configEntry.Value = (T)(object)result3;
				return;
			}
			if (typeof(T) == typeof(bool) && bool.TryParse(value, out var result4))
			{
				configEntry.Value = (T)(object)result4;
				return;
			}
			if (typeof(T) == typeof(string))
			{
				configEntry.Value = (T)(object)value;
				return;
			}
			throw new InvalidOperationException($"Unsupported type: {typeof(T)}");
		}

		public static void ClearUnusedEntries(ConfigFile configFile = null)
		{
			if (configFile == null)
			{
				configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
			}
			Dictionary<ConfigDefinition, string> orphanedConfigEntries = GetOrphanedConfigEntries(configFile);
			if (orphanedConfigEntries != null)
			{
				orphanedConfigEntries.Clear();
				configFile.Save();
			}
		}
	}
	internal class ConfigManager
	{
		public ConfigEntry<bool> ExtendedLogging { get; private set; }

		public ConfigManager()
		{
			BindConfigs();
		}

		private void BindConfigs()
		{
			ConfigHelper.SkipAutoGen();
			ExtendedLogging = ConfigHelper.Bind("General", "ExtendedLogging", defaultValue: false, requiresRestart: false, "Enable extended logging.");
		}
	}
	internal static class Content
	{
		public static GameObject HoharderControllerPrefab { get; private set; }

		public static AudioClip BrainRotSFX { get; private set; }

		public static List<AudioClip> ChitterSFX { get; private set; } = new List<AudioClip>();


		public static List<AudioClip> AngryScreechSFX { get; private set; } = new List<AudioClip>();


		public static List<AudioClip> BugWalkSFX { get; private set; } = new List<AudioClip>();


		public static void Load()
		{
			LoadAssetsFromAssetBundle();
			LoadAssetsFromHoharder();
		}

		private static void LoadAssetsFromAssetBundle()
		{
			AssetBundle val = LoadAssetBundle("hoharderskin_assets");
			if (!((Object)(object)val == (Object)null))
			{
				HoharderControllerPrefab = LoadAssetFromAssetBundle<GameObject>("HoharderController", val);
				BrainRotSFX = LoadAssetFromAssetBundle<AudioClip>("BrainRotSFX", val);
				Plugin.Logger.LogInfo((object)"Successfully loaded assets from AssetBundle!");
			}
		}

		private static AssetBundle LoadAssetBundle(string fileName)
		{
			try
			{
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location);
				string text = Path.Combine(directoryName, fileName);
				return AssetBundle.LoadFromFile(text);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to load AssetBundle \"{fileName}\". {arg}");
			}
			return null;
		}

		private static T LoadAssetFromAssetBundle<T>(string name, AssetBundle assetBundle) where T : Object
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				Plugin.Logger.LogError((object)("Failed to load asset of type \"" + typeof(T).Name + "\" from AssetBundle. Name is null or whitespace."));
				return default(T);
			}
			if ((Object)(object)assetBundle == (Object)null)
			{
				Plugin.Logger.LogError((object)("Failed to load asset of type \"" + typeof(T).Name + "\" with name \"" + name + "\" from AssetBundle. AssetBundle is null."));
				return default(T);
			}
			T val = assetBundle.LoadAsset<T>(name);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogError((object)("Failed to load asset of type \"" + typeof(T).Name + "\" with name \"" + name + "\" from AssetBundle. No asset found with that type and name."));
				return default(T);
			}
			return val;
		}

		private static void LoadAssetsFromHoharder()
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			string text = Directory.GetDirectories(Paths.PluginPath).FirstOrDefault((string folder) => Path.GetFileName(folder).StartsWith("averageguy-Hoharder"));
			if (text == null)
			{
				Plugin.Logger.LogError((object)"No folder found that starts with \"averageguy-Hoharder\" in the current or parent directory.");
				return;
			}
			string text2 = Directory.GetDirectories(text, "CustomSounds", SearchOption.AllDirectories).FirstOrDefault();
			if (text2 == null)
			{
				Plugin.Logger.LogError((object)"No \"CustomSounds\" folder found inside \"averageguy-Hoharder\" or its subfolders.");
				return;
			}
			StringComparison ordinalIgnoreCase = StringComparison.OrdinalIgnoreCase;
			string[] array = (from f in Directory.GetFiles(text2, "*.*", SearchOption.AllDirectories)
				where f.EndsWith(".wav", ordinalIgnoreCase) || f.EndsWith(".ogg", ordinalIgnoreCase) || f.EndsWith(".mp3", ordinalIgnoreCase)
				select f).ToArray();
			if (array.Length == 0)
			{
				Plugin.Logger.LogWarning((object)"No sound files were found in the \"CustomSounds\" folder.");
				return;
			}
			ChitterSFX = new List<AudioClip>();
			AngryScreechSFX = new List<AudioClip>();
			BugWalkSFX = new List<AudioClip>();
			string[] array2 = array;
			foreach (string text3 in array2)
			{
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text3);
				AudioType type = AudioUtils.DetectAudioType(text3);
				if (fileNameWithoutExtension.StartsWith("Chitter", ordinalIgnoreCase))
				{
					AudioClip val = AudioUtils.LoadAudioClip(text3, type);
					if ((Object)(object)val != (Object)null)
					{
						ChitterSFX.Add(val);
					}
				}
				else if (fileNameWithoutExtension.StartsWith("AngryScreech", ordinalIgnoreCase))
				{
					AudioClip val2 = AudioUtils.LoadAudioClip(text3, type);
					if ((Object)(object)val2 != (Object)null)
					{
						AngryScreechSFX.Add(val2);
					}
				}
				else if (fileNameWithoutExtension.StartsWith("BugWalk", ordinalIgnoreCase))
				{
					AudioClip val3 = AudioUtils.LoadAudioClip(text3, type);
					if ((Object)(object)val3 != (Object)null)
					{
						BugWalkSFX.Add(val3);
					}
				}
			}
			Plugin.Logger.LogInfo((object)"Successfully loaded Hoharder assets.");
		}
	}
	internal static class PlayerUtils
	{
		public static PlayerControllerB GetLocalPlayerScript()
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				return null;
			}
			return GameNetworkManager.Instance.localPlayerController;
		}

		public static bool IsLocalPlayer(PlayerControllerB playerScript)
		{
			return (Object)(object)playerScript == (Object)(object)GetLocalPlayerScript();
		}

		public static bool IsLocalPlayer(PlayerName playerName)
		{
			return SteamUtils.IsLocalClient(playerName);
		}

		public static bool IsLocalPlayer(PlayerName[] playerNames)
		{
			foreach (PlayerName playerName in playerNames)
			{
				if (SteamUtils.IsLocalClient(playerName))
				{
					return true;
				}
			}
			return false;
		}

		public static bool IsPlayer(PlayerControllerB playerScript, PlayerName playerName)
		{
			if ((Object)(object)playerScript == (Object)null)
			{
				return false;
			}
			return SteamUtils.IsPlayer(playerName, playerScript.playerUsername, playerScript.playerSteamId);
		}

		public static bool HasPlayer(PlayerName playerName)
		{
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB playerScript in allPlayerScripts)
			{
				if (IsPlayer(playerScript, playerName))
				{
					return true;
				}
			}
			return false;
		}

		public static PlayerControllerB GetPlayerScript(PlayerName playerName)
		{
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (IsPlayer(val, playerName))
				{
					return val;
				}
			}
			return null;
		}
	}
	[BepInPlugin("com.github.zehsteam.HoharderSkin", "HoharderSkin", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("com.github.zehsteam.HoharderSkin");

		internal static Plugin Instance;

		internal static ManualLogSource Logger;

		internal static ConfigManager ConfigManager;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = Logger.CreateLogSource("com.github.zehsteam.HoharderSkin");
			Logger.LogInfo((object)"HoharderSkin has awoken!");
			_harmony.PatchAll(typeof(StartOfRoundPatch));
			_harmony.PatchAll(typeof(HoarderBugAIPatch));
			ConfigManager = new ConfigManager();
			Content.Load();
			SteamUtils.Initialize();
		}

		public void LogInfoExtended(object data)
		{
			LogExtended((LogLevel)16, data);
		}

		public void LogExtended(LogLevel level, object data)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (ConfigManager == null || ConfigManager.ExtendedLogging == null)
			{
				Logger.Log(level, data);
			}
			else if (ConfigManager.ExtendedLogging.Value)
			{
				Logger.Log(level, data);
			}
		}
	}
	internal enum PlayerName
	{
		CritHaxXoG,
		PsychoHypnotic
	}
	internal static class SteamUtils
	{
		public static List<PlayerData> PlayersData { get; private set; } = new List<PlayerData>();


		public static void Initialize()
		{
			PlayersData = new List<PlayerData>(2)
			{
				new PlayerData(PlayerName.CritHaxXoG, "CritHaxXoG", 76561198993712632uL),
				new PlayerData(PlayerName.PsychoHypnotic, "PsychoHypnotic", 76561197970440803uL)
			};
		}

		public static bool IsPlayer(PlayerName playerName, string username, ulong steamId)
		{
			return GetPlayerData(playerName)?.IsPlayer(username, steamId) ?? false;
		}

		public static PlayerData GetLocalClientPlayerData()
		{
			foreach (PlayerData playersDatum in PlayersData)
			{
				if (playersDatum.IsLocalClient())
				{
					return playersDatum;
				}
			}
			return null;
		}

		public static PlayerData GetPlayerData(PlayerName playerName)
		{
			foreach (PlayerData playersDatum in PlayersData)
			{
				if (playersDatum.PlayerName == playerName)
				{
					return playersDatum;
				}
			}
			return null;
		}

		public static bool IsLocalClient(PlayerName playerName)
		{
			return GetPlayerData(playerName)?.IsLocalClient() ?? false;
		}

		public static bool IsLocalClient(string username, ulong steamId)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (!SteamClient.IsValid)
			{
				return false;
			}
			if (!SteamClient.IsLoggedOn)
			{
				return false;
			}
			if (SteamClient.Name.Equals(username, StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (SteamId.op_Implicit(SteamClient.SteamId) == steamId)
			{
				return true;
			}
			return false;
		}
	}
	internal class PlayerData
	{
		public PlayerName PlayerName { get; private set; }

		public string[] Username { get; private set; }

		public ulong[] SteamId { get; private set; }

		public PlayerData(PlayerName playerName, string username, ulong steamId)
		{
			PlayerName = playerName;
			Username = new string[1] { username };
			SteamId = new ulong[1] { steamId };
		}

		public PlayerData(PlayerName playerName, string[] username, ulong[] steamId)
		{
			PlayerName = playerName;
			Username = username;
			SteamId = steamId;
		}

		public bool IsLocalClient()
		{
			for (int i = 0; i < Username.Length; i++)
			{
				if (SteamUtils.IsLocalClient(Username[i], SteamId[i]))
				{
					return true;
				}
			}
			return false;
		}

		public bool IsPlayer(string username, ulong steamId)
		{
			for (int i = 0; i < Username.Length; i++)
			{
				if (Username[i].Equals(username, StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
				if (SteamId[i] == steamId)
				{
					return true;
				}
			}
			return false;
		}
	}
	internal static class Utils
	{
		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			if ((Object)(object)Plugin.Instance != (Object)null)
			{
				return ((MonoBehaviour)Plugin.Instance).StartCoroutine(routine);
			}
			if ((Object)(object)GameNetworkManager.Instance != (Object)null)
			{
				return ((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(routine);
			}
			Plugin.Logger.LogError((object)("Failed to start coroutine. " + routine));
			return null;
		}

		public static void ExecuteNextFrame(Action action)
		{
			StartCoroutine(ExecuteNextFrameCoroutine(action));
		}

		private static IEnumerator ExecuteNextFrameCoroutine(Action action)
		{
			yield return null;
			action?.Invoke();
		}

		public static void ExecuteAfterDelay(Action action, float seconds)
		{
			StartCoroutine(ExecuteAfterDelayCoroutine(action, seconds));
		}

		private static IEnumerator ExecuteAfterDelayCoroutine(Action action, float seconds)
		{
			yield return (object)new WaitForSeconds(seconds);
			action?.Invoke();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.zehsteam.HoharderSkin";

		public const string PLUGIN_NAME = "HoharderSkin";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}
namespace com.github.zehsteam.HoharderSkin.Patches
{
	[HarmonyPatch(typeof(HoarderBugAI))]
	internal static class HoarderBugAIPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch(ref HoarderBugAI __instance)
		{
			Object.Instantiate<GameObject>(Content.HoharderControllerPrefab, ((Component)__instance).transform);
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal static class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch()
		{
			SaveVoiceLinesForMirage();
		}

		private static void SaveVoiceLinesForMirage()
		{
			if (PlayerUtils.IsLocalPlayer(PlayerName.PsychoHypnotic) && MirageProxy.Enabled)
			{
				MirageProxy.SaveAudioClip(Content.BrainRotSFX, "BrainRotSFX");
			}
		}
	}
}
namespace com.github.zehsteam.HoharderSkin.MonoBehaviours
{
	public class HoharderController : MonoBehaviour
	{
		public Mesh ReplacementMesh;

		public GameObject PotatoPrefab;

		private HoarderBugAI _hoarderBugAI;

		private GameObject _potatoObject;

		private void Start()
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((Component)this).transform.parent == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to initialize HoharderController. Transform parent is null.");
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			if (!((Component)((Component)this).transform.parent).TryGetComponent<HoarderBugAI>(ref _hoarderBugAI))
			{
				Plugin.Logger.LogError((object)"Failed to initialize HoharderController. HoarderBugAI is null.");
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			((Component)this).transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
			ReplaceMesh();
			SpawnPotatoPrefab();
			HideInsideModel();
			SetScanNodeProperties();
			Utils.ExecuteNextFrame(LateStart);
		}

		private void LateStart()
		{
			SetSFX();
		}

		private void ReplaceMesh()
		{
			if ((Object)(object)_hoarderBugAI == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to replace mesh. HoarderBugAI is null.");
				return;
			}
			if ((Object)(object)ReplacementMesh == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to replace mesh. ReplacementMesh is null.");
				return;
			}
			SkinnedMeshRenderer component;
			try
			{
				component = ((Component)((Component)_hoarderBugAI).transform.Find("HoarderBugModel").Find("Cube")).GetComponent<SkinnedMeshRenderer>();
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to replace mesh. Could not find SkinnedMeshRenderer.\n\n{arg}");
				return;
			}
			if ((Object)(object)component == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to replace mesh. SkinnedMeshRenderer is null.");
				return;
			}
			component.sharedMesh = ReplacementMesh;
			Plugin.Logger.LogInfo((object)"Replaced mesh.");
		}

		private void SpawnPotatoPrefab()
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_hoarderBugAI == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to spawn potato prefab. HoarderBugAI is null.");
				return;
			}
			if ((Object)(object)PotatoPrefab == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to spawn potato prefab. PotatoPrefab is null.");
				return;
			}
			Transform val;
			try
			{
				val = ((Component)((EnemyAI)_hoarderBugAI).creatureAnimator).transform.Find("Armature").Find("Abdomen").Find("Chest");
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to spawn potato prefab. Could not find \"Chest\" Transform.\n\n{arg}");
				return;
			}
			if ((Object)(object)_potatoObject != (Object)null)
			{
				Object.Destroy((Object)(object)_potatoObject);
				return;
			}
			_potatoObject = Object.Instantiate<GameObject>(PotatoPrefab, val);
			_potatoObject.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
			Plugin.Logger.LogInfo((object)"Spawned potato prefab.");
		}

		private void HideInsideModel()
		{
			if ((Object)(object)_hoarderBugAI == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to hide inside model. HoarderBugAI is null.");
				return;
			}
			SkinnedMeshRenderer component;
			try
			{
				component = ((Component)((Component)_hoarderBugAI).transform.Find("HoarderBugModel").Find("Cube.001")).GetComponent<SkinnedMeshRenderer>();
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to hide inside model. Could not find SkinnedMeshRenderer.\n\n{arg}");
				return;
			}
			if ((Object)(object)component == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to hide inside model. SkinnedMeshRenderer is null.");
			}
			else
			{
				((Renderer)component).enabled = false;
			}
		}

		private void SetScanNodeProperties()
		{
			if ((Object)(object)_hoarderBugAI == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to set scan node properties. HoarderBugAI is null.");
				return;
			}
			ScanNodeProperties componentInChildren = ((Component)_hoarderBugAI).GetComponentInChildren<ScanNodeProperties>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to set scan node properties. ScanNodeProperties is null.");
			}
			else
			{
				componentInChildren.headerText = "Hoharding bug";
			}
		}

		private void SetSFX()
		{
			if ((Object)(object)_hoarderBugAI == (Object)null)
			{
				Plugin.Logger.LogError((object)"Failed to set custom sounds. HoarderBugAI is null.");
				return;
			}
			if (Content.ChitterSFX.Count > 0)
			{
				_hoarderBugAI.chitterSFX = Content.ChitterSFX.ToArray();
			}
			if (Content.AngryScreechSFX.Count > 0)
			{
				_hoarderBugAI.angryScreechSFX = Content.AngryScreechSFX.ToArray();
			}
			PlayAudioAnimationEvent componentInChildren = ((Component)_hoarderBugAI).GetComponentInChildren<PlayAudioAnimationEvent>();
			if ((Object)(object)componentInChildren != (Object)null && Content.BugWalkSFX.Count > 0)
			{
				componentInChildren.randomClips = Content.BugWalkSFX.ToArray();
			}
			Plugin.Logger.LogInfo((object)"Set custom sounds.");
		}
	}
}
namespace com.github.zehsteam.HoharderSkin.Dependencies
{
	internal static class LethalConfigProxy
	{
		public const string PLUGIN_GUID = "ainavt.lc.lethalconfig";

		public static bool Enabled => Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void SkipAutoGen()
		{
			LethalConfigManager.SkipAutoGen();
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfig<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			AcceptableValueBase acceptableValues = ((ConfigEntryBase)configEntry).Description.AcceptableValues;
			if (acceptableValues != null)
			{
				if (acceptableValues is AcceptableValueRange<float> || acceptableValues is AcceptableValueRange<int>)
				{
					AddConfigSlider<T>(configEntry, requiresRestart);
					return;
				}
				if (acceptableValues is AcceptableValueList<string>)
				{
					AddConfigDropdown<T>(configEntry, requiresRestart);
					return;
				}
			}
			if (!(configEntry is ConfigEntry<string> val))
			{
				if (!(configEntry is ConfigEntry<bool> val2))
				{
					if (!(configEntry is ConfigEntry<float> val3))
					{
						if (!(configEntry is ConfigEntry<int> val4))
						{
							throw new NotSupportedException($"Unsupported type: {typeof(T)}");
						}
						LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(val4, requiresRestart));
					}
					else
					{
						LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(val3, requiresRestart));
					}
				}
				else
				{
					LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(val2, requiresRestart));
				}
			}
			else
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(val, requiresRestart));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfigSlider<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			if (!(configEntry is ConfigEntry<float> val))
			{
				if (!(configEntry is ConfigEntry<int> val2))
				{
					throw new NotSupportedException($"Slider not supported for type: {typeof(T)}");
				}
				LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(val2, requiresRestart));
			}
			else
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(val, requiresRestart));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfigDropdown<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			if (configEntry is ConfigEntry<string> val)
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new TextDropDownConfigItem(val, requiresRestart));
				return;
			}
			throw new NotSupportedException($"Dropdown not supported for type: {typeof(T)}");
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddButton(string section, string name, string description, string buttonText, Action callback)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new GenericButtonConfigItem(section, name, description, buttonText, (GenericButtonHandler)delegate
			{
				callback?.Invoke();
			}));
		}
	}
	internal static class MirageProxy
	{
		public const string PLUGIN_GUID = "qwbarch.Mirage";

		public static bool Enabled => Chainloader.PluginInfos.ContainsKey("qwbarch.Mirage");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void SaveAudioClip(AudioClip audioClip, string fileName = null)
		{
			if ((Object)(object)audioClip == (Object)null)
			{
				return;
			}
			try
			{
				if (string.IsNullOrWhiteSpace(fileName))
				{
					Recording.saveAudioClip(audioClip);
				}
				else
				{
					Recording.saveAudioClipWithName(fileName, audioClip);
				}
				Plugin.Instance.LogInfoExtended("Successfully saved AudioClip to Mirage recordings folder.");
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to save AudioClip to Mirage recordings folder. {arg}");
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}