private void MouseFixHook(On.VideoCamera.orig_Update orig, VideoCamera self)
        {
            orig(self);

            var m_active    = GetValue(typeof(VideoCamera), self, "m_active");
            var m_character = GetValue(typeof(VideoCamera), self, "m_character");

            if (m_active is bool active && m_character is Character character)
            {
                if (active == false && character != null)
                {
                    if (freeCameraFlag && localPlayerID == -1)
                    {
                        localPlayerID = ControlsInput.GetMouseOwner();
                    }
                    if (!freeCameraFlag)
                    {
                        freeCameraFlag   = true;
                        Cursor.lockState = CursorLockMode.Locked;
                        if (localPlayerID != -1)
                        {
                            ControlsInput.AssignMouseKeyboardToPlayer(localPlayerID);
                        }
                    }
                }
                if (active == true && freeCameraFlag == true)
                {
                    freeCameraFlag = false;
                }
            }
        }
Esempio n. 2
0
            public static bool Prefix(PauseMenu __instance, Button ___m_btnSplit, ref bool ___m_suicide, Button ___m_btnDie)
            {
                //var self = __instance;

                //((Button)At.GetField(__instance, "m_btnSplit")).interactable = true;

                At.Invoke(__instance as Panel, "Update");

                if (!___m_btnSplit.interactable)
                {
                    ___m_btnSplit.interactable = true;
                }

                if (__instance.LocalCharacter)
                {
                    //if (__instance.LocalCharacter.Alive && ___m_btnSplit.interactable != PhotonNetwork.offlineMode)
                    //    ___m_btnSplit.interactable = PhotonNetwork.offlineMode;
                    //else if (!__instance.LocalCharacter.Alive && ___m_btnSplit.interactable)
                    //    ___m_btnSplit.interactable = false;

                    if (!___m_suicide &&
                        ((Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.LeftAlt) && Input.GetKeyDown(KeyCode.U)) ||
                         ControlsInput.GamepadUnstuckCheat(__instance.PlayerID)))
                    {
                        ___m_suicide = true;

                        if (___m_btnDie && !___m_btnDie.gameObject.activeSelf)
                        {
                            ___m_btnDie.gameObject.SetActive(true);
                        }
                    }
                }

                return(false);
            }
 // Token: 0x060020B8 RID: 8376 RVA: 0x000C12CC File Offset: 0x000BF4CC
 private void UpdateQuickSlots()
 {
     if (this.m_character != null && this.m_character.QuickSlotMngr != null)
     {
         int playerID = this.m_character.OwnerPlayerSys.PlayerID;
         if (!this.m_character.CharacterUI.IsMenuFocused)
         {
             this.m_character.QuickSlotMngr.ShowQuickSlotSection1 = ControlsInput.QuickSlotToggle1(playerID);
             this.m_character.QuickSlotMngr.ShowQuickSlotSection2 = ControlsInput.QuickSlotToggle2(playerID);
         }
         if (ControlsInput.QuickSlotInstant1(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(0);
         }
         else if (ControlsInput.QuickSlotInstant2(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(1);
         }
         else if (ControlsInput.QuickSlotInstant3(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(2);
         }
         else if (ControlsInput.QuickSlotInstant4(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(3);
         }
         else if (ControlsInput.QuickSlotInstant5(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(4);
         }
         else if (ControlsInput.QuickSlotInstant6(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(5);
         }
         else if (ControlsInput.QuickSlotInstant7(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(6);
         }
         else if (ControlsInput.QuickSlotInstant8(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(7);
         }
         else
         {
             // Loop through the 8 new slots
             for (var x = 0; x < 8; ++x)
             {
                 // See if the action for the slot is pressed
                 if (ControlsInput.QuickSlotInstantX(playerID, x + 12))
                 {
                     // If so, trigger the quick slot.
                     // The index of the slot is 1 less than it's id, as you can see above.
                     this.m_character.QuickSlotMngr.QuickSlotInput(x + 11);
                     break;
                 }
             }
         }
     }
 }
    private void Awake()
    {
        // Bindings
        _controller = GetComponentInParent <CharacterController>();

        // Just add what Input Component we choose ( KeyBoard / Joystic...)
        _movementInput = GetComponentInParent <ControlsInput>();
    }
Esempio n. 5
0
        static private void TryOverrideVanillaQuickslotInput(ref bool input, int playerID)
        {
            #region quit
            if (!_extraGamepadQuickslots)
            {
                return;
            }
            #endregion

            input &= !ControlsInput.QuickSlotToggle1(playerID) && !ControlsInput.QuickSlotToggle2(playerID);
        }
Esempio n. 6
0
    public static void SaveControlsInput(ControlsInput controls)
    {
        //Debug.Log("SaveControlsInput" + controls.m_Action);

        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/controls.cfg";
        FileStream      stream    = new FileStream(path, FileMode.Create);

        ControlsData data = new ControlsData(controls);

        formatter.Serialize(stream, data);
        stream.Close();
    }
Esempio n. 7
0
        static private void TryHandleCustomQuickslotInput(Character character)
        {
            #region quit
            if (!_extraGamepadQuickslots)
            {
                return;
            }
            #endregion

            if (character == null || character.QuickSlotMngr == null || character.CharacterUI.IsMenuFocused)
            {
                return;
            }

            int playerID = character.OwnerPlayerSys.PlayerID;
            if (!ControlsInput.QuickSlotToggle1(playerID) && !ControlsInput.QuickSlotToggle2(playerID))
            {
                return;
            }

            int quickslotID = -1;
            if (GameInput.Pressed(playerID, ControlsInput.GameplayActions.Sheathe))
            {
                quickslotID = 8;
            }
            else if (GameInput.Pressed(playerID, ControlsInput.MenuActions.ToggleMapMenu))
            {
                quickslotID = 9;
            }
            else if (GameInput.Pressed(playerID, ControlsInput.GameplayActions.ToggleLights))
            {
                quickslotID = 10;
            }
            else if (GameInput.Pressed(playerID, ControlsInput.GameplayActions.HandleBag))
            {
                quickslotID = 11;
            }

            if (quickslotID < 0)
            {
                return;
            }

            if (ControlsInput.QuickSlotToggle1(playerID))
            {
                quickslotID += 4;
            }

            character.QuickSlotMngr.QuickSlotInput(quickslotID);
        }
Esempio n. 8
0
 // Token: 0x060020B8 RID: 8376 RVA: 0x000C12CC File Offset: 0x000BF4CC
 private void UpdateQuickSlots()
 {
     if (this.m_character != null && this.m_character.QuickSlotMngr != null)
     {
         int playerID = this.m_character.OwnerPlayerSys.PlayerID;
         if (!this.m_character.CharacterUI.IsMenuFocused)
         {
             this.m_character.QuickSlotMngr.ShowQuickSlotSection1 = ControlsInput.QuickSlotToggle1(playerID);
             this.m_character.QuickSlotMngr.ShowQuickSlotSection2 = ControlsInput.QuickSlotToggle2(playerID);
         }
         if (ControlsInput.QuickSlotInstant1(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(0);
         }
         else if (ControlsInput.QuickSlotInstant2(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(1);
         }
         else if (ControlsInput.QuickSlotInstant3(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(2);
         }
         else if (ControlsInput.QuickSlotInstant4(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(3);
         }
         else if (ControlsInput.QuickSlotInstant5(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(4);
         }
         else if (ControlsInput.QuickSlotInstant6(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(5);
         }
         else if (ControlsInput.QuickSlotInstant7(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(6);
         }
         else if (ControlsInput.QuickSlotInstant8(playerID))
         {
             this.m_character.QuickSlotMngr.QuickSlotInput(7);
         }
     }
 }
Esempio n. 9
0
        public DiscordJoinRequestDialog(DiscordJoinRequest args, CancellationToken cancellation = default(CancellationToken))
        {
            cancellation.Register(async() => {
                await Task.Delay(200);
                CloseWithResult(MessageBoxResult.Cancel);
            });

            Owner       = null;
            DataContext = this;
            InitializeComponent();
            Buttons = new Control[0];

            TitleBlock.Text = $"User {args.UserName} wants to join. Allow?";

            if (!string.IsNullOrWhiteSpace(args.AvatarUrl))
            {
                Image.Filename = $"{args.AvatarUrl}?size=128";
            }
            else
            {
                Image.Visibility = Visibility.Collapsed;
            }

            this.OnActualUnload(OnUnload);

            var config = new IniFile(AcPaths.GetCfgControlsFilename());

            _yes = new ControlsInput(config["__CM_DISCORD_REQUEST_ACCEPT"], Keys.Enter);
            _no  = new ControlsInput(config["__CM_DISCORD_REQUEST_DENY"], Keys.Back);

            try {
                SetDevices().Ignore();
                _yes.SetIcon(YesIcon, this);
                _no.SetIcon(NoIcon, this);
            } catch (Exception e) {
                Logging.Error(e);
            }

            _inGameAppParams = new CmInGameAppJoinRequestParams(args.UserName, args.UserId, args.AvatarUrl,
                                                                b => (b ? YesCommand : NoCommand).ExecuteAsync().Ignore());
            CompositionTargetEx.Rendering += OnRendering;
        }
Esempio n. 10
0
        public static bool IsTargetablePrefix(TargetingSystem __instance, ref bool __result, ref Character ___m_character, Character _character)
        {
            //checks the stack to see if this was called from certain functions that need to have different behavior
            bool checkFrame(StackFrame f)
            {
                System.Reflection.MethodBase method = f.GetMethod();
                //UnityEngine.Debug.Log("Method.Name checked: " + method.Name);
                return(method.Name.Contains("CheckIfCombatWorthy") || method.Name.Contains("IsEnemyClose") || method.DeclaringType == typeof(TargetingSystem) && !method.Name.Contains("IsTargetable"));
            }

            UnityEngine.Debug.Log("FriendlyFire - IsTargetablePatch() Stacktrace: \r\n" + Environment.StackTrace);
            //UnityEngine.Debug.Log("FriendlyFire - IsTargetablePatch() " + _character);
            //foreach (Character c in instance.m_character.EngagedCharacters)
            //{
            //    UnityEngine.Debug.Log("Engaged: " + c);
            //}

            StackTrace st = new StackTrace();
            IEnumerable <StackFrame> frames = from StackFrame sf in st.GetFrames()
                                              where checkFrame(sf)
                                              select sf;

            //any stackframes that met the initial conditions
            if (frames.Any())
            {
                //UnityEngine.Debug.Log("FriendlyFire - IsTargetablePatch() Stacktrace: \r\n" + Environment.StackTrace);
                //UnityEngine.Debug.Log("FriendlyFire - Found this frame: " + frames);
                if (_character.Faction == Character.Factions.Player &&
                    (_character == ___m_character || !ControlsInput.Sprint(___m_character.OwnerPlayerSys.PlayerID) ||
                     //fixes resting and combat music
                     frames.Any(x => x.GetMethod().Name == "IsEnemyClose" || frames.Any(y => y.GetMethod().Name == "CheckIfCombatWorthy"))))
                {
                    __result = false;
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 11
0
 internal bool QuickSlotInstant12(int _playerID)
 {
     return(ControlsInput.QuickSlotToggle2(_playerID) && ControlsInput.QuickSlotToggle1(_playerID) && ControlsInput.QuickSlot4(_playerID));
 }
        public void detectMovementInputs(On.LocalCharacterControl.orig_DetectMovementInputs orig, LocalCharacterControl self)
        {
            Type tSelf = self.GetType();

            // Remove the need for reflection as much as possible
            // These need to be manually set
            Vector2 sm_moveInput;
            Vector3 sm_modifMoveInput;

            // This should update anything changed inside of it
            Character m_character = self.Character;

            if (self.InputLocked)
            {
                sm_moveInput      = Vector2.zero;
                sm_modifMoveInput = (Vector3)Vector2.zero;
                // Exit condition, so set stuff
                m_moveInput.SetValue(self, sm_moveInput);
                m_modifMoveInput.SetValue(self, sm_modifMoveInput);

                if (!m_character.Sprinting)
                {
                    return;
                }
                m_character.SprintInput(false);
            }
            else
            {
                // Static methods are great
                sm_moveInput.x = ControlsInput.MoveHorizontal(m_character.OwnerPlayerSys.PlayerID);
                sm_moveInput.y = ControlsInput.MoveVertical(m_character.OwnerPlayerSys.PlayerID);

                // If we're autorunning
                if ((bool)m_autoRun.GetValue(self))
                {
                    if ((double)sm_moveInput.y == 0.0)
                    {
                        sm_moveInput.y = 1f;
                    }
                    else
                    {
                        StopAutoRun.Invoke(self, null);
                    }
                }

                // Make sure the magnitude of our input vector is at max 1
                sm_moveInput = (Vector2)Vector3.ClampMagnitude((Vector3)sm_moveInput, 1f);
                // Switch to 3D vector
                sm_modifMoveInput = (Vector3)sm_moveInput;

                // Sprinting
                if (ControlsInput.Sprint(m_character.OwnerPlayerSys.PlayerID) && m_character.InLocomotion && m_character.Stats.CanSprint() && ((!m_character.LocomotionAction || (double)m_character.MobileCastMoveMult == -1.0) && (double)sm_moveInput.sqrMagnitude > 0.100000001490116))
                {
                    // We can cast this because m_sprintTime is always a float
                    m_sprintTime.SetValue(self, (float)m_sprintTime.GetValue(self) + Time.deltaTime);

                    if (m_character.Sneaking)
                    {
                        m_character.StealthInput(false);
                    }
                    if (m_character.CurrentlyChargingAttack && !m_character.CancelChargingSent)
                    {
                        m_character.CancelCharging();
                    }

                    // I think this normalize call is pointless
                    sm_modifMoveInput.Normalize();
                    sm_modifMoveInput *= m_character.Speed * 1.75f;
                    m_sprintFacing.SetValue(self, true);
                    m_character.SprintInput(true);

                    if (m_character.BlockDesired)
                    {
                        m_character.BlockInput(false);
                    }
                }
                else // Not sprinting
                {
                    m_sprintTime.SetValue(self, 0.0f);

                    // Do the calculations for our speed normally, then apply modifiers
                    // Having your weapon unsheathed makes you 12.5% slower
                    sm_modifMoveInput *= !m_character.Sheathed ? m_character.Speed * 0.875f : m_character.Speed;

                    // Modify speed based on sneaking status
                    if (m_character.Sneaking)
                    {
                        // Vanilla values have movement speed capped at 2.3 while sneaking, with a 30% increase with the skill
                        float sneakMod = baseSneakSpeed;

                        // Handle "Stealth Training" skill
                        if (m_character.Inventory.SkillKnowledge.IsItemLearned(8205190))
                        {
                            sneakMod *= stealthTrainingBonus;
                        }

                        sm_modifMoveInput *= sneakMod;
                    }


                    if (m_character.Sprinting)
                    {
                        m_character.SprintInput(false);
                    }
                    if (m_character.Blocking || m_character.CurrentlyChargingAttack)
                    {
                        sm_modifMoveInput *= 0.6f;
                    }
                    if (!m_character.LocomotionAllowed)
                    {
                        sm_modifMoveInput *= 0.1f;
                    }
                    if (m_character.LocomotionAction && (double)m_character.MobileCastMoveMult > 0.0)
                    {
                        sm_modifMoveInput *= m_character.MobileCastMoveMultSmooth;
                    }
                    if (m_character.Sliding)
                    {
                        sm_modifMoveInput *= 0.6f;
                    }
                    if (m_character.Falling)
                    {
                        sm_modifMoveInput *= 0.3f;
                    }

                    if (self.FaceLikeCamera)
                    {
                        Vector2 modifMoveInput = (Vector2)sm_modifMoveInput;
                        float   num            = 0.1f;
                        sm_modifMoveInput.y *= (float)(1.0 + (double)Mathf.Abs(modifMoveInput.x) * (double)num);
                        sm_modifMoveInput.x *= (float)(1.0 + (double)Mathf.Abs(modifMoveInput.y) * (double)num);
                    }
                    m_sprintFacing.SetValue(self, false);
                }
                // General movement modifiers
                sm_modifMoveInput *= self.MovementMultiplier * m_character.Stats.MovementSpeed;

                if (m_character.PreparingToSleep)
                {
                    sm_modifMoveInput *= 0.0f;
                }

                // There is an exit condition ahead, so set values
                m_modifMoveInput.SetValue(self, sm_modifMoveInput);
                m_moveInput.SetValue(self, sm_moveInput);

                if ((m_character.CharacterUI == null || !m_character.CharacterUI.IsMenuJustToggled) && ControlsInput.DodgeButton(m_character.OwnerPlayerSys.PlayerID))
                {
                    Transform horiControl = (Transform)m_horiControl.GetValue(self);

                    m_character.DodgeInput(horiControl.forward * sm_moveInput.y + horiControl.right * sm_moveInput.x);
                    StopAutoRun.Invoke(self, null);
                }
                if (ControlsInput.AutoRun(m_character.OwnerPlayerSys.PlayerID))
                {
                    m_autoRun.SetValue(self, !(bool)m_autoRun.GetValue(self));
                }

                if (!((bool)m_character.CharacterUI) || m_character.CharacterUI.IsMenuJustToggled || (ControlsInput.QuickSlotToggled(m_character.OwnerPlayerSys.PlayerID) || !ControlsInput.StealthButton(m_character.OwnerPlayerSys.PlayerID)))
                {
                    return;
                }

                m_character.StealthInput(!m_character.Sneaking);
            }
        }
Esempio n. 13
0
 private bool AnyQuickSlotUsed(int playerID)
 {
     return(ControlsInput.QuickSlotInstant1(playerID) || ControlsInput.QuickSlotInstant2(playerID) || ControlsInput.QuickSlotInstant3(playerID) ||
            ControlsInput.QuickSlotInstant4(playerID) || ControlsInput.QuickSlotInstant5(playerID) || ControlsInput.QuickSlotInstant6(playerID) ||
            ControlsInput.QuickSlotInstant7(playerID) || ControlsInput.QuickSlotInstant8(playerID));
 }
Esempio n. 14
0
 // Constructor
 public ControlsData(ControlsInput controlsInput)
 {
     inputAction       = controlsInput.m_Action;
     inputActionString = controlsInput.m_Action.ToString();
 }
Esempio n. 15
0
 public static bool Prefix(int _playerID, ref bool __result, Dictionary <int, RewiredInputs> ___m_playerInputManager)
 {
     __result = ___m_playerInputManager[_playerID].GetButtonDown("QS_Instant4") || (!ControlsInput.QuickSlotToggle2(_playerID) && ControlsInput.QuickSlotToggle1(_playerID) && ControlsInput.QuickSlot4(_playerID));
     return(false);
 }
Esempio n. 16
0
 static public bool IsUsingGamepad(int playerID)
 => ControlsInput.IsLastActionGamepad(playerID);
Esempio n. 17
0
        public static bool UpdateQuickSlotsPrefix(LocalCharacterControl __instance)
        {
            if (__instance.Character != null && __instance.Character.QuickSlotMngr != null)
            {
                int playerID = __instance.Character.OwnerPlayerSys.PlayerID;
                if (!__instance.Character.CharacterUI.IsMenuFocused)
                {
                    __instance.Character.QuickSlotMngr.ShowQuickSlotSection1 = ControlsInput.QuickSlotToggle1(playerID);
                    __instance.Character.QuickSlotMngr.ShowQuickSlotSection2 = ControlsInput.QuickSlotToggle2(playerID);
                }

                if (m_playerInputManager[playerID].GetButtonDown("Sit_Emote"))
                {
                    __instance.Character.CastSpell(Character.SpellCastType.Sit, __instance.Character.gameObject, Character.SpellCastModifier.Immobilized, 1, -1f);
                }
                else if (m_playerInputManager[playerID].GetButtonDown("Alternate_Idle_Emote"))
                {
                    __instance.Character.CastSpell(Character.SpellCastType.IdleAlternate, __instance.Character.gameObject, Character.SpellCastModifier.Immobilized, 1, -1f);
                }
                else if (ControlsInput.QuickSlotInstant1(playerID))
                {
                    __instance.Character.QuickSlotMngr.QuickSlotInput(0);
                }
                else if (ControlsInput.QuickSlotInstant2(playerID))
                {
                    __instance.Character.QuickSlotMngr.QuickSlotInput(1);
                }
                else if (ControlsInput.QuickSlotInstant3(playerID))
                {
                    __instance.Character.QuickSlotMngr.QuickSlotInput(2);
                }
                else if (ControlsInput.QuickSlotInstant4(playerID))
                {
                    __instance.Character.QuickSlotMngr.QuickSlotInput(3);
                }
                else if (ControlsInput.QuickSlotInstant5(playerID))
                {
                    __instance.Character.QuickSlotMngr.QuickSlotInput(4);
                }
                else if (ControlsInput.QuickSlotInstant6(playerID))
                {
                    __instance.Character.QuickSlotMngr.QuickSlotInput(5);
                }
                else if (ControlsInput.QuickSlotInstant7(playerID))
                {
                    __instance.Character.QuickSlotMngr.QuickSlotInput(6);
                }
                else if (ControlsInput.QuickSlotInstant8(playerID))
                {
                    __instance.Character.QuickSlotMngr.QuickSlotInput(7);
                }
                else
                {
                    //Debug.Log("ExtendedQuickslots - UpdateQuickSlotsPatch() else");
                    for (var x = 0; x < ExtendedQuickslots.numSlots; ++x)
                    {
                        bool inputRecieved = m_playerInputManager[playerID].GetButtonDown(string.Format("QS_Instant{0}", x + 12));
                        //Debug.Log(string.Format("Checking QS_Instant{0}: {1}", x+12, inputRecieved));
                        if (inputRecieved)
                        {
                            Debug.Log("ExtendedQuickslots - UpdateQuickSlotsPatch() QS_Instant" + (x + 12));
                            __instance.Character.QuickSlotMngr.QuickSlotInput(x + 11);
                            break;
                        }
                    }
                }
            }
            return(false);
        }
        internal static void Override(CharacterCamera __instance, ref Vector2 ___m_cameraSmoothAutoInput, ref Vector2 ___m_cameraSmoothInput,
                                      bool ___m_invertedVer, bool ___m_invertedHor, ref Vector2 ___m_smoothCameraInput, Transform ___m_cameraVertHolder, Transform ___m_horiControl,
                                      Transform ___m_vertControl, CameraShaker ___m_shaker)
        {
            if (__instance.TargetCharacter == null || !NetworkLevelLoader.Instance.IsOverallLoadingDone || MenuManager.Instance.IsReturningToMainMenu)
            {
                return;
            }

            if (__instance.transform.position.y < -500f)
            {
                __instance.CameraScript.farClipPlane = 200f;
            }
            else
            {
                __instance.CameraScript.farClipPlane = 26000f;
            }

            float delta = Time.deltaTime;

            if (delta > 0.04f)
            {
                delta = 0.04f;
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // CHANGE: Removed ' * 0.5f ' from the RotateCameraVertical value.
            Vector2 cameraMove = new Vector2(ControlsInput.RotateCameraHorizontal(__instance.TargetCharacter.OwnerPlayerSys.PlayerID),
                                             ControlsInput.RotateCameraVertical(__instance.TargetCharacter.OwnerPlayerSys.PlayerID)); // * 0.5f));

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            if (__instance.TargetCharacter.CharacterUI)
            {
                float mouseSens = OptionManager.Instance.GetMouseSense(__instance.TargetCharacter.OwnerPlayerSys.PlayerID);
                mouseSens  /= 5f;
                cameraMove *= mouseSens;
            }

            cameraMove.x = Mathf.Clamp(cameraMove.x, -30f, 30f);
            cameraMove.y = Mathf.Clamp(cameraMove.y, -20f, 20f);

            // Controller smoothing
            if (ControlsInput.IsLastActionGamepad(__instance.TargetCharacter.OwnerPlayerSys.PlayerID))
            {
                if (cameraMove == Vector2.zero)
                {
                    Vector3 targetPos = Vector3.zero;

                    if (!__instance.TargetCharacter.IsDead)
                    {
                        targetPos = __instance.TargetCharacter.transform.TransformVector(new Vector3(__instance.TargetCharacter.AnimMove.x,
                                                                                                     0f,
                                                                                                     __instance.TargetCharacter.AnimMove.y));
                    }

                    targetPos = __instance.transform.InverseTransformVector(targetPos);

                    float angle = Vector3.forward.AngleWithDir(targetPos, Vector3.up);

                    Vector2 lerpTo = Vector2.zero;

                    if (Mathf.Abs(angle) > 15f)
                    {
                        if (angle > 0f && angle < 30f)
                        {
                            angle = Mathf.Clamp(angle * 1.5f, 20f, 40f);
                        }
                        else if (angle > -30f && angle < 0f)
                        {
                            angle = Mathf.Clamp(angle * 1.5f, -20f, -40f);
                        }

                        angle   /= 360f;
                        angle   *= targetPos.magnitude;
                        lerpTo.x = angle * 0.3f;
                    }

                    float t = (lerpTo.magnitude < 0.1f)
                                ? (Time.deltaTime * 5f)
                                : Mathf.Clamp(Time.deltaTime * 1f, 0f, 0.1f);

                    ___m_cameraSmoothAutoInput = Vector2.Lerp(___m_cameraSmoothAutoInput, lerpTo, t);
                }
                else
                {
                    ___m_cameraSmoothAutoInput = Vector2.Lerp(___m_cameraSmoothAutoInput, Vector2.zero, Time.deltaTime * 20f);
                }

                cameraMove += ___m_cameraSmoothAutoInput;
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // CHANGE: Commenting out these next two lines:
            //___m_cameraSmoothInput = Vector2.Lerp(___m_cameraSmoothInput, cameraMove, Mathf.Clamp(Time.deltaTime * 20f, 0f, 0.6f));
            //cameraMove = ___m_cameraSmoothInput;
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            if (Global.ListenToDebugInput && Input.GetKeyDown(KeyCode.KeypadPeriod))
            {
                OptionManager.Instance.ChangeInvertMouseY(__instance.TargetCharacter.OwnerPlayerSys.PlayerID, !___m_invertedVer);
            }

            cameraMove.y *= (float)(___m_invertedVer ? -1 : 1);
            cameraMove.x *= (float)(___m_invertedHor ? -1 : 1);

            if (__instance.LookAtTransform != null)
            {
                cameraMove *= 0.1f;
            }

            if (__instance.InZoomMode)
            {
                cameraMove *= __instance.ZoomSensModifier;
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // CHANGE: Commenting out these next three lines:
            //___m_smoothCameraInput = Vector2.Lerp(___m_smoothCameraInput, cameraMove, 15f * delta);
            //___m_smoothCameraInput = Vector2.MoveTowards(___m_smoothCameraInput, cameraMove, 5f * delta);
            //cameraMove = ___m_smoothCameraInput;
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            cameraMove *= ((__instance.LookAtTransform == null)
                            ? __instance.FreeSense
                            : __instance.LockedSense) * (ControlsInput.IsLastActionGamepad(__instance.TargetCharacter.OwnerPlayerSys.PlayerID)
                                                            ? delta
                                                            : 0.016f);

            __instance.transform.Rotate(new Vector3(0f, cameraMove.x, 0f));

            ___m_cameraVertHolder.Rotate(new Vector3(-cameraMove.y, 0f, 0f));

            // Vertical position / Lock-on
            if (__instance.LookAtTransform != null || __instance.OverrideTransform != null)
            {
                Vector3 vertPosition;
                if (!__instance.OverrideTransform)
                {
                    Vector3 position = __instance.LookAtTransform.transform.position;
                    position.y -= 0.8f;
                    float diffToPlayer = Mathf.Abs(__instance.LookAtTransform.transform.position.y - __instance.transform.position.y);
                    float diffToTarget = Mathf.Abs(__instance.LookAtTransform.transform.position.y - __instance.TargetCharacter.transform.position.y);
                    float normalize    = Mathf.Clamp(diffToPlayer * 0.5f, 1f, 10f);
                    vertPosition = position - __instance.transform.position;

                    float yCurve = __instance.YMinMaxCurve.Evaluate(Vector3.Distance(__instance.TargetCharacter.transform.position,
                                                                                     __instance.LookAtTransform.transform.position) * 0.1f);

                    float yNormalize = (diffToTarget < 5f) ? __instance.YMinMaxYDiffCurve.Evaluate(diffToTarget) : 1f;

                    yCurve *= yNormalize;

                    vertPosition.y  = Mathf.Clamp(vertPosition.y, -yCurve * normalize, yCurve * normalize);
                    vertPosition.y -= 0.5f;
                }
                else
                {
                    vertPosition = __instance.OverrideTransform.forward;
                }

                float vertAngle = Vector3.Angle(___m_cameraVertHolder.forward, vertPosition);

                ___m_cameraVertHolder.forward = Vector3.MoveTowards(___m_cameraVertHolder.forward,
                                                                    vertPosition,
                                                                    (__instance.RotSpeeds.x + vertAngle * __instance.RotSpeeds.y) * Time.deltaTime);

                __instance.transform.rotation = Quaternion.Euler(0f, ___m_cameraVertHolder.rotation.eulerAngles.y, 0f);
            }

            Vector3 diffToVert      = __instance.transform.InverseTransformDirection(___m_cameraVertHolder.forward);
            float   diffAngle       = new Vector2(diffToVert.z, diffToVert.y).Angle(new Vector2(1f, 0f));
            float   normalizedAngle = 75f;

            if (Mathf.Abs(diffAngle) > normalizedAngle)
            {
                normalizedAngle = (diffAngle > 0f)
                                    ? normalizedAngle
                                    : (-normalizedAngle);

                ___m_cameraVertHolder.Rotate(diffAngle - normalizedAngle, 0f, 0f, Space.Self);
            }

            ___m_cameraVertHolder.localRotation = Quaternion.Euler(___m_cameraVertHolder.localRotation.eulerAngles.x, 0f, 0f);
            ___m_horiControl.transform.rotation = __instance.transform.rotation;
            ___m_vertControl.transform.rotation = ___m_cameraVertHolder.rotation;

            if (___m_shaker && !Global.GamePaused)
            {
                ___m_shaker.RealPosition = __instance.CameraScript.transform.localPosition;
                ___m_shaker.RealRotation = Quaternion.identity;
            }

            if (s_updateZoomMethod == null)
            {
                s_updateZoomMethod = typeof(CharacterCamera).GetMethod("UpdateZoom", BindingFlags.NonPublic | BindingFlags.Instance);
            }

            s_updateZoomMethod.Invoke(__instance, new object[0]);
        }
Esempio n. 19
0
            public static bool Prefix(LocalCharacterControl __instance)
            {
                var self = __instance;

                var m_character       = At.GetField(self as CharacterControl, "m_character") as Character;
                var m_targetingSystem = m_character.TargetingSystem;

                bool m_lockHoldUp = false;

                if (!m_character.CharacterCamera.InZoomMode &&
                    (ControlsInput.LockToggle(m_character.OwnerPlayerSys.PlayerID) || ControlsInput.LockHoldDown(m_character.OwnerPlayerSys.PlayerID)))
                {
                    At.SetField(self, "m_lockHoldUp", false);

                    if (m_targetingSystem.Locked)
                    {
                        At.Invoke(self, "ReleaseTarget");

                        if (self.ControlMode == LocalCharacterControl.CameraControlMode.Classic)
                        {
                            self.FaceLikeCamera = false;
                        }
                    }
                    else
                    {
                        At.Invoke(self, "AcquireTarget");

                        if (m_targetingSystem.Locked && self.ControlMode == LocalCharacterControl.CameraControlMode.Classic)
                        {
                            self.FaceLikeCamera = true;
                        }
                    }
                }

                if (ControlsInput.LockHoldUp(m_character.OwnerPlayerSys.PlayerID))
                {
                    m_lockHoldUp = true;
                    At.SetField(self, "m_lockHoldUp", true);
                }

                if (!m_character.CharacterCamera.InZoomMode && m_lockHoldUp)
                {
                    At.Invoke(self, "ReleaseTarget");
                }

                if (Input.GetMouseButtonDown(3) && self.TargetMode == LocalCharacterControl.TargetingMode.Aim)
                {
                    Ray ray = m_character.CharacterCamera.CameraScript.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast(ray, out RaycastHit raycastHit, m_targetingSystem.TrueRange * 1.5f, Global.AimTargetMask))
                    {
                        LockingPoint lockingPoint = raycastHit.collider.GetComponent <LockingPoint>();
                        if (lockingPoint == null)
                        {
                            Character characterOwner = raycastHit.collider.GetCharacterOwner();
                            if (characterOwner)
                            {
                                lockingPoint = characterOwner.LockingPoint;
                            }
                        }
                        if (lockingPoint)
                        {
                            At.Invoke(self, "SwitchTarget", new object[] { lockingPoint });
                        }
                    }
                }

                if (m_targetingSystem.Locked && !m_character.CharacterCamera.InZoomMode)
                {
                    if (!self.FaceLikeCamera)
                    {
                        self.FaceLikeCamera = true;
                    }

                    if (self.TargetMode == LocalCharacterControl.TargetingMode.Classic)
                    {
                        Vector2 vector = new Vector2(
                            ControlsInput.SwitchTargetHorizontal(m_character.OwnerPlayerSys.PlayerID),
                            ControlsInput.SwitchTargetVertical(m_character.OwnerPlayerSys.PlayerID));

                        float magnitude = vector.magnitude;

                        float m_lastTargetSwitchTime = (float)At.GetField(self, "m_lastTargetSwitchTime");

                        if (Time.time - m_lastTargetSwitchTime > 0.3f)
                        {
                            //Vector2 m_previousInput = (Vector2)At.GetValue(typeof(LocalCharacterControl), self, "m_previousInput");
                            //float magnitude2 = (vector - m_previousInput).magnitude;

                            //if (magnitude2 >= 0.45f && magnitude > 0.6f)
                            //{
                            //    At.Call(self, "SwitchTarget", new object[] { vector });
                            //}

                            // this is for bows
                            if (m_character.CurrentWeapon is ProjectileWeapon)
                            {
                                var m_timeOfLastAimOffset = (float)At.GetField(self, "m_timeOfLastAimOffset");
                                var m_timeToNextAimOffset = (float)At.GetField(self, "m_timeToNextAimOffset");
                                var m_aimOffsetRandom     = (Vector2)At.GetField(self, "m_aimOffsetRandom");

                                if (ControlsInput.IsLastActionGamepad(m_character.OwnerPlayerSys.PlayerID))
                                {
                                    Vector2 a = vector;
                                    a.x *= -1f;
                                    if (Time.time - m_timeOfLastAimOffset > m_timeToNextAimOffset)
                                    {
                                        m_aimOffsetRandom = UnityEngine.Random.insideUnitCircle;
                                        At.SetField(self, "m_aimOffsetRandom", m_aimOffsetRandom);
                                        At.SetField(self, "m_timeOfLastAimOffset", Time.time);
                                        At.SetField(self, "m_timeToNextAimOffset", UnityEngine.Random.Range(0.1f, 0.3f));
                                    }

                                    a += m_aimOffsetRandom * ((Vector3)At.GetField(self, "m_modifMoveInput")).magnitude * Time.deltaTime * 0.5f;

                                    m_character.TargetingSystem.LockingPointOffset = Vector2.Scale(a, new Vector2(-1f, 1f));
                                }
                                else
                                {
                                    Vector2 vector2 = vector * self.LockAimMouseSense;
                                    vector2.x *= -1f;
                                    if (Time.time - m_timeOfLastAimOffset > m_timeToNextAimOffset)
                                    {
                                        m_aimOffsetRandom = UnityEngine.Random.insideUnitCircle;
                                        At.SetField(self, "m_aimOffsetRandom", m_aimOffsetRandom);
                                        At.SetField(self, "m_timeOfLastAimOffset", Time.time);
                                        At.SetField(self, "m_timeToNextAimOffset", UnityEngine.Random.Range(0.1f, 0.3f));
                                    }
                                    vector2 += m_aimOffsetRandom * ((Vector3)At.GetField(self, "m_modifMoveInput")).magnitude * Time.deltaTime * 0.5f;
                                    m_character.TargetingSystem.LockingPointOffset -= new Vector3(vector2.x, vector2.y, 0);
                                    m_character.TargetingSystem.LockingPointOffset  = Vector3.ClampMagnitude(m_character.TargetingSystem.LockingPointOffset, 1f);
                                }
                            }
                            At.SetField(self, "m_previousInput", vector);
                        }
                        else if (ControlsInput.IsLastActionGamepad(m_character.OwnerPlayerSys.PlayerID) && magnitude == 0f)
                        {
                            At.SetField(self, "m_lastTargetSwitchTime", 0f);
                        }
                    }
                    else if (self.TargetMode == LocalCharacterControl.TargetingMode.Aim)
                    {
                        Global.LockCursor(false);
                    }

                    Vector3 lockedPointPos    = m_targetingSystem.LockedPointPos;
                    float   m_lastInSightTime = (float)At.GetField(self, "m_lastInSightTime");
                    if (!Physics.Linecast(m_character.CenterPosition, lockedPointPos, Global.SightHideMask))
                    {
                        m_lastInSightTime = Time.time;
                        At.SetField(self, "m_lastInSightTime", m_lastInSightTime);
                    }

                    bool isLocked = m_targetingSystem.LockedCharacter != null && !m_targetingSystem.LockedCharacter.Alive;
                    if (Vector3.Distance(lockedPointPos, m_character.CenterPosition) > m_targetingSystem.TrueRange + 2f || Time.time - m_lastInSightTime > 1f || isLocked)
                    {
                        At.Invoke(self, "ReleaseTarget");
                        self.Invoke("AcquireTarget", 0.5f);
                    }
                }
                else
                {
                    m_targetingSystem.LockingPointOffset = Vector3.zero;
                    if (m_character.CharacterCamera.InZoomMode)
                    {
                        float m_lastFreeAimUpdateTime = (float)At.GetField(self, "m_lastFreeAimUpdateTime");
                        if (Time.time - m_lastFreeAimUpdateTime > 0.05f)
                        {
                            m_lastFreeAimUpdateTime = Time.time;
                            At.SetField(self, "m_lastFreeAimUpdateTime", m_lastFreeAimUpdateTime);

                            bool m_debugFreeAim = (bool)At.GetField(self, "m_debugFreeAim");

                            At.SetField(self, "m_freeAimTargetPos", m_character.CharacterCamera.GetObstaclePos(new Vector3(0.5f, 0.5f, 0f), m_debugFreeAim));
                        }


                        var m_freeAimLockingPoint = At.GetField(self, "m_freeAimLockingPoint") as LockingPoint;
                        var m_freeAimTargetPos    = (Vector3)At.GetField(self, "m_freeAimTargetPos");
                        if ((bool)At.GetField(self, "m_wasFreeAiming"))
                        {
                            float num = (m_freeAimLockingPoint.transform.position - m_freeAimTargetPos).sqrMagnitude;
                            num = Mathf.Max(num, 10f);
                            m_freeAimLockingPoint.transform.position = Vector3.Lerp(m_freeAimLockingPoint.transform.position, m_freeAimTargetPos, num * Time.deltaTime);
                        }
                        else
                        {
                            m_freeAimLockingPoint.transform.position = m_freeAimTargetPos;
                        }
                    }
                }

                At.SetField(self, "m_wasFreeAiming", m_character.CharacterCamera.InZoomMode);

                return(false);
            }
Esempio n. 20
0
            public static bool Prefix(LocalCharacterControl __instance)
            {
                var self = __instance;

                var character       = self.m_character;
                var targetingSystem = character.TargetingSystem;

                if (!character.CharacterCamera.InZoomMode &&
                    (ControlsInput.LockToggle(character.OwnerPlayerSys.PlayerID) ||
                     ControlsInput.LockHoldDown(character.OwnerPlayerSys.PlayerID)))
                {
                    self.m_lockHoldUp = false;

                    if (targetingSystem.Locked)
                    {
                        self.ReleaseTarget();

                        if (self.ControlMode == LocalCharacterControl.CameraControlMode.Classic)
                        {
                            self.FaceLikeCamera = false;
                        }
                    }
                    else
                    {
                        self.AcquireTarget();

                        if (targetingSystem.Locked && self.ControlMode == LocalCharacterControl.CameraControlMode.Classic)
                        {
                            self.FaceLikeCamera = true;
                        }
                    }
                }

                if (ControlsInput.LockHoldUp(character.OwnerPlayerSys.PlayerID))
                {
                    self.m_lockHoldUp = true;
                }

                if (!character.CharacterCamera.InZoomMode && self.m_lockHoldUp)
                {
                    self.ReleaseTarget();
                }

                if (Input.GetMouseButtonDown(3) && self.TargetMode == LocalCharacterControl.TargetingMode.Aim)
                {
                    Ray ray = character.CharacterCamera.CameraScript.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast(ray, out RaycastHit raycastHit, targetingSystem.TrueRange * 1.5f, Global.AimTargetMask))
                    {
                        LockingPoint lockingPoint = raycastHit.collider.GetComponent <LockingPoint>();
                        if (lockingPoint == null)
                        {
                            Character characterOwner = raycastHit.collider.GetCharacterOwner();
                            if (characterOwner)
                            {
                                lockingPoint = characterOwner.LockingPoint;
                            }
                        }
                        if (lockingPoint)
                        {
                            self.SwitchTarget(lockingPoint);
                        }
                    }
                }

                if (targetingSystem.Locked && !character.CharacterCamera.InZoomMode)
                {
                    if (!self.FaceLikeCamera)
                    {
                        self.FaceLikeCamera = true;
                    }

                    if (self.TargetMode == LocalCharacterControl.TargetingMode.Classic)
                    {
                        Vector2 inputVector = new Vector2(
                            ControlsInput.SwitchTargetHorizontal(character.OwnerPlayerSys.PlayerID),
                            ControlsInput.SwitchTargetVertical(character.OwnerPlayerSys.PlayerID));

                        if (character.CurrentWeapon is ProjectileWeapon)
                        {
                            // this is for bows
                            if (ControlsInput.IsLastActionGamepad(character.OwnerPlayerSys.PlayerID))
                            {
                                Vector2 bowVector = inputVector;
                                bowVector.x *= -1f;
                                if (Time.time - self.m_timeOfLastAimOffset > self.m_timeToNextAimOffset)
                                {
                                    self.m_aimOffsetRandom     = UnityEngine.Random.insideUnitCircle;
                                    self.m_timeOfLastAimOffset = Time.time;
                                    self.m_timeToNextAimOffset = UnityEngine.Random.Range(0.1f, 0.3f);
                                }
                                bowVector += self.m_aimOffsetRandom * self.m_modifMoveInput.magnitude * Time.deltaTime * 0.5f;
                                character.TargetingSystem.LockingPointOffset = Vector2.Scale(bowVector, new Vector2(-1f, 1f));
                            }
                            else
                            {
                                Vector2 aimVector = inputVector * self.LockAimMouseSense;
                                aimVector.x *= -1f;
                                if (Time.time - self.m_timeOfLastAimOffset > self.m_timeToNextAimOffset)
                                {
                                    self.m_aimOffsetRandom     = UnityEngine.Random.insideUnitCircle;
                                    self.m_timeOfLastAimOffset = Time.time;
                                    self.m_timeToNextAimOffset = UnityEngine.Random.Range(0.1f, 0.3f);
                                }
                                aimVector += self.m_aimOffsetRandom * self.m_modifMoveInput.magnitude * Time.deltaTime * 0.5f;
                                character.TargetingSystem.LockingPointOffset -= new Vector3(aimVector.x, aimVector.y, 0);
                                character.TargetingSystem.LockingPointOffset  = Vector3.ClampMagnitude(
                                    character.TargetingSystem.LockingPointOffset,
                                    1f);
                            }
                        }
                        self.m_previousInput = inputVector;
                    }
                    else if (self.TargetMode == LocalCharacterControl.TargetingMode.Aim)
                    {
                        Global.LockCursor(false);
                    }

                    Vector3 lockedPointPos = targetingSystem.LockedPointPos;
                    if (!Physics.Linecast(character.CenterPosition, lockedPointPos, Global.SightHideMask))
                    {
                        self.m_lastInSightTime = Time.time;
                    }

                    bool isLocked = targetingSystem.LockedCharacter != null && targetingSystem.LockedCharacter.Alive;
                    if (Vector3.Distance(lockedPointPos, character.CenterPosition) > targetingSystem.TrueRange + 2f ||
                        Time.time - self.m_lastInSightTime > 1f ||
                        !isLocked)
                    {
                        self.ReleaseTarget();
                        self.Invoke("AcquireTarget", 0.5f);
                    }
                }
                else
                {
                    targetingSystem.LockingPointOffset = Vector3.zero;
                    if (character.CharacterCamera.InZoomMode)
                    {
                        if (Time.time - self.m_lastFreeAimUpdateTime > 0.05f)
                        {
                            self.m_lastFreeAimUpdateTime = Time.time;
                            self.m_freeAimTargetPos      = character.CharacterCamera.GetObstaclePos(new Vector3(0.5f, 0.5f, 0f), self.m_debugFreeAim);
                        }

                        if (self.m_wasFreeAiming)
                        {
                            float num = (self.m_freeAimLockingPoint.transform.position - self.m_freeAimTargetPos).sqrMagnitude;
                            num = Mathf.Max(num, 10f);
                            self.m_freeAimLockingPoint.transform.position = Vector3.Lerp(
                                self.m_freeAimLockingPoint.transform.position,
                                self.m_freeAimTargetPos, num * Time.deltaTime);
                        }
                        else
                        {
                            self.m_freeAimLockingPoint.transform.position = self.m_freeAimTargetPos;
                        }
                    }
                }

                self.m_wasFreeAiming = character.CharacterCamera.InZoomMode;

                return(false);
            }