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("JesterBigDickRandy2")]
[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("JesterBigDickRandy2")]
[assembly: AssemblyTitle("JesterBigDickRandy2")]
[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 JesterBigDickRandy2
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "JesterBigDickRandy2";
public const string PLUGIN_NAME = "JesterBigDickRandy2";
public const string PLUGIN_VERSION = "1.1.0";
}
[BepInPlugin("JesterBigDickRandy2", "JesterBigDickRandy2", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
public static Texture JesterTexture;
public static AudioClip JesterClip;
public static AudioClip JesterPopClip;
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin JesterBigDickRandy2 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>)"bdr2jester");
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/bdr2jester/bdr2jester.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.");
}
}
}
}
namespace JesterBigDickRandy2.Patches
{
[HarmonyPatch(typeof(JesterAI))]
internal class JesterPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void JesterStart(JesterAI __instance)
{
//IL_0042: 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;
}
Material val = 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;
val = item;
}
}
__instance.popGoesTheWeaselTheme = Plugin.JesterClip;
__instance.popUpSFX = Plugin.JesterPopClip;
}
}
}