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 System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ULTRAKILL.Portal;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("RandomPortal")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+73a58415c29e8a64119150cbe5a9316c90d39da7")]
[assembly: AssemblyProduct("RandomPortal")]
[assembly: AssemblyTitle("RandomPortal")]
[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 RandomPortal
{
[BepInPlugin("RandomPortal", "RandomPortal", "1.0.0")]
public class RandomPortal : BaseUnityPlugin
{
public static List<Portal> Portals = new List<Portal>();
public static List<Portal> PickedPortals = new List<Portal>();
public static List<int> CurrentRand = new List<int>();
public static List<Portal> LastPortals = new List<Portal>();
public static List<DoorController> FlaggedDoors = new List<DoorController>();
public static Dictionary<DoorController, Door> DoorList = new Dictionary<DoorController, Door>();
public static bool Updated = false;
public static bool SlowUpdated = false;
public static int rand = 0;
public static RandomPortal Instance { get; private set; } = null;
internal static ManualLogSource Logger { get; private set; } = null;
internal static Harmony? Harmony { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
Patch();
Logger.LogInfo((object)"RandomPortal v1.0.0 has loaded!");
SceneManager.sceneLoaded += delegate
{
string currentScene = SceneHelper.CurrentScene;
if (currentScene != "Main Menu" && currentScene != "Intro" && currentScene != "Bootstrap" && Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "icon.dll") != string.Empty)
{
MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage("Remove icon.dll from your mods folder, im unsure if other mods use the name so im not deleting it", "", "", 0, false, false, true);
}
Portals.Clear();
Portals.Capacity = 0;
PickedPortals.Clear();
PickedPortals.Capacity = 0;
LastPortals.Clear();
LastPortals.Capacity = 0;
FlaggedDoors.Clear();
FlaggedDoors.Capacity = 0;
DoorList.Clear();
CurrentRand.Clear();
CurrentRand.Capacity = 0;
Updated = false;
SlowUpdated = false;
};
}
internal static void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("RandomPortal");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
Logger.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "RandomPortal";
public const string PLUGIN_NAME = "RandomPortal";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace RandomPortal.Patches
{
public class CoroutineRunner : MonoBehaviour
{
private static CoroutineRunner _instance;
public static CoroutineRunner Instance
{
get
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if ((Object)(object)_instance == (Object)null)
{
GameObject val = new GameObject();
_instance = val.AddComponent<CoroutineRunner>();
Object.DontDestroyOnLoad((Object)(object)val);
}
return _instance;
}
}
public Coroutine RunCoroutine(IEnumerator coroutine)
{
return ((MonoBehaviour)this).StartCoroutine(coroutine);
}
}
[HarmonyPatch(typeof(DoorController))]
public class DoorAdder
{
public static void RemoveAt<T>(ref T[] arr, int index)
{
for (int i = index; i < arr.Length - 1; i++)
{
arr[i] = arr[i + 1];
}
Array.Resize(ref arr, arr.Length - 1);
}
public static void Add<T>(ref T[] arr, T obj)
{
Array.Resize(ref arr, arr.Length + 1);
arr[arr.Length - 1] = obj;
}
public static Transform NearRoot(Transform obj)
{
Transform val = obj;
bool flag = true;
do
{
if ((Object)(object)val.parent != (Object)null)
{
if ((Object)(object)val.parent != (Object)(object)val.root)
{
val = val.parent;
}
else if ((Object)(object)val.parent == (Object)(object)val.root)
{
flag = false;
}
}
}
while (flag);
return val;
}
[HarmonyPatch("Update")]
[HarmonyPrefix]
private static void AddDoor(DoorController __instance, Door ___dc)
{
if (!RandomPortal.DoorList.ContainsKey(__instance))
{
return;
}
FieldRef<DoorController, Door> val = AccessTools.FieldRefAccess<DoorController, Door>("dc");
val.Invoke(__instance) = RandomPortal.DoorList[__instance];
if (RandomPortal.DoorList[__instance].deactivatedRooms.ToList().Count != 0)
{
Transform val2 = NearRoot(((Component)__instance).transform);
if (RandomPortal.DoorList[__instance].deactivatedRooms.ToList().Contains(((Component)val2).gameObject))
{
Add(ref RandomPortal.DoorList[__instance].activatedRooms, ((Component)val2).gameObject);
RemoveAt(ref RandomPortal.DoorList[__instance].deactivatedRooms, RandomPortal.DoorList[__instance].deactivatedRooms.ToList().IndexOf(((Component)val2).gameObject));
}
}
}
}
[HarmonyPatch(typeof(PortalManagerV2))]
public class RandomizePortals : MonoBehaviour
{
[CompilerGenerated]
private sealed class <SlowUpdate>d__1 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
private int <i>5__1;
private Transform <exitt>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SlowUpdate>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<exitt>5__2 = 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(5f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if (RandomPortal.Updated)
{
<i>5__1 = 0;
while (<i>5__1 < RandomPortal.Portals.Count)
{
if (!((Component)RandomPortal.Portals[<i>5__1].exit).gameObject.activeInHierarchy & ((Component)RandomPortal.Portals[<i>5__1].entry).gameObject.activeInHierarchy)
{
<exitt>5__2 = RandomPortal.Portals[<i>5__1].exit;
((Component)((Component)<exitt>5__2).transform).gameObject.SetActive(true);
EnableHierarchy(<exitt>5__2);
<exitt>5__2 = null;
}
RandomPortal.SlowUpdated = true;
int num = <i>5__1 + 1;
<i>5__1 = num;
}
CoroutineRunner.Instance.RunCoroutine(SlowUpdate());
}
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 GameObject CreateTrigger(Transform parent)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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)
GameObject val = Object.Instantiate<GameObject>(GameObject.CreatePrimitive((PrimitiveType)3), parent);
val.transform.localScale = Vector3.one;
val.transform.localPosition = new Vector3(0f, 5f, -2f);
val.transform.localRotation = Quaternion.Euler(0f, 270f, 0f);
val.GetComponent<Collider>().isTrigger = true;
val.layer = 16;
return val;
}
[IteratorStateMachine(typeof(<SlowUpdate>d__1))]
public static IEnumerator SlowUpdate()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SlowUpdate>d__1(0);
}
public static object ComponentExtent(Transform obj)
{
int num = 0;
Transform val = obj;
Component result = null;
do
{
if ((Object)(object)val != (Object)null)
{
if ((Object)(object)((Component)val).GetComponent<Door>() != (Object)null)
{
result = (Component)(object)((Component)val).GetComponent<Door>();
}
else
{
val = val.parent;
}
}
num++;
}
while (num <= 4);
return result;
}
public static void EnableHierarchy(Transform obj)
{
((Component)obj).gameObject.SetActive(true);
if ((Object)(object)obj.parent != (Object)(object)obj.root)
{
EnableHierarchy(obj.parent);
}
}
public static int CustomRand()
{
int num = 0;
if (RandomPortal.CurrentRand.Count == 0)
{
for (int i = 0; i < RandomPortal.Portals.Count; i++)
{
RandomPortal.CurrentRand.Add(i);
}
}
num = Random.Range(0, RandomPortal.CurrentRand.Count);
int result = RandomPortal.CurrentRand[num];
RandomPortal.CurrentRand[num] = RandomPortal.CurrentRand[RandomPortal.CurrentRand.Count - 1];
RandomPortal.CurrentRand.RemoveAt(RandomPortal.CurrentRand.Count - 1);
return result;
}
[HarmonyPatch("FixedUpdate")]
[HarmonyPostfix]
private static async void AutoRandomize(PortalManagerV2 __instance)
{
if (RandomPortal.SlowUpdated)
{
if (!Object.FindObjectsOfType<Portal>(true).Any())
{
return;
}
int i = 0;
while (i < RandomPortal.Portals.Count)
{
Door comp = (Door)ComponentExtent(RandomPortal.Portals[i].exit);
if (Object.op_Implicit((Object)(object)comp) & !RandomPortal.LastPortals.Contains(RandomPortal.Portals[i]))
{
RandomPortal.LastPortals.Add(RandomPortal.Portals[i]);
GameObject obj = CreateTrigger(RandomPortal.Portals[i].entry);
obj.transform.localPosition = new Vector3(0f, 0f, 0f);
GameObject obj2 = CreateTrigger(RandomPortal.Portals[i].exit);
obj2.transform.localPosition = new Vector3(0f, 0f, 0f);
Vector3 lossyScale = obj.transform.lossyScale;
Vector3 lossyScale2 = obj2.transform.lossyScale;
Vector3 globalScale = new Vector3(10f, 10f, 10f);
Vector3 scale = new Vector3(globalScale.x / lossyScale.x, globalScale.y / lossyScale.y, globalScale.z / lossyScale.z);
Vector3 scale2 = new Vector3(globalScale.x / lossyScale2.x, globalScale.y / lossyScale2.y, globalScale.z / lossyScale2.z);
obj.transform.localScale = scale;
obj2.transform.localScale = scale2;
DoorController comp2 = obj.AddComponent<DoorController>();
DoorController comp3 = obj2.AddComponent<DoorController>();
RandomPortal.DoorList.Add(comp2, comp);
RandomPortal.DoorList.Add(comp3, comp);
}
int num = i + 1;
i = num;
}
RandomPortal.SlowUpdated = false;
}
if (RandomPortal.Updated || !Object.FindObjectsOfType<Portal>(true).Any())
{
return;
}
int Rand = Random.Range(0, RandomPortal.Portals.Count - 1);
RandomPortal.Portals = Object.FindObjectsOfType<Portal>(true).ToList();
RandomPortal.Updated = true;
CoroutineRunner.Instance.RunCoroutine(SlowUpdate());
await Task.Run(delegate
{
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: Unknown result type (might be due to invalid IL or missing references)
//IL_0281: Unknown result type (might be due to invalid IL or missing references)
for (int j = 0; j < RandomPortal.Portals.Count; j++)
{
RandomPortal.CurrentRand.Clear();
for (int k = 0; k < RandomPortal.Portals.Count; k++)
{
RandomPortal.CurrentRand.Add(k);
}
bool flag = false;
bool flag2 = false;
if (RandomPortal.Portals[j].mirror)
{
break;
}
if (RandomPortal.PickedPortals.Contains(RandomPortal.Portals[Rand]) || RandomPortal.Portals[Rand].mirror || (Object)(object)((Component)RandomPortal.Portals[Rand]).transform.root != (Object)(object)((Component)RandomPortal.Portals[j]).transform.root || (Object)(object)RandomPortal.Portals[j] != (Object)(object)RandomPortal.Portals[Rand])
{
flag = true;
}
do
{
try
{
Rand = CustomRand();
if (RandomPortal.CurrentRand.Count != 0)
{
if ((!RandomPortal.PickedPortals.Contains(RandomPortal.Portals[Rand]) & !RandomPortal.Portals[Rand].mirror & ((Object)(object)((Component)RandomPortal.Portals[Rand]).transform.root == (Object)(object)((Component)RandomPortal.Portals[j]).transform.root) & ((Object)(object)RandomPortal.Portals[j] != (Object)(object)RandomPortal.Portals[Rand])) || RandomPortal.CurrentRand.Count == RandomPortal.Portals.Count)
{
flag = false;
}
continue;
}
flag = false;
flag2 = true;
}
catch
{
continue;
}
break;
}
while (flag);
if (!flag2)
{
Transform exit = RandomPortal.Portals[j].exit;
RandomPortal.Portals[j].exit = RandomPortal.Portals[Rand].exit;
RandomPortal.Portals[Rand].exit = exit;
RandomPortal.Portals[Rand].exitTravelFlags = RandomPortal.Portals[Rand].entryTravelFlags;
RandomPortal.Portals[j].exitTravelFlags = RandomPortal.Portals[j].entryTravelFlags;
RandomPortal.PickedPortals.Add(RandomPortal.Portals[j]);
RandomPortal.PickedPortals.Add(RandomPortal.Portals[Rand]);
RandomPortal.Portals[j].UpdateTransformData();
RandomPortal.Portals[Rand].UpdateTransformData();
}
}
});
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}