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); }
static public bool IsUsingGamepad(int playerID) => ControlsInput.IsLastActionGamepad(playerID);
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]); }
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); }