using System.Diagnostics;
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("ClownMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClownMod")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b37ddfa3-71c3-4e3d-a5b0-63f2967a7490")]
[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 ClownMod;
[BepInPlugin("com.yourname.clownmod", "Enhanced Clown Mod", "1.0.0")]
public class ClownMod : BaseUnityPlugin
{
private void Awake()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"Clown Mod: Initializing...");
Harmony val = new Harmony("com.yourname.clownmod");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Clown Mod loaded with HarmonyX!");
}
}
[HarmonyPatch(typeof(ClownTrap))]
[HarmonyPatch("TrapActivate")]
public class ClownPatch
{
private static bool Prefix(ClownTrap __instance, ref bool ___trapTriggered, ref int ___WarningCount, ref AudioSource ___previousAudioSource, ref PhysGrabObject ___physgrabobject, ref bool ___NoseSqueezeActive, ref bool ___ArmRaiseActive, ref bool ___trapActive, ref MeshRenderer ___noseMesh, ref bool ___CountDownActive)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
if (!___trapTriggered)
{
__instance.NoseSqeak.Play(___physgrabobject.centerPoint, 1f, 1f, 1f, 1f);
((Renderer)___noseMesh).material.EnableKeyword("_EMISSION");
___NoseSqueezeActive = true;
___ArmRaiseActive = true;
___trapActive = true;
___trapTriggered = true;
if (___WarningCount <= 0)
{
if ((Object)(object)___previousAudioSource != (Object)null)
{
___previousAudioSource.Stop();
}
___previousAudioSource = __instance.GonnaBlowVO.Play(___physgrabobject.centerPoint, 1f, 1f, 1f, 1f);
___ArmRaiseActive = true;
((Renderer)___noseMesh).material.EnableKeyword("_EMISSION");
___CountDownActive = true;
ClownProximityTrigger clownProximityTrigger = ((Component)__instance).gameObject.AddComponent<ClownProximityTrigger>();
clownProximityTrigger.wobbleSpeed = 2f;
return false;
}
}
return true;
}
}
public class ClownProximityTrigger : MonoBehaviour
{
private float triggerRadius = 3f;
private ClownTrap clown;
private FieldInfo countDownActiveField;
private FieldInfo trapActiveField;
private FieldInfo explosionCountDownField;
private FieldInfo enemyInvestigateRangeField;
public float wobbleSpeed = 1f;
private const int maxExplosionCountDown = 500;
private SphereCollider triggerCollider;
private FieldInfo isEnemyField;
private bool enemyDetected = false;
private float explosionDelay = 0.5f;
private void Start()
{
clown = ((Component)this).GetComponent<ClownTrap>();
countDownActiveField = typeof(ClownTrap).GetField("CountDownActive", BindingFlags.Instance | BindingFlags.NonPublic);
trapActiveField = typeof(ClownTrap).GetField("trapActive", BindingFlags.Instance | BindingFlags.NonPublic);
explosionCountDownField = typeof(ClownTrap).GetField("ExplosionCountDown", BindingFlags.Instance | BindingFlags.NonPublic);
enemyInvestigateRangeField = typeof(ClownTrap).GetField("enemyInvestigateRange", BindingFlags.Instance | BindingFlags.NonPublic);
isEnemyField = typeof(PhysGrabObject).GetField("isEnemy", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (countDownActiveField != null)
{
countDownActiveField.SetValue(clown, true);
}
if (trapActiveField != null)
{
trapActiveField.SetValue(clown, true);
}
if (explosionCountDownField != null)
{
explosionCountDownField.SetValue(clown, 0);
}
if (enemyInvestigateRangeField != null)
{
enemyInvestigateRangeField.SetValue(clown, 500f);
Debug.Log((object)"Clown enemyInvestigateRange set to 500 units.");
}
((Trap)clown).enemyInvestigate = true;
triggerCollider = ((Component)this).gameObject.AddComponent<SphereCollider>();
((Collider)triggerCollider).isTrigger = true;
triggerCollider.radius = triggerRadius;
Debug.Log((object)("Clown trigger radius set to: " + triggerRadius));
CheckProximityImmediate();
((MonoBehaviour)this).InvokeRepeating("CheckProximityImmediate", 0f, 1f);
}
private void Update()
{
if (explosionCountDownField != null)
{
int num = (int)explosionCountDownField.GetValue(clown);
int num2 = (int)(Time.deltaTime * 50f * wobbleSpeed);
num = Mathf.Min(num + num2, 500);
explosionCountDownField.SetValue(clown, num);
}
if (enemyDetected)
{
explosionDelay -= Time.deltaTime;
if (explosionDelay <= 0f)
{
Debug.Log((object)"Explosion delay finished! Triggering TrapStop.");
clown.TrapStop();
Object.Destroy((Object)(object)this);
}
}
}
private void OnTriggerEnter(Collider other)
{
if (!Object.op_Implicit((Object)(object)clown) || !trapActiveField.GetValue(clown).Equals(true) || enemyDetected)
{
Debug.Log((object)"Clown not active, missing, or already triggered, skipping.");
}
else
{
CheckEnemy(other);
}
}
private void CheckProximityImmediate()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
if (enemyDetected)
{
return;
}
Collider[] array = Physics.OverlapSphere(((Component)this).transform.position, triggerRadius);
Debug.Log((object)("Proximity check: Found " + array.Length + " colliders within " + triggerRadius + " units."));
Collider[] array2 = array;
foreach (Collider other in array2)
{
CheckEnemy(other);
if (enemyDetected)
{
break;
}
}
}
private void CheckEnemy(Collider other)
{
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
PhysGrabObject componentInParent = ((Component)other).GetComponentInParent<PhysGrabObject>();
if ((Object)(object)componentInParent != (Object)null)
{
bool flag = false;
if (isEnemyField != null)
{
flag = (bool)isEnemyField.GetValue(componentInParent);
Debug.Log((object)("PhysGrabObject detected. isEnemy via reflection: " + flag));
}
else
{
flag = ((object)componentInParent).GetType().Name.Contains("Enemy");
Debug.Log((object)("PhysGrabObject detected. isEnemy fallback check: " + flag + " (Type: " + ((object)componentInParent).GetType().Name + ")"));
}
if (flag)
{
Vector3 position = ((Component)other).transform.position;
Debug.Log((object)("Enemy detected at " + ((object)(Vector3)(ref position)).ToString() + "! Starting explosion sequence."));
enemyDetected = true;
if (explosionDelay <= 0f)
{
clown.TrapStop();
Object.Destroy((Object)(object)this);
}
}
}
else
{
Debug.Log((object)("No PhysGrabObject on: " + ((Object)((Component)other).gameObject).name));
}
}
}