コード例 #1
0
        private void Telemetry_Data(ScsTelemetry data, bool updated)
        {
            if (!updated)
            {
                return;
            }
            try {
                if (InvokeRequired)
                {
                    Invoke(new TelemetryData(Telemetry_Data), data, updated);
                    return;
                }

                l_updateRate.Text = Telemetry.UpdateInterval + "ms";

                lbGeneral.Text = "General info:\n " +
                                 "\t SDK Running:\n" +
                                 $"\t\t\t{data.SdkActive}\n" +
                                 "\tSDK Version:\n" +
                                 $"\t\t\t{data.DllVersion}\n" +
                                 "\tGame:\n " +
                                 $"\t\t\t{data.Game}\n" +
                                 "\tGame Version:\n" +
                                 $"\t\t\t{data.GameVersion}\n" +
                                 "\tTelemetry Version:\n" +
                                 $"\t\t\t{data.TelemetryVersion}\n" +
                                 "\tTimeStamp:\n" +
                                 $"\t\t\t{data.Timestamp}\n" +
                                 "\tSimulation TimeStamp:\n" +
                                 $"\t\t\t{data.SimulationTimestamp}\n" +
                                 "\tRender TimeStamp:\n" +
                                 $"\t\t\t{data.RenderTimestamp}\n" +
                                 "\tGame Paused:\n" +
                                 $"\t\t\t{data.Paused}\n" +
                                 "\tOn Job:\n" +
                                 $"\t\t\t{data.SpecialEventsValues.OnJob}\n" +
                                 "\tJob Finished:\n" +
                                 $"\t\t\t{data.SpecialEventsValues.JobFinished}\n" +
                                 "\tJob Delivered:\n" +
                                 $"\t\t\t{data.SpecialEventsValues.JobDelivered}\n" +
                                 "\tJob Cancelled:\n" +
                                 $"\t\t\t{data.SpecialEventsValues.JobCancelled}\n" +
                                 "\tFined:\n" +
                                 $"\t\t\t{data.SpecialEventsValues.Fined}\n" +
                                 "\ttollgate:\n" +
                                 $"\t\t\t{data.SpecialEventsValues.Tollgate}\n" +
                                 "\tferry:\n" +
                                 $"\t\t\t{data.SpecialEventsValues.Ferry}\n" +
                                 "\ttrain:\n" +
                                 $"\t\t\t{data.SpecialEventsValues.Train}\n" +
                                 "\tRefuel Payed:\n" +
                                 $"\t\t\t{data.SpecialEventsValues.RefuelPaid}\n";

                common.Text  = JsonConvert.SerializeObject(data.CommonValues, Formatting.Indented);
                truck.Text   = JsonConvert.SerializeObject(data.TruckValues, Formatting.Indented);
                trailer.Text =
                    JsonConvert.SerializeObject(data.TrailerValues,
                                                Formatting
                                                .Indented);     // TODO better trailer display
                job.Text           = JsonConvert.SerializeObject(data.JobValues, Formatting.Indented);
                control.Text       = JsonConvert.SerializeObject(data.ControlValues, Formatting.Indented);
                navigation.Text    = JsonConvert.SerializeObject(data.NavigationValues, Formatting.Indented);
                substances.Text    = JsonConvert.SerializeObject(data.Substances, Formatting.Indented);
                gameplayevent.Text = JsonConvert.SerializeObject(data.GamePlay, Formatting.Indented);
                rtb_fuel.Text      = data.TruckValues.CurrentValues.DashboardValues.FuelValue.Amount + " " + data.SpecialEventsValues.Refuel;
                fuel = data.GamePlay.RefuelEvent.Amount;
            } catch (Exception ex) {
                // ignored atm i found no proper way to shut the telemetry down and down call this anymore when this or another thing is already disposed
                Console.WriteLine("Telemetry was closed: " + ex);
            }
        }
コード例 #2
0
        /// <summary>
        ///     Convert the Shared Memory Byte data structure in a C# object
        /// </summary>
        /// <param name="structureDataBytes">
        ///     byte array from the shared memory
        /// </param>
        /// <returns>
        ///     C# object with game data of the shared memory
        /// </returns>
        public ScsTelemetry Convert(byte[] structureDataBytes)
        {
            offsetArea = 0;
            SetOffset();


            data = structureDataBytes;
            var retData = new ScsTelemetry();

            #region FIRST ZONE

            retData.SdkActive = GetBool();
            GetBoolArray(3);
            retData.Paused = GetBool();
            GetBoolArray(3);
            retData.Timestamp           = GetULong();
            retData.SimulationTimestamp = GetULong();
            retData.RenderTimestamp     = GetULong();



            NextOffsetArea();

            #endregion

            #region SECOND ZONE

            retData.DllVersion        = GetUint();
            retData.GameVersion.Major = GetUint();
            retData.GameVersion.Minor = GetUint();
            retData.Game = GetUint().ToEnum <ScsGame>();
            retData.TelemetryVersion.Major = GetUint();
            retData.TelemetryVersion.Minor = GetUint();

            retData.CommonValues.GameTime = GetUint();
            retData.TruckValues.ConstantsValues.MotorValues.ForwardGearCount  = GetUint();
            retData.TruckValues.ConstantsValues.MotorValues.ReverseGearCount  = GetUint();
            retData.TruckValues.ConstantsValues.MotorValues.RetarderStepCount = GetUint();
            retData.TruckValues.ConstantsValues.WheelsValues.Count            = GetUint();
            retData.TruckValues.ConstantsValues.MotorValues.SelectorCount     = GetUint();
            retData.SetDeliveryTime(GetUint());
            retData.MaxTrailerCount = GetUint();
            retData.JobValues.CargoValues.UnitCount = GetUint();
            retData.JobValues.PlannedDistanceKm     = GetUint();


            retData.TruckValues.CurrentValues.MotorValues.GearValues.HShifterSlot   = GetUint();
            retData.TruckValues.CurrentValues.MotorValues.BrakeValues.RetarderLevel = GetUint();
            retData.TruckValues.CurrentValues.LightsValues.AuxFront  = GetUint().ToEnum <AuxLevel>();
            retData.TruckValues.CurrentValues.LightsValues.AuxRoof   = GetUint().ToEnum <AuxLevel>();
            retData.TruckValues.CurrentValues.WheelsValues.Substance = GetUintArray(_wheelSize);

            retData.TruckValues.ConstantsValues.MotorValues.SlotHandlePosition = GetUintArray(32);
            retData.TruckValues.ConstantsValues.MotorValues.SlotSelectors      = GetUintArray(32);

            retData.GamePlay.JobDelivered.DeliveryTime = GetUint();
            var jobStartingTime = new ScsTelemetry.Time(GetUint());
            retData.GamePlay.JobCancelled.Started = jobStartingTime;
            retData.GamePlay.JobDelivered.Started = jobStartingTime;
            var jobFinishingTime = new ScsTelemetry.Time(GetUint());
            retData.GamePlay.JobCancelled.Finished = jobFinishingTime;
            retData.GamePlay.JobDelivered.Finished = jobFinishingTime;

            NextOffsetArea();

            #endregion

            #region THIRD ZONE

            retData.CommonValues.NextRestStop = GetInt();

            retData.TruckValues.CurrentValues.MotorValues.GearValues.Selected = GetInt();
            retData.TruckValues.CurrentValues.DashboardValues.GearDashboards  = GetInt();
            retData.TruckValues.ConstantsValues.MotorValues.SlotGear          = GetIntArray(32);

            retData.GamePlay.JobDelivered.EarnedXp = GetInt();

            NextOffsetArea();

            #endregion

            #region 4TH ZONE

            retData.CommonValues.Scale = GetFloat();

            retData.TruckValues.ConstantsValues.CapacityValues.Fuel                      = GetFloat();
            retData.TruckValues.ConstantsValues.WarningFactorValues.Fuel                 = GetFloat();
            retData.TruckValues.ConstantsValues.CapacityValues.AdBlue                    = GetFloat();
            retData.TruckValues.ConstantsValues.WarningFactorValues.AdBlue               = GetFloat();
            retData.TruckValues.ConstantsValues.WarningFactorValues.AirPressure          = GetFloat();
            retData.TruckValues.ConstantsValues.WarningFactorValues.AirPressureEmergency = GetFloat();
            retData.TruckValues.ConstantsValues.WarningFactorValues.OilPressure          = GetFloat();
            retData.TruckValues.ConstantsValues.WarningFactorValues.WaterTemperature     = GetFloat();
            retData.TruckValues.ConstantsValues.WarningFactorValues.BatteryVoltage       = GetFloat();
            retData.TruckValues.ConstantsValues.MotorValues.EngineRpmMax                 = GetFloat();
            retData.TruckValues.ConstantsValues.MotorValues.DifferentialRation           = GetFloat();
            retData.JobValues.CargoValues.Mass = GetFloat();
            retData.TruckValues.ConstantsValues.WheelsValues.Radius           = GetFloatArray(_wheelSize);
            retData.TruckValues.ConstantsValues.MotorValues.GearRatiosForward = GetFloatArray(24);
            retData.TruckValues.ConstantsValues.MotorValues.GearRatiosReverse = GetFloatArray(8);
            retData.JobValues.CargoValues.UnitMass = GetFloat();

            retData.TruckValues.CurrentValues.DashboardValues.Speed.Value = GetFloat();
            retData.TruckValues.CurrentValues.DashboardValues.Rpm         = GetFloat();
            retData.ControlValues.InputValues.Steering = GetFloat();
            retData.ControlValues.InputValues.Throttle = GetFloat();
            retData.ControlValues.InputValues.Brake    = GetFloat();
            retData.ControlValues.InputValues.Clutch   = GetFloat();
            retData.ControlValues.GameValues.Steering  = GetFloat();
            retData.ControlValues.GameValues.Throttle  = GetFloat();
            retData.ControlValues.GameValues.Brake     = GetFloat();
            retData.ControlValues.GameValues.Clutch    = GetFloat();
            retData.TruckValues.CurrentValues.DashboardValues.CruiseControlSpeed.Value     = GetFloat();
            retData.TruckValues.CurrentValues.MotorValues.BrakeValues.AirPressure          = GetFloat();
            retData.TruckValues.CurrentValues.MotorValues.BrakeValues.Temperature          = GetFloat();
            retData.TruckValues.CurrentValues.DashboardValues.FuelValue.Amount             = GetFloat();
            retData.TruckValues.CurrentValues.DashboardValues.FuelValue.AverageConsumption = GetFloat();
            retData.TruckValues.CurrentValues.DashboardValues.FuelValue.Range  = GetFloat();
            retData.TruckValues.CurrentValues.DashboardValues.AdBlue           = GetFloat();
            retData.TruckValues.CurrentValues.DashboardValues.OilPressure      = GetFloat();
            retData.TruckValues.CurrentValues.DashboardValues.OilTemperature   = GetFloat();
            retData.TruckValues.CurrentValues.DashboardValues.WaterTemperature = GetFloat();
            retData.TruckValues.CurrentValues.DashboardValues.BatteryVoltage   = GetFloat();
            retData.TruckValues.CurrentValues.LightsValues.DashboardBacklight  = GetFloat();
            retData.TruckValues.CurrentValues.DamageValues.Engine       = GetFloat();
            retData.TruckValues.CurrentValues.DamageValues.Transmission = GetFloat();
            retData.TruckValues.CurrentValues.DamageValues.Cabin        = GetFloat();
            retData.TruckValues.CurrentValues.DamageValues.Chassis      = GetFloat();
            retData.TruckValues.CurrentValues.DamageValues.WheelsAvg    = GetFloat();


            retData.TruckValues.CurrentValues.DashboardValues.Odometer = GetFloat();
            retData.NavigationValues.NavigationDistance = GetFloat();
            retData.NavigationValues.NavigationTime     = GetFloat();
            retData.NavigationValues.SpeedLimit         = GetFloat();
            retData.TruckValues.CurrentValues.WheelsValues.SuspDeflection = GetFloatArray(_wheelSize);
            retData.TruckValues.CurrentValues.WheelsValues.Velocity       = GetFloatArray(_wheelSize);
            retData.TruckValues.CurrentValues.WheelsValues.Steering       = GetFloatArray(_wheelSize);
            retData.TruckValues.CurrentValues.WheelsValues.Rotation       = GetFloatArray(_wheelSize);
            retData.TruckValues.CurrentValues.WheelsValues.Lift           = GetFloatArray(_wheelSize);
            retData.TruckValues.CurrentValues.WheelsValues.LiftOffset     = GetFloatArray(_wheelSize);

            retData.GamePlay.JobDelivered.CargoDamage = GetFloat();
            retData.GamePlay.JobDelivered.DistanceKm  = GetFloat();

            retData.GamePlay.RefuelEvent.Amount = GetFloat();

            retData.JobValues.CargoValues.CargoDamage = GetFloat();

            NextOffsetArea();

            #endregion

            #region 5Th ZONE

            retData.TruckValues.ConstantsValues.WheelsValues.Steerable = GetBoolArray(_wheelSize);
            retData.TruckValues.ConstantsValues.WheelsValues.Simulated = GetBoolArray(_wheelSize);
            retData.TruckValues.ConstantsValues.WheelsValues.Powered   = GetBoolArray(_wheelSize);
            retData.TruckValues.ConstantsValues.WheelsValues.Liftable  = GetBoolArray(_wheelSize);

            retData.JobValues.CargoLoaded = GetBool();
            retData.JobValues.SpecialJob  = GetBool();

            retData.TruckValues.CurrentValues.MotorValues.BrakeValues.ParkingBrake               = GetBool();
            retData.TruckValues.CurrentValues.MotorValues.BrakeValues.MotorBrake                 = GetBool();
            retData.TruckValues.CurrentValues.DashboardValues.WarningValues.AirPressure          = GetBool();
            retData.TruckValues.CurrentValues.DashboardValues.WarningValues.AirPressureEmergency = GetBool();

            retData.TruckValues.CurrentValues.DashboardValues.WarningValues.FuelW            = GetBool();
            retData.TruckValues.CurrentValues.DashboardValues.WarningValues.AdBlue           = GetBool();
            retData.TruckValues.CurrentValues.DashboardValues.WarningValues.OilPressure      = GetBool();
            retData.TruckValues.CurrentValues.DashboardValues.WarningValues.WaterTemperature = GetBool();
            retData.TruckValues.CurrentValues.DashboardValues.WarningValues.BatteryVoltage   = GetBool();
            retData.TruckValues.CurrentValues.ElectricEnabled                         = GetBool();
            retData.TruckValues.CurrentValues.EngineEnabled                           = GetBool();
            retData.TruckValues.CurrentValues.DashboardValues.Wipers                  = GetBool();
            retData.TruckValues.CurrentValues.LightsValues.BlinkerLeftActive          = GetBool();
            retData.TruckValues.CurrentValues.LightsValues.BlinkerRightActive         = GetBool();
            retData.TruckValues.CurrentValues.LightsValues.BlinkerLeftOn              = GetBool();
            retData.TruckValues.CurrentValues.LightsValues.BlinkerRightOn             = GetBool();
            retData.TruckValues.CurrentValues.LightsValues.Parking                    = GetBool();
            retData.TruckValues.CurrentValues.LightsValues.BeamLow                    = GetBool();
            retData.TruckValues.CurrentValues.LightsValues.BeamHigh                   = GetBool();
            retData.TruckValues.CurrentValues.LightsValues.Beacon                     = GetBool();
            retData.TruckValues.CurrentValues.LightsValues.Brake                      = GetBool();
            retData.TruckValues.CurrentValues.LightsValues.Reverse                    = GetBool();
            retData.TruckValues.CurrentValues.DashboardValues.CruiseControl           = GetBool();
            retData.TruckValues.CurrentValues.WheelsValues.OnGround                   = GetBoolArray(_wheelSize);
            retData.TruckValues.CurrentValues.MotorValues.GearValues.HShifterSelector = GetBoolArray(2);

            retData.GamePlay.JobDelivered.AutoParked = GetBool();
            retData.GamePlay.JobDelivered.AutoLoaded = GetBool();

            NextOffsetArea();

            #endregion

            #region 6TH ZONE

            retData.TruckValues.Positioning.Cabin = GetFVector();
            retData.TruckValues.Positioning.Head  = GetFVector();
            retData.TruckValues.Positioning.Hook  = GetFVector();
            var tempPos = new ScsTelemetry.FVector[_wheelSize];
            for (var j = 0; j < _wheelSize; j++)
            {
                tempPos[j] = new ScsTelemetry.FVector {
                    X = GetFloat()
                };
            }

            for (var j = 0; j < _wheelSize; j++)
            {
                tempPos[j].Y = GetFloat();
            }

            for (var j = 0; j < _wheelSize; j++)
            {
                tempPos[j].Z = GetFloat();
            }

            retData.TruckValues.ConstantsValues.WheelsValues.PositionValues = tempPos;


            retData.TruckValues.CurrentValues.AccelerationValues.LinearVelocity           = GetFVector();
            retData.TruckValues.CurrentValues.AccelerationValues.AngularVelocity          = GetFVector();
            retData.TruckValues.CurrentValues.AccelerationValues.LinearAcceleration       = GetFVector();
            retData.TruckValues.CurrentValues.AccelerationValues.AngularAcceleration      = GetFVector();
            retData.TruckValues.CurrentValues.AccelerationValues.CabinAngularVelocity     = GetFVector();
            retData.TruckValues.CurrentValues.AccelerationValues.CabinAngularAcceleration = GetFVector();

            NextOffsetArea();

            #endregion

            #region 7TH ZONE

            retData.TruckValues.Positioning.CabinOffset = GetFPlacement();
            retData.TruckValues.Positioning.HeadOffset  = GetFPlacement();


            NextOffsetArea();

            #endregion

            #region 8TH ZONE

            retData.SetTruckPosition(GetDPlacement());


            NextOffsetArea();

            #endregion

            #region 9TH ZONE

            retData.TruckValues.ConstantsValues.BrandId = GetString();
            retData.TruckValues.ConstantsValues.Brand   = GetString();
            retData.TruckValues.ConstantsValues.Id      = GetString();
            retData.TruckValues.ConstantsValues.Name    = GetString();
            retData.JobValues.CargoValues.Id            = GetString();
            retData.JobValues.CargoValues.Name          = GetString();
            retData.JobValues.CityDestinationId         = GetString();
            retData.JobValues.CityDestination           = GetString();
            retData.JobValues.CompanyDestinationId      = GetString();
            retData.JobValues.CompanyDestination        = GetString();
            retData.JobValues.CitySourceId    = GetString();
            retData.JobValues.CitySource      = GetString();
            retData.JobValues.CompanySourceId = GetString();
            retData.JobValues.CompanySource   = GetString();
            var tempShift = GetString(16);
            if (tempShift?.Length > 0)
            {
                retData.TruckValues.ConstantsValues.MotorValues.ShifterTypeValue = tempShift.ToEnum <ShifterType>();
            }

            retData.TruckValues.ConstantsValues.LicensePlate          = GetString();
            retData.TruckValues.ConstantsValues.LicensePlateCountryId = GetString();
            retData.TruckValues.ConstantsValues.LicensePlateCountry   = GetString();

            var tempJobMarket = GetString(32);
            if (tempJobMarket?.Length > 0)
            {
                retData.JobValues.Market = tempJobMarket.ToEnum <JobMarket>();
            }

            var tempfineOffence = GetString(32);
            if (tempfineOffence?.Length > 0)
            {
                retData.GamePlay.FinedEvent.Offence = tempfineOffence.ToEnum <Offence>();
            }

            retData.GamePlay.FerryEvent.SourceName = GetString();
            retData.GamePlay.FerryEvent.TargetName = GetString();
            retData.GamePlay.FerryEvent.SourceId   = GetString();
            retData.GamePlay.FerryEvent.TargetId   = GetString();
            retData.GamePlay.TrainEvent.SourceName = GetString();
            retData.GamePlay.TrainEvent.TargetName = GetString();
            retData.GamePlay.TrainEvent.SourceId   = GetString();
            retData.GamePlay.TrainEvent.TargetId   = GetString();


            NextOffsetArea();

            #endregion

            #region 10TH ZONE

            retData.JobValues.Income = GetULong();

            NextOffsetArea();

            #endregion

            #region 11TH ZONE

            retData.GamePlay.JobCancelled.Penalty    = GetLong();
            retData.GamePlay.JobDelivered.Revenue    = GetLong();
            retData.GamePlay.FinedEvent.Amount       = GetLong();
            retData.GamePlay.TollgateEvent.PayAmount = GetLong();
            retData.GamePlay.FerryEvent.PayAmount    = GetLong();
            retData.GamePlay.TrainEvent.PayAmount    = GetLong();

            NextOffsetArea();

            #endregion

            #region 12TH ZONE

            retData.SpecialEventsValues.OnJob       = GetBool();
            retData.SpecialEventsValues.JobFinished = GetBool();

            retData.SpecialEventsValues.JobCancelled = GetBool();
            retData.SpecialEventsValues.JobDelivered = GetBool();
            retData.SpecialEventsValues.Fined        = GetBool();
            retData.SpecialEventsValues.Tollgate     = GetBool();
            retData.SpecialEventsValues.Ferry        = GetBool();
            retData.SpecialEventsValues.Train        = GetBool();

            retData.SpecialEventsValues.Refuel     = GetBool();
            retData.SpecialEventsValues.RefuelPaid = GetBool();

            NextOffsetArea();

            #endregion

            #region 13TH ZONE

            for (var i = 0; i < _substances; i++)
            {
                var tempSubstance = GetString();
                if (tempSubstance.Length != 0)
                {
                    retData.Substances.Add(new ScsTelemetry.Substance {
                        Index = i, Value = tempSubstance
                    });
                }
            }

            NextOffsetArea();

            #endregion

            #region 14TH ZONE

            retData.TrailerValues = GetTrailers();

            #endregion


            return(retData);
        }