Decompiled source of HoharderSkin v2.1.0

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 AntlerShed.SkinRegistry;
using AntlerShed.SkinRegistry.Events;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using com.github.zehsteam.HoharderSkin.Extensions;
using com.github.zehsteam.HoharderSkin.Objects;

[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 and adds some funny voice lines + custom sounds.")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyInformationalVersion("2.1.0+bb42f900e94b00bdb065c7782ee56b8f656406e7")]
[assembly: AssemblyProduct("HoharderSkin")]
[assembly: AssemblyTitle("com.github.zehsteam.HoharderSkin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.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 com.github.zehsteam.HoharderSkin
{
	internal static class Content
	{
		public static HoharderBugAssets HoharderBugAssets { get; private set; }

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

		private static void LoadAssetsFromAssetBundle()
		{
			AssetBundle val = LoadAssetBundle("hoharderskin_assets");
			if (!((Object)(object)val == (Object)null))
			{
				HoharderBugAssets = LoadAssetFromAssetBundle<HoharderBugAssets>("HoharderBugAssets", 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;
		}
	}
	[BepInPlugin("com.github.zehsteam.HoharderSkin", "HoharderSkin", "2.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = Logger.CreateLogSource("com.github.zehsteam.HoharderSkin");
			Logger.LogInfo((object)"HoharderSkin has awoken!");
			Content.Load();
			EnemySkinRegistry.RegisterSkin((Skin)(object)new HoharderBugSkin());
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.zehsteam.HoharderSkin";

		public const string PLUGIN_NAME = "HoharderSkin";

		public const string PLUGIN_VERSION = "2.1.0";
	}
}
namespace com.github.zehsteam.HoharderSkin.Objects
{
	[CreateAssetMenu(fileName = "HoharderBugAssets", menuName = "HoharderSkin/HoharderBugAssets")]
	public class HoharderBugAssets : ScriptableObject
	{
		[Header("EnemySkinRegistry")]
		[Space(5f)]
		public Texture2D Icon;

		[Space(20f)]
		[Header("Visuals")]
		[Space(5f)]
		public Mesh Mesh;

		public GameObject PotatoPrefab;

		[Space(20f)]
		[Header("Audio")]
		[Space(5f)]
		public AudioClip AngrySFX;

		public AudioClip FlySFX;

		public AudioClip DeathSFX;

		public AudioClip StunSFX;

		public AudioClip HitBodySFX;

		public AudioClip[] ChitterSFX = Array.Empty<AudioClip>();

		public AudioClip[] AngryScreechSFX = Array.Empty<AudioClip>();

		public AudioClip[] WalkSFX = Array.Empty<AudioClip>();
	}
	internal class HoharderBugSkin : Skin, Skinner, HoarderBugEventHandler, EnemyEventHandler
	{
		private static EnemyType _customEnemyType;

		public string Label => "Hoharder Bug";

		public string Id => "com.github.zehsteam.HoharderSkin.HoharderBug";

		public string EnemyId => "LethalCompany.HoarderBug";

		public Texture2D Icon => _assets.Icon ?? Texture2D.blackTexture;

		private HoharderBugAssets _assets => Content.HoharderBugAssets;

		public Skinner CreateSkinner()
		{
			return (Skinner)(object)new HoharderBugSkin();
		}

		public void Apply(GameObject enemy)
		{
			HoarderBugAI val = default(HoarderBugAI);
			if (enemy.TryGetComponent<HoarderBugAI>(ref val) && !((Object)(object)_assets == (Object)null))
			{
				SetCustomEnemyType(val);
				SetScanNodeProperties(val);
				ReplaceMainMesh(val);
				HideInsideModel(val);
				SpawnPotatoModel(val);
				((MonoBehaviour)val).StartCoroutine(ApplyCustomSoundsCoroutine(val));
			}
		}

		private void SetCustomEnemyType(HoarderBugAI hoarderBugAI)
		{
			if ((Object)(object)_customEnemyType != (Object)null)
			{
				((EnemyAI)hoarderBugAI).enemyType = _customEnemyType;
				return;
			}
			_customEnemyType = ScriptableObject.CreateInstance<EnemyType>();
			_customEnemyType.Copy(((EnemyAI)hoarderBugAI).enemyType);
			((EnemyAI)hoarderBugAI).enemyType = _customEnemyType;
		}

		private void SetScanNodeProperties(HoarderBugAI hoarderBugAI)
		{
			ScanNodeProperties componentInChildren = ((Component)hoarderBugAI).GetComponentInChildren<ScanNodeProperties>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.headerText = "Hoharding bug";
			}
		}

		private void ReplaceMainMesh(HoarderBugAI hoarderBugAI)
		{
			try
			{
				SkinnedMeshRenderer component = ((Component)((Component)hoarderBugAI).transform.Find("HoarderBugModel").Find("Cube")).GetComponent<SkinnedMeshRenderer>();
				component.sharedMesh = _assets.Mesh;
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to replace main mesh. {arg}");
			}
		}

		private void HideInsideModel(HoarderBugAI hoarderBugAI)
		{
			try
			{
				SkinnedMeshRenderer component = ((Component)((Component)hoarderBugAI).transform.Find("HoarderBugModel").Find("Cube.001")).GetComponent<SkinnedMeshRenderer>();
				((Renderer)component).enabled = false;
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to hide inside model. {arg}");
			}
		}

		private void SpawnPotatoModel(HoarderBugAI hoarderBugAI)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Transform val = ((Component)((EnemyAI)hoarderBugAI).creatureAnimator).transform.Find("Armature").Find("Abdomen").Find("Chest");
				GameObject val2 = Object.Instantiate<GameObject>(_assets.PotatoPrefab, val);
				val2.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to spawn potato model. {arg}");
			}
		}

		private void ApplyCustomSounds(HoarderBugAI hoarderBugAI)
		{
			hoarderBugAI.angryVoiceSFX = _assets.AngrySFX;
			hoarderBugAI.bugFlySFX = _assets.FlySFX;
			((EnemyAI)hoarderBugAI).dieSFX = _assets.DeathSFX;
			hoarderBugAI.chitterSFX = _assets.ChitterSFX;
			hoarderBugAI.angryScreechSFX = _assets.AngryScreechSFX;
			((EnemyAI)hoarderBugAI).enemyType.hitBodySFX = _assets.HitBodySFX;
			((EnemyAI)hoarderBugAI).enemyType.deathSFX = _assets.DeathSFX;
			((EnemyAI)hoarderBugAI).enemyType.stunSFX = _assets.StunSFX;
			if (_assets.WalkSFX.Length != 0)
			{
				PlayAudioAnimationEvent componentInChildren = ((Component)hoarderBugAI).GetComponentInChildren<PlayAudioAnimationEvent>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.randomClips = _assets.WalkSFX;
				}
			}
			if (_assets.AngryScreechSFX.Length != 0)
			{
				((EnemyAI)hoarderBugAI).creatureVoice.clip = _assets.AngryScreechSFX[0];
				EnemyBehaviourState val = ((IEnumerable<EnemyBehaviourState>)((EnemyAI)hoarderBugAI).enemyBehaviourStates).FirstOrDefault((Func<EnemyBehaviourState, bool>)((EnemyBehaviourState state) => state.name.Equals("Chasing", StringComparison.OrdinalIgnoreCase)));
				if (val != null)
				{
					val.VoiceClip = _assets.AngryScreechSFX[0];
				}
			}
		}

		private IEnumerator ApplyCustomSoundsCoroutine(HoarderBugAI hoarderBugAI)
		{
			for (int i = 0; i < 2; i++)
			{
				ApplyCustomSounds(hoarderBugAI);
				yield return null;
			}
		}

		public void Remove(GameObject enemy)
		{
		}
	}
}
namespace com.github.zehsteam.HoharderSkin.Extensions
{
	public static class EnemyTypeExtensions
	{
		public static void Copy(this EnemyType target, EnemyType source)
		{
			if ((Object)(object)target == (Object)null || (Object)(object)source == (Object)null)
			{
				Plugin.Logger.LogError((object)"EnemyType.Copy: Either target or source is null.");
				return;
			}
			FieldInfo[] fields = typeof(EnemyType).GetFields(BindingFlags.Instance | BindingFlags.Public);
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				fieldInfo.SetValue(target, fieldInfo.GetValue(source));
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}