using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 EnderPearlMod
{
public abstract class BaseEnderPearlMod : BaseUnityPlugin
{
protected ManualLogSource ModLogger => ((BaseUnityPlugin)this).Logger;
protected Harmony? HarmonyInstance { get; private set; }
protected virtual void Initialize()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
string gUID = ((BaseUnityPlugin)this).Info.Metadata.GUID;
HarmonyInstance = new Harmony(gUID);
HarmonyInstance.PatchAll();
ModLogger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
}
protected virtual void Cleanup()
{
Harmony? harmonyInstance = HarmonyInstance;
if (harmonyInstance != null)
{
harmonyInstance.UnpatchSelf();
}
}
protected virtual void OnDestroy()
{
Cleanup();
}
}
[BepInPlugin("CarsonJF.EnderPearl", "EnderPearl", "1.0")]
public class EnderPearl : BaseEnderPearlMod
{
public enum States
{
Idle,
Active,
Used
}
[CompilerGenerated]
private sealed class <VerifyAndResetTeleport>d__31 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public PlayerController controller;
public Vector3 targetPos;
object? IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object? IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <VerifyAndResetTeleport>d__31(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_006b: 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 WaitForFixedUpdate();
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if (Vector3.Distance(((Component)controller).transform.position, targetPos) > 0.1f)
{
((Component)controller).transform.position = targetPos;
}
<>2__current = (object)new WaitForSeconds(0.2f);
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
if ((Object)(object)controller.rb != (Object)null)
{
controller.rb.isKinematic = false;
}
controller.OverrideSpeed(1f, 0.1f);
controller.OverrideTimeScale(1f, 0.1f);
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();
}
}
private PhysGrabObject? physGrabObject;
private PhotonView? photonView;
internal States currentState;
private bool stateStart;
[Header("Visual Effects")]
[SerializeField]
private Transform? particleSystemTransform;
[SerializeField]
private ParticleSystem? particleSystemSwirl;
[SerializeField]
private ParticleSystem? particleSystemGlitter;
[SerializeField]
private ParticleSystem? teleportSuccessParticles;
[SerializeField]
private MeshRenderer? pearlRenderer;
[Header("Light Settings")]
[SerializeField]
private Light? lightWhenHeld;
[SerializeField]
private float lightIntensityActive = 4f;
[SerializeField]
private float lightIntensityTeleport = 8f;
[SerializeField]
private Color lightColorActive = new Color(0.5f, 0f, 0.5f);
[SerializeField]
private Color lightColorIdle = new Color(0f, 1f, 0f);
[Header("Sound Effects")]
[SerializeField]
private Sound? impactSound;
private int particleFocus;
private PhysGrabber? lastHolder;
private float lastHoldTime;
private const float TELEPORT_MEMORY_DURATION = 5f;
private Rigidbody? rb;
private Vector3 impactPosition;
public static EnderPearl Instance { get; private set; }
private void Awake()
{
Instance = this;
Initialize();
physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
if ((Object)(object)physGrabObject == (Object)null)
{
Debug.LogError((object)"EnderPearl: Failed to get PhysGrabObject component");
return;
}
photonView = ((Component)this).GetComponent<PhotonView>();
if ((Object)(object)photonView == (Object)null)
{
Debug.LogError((object)"EnderPearl: Failed to get PhotonView component");
return;
}
rb = ((Component)this).GetComponent<Rigidbody>();
if ((Object)(object)rb == (Object)null)
{
rb = ((Component)this).gameObject.AddComponent<Rigidbody>();
}
currentState = States.Idle;
stateStart = true;
lastHoldTime = -5f;
StopAllParticleSystems();
Debug.Log((object)$"EnderPearl initialized. PhotonView ID: {photonView.ViewID}, IsMine: {photonView.IsMine}");
}
private void StopAllParticleSystems()
{
if ((Object)(object)particleSystemSwirl != (Object)null)
{
particleSystemSwirl.Stop();
}
if ((Object)(object)particleSystemGlitter != (Object)null)
{
particleSystemGlitter.Stop();
}
if ((Object)(object)teleportSuccessParticles != (Object)null)
{
teleportSuccessParticles.Stop();
}
}
private void Update()
{
if ((Object)(object)photonView == (Object)null || (Object)(object)physGrabObject == (Object)null)
{
return;
}
if (physGrabObject.grabbed)
{
if (physGrabObject.playerGrabbing != null && physGrabObject.playerGrabbing.Count > 0)
{
PhysGrabber val = physGrabObject.playerGrabbing[0];
if ((Object)(object)val != (Object)(object)lastHolder || currentState == States.Used)
{
Debug.Log((object)$"New holder detected or pearl reset: {((val != null) ? ((Object)val).name : null)}, CurrentState: {currentState}");
lastHolder = val;
lastHoldTime = Time.time;
if (photonView.IsMine)
{
Debug.Log((object)"Setting state to Active on pickup");
SetState(States.Active);
}
}
}
}
else if (currentState == States.Used && Time.time - lastHoldTime > 5f && photonView.IsMine)
{
Debug.Log((object)"Teleport memory expired, returning to Idle");
SetState(States.Idle);
}
switch (currentState)
{
case States.Active:
StateActive();
break;
case States.Idle:
StateIdle();
break;
case States.Used:
StateUsed();
break;
}
}
private void TryTeleportLastHolder()
{
if ((Object)(object)lastHolder == (Object)null || Time.time - lastHoldTime > 5f)
{
PhysGrabber? obj = lastHolder;
Debug.Log((object)$"Teleport cancelled - Invalid last holder or expired. LastHolder: {((obj != null) ? ((Object)obj).name : null)}, TimeSinceHold: {Time.time - lastHoldTime}");
}
else if ((Object)(object)lastHolder.playerAvatar != (Object)null && (Object)(object)photonView != (Object)null)
{
Debug.Log((object)$"Attempting to teleport player {lastHolder.playerAvatar.photonView.ViewID}");
photonView.RPC("ExecuteTeleportRPC", (RpcTarget)0, new object[4]
{
lastHolder.playerAvatar.photonView.ViewID,
impactPosition.x,
impactPosition.y,
impactPosition.z
});
}
}
[PunRPC]
private void ExecuteTeleportRPC(int playerViewID, float x, float y, float z)
{
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
PhotonView val = PhotonView.Find(playerViewID);
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)$"Failed to find PhotonView with ID: {playerViewID}");
return;
}
if (!val.IsMine)
{
Debug.Log((object)$"Skipping teleport for non-owned player. ViewID: {playerViewID}");
return;
}
Debug.Log((object)$"Executing teleport for player {playerViewID}");
Vector3 val2 = default(Vector3);
((Vector3)(ref val2))..ctor(x, y + 0.1f, z);
PlayerAvatar component = ((Component)val).GetComponent<PlayerAvatar>();
if ((Object)(object)component == (Object)null)
{
Debug.LogError((object)"Failed to get PlayerAvatar component");
return;
}
PlayerController instance = PlayerController.instance;
if ((Object)(object)instance == (Object)null)
{
Debug.LogError((object)"Failed to get PlayerController instance");
return;
}
instance.InputDisable(0.5f);
instance.OverrideSpeed(0f, 0.5f);
instance.OverrideTimeScale(0f, 0.5f);
if ((Object)(object)instance.rb != (Object)null)
{
instance.rb.velocity = Vector3.zero;
instance.rb.angularVelocity = Vector3.zero;
instance.rb.isKinematic = true;
}
((Component)instance).transform.position = val2;
((MonoBehaviour)this).StartCoroutine(VerifyAndResetTeleport(instance, val2));
if ((Object)(object)teleportSuccessParticles != (Object)null)
{
((Component)teleportSuccessParticles).transform.position = val2;
teleportSuccessParticles.Play();
}
if ((Object)(object)lightWhenHeld != (Object)null)
{
lightWhenHeld.intensity = lightIntensityTeleport;
((Component)lightWhenHeld).gameObject.SetActive(true);
}
}
[IteratorStateMachine(typeof(<VerifyAndResetTeleport>d__31))]
private IEnumerator VerifyAndResetTeleport(PlayerController controller, Vector3 targetPos)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <VerifyAndResetTeleport>d__31(0)
{
controller = controller,
targetPos = targetPos
};
}
private void StateActive()
{
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
if (stateStart)
{
if ((Object)(object)particleSystemGlitter != (Object)null)
{
particleSystemGlitter.Play();
}
if ((Object)(object)particleSystemSwirl != (Object)null)
{
particleSystemSwirl.Play();
}
stateStart = false;
if ((Object)(object)lightWhenHeld != (Object)null)
{
((Component)lightWhenHeld).gameObject.SetActive(true);
}
}
if ((Object)(object)lightWhenHeld != (Object)null && !((Component)lightWhenHeld).gameObject.activeSelf)
{
((Component)lightWhenHeld).gameObject.SetActive(true);
}
if ((Object)(object)particleSystemTransform != (Object)null && ((Component)particleSystemTransform).gameObject.activeSelf && (Object)(object)physGrabObject != (Object)null)
{
List<PhysGrabber> playerGrabbing = physGrabObject.playerGrabbing;
if (playerGrabbing != null && particleFocus >= 0 && particleFocus < playerGrabbing.Count)
{
PhysGrabber val = playerGrabbing[particleFocus];
if ((Object)(object)val != (Object)null && (Object)(object)val.playerAvatar?.playerAvatarVisuals?.headLookAtTransform != (Object)null)
{
particleSystemTransform.LookAt(val.playerAvatar.playerAvatarVisuals.headLookAtTransform);
particleFocus++;
}
else
{
particleFocus = 0;
}
}
else
{
particleFocus = 0;
}
}
if ((Object)(object)lightWhenHeld != (Object)null)
{
lightWhenHeld.intensity = Mathf.Lerp(lightWhenHeld.intensity, lightIntensityActive, Time.deltaTime * 5f);
MeshRenderer? obj = pearlRenderer;
if ((Object)(object)((obj != null) ? ((Renderer)obj).material : null) != (Object)null)
{
((Renderer)pearlRenderer).material.SetColor("_EmissionColor", lightColorActive * lightWhenHeld.intensity);
}
}
}
private void StateIdle()
{
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
if (stateStart)
{
Debug.Log((object)"Entering Idle state");
StopAllParticleSystems();
stateStart = false;
}
if ((Object)(object)physGrabObject != (Object)null && physGrabObject.grabbed && photonView.IsMine)
{
Debug.Log((object)"Transitioning from Idle to Active state");
SetState(States.Active);
}
if ((Object)(object)lightWhenHeld != (Object)null)
{
lightWhenHeld.intensity = Mathf.Lerp(lightWhenHeld.intensity, 0f, Time.deltaTime * 10f);
MeshRenderer? obj = pearlRenderer;
if ((Object)(object)((obj != null) ? ((Renderer)obj).material : null) != (Object)null)
{
((Renderer)pearlRenderer).material.SetColor("_EmissionColor", lightColorIdle * lightWhenHeld.intensity);
}
if (lightWhenHeld.intensity < 0.01f)
{
((Component)lightWhenHeld).gameObject.SetActive(false);
}
}
}
private void StateUsed()
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
if (stateStart)
{
Debug.Log((object)"Entering Used state");
StopAllParticleSystems();
stateStart = false;
}
if ((Object)(object)lightWhenHeld != (Object)null)
{
lightWhenHeld.intensity = Mathf.Lerp(lightWhenHeld.intensity, 0f, Time.deltaTime * 10f);
MeshRenderer? obj = pearlRenderer;
if ((Object)(object)((obj != null) ? ((Renderer)obj).material : null) != (Object)null)
{
((Renderer)pearlRenderer).material.SetColor("_EmissionColor", lightColorIdle * lightWhenHeld.intensity);
}
if (lightWhenHeld.intensity < 0.01f)
{
((Component)lightWhenHeld).gameObject.SetActive(false);
}
}
}
[PunRPC]
public void SetStateRPC(States state)
{
Debug.Log((object)$"State changed to {state}");
currentState = state;
stateStart = true;
}
private void SetState(States state)
{
if ((Object)(object)photonView == (Object)null)
{
Debug.LogError((object)"Cannot set state - PhotonView is null");
}
else if (photonView.IsMine)
{
Debug.Log((object)$"Setting state to {state}");
photonView.RPC("SetStateRPC", (RpcTarget)0, new object[1] { state });
}
}
private void OnCollisionEnter(Collision collision)
{
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)photonView == (Object)null)
{
return;
}
Debug.Log((object)$"Pearl collision. IsMine: {photonView.IsMine}, State: {currentState}, IsGrabbed: {physGrabObject?.grabbed}, TimeSinceHold: {Time.time - lastHoldTime}");
if (photonView.IsMine && (Object)(object)physGrabObject != (Object)null && !physGrabObject.grabbed && Time.time - lastHoldTime <= 5f && currentState == States.Active)
{
PhysGrabber? obj = lastHolder;
Debug.Log((object)$"Valid collision detected. LastHolder: {((obj != null) ? ((Object)obj).name : null)}, TimeSinceHold: {Time.time - lastHoldTime}");
impactPosition = ((ContactPoint)(ref collision.contacts[0])).point;
if ((Object)(object)particleSystemGlitter != (Object)null)
{
particleSystemGlitter.Play();
}
if ((Object)(object)particleSystemSwirl != (Object)null)
{
particleSystemSwirl.Play();
}
if (impactSound != null)
{
impactSound.Play(((Component)this).transform.position, 1f, 1f, 1f, 1f);
}
TryTeleportLastHolder();
SetState(States.Used);
}
}
}
}