Example #1
0
    private void ProcessInput(ref HumanController.InputSample sample)
    {
        bool flag;
        bool flag1;

        CCMotor.InputFrame movementScale = new CCMotor.InputFrame();
        float   single;
        float   single1;
        CCMotor cCMotor = base.ccmotor;

        if (!cCMotor)
        {
            flag1 = false;
            flag  = true;
        }
        else
        {
            flag  = cCMotor.isGrounded;
            flag1 = cCMotor.isSliding;
            if (!flag && !flag1)
            {
                sample.sprint = false;
                sample.crouch = false;
                sample.aim    = false;
                sample.info__crouchBlocked = false;
                if (!this.wasInAir)
                {
                    this.wasInAir       = true;
                    this.magnitudeAir   = cCMotor.input.moveDirection.magnitude;
                    this.midairStartPos = base.transform.position;
                }
                this.lastFrameVelocity = cCMotor.velocity;
            }
            else if (this.wasInAir)
            {
                this.wasInAir                = false;
                this.magnitudeAir            = 1f;
                this.landingSpeedPenaltyTime = 0f;
                if (base.transform.position.y < this.midairStartPos.y && Mathf.Abs(base.transform.position.y - this.midairStartPos.y) > 2f)
                {
                    base.idMain.GetLocal <FallDamage>().SendFallImpact(this.lastFrameVelocity);
                }
                this.lastFrameVelocity = Vector3.zero;
                this.midairStartPos    = Vector3.zero;
            }
            bool flag2 = (sample.crouch ? true : sample.info__crouchBlocked);
            movementScale.jump            = sample.jump;
            movementScale.moveDirection.x = sample.strafe;
            movementScale.moveDirection.y = 0f;
            movementScale.moveDirection.z = sample.walk;
            movementScale.crouchSpeed     = (!sample.crouch ? 1f : -1f);
            if (movementScale.moveDirection == Vector3.zero)
            {
                this.sprinting     = false;
                this.exitingSprint = false;
                this.sprintTime    = 0f;
                this.crouchTime    = (!sample.crouch ? 0f : this.controlConfig.curveCrouchMulSpeedByTime.GetEndTime());
                this.magnitudeAir  = 1f;
            }
            else
            {
                float single2 = movementScale.moveDirection.magnitude;
                if (single2 < 1f)
                {
                    movementScale.moveDirection = movementScale.moveDirection / single2;
                    single2 = single2 * single2;
                    movementScale.moveDirection = movementScale.moveDirection * single2;
                }
                else if (single2 > 1f)
                {
                    movementScale.moveDirection = movementScale.moveDirection / single2;
                }
                if (HumanController.InputSample.MovementScale < 1f)
                {
                    if (HumanController.InputSample.MovementScale <= 0f)
                    {
                        movementScale.moveDirection = Vector3.zero;
                    }
                    else
                    {
                        movementScale.moveDirection = movementScale.moveDirection * HumanController.InputSample.MovementScale;
                    }
                }
                Vector3 vector3 = movementScale.moveDirection;
                vector3.x = vector3.x * this.controlConfig.sprintScaleX;
                vector3.z = vector3.z * this.controlConfig.sprintScaleY;
                if (!sample.sprint || flag2 || sample.aim)
                {
                    sample.sprint = false;
                    single        = -Time.deltaTime;
                }
                else
                {
                    single = Time.deltaTime * this.sprintInMulTime;
                }
                movementScale.moveDirection = movementScale.moveDirection + (vector3 * this.controlConfig.curveSprintAddSpeedByTime.EvaluateClampedTime(ref this.sprintTime, single));
                single1 = (!flag2 ? -Time.deltaTime : Time.deltaTime * this.crouchInMulTime);
                movementScale.moveDirection = movementScale.moveDirection * this.controlConfig.curveCrouchMulSpeedByTime.EvaluateClampedTime(ref this.crouchTime, single1);
                movementScale.moveDirection = base.transform.TransformDirection(movementScale.moveDirection);
                if (!this.wasInAir)
                {
                    movementScale.moveDirection = movementScale.moveDirection * this.controlConfig.curveLandingSpeedPenalty.EvaluateClampedTime(ref this.landingSpeedPenaltyTime, Time.deltaTime);
                }
                else
                {
                    float single3 = movementScale.moveDirection.magnitude;
                    if (!Mathf.Approximately(single3, this.magnitudeAir))
                    {
                        movementScale.moveDirection = movementScale.moveDirection / single3;
                        movementScale.moveDirection = movementScale.moveDirection * this.magnitudeAir;
                    }
                }
            }
            if (DebugInput.GetKey(KeyCode.H))
            {
                movementScale.moveDirection = movementScale.moveDirection * 100f;
            }
            cCMotor.input = movementScale;
            if (cCMotor.stepMode == CCMotor.StepMode.Elsewhere)
            {
                cCMotor.Step();
            }
        }
        Character  character  = base.idMain;
        Crouchable crouchable = character.crouchable;

        if (character)
        {
            Angle2 angle2  = base.eyesAngles;
            Angle2 angle21 = base.eyesAngles;
            angle2.yaw      = Mathf.DeltaAngle(0f, angle21.yaw + sample.yaw);
            angle2.pitch    = base.ClampPitch(angle2.pitch + sample.pitch);
            base.eyesAngles = angle2;
            ushort num = character.stateFlags.flags;
            if (crouchable)
            {
                this.crouch_smoothing.AddSeconds((double)Time.deltaTime);
                crouchable.LocalPlayerUpdateCrouchState(cCMotor, ref sample.crouch, ref sample.info__crouchBlocked, ref this.crouch_smoothing);
            }
            int num1 = (!sample.aim ? 0 : 4) | (!sample.sprint ? 0 : 2) | (!sample.attack ? 0 : 8) | (!sample.attack2 ? 0 : 256) | (!sample.crouch ? 0 : 1) | (sample.strafe != 0f || sample.walk != 0f ? 64 : 0) | (!LockCursorManager.IsLocked() ? 128 : 0) | (!flag ? 16 : 0) | (!flag1 ? 0 : 32) | (!this.bleeding ? 0 : 512) | (!sample.lamp ? 0 : 2048) | (!sample.laser ? 0 : 4096) | (!sample.info__crouchBlocked ? 0 : 1024);
            character.stateFlags = num1;
            if (num != num1)
            {
                character.Signal_State_FlagsChanged(false);
            }
        }
        this.crouch_was_blocked = sample.info__crouchBlocked;
        if (sample.inventory)
        {
            RPOS.Toggle();
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            RPOS.Hide();
        }
    }
Example #2
0
 private void ProcessInput(ref HumanController.InputSample sample)
 {
     bool flag;
     bool flag1;
     CCMotor.InputFrame movementScale = new CCMotor.InputFrame();
     float single;
     float single1;
     CCMotor cCMotor = base.ccmotor;
     if (!cCMotor)
     {
         flag1 = false;
         flag = true;
     }
     else
     {
         flag = cCMotor.isGrounded;
         flag1 = cCMotor.isSliding;
         if (!flag && !flag1)
         {
             sample.sprint = false;
             sample.crouch = false;
             sample.aim = false;
             sample.info__crouchBlocked = false;
             if (!this.wasInAir)
             {
                 this.wasInAir = true;
                 this.magnitudeAir = cCMotor.input.moveDirection.magnitude;
                 this.midairStartPos = base.transform.position;
             }
             this.lastFrameVelocity = cCMotor.velocity;
         }
         else if (this.wasInAir)
         {
             this.wasInAir = false;
             this.magnitudeAir = 1f;
             this.landingSpeedPenaltyTime = 0f;
             if (base.transform.position.y < this.midairStartPos.y && Mathf.Abs(base.transform.position.y - this.midairStartPos.y) > 2f)
             {
                 base.idMain.GetLocal<FallDamage>().SendFallImpact(this.lastFrameVelocity);
             }
             this.lastFrameVelocity = Vector3.zero;
             this.midairStartPos = Vector3.zero;
         }
         bool flag2 = (sample.crouch ? true : sample.info__crouchBlocked);
         movementScale.jump = sample.jump;
         movementScale.moveDirection.x = sample.strafe;
         movementScale.moveDirection.y = 0f;
         movementScale.moveDirection.z = sample.walk;
         movementScale.crouchSpeed = (!sample.crouch ? 1f : -1f);
         if (movementScale.moveDirection == Vector3.zero)
         {
             this.sprinting = false;
             this.exitingSprint = false;
             this.sprintTime = 0f;
             this.crouchTime = (!sample.crouch ? 0f : this.controlConfig.curveCrouchMulSpeedByTime.GetEndTime());
             this.magnitudeAir = 1f;
         }
         else
         {
             float single2 = movementScale.moveDirection.magnitude;
             if (single2 < 1f)
             {
                 movementScale.moveDirection = movementScale.moveDirection / single2;
                 single2 = single2 * single2;
                 movementScale.moveDirection = movementScale.moveDirection * single2;
             }
             else if (single2 > 1f)
             {
                 movementScale.moveDirection = movementScale.moveDirection / single2;
             }
             if (HumanController.InputSample.MovementScale < 1f)
             {
                 if (HumanController.InputSample.MovementScale <= 0f)
                 {
                     movementScale.moveDirection = Vector3.zero;
                 }
                 else
                 {
                     movementScale.moveDirection = movementScale.moveDirection * HumanController.InputSample.MovementScale;
                 }
             }
             Vector3 vector3 = movementScale.moveDirection;
             vector3.x = vector3.x * this.controlConfig.sprintScaleX;
             vector3.z = vector3.z * this.controlConfig.sprintScaleY;
             if (!sample.sprint || flag2 || sample.aim)
             {
                 sample.sprint = false;
                 single = -Time.deltaTime;
             }
             else
             {
                 single = Time.deltaTime * this.sprintInMulTime;
             }
             movementScale.moveDirection = movementScale.moveDirection + (vector3 * this.controlConfig.curveSprintAddSpeedByTime.EvaluateClampedTime(ref this.sprintTime, single));
             single1 = (!flag2 ? -Time.deltaTime : Time.deltaTime * this.crouchInMulTime);
             movementScale.moveDirection = movementScale.moveDirection * this.controlConfig.curveCrouchMulSpeedByTime.EvaluateClampedTime(ref this.crouchTime, single1);
             movementScale.moveDirection = base.transform.TransformDirection(movementScale.moveDirection);
             if (!this.wasInAir)
             {
                 movementScale.moveDirection = movementScale.moveDirection * this.controlConfig.curveLandingSpeedPenalty.EvaluateClampedTime(ref this.landingSpeedPenaltyTime, Time.deltaTime);
             }
             else
             {
                 float single3 = movementScale.moveDirection.magnitude;
                 if (!Mathf.Approximately(single3, this.magnitudeAir))
                 {
                     movementScale.moveDirection = movementScale.moveDirection / single3;
                     movementScale.moveDirection = movementScale.moveDirection * this.magnitudeAir;
                 }
             }
         }
         if (DebugInput.GetKey(KeyCode.H))
         {
             movementScale.moveDirection = movementScale.moveDirection * 100f;
         }
         cCMotor.input = movementScale;
         if (cCMotor.stepMode == CCMotor.StepMode.Elsewhere)
         {
             cCMotor.Step();
         }
     }
     Character character = base.idMain;
     Crouchable crouchable = character.crouchable;
     if (character)
     {
         Angle2 angle2 = base.eyesAngles;
         Angle2 angle21 = base.eyesAngles;
         angle2.yaw = Mathf.DeltaAngle(0f, angle21.yaw + sample.yaw);
         angle2.pitch = base.ClampPitch(angle2.pitch + sample.pitch);
         base.eyesAngles = angle2;
         ushort num = character.stateFlags.flags;
         if (crouchable)
         {
             this.crouch_smoothing.AddSeconds((double)Time.deltaTime);
             crouchable.LocalPlayerUpdateCrouchState(cCMotor, ref sample.crouch, ref sample.info__crouchBlocked, ref this.crouch_smoothing);
         }
         int num1 = (!sample.aim ? 0 : 4) | (!sample.sprint ? 0 : 2) | (!sample.attack ? 0 : 8) | (!sample.attack2 ? 0 : 256) | (!sample.crouch ? 0 : 1) | (sample.strafe != 0f || sample.walk != 0f ? 64 : 0) | (!LockCursorManager.IsLocked() ? 128 : 0) | (!flag ? 16 : 0) | (!flag1 ? 0 : 32) | (!this.bleeding ? 0 : 512) | (!sample.lamp ? 0 : 2048) | (!sample.laser ? 0 : 4096) | (!sample.info__crouchBlocked ? 0 : 1024);
         character.stateFlags = num1;
         if (num != num1)
         {
             character.Signal_State_FlagsChanged(false);
         }
     }
     this.crouch_was_blocked = sample.info__crouchBlocked;
     if (sample.inventory)
     {
         RPOS.Toggle();
     }
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         RPOS.Hide();
     }
 }