Ejemplo n.º 1
0
        public override void BeforePatch()
        {
            IGConsole.RegisterCommand <CommandRate>(this);

            ModInput.RegisterBinding(this, "RateIncrement", KeyCode.KeypadPlus).ListenKeyDown(Increment);
            ModInput.RegisterBinding(this, "RateDecrement", KeyCode.KeypadMinus).ListenKeyDown(Decrement);
        }
Ejemplo n.º 2
0
        public override void BeforePatch()
        {
            Arduino.Instance.Init();

            ModInput.RegisterBinding(this, "LampAction", KeyCode.H).ListenKeyDown(LampAction);
            ModInput.RegisterBinding(this, "LampPinAdd", KeyCode.UpArrow).ListenKeyDown(PinDownKey);
        }
Ejemplo n.º 3
0
        private bool SetBinding(string name, string keyStr)
        {
            KeyCode key = KeyCode.None;

            foreach (var item in Enum.GetNames(typeof(KeyCode)))
            {
                if (item.Equals(keyStr, StringComparison.InvariantCultureIgnoreCase))
                {
                    key = (KeyCode)Enum.Parse(typeof(KeyCode), keyStr, true);
                    break;
                }
            }

            if (key == KeyCode.None)
            {
                Error($"Invalid key '{keyStr}'.");
                return(true);
            }

            var b = GetBinding(name);

            if (b == null)
            {
                return(true);
            }

            b.Key = key;
            ModInput.SaveBinds();

            PrintBinding(name);

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Call this function before doing anything with the console
        /// </summary>
        internal static void Init()
        {
            CmdLog  = new DropOutStack <LogEntry>(MaxHistory);
            History = new DropOutStack <string>(MaxHistory);
            Style   = new GUIStyle
            {
                font     = Font.CreateDynamicFontFromOSFont("Consolas", 16),
                richText = true
            };

            Shell.LoadCommands();

            ModInput.RegisterBinding(null, "ToggleConsole", KeyCode.BackQuote);
            ModInput.RegisterBinding(null, "ConsoleAutocompletion", KeyCode.Tab);

            Initialized = true;

            Log("Console initialized");
            Log("Type \"help\" to get a list of commands");

            while (EntryQueue.Any())
            {
                KeyValuePair <LogType, object> entry = EntryQueue.Dequeue();
                Log(entry.Key, entry.Value);
            }
        }
Ejemplo n.º 5
0
        public override void BeforePatch()
        {
            ModInput.RegisterBinding("Select", KeyCode.L).ListenKeyDown(() => State.Fire(Triggers.BeginSelect));
            ModInput.RegisterBinding("Confirm", KeyCode.Return).ListenKeyDown(() => State.Fire(Triggers.Confirm));
            ModInput.RegisterBinding("Cancel", KeyCode.Delete).ListenKeyDown(() => State.Fire(Triggers.Cancel));
            ModInput.RegisterBinding("CycleSelection", KeyCode.Z).ListenKeyDown(() => Selection.Instance?.NextSelection());

            ShowGuide = Configuration.Get("ShowGuide", true);

            State.Configure(States.None)
            .OnEnter(ExitEditing)
            .Permit(Triggers.BeginSelect, States.Selecting)
            .Permit(Triggers.Cancel, States.None, Editing.UndoLast);

            State.Configure(States.Selecting)
            .OnEnter(() => FirstPersonInteraction.FirstPersonCamera.gameObject.AddComponent <Selection>())
            .Permit(Triggers.Cancel, States.None, ExitEditing)
            .Permit(Triggers.Confirm, States.Editing)
            .Permit(Triggers.BeginSelect, States.Selecting, LoadLastSelection);

            State.Configure(States.Editing)
            .OnEnter(EnterEditing)
            .OnExit(ExitEditing)
            .Permit(Triggers.Cancel, States.None)
            .Permit(Triggers.Confirm, States.None, () => Editing.Instance.Apply());

            State.Configure(States.Moving)
            .Permit(Triggers.Cancel, States.None)
            .Permit(Triggers.Confirm, States.None);
        }
Ejemplo n.º 6
0
        static void Prefix()
        {
            //TODO: Maybe bring this back if I ever properly implement the config menu.
            //if (Input.GetKeyDown(KeyCode.F5))
            //{
            //    ConfigMenu.Instance.Show = !ConfigMenu.Instance.Show;

            //    UIManager.SomeOtherMenuIsOpen = ConfigMenu.Instance.Show;

            //    if (ConfigMenu.Instance.Show)
            //    {
            //        UIManager.UnlockMouseAndDisableFirstPersonLooking();
            //    }
            //    else
            //    {
            //        UIManager.LockMouseAndEnableFirstPersonLooking();
            //    }
            //}

            foreach (var key in KeyCodesToListenTo)
            {
                if ((Input.GetKeyDown(key.Key)) ||
                    (key.Repeat && Input.GetKey(key.Key) && Time.time - PressedTimes[key] >= key.RepeatInterval))
                {
                    PressedTimes[key] = Time.time;
                    KeyDown?.Invoke(key.Key);
                }
            }

            ModInput.UpdateListeners();
        }
Ejemplo n.º 7
0
    void Update()
    {
        if (Input.GetKey(ReleaseKey))
        {
            Cursor.lockState = CursorLockMode.None;
            return;
        }

        // Ensure the cursor is always locked when set
        Cursor.lockState = CursorLockMode.Locked;

        // Allow the script to clamp based on a desired target value.
        var targetOrientation          = Quaternion.Euler(targetDirection);
        var targetCharacterOrientation = Quaternion.Euler(targetCharacterDirection);

        // Get raw mouse input for a cleaner reading on more sensitive mice.
        var mouseDelta = new Vector2(ModInput.GetAxisRaw("FPV Camera X"), ModInput.GetAxisRaw("FPV Camera Y"));

        // Scale input against the sensitivity setting and multiply that against the smoothing value.
        mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity.x * smoothing.x, sensitivity.y * smoothing.y));

        // Interpolate mouse movement over time to apply smoothing delta.
        smoothMouse.x = Mathf.Lerp(smoothMouse.x, mouseDelta.x, 1f / smoothing.x);
        smoothMouse.y = Mathf.Lerp(smoothMouse.y, mouseDelta.y, 1f / smoothing.y);

        // Find the absolute mouse movement value from point zero.
        mouseAbsolute += smoothMouse;

        // Clamp and apply the local x value first, so as not to be affected by world transforms.
        if (clampInDegrees.x < 360)
        {
            mouseAbsolute.x = Mathf.Clamp(mouseAbsolute.x, -clampInDegrees.x * 0.5f, clampInDegrees.x * 0.5f);
        }

        var xRotation = Quaternion.AngleAxis(-mouseAbsolute.y, targetOrientation * Vector3.right);

        transform.localRotation = xRotation;

        // Then clamp and apply the global y value.
        if (clampInDegrees.y < 360)
        {
            mouseAbsolute.y = Mathf.Clamp(mouseAbsolute.y, -clampInDegrees.y * 0.5f, clampInDegrees.y * 0.5f);
        }

        transform.localRotation *= targetOrientation;

        // If there's a character body that acts as a parent to the camera
        if (characterBody)
        {
            var yRotation = Quaternion.AngleAxis(mouseAbsolute.x, characterBody.transform.up);
            characterBody.transform.localRotation  = yRotation;
            characterBody.transform.localRotation *= targetCharacterOrientation;
        }
        else
        {
            var yRotation = Quaternion.AngleAxis(mouseAbsolute.x, transform.InverseTransformDirection(Vector3.up));
            transform.localRotation *= yRotation;
        }
    }
Ejemplo n.º 8
0
        public override void BeforePatch()
        {
            ModInput.RegisterBinding(this, "Copy", KeyCode.G, KeyModifiers.Shift)
            .ListenKeyDown(Copy);

            ModInput.RegisterBinding(this, "Paste", KeyCode.G)
            .ListenKeyDown(Paste);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Main bootstrap method. Loads and patches all mods.
        /// </summary>
        public void Patch(bool hotload = false)
        {
            if (Patched && !hotload)
            {
                return;
            }
            Patched = true;

            string tungVersion = GetTungVersion();

            MDebug.WriteLine("PiTUNG Framework version {0} on TUNG {1}", 0, new Version(PiTUNG.FrameworkVersion.Major, PiTUNG.FrameworkVersion.Minor, PiTUNG.FrameworkVersion.Build), tungVersion);
            MDebug.WriteLine("-------------Patching-------------" + (hotload ? " (reloading)" : ""));

            if (!hotload)
            {
                Configuration.LoadPitungConfig();

                _Mods.Clear();

                _Harmony = HarmonyInstance.Create("me.pipe01.pitung");

                if (!Testing)
                {
                    try
                    {
                        _Harmony.PatchAll(Assembly.GetExecutingAssembly());
                    }
                    catch (Exception ex)
                    {
                        MDebug.WriteLine("[ERROR] PiTUNG failed to load! Exception: \n" + ex);
                        return;
                    }

                    ModInput.LoadBinds();
                    IGConsole.Init();
                }

                SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
            }

            if (!Testing)
            {
                AddDummyComponent(SceneManager.GetActiveScene());
            }

            SelectionMenu.AllowModdedComponents = true;

            var mods = ModLoader.Order(ModLoader.GetMods());

            foreach (var item in mods.Where(o => !o.MultiThreadedLoad))
            {
                LoadMod(item, hotload);
            }

            CurrentlyLoading = null;

            new Thread(() => PatchThread(mods, hotload)).Start();
        }
Ejemplo n.º 10
0
        private static void ReadInput()
        {
            foreach (char c in Input.inputString)
            {
                if (c == '\b') // has backspace/delete been pressed?
                {
                    if (CurrentCmd.Length != 0)
                    {
                        string firstHalf  = CurrentCmd.Substring(0, EditLocation - 1);
                        string secondHalf = CurrentCmd.Substring(EditLocation, CurrentCmd.Length - EditLocation);
                        CurrentCmd = firstHalf + secondHalf;
                        EditLocation--;
                    }
                }
                else if (c == 0x7F) // Ctrl + Backspace (erase word)
                {
                    if (CurrentCmd.Length != 0)
                    {
                        int index = EditLocation;
                        while (index > 0 && Char.IsLetterOrDigit(CurrentCmd.ElementAt(index - 1)))
                        {
                            index--;
                        }
                        if (index == EditLocation && EditLocation > 0) // Delete at least 1 character
                        {
                            index--;
                        }
                        int    length     = EditLocation - index;
                        string firstHalf  = CurrentCmd.Substring(0, index);
                        string secondHalf = CurrentCmd.Substring(EditLocation, CurrentCmd.Length - EditLocation);
                        CurrentCmd    = firstHalf + secondHalf;
                        EditLocation -= length;
                    }
                }
                else if ((c == '\n') || (c == '\r')) // enter/return
                {
                    if (!string.IsNullOrEmpty(CurrentCmd.Trim()))
                    {
                        Log(LogType.USERINPUT, "> " + CurrentCmd);
                        History.Push(CurrentCmd);
                        Shell.ExecuteCommand(CurrentCmd);
                    }

                    CurrentCmd   = "";
                    EditLocation = 0;
                }
                else if ((KeyCode)c != ModInput.GetBindingKey("ToggleConsole"))
                {
                    CurrentCmd = CurrentCmd.Insert(EditLocation, c.ToString());
                    EditLocation++;
                }
            }
        }
Ejemplo n.º 11
0
        public void Update()
        {
            if (ModInput.GetKeyDown("ToggleFlight"))
            {
                m_Enabled = !m_Enabled;
                FirstPersonController.Instance.enabled = !m_Enabled;
            }

            if (!m_Enabled)
            {
                return;
            }

            if (ModInput.GetKeyDown("ToggleAxisLock"))
            {
                fixedYAxis = !fixedYAxis;
            }

            this.m_MouseLook.LookRotation(base.transform, this.m_Camera.transform);
            this.m_MouseLook.UpdateCursorLock();

            float speedMult = 1;

            if (Input.GetKey(KeyCode.LeftShift))
            {
                speedMult = fastMoveFactor;
            }
            else if (Input.GetKey(KeyCode.LeftControl))
            {
                speedMult = slowMoveFactor;
            }

            var trans = m_Camera.transform;

            float vertical   = Input.GetAxisRaw("Vertical");
            float horizontal = Input.GetAxisRaw("Horizontal");

            Vector3 forward = new Vector3(trans.forward.x, fixedYAxis ? 0 : trans.forward.y, trans.forward.z);

            transform.position += forward * moveSpeed * speedMult * vertical * Time.deltaTime;
            transform.position += trans.right * moveSpeed * speedMult * horizontal * Time.deltaTime;

            if (Input.GetKey(KeyCode.Space))
            {
                transform.position += Vector3.up * climbSpeed * speedMult * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.C))
            {
                transform.position -= Vector3.up * climbSpeed * speedMult * Time.deltaTime;
            }
        }
Ejemplo n.º 12
0
        public override void BeforePatch()
        {
            ThroughInverter.Register();
            KeyButton.Register();
            TFlipFlop.Register();
            DLatch.Register();
            FileReader.Register();
            EdgeDetector.Register();
            GateAND.Register();
            GateANDB.Register();
            GateAND4.Register();
            GateNAND.Register();
            GateOR.Register();
            GateXOR.Register();
            GateXNOR.Register();

            ModInput.RegisterBinding("DeleteWholeBoard", KeyCode.T, KeyModifiers.Control | KeyModifiers.Shift)
            .ListenKeyDown(DeleteBoard);
        }
Ejemplo n.º 13
0
 public override void BeforePatch()
 {
     ModInput.RegisterBinding(this, "ToggleFlight", KeyCode.F);
     ModInput.RegisterBinding(this, "ToggleAxisLock", KeyCode.B);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Call this function on Update calls
        /// </summary>
        internal static void Update()
        {
            // Toggle console with TAB
            if (ModInput.GetKeyDown("ToggleConsole"))
            {
                Shown = !Shown;

                float off = 0;

                //The user is toggling the console but the animation hasn't yet ended, resume it later
                if (Time.time - ShownAtTime < ShowAnimationTime)
                {
                    off -= ShowAnimationTime - (Time.time - ShownAtTime);
                }

                ShownAtTime = Time.time + off;

                if (SceneManager.GetActiveScene().name == "gameplay")
                {
                    if (Shown)
                    {
                        PreviousUIState           = GameplayUIManager.UIState;
                        GameplayUIManager.UIState = UIState.PauseMenuOrSubMenu;
                    }
                    else
                    {
                        GameplayUIManager.UIState = PreviousUIState;
                        PreviousUIState           = UIState.None;
                    }
                }
            }

            if (Shown)
            {
                if (ModInput.GetKeyDown("ConsoleAutocompletion"))
                {
                    TriggerAutocompletion();
                }

                // Handling history
                if (Input.GetKeyDown(KeyCode.UpArrow) && HistorySelector < History.Count - 1)
                {
                    HistorySelector += 1;
                    CurrentCmd       = History.Get(HistorySelector);
                    EditLocation     = CurrentCmd.Length;
                }
                if (Input.GetKeyDown(KeyCode.DownArrow) && HistorySelector > -1)
                {
                    HistorySelector -= 1;
                    if (HistorySelector == -1)
                    {
                        CurrentCmd = "";
                    }
                    else
                    {
                        CurrentCmd = History.Get(HistorySelector);
                    }
                    EditLocation = CurrentCmd.Length;
                }
                // Handle editing
                if (Input.GetKeyDown(KeyCode.LeftArrow) && EditLocation > 0)
                {
                    EditLocation--;
                }
                if (Input.GetKeyDown(KeyCode.RightArrow) && EditLocation < CurrentCmd.Length)
                {
                    EditLocation++;
                }

                ReadInput(); // Read text input
            }
        }
Ejemplo n.º 15
0
    public override void Init()
    {
        Instance = this;

        new SGroup()
        {
            Parent     = ModGUI.HelpGroup,
            Background = new Color(0f, 0f, 0f, 0f),
            AutoLayout = elem => elem.AutoLayoutVertical,
            AutoLayoutVerticalStretch = false,
            AutoLayoutPadding         = 0f,
            OnUpdateStyle             = ModGUI.SegmentGroupUpdateStyle,
            Children =
            {
                new SLabel("Magic Camera™:")
                {
                    Background = ModGUI.HeaderBackground,
                    Foreground = ModGUI.HeaderForeground
                },
                new SLabel("Special thanks to Shesez (Boundary Break)!")
                {
                    Background = ModGUI.HeaderBackground,
                    Foreground = ModGUI.HeaderForeground
                },

                new SLabel("Controller:")
                {
                    Background = ModGUI.HeaderBackground,
                    Foreground = ModGUI.HeaderForeground
                },
                new SLabel("Press L3 and R3 (into the two sticks) at the same time."),
                new SLabel("Movement:")
                {
                    Background = ModGUI.Header2Background,
                    Foreground = ModGUI.Header2Foreground
                },
                new SLabel("Left stick: First person movement"),
                new SLabel("Right stick: Rotate camera"),
                new SLabel("LB / L1: Move straight down"),
                new SLabel("RB / R1: Move straight up"),
                new SLabel("Speed manipulation:")
                {
                    Background = ModGUI.Header2Background,
                    Foreground = ModGUI.Header2Foreground
                },
                new SLabel("LT / L2: Reduce move speed"),
                new SLabel("RT / R2: Increase move speed"),
                new SLabel("LT + RT / L2 + R2: Reset move speed"),
                new SLabel("DPad left: Freeze game"),
                new SLabel("DPad right: Reset game speed"),
                new SLabel("LT + RT / L2 + R2: Reset move speed"),
                new SLabel("Other:")
                {
                    Background = ModGUI.Header2Background,
                    Foreground = ModGUI.Header2Foreground
                },
                new SLabel("B / Circle: Toggle info in bottom-right corner"),
                new SLabel("X / Square: Toggle game GUI / HUD"),
                new SLabel("Y / Triangle: Toggle neutral lighting"),

                new SLabel("Keyboard:")
                {
                    Background = ModGUI.HeaderBackground,
                    Foreground = ModGUI.HeaderForeground
                },
                new SLabel("Press F12."),
                new SLabel("Movement:")
                {
                    Background = ModGUI.Header2Background,
                    Foreground = ModGUI.Header2Foreground
                },
                new SLabel("WASD: First person movement"),
                new SLabel("R / F: Move straight down"),
                new SLabel("Q / E: Move straight up"),
                new SLabel("Mouse: Rotate camera"),
                new SLabel("Shift: Run"),
                new SLabel("Speed manipulation:")
                {
                    Background = ModGUI.Header2Background,
                    Foreground = ModGUI.Header2Foreground
                },
                new SLabel("1 / Scroll up: Reduce move* speed"),
                new SLabel("2 / Scroll down: Increase move* speed"),
                new SLabel("3 / Middle mouse button: Reset move* speed"),
                new SLabel("Hold control + scroll = modify game speed"),
                new SLabel("4: Reduce game speed"),
                new SLabel("5: Increase game speed"),
                new SLabel("6: Reset game speed"),
                new SLabel("7: Freeze game"),
                new SLabel("Other:")
                {
                    Background = ModGUI.Header2Background,
                    Foreground = ModGUI.Header2Foreground
                },
                new SLabel("F3: Toggle info in bottom-right corner"),
                new SLabel("F4: Toggle neutral lighting")
            }
        };

        GUISettingsGroup = new SGroup()
        {
            Parent        = ModGUI.SettingsGroup,
            Background    = new Color(0f, 0f, 0f, 0f),
            AutoLayout    = elem => elem.AutoLayoutVertical,
            OnUpdateStyle = ModGUI.SegmentGroupUpdateStyle,
            Children      =
            {
                new SLabel("Magic Camera™:")
                {
                    Background = ModGUI.HeaderBackground,
                    Foreground = ModGUI.HeaderForeground
                },

                new SButton("Show Camera Info")
                {
                    Alignment = TextAnchor.MiddleLeft,
                    With      = { new SCheckboxModifier()
                                  {
                                      GetValue = b => IsGUIVisible,
                                      SetValue = (b, v) => IsGUIVisible = v
                                  } }
                },

                new SButton("Neutral Ambient Lighting")
                {
                    Alignment = TextAnchor.MiddleLeft,
                    With      = { new SCheckboxModifier()
                                  {
                                      GetValue = b => IsFullBright,
                                      SetValue = (b, v) => IsFullBright = v
                                  } }
                }
            }
        };

        GUIInfoGroup = new SGroup()
        {
            ScrollDirection   = SGroup.EDirection.Vertical,
            AutoLayout        = elem => elem.AutoLayoutVertical,
            AutoLayoutPadding = 0f,

            OnUpdateStyle = elem => {
                elem.Size     = new Vector2(256, elem.Backend.LineHeight * elem.Children.Count);
                elem.Position = elem.Root.Size - elem.Size;
            },

            Children =
            {
                new SLabel("MAGIC CAMERA™")
                {
                    Background = ModGUI.HeaderBackground,
                    Foreground = ModGUI.HeaderForeground
                },
                new SLabel("Press F1 to view controls."),
                new SLabel(),
                (GUIInfoGameSpeed = new SLabel()),
                (GUIInfoMoveSpeed = new SLabel()),
                new SLabel(),
                (GUIInfoSceneName = new SLabel()),
                (GUIInfoPosition = new SLabel()),
                (GUIInfoRotation = new SLabel()),
            }
        };


        ModInput.ButtonMap["FreeCam Toggle"] =
            input => Input.GetKey(KeyCode.F12) || (ModInput.GetButton("LS") && ModInput.GetButton("RS"));
        ModInput.ButtonMap["FreeCam GUI Toggle"] =
            input => Input.GetKey(KeyCode.F3) || ModInput.GetButton("B");
        ModInput.ButtonMap["FreeCam Game GUI Toggle Ext"] =
            input => ModInput.GetButton("X");

        ModInput.ButtonMap["FreeCam Light Toggle"] =
            input => Input.GetKey(KeyCode.F4) || ModInput.GetButton("Y");

        ModInput.ButtonMap["FreeCam Run"] =
            input => Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

        ModInput.ButtonMap["FreeCam Internal Speed Switch"] =
            input => Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);

        ModInput.ButtonMap["FreeCam Internal Speed Reset"] =
            input => Input.GetMouseButton(2) || (ModInput.GetButton("LT") && ModInput.GetButton("RT"));
        ModInput.ButtonMap["FreeCam Move Speed Reset"] =
            input =>
            Input.GetKey(KeyCode.Alpha3) ||
            (!ModInput.GetButton("FreeCam Internal Speed Switch") && ModInput.GetButton("FreeCam Internal Speed Reset"));
        ModInput.ButtonMap["FreeCam Game Speed Reset"] =
            input =>
            Input.GetKey(KeyCode.Alpha6) || ModInput.GetButton("DPadRight") ||
            (ModInput.GetButton("FreeCam Internal Speed Switch") && ModInput.GetButton("FreeCam Internal Speed Reset"));
        ModInput.ButtonMap["FreeCam Game Speed Freeze"] =
            input => Input.GetKey(KeyCode.Alpha7) || ModInput.GetButton("DPadLeft");

        ModInput.AxisMap["FreeCam Y Movement"] =
            input =>
            Input.GetKey(KeyCode.F) || Input.GetKey(KeyCode.Q) || ModInput.GetButton("LB") ? -1f :
            Input.GetKey(KeyCode.R) || Input.GetKey(KeyCode.E) || ModInput.GetButton("RB") ?  1f :
            0f;

        ModInput.AxisMap["FreeCam Internal Speed"] =
            input =>
            Input.mouseScrollDelta.y +
            (ModInput.GetButton("LT") ? -0.4f : ModInput.GetButton("RT") ? 0.4f : 0f);
        ModInput.AxisMap["FreeCam Move Speed"] =
            input =>
            (Input.GetKey(KeyCode.Alpha1) ? -0.4f : Input.GetKey(KeyCode.Alpha2) ? 0.4f : 0f) +
            (!ModInput.GetButton("FreeCam Internal Speed Switch") ? ModInput.GetAxis("FreeCam Internal Speed") : 0f);
        ModInput.AxisMap["FreeCam Game Speed"] =
            input =>
            (ModInput.GetButton("DPadUp") ? 0.4f : ModInput.GetButton("DPadDown") ? -0.4f : 0f) +
            (Input.GetKey(KeyCode.Alpha4) ? -0.4f : Input.GetKey(KeyCode.Alpha5) ? 0.4f : 0f) +
            (ModInput.GetButton("FreeCam Internal Speed Switch") ? ModInput.GetAxis("FreeCam Internal Speed") : 0f);

        SceneManager.activeSceneChanged += (sceneA, sceneB) => {
            WasFullBright = IsFullBright = false;
        };

        ModEvents.OnUpdate += Update;
        // Only make the game use the player input when the free cam is disabled.
        ModEvents.OnPlayerInputUpdate += input => !IsEnabled;
    }
Ejemplo n.º 16
0
 public override void BeforePatch()
 {
     ModInput.RegisterBinding(this, "Teleport", KeyCode.R).ListenKeyDown(Teleport);
 }
Ejemplo n.º 17
0
    public void Update()
    {
        if (ModInput.GetButtonDown("FreeCam Toggle"))
        {
            IsEnabled = !IsEnabled;

            if (!IsEnabled)
            {
                Time.timeScale = 1f;

                FreeCamera.enabled = false;
                if (PrevCamera != null)
                {
                    PrevCamera.enabled = true;
                }
            }
            else
            {
                QualitySettings.lodBias         = 1f;
                QualitySettings.maximumLODLevel = 0;

                PrevCamera = Camera.main;
                if (PrevCamera != null)
                {
                    FreeCamera.transform.position    = PrevCamera.transform.position;
                    FreeCamera.transform.eulerAngles = new Vector3(0f, PrevCamera.transform.eulerAngles.y, 0f);
                    MouseLook.targetDirection        = PrevCamera.transform.rotation.eulerAngles;
                    MouseLook.mouseAbsolute          = Vector2.zero;
                    FreeCamera.fieldOfView           = PrevCamera.fieldOfView;
                    if (FreeCamera.fieldOfView < 10f)
                    {
                        FreeCamera.fieldOfView = 75f;
                    }
                    PrevCamera.enabled = false;
                }
                FreeCamera.enabled = true;

                if (CameraManager.Instance != null)
                {
                    ApplyDOFToFreeCam();
                }
            }

            ModLogger.Log("freecam", $"{(IsEnabled ? "Enabled" : "Disabled")} MAGIC CAMERA™ mode.");
        }

        if (IsEnabled && ModInput.GetButtonDown("FreeCam Light Toggle"))
        {
            IsFullBright = !IsFullBright;
        }
        if (!WasFullBright && IsFullBright)
        {
            OriginalAmbienceColor       = RenderSettings.ambientLight;
            RenderSettings.ambientLight = new Color(1f, 1f, 1f, 1f);
        }
        else if (WasFullBright && !IsFullBright)
        {
            RenderSettings.ambientLight = OriginalAmbienceColor;
        }
        WasFullBright = IsFullBright;

        if (CameraManager.Instance != null)
        {
            CameraManager.Instance.enabled = !IsEnabled;
        }

        GUIInfoGroup.Visible = IsEnabled && IsGUIVisible;

        if (_FreeCamera != null)
        {
            MouseLook.enabled = IsEnabled;
        }

        if (!IsEnabled)
        {
            return;
        }

        MouseLook.enabled = !ModGUI.MainGroup.Visible;

        if (ModInput.GetButtonDown("FreeCam GUI Toggle"))
        {
            IsGUIVisible = !IsGUIVisible;
        }
        if (ModInput.GetButtonDown("FreeCam Game GUI Toggle Ext"))
        {
            ModGUI.ToggleGameGUI();
        }

        /*
         * if (CameraManager.Instance != null) {
         *  FreeCamera.enabled = true;
         *  if (Camera.main != null && Camera.main != FreeCamera)
         *      ApplyDOFToFreeCam();
         * }
         */

        FreeCamera.enabled = true;

        Transform camt = FreeCamera.transform;

        Speed = Mathf.Max(0.01f, Speed + 0.01f * ModInput.GetAxis("FreeCam Move Speed"));
        if (ModInput.GetButton("FreeCam Move Speed Reset"))
        {
            Speed = DefaultSpeed;
        }

        float speed = Speed;

        if (ModInput.GetButton("FreeCam Run"))
        {
            speed *= 4f;
        }

        Vector3 dir = Vector3.zero;

        dir += camt.forward * ModInput.GetAxis("Vertical");

        float angleY = camt.rotation.eulerAngles.y;

        angleY = (angleY + 90f) / 180f * Mathf.PI;
        if (camt.rotation.eulerAngles.z == 180f)
        {
            angleY += Mathf.PI;
        }
        dir += new Vector3(Mathf.Sin(angleY), 0f, Mathf.Cos(angleY)) * ModInput.GetAxis("Horizontal");

        if (dir != Vector3.zero)
        {
            dir.Normalize();
            camt.position += dir * speed * SpeedF;
        }

        camt.position += Vector3.up * ModInput.GetAxis("FreeCam Y Movement") * speed * SpeedF;

        float timeScalePrev = Time.timeScale;

        Time.timeScale = Mathf.Clamp(Time.timeScale + ModInput.GetAxis("FreeCam Game Speed") * (
                                         Time.timeScale < 0.24999f ? 0.01f :
                                         Time.timeScale < 1.99999f ? 0.05f :
                                         Time.timeScale < 7.99999f ? 0.5f :
                                         Time.timeScale < 15.99999f ? 1f :
                                         4f
                                         ), 0f, 100f);

        if (ModInput.GetButton("FreeCam Game Speed Reset"))
        {
            Time.timeScale = 1f;
        }

        if (ModInput.GetButton("FreeCam Game Speed Freeze"))
        {
            Time.timeScale = 0f;
        }

        int scaleRound = Mathf.FloorToInt(Time.timeScale * 100f);

        if (Time.timeScale >= 0.25f && scaleRound % 10 == 9)
        {
            Time.timeScale = (scaleRound + 1) / 100f;
        }

        GUIInfoGameSpeed.Text = $"Game speed: {Mathf.FloorToInt(Time.timeScale * 100f)}%";
        GUIInfoMoveSpeed.Text = $"Movement speed: {(speed / DefaultSpeed * 100f).ToString("N0")}%";
        GUIInfoSceneName.Text = $"Scene (level): {SceneManager.GetActiveScene().name}";
        Vector3 pos = camt.position;
        Vector3 rot = camt.eulerAngles;

        GUIInfoPosition.Text = $"Position: {pos.x.ToString("0000.00")}, {pos.y.ToString("0000.00")}, {pos.z.ToString("0000.00")}";
        GUIInfoRotation.Text = $"Rotation: {rot.x.ToString("0000.00")}, {rot.y.ToString("0000.00")}, {rot.z.ToString("0000.00")}";
    }
Ejemplo n.º 18
0
 public override void BeforePatch()
 {
     ModInput.RegisterBinding("Undo", KeyCode.Z, KeyModifiers.Control).ListenKeyDown(Undo);
 }