Exemplo n.º 1
0
        public void askInput(CSteamID steamID)
        {
            if (!base.channel.checkOwner(steamID))
            {
                return;
            }
            int  num = -1;
            byte b   = (byte)base.channel.read(Types.BYTE_TYPE);

            for (byte b2 = 0; b2 < b; b2 += 1)
            {
                byte b3 = (byte)base.channel.read(Types.BYTE_TYPE);
                PlayerInputPacket playerInputPacket;
                if (b3 > 0)
                {
                    playerInputPacket = new DrivingPlayerInputPacket();
                }
                else
                {
                    playerInputPacket = new WalkingPlayerInputPacket();
                }
                playerInputPacket.read(base.channel);
                if (playerInputPacket.sequence > this.sequence)
                {
                    this.sequence = playerInputPacket.sequence;
                    this.serversidePackets.Enqueue(playerInputPacket);
                    num = playerInputPacket.sequence;
                }
            }
            if (num == -1)
            {
                return;
            }
            base.channel.send("askAck", ESteamCall.OWNER, ESteamPacket.UPDATE_UNRELIABLE_INSTANT, new object[]
            {
                num
            });
            this.lastInputed = Time.realtimeSinceStartup;
            this.hasInputed  = true;
        }
Exemplo n.º 2
0
 private void FixedUpdate()
 {
     if (this.isDismissed)
     {
         return;
     }
     if (base.channel.isOwner)
     {
         if (this.count % PlayerInput.SAMPLES == 0u)
         {
             this._tick   = Time.realtimeSinceStartup;
             this.keys[0] = base.player.movement.jump;
             this.keys[1] = base.player.equipment.primary;
             this.keys[2] = base.player.equipment.secondary;
             this.keys[3] = base.player.stance.crouch;
             this.keys[4] = base.player.stance.prone;
             this.keys[5] = base.player.stance.sprint;
             this.keys[6] = base.player.animator.leanLeft;
             this.keys[7] = base.player.animator.leanRight;
             this.keys[8] = false;
             this.analog  = (byte)((int)base.player.movement.horizontal << 4 | (int)base.player.movement.vertical);
             base.player.life.simulate(this.simulation);
             base.player.stance.simulate(this.simulation, base.player.stance.crouch, base.player.stance.prone, base.player.stance.sprint);
             this.pitch = base.player.look.pitch;
             this.yaw   = base.player.look.yaw;
             base.player.movement.simulate(this.simulation, 0, (int)(base.player.movement.horizontal - 1), (int)(base.player.movement.vertical - 1), base.player.look.look_x, base.player.look.look_y, base.player.movement.jump, Vector3.zero, PlayerInput.RATE);
             if (Provider.isServer)
             {
                 this.inputs.Clear();
             }
             else
             {
                 this.sequence++;
                 if (base.player.stance.stance == EPlayerStance.DRIVING)
                 {
                     this.clientsidePackets.Add(new DrivingPlayerInputPacket());
                 }
                 else
                 {
                     this.clientsidePackets.Add(new WalkingPlayerInputPacket());
                 }
                 PlayerInputPacket playerInputPacket = this.clientsidePackets[this.clientsidePackets.Count - 1];
                 playerInputPacket.sequence = this.sequence;
                 playerInputPacket.recov    = this.recov;
             }
             base.player.equipment.simulate(this.simulation, base.player.equipment.primary, base.player.equipment.secondary, base.player.stance.sprint);
             base.player.animator.simulate(this.simulation, base.player.animator.leanLeft, base.player.animator.leanRight);
             this.buffer      += PlayerInput.SAMPLES;
             this._simulation += 1u;
         }
         if (this.consumed < this.buffer)
         {
             this.consumed += 1u;
             base.player.equipment.tock(this.clock);
             this._clock += 1u;
         }
         if (this.consumed == this.buffer && this.clientsidePackets.Count > 0 && !Provider.isServer)
         {
             ushort num = 0;
             byte   b   = 0;
             while ((int)b < this.keys.Length)
             {
                 if (this.keys[(int)b])
                 {
                     num |= this.flags[(int)b];
                 }
                 b += 1;
             }
             PlayerInputPacket playerInputPacket2 = this.clientsidePackets[this.clientsidePackets.Count - 1];
             playerInputPacket2.keys = num;
             if (playerInputPacket2 is DrivingPlayerInputPacket)
             {
                 DrivingPlayerInputPacket drivingPlayerInputPacket = playerInputPacket2 as DrivingPlayerInputPacket;
                 drivingPlayerInputPacket.position     = base.transform.parent.parent.parent.position;
                 drivingPlayerInputPacket.angle_x      = MeasurementTool.angleToByte2(base.transform.parent.parent.parent.rotation.eulerAngles.x);
                 drivingPlayerInputPacket.angle_y      = MeasurementTool.angleToByte2(base.transform.parent.parent.parent.rotation.eulerAngles.y);
                 drivingPlayerInputPacket.angle_z      = MeasurementTool.angleToByte2(base.transform.parent.parent.parent.rotation.eulerAngles.z);
                 drivingPlayerInputPacket.speed        = (byte)(Mathf.Clamp(base.player.movement.getVehicle().speed, -100f, 100f) + 128f);
                 drivingPlayerInputPacket.physicsSpeed = (byte)(Mathf.Clamp(base.player.movement.getVehicle().physicsSpeed, -100f, 100f) + 128f);
                 drivingPlayerInputPacket.turn         = (byte)(base.player.movement.getVehicle().turn + 1);
             }
             else
             {
                 WalkingPlayerInputPacket walkingPlayerInputPacket = playerInputPacket2 as WalkingPlayerInputPacket;
                 walkingPlayerInputPacket.analog   = this.analog;
                 walkingPlayerInputPacket.position = base.transform.localPosition;
                 walkingPlayerInputPacket.yaw      = this.yaw;
                 walkingPlayerInputPacket.pitch    = this.pitch;
             }
             base.channel.openWrite();
             while (this.clientsidePackets.Count >= 25)
             {
                 this.clientsidePackets.RemoveAt(0);
             }
             base.channel.write((byte)this.clientsidePackets.Count);
             foreach (PlayerInputPacket playerInputPacket3 in this.clientsidePackets)
             {
                 if (playerInputPacket3 is DrivingPlayerInputPacket)
                 {
                     base.channel.write(1);
                 }
                 else
                 {
                     base.channel.write(0);
                 }
                 playerInputPacket3.write(base.channel);
             }
             base.channel.closeWrite("askInput", ESteamCall.SERVER, ESteamPacket.UPDATE_UNRELIABLE_CHUNK_INSTANT);
         }
         this.count += 1u;
     }
     else if (Provider.isServer)
     {
         if (this.serversidePackets.Count > 0)
         {
             PlayerInputPacket playerInputPacket4 = this.serversidePackets.Peek();
             if (playerInputPacket4 is WalkingPlayerInputPacket || this.count % PlayerInput.SAMPLES == 0u)
             {
                 if (this.simulation > (uint)((Time.realtimeSinceStartup + 5f - this.tick) / PlayerInput.RATE))
                 {
                     return;
                 }
                 playerInputPacket4 = this.serversidePackets.Dequeue();
                 if (playerInputPacket4 == null)
                 {
                     return;
                 }
                 this.hasDoneOcclusionCheck = false;
                 this.inputs = playerInputPacket4.serversideInputs;
                 byte b2 = 0;
                 while ((int)b2 < this.keys.Length)
                 {
                     this.keys[(int)b2] = ((playerInputPacket4.keys & this.flags[(int)b2]) == this.flags[(int)b2]);
                     b2 += 1;
                 }
                 if (playerInputPacket4 is DrivingPlayerInputPacket)
                 {
                     DrivingPlayerInputPacket drivingPlayerInputPacket2 = playerInputPacket4 as DrivingPlayerInputPacket;
                     if (!base.player.life.isDead)
                     {
                         base.player.life.simulate(this.simulation);
                         base.player.look.simulate(0f, 0f, PlayerInput.RATE);
                         base.player.stance.simulate(this.simulation, false, false, false);
                         base.player.movement.simulate(this.simulation, drivingPlayerInputPacket2.recov, this.keys[0], drivingPlayerInputPacket2.position, MeasurementTool.byteToAngle2(drivingPlayerInputPacket2.angle_x), MeasurementTool.byteToAngle2(drivingPlayerInputPacket2.angle_y), MeasurementTool.byteToAngle2(drivingPlayerInputPacket2.angle_z), (float)(drivingPlayerInputPacket2.speed - 128), (float)(drivingPlayerInputPacket2.physicsSpeed - 128), (int)(drivingPlayerInputPacket2.turn - 1), PlayerInput.RATE);
                         base.player.equipment.simulate(this.simulation, this.keys[1], this.keys[2], this.keys[5]);
                         base.player.animator.simulate(this.simulation, false, false);
                     }
                 }
                 else
                 {
                     WalkingPlayerInputPacket walkingPlayerInputPacket2 = playerInputPacket4 as WalkingPlayerInputPacket;
                     this.analog = walkingPlayerInputPacket2.analog;
                     if (!base.player.life.isDead)
                     {
                         base.player.life.simulate(this.simulation);
                         base.player.look.simulate(walkingPlayerInputPacket2.yaw, walkingPlayerInputPacket2.pitch, PlayerInput.RATE);
                         base.player.stance.simulate(this.simulation, this.keys[3], this.keys[4], this.keys[5]);
                         base.player.movement.simulate(this.simulation, walkingPlayerInputPacket2.recov, (this.analog >> 4 & 15) - 1, (int)((this.analog & 15) - 1), 0f, 0f, this.keys[0], walkingPlayerInputPacket2.position, PlayerInput.RATE);
                         base.player.equipment.simulate(this.simulation, this.keys[1], this.keys[2], this.keys[5]);
                         base.player.animator.simulate(this.simulation, this.keys[6], this.keys[7]);
                     }
                 }
                 this.buffer      += PlayerInput.SAMPLES;
                 this._simulation += 1u;
                 while (this.consumed < this.buffer)
                 {
                     this.consumed += 1u;
                     if (!base.player.life.isDead)
                     {
                         base.player.equipment.tock(this.clock);
                     }
                     this._clock += 1u;
                 }
             }
             this.count += 1u;
         }
         else
         {
             base.player.movement.simulate();
             if (this.hasInputed && Time.realtimeSinceStartup - this.lastInputed > 10f)
             {
                 Provider.dismiss(base.channel.owner.playerID.steamID);
                 this.isDismissed = true;
             }
         }
     }
 }