using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PuppetJester")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PuppetJester")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1ad5dcd5-3605-4fb1-aab6-05923ce90b0c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PuppetJester
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "PuppetJester";
public const string PLUGIN_NAME = "PuppetJester";
public const string PLUGIN_VERSION = "1.0.0";
}
public class OrtonAnimationEventAudioTunnel : MonoBehaviour
{
private PlayAudioAnimationEvent eventBehaviour;
private void OnEnable()
{
Transform parent = ((Component)this).gameObject.transform.parent;
object obj;
if (parent == null)
{
obj = null;
}
else
{
Transform obj2 = parent.Find("OldAnimContainer");
obj = ((obj2 != null) ? ((Component)obj2).GetComponent<PlayAudioAnimationEvent>() : null);
}
PlayAudioAnimationEvent val = (PlayAudioAnimationEvent)obj;
if ((Object)(object)val != (Object)null)
{
eventBehaviour = val;
}
}
public void PlayAudio1()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayAudio1();
}
}
public void PlayAudio1RandomClip()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayAudio1RandomClip();
}
}
public void PlayAudio2RandomClip()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayAudio2RandomClip();
}
}
public void PlayAudioB1()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayAudioB1();
}
}
public void PlayParticle()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayParticle();
}
}
public void PlayParticleWithChildren()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayParticleWithChildren();
}
}
public void StopParticle()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.StopParticle();
}
}
public void PlayAudio1Oneshot()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayAudio1Oneshot();
}
}
public void PlayAudio2()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayAudio2();
}
}
public void PlayAudioB2()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayAudioB2();
}
}
public void PlayAudio2Oneshot()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayAudio2Oneshot();
}
}
public void PlayAudio3Oneshot()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayAudio3Oneshot();
}
}
public void StopAudio()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.StopAudio();
}
}
public void PauseAudio()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PauseAudio();
}
}
public void PlayAudio1DefaultClip()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.PlayAudio1DefaultClip();
}
}
public void OnAnimationEvent()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.OnAnimationEvent();
}
}
public void DestroyObject()
{
if ((Object)(object)eventBehaviour != (Object)null)
{
eventBehaviour.DestroyObject();
}
}
}
[BepInPlugin("PuppetJester", "PuppetJester", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static GameObject Visuals;
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin PuppetJester is loaded!");
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "puppet.bundle");
AssetBundle val = AssetBundle.LoadFromFile(text);
Visuals = val.LoadAsset<GameObject>("assets/prefabs/puppet.prefab");
Renderer[] componentsInChildren = Visuals.GetComponentsInChildren<Renderer>(true);
foreach (Renderer val2 in componentsInChildren)
{
((Component)val2).gameObject.layer = LayerMask.NameToLayer("Enemies");
}
}
}
}
namespace PuppetJester.Patches
{
[HarmonyPatch(typeof(JesterAI), "Start")]
internal class JesterPatch
{
private static void Postfix(JesterAI __instance)
{
if ((Object)(object)Plugin.Visuals == (Object)null)
{
return;
}
Renderer[] componentsInChildren = ((Component)((Component)__instance).transform.Find("MeshContainer")).gameObject.GetComponentsInChildren<Renderer>();
foreach (Renderer val in componentsInChildren)
{
val.enabled = false;
}
Transform obj = ((Component)__instance).transform.Find("MeshContainer");
object obj2;
if (obj == null)
{
obj2 = null;
}
else
{
Transform obj3 = obj.Find("AnimContainer");
obj2 = ((obj3 != null) ? ((Component)obj3).gameObject : null);
}
GameObject val2 = (GameObject)obj2;
((Object)val2).name = "OldAnimContainer";
((Behaviour)val2.GetComponent<Animator>()).enabled = false;
Transform obj4 = val2.transform.Find("metarig");
if (obj4 != null)
{
((Component)obj4).gameObject.SetActive(false);
}
GameObject val3 = Object.Instantiate<GameObject>(Plugin.Visuals, val2.transform.parent);
((Object)val3).name = "AnimContainer";
Animator component = val3.GetComponent<Animator>();
component.SetBool("turningCrank", false);
component.SetBool("poppedOut", false);
component.SetFloat("CrankSpeedMultiplier", 1f);
component.SetBool("stunned", false);
((EnemyAI)__instance).creatureAnimator = component;
Transform obj5 = val3.transform.Find("metarig");
object grabBodyPoint;
if (obj5 == null)
{
grabBodyPoint = null;
}
else
{
Transform obj6 = obj5.Find("BoxContainer");
if (obj6 == null)
{
grabBodyPoint = null;
}
else
{
Transform obj7 = obj6.Find("spine.004");
if (obj7 == null)
{
grabBodyPoint = null;
}
else
{
Transform obj8 = obj7.Find("spine.005");
if (obj8 == null)
{
grabBodyPoint = null;
}
else
{
Transform obj9 = obj8.Find("spine.006");
grabBodyPoint = ((obj9 != null) ? obj9.Find("GrabBodyPoint") : null);
}
}
}
}
__instance.grabBodyPoint = (Transform)grabBodyPoint;
Transform obj10 = val3.transform.Find("Rig 1");
object headRigTarget;
if (obj10 == null)
{
headRigTarget = null;
}
else
{
Transform obj11 = obj10.Find("HeadRig");
headRigTarget = ((obj11 != null) ? obj11.Find("HeadTarget") : null);
}
__instance.headRigTarget = (Transform)headRigTarget;
((EnemyAI)__instance).skinnedMeshRenderers = ((Component)__instance).gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
((EnemyAI)__instance).meshRenderers = ((Component)__instance).gameObject.GetComponentsInChildren<MeshRenderer>();
}
}
}