using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
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: AssemblyTitle("tp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("tp")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("177e9b31-b651-4aa6-aac8-03f4b96f12c5")]
[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")]
[BepInPlugin("com.peak.randomteleportation", "Random teleportation", "2.5.0")]
public class RandomTeleportation : BaseUnityPlugin, IOnEventCallback
{
[CompilerGenerated]
private sealed class <ForceHideUI>d__16 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public RandomTeleportation <>4__this;
private EndgameCounter[] <>s__1;
private int <>s__2;
private EndgameCounter <c>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ForceHideUI>d__16(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>s__1 = null;
<c>5__3 = null;
<>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(0.1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<>s__1 = Resources.FindObjectsOfTypeAll<EndgameCounter>();
for (<>s__2 = 0; <>s__2 < <>s__1.Length; <>s__2++)
{
<c>5__3 = <>s__1[<>s__2];
if ((Object)(object)<c>5__3 != (Object)null)
{
<c>5__3.Disable();
}
<c>5__3 = null;
}
<>s__1 = null;
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 static RandomTeleportation Instance;
private ConfigEntry<float> _configInterval;
private ConfigEntry<KeyCode> _configKey;
private ConfigEntry<float> _configWarningSec;
private float _autoTimer;
private int _lastSentSecond = -1;
private const byte EVENT_SYNC_COUNTER = 152;
private void Awake()
{
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
Instance = this;
_configInterval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "IntervalMin", 5f, "交换间隔(分钟)");
_configWarningSec = ((BaseUnityPlugin)this).Config.Bind<float>("General", "WarningSec", 10f, "倒计时秒数");
_configKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ManualSwapKey", (KeyCode)108, "手动触发键");
_autoTimer = _configInterval.Value * 60f;
Harmony val = new Harmony("com.peak.randomteleportation");
val.PatchAll();
}
private void OnEnable()
{
PhotonNetwork.AddCallbackTarget((object)this);
}
private void OnDisable()
{
PhotonNetwork.RemoveCallbackTarget((object)this);
}
private bool IsInValidGameScene()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
string name = ((Scene)(ref activeScene)).name;
if (name.Contains("Airport") || name.Contains("Menu") || name.Contains("Lobby"))
{
return false;
}
return PhotonNetwork.InRoom && Character.AllCharacters.Count >= 2;
}
private void Update()
{
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
if (!PhotonNetwork.IsMasterClient || !IsInValidGameScene())
{
if (PhotonNetwork.IsMasterClient)
{
_autoTimer = _configInterval.Value * 60f;
}
return;
}
_autoTimer -= Time.deltaTime;
if (_autoTimer <= _configWarningSec.Value && _autoTimer > 0f)
{
int num = Mathf.CeilToInt(_autoTimer);
if (num != _lastSentSecond)
{
_lastSentSecond = num;
SendCounterEvent(num);
}
}
if (_autoTimer <= 0f || Input.GetKeyDown(_configKey.Value))
{
_autoTimer = _configInterval.Value * 60f;
_lastSentSecond = -1;
SendCounterEvent(-1);
ExecuteSwap();
}
}
private void SendCounterEvent(int second)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_000d: 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)
//IL_0015: Expected O, but got Unknown
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
RaiseEventOptions val = new RaiseEventOptions
{
Receivers = (ReceiverGroup)1,
CachingOption = (EventCaching)0
};
PhotonNetwork.RaiseEvent((byte)152, (object)second, val, SendOptions.SendReliable);
}
public void OnEvent(EventData photonEvent)
{
if (photonEvent.Code == 152 && IsInValidGameScene())
{
int num = (int)photonEvent.CustomData;
if (num == -1)
{
((MonoBehaviour)this).StartCoroutine(ForceHideUI());
}
else
{
ApplyNativeUI(num);
}
}
}
private void ApplyNativeUI(int val)
{
EndgameCounter[] array = Resources.FindObjectsOfTypeAll<EndgameCounter>();
EndgameCounter[] array2 = array;
foreach (EndgameCounter val2 in array2)
{
if (!((Object)(object)val2 == (Object)null))
{
if ((Object)(object)val2.counterGroup != (Object)null)
{
((Component)val2.counterGroup).gameObject.SetActive(true);
val2.counterGroup.alpha = 1f;
}
val2.UpdateCounter(val);
}
}
}
public void ExecuteSwap()
{
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
List<Character> list = Character.AllCharacters.Where((Character c) => (Object)(object)c != (Object)null && !c.data.dead).ToList();
int count = list.Count;
if (count < 2)
{
return;
}
List<Vector3> list2 = list.Select((Character p) => p.Center).ToList();
List<int> list3 = Enumerable.Range(0, count).ToList();
for (int num = count - 1; num > 0; num--)
{
int index = Random.Range(0, num + 1);
int value = list3[num];
list3[num] = list3[index];
list3[index] = value;
}
for (int i = 0; i < count; i++)
{
if (list3[i] == i)
{
int index2 = (i + 1) % count;
int value2 = list3[i];
list3[i] = list3[index2];
list3[index2] = value2;
}
}
for (int j = 0; j < count; j++)
{
if ((Object)(object)((MonoBehaviourPun)list[j]).photonView != (Object)null)
{
((MonoBehaviourPun)list[j]).photonView.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2]
{
list2[list3[j]],
true
});
}
}
}
[IteratorStateMachine(typeof(<ForceHideUI>d__16))]
private IEnumerator ForceHideUI()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ForceHideUI>d__16(0)
{
<>4__this = this
};
}
}