using System;
using System.Collections;
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.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
[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("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmpressPennywise")]
[assembly: AssemblyTitle("EmpressPennywise")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 Empress.Pennywise
{
[BepInPlugin("empress.repo.pennywise", "Pennywise", "1.2.3")]
public class PennywisePlugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <LoadCustomAudio>d__20 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public PennywisePlugin <>4__this;
private string <myDir>5__1;
private string <attackPath>5__2;
private string <balloonPath>5__3;
private string[] <files>5__4;
private UnityWebRequest <www>5__5;
private UnityWebRequest <www>5__6;
private string[] <>s__7;
private int <>s__8;
private string <f>5__9;
private UnityWebRequest <www>5__10;
private AudioClip <clip>5__11;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <LoadCustomAudio>d__20(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
switch (<>1__state)
{
case -3:
case 1:
try
{
}
finally
{
<>m__Finally1();
}
break;
case -4:
case 2:
try
{
}
finally
{
<>m__Finally2();
}
break;
case -5:
case 3:
try
{
}
finally
{
<>m__Finally3();
}
break;
}
<myDir>5__1 = null;
<attackPath>5__2 = null;
<balloonPath>5__3 = null;
<files>5__4 = null;
<www>5__5 = null;
<www>5__6 = null;
<>s__7 = null;
<f>5__9 = null;
<www>5__10 = null;
<clip>5__11 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Invalid comparison between Unknown and I4
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Invalid comparison between Unknown and I4
//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Invalid comparison between Unknown and I4
try
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<myDir>5__1 = Path.GetDirectoryName(((BaseUnityPlugin)<>4__this).Info.Location);
if (string.IsNullOrEmpty(<myDir>5__1))
{
<myDir>5__1 = Paths.PluginPath;
}
<attackPath>5__2 = Path.Combine(<myDir>5__1, "attack.ogg");
if (File.Exists(<attackPath>5__2))
{
<www>5__5 = UnityWebRequestMultimedia.GetAudioClip("file://" + <attackPath>5__2, (AudioType)14);
<>1__state = -3;
<>2__current = <www>5__5.SendWebRequest();
<>1__state = 1;
return true;
}
goto IL_0140;
case 1:
<>1__state = -3;
if ((int)<www>5__5.result == 1)
{
AttackClip = DownloadHandlerAudioClip.GetContent(<www>5__5);
((Object)AttackClip).name = "AttackSound";
Log.LogInfo((object)"Loaded attack.ogg");
}
<>m__Finally1();
<www>5__5 = null;
goto IL_0140;
case 2:
<>1__state = -4;
if ((int)<www>5__6.result == 1)
{
BalloonPopClip = DownloadHandlerAudioClip.GetContent(<www>5__6);
((Object)BalloonPopClip).name = "BalloonPop";
Log.LogInfo((object)"Loaded balloon.ogg");
}
<>m__Finally2();
<www>5__6 = null;
goto IL_020e;
case 3:
{
<>1__state = -5;
if ((int)<www>5__10.result == 1)
{
<clip>5__11 = DownloadHandlerAudioClip.GetContent(<www>5__10);
((Object)<clip>5__11).name = Path.GetFileName(<f>5__9);
StalkClips.Add(<clip>5__11);
<clip>5__11 = null;
}
<>m__Finally3();
<www>5__10 = null;
<f>5__9 = null;
<>s__8++;
break;
}
IL_0140:
<balloonPath>5__3 = Path.Combine(<myDir>5__1, "balloon.ogg");
if (File.Exists(<balloonPath>5__3))
{
<www>5__6 = UnityWebRequestMultimedia.GetAudioClip("file://" + <balloonPath>5__3, (AudioType)14);
<>1__state = -4;
<>2__current = <www>5__6.SendWebRequest();
<>1__state = 2;
return true;
}
goto IL_020e;
IL_020e:
<files>5__4 = Directory.GetFiles(<myDir>5__1, "penny*.ogg");
<>s__7 = <files>5__4;
<>s__8 = 0;
break;
}
if (<>s__8 < <>s__7.Length)
{
<f>5__9 = <>s__7[<>s__8];
<www>5__10 = UnityWebRequestMultimedia.GetAudioClip("file://" + <f>5__9, (AudioType)14);
<>1__state = -5;
<>2__current = <www>5__10.SendWebRequest();
<>1__state = 3;
return true;
}
<>s__7 = null;
Log.LogInfo((object)$"Loaded {StalkClips.Count} stalk sounds.");
return false;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<www>5__5 != null)
{
((IDisposable)<www>5__5).Dispose();
}
}
private void <>m__Finally2()
{
<>1__state = -1;
if (<www>5__6 != null)
{
((IDisposable)<www>5__6).Dispose();
}
}
private void <>m__Finally3()
{
<>1__state = -1;
if (<www>5__10 != null)
{
((IDisposable)<www>5__10).Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <WaitLevelThenSpawn>d__26 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public PennywisePlugin <>4__this;
private float <t>5__1;
private float <chance>5__2;
private float <randomDelay>5__3;
private List<PlayerAvatar> <players>5__4;
private PlayerAvatar <target>5__5;
private int <targetId>5__6;
private Vector3? <spawnPos>5__7;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <WaitLevelThenSpawn>d__26(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<players>5__4 = null;
<target>5__5 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
if (<>4__this._spawnRoutineRunning || _hasKilledThisLevel)
{
return false;
}
<>4__this._spawnRoutineRunning = true;
<t>5__1 = 0f;
goto IL_00b3;
case 1:
<>1__state = -1;
goto IL_00b3;
case 2:
{
<>1__state = -1;
<players>5__4 = GetPlayers();
if (<players>5__4.Count == 0)
{
<>4__this._spawnRoutineRunning = false;
return false;
}
<target>5__5 = <players>5__4[Random.Range(0, <players>5__4.Count)];
<targetId>5__6 = <target>5__5.photonView.ViewID;
<spawnPos>5__7 = GetValidFarPoint(((Component)<target>5__5).transform.position, 15f, 999f);
if (<spawnPos>5__7.HasValue)
{
PennywiseEventRouter.BroadcastSpawnBalloon(<spawnPos>5__7.Value + Vector3.up * 0.6f, Quaternion.identity, <targetId>5__6);
}
<>4__this._spawnRoutineRunning = false;
return false;
}
IL_00b3:
if (BlockedMenuOrHub() || (Object)(object)LevelGenerator.Instance == (Object)null || !LevelGenerator.Instance.Generated || !NavMeshReady())
{
if (<t>5__1 >= 30f)
{
<>4__this._spawnRoutineRunning = false;
return false;
}
<t>5__1 += Time.unscaledDeltaTime;
<>2__current = null;
<>1__state = 1;
return true;
}
if (!IsHost())
{
<>4__this._spawnRoutineRunning = false;
return false;
}
if ((Object)(object)BalloonPrefab == (Object)null || (Object)(object)PennywisePrefab == (Object)null)
{
<>4__this._spawnRoutineRunning = false;
return false;
}
<chance>5__2 = Mathf.Clamp01(SpawnChance.Value);
if (Random.value > <chance>5__2)
{
<>4__this._spawnRoutineRunning = false;
return false;
}
<randomDelay>5__3 = Random.Range(20f, 120f);
<>2__current = (object)new WaitForSeconds(<randomDelay>5__3);
<>1__state = 2;
return true;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public const string PluginGuid = "empress.repo.pennywise";
public const string PluginName = "Pennywise";
public const string PluginVersion = "1.2.3";
internal static ManualLogSource Log;
private Harmony _harmony;
private static AssetBundle _bundle;
internal static GameObject BalloonPrefab;
internal static GameObject PennywisePrefab;
internal static List<AudioClip> StalkClips = new List<AudioClip>();
internal static AudioClip AttackClip;
internal static AudioClip BalloonPopClip;
internal static ConfigEntry<float> SpawnChance;
internal static ConfigEntry<float> SoundVolume;
public static float BalloonSpeed = 3f;
public static float PennywiseSpeed = 9f;
public static float SwitchTargetTime = 180f;
private bool _spawnRoutineRunning;
private static bool _hasKilledThisLevel;
public static LayerMask VisionMask = LayerMask.op_Implicit(-1);
private void Awake()
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Expected O, but got Unknown
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
Log = ((BaseUnityPlugin)this).Logger;
_harmony = new Harmony("empress.repo.pennywise");
_harmony.PatchAll(typeof(PennywisePlugin).Assembly);
SpawnChance = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn", "SpawnChance", 0.05f, "Chance [0..1] that Pennywise spawns.");
SoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "Volume", 1f, "Master volume for Pennywise sounds [0..1].");
LoadBundle();
((MonoBehaviour)this).StartCoroutine(LoadCustomAudio());
GameObject val = new GameObject("Pennywise_RouterHost");
Object.DontDestroyOnLoad((Object)(object)val);
((Object)val).hideFlags = (HideFlags)52;
val.AddComponent<PennywiseEventRouter>();
SceneManager.sceneLoaded += OnSceneLoaded;
}
[IteratorStateMachine(typeof(<LoadCustomAudio>d__20))]
private IEnumerator LoadCustomAudio()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <LoadCustomAudio>d__20(0)
{
<>4__this = this
};
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void OnSceneLoaded(Scene s, LoadSceneMode m)
{
_spawnRoutineRunning = false;
_hasKilledThisLevel = false;
((MonoBehaviour)this).StopAllCoroutines();
if (PhotonNetwork.InRoom || !PhotonNetwork.IsConnected)
{
((MonoBehaviour)this).StartCoroutine(WaitLevelThenSpawn());
}
}
private static bool BlockedMenuOrHub()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
try
{
Scene activeScene = SceneManager.GetActiveScene();
string text = SafeLower(((Scene)(ref activeScene)).name);
if (text.Contains("menu") || text.Contains("loader") || text.Contains("intro"))
{
return true;
}
if ((Object)(object)RunManager.instance != (Object)null && (Object)(object)RunManager.instance.levelCurrent != (Object)null)
{
string text2 = SafeLower(RunManager.instance.levelCurrent.NarrativeName);
if (text2.Contains("lobby") || text2.Contains("menu"))
{
return true;
}
}
return false;
}
catch
{
return true;
}
}
private static string SafeLower(string s)
{
return (s ?? string.Empty).Trim().ToLowerInvariant();
}
private static bool NavMeshReady()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
try
{
return NavMesh.CalculateTriangulation().vertices.Length != 0;
}
catch
{
return false;
}
}
[IteratorStateMachine(typeof(<WaitLevelThenSpawn>d__26))]
private IEnumerator WaitLevelThenSpawn()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <WaitLevelThenSpawn>d__26(0)
{
<>4__this = this
};
}
public static Vector3? GetValidFarPoint(Vector3 center, float minDst, float maxDst)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
LevelGenerator instance = LevelGenerator.Instance;
if ((Object)(object)instance == (Object)null || !instance.Generated || instance.LevelPathPoints == null)
{
return null;
}
List<Transform> list = (from p in instance.LevelPathPoints
where (Object)(object)p != (Object)null
select ((Component)p).transform).Where(delegate(Transform t)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
float num = Vector3.Distance(t.position, center);
return num >= minDst && num <= maxDst;
}).ToList();
if (list.Count == 0)
{
if (instance.LevelPathPoints.Count <= 0)
{
return null;
}
list = (from p in instance.LevelPathPoints
where (Object)(object)p != (Object)null
select ((Component)p).transform).ToList();
}
NavMeshHit val2 = default(NavMeshHit);
for (int i = 0; i < 10; i++)
{
Transform val = list[Random.Range(0, list.Count)];
if (NavMesh.SamplePosition(val.position, ref val2, 5f, -1))
{
return ((NavMeshHit)(ref val2)).position;
}
}
return null;
}
private void LoadBundle()
{
if ((Object)(object)_bundle != (Object)null)
{
return;
}
try
{
string text = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
if (string.IsNullOrEmpty(text))
{
text = Paths.PluginPath;
}
string text2 = Directory.GetFiles(text, "scary", SearchOption.AllDirectories).FirstOrDefault();
if (!string.IsNullOrEmpty(text2))
{
_bundle = AssetBundle.LoadFromFile(text2);
if (Object.op_Implicit((Object)(object)_bundle))
{
BalloonPrefab = _bundle.LoadAsset<GameObject>("Balloon");
PennywisePrefab = _bundle.LoadAsset<GameObject>("Pennywise");
SetupPrefab(BalloonPrefab);
SetupPrefab(PennywisePrefab);
Log.LogInfo((object)"Loaded 'scary' bundle.");
}
}
}
catch (Exception arg)
{
Log.LogError((object)$"LoadBundle failed: {arg}");
}
}
public static void MarkKillAchieved()
{
_hasKilledThisLevel = true;
}
public static bool IsHost()
{
return !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient;
}
public static bool IsDead(PlayerAvatar p)
{
if ((Object)(object)p == (Object)null)
{
return true;
}
object value = AccessTools.Field(typeof(PlayerAvatar), "deadSet").GetValue(p);
return value != null && (bool)value;
}
public static List<PlayerAvatar> GetPlayers()
{
return (from p in Object.FindObjectsOfType<PlayerAvatar>()
where (Object)(object)p != (Object)null && !IsDead(p)
select p).ToList();
}
private void SetupPrefab(GameObject go)
{
if (Object.op_Implicit((Object)(object)go))
{
NavMeshAgent val = go.GetComponent<NavMeshAgent>();
if (!Object.op_Implicit((Object)(object)val))
{
val = go.AddComponent<NavMeshAgent>();
}
if (!Object.op_Implicit((Object)(object)go.GetComponent<PennywiseController>()))
{
go.AddComponent<PennywiseController>();
}
val.radius = 0.25f;
val.height = 1.8f;
((Behaviour)val).enabled = false;
AudioSource[] componentsInChildren = go.GetComponentsInChildren<AudioSource>();
AudioSource[] array = componentsInChildren;
foreach (AudioSource val2 in array)
{
val2.spatialBlend = 1f;
val2.minDistance = 2f;
val2.maxDistance = 15f;
val2.rolloffMode = (AudioRolloffMode)1;
val2.loop = true;
}
}
}
}
[RequireComponent(typeof(NavMeshAgent))]
public class PennywiseController : MonoBehaviour
{
public enum EnemyType
{
Balloon,
Stalker,
Clown
}
[CompilerGenerated]
private sealed class <AttackSequence>d__23 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public PennywiseController <>4__this;
private float <timer>5__1;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <AttackSequence>d__23(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_026a: Unknown result type (might be due to invalid IL or missing references)
//IL_0274: Expected O, but got Unknown
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(2f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if ((Object)(object)PennywisePlugin.AttackClip != (Object)null)
{
<>4__this._audioSrc.PlayOneShot(PennywisePlugin.AttackClip);
}
<>4__this._charging = true;
if (Object.op_Implicit((Object)(object)<>4__this._anim))
{
<>4__this._anim.SetBool("attack", true);
}
if (Object.op_Implicit((Object)(object)<>4__this._agent) && <>4__this._agent.isOnNavMesh)
{
<>4__this._agent.isStopped = false;
<>4__this._agent.speed = PennywisePlugin.PennywiseSpeed;
<>4__this._agent.acceleration = 200f;
<>4__this._agent.angularSpeed = 720f;
<>4__this._agent.stoppingDistance = 0f;
<>4__this._agent.autoBraking = false;
<>4__this._agent.updateRotation = false;
}
else if ((Object)(object)<>4__this._targetPlayer != (Object)null)
{
((Component)<>4__this).transform.position = ((Component)<>4__this._targetPlayer).transform.position;
}
PennywisePlugin.MarkKillAchieved();
if (!PennywisePlugin.IsHost())
{
break;
}
<timer>5__1 = 0f;
goto IL_024e;
case 2:
<>1__state = -1;
goto IL_024e;
case 3:
{
<>1__state = -1;
PennywiseEventRouter.BroadcastDespawn();
break;
}
IL_024e:
if (<timer>5__1 < 10f && !((Object)(object)<>4__this._targetPlayer == (Object)null) && !(Vector3.Distance(((Component)<>4__this).transform.position, ((Component)<>4__this._targetPlayer).transform.position) < 1.5f))
{
<timer>5__1 += Time.deltaTime;
<>2__current = null;
<>1__state = 2;
return true;
}
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 3;
return true;
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <StalkLifeCycle>d__22 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public PennywiseController <>4__this;
private bool <nextIsAttack>5__1;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <StalkLifeCycle>d__22(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(2f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<>4__this._stalkCount++;
<nextIsAttack>5__1 = <>4__this._stalkCount >= 3;
<>4__this.SpawnNextPhase(<nextIsAttack>5__1);
Object.Destroy((Object)(object)((Component)<>4__this).gameObject);
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public EnemyType Type;
private NavMeshAgent _agent;
private PlayerAvatar _targetPlayer;
private int _targetViewId;
private int _stalkCount;
private float _spawnTime;
private Animator _anim;
private AudioSource _audioSrc;
private bool _charging;
private bool _balloonFollowing;
private float _balloonFollowTimer;
public void Setup(int targetViewID, EnemyType type, int stalkCount)
{
_targetViewId = targetViewID;
Type = type;
_stalkCount = stalkCount;
RefreshTargetRef();
}
private void Awake()
{
_spawnTime = Time.time;
_agent = ((Component)this).GetComponent<NavMeshAgent>();
_anim = ((Component)this).GetComponent<Animator>();
_audioSrc = ((Component)this).GetComponent<AudioSource>();
if (!Object.op_Implicit((Object)(object)_audioSrc))
{
_audioSrc = ((Component)this).gameObject.AddComponent<AudioSource>();
_audioSrc.spatialBlend = 1f;
_audioSrc.minDistance = 2f;
_audioSrc.maxDistance = 25f;
}
if (PennywisePlugin.SoundVolume != null)
{
_audioSrc.volume = PennywisePlugin.SoundVolume.Value;
}
}
private void Start()
{
RefreshTargetRef();
if (Object.op_Implicit((Object)(object)_targetPlayer))
{
Debug.LogWarning((object)$"[Pennywise] Spawned {Type}. Target: {((Object)_targetPlayer).name} (ID: {_targetViewId})");
}
if (Object.op_Implicit((Object)(object)_agent))
{
_agent.updateRotation = false;
}
switch (Type)
{
case EnemyType.Balloon:
if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
{
((Behaviour)_agent).enabled = true;
_agent.speed = PennywisePlugin.BalloonSpeed;
_agent.stoppingDistance = 2f;
_agent.baseOffset = 0.6f;
_agent.updateRotation = true;
}
else if (PennywisePlugin.IsHost())
{
Object.Destroy((Object)(object)((Component)this).gameObject);
}
break;
case EnemyType.Stalker:
if (PennywisePlugin.StalkClips.Count > 0)
{
AudioClip val = PennywisePlugin.StalkClips[_stalkCount % PennywisePlugin.StalkClips.Count];
_audioSrc.PlayOneShot(val);
}
if (Object.op_Implicit((Object)(object)_agent))
{
((Behaviour)_agent).enabled = true;
_agent.speed = 0f;
_agent.baseOffset = 0f;
}
if (PennywisePlugin.IsHost())
{
((MonoBehaviour)this).StartCoroutine(StalkLifeCycle());
}
break;
case EnemyType.Clown:
if (Object.op_Implicit((Object)(object)_agent))
{
((Behaviour)_agent).enabled = true;
_agent.baseOffset = 0f;
_agent.speed = 0f;
}
((MonoBehaviour)this).StartCoroutine(AttackSequence());
break;
}
}
private void Update()
{
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_targetPlayer == (Object)null)
{
RefreshTargetRef();
}
if ((Object)(object)_targetPlayer == (Object)null && PennywisePlugin.IsHost())
{
PickNewTarget();
if ((Object)(object)_targetPlayer == (Object)null)
{
Object.Destroy((Object)(object)((Component)this).gameObject);
return;
}
}
if ((Object)(object)_targetPlayer != (Object)null && (Type == EnemyType.Stalker || (Type == EnemyType.Clown && !_charging) || Type == EnemyType.Balloon))
{
Vector3 position = ((Component)_targetPlayer).transform.position;
position.y = ((Component)this).transform.position.y;
((Component)this).transform.LookAt(position);
}
if (Type == EnemyType.Balloon)
{
BalloonLogic();
}
if (PennywisePlugin.IsHost() && Type == EnemyType.Clown && _charging && Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh && (Object)(object)_targetPlayer != (Object)null)
{
_agent.SetDestination(((Component)_targetPlayer).transform.position);
Vector3 velocity = _agent.velocity;
if (((Vector3)(ref velocity)).sqrMagnitude > 0.1f)
{
((Component)this).transform.rotation = Quaternion.LookRotation(_agent.velocity);
}
}
}
private void OnCollisionEnter(Collision collision)
{
if (PennywisePlugin.IsHost() && Type == EnemyType.Balloon && !(Time.time < _spawnTime + 5f) && IsValidPopObject(collision.gameObject))
{
PopBalloon();
}
}
private void OnTriggerEnter(Collider other)
{
if (PennywisePlugin.IsHost() && Type == EnemyType.Balloon && !(Time.time < _spawnTime + 5f) && IsValidPopObject(((Component)other).gameObject))
{
PopBalloon();
}
}
private bool IsValidPopObject(GameObject obj)
{
if ((Object)(object)obj.GetComponentInParent<Item>() != (Object)null)
{
return true;
}
if ((Object)(object)obj.GetComponentInParent<ValuableObject>() != (Object)null)
{
return true;
}
return false;
}
private void PopBalloon()
{
PlayPopSound();
PennywiseEventRouter.BroadcastDespawn();
Object.Destroy((Object)(object)((Component)this).gameObject);
}
private void BalloonLogic()
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)_agent) || !_agent.isOnNavMesh || (Object)(object)_targetPlayer == (Object)null)
{
return;
}
_agent.SetDestination(((Component)_targetPlayer).transform.position);
if (!PennywisePlugin.IsHost())
{
return;
}
if (_balloonFollowing)
{
_balloonFollowTimer += Time.deltaTime;
if (_balloonFollowTimer > 5f)
{
PlayPopSound();
SpawnNextPhase(isAttack: false);
Object.Destroy((Object)(object)((Component)this).gameObject);
}
}
else if (Vector3.Distance(((Component)this).transform.position, ((Component)_targetPlayer).transform.position) < 3f)
{
_balloonFollowing = true;
_balloonFollowTimer = 0f;
}
if (Time.time - _spawnTime > PennywisePlugin.SwitchTargetTime)
{
PickNewTarget();
_spawnTime = Time.time;
}
}
private void PlayPopSound()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)PennywisePlugin.BalloonPopClip != (Object)null)
{
AudioSource.PlayClipAtPoint(PennywisePlugin.BalloonPopClip, ((Component)this).transform.position, PennywisePlugin.SoundVolume.Value);
}
}
[IteratorStateMachine(typeof(<StalkLifeCycle>d__22))]
private IEnumerator StalkLifeCycle()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <StalkLifeCycle>d__22(0)
{
<>4__this = this
};
}
[IteratorStateMachine(typeof(<AttackSequence>d__23))]
private IEnumerator AttackSequence()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <AttackSequence>d__23(0)
{
<>4__this = this
};
}
private void SpawnNextPhase(bool isAttack)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_targetPlayer == (Object)null))
{
float minDst = (isAttack ? 8f : 15f);
Vector3? validFarPoint = PennywisePlugin.GetValidFarPoint(((Component)_targetPlayer).transform.position, minDst, 999f);
Vector3 pos = (validFarPoint.HasValue ? validFarPoint.Value : ((Component)_targetPlayer).transform.position);
if (isAttack)
{
PennywiseEventRouter.BroadcastAttack(pos, Quaternion.identity, _targetViewId);
}
else
{
PennywiseEventRouter.BroadcastStalk(pos, Quaternion.identity, _targetViewId, _stalkCount);
}
}
}
private void PickNewTarget()
{
List<PlayerAvatar> players = PennywisePlugin.GetPlayers();
List<PlayerAvatar> list = players.Where((PlayerAvatar p) => (Object)(object)p != (Object)(object)_targetPlayer).ToList();
if (list.Count > 0)
{
_targetPlayer = list[Random.Range(0, list.Count)];
_targetViewId = _targetPlayer.photonView.ViewID;
PennywiseEventRouter.BroadcastNewTarget(((Component)this).gameObject.GetComponent<PhotonView>().ViewID, _targetViewId);
}
}
public void SetNewTargetClient(int newTargetID)
{
_targetViewId = newTargetID;
RefreshTargetRef();
}
private void RefreshTargetRef()
{
List<PlayerAvatar> players = PennywisePlugin.GetPlayers();
_targetPlayer = ((IEnumerable<PlayerAvatar>)players).FirstOrDefault((Func<PlayerAvatar, bool>)((PlayerAvatar p) => p.photonView.ViewID == _targetViewId));
if ((Object)(object)_targetPlayer == (Object)null && players.Count > 0)
{
_targetPlayer = players[0];
}
}
}
public class PennywiseEventRouter : MonoBehaviourPunCallbacks, IOnEventCallback
{
public enum Ev : byte
{
SpawnBalloon = 60,
Transform,
Despawn,
NewTarget,
Stalk
}
private static bool _callbackHooked;
private static GameObject _activeEnemy;
private void OnEnable()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDisable()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
if (_callbackHooked)
{
PhotonNetwork.RemoveCallbackTarget((object)this);
}
_callbackHooked = false;
}
public override void OnJoinedRoom()
{
EnsureCallbackHooked();
}
public override void OnLeftRoom()
{
if (_callbackHooked)
{
PhotonNetwork.RemoveCallbackTarget((object)this);
_callbackHooked = false;
}
if (Object.op_Implicit((Object)(object)_activeEnemy))
{
Object.Destroy((Object)(object)_activeEnemy);
}
}
private void OnSceneLoaded(Scene s, LoadSceneMode m)
{
if (Object.op_Implicit((Object)(object)_activeEnemy))
{
Object.Destroy((Object)(object)_activeEnemy);
}
if (PhotonNetwork.InRoom)
{
EnsureCallbackHooked();
}
}
private void EnsureCallbackHooked()
{
if (!_callbackHooked)
{
PhotonNetwork.AddCallbackTarget((object)this);
_callbackHooked = true;
}
}
internal static void BroadcastSpawnBalloon(Vector3 pos, Quaternion rot, int targetID)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
CreateLocal(pos, rot, targetID, PennywiseController.EnemyType.Balloon, 0);
if (PhotonNetwork.InRoom)
{
object[] array = new object[3] { pos, rot, targetID };
PhotonNetwork.RaiseEvent((byte)60, (object)array, new RaiseEventOptions
{
Receivers = (ReceiverGroup)0
}, SendOptions.SendReliable);
}
}
internal static void BroadcastStalk(Vector3 pos, Quaternion rot, int targetID, int count)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Expected O, but got Unknown
if (Object.op_Implicit((Object)(object)_activeEnemy))
{
Object.Destroy((Object)(object)_activeEnemy);
}
CreateLocal(pos, rot, targetID, PennywiseController.EnemyType.Stalker, count);
if (PhotonNetwork.InRoom)
{
object[] array = new object[4] { pos, rot, targetID, count };
PhotonNetwork.RaiseEvent((byte)64, (object)array, new RaiseEventOptions
{
Receivers = (ReceiverGroup)0
}, SendOptions.SendReliable);
}
}
internal static void BroadcastAttack(Vector3 pos, Quaternion rot, int targetID)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
if (Object.op_Implicit((Object)(object)_activeEnemy))
{
Object.Destroy((Object)(object)_activeEnemy);
}
CreateLocal(pos, rot, targetID, PennywiseController.EnemyType.Clown, 0);
if (PhotonNetwork.InRoom)
{
object[] array = new object[3] { pos, rot, targetID };
PhotonNetwork.RaiseEvent((byte)61, (object)array, new RaiseEventOptions
{
Receivers = (ReceiverGroup)0
}, SendOptions.SendReliable);
}
}
internal static void BroadcastDespawn()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
if (Object.op_Implicit((Object)(object)_activeEnemy))
{
Object.Destroy((Object)(object)_activeEnemy);
}
if (PhotonNetwork.InRoom)
{
PhotonNetwork.RaiseEvent((byte)62, (object)null, new RaiseEventOptions
{
Receivers = (ReceiverGroup)0
}, SendOptions.SendReliable);
}
}
internal static void BroadcastNewTarget(int enemyPhotonID, int newTargetID)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
if (Object.op_Implicit((Object)(object)_activeEnemy))
{
_activeEnemy.GetComponent<PennywiseController>()?.SetNewTargetClient(newTargetID);
}
if (PhotonNetwork.InRoom)
{
object[] array = new object[2] { enemyPhotonID, newTargetID };
PhotonNetwork.RaiseEvent((byte)63, (object)array, new RaiseEventOptions
{
Receivers = (ReceiverGroup)0
}, SendOptions.SendReliable);
}
}
private static void CreateLocal(Vector3 pos, Quaternion rot, int targetID, PennywiseController.EnemyType type, int stalkCount)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: 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_0165: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)_activeEnemy))
{
Object.Destroy((Object)(object)_activeEnemy);
}
Scene activeScene = SceneManager.GetActiveScene();
string text = ((Scene)(ref activeScene)).name.ToLower();
if (text.Contains("menu") || text.Contains("loader") || text.Contains("intro"))
{
return;
}
GameObject val = ((type == PennywiseController.EnemyType.Balloon) ? PennywisePlugin.BalloonPrefab : PennywisePlugin.PennywisePrefab);
if (!Object.op_Implicit((Object)(object)val))
{
return;
}
NavMeshHit val2 = default(NavMeshHit);
if (NavMesh.SamplePosition(pos, ref val2, 5f, -1))
{
pos = ((NavMeshHit)(ref val2)).position;
}
_activeEnemy = Object.Instantiate<GameObject>(val, pos, rot);
NavMeshAgent component = _activeEnemy.GetComponent<NavMeshAgent>();
if (Object.op_Implicit((Object)(object)component))
{
((Behaviour)component).enabled = true;
if (!component.Warp(pos))
{
List<PlayerAvatar> players = PennywisePlugin.GetPlayers();
PlayerAvatar val3 = ((IEnumerable<PlayerAvatar>)players).FirstOrDefault((Func<PlayerAvatar, bool>)((PlayerAvatar p) => p.photonView.ViewID == targetID));
if (Object.op_Implicit((Object)(object)val3))
{
Vector3 val4 = ((Component)val3).transform.position - ((Component)val3).transform.forward * 3f;
NavMeshHit val5 = default(NavMeshHit);
if (NavMesh.SamplePosition(val4, ref val5, 5f, -1))
{
component.Warp(((NavMeshHit)(ref val5)).position);
}
else
{
component.Warp(((Component)val3).transform.position);
}
}
}
}
PennywiseController component2 = _activeEnemy.GetComponent<PennywiseController>();
if (Object.op_Implicit((Object)(object)component2))
{
component2.Setup(targetID, type, stalkCount);
}
}
public void OnEvent(EventData e)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
try
{
if (e.Code == 60)
{
object[] array = (object[])e.CustomData;
CreateLocal((Vector3)array[0], (Quaternion)array[1], (int)array[2], PennywiseController.EnemyType.Balloon, 0);
}
else if (e.Code == 64)
{
object[] array2 = (object[])e.CustomData;
CreateLocal((Vector3)array2[0], (Quaternion)array2[1], (int)array2[2], PennywiseController.EnemyType.Stalker, (int)array2[3]);
}
else if (e.Code == 61)
{
object[] array3 = (object[])e.CustomData;
if (Object.op_Implicit((Object)(object)_activeEnemy))
{
Object.Destroy((Object)(object)_activeEnemy);
}
CreateLocal((Vector3)array3[0], (Quaternion)array3[1], (int)array3[2], PennywiseController.EnemyType.Clown, 0);
}
else if (e.Code == 62)
{
if (Object.op_Implicit((Object)(object)_activeEnemy))
{
Object.Destroy((Object)(object)_activeEnemy);
}
}
else if (e.Code == 63)
{
object[] array4 = (object[])e.CustomData;
int newTargetClient = (int)array4[1];
if (Object.op_Implicit((Object)(object)_activeEnemy))
{
_activeEnemy.GetComponent<PennywiseController>()?.SetNewTargetClient(newTargetClient);
}
}
}
catch
{
}
}
}
}