Decompiled source of Portal Warning v0.3.0
BepInEx/plugins/PortalWarning/PortalWarning.dll
Decompiled 19 hours ago
The result has been truncated due to the large size, download it to view full contents!
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.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using ExitGames.Client.Photon; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using Photon.Realtime; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; using UnityEngine.SceneManagement; using Zorro.Core; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("PortalWarning")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.3.0.0")] [assembly: AssemblyInformationalVersion("0.3.0")] [assembly: AssemblyProduct("PortalWarning")] [assembly: AssemblyTitle("PortalWarning")] [assembly: AssemblyVersion("0.3.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 PortalWarning { internal static class GameAccess { private static readonly FieldRef<PlayerRagdoll, List<Rigidbody>> BodiesField = AccessTools.FieldRefAccess<PlayerRagdoll, List<Rigidbody>>("rigList"); private static readonly FieldRef<PlayerRagdoll, Collider[]> CollidersField = AccessTools.FieldRefAccess<PlayerRagdoll, Collider[]>("colliders"); private static readonly FieldRef<Bodypart, Rigidbody> BodyRig = AccessTools.FieldRefAccess<Bodypart, Rigidbody>("rig"); private static readonly Func<PlayerRagdoll, BodypartType, Bodypart> BodyMethod = AccessTools.MethodDelegate<Func<PlayerRagdoll, BodypartType, Bodypart>>(AccessTools.Method(typeof(PlayerRagdoll), "GetBodypart", (Type[])null, (Type[])null), (object)null, true); private static readonly Func<Vector3, Vector3> LookMethod = AccessTools.MethodDelegate<Func<Vector3, Vector3>>(AccessTools.Method(typeof(HelperFunctions), "DirectionToLook", (Type[])null, (Type[])null), (object)null, true); internal static List<Rigidbody> Bodies(PlayerRagdoll ragdoll) { return BodiesField.Invoke(ragdoll); } internal static Collider[] Colliders(PlayerRagdoll ragdoll) { return CollidersField.Invoke(ragdoll); } internal static Rigidbody Hip(Player p) { return BodyRig.Invoke(BodyMethod(p.refs.ragdoll, (BodypartType)0)); } internal static Bodypart Body(PlayerRagdoll ragdoll, BodypartType type) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return BodyMethod(ragdoll, type); } internal static Vector2 Look(Vector3 direction) { //IL_0005: 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_000b: Unknown result type (might be due to invalid IL or missing references) return Vector2.op_Implicit(LookMethod(direction)); } } internal static class LocalPortalModel { private sealed class Vpk { private struct Entry { internal byte[] Preload; internal ushort Archive; internal uint Offset; internal uint Size; } private readonly Dictionary<string, Entry> entries = new Dictionary<string, Entry>(); private readonly string filename; private readonly int dataStart; internal Vpk(string path) { filename = path; byte[] array = File.ReadAllBytes(path); if (I(array, 0) != 1437209140) { throw new InvalidDataException("Invalid VPK"); } int p = ((I(array, 4) == 2) ? 28 : 12); dataStart = p + I(array, 8); while (true) { string text = String(array, ref p); if (text.Length == 0) { break; } while (true) { string text2 = String(array, ref p); if (text2.Length == 0) { break; } while (true) { string text3 = String(array, ref p); if (text3.Length == 0) { break; } int num = U(array, p + 4); Entry value = new Entry { Archive = U(array, p + 6), Offset = BitConverter.ToUInt32(array, p + 8), Size = BitConverter.ToUInt32(array, p + 12), Preload = new byte[num] }; p += 18; Buffer.BlockCopy(array, p, value.Preload, 0, num); p += num; entries[((text2 == " ") ? "" : (text2 + "/")) + text3 + "." + text] = value; } } } } internal byte[] Read(string name) { if (!entries.TryGetValue(name, out var value)) { throw new FileNotFoundException(name); } if (value.Size > 33554432) { throw new InvalidDataException("Unexpected asset size"); } byte[] array = new byte[value.Preload.Length + value.Size]; value.Preload.CopyTo(array, 0); using FileStream fileStream = File.OpenRead((value.Archive == 32767) ? filename : filename.Replace("_dir.vpk", "_" + value.Archive.ToString("000") + ".vpk")); fileStream.Position = value.Offset + ((value.Archive == 32767) ? dataStart : 0); int num; for (int i = value.Preload.Length; i < array.Length; i += num) { num = fileStream.Read(array, i, array.Length - i); if (num == 0) { throw new EndOfStreamException(); } } return array; } private static string String(byte[] b, ref int p) { int num = p; while (b[p] != 0) { p++; } return Encoding.UTF8.GetString(b, num, p++ - num); } } internal static Mesh Mesh; internal static Material Material; internal static bool Loaded; internal static string Source = "Original fallback"; internal static bool Load(string configured) { //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_048c: Unknown result type (might be due to invalid IL or missing references) //IL_0491: Unknown result type (might be due to invalid IL or missing references) //IL_04a1: Expected O, but got Unknown //IL_04e5: Unknown result type (might be due to invalid IL or missing references) //IL_04ea: Unknown result type (might be due to invalid IL or missing references) //IL_04ee: Unknown result type (might be due to invalid IL or missing references) //IL_04f3: Unknown result type (might be due to invalid IL or missing references) //IL_0504: Unknown result type (might be due to invalid IL or missing references) //IL_0509: Unknown result type (might be due to invalid IL or missing references) //IL_050b: Unknown result type (might be due to invalid IL or missing references) //IL_0510: Unknown result type (might be due to invalid IL or missing references) //IL_054b: Unknown result type (might be due to invalid IL or missing references) //IL_05e1: Unknown result type (might be due to invalid IL or missing references) //IL_05e6: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Unknown result type (might be due to invalid IL or missing references) //IL_05ef: Unknown result type (might be due to invalid IL or missing references) try { string text = FindPortal(configured); if (text == null) { return false; } Vpk vpk = new Vpk(Path.Combine(text, "portal", "portal_pak_dir.vpk")); byte[] b = vpk.Read("models/weapons/w_portalgun.mdl"); byte[] b2 = vpk.Read("models/weapons/w_portalgun.vvd"); byte[] array = vpk.Read("models/weapons/w_portalgun.dx90.vtx"); if (I(b, 0) != 1414743113 || I(b, 4) != 44 || I(b2, 4) != 4 || I(array, 0) != 7 || I(b, 8) != I(b2, 8) || I(b, 8) != I(array, 16)) { throw new InvalidDataException("Unsupported or mismatched Portal model version"); } int num = I(b2, 16); int num2 = I(b2, 56); if (num < 1 || num > 100000) { throw new InvalidDataException("Invalid vertex count"); } Vector3[] array2 = (Vector3[])(object)new Vector3[num]; Vector3[] array3 = (Vector3[])(object)new Vector3[num]; Vector2[] array4 = (Vector2[])(object)new Vector2[num]; List<int> list = new List<int>(); int num3 = I(b2, 48); int num4 = I(b2, 52); if (num3 == 0) { for (int i = 0; i < num; i++) { list.Add(i); } } else { for (int j = 0; j < num3; j++) { int num5 = num4 + j * 12; for (int k = 0; k < I(b2, num5 + 8); k++) { list.Add(I(b2, num5 + 4) + k); } } } if (list.Count != num) { throw new InvalidDataException("Invalid vertex fixups"); } for (int l = 0; l < num; l++) { int num6 = num2 + list[l] * 48; array2[l] = Map(new Vector3(F(b2, num6 + 16), F(b2, num6 + 20), F(b2, num6 + 24))) * 0.0254f; array3[l] = Map(new Vector3(F(b2, num6 + 28), F(b2, num6 + 32), F(b2, num6 + 36))); array4[l] = new Vector2(F(b2, num6 + 40), F(b2, num6 + 44)); } List<int> list2 = new List<int>(); int num7 = I(b, 236); int num8 = I(array, 32); for (int m = 0; m < I(b, 232); m++) { int num9 = num7 + m * 16; int num10 = num8 + m * 8; int num11 = num9 + I(b, num9 + 12); int num12 = num10 + I(array, num10 + 4); int num13 = num12 + I(array, num12 + 4); for (int n = 0; n < I(b, num11 + 72); n++) { int num14 = num11 + I(b, num11 + 76) + n * 116; int num15 = num13 + I(array, num13 + 4) + n * 9; int baseVertex = I(b, num11 + 84) / 48 + I(b, num14 + 12); for (int num16 = 0; num16 < I(array, num15); num16++) { int num17 = num15 + I(array, num15 + 4) + num16 * 25; int verts = num17 + I(array, num17 + 4); int ids = num17 + I(array, num17 + 12); for (int num18 = 0; num18 < I(array, num17 + 16); num18++) { int num19 = num17 + I(array, num17 + 20) + num18 * 27; int num20 = I(array, num19); int num21 = I(array, num19 + 4); bool flag = (array[num19 + 18] & 1) != 0; for (int num22 = 0; num22 < (flag ? num20 : (num20 - 2)); num22 += ((!flag) ? 1 : 3)) { int num23 = Index(array, ids, verts, num21 + num22, baseVertex); int num24 = Index(array, ids, verts, num21 + num22 + 2, baseVertex); int num25 = Index(array, ids, verts, num21 + num22 + 1, baseVertex); if (!flag && (num22 & 1) != 0) { int num26 = num23; num23 = num25; num25 = num26; } if (num23 != num25 && num23 != num24 && num25 != num24) { list2.Add(num23); list2.Add(num25); list2.Add(num24); } } } } } } Mesh = new Mesh { name = "Portal official world portal gun (local read only)" }; Mesh.vertices = array2; Mesh.normals = array3; Mesh.uv = array4; Mesh.triangles = list2.ToArray(); Mesh.RecalculateBounds(); Bounds bounds = Mesh.bounds; Vector3 center = ((Bounds)(ref bounds)).center; for (int num27 = 0; num27 < array2.Length; num27++) { ref Vector3 reference = ref array2[num27]; reference -= center; } Mesh.vertices = array2; Mesh.RecalculateBounds(); Texture2D val = Texture(vpk.Read("materials/models/weapons/w_models/portalgun/w_portalgun.vtf")); Material = Visuals.Material(Color.white); Material.mainTexture = (Texture)(object)val; if (Material.HasProperty("_BaseMap")) { Material.SetTexture("_BaseMap", (Texture)(object)val); } Loaded = true; Source = "Official Portal model from local installation"; Plugin instance = Plugin.Instance; string[] obj = new string[6] { "Loaded official Portal gun: ", num.ToString(), " vertices, ", (list2.Count / 3).ToString(), " triangles, bounds ", null }; bounds = Mesh.bounds; obj[5] = ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString(); instance.LogItem(string.Concat(obj)); return true; } catch (Exception ex) { Plugin.Instance.Warn("Local Portal model unavailable: " + ex.Message + ". Using original fallback."); return false; } } private static Vector3 Map(Vector3 v) { //IL_0000: 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) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Vector3(0f - v.y, v.x, 0f - v.z); } private static int Index(byte[] v, int ids, int verts, int i, int baseVertex) { return baseVertex + U(v, verts + U(v, ids + i * 2) * 9 + 4); } private static int I(byte[] b, int p) { return BitConverter.ToInt32(b, p); } private static ushort U(byte[] b, int p) { return BitConverter.ToUInt16(b, p); } private static float F(byte[] b, int p) { return BitConverter.ToSingle(b, p); } private static Texture2D Texture(byte[] b) { //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Expected O, but got Unknown if (I(b, 0) != 4609110) { throw new InvalidDataException("Invalid VTF texture"); } int num = U(b, 16); int num2 = U(b, 18); int num3 = I(b, 52); int num4 = b[56]; int num5 = I(b, 12); int num6 = U(b, 24); if (num3 != 13 && num3 != 15) { throw new InvalidDataException("Unsupported VTF compression"); } int num7 = ((num3 == 13) ? 8 : 16); if (I(b, 8) >= 3) { for (int i = 0; i < I(b, 68); i++) { int num8 = 80 + i * 8; if (b[num8] == 48 && b[num8 + 1] == 0 && b[num8 + 2] == 0) { num5 = I(b, num8 + 4); } } } else { num5 += Math.Max(1, (b[61] + 3) / 4) * Math.Max(1, (b[62] + 3) / 4) * 8; } for (int num9 = num4 - 1; num9 > 0; num9--) { num5 += Math.Max(1, ((num >> num9) + 3) / 4) * Math.Max(1, ((num2 >> num9) + 3) / 4) * num7 * num6; } int num10 = Math.Max(1, (num + 3) / 4) * Math.Max(1, (num2 + 3) / 4) * num7; byte[] array = new byte[num10]; Buffer.BlockCopy(b, num5, array, 0, num10); Texture2D val = new Texture2D(num, num2, (TextureFormat)((num3 == 13) ? 10 : 12), false) { name = "Portal local gun texture" }; val.LoadRawTextureData(array); val.Apply(false, true); return val; } private static string FindPortal(string configured) { if (!string.IsNullOrWhiteSpace(configured)) { return configured; } List<string> list = new List<string> { Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Steam") }; string path = Path.Combine(list[0], "steamapps", "libraryfolders.vdf"); if (File.Exists(path)) { foreach (Match item in Regex.Matches(File.ReadAllText(path), "\"path\"\\s*\"([^\"]+)\"")) { list.Add(item.Groups[1].Value.Replace("\\\\", "\\")); } } foreach (string item2 in list) { string text = Path.Combine(item2, "steamapps", "common", "Portal"); if (File.Exists(Path.Combine(text, "portal", "portal_pak_dir.vpk"))) { return text; } } return null; } } [BepInPlugin("peter.portalwarning", "Portal Warning", "0.3.0")] [ContentWarningPlugin("peter.portalwarning", "0.3.0", false)] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "peter.portalwarning"; public const string Version = "0.3.0"; internal static Plugin Instance; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> LiveViews; internal static ConfigEntry<bool> ShowHud; internal static ConfigEntry<bool> ShowDevice; internal static ConfigEntry<Key> ClearKey; internal static ConfigEntry<string> PortalInstallDirectory; internal static ConfigEntry<int> ViewResolution; internal PortalSystem Portals; internal PortalHud Hud; internal PortalDevice Device; internal string Status = "Place both portals to link them"; internal float StatusUntil; private Harmony harmony; private int lastScene; internal bool DeviceActive => PortalGunItem.Equipped(Player.localPlayer); internal static Camera Cam { get { if (!Object.op_Implicit((Object)(object)MainCamera.instance)) { return Camera.main; } return MainCamera.instance.Cam; } } private void Awake() { //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) Instance = this; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable Portal Warning. Restart after changing this setting."); LiveViews = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "LivePortalViews", true, "Render a live view through each linked portal. Disable on slow GPUs."); ViewResolution = ((BaseUnityPlugin)this).Config.Bind<int>("Visuals", "PortalViewResolution", 512, "Long edge of each portal render texture (128 to 1024)."); ShowHud = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "ShowHud", true, "Show the blue/orange reticle and portal status."); ShowDevice = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "ShowDevice", true, "Show the actual held portal gun in first person. Other players' equipped guns remain visible."); PortalInstallDirectory = ((BaseUnityPlugin)this).Config.Bind<string>("Visuals", "PortalInstallDirectory", "", "Optional Portal installation directory. Blank automatically searches Steam libraries. Reads the official model locally; does not modify game files."); ClearKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "ClearPortals", (Key)32, "Clear your paired portals while the portal device is active."); if (Enabled.Value) { Portals = new PortalSystem(this); Hud = new PortalHud(this); Device = new PortalDevice(this); harmony = new Harmony("peter.portalwarning"); harmony.PatchAll(typeof(Plugin).Assembly); LocalPortalModel.Load(PortalInstallDirectory.Value); PortalGunItem.Register(); ((MonoBehaviour)this).StartCoroutine(RenderViews()); Scene activeScene = SceneManager.GetActiveScene(); lastScene = ((Scene)(ref activeScene)).handle; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Portal Warning 0.3.0 loaded. Pick up Portal Gun beside camera; select its inventory slot to fire."); } } private IEnumerator RenderViews() { WaitForEndOfFrame wait = new WaitForEndOfFrame(); while (true) { yield return wait; if (Portals != null) { Portals.RenderViews(); } } } private void Update() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) if (Portals == null) { return; } int num = lastScene; Scene activeScene = SceneManager.GetActiveScene(); if (num != ((Scene)(ref activeScene)).handle) { activeScene = SceneManager.GetActiveScene(); lastScene = ((Scene)(ref activeScene)).handle; Portals.ResetScene(); Device.Destroy(); } Portals.NetworkTick(); Player localPlayer = Player.localPlayer; if (!Ready(localPlayer) || !DeviceActive) { Portals.Drop(); } if (!Ready(localPlayer)) { return; } if (CanPlay(localPlayer) && Keyboard.current != null && DeviceActive && ((ButtonControl)Keyboard.current[ClearKey.Value]).wasPressedThisFrame) { Portals.ClearOwn(); } if (CanPlay(localPlayer) && DeviceActive && Mouse.current != null) { if (Mouse.current.leftButton.wasPressedThisFrame) { Portals.Shoot(0); } if (Mouse.current.rightButton.wasPressedThisFrame) { Portals.Shoot(1); } if (Mouse.current.middleButton.wasPressedThisFrame) { Portals.GrabOrDrop(); } } } private void FixedUpdate() { if (Portals != null) { Portals.PhysicsTick(); } } private void LateUpdate() { if (Portals != null) { Portals.VisualTick(); Device.Tick(); } } private void OnGUI() { if (Hud != null) { Hud.Draw(); } } private void OnDestroy() { if (harmony != null) { harmony.UnpatchSelf(); } if (Portals != null) { Portals.Dispose(); } if (Device != null) { Device.Destroy(); } Instance = null; } internal void Notify(string s) { Status = s; StatusUntil = Time.unscaledTime + 3f; ((BaseUnityPlugin)this).Logger.LogInfo((object)s); } internal void Warn(string s) { ((BaseUnityPlugin)this).Logger.LogWarning((object)s); } internal void LogItem(string s) { ((BaseUnityPlugin)this).Logger.LogInfo((object)s); } internal static bool Ready(Player p) { if (Object.op_Implicit((Object)(object)p) && p.data != null && p.refs != null && p.data.playerSetUpAndReady && p.data.physicsAreReady && Object.op_Implicit((Object)(object)p.refs.ragdoll) && Object.op_Implicit((Object)(object)p.refs.view)) { return p.refs.view.IsMine; } return false; } internal static bool CanPlay(Player p) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Invalid comparison between Unknown and I4 if (Ready(p) && !p.data.dead && !p.data.hookedIntoTerminal && !Object.op_Implicit((Object)(object)p.data.currentBed) && !Object.op_Implicit((Object)(object)p.data.currentSeat) && !p.HasLockedInput() && !p.HasLockedMovement() && !Ragdoll(p)) { return (int)Cursor.lockState == 1; } return false; } internal static bool Ragdoll(Player p) { if (Object.op_Implicit((Object)(object)p) && !p.data.dead) { return p.data.fallTime > 0f; } return true; } internal static Rigidbody Hip(Player p) { return GameAccess.Hip(p); } } public sealed class PortalMarker : MonoBehaviour { } internal sealed class Portal : IDisposable { internal readonly PortalPair Pair; internal readonly int ColorIndex; internal readonly Vector3 Position; internal readonly Quaternion Rotation; internal readonly List<Collider> Surfaces; internal readonly GameObject Root; private readonly Mesh mesh; private readonly Vector3[] vertices; private readonly Vector2[] uv; private readonly MeshRenderer face; private readonly Material faceMaterial; private readonly Material rimMaterial; private readonly Texture2D idleTexture; private readonly LineRenderer rim; private Camera viewCamera; private RenderTexture texture; private bool renderFailed; private bool rendered; private float nextRender; internal static Color BlueColor = new Color(0.12f, 0.66f, 1f); internal static Color OrangeColor = new Color(1f, 0.47f, 0.08f); internal Vector3 Normal => Rotation * Vector3.forward; internal Vector3 Up => Rotation * Vector3.up; internal Vector3 Right => Rotation * Vector3.right; internal bool ViewRendered => rendered; internal Portal(PortalPair pair, int color, Vector3 point, Quaternion rotation, List<Collider> surfaces) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_005c: 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_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Expected O, but got Unknown //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_031b: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) Pair = pair; ColorIndex = color; Position = point; Rotation = rotation; Surfaces = surfaces; Root = new GameObject((color == 0) ? "PortalWarning_Blue" : "PortalWarning_Orange"); Root.AddComponent<PortalMarker>(); Root.transform.SetPositionAndRotation(point, rotation); Color val = ((color == 0) ? BlueColor : OrangeColor); faceMaterial = Visuals.Material(Color.white); rimMaterial = Visuals.Material(val * 1.4f); mesh = new Mesh { name = "PortalWarning aperture" }; vertices = (Vector3[])(object)new Vector3[81]; uv = (Vector2[])(object)new Vector2[81]; int[] array = new int[480]; for (int i = 0; i < 80; i++) { float num = (float)i * MathF.PI * 2f / 80f; vertices[i + 1] = new Vector3(Mathf.Cos(num) * 0.8f, Mathf.Sin(num) * 1.35f, 0f); uv[i + 1] = new Vector2(Mathf.Cos(num) * 0.5f + 0.5f, Mathf.Sin(num) * 0.5f + 0.5f); int num2 = (i + 1) % 80 + 1; array[i * 6] = 0; array[i * 6 + 1] = i + 1; array[i * 6 + 2] = num2; array[i * 6 + 3] = 0; array[i * 6 + 4] = num2; array[i * 6 + 5] = i + 1; } uv[0] = new Vector2(0.5f, 0.5f); mesh.vertices = vertices; mesh.uv = uv; mesh.triangles = array; mesh.RecalculateNormals(); mesh.RecalculateBounds(); Root.AddComponent<MeshFilter>().sharedMesh = mesh; face = Root.AddComponent<MeshRenderer>(); ((Renderer)face).sharedMaterial = faceMaterial; ((Renderer)face).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)face).receiveShadows = false; idleTexture = Visuals.Swirl(val); faceMaterial.mainTexture = (Texture)(object)idleTexture; GameObject val2 = new GameObject("Rim"); val2.transform.SetParent(Root.transform, false); rim = val2.AddComponent<LineRenderer>(); rim.useWorldSpace = false; rim.loop = true; rim.positionCount = 80; rim.widthMultiplier = 0.065f; ((Renderer)rim).sharedMaterial = rimMaterial; ((Renderer)rim).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)rim).receiveShadows = false; for (int j = 0; j < 80; j++) { rim.SetPosition(j, vertices[j + 1] + Vector3.forward * 0.006f); } Light obj = Root.AddComponent<Light>(); obj.type = (LightType)2; obj.color = val; obj.range = 3f; obj.intensity = 1.5f; obj.shadows = (LightShadows)0; } internal Vector3 Local(Vector3 point) { //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_000b: 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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) return Quaternion.Inverse(Rotation) * (point - Position); } internal bool Contains(Vector3 point, float margin) { //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_0007: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Local(point); float num = val.x / Mathf.Max(0.1f, 0.8f - margin); float num2 = val.y / Mathf.Max(0.1f, 1.35f - margin); return num * num + num2 * num2 <= 1f; } internal Vector3 MapPoint(Portal source, Vector3 point) { //IL_0001: 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) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) return Position + Rotation * (Quaternion.Euler(0f, 180f, 0f) * (Quaternion.Inverse(source.Rotation) * (point - source.Position))); } internal void Tick() { //IL_0093: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)Root)) { float num = 1f + Mathf.Sin(Time.time * 4f + (float)ColorIndex) * 0.08f; rim.widthMultiplier = 0.065f * num; if (!Pair.Linked || !Plugin.LiveViews.Value || renderFailed) { faceMaterial.mainTexture = (Texture)(object)idleTexture; faceMaterial.mainTextureOffset = new Vector2(Time.time * 0.035f, Time.time * 0.02f); } } } internal void Render(Camera source) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: 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_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_0203: 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_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Expected O, but got Unknown //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_030f: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_035a: Unknown result type (might be due to invalid IL or missing references) //IL_038d: Unknown result type (might be due to invalid IL or missing references) //IL_0392: Unknown result type (might be due to invalid IL or missing references) //IL_03a0: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)Root) || !Object.op_Implicit((Object)(object)source) || renderFailed || !Pair.Linked || Time.unscaledTime < nextRender) { return; } nextRender = Time.unscaledTime + 0.025f; if (Vector3.Dot(Normal, ((Component)source).transform.position - Position) < 0.02f) { return; } Vector3 val = source.WorldToViewportPoint(Position); if (val.z <= 0f || val.x < -0.8f || val.x > 1.8f || val.y < -1f || val.y > 2f) { return; } try { Portal portal = Pair.Other(this); if (!Object.op_Implicit((Object)(object)viewCamera)) { GameObject val2 = new GameObject("PortalWarning_View"); val2.transform.SetParent(Root.transform, false); viewCamera = val2.AddComponent<Camera>(); ((Behaviour)viewCamera).enabled = false; UniversalAdditionalCameraData obj = val2.AddComponent<UniversalAdditionalCameraData>(); obj.renderPostProcessing = false; obj.renderShadows = true; obj.requiresColorOption = (CameraOverrideOption)0; obj.requiresDepthOption = (CameraOverrideOption)0; int value = Plugin.ViewResolution.Value; texture = new RenderTexture(value, Mathf.Max(64, Mathf.RoundToInt((float)value / source.aspect)), 24, (RenderTextureFormat)0); ((Object)texture).name = "PortalWarning live view"; texture.Create(); } viewCamera.CopyFrom(source); ((Behaviour)viewCamera).enabled = false; viewCamera.targetTexture = texture; viewCamera.stereoTargetEye = (StereoTargetEyeMask)0; ((Component)viewCamera).transform.position = portal.MapPoint(this, ((Component)source).transform.position); ((Component)viewCamera).transform.rotation = portal.Rotation * Quaternion.Euler(0f, 180f, 0f) * Quaternion.Inverse(Rotation) * ((Component)source).transform.rotation; viewCamera.nearClipPlane = 0.03f; viewCamera.projectionMatrix = source.projectionMatrix; Vector3 val3 = portal.Position + portal.Normal * 0.04f; Matrix4x4 worldToCameraMatrix = viewCamera.worldToCameraMatrix; Vector3 val4 = ((Matrix4x4)(ref worldToCameraMatrix)).MultiplyPoint(val3); worldToCameraMatrix = viewCamera.worldToCameraMatrix; Vector3 val5 = ((Matrix4x4)(ref worldToCameraMatrix)).MultiplyVector(portal.Normal); Vector3 normalized = ((Vector3)(ref val5)).normalized; Vector4 val6 = default(Vector4); ((Vector4)(ref val6))..ctor(normalized.x, normalized.y, normalized.z, 0f - Vector3.Dot(val4, normalized)); viewCamera.projectionMatrix = viewCamera.CalculateObliqueMatrix(val6); for (int i = 0; i < vertices.Length; i++) { Vector3 val7 = source.WorldToViewportPoint(Root.transform.TransformPoint(vertices[i])); uv[i] = new Vector2(val7.x, val7.y); } mesh.uv = uv; faceMaterial.mainTextureOffset = Vector2.zero; ((Renderer)face).enabled = false; ((Renderer)portal.face).enabled = false; bool active = Plugin.Instance.Device.HideForCapture(); try { SingleCameraRequest val8 = new SingleCameraRequest { destination = texture }; if (RenderPipeline.SupportsRenderRequest<SingleCameraRequest>(viewCamera, val8)) { RenderPipeline.SubmitRenderRequest<SingleCameraRequest>(viewCamera, val8); } else { if (!((Object)(object)GraphicsSettings.currentRenderPipeline == (Object)null)) { throw new InvalidOperationException("The current render pipeline does not support portal render requests."); } viewCamera.Render(); } rendered = true; } finally { ((Renderer)face).enabled = true; if (Object.op_Implicit((Object)(object)portal.Root)) { ((Renderer)portal.face).enabled = true; } Plugin.Instance.Device.RestoreAfterCapture(active); } faceMaterial.mainTexture = (Texture)(object)texture; } catch (Exception ex) { renderFailed = true; Plugin.Instance.Warn("Live portal view disabled for this portal: " + ex.Message); } } public void Dispose() { if (Object.op_Implicit((Object)(object)texture)) { texture.Release(); Object.Destroy((Object)(object)texture); } Object.Destroy((Object)(object)faceMaterial); Object.Destroy((Object)(object)rimMaterial); Object.Destroy((Object)(object)mesh); Object.Destroy((Object)(object)idleTexture); if (Object.op_Implicit((Object)(object)Root)) { Object.Destroy((Object)(object)Root); } } } internal static class Visuals { internal static Material Material(Color color) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0040: 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) Shader obj = Shader.Find("Universal Render Pipeline/Unlit") ?? Shader.Find("Unlit/Texture") ?? Shader.Find("Sprites/Default"); if (!Object.op_Implicit((Object)(object)obj)) { throw new InvalidOperationException("No unlit shader is available."); } Material val = new Material(obj); val.color = color; if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", color); } if (val.HasProperty("_Cull")) { val.SetFloat("_Cull", 0f); } return val; } internal static Texture2D Swirl(Color tint) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: 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) Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false); Color[] array = (Color[])(object)new Color[16384]; for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { float num = ((float)j - 64f) / 64f; float num2 = ((float)i - 64f) / 64f; float num3 = Mathf.Sqrt(num * num + num2 * num2); float num4 = Mathf.Sin(Mathf.Atan2(num2, num) * 4f + num3 * 20f) * 0.5f + 0.5f; array[i * 128 + j] = Color.Lerp(new Color(0.006f, 0.014f, 0.025f), tint, (0.1f + 0.25f * num4) * Mathf.Clamp01(num3 + 0.3f)); } } val.SetPixels(array); val.Apply(); return val; } } internal static class PortalAudio { private static readonly Dictionary<string, AudioClip> clips = new Dictionary<string, AudioClip>(); internal static void Play(Vector3 pos, float frequency, float duration) { //IL_00d7: Unknown result type (might be due to invalid IL or missing references) string key = frequency + ":" + duration; if (!clips.TryGetValue(key, out var value)) { float[] array = new float[(int)(duration * 22050f)]; for (int i = 0; i < array.Length; i++) { float num = (float)i / 22050f; float num2 = (float)i / (float)array.Length; float num3 = MathF.PI * 2f * (frequency * num + frequency * 1.3f * num * num); array[i] = (Mathf.Sin(num3) * 0.6f + Mathf.Sin(num3 * 1.501f) * 0.2f) * Mathf.Sin(num2 * MathF.PI) * 0.2f; } value = AudioClip.Create("PortalWarning synthesized tone", array.Length, 1, 22050, false); value.SetData(array, 0); clips[key] = value; } AudioSource.PlayClipAtPoint(value, pos, 0.45f); } } internal sealed class PortalDevice { private readonly Plugin plugin; private GameObject root; private readonly List<Material> materials = new List<Material>(); private Material core; private ItemInstance hiddenItem; internal PortalDevice(Plugin p) { plugin = p; } private void Create(Camera camera) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: 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_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0191: 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_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) root = new GameObject("PortalWarning portal gun visual"); if (Object.op_Implicit((Object)(object)camera)) { root.transform.SetParent(((Component)camera).transform, false); } if (LocalPortalModel.Loaded) { root.AddComponent<MeshFilter>().sharedMesh = LocalPortalModel.Mesh; MeshRenderer obj = root.AddComponent<MeshRenderer>(); ((Renderer)obj).sharedMaterial = LocalPortalModel.Material; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)obj).receiveShadows = false; return; } root.transform.localScale = Vector3.one * 0.58f; Material material = NewMaterial(new Color(0.88f, 0.9f, 0.91f)); Material material2 = NewMaterial(new Color(0.055f, 0.065f, 0.085f)); core = NewMaterial(Portal.BlueColor); Part("Housing", (PrimitiveType)1, new Vector3(0f, 0f, 0f), new Vector3(0.23f, 0.23f, 0.36f), new Vector3(90f, 0f, 0f), material); Part("Barrel", (PrimitiveType)2, new Vector3(0f, 0f, 0.21f), new Vector3(0.14f, 0.12f, 0.14f), new Vector3(90f, 0f, 0f), material2); Part("Energy core", (PrimitiveType)0, new Vector3(0f, 0.11f, 0.04f), new Vector3(0.075f, 0.075f, 0.18f), Vector3.zero, core); Part("Grip", (PrimitiveType)3, new Vector3(0f, -0.14f, -0.07f), new Vector3(0.1f, 0.17f, 0.12f), new Vector3(-15f, 0f, 0f), material2); Part("Sight", (PrimitiveType)3, new Vector3(0f, 0.14f, 0.15f), new Vector3(0.045f, 0.045f, 0.04f), Vector3.zero, material2); for (int i = 0; i < 3; i++) { float num = (float)i * MathF.PI * 2f / 3f; Part("Emitter arm", (PrimitiveType)3, new Vector3(Mathf.Cos(num) * 0.095f, Mathf.Sin(num) * 0.095f, 0.32f), new Vector3(0.025f, 0.025f, 0.2f), Vector3.zero, material2); Part("Emitter tip", (PrimitiveType)0, new Vector3(Mathf.Cos(num) * 0.07f, Mathf.Sin(num) * 0.07f, 0.42f), Vector3.one * 0.028f, Vector3.zero, core); } } internal static void BuildModel(Transform parent) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) PortalDevice portalDevice = new PortalDevice(null); portalDevice.Create(null); portalDevice.root.transform.SetParent(parent, false); if (LocalPortalModel.Loaded) { portalDevice.root.transform.localRotation = Quaternion.Euler(0f, 0f, 180f); } } private Material NewMaterial(Color c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) Material val = Visuals.Material(c); materials.Add(val); return val; } private void Part(string name, PrimitiveType type, Vector3 pos, Vector3 scale, Vector3 rotation, Material material) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) GameObject obj = GameObject.CreatePrimitive(type); ((Object)obj).name = name; obj.transform.SetParent(root.transform, false); obj.transform.localPosition = pos; obj.transform.localRotation = Quaternion.Euler(rotation); obj.transform.localScale = scale; Object.Destroy((Object)(object)obj.GetComponent<Collider>()); Renderer component = obj.GetComponent<Renderer>(); component.sharedMaterial = material; component.shadowCastingMode = (ShadowCastingMode)0; component.receiveShadows = false; } internal void Tick() { Player localPlayer = Player.localPlayer; ItemInstance val = (PortalGunItem.Equipped(localPlayer) ? localPlayer.data.currentItem : null); if ((Object)(object)hiddenItem != (Object)(object)val) { if (Object.op_Implicit((Object)(object)hiddenItem)) { Renderer[] componentsInChildren = ((Component)hiddenItem).GetComponentsInChildren<Renderer>(); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = true; } } hiddenItem = val; } if (Object.op_Implicit((Object)(object)hiddenItem)) { Renderer[] componentsInChildren = ((Component)hiddenItem).GetComponentsInChildren<Renderer>(); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = Plugin.ShowDevice.Value; } } } internal void Fire(int color) { } internal bool HideForCapture() { return false; } internal void RestoreAfterCapture(bool active) { } internal void Destroy() { if (Object.op_Implicit((Object)(object)root)) { Object.Destroy((Object)(object)root); } foreach (Material material in materials) { if (Object.op_Implicit((Object)(object)material)) { Object.Destroy((Object)(object)material); } } materials.Clear(); root = null; } } public sealed class PortalGunAttachment : ItemInstanceBehaviour { private Player owner; private Transform visual; private Transform grip; private Quaternion modelRotation; private Collider[] heldColliders; internal float VisualGripError; public override void ConfigItem(ItemInstanceData data, PhotonView playerView) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) if (!base.isHeld || !Object.op_Implicit((Object)(object)playerView)) { return; } owner = ((Component)playerView).GetComponent<Player>(); visual = ((Component)this).transform.Find("PortalWarning portal gun visual"); grip = ((Component)((Component)this).GetComponentInChildren<HandGizmo>()).transform; modelRotation = visual.localRotation; heldColliders = ((Component)this).GetComponentsInChildren<Collider>(); if (!Object.op_Implicit((Object)(object)owner) || !Object.op_Implicit((Object)(object)owner.refs.ragdoll)) { return; } Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(); foreach (Collider val in componentsInChildren) { Collider[] array = GameAccess.Colliders(owner.refs.ragdoll); foreach (Collider val2 in array) { if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val2) && (Object)(object)val != (Object)(object)val2) { Physics.IgnoreCollision(val, val2, true); } } } } private void FixedUpdate() { if (!base.isHeld || heldColliders == null) { return; } Collider[] array = heldColliders; foreach (Collider val in array) { if (Object.op_Implicit((Object)(object)val)) { val.enabled = false; } } } private void LateUpdate() { //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: 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_00ce: Unknown result type (might be due to invalid IL or missing references) if (base.isHeld && Object.op_Implicit((Object)(object)owner) && Object.op_Implicit((Object)(object)visual) && Object.op_Implicit((Object)(object)grip) && Object.op_Implicit((Object)(object)owner.refs.ragdoll)) { Transform transform = ((Component)GameAccess.Body(owner.refs.ragdoll, (BodypartType)10)).transform; Quaternion val = transform.rotation * Quaternion.Inverse(grip.localRotation); Vector3 val2 = transform.position - val * grip.localPosition; visual.SetPositionAndRotation(val2, val * modelRotation); VisualGripError = Vector3.Distance(val2 + val * grip.localPosition, transform.position); } } } internal static class PortalGunItem { internal static Item Definition; internal static GameObject Template; internal static bool Equipped(Player p) { if (Object.op_Implicit((Object)(object)p) && p.data != null && Object.op_Implicit((Object)(object)p.data.currentItem) && (Object)(object)p.data.currentItem.item == (Object)(object)Definition) { return Object.op_Implicit((Object)(object)Definition); } return false; } internal static void Register() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0291: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02cd: 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_00ec: Invalid comparison between Unknown and I4 //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)Definition)) { return; } ItemDatabase instance = SingletonAsset<ItemDatabase>.Instance; GameObject val = new GameObject("PortalWarning runtime item templates"); Object.DontDestroyOnLoad((Object)(object)val); val.SetActive(false); Template = new GameObject("Portal Gun"); Template.transform.SetParent(val.transform, false); Template.AddComponent<ItemInstance>(); Template.AddComponent<PortalGunAttachment>(); GameObject val2 = new GameObject("Right hand grip"); val2.transform.SetParent(Template.transform, false); val2.transform.localPosition = new Vector3(0f, -0.105f, -0.12f); val2.AddComponent<HandGizmo>(); foreach (Item @object in ((DatabaseAsset<ItemDatabase, Item>)(object)instance).Objects) { if (Object.op_Implicit((Object)(object)@object) && Object.op_Implicit((Object)(object)@object.itemObject) && (int)@object.itemType == 1 && (@object.displayName ?? ((Object)@object).name).ToLowerInvariant().Contains("flashlight")) { HandGizmo componentInChildren = @object.itemObject.GetComponentInChildren<HandGizmo>(); if (Object.op_Implicit((Object)(object)componentInChildren)) { val2.transform.localRotation = Quaternion.Inverse(@object.itemObject.transform.rotation) * ((Component)componentInChildren).transform.rotation; Template.layer = @object.itemObject.layer; Plugin.Instance.LogItem("Native hand grip rotation: " + ((object)val2.transform.localEulerAngles/*cast due to .constrained prefix*/).ToString() + " layer=" + LayerMask.LayerToName(Template.layer)); break; } } } new GameObject("Grip editor marker").transform.SetParent(val2.transform, false); BoxCollider obj = Template.AddComponent<BoxCollider>(); obj.center = new Vector3(0f, 0f, 0.04f); obj.size = new Vector3(0.24f, 0.26f, 0.58f); PortalDevice.BuildModel(Template.transform); Definition = ScriptableObject.CreateInstance<Item>(); ((Object)Definition).name = "PortalWarningPortalGun"; Definition.displayName = "Portal Gun"; Definition.PersistentID = new Guid("d6a63fb1-6ba1-4b12-9b1e-6c2897c204e2"); Definition.itemObject = Template; Definition.itemType = (ItemType)1; Definition.mass = 1.2f; Definition.holdPos = new Vector3(0.35f, -0.35f, 0.65f); Definition.holdRotation = Vector3.zero; Definition.icon = Icon(); Object.DontDestroyOnLoad((Object)(object)Definition); ((DatabaseAsset<ItemDatabase, Item>)(object)instance).AddRuntimeEntry(Definition); Plugin.Instance.LogItem("Portal Gun registered as item " + Definition.id); } private static Sprite Icon() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false); Color[] array = (Color[])(object)new Color[4096]; for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { float num = (float)(j - 20) / 10f; float num2 = (float)(i - 32) / 22f; float num3 = (float)(j - 44) / 10f; float num4 = num * num + num2 * num2; float num5 = num3 * num3 + num2 * num2; array[i * 64 + j] = ((num4 > 0.65f && num4 < 1f) ? Portal.BlueColor : ((num5 > 0.65f && num5 < 1f) ? Portal.OrangeColor : Color.clear)); } } val.SetPixels(array); val.Apply(); return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), Vector2.one * 0.5f); } internal unsafe static void SpawnBesideCamera(PickupSpawner spawner) { //IL_0026: 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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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_0055: 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_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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: 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_00d0: 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) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Expected O, but got Unknown //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)Definition) || !PhotonNetwork.IsMasterClient || !Object.op_Implicit((Object)(object)spawner.ItemToSpawn) || (int)spawner.ItemToSpawn.itemType != 0) { return; } Vector3 val = ((Component)spawner).transform.position + Vector3.up * 0.18f; Vector3 val2 = val - ((Component)spawner).transform.right * 0.65f; Vector3[] array = (Vector3[])(object)new Vector3[4] { -((Component)spawner).transform.right, ((Component)spawner).transform.right, -((Component)spawner).transform.forward, ((Component)spawner).transform.forward }; foreach (Vector3 val3 in array) { Vector3 val4 = val + val3 * 0.65f; if (!Physics.CheckBox(val4, new Vector3(0.17f, 0.15f, 0.34f), ((Component)spawner).transform.rotation, LayerMask.op_Implicit(HelperFunctions.terrainPropMask), (QueryTriggerInteraction)1)) { val2 = val4; break; } } Rigidbody componentInChildren = ((Component)PickupHandler.CreatePickup(Definition.id, new ItemInstanceData(Guid.NewGuid()), val2, ((Component)spawner).transform.rotation)).GetComponentInChildren<Rigidbody>(); componentInChildren.useGravity = false; componentInChildren.isKinematic = true; Plugin instance = Plugin.Instance; Vector3 val5 = val2; instance.LogItem("Portal Gun spawned beside the video camera at " + ((object)(*(Vector3*)(&val5))/*cast due to .constrained prefix*/).ToString()); } } [HarmonyPatch(typeof(PickupSpawner), "SpawnMe")] internal static class CameraGunSpawnPatch { private static void Prefix(PickupSpawner __instance, bool force, ref bool __state) { __state = force || !(bool)AccessTools.Field(typeof(PickupSpawner), "m_Spawned").GetValue(__instance); } private static void Postfix(PickupSpawner __instance, bool __state) { if (__state) { PortalGunItem.SpawnBesideCamera(__instance); } } } [HarmonyPatch(typeof(Item), "GetLocalizedDisplayName")] internal static class PortalGunNamePatch { private static bool Prefix(Item __instance, ref string __result) { if ((Object)(object)__instance != (Object)(object)PortalGunItem.Definition) { return true; } __result = "Portal Gun"; return false; } } internal sealed class PortalHud { private readonly Plugin plugin; private Texture2D blueArc; private Texture2D orangeArc; private GUIStyle text; private GUIStyle small; private GUIStyle center; internal PortalHud(Plugin p) { plugin = p; } private void Init() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_002f: 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_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Expected O, but got Unknown text = new GUIStyle(GUI.skin.label) { fontSize = 18, fontStyle = (FontStyle)1 }; text.normal.textColor = Color.white; small = new GUIStyle(text) { fontSize = 13, fontStyle = (FontStyle)0 }; small.normal.textColor = new Color(0.75f, 0.82f, 0.88f); center = new GUIStyle(small) { alignment = (TextAnchor)4 }; blueArc = Arc(left: true); orangeArc = Arc(left: false); } private static Texture2D Arc(bool left) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(96, 96, (TextureFormat)4, false); Color[] array = (Color[])(object)new Color[9216]; for (int i = 0; i < 96; i++) { for (int j = 0; j < 96; j++) { float num = (float)j - 48f; float num2 = (float)i - 48f; float num3 = Mathf.Sqrt(num * num + num2 * num2); bool flag = (left ? (num < -10f) : (num > 10f)); array[i * 96 + j] = ((num3 > 30f && num3 < 34f && flag) ? Color.white : Color.clear); } } val.SetPixels(array); val.Apply(); return val; } private static void Box(Rect rect, Color color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) Color color2 = GUI.color; GUI.color = color; GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture); GUI.color = color2; } internal void Draw() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_03dc: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_0402: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Unknown result type (might be due to invalid IL or missing references) //IL_043b: Unknown result type (might be due to invalid IL or missing references) //IL_0477: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_04e2: Unknown result type (might be due to invalid IL or missing references) //IL_04fb: Unknown result type (might be due to invalid IL or missing references) //IL_0521: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Unknown result type (might be due to invalid IL or missing references) //IL_0356: Unknown result type (might be due to invalid IL or missing references) //IL_037e: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.ShowHud.Value || !Plugin.Ready(Player.localPlayer)) { return; } Player localPlayer = Player.localPlayer; if (!localPlayer.data.dead && !localPlayer.data.hookedIntoTerminal) { if (text == null) { Init(); } Matrix4x4 matrix = GUI.matrix; Color color = GUI.color; float num = Mathf.Clamp((float)Screen.height / 900f, 0.7f, 1.7f); GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f)); float num2 = (float)Screen.width / num; float num3 = (float)Screen.height / num; PortalPair own = plugin.Portals.Own; Box(new Rect(num2 - 312f, 22f, 290f, 84f), new Color(0.025f, 0.04f, 0.065f, 0.86f)); Box(new Rect(num2 - 312f, 22f, 3f, 84f), Portal.BlueColor); GUI.Label(new Rect(num2 - 297f, 31f, 265f, 27f), "PORTAL WARNING", text); GUI.Label(new Rect(num2 - 297f, 61f, 265f, 23f), plugin.DeviceActive ? "PORTAL GUN // Q: DROP" : "Pick up the Portal Gun beside the camera", small); GUI.Label(new Rect(num2 - 297f, 82f, 265f, 20f), "Portal-inspired traversal / v0.3.0", small); if (plugin.DeviceActive && Plugin.CanPlay(localPlayer)) { Rect val = new Rect(num2 / 2f - 32f, num3 / 2f - 32f, 64f, 64f); GUI.color = ((own.Blue == null) ? (Portal.BlueColor * 0.42f) : Portal.BlueColor); GUI.DrawTexture(val, (Texture)(object)blueArc); GUI.color = ((own.Orange == null) ? (Portal.OrangeColor * 0.42f) : Portal.OrangeColor); GUI.DrawTexture(val, (Texture)(object)orangeArc); GUI.color = Color.white; Box(new Rect(num2 / 2f - 1f, num3 / 2f - 1f, 2f, 2f), Color.white); Box(new Rect(num2 / 2f - 218f, num3 - 105f, 436f, 74f), new Color(0.025f, 0.04f, 0.065f, 0.82f)); GUI.color = Portal.BlueColor; GUI.Label(new Rect(num2 / 2f - 198f, num3 - 96f, 190f, 25f), (own.Blue != null) ? "BLUE // PLACED" : "BLUE // LEFT CLICK", small); GUI.color = Portal.OrangeColor; GUI.Label(new Rect(num2 / 2f + 8f, num3 - 96f, 195f, 25f), (own.Orange != null) ? "ORANGE // PLACED" : "ORANGE // RIGHT CLICK", small); GUI.color = Color.white; GUI.Label(new Rect(num2 / 2f - 210f, num3 - 72f, 420f, 24f), "CTRL: CROUCH SPACE: JUMP R: CLEAR MMB: CARRY", center); GUI.Label(new Rect(num2 / 2f - 210f, num3 - 50f, 420f, 20f), own.Linked ? "LINK ACTIVE // MOMENTUM PRESERVED" : "Place a blue and an orange portal on flat surfaces", center); } Vector3 linearVelocity = Plugin.Hip(localPlayer).linearVelocity; float magnitude = ((Vector3)(ref linearVelocity)).magnitude; Box(new Rect(num2 - 195f, 114f, 172f, 61f), new Color(0.025f, 0.04f, 0.065f, 0.8f)); GUI.Label(new Rect(num2 - 181f, 120f, 154f, 24f), magnitude.ToString("0.0") + " m/s", text); GUI.Label(new Rect(num2 - 181f, 147f, 154f, 21f), localPlayer.data.isCrouching ? "CROUCHING" : (localPlayer.data.isGrounded ? "GROUNDED" : "AIRBORNE"), small); if (Time.unscaledTime < plugin.StatusUntil) { Box(new Rect(num2 / 2f - 265f, 115f, 530f, 36f), new Color(0.025f, 0.04f, 0.065f, 0.86f)); GUI.Label(new Rect(num2 / 2f - 255f, 119f, 510f, 28f), plugin.Status, center); } GUI.color = color; GUI.matrix = matrix; } } } [HarmonyPatch(typeof(PlayerRagdoll), "GroundRaycast")] internal static class PortalGroundPatch { private static void Postfix(Player ___player, ref RaycastHit __result) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)Plugin.Instance) && Plugin.Ready(___player) && Object.op_Implicit((Object)(object)((RaycastHit)(ref __result)).collider) && Plugin.Instance.Portals.IsOpenSurface(((RaycastHit)(ref __result)).collider, ((RaycastHit)(ref __result)).point)) { __result = default(RaycastHit); ___player.data.isGrounded = false; } } } [HarmonyPatch(typeof(PlayerInput), "SampeInput")] internal static class DeviceInputPatch { private static void Postfix(Player player, PlayerInput __instance) { if (Object.op_Implicit((Object)(object)Plugin.Instance) && Plugin.Instance.DeviceActive && Plugin.CanPlay(player)) { __instance.clickWasPressed = (__instance.clickIsPressed = (__instance.clickWasReleased = false)); __instance.aimWasPressed = (__instance.aimIsPressed = false); } } } internal sealed class PortalPair { internal int Owner; internal int Revision = -1; internal Portal Blue; internal Portal Orange; internal bool Linked { get { if (Blue != null && Orange != null && Object.op_Implicit((Object)(object)Blue.Root)) { return Object.op_Implicit((Object)(object)Orange.Root); } return false; } } internal IEnumerable<Portal> All { get { if (Blue != null) { yield return Blue; } if (Orange != null) { yield return Orange; } } } internal Portal Other(Portal p) { if (p != Blue) { return Blue; } return Orange; } internal void Destroy() { if (Blue != null) { Blue.Dispose(); } if (Orange != null) { Orange.Dispose(); } Blue = (Orange = null); } } internal sealed class PortalSystem : IDisposable { private sealed class CollisionLease { internal Collider Body; internal Collider Surface; } internal const float RadiusX = 0.8f; internal const float RadiusY = 1.35f; private const string Property = "portalwarning.pair.v1"; private readonly Plugin plugin; internal readonly Dictionary<int, PortalPair> Pairs = new Dictionary<int, PortalPair>(); private readonly List<CollisionLease> ignores = new List<CollisionLease>(); private readonly Dictionary<Rigidbody, float> objectCooldown = new Dictionary<Rigidbody, float>(); private float networkAt; private float playerCooldown; private float objectScanAt; private int revision; private Player lastPlayer; private Rigidbody held; private float heldDrag; private float heldAngularDrag; private bool heldGravity; private readonly List<Rigidbody> nearby = new List<Rigidbody>(); internal int Teleports; internal bool Holding => Object.op_Implicit((Object)(object)held); internal int Owner { get { if (!PhotonNetwork.InRoom || PhotonNetwork.LocalPlayer == null) { return 0; } return PhotonNetwork.LocalPlayer.ActorNumber; } } internal PortalPair Own { get { if (!Pairs.TryGetValue(Owner, out var value)) { value = new PortalPair { Owner = Owner }; Pairs[Owner] = value; } return value; } } internal IEnumerable<Portal> LinkedPortals { get { foreach (PortalPair value in Pairs.Values) { if (!value.Linked) { continue; } foreach (Portal item in value.All) { yield return item; } } } } internal PortalSystem(Plugin p) { plugin = p; } internal void Shoot(int color) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: 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_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: 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_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) Camera cam = Plugin.Cam; if (!Object.op_Implicit((Object)(object)cam)) { return; } if (!FindPlacement(new Ray(((Component)cam).transform.position, ((Component)cam).transform.forward), out var point, out var rotation, out var surfaces, out var reason)) { plugin.Notify(reason); PortalAudio.Play(((Component)cam).transform.position, 170f, 0.07f); return; } PortalPair own = Own; Portal portal = ((color == 0) ? own.Orange : own.Blue); if (portal != null && Vector3.Dot(portal.Normal, rotation * Vector3.forward) > 0.98f) { Vector3 val = Quaternion.Inverse(portal.Rotation) * (point - portal.Position); if (Mathf.Abs(val.z) < 0.3f && Mathf.Abs(val.x) < 1.75f && Mathf.Abs(val.y) < 2.8500001f) { plugin.Notify("Portals need separate space"); return; } } SetPortal(own, color, point, rotation, surfaces); Publish(); plugin.Device.Fire(color); PortalAudio.Play(point, (color == 0) ? 490 : 340, 0.17f); plugin.Notify(own.Linked ? "Portals linked - walk or fall through" : ((color == 0) ? "Blue portal placed" : "Orange portal placed")); } internal bool FindPlacement(Ray ray, out Vector3 point, out Quaternion rotation, out List<Collider> surfaces, out string reason) { //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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_0068: 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) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_018f: 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) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_03c0: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) point = Vector3.zero; rotation = Quaternion.identity; surfaces = new List<Collider>(); reason = "Aim at a flat solid surface"; IOrderedEnumerable<RaycastHit> orderedEnumerable = from h in Physics.RaycastAll(ray, 120f, -1, (QueryTriggerInteraction)1) orderby ((RaycastHit)(ref h)).distance select h; RaycastHit val = default(RaycastHit); foreach (RaycastHit item in orderedEnumerable) { RaycastHit current = item; if (Object.op_Implicit((Object)(object)((RaycastHit)(ref current)).collider) && !Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<Player>()) && !Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<PortalMarker>())) { val = current; break; } } if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider)) { return false; } if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider.attachedRigidbody) && !((RaycastHit)(ref val)).collider.attachedRigidbody.isKinematic) { reason = "Portals need a stationary wall or floor"; return false; } if (Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Bot>())) { return false; } point = ((RaycastHit)(ref val)).point; Vector3 val2 = Vector3.up; Vector3 val3; if (Mathf.Abs(Vector3.Dot(((RaycastHit)(ref val)).normal, val2)) > 0.85f) { val3 = Vector3.ProjectOnPlane(Object.op_Implicit((Object)(object)Plugin.Cam) ? ((Component)Plugin.Cam).transform.forward : Vector3.forward, ((RaycastHit)(ref val)).normal); val2 = ((Vector3)(ref val3)).normalized; if (((Vector3)(ref val2)).sqrMagnitude < 0.1f) { val2 = Vector3.forward; } } else { val3 = Vector3.ProjectOnPlane(Vector3.up, ((RaycastHit)(ref val)).normal); val2 = ((Vector3)(ref val3)).normalized; RaycastHit val4 = default(RaycastHit); if (Physics.Raycast(point + ((RaycastHit)(ref val)).normal * 0.3f + val2 * 1.35f, Vector3.down, ref val4, 6.05f, LayerMask.op_Implicit(HelperFunctions.GetMask((LayerType)1)), (QueryTriggerInteraction)1)) { float num = point.y - ((RaycastHit)(ref val4)).point.y; if (num < 2.35f) { point += val2 * (1.4300001f - num); } } } rotation = Quaternion.LookRotation(((RaycastHit)(ref val)).normal, val2); RaycastHit val5 = default(RaycastHit); for (int num2 = -1; num2 < 20; num2++) { float num3 = (float)num2 * MathF.PI * 2f / 20f; if (!Physics.Raycast(point + ((num2 < 0) ? Vector3.zero : (rotation * new Vector3(Mathf.Cos(num3) * 0.86f, Mathf.Sin(num3) * 1.41f, 0f))) + ((RaycastHit)(ref val)).normal * 0.3f, -((RaycastHit)(ref val)).normal, ref val5, 0.65f, -1, (QueryTriggerInteraction)1) || Vector3.Dot(((RaycastHit)(ref val5)).normal, ((RaycastHit)(ref val)).normal) < 0.97f || Mathf.Abs(Vector3.Dot(((RaycastHit)(ref val5)).point - point, ((RaycastHit)(ref val)).normal)) > 0.075f || Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val5)).collider).GetComponentInParent<Player>()) || Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val5)).collider).GetComponentInParent<Bot>()) || (Object.op_Implicit((Object)(object)((RaycastHit)(ref val5)).collider.attachedRigidbody) && !((RaycastHit)(ref val5)).collider.attachedRigidbody.isKinematic)) { reason = "Not enough flat space for a portal"; return false; } if (!surfaces.Contains(((RaycastHit)(ref val5)).collider)) { surfaces.Add(((RaycastHit)(ref val5)).collider); } } point += ((RaycastHit)(ref val)).normal * 0.018f; return true; } internal Portal SetPortal(PortalPair pair, int color, Vector3 pos, Quaternion rot, List<Collider> surfaces) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) RestoreCollisions(); ((color == 0) ? pair.Blue : pair.Orange)?.Dispose(); Portal portal = new Portal(pair, color, pos, rot, surfaces); if (color == 0) { pair.Blue = portal; } else { pair.Orange = portal; } return portal; } internal void ClearOwn() { Own.Destroy(); RestoreCollisions(); Publish(); plugin.Notify("Portals cleared"); } internal void ResetScene() { Drop(); RestoreCollisions(); foreach (PortalPair value in Pairs.Values) { value.Destroy(); } Pairs.Clear(); objectCooldown.Clear(); nearby.Clear(); lastPlayer = null; Publish(); } internal void Publish() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0078: Expected O, but got Unknown //IL_007f: Expected O, but got Unknown if (PhotonNetwork.InRoom && PhotonNetwork.LocalPlayer != null) { PortalPair own = Own; object[] obj = new object[4] { ++revision, null, null, null }; Scene activeScene = SceneManager.GetActiveScene(); obj[1] = ((Scene)(ref activeScene)).name; obj[2] = Pack(own.Blue); obj[3] = Pack(own.Orange); object[] value = obj; Player localPlayer = PhotonNetwork.LocalPlayer; Hashtable val = new Hashtable(); ((Dictionary<object, object>)val).Add((object)"portalwarning.pair.v1", (object)value); localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null); } } private static float[] Pack(Portal p) { if (p == null) { return new float[0]; } return new float[7] { p.Position.x, p.Position.y, p.Position.z, p.Rotation.x, p.Rotation.y, p.Rotation.z, p.Rotation.w }; } internal void NetworkTick() { //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) if (Time.unscaledTime < networkAt) { return; } networkAt = Time.unscaledTime + 0.5f; if (!PhotonNetwork.InRoom) { if (Pairs.Keys.Any((int k) => k != 0)) { ResetScene(); } return; } int own = Owner; if (Pairs.ContainsKey(0)) { Pairs[0].Destroy(); Pairs.Remove(0); } Player[] players = PhotonNetwork.PlayerList; int[] array = Pairs.Keys.Where((int id) => id != own && !players.Any((Player p) => p.ActorNumber == id)).ToArray(); foreach (int key in array) { Pairs[key].Destroy(); Pairs.Remove(key); RestoreCollisions(); } Player[] array2 = players; foreach (Player val in array2) { if (val.ActorNumber == own || !((Dictionary<object, object>)(object)val.CustomProperties).ContainsKey((object)"portalwarning.pair.v1") || !(val.CustomProperties[(object)"portalwarning.pair.v1"] is object[] array3) || array3.Length != 4 || !(array3[0] is int) || !(array3[1] is string)) { continue; } if (!Pairs.TryGetValue(val.ActorNumber, out var value)) { Dictionary<int, PortalPair> pairs = Pairs; int actorNumber = val.ActorNumber; PortalPair obj = new PortalPair { Owner = val.ActorNumber }; value = obj; pairs[actorNumber] = obj; } if (value.Revision != (int)array3[0]) { value.Destroy(); RestoreCollisions(); value.Revision = (int)array3[0]; string obj2 = (string)array3[1]; Scene activeScene = SceneManager.GetActiveScene(); if (!(obj2 != ((Scene)(ref activeScene)).name)) { Receive(value, 0, array3[2] as float[]); Receive(value, 1, array3[3] as float[]); } } } } private void Receive(PortalPair pair, int color, float[] pose) { //IL_0041: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: 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_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missin