using System;
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 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: AssemblyCompany("JesterBigDickRandyChristmas")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Replaces the Jester's skin with a custom one")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("JesterBigDickRandyChristmas")]
[assembly: AssemblyTitle("JesterBigDickRandyChristmas")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[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 JesterBigDickRandyChristmas
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "JesterBigDickRandyChristmas";
public const string PLUGIN_NAME = "JesterBigDickRandyChristmas";
public const string PLUGIN_VERSION = "1.0.0";
}
[BepInPlugin("JesterBigDickRandyChristmas", "JesterBigDickRandyChristmas", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static Texture JesterTexture;
public static GameObject JesterHat;
public static AudioClip JesterClip;
public static AudioClip JesterPopClip;
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin JesterBigDickRandyChristmas 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>)"bdrcjester");
AssetBundle val = AssetBundle.LoadFromFile(text);
if ((Object)(object)val == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load asset bundle from path: " + text));
return;
}
string text2 = "assets/modassets/bdrcjester/bdrcjester.prefab";
GameObject val2 = val.LoadAsset<GameObject>(text2);
if ((Object)(object)val2 == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load prefab from asset bundle at path: " + text2));
return;
}
if (val2.transform.childCount > 0)
{
Renderer component = ((Component)val2.transform.GetChild(0)).GetComponent<Renderer>();
if ((Object)(object)component != (Object)null)
{
JesterTexture = component.sharedMaterial.mainTexture;
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"Renderer not found for the prefab's first child.");
}
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"Prefab has no children, cannot find texture.");
}
if (val2.transform.childCount > 1)
{
AudioSource component2 = ((Component)val2.transform.GetChild(1)).GetComponent<AudioSource>();
if ((Object)(object)component2 != (Object)null)
{
JesterClip = component2.clip;
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"AudioSource for JesterClip not found in second child.");
}
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"Prefab doesn't have a second child for JesterClip.");
}
if (val2.transform.childCount > 2)
{
AudioSource component3 = ((Component)val2.transform.GetChild(2)).GetComponent<AudioSource>();
if ((Object)(object)component3 != (Object)null)
{
JesterPopClip = component3.clip;
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"AudioSource for JesterPopClip not found in third child.");
}
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"Prefab doesn't have a third child for JesterPopClip.");
}
if (val2.transform.childCount > 3)
{
JesterHat = ((Component)val2.transform.GetChild(3)).gameObject;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Jester hat successfully loaded.");
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"Prefab doesn't have a fourth child for the Jester Hat.");
}
if (val2.transform.childCount > 3)
{
JesterHat = ((Component)val2.transform.GetChild(3)).gameObject;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Jester hat successfully loaded.");
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)"Prefab doesn't have a fourth child for the Jester Hat.");
}
}
}
}
namespace JesterBigDickRandyChristmas.Patches
{
[HarmonyPatch(typeof(JesterAI))]
internal class JesterPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void JesterStart(JesterAI __instance)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: 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.JesterPopClip == (Object)null)
{
Debug.Log((object)"JesterBigDickRandy2 replacement assets null, returning");
return;
}
Transform val = ((Component)__instance).transform.Find("MeshContainer").Find("AnimContainer").Find("metarig")
.Find("BoxContainer")
.Find("spine.004")
.Find("spine.005")
.Find("spine.006")
.Find("UpperJaw");
if ((Object)(object)val == (Object)null)
{
Debug.Log((object)"Could not find jester hat parent, returning");
return;
}
Material val2 = null;
foreach (Material item in ((Component)__instance).GetComponentsInChildren<Renderer>(true).SelectMany((Renderer x) => x.sharedMaterials).ToList())
{
if (((Object)item).name.StartsWith("JesterTex"))
{
item.mainTexture = Plugin.JesterTexture;
val2 = item;
}
}
__instance.popGoesTheWeaselTheme = Plugin.JesterClip;
__instance.popUpSFX = Plugin.JesterPopClip;
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);
for (int i = 0; i < componentsInChildren.Length; i++)
{
componentsInChildren[i].sharedMaterial.shader = val2.shader;
}
}
}
}
}