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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
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.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a009c6cfaaa6f720a7a885b3cfaf9b00b15dfaaf")]
[assembly: AssemblyProduct("HoharderSkin")]
[assembly: AssemblyTitle("com.github.zehsteam.HoharderSkin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 GameObject HoharderControllerPrefab;
public static void Load()
{
LoadAssetsFromAssetBundle();
}
private static void LoadAssetsFromAssetBundle()
{
try
{
AssetBundle val = LoadAssetBundle("hoharderskin_assets");
HoharderControllerPrefab = val.LoadAsset<GameObject>("HoharderController");
Plugin.logger.LogInfo((object)"Successfully loaded assets from AssetBundle!");
}
catch (Exception arg)
{
Plugin.logger.LogError((object)$"Failed to load assets from AssetBundle.\n\n{arg}");
}
}
private static AssetBundle LoadAssetBundle(string fileName)
{
string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location);
string text = Path.Combine(directoryName, fileName);
return AssetBundle.LoadFromFile(text);
}
}
[BepInPlugin("com.github.zehsteam.HoharderSkin", "HoharderSkin", "1.0.0")]
internal class Plugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("com.github.zehsteam.HoharderSkin");
internal static Plugin Instance;
internal static ManualLogSource logger;
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(HoarderBugAIPatch));
Content.Load();
}
}
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.0";
}
}
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);
}
}
}
namespace com.github.zehsteam.HoharderSkin.MonoBehaviours
{
public class HoharderController : MonoBehaviour
{
public Mesh ReplacementMesh;
public GameObject PotatoPrefab;
public AudioClip[] AngryScreechSFX;
private HoarderBugAI _hoarderBugAI;
private GameObject _potatoObject;
private void Start()
{
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: 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();
SetSFX();
SetScanNodeProperties();
}
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 SetSFX()
{
if ((Object)(object)_hoarderBugAI == (Object)null)
{
Plugin.logger.LogError((object)"Failed to set sound effects. HoarderBugAI is null.");
}
else if (AngryScreechSFX != null && AngryScreechSFX.Length != 0)
{
_hoarderBugAI.angryScreechSFX = AngryScreechSFX;
}
}
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";
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}