Decompiled source of PortalGun v1.26.2
plugins/PortalGun.dll
Decompiled 2 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.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using ComputerysModdingUtilities; using FishNet; using FishNet.Broadcast; using FishNet.Component.Transforming; using FishNet.Connection; using FishNet.Managing; using FishNet.Managing.Object; using FishNet.Managing.Timing; using FishNet.Object; using FishNet.Object.Delegating; using FishNet.Serializing; using FishNet.Transporting; using FishySteamworks; using HarmonyLib; using HeathenEngineering.PhysKit; using Microsoft.CodeAnalysis; using Steamworks; using TMPro; using UnityEngine; using UnityEngine.Audio; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.LowLevel; using UnityEngine.InputSystem.Utilities; using UnityEngine.Rendering; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: StraftatMod(false)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Goomageddon")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.26.2.0")] [assembly: AssemblyInformationalVersion("1.26.2+0ce41090d3b79f30a69ced6050b05536b2b990c9")] [assembly: AssemblyProduct("PortalGun")] [assembly: AssemblyTitle("PortalGun")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.26.2.0")] [module: UnverifiableCode] [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 PortalGun { internal static class AliveObjects { private static readonly List<FirstPersonController> AllPlayers = new List<FirstPersonController>(); private static readonly List<ItemBehaviour> AllItems = new List<ItemBehaviour>(); private static readonly List<FirstPersonController> ActivePlayers = new List<FirstPersonController>(); private static readonly List<ItemBehaviour> ActiveItems = new List<ItemBehaviour>(); public static List<FirstPersonController> Players() { return Active<FirstPersonController>(AllPlayers, ActivePlayers); } public static List<ItemBehaviour> Items() { return Active<ItemBehaviour>(AllItems, ActiveItems); } private static List<T> Active<T>(List<T> all, List<T> active) where T : Behaviour { active.Clear(); for (int num = all.Count - 1; num >= 0; num--) { T val = all[num]; if ((Object)(object)val == (Object)null) { all.RemoveAt(num); } else if (((Component)(object)val).gameObject.activeInHierarchy) { active.Add(val); } } active.Reverse(); return active; } public static void ApplyPatches(Harmony harmony) { Patch(harmony, typeof(FirstPersonController), "AfterPlayerAwake"); Patch(harmony, typeof(ItemBehaviour), "AfterItemAwake"); } private static void Patch(Harmony harmony, Type type, string postfix) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown MethodInfo method = type.GetMethod("Awake", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (method == null) { Plugin.Log.LogWarning((object)("Alive objects: NOT patched " + type.Name + ".Awake (method not found; the game has changed): Dimension looks miss them")); return; } try { harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(AliveObjects), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Alive objects: NOT patched " + type.Name + ".Awake: " + ex.Message)); } } private static void AfterPlayerAwake(FirstPersonController __instance) { if ((Object)(object)__instance != (Object)null) { AllPlayers.Add(__instance); } } private static void AfterItemAwake(ItemBehaviour __instance) { if ((Object)(object)__instance != (Object)null) { AllItems.Add(__instance); } } } internal static class AltPortalPreset { public const string PresetName = "alt_portal"; private const string EveryMap = "*"; private static readonly string[] PistolPrecursors = new string[3] { "Gun", "Glock", "Silenzzio" }; private static readonly string[] LauncherPrecursors = new string[1] { "Revolver" }; public static bool IsSelectedInMap() { //IL_0013: 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) if (WeaponRemapper.SelectedPreset != null && IsAltPortal(WeaponRemapper.SelectedPreset)) { Scene activeScene = SceneManager.GetActiveScene(); return ((Scene)(ref activeScene)).name != "MainMenu"; } return false; } public static void EnsureExists(bool reselect) { //IL_0028: 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_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_0087: Expected O, but got Unknown try { SpawnerManager.PopulateAllWeapons(); WeaponRemapper[] array = Resources.FindObjectsOfTypeAll<WeaponRemapper>(); foreach (WeaponRemapper val in array) { if ((Object)(object)val == (Object)null) { continue; } Scene scene = ((Component)val).gameObject.scene; if (!((Scene)(ref scene)).IsValid()) { continue; } List<WeaponRemapPreset> list = GameAccess.WeaponRemaps.Invoke(val); if (list == null) { continue; } WeaponRemapPreset val2 = list.Find(IsAltPortal); if (val2 == null) { val2 = new WeaponRemapPreset { Name = "alt_portal" }; int num = AddStarterRules(val2); val.AddPreset(val2); Plugin.Log.LogInfo((object)string.Format("Added Weapon Swap preset '{0}' with {1} starter rule(s): {2}", "alt_portal", num, Describe(val2))); } else { int num2 = RenameLegacyResults(val2); int num3 = RetirePistolRules(val2); int num4 = ((!HasPortalRule(val2)) ? AddStarterRules(val2) : 0); if (num3 > 0 && num4 == 0) { num4 = AddRules(EveryMapEntry(val2), MinePrecursors(), "PortalMine"); } if (num2 > 0 || num3 > 0 || num4 > 0) { Plugin.Log.LogInfo((object)string.Format("Weapon Swap preset '{0}': {1} old Portal Gun rule(s) updated, {2} Portal Pistol rule(s) retired, {3} starter rule(s) added: {4}", "alt_portal", num2, num3, num4, Describe(val2))); } } if (reselect && WeaponRemapper.SelectedPreset == null) { Reselect(val, val2); } } } catch (Exception ex) { Plugin.Log.LogError((object)("Could not set up the 'alt_portal' Weapon Swap preset: " + ex)); } } private static bool IsAltPortal(WeaponRemapPreset preset) { if (preset != null) { return string.Equals(preset.Name, "alt_portal", StringComparison.OrdinalIgnoreCase); } return false; } private static bool HasPortalRule(WeaponRemapPreset preset) { foreach (WeaponRemapMap map in preset.Maps) { if (map == null) { continue; } foreach (WeaponRemap weaponRemap in map.WeaponRemaps) { if (weaponRemap != null && PortalGunFamily.IsFamily(weaponRemap.Result, out var _)) { return true; } } } return false; } private static int RenameLegacyResults(WeaponRemapPreset preset) { int num = 0; foreach (WeaponRemapMap map in preset.Maps) { if (map == null) { continue; } foreach (WeaponRemap weaponRemap in map.WeaponRemaps) { if (weaponRemap != null && !(weaponRemap.Result != "PortalGun")) { weaponRemap.Result = ((Array.IndexOf(PistolPrecursors, weaponRemap.Precursor) >= 0) ? "PortalPistol" : "PortalLauncher"); num++; } } } return num; } private static int RetirePistolRules(WeaponRemapPreset preset) { int num = 0; foreach (WeaponRemapMap map in preset.Maps) { if (map != null) { num += map.WeaponRemaps.RemoveAll((WeaponRemap r) => r != null && r.Result == "PortalPistol"); } } return num; } private static string[] MinePrecursors() { List<string> list = new List<string>(); if (SpawnerManager.AllWeapons == null) { return list.ToArray(); } GameObject[] allWeapons = SpawnerManager.AllWeapons; foreach (GameObject val in allWeapons) { if (!((Object)(object)val == (Object)null) && !PortalGunFamily.IsFamily(((Object)val).name, out var _) && !SpiritGuns.IsName(((Object)val).name) && (Object)(object)val.GetComponent<WeaponHandSpawner>() != (Object)null) { list.Add(((Object)val).name); } } return list.ToArray(); } private static WeaponRemapMap EveryMapEntry(WeaponRemapPreset preset) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown WeaponRemapMap val = preset.Maps.Find((WeaponRemapMap m) => m != null && m.MapString == "*"); if (val == null) { val = new WeaponRemapMap { MapString = "*" }; preset.Maps.Add(val); } return val; } private static int AddStarterRules(WeaponRemapPreset preset) { WeaponRemapMap map = EveryMapEntry(preset); return AddRules(map, MinePrecursors(), "PortalMine") + AddRules(map, LauncherPrecursors, "PortalLauncher"); } private static int AddRules(WeaponRemapMap map, string[] precursors, string result) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_0089: Expected O, but got Unknown int num = 0; foreach (string precursor in precursors) { if (!SpawnerManager.NameToWeaponDict.ContainsKey(precursor)) { Plugin.Log.LogWarning((object)("Weapon Swap preset 'alt_portal': the game has no weapon '" + precursor + "', starter rule skipped")); } else if (!map.WeaponRemaps.Exists((WeaponRemap r) => r != null && r.Precursor == precursor)) { map.WeaponRemaps.Add(new WeaponRemap { Precursor = precursor, Result = result }); num++; } } return num; } private static void Reselect(WeaponRemapper remapper, WeaponRemapPreset preset) { RectTransform val = GameAccess.PresetParent.Invoke(remapper); if ((Object)(object)val == (Object)null) { return; } WeaponRemapperPresetUI[] componentsInChildren = ((Component)val).GetComponentsInChildren<WeaponRemapperPresetUI>(true); foreach (WeaponRemapperPresetUI val2 in componentsInChildren) { if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.inputField == (Object)null) && !(val2.inputField.text != preset.Name)) { ((UnityEvent<string>)(object)val2.inputField.onSelect).Invoke(preset.Name); break; } } Plugin.Log.LogInfo((object)((WeaponRemapper.SelectedPreset == preset) ? "Weapon Swap preset 'alt_portal' selected again after the save file was reloaded" : "Weapon Swap preset 'alt_portal' was selected before the save file was reloaded, but could not be selected again")); } private static string Describe(WeaponRemapPreset preset) { List<string> list = new List<string>(); foreach (WeaponRemapMap map in preset.Maps) { if (map == null) { continue; } foreach (WeaponRemap weaponRemap in map.WeaponRemaps) { if (weaponRemap != null) { list.Add("[" + map.MapString + "] " + weaponRemap.Precursor + " -> " + weaponRemap.Result); } } } if (list.Count <= 0) { return "(no rules)"; } return string.Join(", ", list); } } internal sealed class ArenaMode : PortalMode { private const float GetReadySeconds = 3f; public override PortalModeKind Kind => PortalModeKind.Arena; public override string Name => "Portal Arena"; public static void Init() { PortalModes.Register(new ArenaMode()); } public override void OnTakeSpawn() { ModeWeapons.HoldMapWeapons = true; ModeDamage.NoDamage = true; ModePlayers.VoidRescue = true; PortalLifetime.KeepPairsOfDeadOwners = true; } public override void OnTakeStarted() { foreach (ModePlayer item in ModePlayers.All()) { ModeWeapons.GiveModePortalGun(item.Id); } PhaseClock.Start(new Phase("Setup", PortalModes.Settings.SetupTime), new Phase("Get ready", 3f)); } public override void OnPhaseEnded(int index, Phase phase, bool last) { if (index == 0) { ModeWeapons.TakeAllGiven(); PortalLifetime.PlacementLocked = true; ModePlayers.SendAllToSpawn(); foreach (ModePlayer item in ModePlayers.All()) { ModePlayers.Freeze(item.Id); } ModeWeapons.HoldMapWeapons = false; return; } foreach (ModePlayer item2 in ModePlayers.All()) { ModePlayers.Freeze(item2.Id, frozen: false); } ModeDamage.NoDamage = false; ModePlayers.VoidRescue = false; } } internal sealed class AudioRecord : MonoBehaviour { private float[] _buffer; private int _written; private int _channels; private int _rate; private string _path; private volatile bool _done; private string _frameDir; private int _frame; private float _startedAt; private float _nextFrame; private StringBuilder _times; public static string Start(string arg, string shotDir) { string[] array = arg.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length < 2 || !float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { return "error: record-audio <seconds> <name>"; } AudioListener val = Object.FindObjectOfType<AudioListener>(); if ((Object)(object)val == (Object)null) { return "error: no AudioListener"; } AudioRecord audioRecord = ((Component)val).gameObject.AddComponent<AudioRecord>(); audioRecord._rate = AudioSettings.outputSampleRate; audioRecord._channels = 2; audioRecord._buffer = new float[(int)(Mathf.Clamp(result, 0.5f, 120f) * (float)audioRecord._rate) * 2]; audioRecord._path = Path.Combine(shotDir, array[1] + ".wav"); Plugin.Log.LogInfo((object)$"AudioRecord: recording {result:0.#} s at {audioRecord._rate} Hz to {audioRecord._path}"); return $"ok recording {result:0.#} s to {array[1]}.wav"; } private void OnAudioFilterRead(float[] data, int channels) { if (_done || _buffer == null) { return; } _channels = channels; int num = data.Length / channels; for (int i = 0; i < num; i++) { if (_written + 1 >= _buffer.Length) { break; } _buffer[_written++] = data[i * channels]; _buffer[_written++] = data[i * channels + ((channels > 1) ? 1 : 0)]; } if (_written + 1 >= _buffer.Length) { _done = true; } } public static string StartVideo(string arg, string shotDir) { string text = Start(arg, shotDir); if (!text.StartsWith("ok")) { return text; } AudioRecord component = ((Component)Object.FindObjectOfType<AudioListener>()).GetComponent<AudioRecord>(); string text2 = arg.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1]; component._frameDir = Path.Combine(shotDir, text2); if (Directory.Exists(component._frameDir)) { Directory.Delete(component._frameDir, recursive: true); } Directory.CreateDirectory(component._frameDir); component._times = new StringBuilder(); component._startedAt = Time.unscaledTime; ((MonoBehaviour)component).StartCoroutine(component.Frames()); return text + " with frames in " + text2 + "/"; } private IEnumerator Frames() { WaitForEndOfFrame wait = new WaitForEndOfFrame(); while (!_done) { yield return wait; if (!(Time.unscaledTime < _nextFrame)) { _nextFrame = Time.unscaledTime + 0.05f; Texture2D val = ScreenCapture.CaptureScreenshotAsTexture(); File.WriteAllBytes(Path.Combine(_frameDir, $"f{++_frame:00000}.jpg"), ImageConversion.EncodeToJPG(val, 88)); Object.Destroy((Object)(object)val); _times.AppendLine((Time.unscaledTime - _startedAt).ToString("0.0000", CultureInfo.InvariantCulture)); } } File.WriteAllText(Path.Combine(_frameDir, "times.txt"), _times.ToString()); } private void Update() { if (!_done || (_frameDir != null && !File.Exists(Path.Combine(_frameDir, "times.txt")))) { return; } try { using (FileStream output = new FileStream(_path, FileMode.Create)) { using BinaryWriter binaryWriter = new BinaryWriter(output); int num = _written * 2; binaryWriter.Write(Encoding.ASCII.GetBytes("RIFF")); binaryWriter.Write(36 + num); binaryWriter.Write(Encoding.ASCII.GetBytes("WAVEfmt ")); binaryWriter.Write(16); binaryWriter.Write((short)1); binaryWriter.Write((short)2); binaryWriter.Write(_rate); binaryWriter.Write(_rate * 4); binaryWriter.Write((short)4); binaryWriter.Write((short)16); binaryWriter.Write(Encoding.ASCII.GetBytes("data")); binaryWriter.Write(num); for (int i = 0; i < _written; i++) { binaryWriter.Write((short)(Mathf.Clamp(_buffer[i], -1f, 1f) * 32767f)); } } Plugin.Log.LogInfo((object)("AudioRecord: wrote " + _path)); } catch (Exception ex) { Plugin.Log.LogError((object)("AudioRecord: could not write: " + ex)); } Object.Destroy((Object)(object)this); } } internal static class BlindSound { private static AudioListener _listener; private static bool _wasBlind; public static bool Forced; private static readonly float[] Buffer = new float[1024]; public static bool Active { get { if (!ModeClient.LocalBlindfolded) { return Forced; } return true; } } public static void Tick() { bool active = Active; if (active != _wasBlind) { _wasBlind = active; Plugin.Log.LogInfo((object)(active ? "Blind sound: on, every sound reaches both ears equally" : "Blind sound: off, sounds have direction again")); } MonoFold.Target = (active ? 1f : 0f); if (active && (!Object.op_Implicit((Object)(object)_listener) || !((Behaviour)_listener).isActiveAndEnabled)) { _listener = FindListener(); if (Object.op_Implicit((Object)(object)_listener) && !Object.op_Implicit((Object)(object)((Component)_listener).GetComponent<MonoFold>())) { ((Component)_listener).gameObject.AddComponent<MonoFold>(); } } } private static AudioListener FindListener() { Camera main = Camera.main; if (Object.op_Implicit((Object)(object)main)) { AudioListener componentInChildren = ((Component)main).GetComponentInChildren<AudioListener>(); if (Object.op_Implicit((Object)(object)componentInChildren) && ((Behaviour)componentInChildren).isActiveAndEnabled) { return componentInChildren; } } return ((IEnumerable<AudioListener>)Object.FindObjectsOfType<AudioListener>()).FirstOrDefault((Func<AudioListener, bool>)((AudioListener l) => ((Behaviour)l).isActiveAndEnabled)); } public static string Report() { double num = Rms(0); double num2 = Rms(1); double num3 = 0.0; AudioListener.GetOutputData(Buffer, 0); float[] array = new float[Buffer.Length]; AudioListener.GetOutputData(array, 1); for (int i = 0; i < Buffer.Length; i++) { num3 += (double)((Buffer[i] - array[i]) * (Buffer[i] - array[i])); } num3 = Math.Sqrt(num3 / (double)Buffer.Length); int num4 = Object.FindObjectsOfType<AudioSource>().Count((AudioSource s) => s.isPlaying && (Object)(object)s.outputAudioMixerGroup != (Object)null); return string.Format("blind {0} (blindfolded {1}, forced {2}), fold {3:0.00}, ", Active ? "on" : "off", ModeClient.LocalBlindfolded, Forced, MonoFold.Applied) + string.Format("listener {0}, output rms L {1:0.0000} R {2:0.0000} L-R {3:0.0000}, ", Object.op_Implicit((Object)(object)_listener) ? ((Object)_listener).name : "none", num, num2, num3) + $"playing sources routed to a mixer {num4}"; } private static double Rms(int channel) { AudioListener.GetOutputData(Buffer, channel); double num = 0.0; float[] buffer = Buffer; foreach (float num2 in buffer) { num += (double)(num2 * num2); } return Math.Sqrt(num / (double)Buffer.Length); } } internal sealed class MonoFold : MonoBehaviour { public static volatile float Target; private static float _amount; public static float Applied => _amount; private void OnAudioFilterRead(float[] data, int channels) { float target = Target; float num = _amount; if (channels < 2 || (num == 0f && target == 0f)) { return; } int num2 = data.Length / channels; float num3 = ((num2 > 0) ? ((target - num) / (float)num2) : 0f); int num4 = 0; int num5 = 0; while (num4 < num2) { num += num3; float num6 = 0f; for (int i = 0; i < channels; i++) { num6 += data[num5 + i]; } num6 /= (float)channels; for (int j = 0; j < channels; j++) { data[num5 + j] += (num6 - data[num5 + j]) * num; } num4++; num5 += channels; } _amount = target; } } internal enum WeaponKind { Normal, SpiritGun, Tear } internal enum Reach { Direct, Area } internal enum Verdict { Hit, HitCapped, Chip, Ignore } internal static class DamageRule { public const float OneHp = 0.04f; public const float SpiritGunCap = 2f; public static Verdict Of(Dimension fired, int doors, WeaponKind kind, Reach reach, Dimension victim, bool isShooter) { bool flag = DimensionRule.After(fired, doors) != victim; switch (kind) { case WeaponKind.Tear: return Verdict.Hit; case WeaponKind.SpiritGun: if (!flag) { return Verdict.HitCapped; } return Verdict.Hit; default: if (!flag) { return Verdict.Hit; } if (reach != Reach.Direct || doors > 0 || isShooter) { return Verdict.Ignore; } return Verdict.Chip; } } } internal sealed class ShotTally { private readonly HashSet<long> _chipped = new HashSet<long>(); private readonly Dictionary<long, float> _given = new Dictionary<long, float>(); private int _frame = int.MinValue; public void Begin(int frame) { if (frame != _frame) { _frame = frame; _chipped.Clear(); _given.Clear(); } } public bool FirstChip(long victimAndShot) { return _chipped.Add(victimAndShot); } public float Allow(long victimAndShot, float damage, out float givenBefore) { _given.TryGetValue(victimAndShot, out givenBefore); float num = Math.Max(0f, Math.Min(damage, 2f - givenBefore)); _given[victimAndShot] = givenBefore + num; return num; } } internal sealed class DebugCommands : MonoBehaviour { private sealed class Result { public string Text; } private const string Section = "Debug"; private const float PollInterval = 0.25f; private const float ShotTimeout = 10f; private static ConfigEntry<bool> _enabled; private static string _cmdFile; private static string _logFile; private static string _shotDir; private static ConfigEntry<bool> _freeCursor; private static DebugCommands _instance; private static Vector3 _glide; private static float _glideUntil; private static int _injectedUntil = -1; private static bool _played; private static MouseState _heldMouse; private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4]; private static readonly FieldRef<WeaponHandSpawner, bool> CanPlace = AccessTools.FieldRefAccess<WeaponHandSpawner, bool>("canPlace"); private static readonly FieldRef<WeaponHandSpawner, Vector3> PlacePosition = AccessTools.FieldRefAccess<WeaponHandSpawner, Vector3>("position"); public static bool On { get { if (_enabled != null) { return _enabled.Value; } return false; } } internal static bool VisualTest { get; private set; } public static void Init(ConfigFile config, GameObject host) { _enabled = config.Bind<bool>("Debug", "DebugCommands", false, "Developer tool. Runs commands from BepInEx/portalgun-cmd.txt (screenshots, UI dumps, clicks) for tools/game.sh. Takes effect on the next game start."); _freeCursor = config.Bind<bool>("Debug", "FreeCursor", true, "Developer tool, only while DebugCommands is on: undo the game's cursor lock, so a test run driven by commands does not take the mouse from whoever is using the computer. Once a person presses a key or mouse button in the game's window, the game keeps the cursor (locked and hidden in play) whenever its window has focus."); if (_enabled.Value) { string? directoryName = Path.GetDirectoryName(Paths.BepInExRootPath.TrimEnd('/', '\\')); _cmdFile = Path.Combine(Paths.BepInExRootPath, "portalgun-cmd.txt"); _logFile = Path.Combine(Paths.BepInExRootPath, "portalgun-cmd.log"); _shotDir = Path.Combine(directoryName, "PortalGunShots"); Application.runInBackground = true; host.AddComponent<DebugCommands>(); Plugin.Log.LogInfo((object)("Debug commands on: polling '" + _cmdFile + "'")); } } private void Awake() { _instance = this; } private void Update() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) if (!(Time.unscaledTime >= _glideUntil)) { FirstPersonController val = GameAccess.LocalPlayer(); if ((Object)(object)val != (Object)null && (Object)(object)val.characterController != (Object)null && ((Collider)val.characterController).enabled) { val.characterController.Move(_glide * Time.deltaTime); } } } private void LateUpdate() { //IL_0052: Unknown result type (might be due to invalid IL or missing references) if (_freeCursor == null || !_freeCursor.Value) { return; } if (Application.isFocused) { if (!_played && Time.frameCount > _injectedUntil && PersonPressed()) { _played = true; Plugin.Log.LogInfo((object)"FreeCursor: a person is playing; the game keeps the cursor while its window has focus"); } if (_played) { return; } } if ((int)Cursor.lockState != 0) { Cursor.lockState = (CursorLockMode)0; } if (!Cursor.visible) { Cursor.visible = true; } } private static bool PersonPressed() { Keyboard current = Keyboard.current; Mouse current2 = Mouse.current; if (current == null || !((ButtonControl)current.anyKey).wasPressedThisFrame) { if (current2 != null) { if (!current2.leftButton.wasPressedThisFrame && !current2.rightButton.wasPressedThisFrame) { return current2.middleButton.wasPressedThisFrame; } return true; } return false; } return true; } private static void Inject<TState>(InputDevice device, TState state) where TState : struct, IInputStateTypeInfo { _injectedUntil = Time.frameCount + 5; InputSystem.QueueStateEvent<TState>(device, state, -1.0); } private IEnumerator Start() { WaitForSecondsRealtime wait = new WaitForSecondsRealtime(0.25f); while (true) { yield return wait; string[] array = null; try { if (File.Exists(_cmdFile)) { array = File.ReadAllLines(_cmdFile); File.Delete(_cmdFile); } } catch (Exception ex) { Plugin.Log.LogInfo((object)("Debug commands: could not read the command file yet: " + ex.Message)); } if (array == null) { continue; } string[] array2 = array; foreach (string text in array2) { string line = text.Trim(); if (line.Length != 0 && !line.StartsWith("#")) { Result result = new Result(); yield return Run(line, result); Append(line, result.Text ?? "ok"); } } } } private static void Append(string command, string result) { try { File.AppendAllText(_logFile, command.Replace('\t', ' ') + "\t" + result.Replace('\n', ' ') + "\n"); } catch (Exception ex) { Plugin.Log.LogInfo((object)("Debug commands: could not write the result log: " + ex.Message)); } Plugin.Log.LogInfo((object)("Debug command '" + command + "': " + result)); } private static IEnumerator Run(string line, Result result) { int num = line.IndexOf(' '); string text = ((num < 0) ? line : line.Substring(0, num)); string text2 = ((num < 0) ? "" : line.Substring(num + 1).Trim()); switch (text) { case "shot": yield return Shot(text2, result); yield break; case "key": yield return Key(text2, result); yield break; case "sound-log": result.Text = SoundLog.Set(text2); yield break; case "listen": { if (!float.TryParse(text2, NumberStyles.Float, CultureInfo.InvariantCulture, out var result3) || result3 <= 0f) { result.Text = "error: listen <seconds>"; yield break; } yield return SoundLog.Listen(result3, delegate(string text4) { result.Text = text4; }); yield break; } case "glide": { float[] array = Numbers(text2); if (array == null || array.Length != 3) { result.Text = "error: glide <vx> <vz> <seconds>"; yield break; } _glide = new Vector3(array[0], 0f, array[1]); _glideUntil = Time.unscaledTime + array[2]; result.Text = $"ok gliding at ({array[0]:0.##}, {array[1]:0.##}) m/s for {array[2]:0.##} s"; yield break; } case "mine-sweep": yield return MineSweep(text2, result); yield break; case "key-hold": result.Text = KeyHold(text2); yield break; case "track": result.Text = Track(text2); yield break; case "mouse": yield return Mouse(text2, result); yield break; case "hold": yield return Hold(text2, result); yield break; case "wait": { if (!float.TryParse(text2, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) || result2 < 0f) { result.Text = "error: wait needs a number of seconds"; yield break; } yield return (object)new WaitForSecondsRealtime(result2); result.Text = "ok"; yield break; } } try { switch (text) { case "ui-dump": result.Text = UiDump(text2 == "all"); break; case "adv-hint": result.Text = PortalSettingsUi.DebugHint(text2); break; case "open-portal-settings": result.Text = PortalSettingsUi.DebugOpen(); break; case "close-portal-settings": result.Text = PortalSettingsUi.DebugClose(); break; case "click": result.Text = Click(text2); break; case "select": result.Text = Select(text2); break; case "hit": result.Text = Hit(text2); break; case "give": result.Text = Give(text2); break; case "visual-test": if (text2 != "on" && text2 != "off") { result.Text = "error: visual-test on|off"; break; } VisualTest = text2 == "on"; result.Text = (VisualTest ? "ok visual test: no Mine Pull, no walking through Portals" : "ok visual test off"); break; case "timescale": { if (!float.TryParse(text2, NumberStyles.Float, CultureInfo.InvariantCulture, out var result17) || result17 <= 0f || result17 > 4f) { result.Text = "error: timescale needs a number above 0 and up to 4 (1 = normal)"; break; } Time.timeScale = result17; result.Text = $"ok time runs at {result17:0.###}x"; break; } case "explore": result.Text = Explore(text2); break; case "maps": result.Text = Maps(); break; case "leave": if ((Object)(object)SteamLobby.Instance == (Object)null) { result.Text = "error: no SteamLobby"; break; } SteamLobby.Instance.LeaveMatch(); result.Text = "ok leaving to the main menu"; break; case "local-lobby": result.Text = LocalTwoPlayer.DebugLobby(); break; case "local-join": result.Text = LocalTwoPlayer.DebugJoin(text2); break; case "local-ping": result.Text = LocalTwoPlayer.DebugPing(); break; case "scene-dump": result.Text = SceneDump(text2); break; case "map-info": result.Text = MapInfo(); break; case "overview": result.Text = Overview(text2); break; case "look": result.Text = Look(text2); break; case "tp": result.Text = Tp(text2); break; case "where": result.Text = Where(); break; case "viewmodel": result.Text = Viewmodel(); break; case "parts": result.Text = HeldParts(text2); break; case "hand-in": result.Text = HandIn(text2); break; case "grenade-parts": result.Text = LuckyRift.DumpTemplate(); break; case "hide": result.Text = HideHeldPart(text2, hide: true); break; case "show": result.Text = HideHeldPart(text2, hide: false); break; case "territory": result.Text = Territory(text2); break; case "give-item": result.Text = GiveItem(text2); break; case "lucky-grenades": LuckyRift.ForceGrenades = text2 == "on"; result.Text = "ok every thing out of a Lucky Rift is " + (LuckyRift.ForceGrenades ? "a live grenade" : "random again"); break; case "lucky-rift": result.Text = LuckyRift.DebugOpen(); break; case "rift-cut": result.Text = RiftCuts.DebugCut(text2); break; case "portal": result.Text = PlacePortal(text2); break; case "door": result.Text = DimensionDebug.Door(); break; case "dimension": result.Text = DimensionDebug.Dimension(text2); break; case "items": result.Text = "ok " + DimensionItems.Describe(); break; case "look-undo": result.Text = DimensionLook.UndoOne(); break; case "pale-loot": result.Text = PaleLoot.Force(); break; case "powerup": result.Text = Powerups.Debug(text2); break; case "weapon-tiers": { int strong; int weak; string contents = WeaponTiers.Table(out strong, out weak); File.WriteAllText(Path.Combine(_shotDir, "weapon-tiers.tsv"), contents); result.Text = $"ok {strong} strong and {weak} weak weapon(s) to weapon-tiers.tsv"; break; } case "drain": result.Text = DimensionDebug.Drain(text2); break; case "record-audio": result.Text = (text2.TrimEnd().EndsWith(" video") ? AudioRecord.StartVideo(text2, _shotDir) : AudioRecord.Start(text2, _shotDir)); break; case "drain-look": result.Text = DrainHud.Preview(text2); break; case "pale-set": result.Text = DimensionDebug.PaleSet(text2); break; case "spirit-gun-look": { string[] array3 = text2.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); CultureInfo invariantCulture = CultureInfo.InvariantCulture; if (array3.Length > 1 && float.TryParse(array3[1], NumberStyles.Float, invariantCulture, out var result12)) { SpiritGuns.CoatFill = result12; } if (array3.Length > 2 && float.TryParse(array3[2], NumberStyles.Float, invariantCulture, out var result13)) { SpiritGuns.CoatRim = result13; } result.Text = SpiritGuns.SetLook((array3.Length != 0 && int.TryParse(array3[0], out var result14)) ? result14 : 0); break; } case "spirit-set": result.Text = DimensionDebug.SpiritSet(text2); SpiritBullets.ValuesChanged(); break; case "dimension-sound": result.Text = DimensionSound.DebugSet(text2); break; case "bullet-set": result.Text = SpiritBullets.DebugSet(text2); break; case "placement": result.Text = Placement(); break; case "headwarp": result.Text = HeadWarp(text2); break; case "head-probe": result.Text = HeadProbe(); break; case "headshot-test": result.Text = HeadshotTest(text2); break; case "aim-head": result.Text = AimHead(); break; case "fire": { if (text2 != "a" && text2 != "b") { result.Text = "error: fire a|b"; break; } PortalRailWeapon portalRailWeapon = Object.FindObjectsOfType<PortalRailWeapon>().FirstOrDefault((PortalRailWeapon w) => ((NetworkBehaviour)w).IsOwner && ((Component)w).gameObject.layer != 7); if ((Object)(object)portalRailWeapon == (Object)null) { result.Text = "error: hold a Portal Rail first (give rail)"; break; } string text3 = portalRailWeapon.DebugFire(text2 == "b"); result.Text = ((text3 == null) ? ("ok fired Portal " + text2.ToUpperInvariant() + " (the result is in LogOutput.log)") : ("error: " + text3)); break; } case "mode-run": { PortalModeKind result18; if (!ModeNet.IsServer) { result.Text = "error: host only"; } else if (text2 == "stop") { HideAndSeekMode.SoloTest = false; PortalModes.Force(null, startNow: true); result.Text = "ok mode stopped"; } else if (!Enum.TryParse<PortalModeKind>(text2, ignoreCase: true, out result18) || PortalModes.Get(result18) == null) { result.Text = "error: mode-run Arena|HideAndSeek|Territory|TrickShots|PocketPortals|Dimension|stop"; } else { HideAndSeekMode.SoloTest = result18 == PortalModeKind.HideAndSeek; PortalModes.Force(PortalModes.Get(result18), startNow: true); result.Text = "ok running " + result18; } break; } case "blind": result.Text = Blind(text2); break; case "summary": result.Text = ModeStats.DebugSummary(); break; case "reveal": result.Text = HiderReveal.Debug(text2); break; case "hide-mode": if (!ModeNet.IsServer) { result.Text = "error: host only"; } else if (!GameAccess.InExplorationMap()) { result.Text = "error: exploration maps only"; } else if (text2 == "stop") { HideAndSeekMode.SoloTest = false; PortalModes.Force(null, startNow: true); result.Text = "ok Hide and Seek stopped"; } else { HideAndSeekMode.SoloTest = true; PortalModes.Force(HideAndSeekMode.Instance, startNow: true); result.Text = string.Format("ok Hide and Seek started, everyone hides (Hide {0:0} s, Seek {1:0} s, Forced taunt {2})", PortalModes.Settings.HideTime, PortalModes.Settings.SeekTime, PortalModes.Settings.ForcedTaunt ? "on" : "off"); } break; case "trick-mode": result.Text = TrickMode(text2); break; case "pocket-mode": result.Text = PocketMode(text2); break; case "trick-rule": result.Text = TrickRule(text2); break; case "trick-show": result.Text = TrickShots.DebugShow(text2); break; case "teleporters": result.Text = Teleporters(text2); break; case "perf": result.Text = PerfProbe.Command(text2); break; case "hands": result.Text = Hands(text2); break; case "door-key": if (text2 == "down") { DimensionMode.DebugHeld = true; } else if (text2 == "up") { DimensionMode.DebugHeld = false; } else if (text2 != "" && text2 != "state") { result.Text = "error: door-key down|up|state"; break; } result.Text = "ok " + DimensionMode.Describe(); break; case "taunt": result.Text = Taunt(text2); break; case "pose": result.Text = PoseCommand(text2); break; case "wheel": { string[] array4 = text2.Split(' '); float result15; float result16; if (array4[0] == "release") { HiderLook.DebugHeld = false; result.Text = "ok wheel released"; } else if (array4[0] == "open" && array4.Length >= 3 && float.TryParse(array4[1], out result15) && float.TryParse(array4[2], out result16)) { HiderLook.DebugAim = new Vector2(result15, result16); HiderLook.DebugHeld = true; result.Text = "ok wheel held open"; } else { result.Text = "error: wheel open <x> <y> | wheel release"; } break; } case "pose-gap": result.Text = $"ok {Poses.LastGapPose}: lowest point {Poses.LastGap:+0.000;-0.000} m from the floor"; Poses.GapRequested = true; break; case "self-view": result.Text = PoseDebug.SelfView(text2.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); break; case "view": { string[] array2 = text2.Split(' '); float result5; float result6; float result7; float result8; float result9; float result10; float result11; if (array2[0] == "off") { HiderView.DebugMode = "off"; result.Text = "ok view off"; } else if (array2[0] == "self" || array2[0] == "free") { HiderView.DebugMode = array2[0]; result.Text = "ok view " + array2[0]; } else if (array2[0] == "fly" && array2.Length >= 4 && float.TryParse(array2[1], out result5) && float.TryParse(array2[2], out result6) && float.TryParse(array2[3], out result7)) { HiderView.DebugFly = new Vector3(result5, result6, result7); result.Text = "ok flying"; } else if (array2[0] == "spin" && array2.Length >= 2 && float.TryParse(array2[1], out result8)) { HiderView.DebugSpin = result8; result.Text = $"ok turning {result8:0} deg/s"; } else if (array2[0] == "drift" && array2.Length >= 4 && float.TryParse(array2[1], out result9) && float.TryParse(array2[2], out result10) && float.TryParse(array2[3], out result11)) { HiderView.DebugDrift = new Vector3(result9, result10, result11); result.Text = "ok gliding (right, up, forward) m/s"; } else { result.Text = "error: view self|free|off | view fly <dx> <dy> <dz> | view spin <deg/s> | view drift <right> <up> <forward>"; } break; } case "pose-try": result.Text = Poses.Try(text2); break; case "forced-taunt": { if (!ModeNet.IsServer) { result.Text = "error: host only"; break; } ModeNet.SendCommand(ModeCommand.ForcedTaunt, ModePlayers.LocalId(), new int[1] { int.TryParse(text2, out var result4) ? result4 : 300 }); result.Text = "ok forced taunt sent (see the log for its range)"; break; } case "rig": result.Text = PoseDebug.Rig(); break; case "shot-self": result.Text = PoseDebug.ShotSelf(_shotDir, text2.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); break; default: result.Text = "error: unknown command '" + text + "' (shot, ui-dump, open-portal-settings, close-portal-settings, click, select, hit, key, mouse, give, give-item, portal, placement, trick-mode, trick-rule, trick-show, pocket-mode, hands, taunt, explore, look, tp, where, territory, teleporters, wait)"; break; } } catch (Exception ex) { result.Text = "error: " + ex.GetType().Name + ": " + ex.Message; Plugin.Log.LogInfo((object)$"Debug command '{line}' threw: {ex}"); } } private static IEnumerator Key(string name, Result result) { Keyboard keyboard = Keyboard.current; if (keyboard == null) { result.Text = "error: no keyboard"; yield break; } if (!Enum.TryParse<Key>(name, ignoreCase: true, out Key result2) || (int)result2 == 0) { result.Text = "error: '" + name + "' is not an Input System Key name (Escape, Space, Enter, F8, A, ...)"; yield break; } Inject<KeyboardState>((InputDevice)(object)keyboard, new KeyboardState((Key[])(object)new Key[1] { (Key)(int)result2 })); yield return null; yield return null; Inject<KeyboardState>((InputDevice)(object)keyboard, default(KeyboardState)); yield return null; result.Text = "ok"; } private static IEnumerator MineSweep(string arg, Result result) { float[] v = Numbers(arg); FirstPersonController body = GameAccess.LocalPlayer(); if (v == null || v.Length != 5 || v[4] <= 0f || (Object)(object)body == (Object)null) { result.Text = "error: mine-sweep yaw0 yaw1 pitch0 pitch1 step (with a local player)"; yield break; } PortalMineWeapon mine = Object.FindObjectsOfType<PortalMineWeapon>().FirstOrDefault((PortalMineWeapon w) => ((NetworkBehaviour)w).IsOwner && ((Component)w).gameObject.layer != 7); if ((Object)(object)mine == (Object)null) { result.Text = "error: no held Portal Mine"; yield break; } int can = 0; int total = 0; CultureInfo inv = CultureInfo.InvariantCulture; Plugin.Log.LogInfo((object)$"MineSweep start body {((Component)body).transform.position:F3}"); for (float pitch = v[2]; pitch <= v[3] + 0.001f; pitch += v[4]) { StringBuilder row = new StringBuilder(); for (float yaw = v[0]; yaw <= v[1] + 0.001f; yaw += v[4]) { Look(yaw.ToString(inv) + " " + pitch.ToString(inv)); yield return null; yield return null; yield return null; if ((Object)(object)mine == (Object)null) { result.Text = "error: the Portal Mine went away"; yield break; } string placementState = mine.PlacementState; total++; bool flag = placementState.StartsWith("can place"); if (flag) { can++; } row.Append(flag ? 'O' : (placementState.Contains("flat room") ? 'x' : (placementState.StartsWith("nothing") ? '.' : '?'))); Plugin.Log.LogInfo((object)$"MineSweep yaw {yaw:0.#} pitch {pitch:0.#} eye {((Component)body.playerCamera).transform.position:F3}: {placementState}"); } Plugin.Log.LogInfo((object)$"MineSweepRow pitch {pitch,6:0.#} {row}"); } result.Text = $"ok can place at {can} of {total} aims"; } private static string KeyHold(string arg) { //IL_0069: 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) Keyboard current = Keyboard.current; if (current == null) { return "error: no keyboard"; } string[] array = arg.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length < 2 || !float.TryParse(array[^1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || result <= 0f) { return "error: key-hold <key> [key ...] <seconds>"; } List<Key> list = new List<Key>(); for (int i = 0; i < array.Length - 1; i++) { if (!Enum.TryParse<Key>(array[i], ignoreCase: true, out Key result2) || (int)result2 == 0) { return "error: '" + array[i] + "' is not an Input System Key name"; } list.Add(result2); } ((MonoBehaviour)_instance).StartCoroutine(HoldKeys(current, list.ToArray(), result)); return string.Format("ok holding {0} for {1:0.##} s", string.Join("+", list), result); } private static IEnumerator HoldKeys(Keyboard keyboard, Key[] keys, float seconds) { float until = Time.unscaledTime + seconds; while (Time.unscaledTime < until) { Inject<KeyboardState>((InputDevice)(object)keyboard, new KeyboardState(keys)); yield return null; } Inject<KeyboardState>((InputDevice)(object)keyboard, default(KeyboardState)); } private static string Track(string arg) { if (!float.TryParse(arg, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || result <= 0f) { return "error: track <seconds>"; } ((MonoBehaviour)_instance).StartCoroutine(TrackLoop(result)); return $"ok tracking for {result:0.##} s (lines start 'Track:')"; } private static IEnumerator TrackLoop(float seconds) { float until = Time.unscaledTime + seconds; while (Time.unscaledTime < until) { StringBuilder stringBuilder = new StringBuilder($"Track: t {Time.unscaledTime:F2}"); FirstPersonController[] array = Object.FindObjectsOfType<FirstPersonController>(); foreach (FirstPersonController val in array) { if (((NetworkBehaviour)val).IsOwner) { continue; } stringBuilder.Append($" | player {((NetworkBehaviour)val).OwnerId} body {((Component)val).transform.position:F1}"); if ((Object)(object)val.playerCameraHolder != (Object)null) { stringBuilder.Append($" camHolder {val.playerCameraHolder.transform.position:F1}"); } AudioSource[] componentsInChildren = ((Component)val).GetComponentsInChildren<AudioSource>(true); foreach (AudioSource val2 in componentsInChildren) { if (val2.isPlaying) { stringBuilder.Append(string.Format(" playing '{0}'{1} at {2:F1}", ((Object)val2).name, ((Object)(object)val2.clip != (Object)null) ? ("/" + ((Object)val2.clip).name) : "", ((Component)val2).transform.position)); } } } ClientInstance[] array2 = Object.FindObjectsOfType<ClientInstance>(); foreach (ClientInstance val3 in array2) { if (!((NetworkBehaviour)val3).IsOwner) { AudioSource voiceChatSource = val3.voiceChatSource; stringBuilder.Append($" | client {((NetworkBehaviour)val3).OwnerId} obj {((Component)val3).transform.position:F1}"); if ((Object)(object)voiceChatSource != (Object)null) { stringBuilder.Append(string.Format(" voiceSrc '{0}' at {1:F1} blend {2:F2}{3}", ((Object)voiceChatSource).name, ((Component)voiceChatSource).transform.position, voiceChatSource.spatialBlend, voiceChatSource.isPlaying ? " playing" : "")); } } } Plugin.Log.LogInfo((object)stringBuilder.ToString()); yield return (object)new WaitForSecondsRealtime(0.2f); } } private static IEnumerator Mouse(string name, Result result) { Mouse mouse = Mouse.current; if (mouse == null) { result.Text = "error: no mouse"; yield break; } if (name.StartsWith("move ")) { string[] array = name.Substring(5).Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length != 2 || !float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) || !float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3)) { result.Text = "error: mouse move <x> <y>, fractions of the screen from its top-left (0.5 0.5 = the middle)"; yield break; } _heldMouse.position = new Vector2(result2 * (float)Screen.width, (1f - result3) * (float)Screen.height); Inject<MouseState>((InputDevice)(object)mouse, _heldMouse); yield return null; yield return null; result.Text = $"ok pointer at {_heldMouse.position.x:0},{_heldMouse.position.y:0} px"; yield break; } if (name == "scroll-up" || name == "scroll-down") { MouseState heldMouse = _heldMouse; heldMouse.scroll = new Vector2(0f, (name == "scroll-up") ? 120f : (-120f)); Inject<MouseState>((InputDevice)(object)mouse, heldMouse); yield return null; Inject<MouseState>((InputDevice)(object)mouse, _heldMouse); yield return null; result.Text = "ok"; yield break; } bool flag = name.EndsWith("-down"); bool flag2 = name.EndsWith("-up"); MouseButton val; switch (flag ? name.Substring(0, name.Length - 5) : (flag2 ? name.Substring(0, name.Length - 3) : name)) { case "left": val = (MouseButton)0; break; case "right": val = (MouseButton)1; break; case "middle": val = (MouseButton)2; break; default: result.Text = "error: mouse left|right|middle, <button>-down / <button>-up to hold one, or scroll-up|scroll-down"; yield break; } if (flag || flag2) { _heldMouse = ((MouseState)(ref _heldMouse)).WithButton(val, flag); Inject<MouseState>((InputDevice)(object)mouse, _heldMouse); yield return null; yield return null; result.Text = "ok"; } else { MouseState heldMouse2 = _heldMouse; Inject<MouseState>((InputDevice)(object)mouse, ((MouseState)(ref heldMouse2)).WithButton(val, true)); yield return null; yield return null; Inject<MouseState>((InputDevice)(object)mouse, _heldMouse); yield return null; result.Text = "ok"; } } private static IEnumerator Shot(string name, Result result) { if (name.Length == 0 || name.Any((char c) => !char.IsLetterOrDigit(c) && c != '-' && c != '_' && c != '.')) { result.Text = "error: shot needs a name of letters, digits, '-', '_' or '.'"; yield break; } string path = Path.Combine(_shotDir, name.EndsWith(".png") ? name : (name + ".png")); try { Directory.CreateDirectory(_shotDir); if (File.Exists(path)) { File.Delete(path); } ScreenCapture.CaptureScreenshot(path); } catch (Exception ex) { result.Text = "error: " + ex.Message; yield break; } float deadline = Time.realtimeSinceStartup + 10f; long lastSize = -1L; while (Time.realtimeSinceStartup < deadline) { yield return null; long num = (File.Exists(path) ? new FileInfo(path).Length : (-1)); if (num > 0 && num == lastSize) { result.Text = "ok " + path; yield break; } lastSize = num; } result.Text = $"error: no screenshot at '{path}' after {10f} s"; } private static string UiDump(bool all) { //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_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); object[] obj = new object[4] { DateTime.Now, null, null, null }; Scene activeScene = SceneManager.GetActiveScene(); obj[1] = ((Scene)(ref activeScene)).name; obj[2] = Screen.width; obj[3] = Screen.height; stringBuilder.AppendLine(string.Format("# ui-dump {0:yyyy-MM-dd HH:mm:ss}; scene '{1}'; screen {2}x{3}; ", obj) + "rect = screen pixels x,y (bottom-left) w x h; inactive subtrees " + (all ? "expanded" : "collapsed (ui-dump all expands them)")); int count = 0; foreach (Canvas item in from c in Resources.FindObjectsOfTypeAll<Canvas>().Where(delegate(Canvas c) { //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) if ((Object)(object)c != (Object)null) { Scene scene = ((Component)c).gameObject.scene; if (((Scene)(ref scene)).IsValid()) { return c.isRootCanvas; } } return false; }) orderby FullPath(((Component)c).transform) select c) { if (all || ((Component)item).gameObject.activeInHierarchy) { Camera cam = (((int)item.renderMode == 0) ? null : item.worldCamera); stringBuilder.AppendLine($"## canvas '{FullPath(((Component)item).transform)}' mode={item.renderMode} sortingOrder={item.sortingOrder}"); DumpNode(((Component)item).transform, cam, all, stringBuilder, ref count); } } Directory.CreateDirectory(_shotDir); string text = Path.Combine(_shotDir, "ui-dump.txt"); File.WriteAllText(text, stringBuilder.ToString()); return $"ok {text} ({count} objects)"; } private static void DumpNode(Transform t, Camera cam, bool all, StringBuilder sb, ref int count) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) count++; GameObject gameObject = ((Component)t).gameObject; sb.Append(gameObject.activeInHierarchy ? "+ " : (gameObject.activeSelf ? "~ " : "- ")); sb.Append(FullPath(t)); RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null); if (val != null) { Rect val2 = ScreenRect(val, cam); sb.Append($" [{((Rect)(ref val2)).x:F0},{((Rect)(ref val2)).y:F0} {((Rect)(ref val2)).width:F0}x{((Rect)(ref val2)).height:F0}]"); } List<string> list = new List<string>(); Component[] components = gameObject.GetComponents<Component>(); foreach (Component val3 in components) { if (!((Object)(object)val3 == (Object)null) && !(val3 is Transform) && !(val3 is CanvasRenderer)) { string text = ((object)val3).GetType().Name; Selectable val4 = (Selectable)(object)((val3 is Selectable) ? val3 : null); if (val4 != null && !val4.interactable) { text += "(off)"; } Behaviour val5 = (Behaviour)(object)((val3 is Behaviour) ? val3 : null); if (val5 != null && !val5.enabled) { text += "(disabled)"; } list.Add(text); } } if (list.Count > 0) { sb.Append(" {" + string.Join(", ", list) + "}"); } TMP_Text component = gameObject.GetComponent<TMP_Text>(); if ((Object)(object)component != (Object)null && !string.IsNullOrEmpty(component.text)) { sb.Append(" \"" + Short(component.text) + "\""); } Text component2 = gameObject.GetComponent<Text>(); if ((Object)(object)component2 != (Object)null && !string.IsNullOrEmpty(component2.text)) { sb.Append(" \"" + Short(component2.text) + "\""); } sb.AppendLine(); if (gameObject.activeSelf || all) { for (int j = 0; j < t.childCount; j++) { DumpNode(t.GetChild(j), cam, all, sb, ref count); } } } private static string Short(string s) { s = s.Replace("\n", "\\n").Replace("\r", ""); if (s.Length <= 60) { return s; } return s.Substring(0, 60) + "..."; } private static Rect ScreenRect(RectTransform rt, Camera cam) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: 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_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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_0052: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_0072: 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_007e: Unknown result type (might be due to invalid IL or missing references) rt.GetWorldCorners(Corners); Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(float.MaxValue, float.MaxValue); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(float.MinValue, float.MinValue); Vector3[] corners = Corners; foreach (Vector3 val3 in corners) { Vector2 val4 = RectTransformUtility.WorldToScreenPoint(cam, val3); val = Vector2.Min(val, val4); val2 = Vector2.Max(val2, val4); } return Rect.MinMaxRect(val.x, val.y, val2.x, val2.y); } private static string Click(string path) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown if (path.Length == 0) { return "error: click needs a hierarchy path"; } GameObject val = Find(path); if ((Object)(object)val == (Object)null) { return "error: nothing at '" + path + "'"; } if (!val.activeInHierarchy) { return "error: '" + path + "' is inactive"; } Selectable component = val.GetComponent<Selectable>(); if ((Object)(object)component != (Object)null && !component.IsInteractable()) { return "error: '" + path + "' is not interactable"; } PointerEventData val2 = new PointerEventData(EventSystem.current) { button = (InputButton)0 }; GameObject val3 = ExecuteEvents.ExecuteHierarchy<IPointerClickHandler>(val, (BaseEventData)(object)val2, ExecuteEvents.pointerClickHandler); if ((Object)(object)val3 == (Object)null) { return "error: '" + path + "' has no click handler"; } return "ok clicked " + ((Object)val3).name + " (" + string.Join(", ", from h in val3.GetComponents<IPointerClickHandler>() select ((object)h).GetType().Name) + ")"; } private static string Hit(string path) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_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_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: 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_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) GameObject val = Find(path); if ((Object)(object)val == (Object)null) { return "error: nothing at '" + path + "'"; } if (!val.activeInHierarchy) { return "error: '" + path + "' is inactive"; } Transform transform = val.transform; RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null); if ((Object)(object)val2 == (Object)null) { return "error: '" + path + "' is not UI"; } EventSystem current = EventSystem.current; if ((Object)(object)current == (Object)null) { return "error: no EventSystem"; } Canvas componentInParent = val.GetComponentInParent<Canvas>(); Camera cam = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.rootCanvas.renderMode != 0) ? componentInParent.rootCanvas.worldCamera : null); Rect val3 = ScreenRect(val2, cam); Vector2 center = ((Rect)(ref val3)).center; List<RaycastResult> list = new List<RaycastResult>(); current.RaycastAll(new PointerEventData(current) { position = center }, list); if (list.Count == 0) { return $"ok at {center.x:0},{center.y:0}: nothing"; } RaycastResult val4 = list[0]; bool flag = ((RaycastResult)(ref val4)).gameObject.transform.IsChildOf(val.transform); string text = string.Join(" > ", from r in list.Take(4) select $"'{((Object)((RaycastResult)(ref r)).gameObject).name}' ({((object)r.module)?.GetType().Name} depth {r.depth})"); return string.Format("ok at {0:0},{1:0}: {2}: {3}", center.x, center.y, flag ? "reaches it" : "BLOCKED", text); } private static string Select(string arg) { int num = arg.IndexOf(' '); if (num < 0 || !int.TryParse(arg.Substring(0, num), out var result)) { return "error: select <index> <hierarchy path>"; } string text = arg.Substring(num + 1).Trim(); GameObject val = Find(text); if ((Object)(object)val == (Object)null) { return "error: nothing at '" + text + "'"; } TMP_Dropdown component = val.GetComponent<TMP_Dropdown>(); if ((Object)(object)component == (Object)null) { return "error: '" + text + "' has no TMP_Dropdown"; } if (!((Selectable)component).IsInteractable()) { return "error: '" + text + "' is not interactable"; } if (result < 0 || result >= component.options.Count) { return $"error: index {result} out of 0..{component.options.Count - 1}"; } component.value = result; return $"ok '{component.options[component.value].text}' (value {component.value})"; } private static GameObject Find(string path) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) string[] array = path.Split('/'); Transform[] array2 = Resources.FindObjectsOfTypeAll<Transform>(); foreach (Transform val in array2) { if ((Object)(object)val.parent != (Object)null) { continue; } Scene scene = ((Component)val).gameObject.scene; if (!((Scene)(ref scene)).IsValid() || ((Object)val).name != array[0]) { continue; } Transform val2 = val; for (int j = 1; j < array.Length; j++) { if (!((Object)(object)val2 != (Object)null)) { break; } val2 = ChildNamed(val2, array[j]); } if ((Object)(object)val2 != (Object)null) { return ((Component)val2).gameObject; } } return null; } private static Transform ChildNamed(Transform parent, string name) { for (int i = 0; i < parent.childCount; i++) { if (((Object)parent.GetChild(i)).name == name) { return parent.GetChild(i); } } return null; } private static string Give(string what) { string[] words = what.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length >= 2 && (words[0] == "spirit" || words[0] == "gun")) { if (!ModeNet.IsServer) { return "error: only the host can give weapons"; } SpawnerManager.PopulateAllWeapons(); GameObject val = (GameObject)((words[0] == "spirit") ? ((object)SpiritGuns.Prefab(words[1])) : ((object)((IEnumerable<GameObject>)SpawnerManager.AllWeapons).FirstOrDefault((Func<GameObject, bool>)((GameObject w) => (Object)(object)w != (Object)null && string.Equals(((Object)w).name, words[1], StringComparison.OrdinalIgnoreCase))))); if ((Object)(object)val == (Object)null) { if (!(words[0] == "spirit")) { return "error: no weapon named '" + words[1] + "' (weapon-tiers lists them)"; } return "error: give spirit " + string.Join("|", SpiritGuns.Bases).ToLowerInvariant() + " [player id]"; } int result = ModePlayers.LocalId(); if (words.Length > 2 && !int.TryParse(words[2], out result)) { return "error: the player id is a number (see 'dimension')"; } NetworkObject val2 = ModeWeapons.Give(result, val); if (!((Object)(object)val2 != (Object)null)) { return $"error: could not give player {result} a {((Object)val).name} (see LogOutput.log)"; } return $"ok gave player {result} a {((Object)val).name} (weapon {val2.ObjectId})"; } PortalGunKind kind; switch (what) { case "rail": kind = PortalGunKind.Rail; break; case "launcher": kind = PortalGunKind.Launcher; break; case "mine": kind = PortalGunKind.Mine; break; case "door": kind = PortalGunKind.Door; break; default: return "error: give rail|launcher|mine|door, give spirit <base> [player id], give gun <prefab name> [player id]"; } DebugGive.TryGive(kind, inHand: true, anyMap: true); return "ok, into the player's hands (the result is in LogOutput.log)"; } private static IEnumerator Hold(string name, Result result) { string text = GiveItem(name); if (!text.StartsWith("ok")) { result.Text = text; yield break; } FirstPersonController player = GameAccess.LocalPlayer(); GameObject item = null; Weapon[] array = Object.FindObjectsOfType<Weapon>(); foreach (Weapon val in array) { if (((Object)val).name.StartsWith(name) && ((Object)(object)item == (Object)null || Vector3.Distance(((Component)val).transform.position, ((Component)player).transform.position) < Vector3.Distance(item.transform.position, ((Component)player).transform.position))) { item = ((Component)val).gameObject; } } for (int j = 0; j < 120; j++) { yield return null; if ((Object)(object)item != (Object)null && ModeClient.DebugPickUp(player, item)) { result.Text = "ok holding " + name; yield break; } } result.Text = "error: could not hold " + name; } private static string GiveItem(string name) { //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_018a: 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_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: 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_0212: Unknown result type (might be due to invalid IL or missing references) SpawnerManager.PopulateAllWeapons(); if (name.Length == 0) { IEnumerable<string> values = from w in SpawnerManager.AllWeapons where (Object)(object)w != (Object)null && (Object)(object)w.GetComponent<WeaponHandSpawner>() != (Object)null select ((Object)w).name; return "error: give-item <name>; placeables: " + string.Join(", ", values); } bool flag = name.EndsWith(" other"); if (flag) { name = name.Substring(0, name.Length - " other".Length).Trim(); } GameObject val = ((IEnumerable<GameObject>)SpawnerManager.AllWeapons).FirstOrDefault((Func<GameObject, bool>)((GameObject w) => (Object)(object)w != (Object)null && ((Object)w).name == name)); if ((Object)(object)val == (Object)null) { return "error: no weapon named '" + name + "'"; } FirstPersonController player = GameAccess.LocalPlayer(); if ((Object)(object)player == (Object)null) { return "error: no local player"; } NetworkManager networkManager = InstanceFinder.NetworkManager; if ((Object)(object)networkManager == (Object)null || !networkManager.IsServer) { return "error: only the host can spawn weapons"; } Transform transform = ((Component)player).transform; if (flag) { FirstPersonController val2 = ((IEnumerable<FirstPersonController>)Object.FindObjectsOfType<FirstPersonController>()).FirstOrDefault((Func<FirstPersonController, bool>)((FirstPersonController p) => (Object)(object)p != (Object)(object)player)); if ((Object)(object)val2 == (Object)null) { return "error: no other player"; } transform = ((Component)val2).transform; } Vector3 val3 = transform.position + Vector3.up * 1.4f + transform.forward * 1.2f; GameObject val4 = Object.Instantiate<GameObject>(val, val3, Quaternion.LookRotation(transform.right)); networkManager.ServerManager.Spawn(val4, (NetworkConnection)null); ItemBehaviour component = val4.GetComponent<ItemBehaviour>(); if (component != null) { component.DispenserDrop(transform.forward * 0.3f + Vector3.up * 0.3f); } return $"ok dropped {name} at {val3:F1}"; } private static string PlacePortal(string which) { //IL_00c0: 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 (which != "a" && which != "b") { return "error: portal a|b"; } FirstPersonController val = GameAccess.LocalPlayer(); Camera val2 = (((Object)(object)val != (Object)null) ? val.playerCamera : null); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return "error: no local player or camera"; } PortalPose pose; Vector3 fizzlePoint; Vector3 fizzleNormal; string reason; Dimension landedIn; ShotResult shotResult = PortalPlacement.Resolve(((Component)val2).transform, ((Component)val).gameObject, null, out pose, out fizzlePoint, out fizzleNormal, out reason, out landedIn); if (shotResult != ShotResult.Placed) { return $"error: {shotResult} ({reason})"; } GameObject gameObject = ((Component)val).gameObject; bool isB = which == "b"; PortalPose pose2 = pose; Dimension dimension = landedIn; PortalManager.Place(gameObject, isB, pose2, minePortal: false, null, dimension); return $"ok Portal {which} at {pose.Position:F2} normal {pose.Normal:F2} in {Dimensions.Name(landedIn)}"; } private static string HeadWarp(string which) { //IL_006a: 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) if (which != "a" && which != "b") { return "error: headwarp a|b (the colour of the shot)"; } FirstPersonController val = GameAccess.LocalPlayer(); Camera val2 = (((Object)(object)val != (Object)null) ? val.playerCamera : null); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return "error: no local player or camera"; } bool flag = which == "b"; PortalGunWeapon.ShowWarp(((Component)val).gameObject, flag, ((Component)val2).transform.position, ownedByViewer: true); string text = HeadshotWarp.Arrive(((Component)val).gameObject, flag); if (text != null) { return "ok not warped: " + text; } return string.Format("ok warped out of Portal {0}, now at {1:F2}", flag ? "A" : "B", ((Component)val).transform.position); } private static string HeadProbe() { FirstPersonController val = GameAccess.LocalPlayer(); Camera val2 = (((Object)(object)val != (Object)null) ? val.playerCamera : null); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return "error: no local player or camera"; } List<Collider> list = new List<Collider>(); Collider[] componentsInChildren = ((Component)val).GetComponentsInChildren<Collider>(true); foreach (Collider val3 in componentsInChildren) { if (((Component)val3).gameObject.layer == 16 && ((Object)val3).name.EndsWith("_Col")) { ((Component)val3).gameObject.layer = 11; list.Add(val3); } } Physics.SyncTransforms(); try { return HeadProbeNow(val, val2); } finally { foreach (Collider item in list) { ((Component)item).gameObject.layer = 16; } } } private static string HeadshotTest(string which) { //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: 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_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0162: 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_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0175: 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_017c: 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_019b: 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_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: 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) if (which != "a" && which != "b") { return "error: headshot-test a|b (the colour of the shot)"; } FirstPersonController val = GameAccess.LocalPlayer(); Camera val2 = (((Object)(object)val != (Object)null) ? val.playerCamera : null); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return "error: no local player or camera"; } PortalGunWeapon portalGunWeapon = Object.FindObjectsOfType<PortalGunWeapon>().FirstOrDefault((PortalGunWeapon w) => ((NetworkBehaviour)w).IsOwner && ((Component)w).gameObject.layer != 7); if ((Object)(object)portalGunWeapon == (Object)null) { return "error: hold a Portal Gun first (give rail)"; } List<Collider> list = new List<Collider>(); Collider[] componentsInChildren = ((Component)val).GetComponentsInChildren<Collider>(true); foreach (Collider val3 in componentsInChildren) { if (((Component)val3).gameObject.layer == 16 && ((Object)val3).name.EndsWith("_Col")) { ((Component)val3).gameObject.layer = 11; list.Add(val3); } } Transform val4 = ((Component)val).GetComponent<PlayerSetup>()?.hatToWearPosition; bool active = (Object)(object)val4 != (Object)null && ((Component)val4).gameObject.activeSelf; if ((Object)(object)val4 != (Object)null) { ((Component)val4).gameObject.SetActive(true); } Physics.SyncTransforms(); try { Vector3 travel = Vector3.ProjectOnPlane(((Component)val).transform.forward, Vector3.up); Vector3 normalized = ((Vector3)(ref travel)).normalized; Vector3 origin = ((Component)val2).transform.position + normalized * 3f; Vector3 dir = -normalized; RaycastHit hit; Dimension landedIn; bool touched = PortalPlacement.Trace(origin, dir, 6f, null, (Weapon)(object)portalGunWeapon, null, out hit, out travel, out landedIn); string text = "trace stops on " + Describe(touched, hit); if (!HeadshotWarp.FindHead(origin, dir, 6f, null, (Weapon)(object)portalGunWeapon, out var victim, out var point)) { return "error: no headshot; " + text; } portalGunWeapon.Headshot(((Component)val).gameObject, which == "b", victim, point, dir); return $"ok headshot on {((Object)victim).name} at {point:F2}; {text}"; } finally { foreach (Collider item in list) { ((Component)item).gameObject.layer = 16; } if ((Object)(object)val4 != (Object)null) { ((Component)val4).gameObject.SetActive(active); } } static string Describe(bool flag, RaycastHit h) { if (!flag) { return "nothing"; } return string.Format("'{0}' (layer {1}{2}) at {3:F2} m", ((Object)((RaycastHit)(ref h)).collider).name, ((Component)((RaycastHit)(ref h)).collider).gameObject.layer, ((RaycastHit)(ref h)).collider.isTrigger ? ", trigger" : "", ((RaycastHit)(ref h)).distance); } } private static string AimHead() { //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_00f0: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0200: 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_0209: 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_0096: 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) FirstPersonController val = GameAccess.LocalPlayer(); Camera val2 = (((Object)(object)val != (Object)null) ? val.playerCamera : null); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return "error: no local player or camera"; } Collider val3 = null; float num = float.MaxValue; PlayerHealth[] array = Object.FindObjectsOfType<PlayerHealth>(); Bounds bounds; foreach (PlayerHealth val4 in array) { if ((Object)(object)((Component)val4).gameObject == (Object)(object)((Component)val).gameObject) { continue; } Collider[] componentsInChildren = ((Component)val4).GetComponentsInChildren<Collider>(); foreach (Collider val5 in componentsInChildren) { if (!(((Object)val5).name != "Head_Col")) { bounds = val5.bounds; float num2 = Vector3.Distance(((Bounds)(ref bounds)).center, ((Component)val2).transform.position); if (num2 < num) { num = num2; val3 = val5; } } } } if ((Object)(object)val3 == (Object)null) { return "error: no other player's head"; } bounds = val3.bounds; Vector3 val6 = ((Bounds)(ref bounds)).center - ((Component)val2).transform.position; float num3 = Mathf.Atan2(val6.x, val6.z) * 57.29578f; float num4 = (0f - Mathf.Asin(Mathf.Clamp(val6.y / ((Vector3)(ref val6)).magnitude, -1f, 1f))) * 57.29578f; ((Component)val).transform.rotation = Quaternion.Euler(0f, num3, 0f); val.rotationX = num4; Physics.SyncTransforms(); string text = "nothing"; if (PortalPlacement.NearestHit(((Component)val2).transform.position, ((Vector3)(ref val6)).normalized, 200f, ((Component)val).gameObject, null, out var best)) { text = $"'{((Object)((RaycastHit)(ref best)).collider).name}' (layer {((Component)((RaycastHit)(ref best)).collider).gameObject.layer}) at {((RaycastHit)(ref best)).distance:F2} m"; } object[] obj = new object[8] { ((Object)((Component)val3).transform.root).name, null, null, null, null, null, null, null }; bounds = val3.bounds; obj[1] = ((Bounds)(ref bounds)).center; obj[2] = num; obj[3] = num3; obj[4] = num4; obj[5] = ((Component)val3).gameObject.layer; obj[6] = (val3.enabled ? "" : ", off"); obj[7] = text; return string.Format("ok aimed at {0}'s head at {1:F2}, {2:F1} m (yaw {3:0.#} pitch {4:0.#}, layer {5}{6}); first along the aim: {7}", obj); } private static string HeadProbeNow(FirstPersonController player, Camera cam) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: 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_0030: 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_0044: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Vector3.ProjectOnPlane(((Component)player).transform.forward, Vector3.up); Vector3 forward = ((Vector3)(ref val)).normalized; Vector3 position = ((Component)cam).transform.position; string text = Probe("head", position); string text2 = Probe("chest", position + Vector3.down * 0.6f); List<string> list = new List<string>(); Collider[] componentsInChildren = ((Component)player).GetComponentsInChildren<Collider>(true); foreach (Collider val2 in componentsInChildren) { if (((Component)val2).gameObject.layer == 11) { list.Add(((Object)val2).name + (val2.enabled ? "" : "(off)") + (val2.isTrigger ? "(trigger)" : "")); } } return "ok " + text + "; " + text2 + "; hitboxes: " + string.Join(", ", list); string Probe(string name, Vector3 target) { //IL_0000: 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_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_0017: 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_004b: Unknown result type (might be due to invalid IL or missing references) if (!HeadshotWarp.FindHead(target + forward * 3f, -forward, 4f, null, null, out var victim, out var point)) { return name + ": no headshot"; } return $"{name}: headshot on {((Object)victim).name} at {point:F2}"; } } private static string DescribePreview(WeaponHandSpawner w) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) Transform val = GameAccess.PlacementPreview.Invoke(w); if ((Object)(object)val == (Object)null) { return "no preview"; } IEnumerable<string> values = from r in ((Component)val).GetComponentsInChildren<Renderer>(true) select string.Format("{0} layer {1} {2}", ((Object)r).name, ((Component)r).gameObject.layer, r.enabled ? "on" : "off"); return string.Format("preview {0} at {1:F2} up {2:F2} layer {3}, renderers [{4}]", ((Component)val).gameObject.activeInHierarchy ? "shown" : "hidden", val.position, val.up, ((Component)val).gameObject.layer, string.Join(", ", values)); } private static string Placement() { List<WeaponHandSpawner> list = (from w in Object.FindObjectsOfType<WeaponHandSpawner>() where ((NetworkBehaviour)w).IsOwner && ((Component)w).gameObject.layer != 7 select w).ToList(); string text = ((list.Count == 0) ? "no held placeable weapon" : string.Join("; ", list.Select((WeaponHandSpawner w) => ((Object)w).name + ": " + (CanPlace.Invoke(w) ? $"can place at {PlacePosition.Invoke(w):F2}" : "cannot place") + ", " + DescribePreview(w)))); List<string> list2 = (from m in Object.FindObjectsOfType<ProximityMine>() select $"{((Object)m).name} at {((Component)m).transform.position:F2}").Concat(from c in Object.FindObjectsOfType<Claymore>() select $"{((Object)c).name} at {((Component)c).transform.position:F2}").ToList(); List<string> list3 = (from w in Object.FindObjectsOfType<PortalMineWeapon>() where ((NetworkBehaviour)w).IsOwner && ((Component)w).gameObject.layer != 7 select ((Object)w).name + ": " + w.PlacementState).ToList(); if (list3.Count > 0) { text = ((list.Count == 0) ? "" : (text + "; ")) + string.Join("; ", list3); } return "ok " + text + "; placed: " + ((list2.Count == 0) ? "none" : string.Join(", ", list2)) + "; Primed Mines: " + PrimedMines.Describe(); } private static string TrickMode(string arg) { if (!ModeNet.IsServer) { return "error: host only"; } if (!GameAccess.InExplorationMap()) { return "error: exploration maps only"; } if (arg == "stop") { PortalModes.Force(null, startNow: true); return "ok Trick Shots stopped"; } PortalModes.Force(TrickShotsMode.Instance, startNow: true); return $"ok Trick Shots started (Setup {PortalModes.Settings.TrickShotsSetupTime:0} s, fight {PortalModes.Settings.TrickShotsFightTime:0} s)"; } private static string PocketMode(string arg) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) if (!ModeNet.IsServer) { return "error: host only"; } if (!GameAccess.InExplorationMap()) { return "error: exploration maps only"; } if (arg == "stop") { PortalModes.Force(null, startNow: true); return "ok Pocket Portals stopped"; } PortalModes.Force(PocketPortalsMode.Instance, startNow: true); return $"ok Pocket Portals started (Pocket key {PocketPortalsMode.Key}, {PocketPortalsMode.Describe()})"; } private static string Blind(string arg) { switch (arg) { default: if (arg.Length == 0) { break; } goto case null; case "on": BlindSound.Forced = true; break; case "off": BlindSound.Forced = false; break; case "fold": case "unfold": { if (!ModeNet.IsServer) { return "error: host only"; } int num = ModePlayers.LocalId(); if (num < 0) { return "error: no local player"; } ModePlayers.Blindfold(num, arg == "fold"); return "ok local player " + ((arg == "fold") ? "blindfolded" : "no longer blindfolded") + " (takes effect next frame)"; } case null: return "error: blind [on|off|fold|unfold]"; } return "ok " + BlindSound.Report(); } private static string Hands(string arg) { if (!ModeNet.IsServer) { return "error: host only"; } int playerId = ModePlayers.LocalId(); if (!ModePlayers.TryGet(playerId, out var player) || !player.Alive) { return "error: no living local player"; } if (arg == "take") { ModeWeapons.Take(playerId); return "ok taken"; } ModeWeapons.Hands(player, out var right, out var left); return "ok right " + Name(right) + ", left " + Name(left) + "; " + PocketPortalsMode.Describe(); static string Name(NetworkObject n) { if (!((Object)(object)n == (Object)null)) { return $"{((Object)n).name}#{n.ObjectId}"; } return "empty"; } } private static string PoseCommand(string arg) { if (arg == "list" || arg.Length == 0) { return "ok " + string.Join(", ", Poses.All.Select((PoseDef p, int i) => $"{i} {p.Name}")); } if (!ModeNet.IsServer) { return "error: host only"; } int result; int num = (int.TryParse(arg, out result) ? result : Array.FindIndex(Poses.All, (PoseDef p) => string.Equals(p.Name, arg, StringComparison.OrdinalIgnoreCase))); if (num < 0 || num >= Poses.All.Length) { return "error: no Pose " + arg; } int num2 = ModePlayers.LocalId(); if (ModeServer.State.Mode != PortalModeKind.HideAndSeek) { ModeServer.State.Mode = PortalModeKind.HideAndSeek; } ModeServer.State.Hiders.Add(num2); if (num == 0) { ModeServer.State.Poses.Remove(num2); } else { ModeServer.State.Poses[num2] = (byte)num; } ModeServer.MarkDirty(); ModeServer.FlushState(); return $"ok Pose {num} {Poses.All[num].Name}"; } private static string Taunt(string arg) { if (!ModeNet.IsServer) { return "error: host only"; } FirstPersonController val = GameAccess.LocalPlayer(); if ((Object)(object)val == (Object)null) { return "error: no local player"; } int result; int num = (int.TryParse(arg, out result) ? result : 4); MethodInfo methodInfo = ModePatches.FindTauntServerLogic(); if (methodInfo == null) { return "error: taunt code not found"; } methodInfo.Invoke(val, new object[1] { num }); return $"ok taunt clip {num}"; } private static string TrickRule(string arg) { if (!ModeNet.IsServer) { return "error: host only"; } if (arg != "on" && arg != "off") { return "error: trick-rule on|off"; } ModeServer.State.TrickShotsOnly = arg == "on"; ModeServer.MarkDirty(); ModeServer.FlushState(); return "ok rule " + (TrickShots.RuleOn ? "on" : "off") + " here"; } private static string Explore(string map) { MapsManager instance = MapsManager.Instance; if ((Object)(object)instance == (Object)null || instance.allMapsDict == null) { return "error: no MapsManager yet"; } if (map.Length == 0 || !instance.allMapsDict.ContainsKey(map)) { return "error: explore <map>, one of: " + string.Join(", ", instance.allMapsDict.Keys.OrderBy((string k) => k)); } if ((Object)(object)SteamLobby.Instance == (Object)null) { return "error: no SteamLobby"; } SteamLobby.Instance.EnterExplorationMap(map); return "ok entering " + map; } private static string Maps() { MapsManager instance = MapsManager.Instance; if ((Object)(object)instance == (Object)null || instance.allMaps == null) { return "error: no MapsManager yet"; } Dictionary<string, string> dictionary = new Dictionary<string, string>(); ProgressManager instance2 = ProgressManager.Instance; if ((Object)(object)instance2 != (Object)null && instance2.instances != null) { ProgressInstance[] instances = instance2.instances; foreach (ProgressInstance val in instances) { if (val.maps != null) { string[] maps = val.maps; foreach (string key in maps) { dictionary[key] = string.Format("tier {0} xp {1}{2}", val.index, val.xpToUnlock, val.dlcExlusive ? " dlc" : ""); } } } } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("index\tname\talt\tdlc\tunlocked\tunlock"); Map[] allMaps = instance.allMaps; foreach (Map val2 in allMaps) { stringBuilder.AppendLine(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", val2.index, val2.mapName, val2.isAltMap, val2.isDlcExclusive, val2.isUnlocked, dictionary.TryGetValue(val2.mapName, out var value) ? value : "start")); } stringBuilder.AppendLine(); PlaylistPreset[] array = Resources.LoadAll<PlaylistPreset>("PlaylistPresets"); foreach (PlaylistPreset val3 in array) { stringBuilder.AppendLine("playlist " + val3.Name + (val3.IsDlcExclusive ? " (dlc)" : "") + ": " + string.Join(", ", val3.Maps ?? new string[0])); } File.WriteAllText(Path.Combine(_shotDir, "maps.txt"), stringBuilder.ToString()); return $"ok {instance.allMaps.Length} maps to maps.txt"; } private static Bounds? PlayArea() { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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) //IL_0044: Unknown result type (might be due to invalid IL or missing references) Bounds? result = null; foreach (Component item in Object.FindObjectsOfType<SpawnPoint>().Cast<Component>().Concat((IEnumerable<Component>)(object)Object.FindObjectsOfType<ItemSpawner>())) { if (!result.HasValue) { result = new Bounds(item.transform.position, Vector3.zero); continue; } Bounds value = result.Value; ((Bounds)(ref value)).Encapsulate(item.transform.position); result = value; } return result; } private static string SceneDump(string filter) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); int num = 0; Scene activeScene = SceneManager.GetActiveScene(); GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects(); for (int i = 0; i < rootGameObjects.Length; i++) { Transform[] componentsInChildren = rootGameObjects[i].GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { string text = MapTeleporter.PathOf(val); if (!string.IsNullOrEmpty(filter) && text.IndexOf(filter, StringComparison.OrdinalIgnoreCase) < 0) { continue; } num++; StringBuilder stringBuilder2 = stringBuilder.Append(((Component)val).gameObject.activeInHierarchy ? "+ " : "- ").Append(text).Append(" tag=") .Append(((Component)val).tag) .Append(" layer=") .Append(((Component)val).gameObject.layer) .Append(" pos="); Vector3 position = val.position; stringBuilder2.Append(((Vector3)(ref position)).ToString("F1")).AppendLine(); Component[] components = ((Component)val).GetComponents<Component>(); foreach (Component val2 in components) { if ((Object)(object)val2 == (Object)null || val2 is Transform) { continue; } stringBuilder.Append(" ").Append(((object)val2).GetType().Name); Behaviour val3 = (Behaviour)(object)((val2 is Behaviour) ? val2 : null); if (val3 != null) { stringBuilder.Append(val3.enabled ? "" : " (disabled)"); } Collider val4 = (Collider)(object)((val2 is Collider) ? val2 : null); if (val4 != null) { stringBuilder.Append(val4.isTrigger ? " trigger" : "").Append(val4.enabled ? "" : " (disabled)"); } stringBuilder.AppendLine(); Animator val5 = (Animator)(object)((val2 is Animator) ? val2 : null); if (val5 != null && (Object)(object)val5.runtimeAnimatorController != (Object)null) { stringBuilder.Append(" controller ").Append(((Object)val5.runtimeAnimatorController).name).AppendLine(); AnimationClip[] animationClips = val5.runtimeAnimatorController.animationClips; foreach (AnimationClip val6 in animationClips) { stringBuilder.Append(" clip ").Append(((Object)val6).name).Append(' ') .Append(val6.length.ToString("F1")) .Append(" s"); AnimationEvent[] events = val6.events; foreach (AnimationEvent val7 in events) { stringBuilder.Append(" event@").Append(val7.time.ToString("F1")).Append(' ') .Append(val7.functionName); } stringBuilder.AppendLine(); } } if (!(((object)val2).GetType().Assembly == typeof(Teleporter).Assembly)) { continue; } FieldInfo[] fields = ((object)val2).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { object value;