using System;
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.Logging;
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: AssemblyCompany("NewYearJester")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Making Jester More Festive!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NewYearJester")]
[assembly: AssemblyTitle("NewYearJester")]
[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 NewYearJester
{
[BepInPlugin("rainbow137-NewYearJester", "NewYearJester", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static ManualLogSource Logger;
public static Texture JesterTexture;
public static GameObject JesterHat;
public static AudioClip JesterClip;
public static AudioClip JesterPopClip;
public static AudioClip JesterScreamingClip;
public static AudioClip JesterKillingClip;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin rainbow137-NewYearJester is loaded!");
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
LoadAssets();
}
private void LoadAssets()
{
string text = Path.Join((ReadOnlySpan<char>)Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), (ReadOnlySpan<char>)"jestervisuals");
AssetBundle val = AssetBundle.LoadFromFile(text);
GameObject val2 = val.LoadAsset<GameObject>("assets/prefabs/jestervisuals.prefab");
JesterTexture = ((Component)val2.transform.GetChild(0)).GetComponent<Renderer>().sharedMaterial.mainTexture;
JesterHat = ((Component)val2.transform.GetChild(1)).gameObject;
JesterClip = ((Component)val2.transform.GetChild(2)).GetComponent<AudioSource>().clip;
JesterPopClip = ((Component)val2.transform.GetChild(3)).GetComponent<AudioSource>().clip;
JesterScreamingClip = ((Component)val2.transform.GetChild(4)).GetComponent<AudioSource>().clip;
JesterKillingClip = ((Component)val2.transform.GetChild(5)).GetComponent<AudioSource>().clip;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "NewYearJester";
public const string PLUGIN_NAME = "NewYearJester";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace NewYearJester.Patches
{
[HarmonyPatch(typeof(JesterAI))]
internal class JesterPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void JesterStart(JesterAI __instance)
{
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Plugin.JesterTexture == (Object)null || (Object)(object)Plugin.JesterClip == (Object)null || (Object)(object)Plugin.JesterHat == (Object)null || (Object)(object)Plugin.JesterPopClip == (Object)null || (Object)(object)Plugin.JesterKillingClip == (Object)null || (Object)(object)Plugin.JesterScreamingClip == (Object)null)
{
Plugin.Logger.LogWarning((object)"NewYearJester replacement assets null, returning");
return;
}
Transform val = ((Component)__instance).transform.Find("MeshContainer/AnimContainer/metarig/BoxContainer/spine.004/spine.005/spine.006/UpperJaw");
if ((Object)(object)val == (Object)null)
{
Plugin.Logger.LogWarning((object)"Could not find jester hat parent, returning");
return;
}
Material val2 = null;
List<Material> list = ((Component)__instance).GetComponentsInChildren<Renderer>(true).SelectMany((Renderer x) => x.sharedMaterials).ToList();
foreach (Material item in list)
{
if (((Object)item).name.StartsWith("JesterTex"))
{
item.mainTexture = Plugin.JesterTexture;
val2 = item;
}
}
__instance.popGoesTheWeaselTheme = Plugin.JesterClip;
__instance.popUpSFX = Plugin.JesterPopClip;
__instance.screamingSFX = Plugin.JesterScreamingClip;
__instance.killPlayerSFX = Plugin.JesterKillingClip;
GameObject val3 = Object.Instantiate<GameObject>(Plugin.JesterHat);
val3.transform.SetParent(val);
val3.transform.localPosition = Vector3.zero;
val3.transform.localRotation = Quaternion.identity;
val3.transform.localScale = Vector3.one;
if (!((Object)(object)val2 == (Object)null))
{
Renderer[] componentsInChildren = val3.GetComponentsInChildren<Renderer>(true);
foreach (Renderer val4 in componentsInChildren)
{
val4.sharedMaterial.shader = val2.shader;
}
}
}
}
}