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); }
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); }