public override void StreamOut()
 {
     if (blip != null && blip.Exists())
     {
         blip.Delete();
     }
     if (nickDraw != null)
     {
         nickDraw.destroy();
     }
     if (healthDraw != null)
     {
         healthDraw.destroy();
     }
     if (healthDraw2 != null)
     {
         healthDraw2.destroy();
     }
     if (carHealthDraw != null)
     {
         carHealthDraw.destroy();
     }
     if (carHealthDraw2 != null)
     {
         carHealthDraw2.destroy();
     }
     if (chatDraw != null)
     {
         chatDraw.destroy();
     }
     if (iconDraw != null)
     {
         iconDraw.destroy();
     }
     nickDraw = null;
     if (gameReference != null && gameReference.Exists())
     {
         gameReference.Delete();
     }
     gameReference  = null;
     hasNetworkName = false;
 }
Beispiel #2
0
        private void eventOnTick(object sender, EventArgs e)
        {
            try
            {
                while (actionQueue.Count > 0)
                {
                    actionQueue.Dequeue().Invoke();
                }
            }
            catch (Exception ex)
            {
                log("Failed executing action queue with message " + ex.Message);
            }
            if (currentState == ClientState.Connected)
            {
                if (currentData == null)
                {
                    currentData = UpdateDataStruct.Zero;
                }
                if (!BroadcastingPaused && Player.Character.Exists())
                {
                    try
                    {
                        UpdateDataStruct data = new UpdateDataStruct();
                        if (Player.Character.isInVehicle() && Player.Character.CurrentVehicle.GetPedOnSeat(VehicleSeat.Driver) == Player.Character)
                        {
                            if (vehicleController.dict.Count(a => a.Value.IsStreamedIn() && a.Value.gameReference == Player.Character.CurrentVehicle) > 0)
                            {
                                try
                                {
                                    Vector3 pos = Player.Character.CurrentVehicle.Position;
                                    data.pos_x = pos.X;
                                    data.pos_y = pos.Y;
                                    data.pos_z = pos.Z;

                                    Vector3 currentSpeed = Player.Character.CurrentVehicle.Velocity;
                                    float   speed        = Player.Character.CurrentVehicle.Speed;
                                    if (currentData.pos_x != 0)
                                    {
                                        float deltax = (pos.X - currentData.pos_x);
                                        float deltay = (pos.Y - currentData.pos_y);
                                        float deltaz = (pos.Z - currentData.pos_z);
                                        data.vel_x = (deltax < 0 ? currentSpeed.X * -1 : currentSpeed.X);
                                        data.vel_y = (deltay < 0 ? currentSpeed.Y * -1 : currentSpeed.Y);
                                        data.vel_z = (deltaz < 0 ? currentSpeed.Z * -1 : currentSpeed.Z);
                                    }
                                    else
                                    {
                                        data.vel_x = currentSpeed.X;
                                        data.vel_y = currentSpeed.Y;
                                        data.vel_z = currentSpeed.Z;
                                    }

                                    Quaternion quat = Player.Character.CurrentVehicle.RotationQuaternion;
                                    data.rot_x = quat.X;
                                    data.rot_y = quat.Y;
                                    data.rot_z = quat.Z;
                                    data.rot_a = quat.W;

                                    data.vehicle_model  = Player.Character.CurrentVehicle.Model.Hash;
                                    data.vehicle_health = Player.Character.CurrentVehicle.Health;
                                    var cveh = vehicleController.dict.First(a => a.Value.IsStreamedIn() && a.Value.gameReference == Player.Character.CurrentVehicle);

                                    data.vehicle_id = cveh.Key;
                                    data.ped_health = Player.Character.Health;
                                    data.heading    = Player.Character.CurrentVehicle.Heading;

                                    cveh.Value.position    = pos;
                                    cveh.Value.orientation = quat;
                                }
                                catch (Exception eq)
                                {
                                    Game.Log("Failed pedInvehicle position measure processing: " + eq.Message);
                                }
                            }
                            data.state = 0;
                        }
                        else
                        {
                            try
                            {
                                Vector3 pos = Player.Character.Position;
                                data.pos_x = pos.X;
                                data.pos_y = pos.Y;
                                data.pos_z = pos.Z;

                                Vector3 vel = Player.Character.Velocity;
                                data.vel_x = vel.X;
                                data.vel_y = vel.Y;
                                data.vel_z = vel.Z;

                                data.rot_x = Player.Character.Direction.X;
                                data.rot_y = Player.Character.Direction.Y;
                                data.rot_z = Player.Character.Direction.Z;
                                data.rot_a = 0;

                                data.vehicle_model  = 0;
                                data.vehicle_health = 0;
                                // for passengers:)client.pedController.dict.First(a => a.Value.IsStreamedIn() && a.Value.gameReference == selectedPed)
                                data.vehicle_id = Player.Character.isInVehicle() ? vehicleController.dict.First(a => a.Value.IsStreamedIn() && a.Value.gameReference == Player.Character.CurrentVehicle).Key : 0;
                                data.ped_health = Player.Character.Health;
                                data.heading    = Player.Character.Heading;
                                data.weapon     = (int)Player.Character.Weapons.CurrentType;
                                data.state      = 0;
                                data.state     |= Player.Character.isShooting ? PlayerState.IsShooting : 0;
                                data.state     |= Game.isGameKeyPressed(GameKey.Aim) ? PlayerState.IsAiming : 0;
                                data.state     |= Game.isGameKeyPressed(GameKey.Crouch) ? PlayerState.IsCrouching : 0;
                                data.state     |= Game.isGameKeyPressed(GameKey.Jump) ? PlayerState.IsJumping : 0;
                                data.state     |= Game.isGameKeyPressed(GameKey.Attack) ? PlayerState.IsShooting : 0;

                                data.state |= Player.Character.isInVehicle() && Player.Character.CurrentVehicle.GetPedOnSeat(VehicleSeat.RightFront) == Player.Character ? PlayerState.IsPassenger1 : 0;
                                data.state |= Player.Character.isInVehicle() && Player.Character.CurrentVehicle.GetPedOnSeat(VehicleSeat.LeftRear) == Player.Character ? PlayerState.IsPassenger2 : 0;
                                data.state |= Player.Character.isInVehicle() && Player.Character.CurrentVehicle.GetPedOnSeat(VehicleSeat.RightRear) == Player.Character ? PlayerState.IsPassenger3 : 0;
                            }
                            catch (Exception eq)
                            {
                                Game.Log("Failed ped position measure processing: " + eq.Message);
                            }
                        }
                        data.vstate  = 0;
                        data.vstate |= Game.isGameKeyPressed(GameKey.MoveForward) ? VehicleState.IsAccelerating : 0;
                        data.vstate |= Game.isGameKeyPressed(GameKey.MoveBackward) ? VehicleState.IsBraking : 0;
                        data.vstate |= Game.isGameKeyPressed(GameKey.MoveLeft) ? VehicleState.IsSterringLeft : 0;
                        data.vstate |= Game.isGameKeyPressed(GameKey.MoveRight) ? VehicleState.IsSterringRight : 0;
                        data.vstate |= Game.isGameKeyPressed(GameKey.Sprint) ? VehicleState.IsSprinting : 0;
                        data.vstate |= Player.Character.isGettingIntoAVehicle ? VehicleState.IsEnteringVehicle : 0;
                        data.vstate |= (data.state & PlayerState.IsPassenger1) != 0 || (data.state & PlayerState.IsPassenger2) != 0 || (data.state & PlayerState.IsPassenger3) != 0
                            ? VehicleState.IsAsPassenger : 0;

                        data.camdir_x = Game.CurrentCamera.Direction.X;
                        data.camdir_y = Game.CurrentCamera.Direction.Y;
                        data.camdir_z = Game.CurrentCamera.Direction.Z;

                        /*
                         * var bpf = new BinaryPacketFormatter(Commands.UpdateData);
                         * bpf.Add(data);
                         * serverConnection.write(bpf.getBytes());*/
                        if (udpTunnel != null)
                        {
                            udpTunnel.broadcastData(data);
                        }

                        try
                        {
                            if (!isCurrentlyDead && (Player.Character.Health == 0 || Player.Character.isDead || !Player.Character.isAlive))
                            {
                                //Game.FadeScreenOut(4000);
                                //Player.Character.Die();
                                //AlternateHook.call(AlternateHookRequest.OtherCommands.FAKE_DEATHARREST);
                                //AlternateHook.call(AlternateHookRequest.OtherCommands.CREATE_PLAYER, 0.0f, 0.0f, 0.0f, null);
                                isCurrentlyDead = true;
                            }

                            if (isCurrentlyDead && !Player.Character.isDead && Player.Character.isAlive && Player.Character.Health > 0)
                            {
                                Game.FadeScreenIn(2000);
                                isCurrentlyDead = false;

                                var bpf2 = new BinaryPacketFormatter(Commands.InternalClient_requestSpawn);
                                serverConnection.write(bpf2.getBytes());
                            }
                        }
                        catch (Exception eq)
                        {
                            Game.Log("Failed death processing: " + eq.Message);
                        }

                        currentData = data;
                    }
                    catch (Exception ex)
                    {
                        Game.Log("Failed sending new Player data with message " + ex.Message);
                    }
                }
                try
                {
                    serverConnection.flush();
                }
                catch (Exception ex)
                {
                    Game.Log("Failed sending packets " + ex.Message);
                }
                try
                {
                    updateAllPlayers();
                    pedStreamer.Update();
                    vehicleStreamer.Update();
                    pedStreamer.UpdateNormalTick();
                    vehicleStreamer.UpdateNormalTick();
                }
                catch (Exception ex)
                {
                    log("Failed updating streamers and players with message " + ex.Message);
                }
            }

            if (currentState == ClientState.Connecting)
            {
                currentState = ClientState.Connected;

                darkscreen.destroy();
                Game.FadeScreenIn(3000);
                GTA.Native.Function.Call("DO_SCREEN_FADE_IN_UNHACKED", 2000);
                GTA.Native.Function.Call("FORCE_LOADING_SCREEN", false);

                var bpf = new BinaryPacketFormatter(Commands.Connect);
                bpf.Add(nick);
                serverConnection.write(bpf.getBytes());

                Player.Model          = new Model("F_Y_HOOKER_01");
                Player.NeverGetsTired = true;

                //ClientTextureDraw draw = new ClientTextureDraw(new System.Drawing.RectangleF(20, 20, 400, 400), @"C:\Users\Aerofly\Desktop\4duzy.png");

                //chatController.writeChat("Connected");
            }
        }