Esempio n. 1
0
        public void Write <T>(TelemetryChannel channel, T i)
        {
            if (ActiveProcess == null)
            {
                return;
            }

            if (!openedTduAsWriter)
            {
                _tdu2Reader.Close();
                _tdu2Reader             = new MemoryWriter();
                _tdu2Reader.ReadProcess = ActiveProcess;
                _tdu2Reader.Open();

                openedTduAsWriter = true;
            }

            var channelAddress = GetWriteAddress(channel);

            var writer = _tdu2Reader as MemoryWriter;

            if (i is float)
            {
                writer.WriteFloat(channelAddress, float.Parse(i.ToString()));
            }
        }
Esempio n. 2
0
        public Telemetry(IPluginTelemetryProvider provider, Process simulatorProcess)
        {
            Provider = provider;

            // Initialize memory objects
            var mem = new MemoryReader();
            mem.Open(simulatorProcess);

            Memory = new MemoryProvider(mem);

            // Initialize telemetry provider; this class gives us the address layout to read.
            Memory.Scanner.Enable();
            Provider.Initialize(Memory);
            Memory.Scanner.Disable();

            // Start outside-world telemetry objects
            Session = new TelemetrySession();
            Simulator = new TelemetryGame();
            Acquisition = new TelemetryAcquisition();
            Support = new TelemetrySupport();

            // Start 40Hz clock signal (25ms)
            Clock = new MMTimer(25);
            Clock.Tick += (o, s) => GlobalEvents.Fire(new TelemetryRefresh(this), true);
            Clock.Start();

            // Hook both events together:
            GlobalEvents.Hook<TelemetryRefresh>(Update, true);
        }
Esempio n. 3
0
        public Telemetry(IPluginTelemetryProvider provider, Process simulatorProcess)
        {
            Provider = provider;

            // Initialize memory objects
            var mem = new MemoryReader();

            mem.Open(simulatorProcess);

            Memory = new MemoryProvider(mem);

            // Initialize telemetry provider; this class gives us the address layout to read.
            Memory.Scanner.Enable();
            Provider.Initialize(Memory);
            Memory.Scanner.Disable();

            // Start outside-world telemetry objects
            Session     = new TelemetrySession();
            Simulator   = new TelemetryGame();
            Acquisition = new TelemetryAcquisition();
            Support     = new TelemetrySupport();

            // Start 40Hz clock signal (25ms)
            Clock       = new MMTimer(25);
            Clock.Tick += (o, s) => GlobalEvents.Fire(new TelemetryRefresh(this), true);
            Clock.Start();

            // Hook both events together:
            GlobalEvents.Hook <TelemetryRefresh>(Update, true);
        }
Esempio n. 4
0
        public void EvtStart()
        {
            Telemetry = default(GenericDataDefinition);

            _tdu2Reader             = new MemoryReader();
            _tdu2Reader.ReadProcess = ActiveProcess;
            _tdu2Reader.Open();
            openedTduAsWriter = false;

            _updateTel.Start();
        }
Esempio n. 5
0
        public void ReadPage(FileReader rdr, HexDumperConsole console)
        {
            for (int i = 0; i < 1000; i++)
            {
                rdr.SetMilestone();
                if (PageHeader.AllocationBitmap[i])
#pragma warning disable CS0642 // Possible mistaken empty statement
                {
                    ;          //console.ColorSpans.Add( new ColorSpan(ConsoleColor.Green, rdr.Position, rdr.Position + 63));
                }
#pragma warning restore CS0642 // Possible mistaken empty statement
                else
                {
                    console.ColorSpans.Add(new ColorSpan(ConsoleColor.Gray, rdr.Position, rdr.Position + 63));
                }

                PageHeader.Slot.Read(rdr);
                var ix = PageHeader.Slot.IndexOf(new byte[] { 0x23, 0xA3, 0xDB }); // Normal message types
                if (ix < 0)
                {
                    ix = PageHeader.Slot.IndexOf(new byte[] { /*0x50,*/ 0x3B, 0xC1, 0x5C }); // Long message
                }
                if (ix >= 0)
                {
                    byte   type = PageHeader.Slot.Value[ix - 1];
                    UInt32 len  = BitConverter.ToUInt32(PageHeader.Slot.Value, ix - 13);
                    if (PageHeader.AllocationBitmap[i])
                    {
                        Parser.Dumper.OnInfo($"Found a signature: {type:X2}, length: {len} ({len:X4})");
                    }
                    else
                    {
                        Parser.Dumper.OnInfo($"Found a signature IN UNALLOCATED SPACE: {type:X2}, length: {len} ({len:X4})");
                    }
                    rdr.GoToMilestone();
                    console.ColorSpans.Add(new ColorSpan(ConsoleColor.White, rdr.Position + ix - 13, rdr.Position + ix - 13 + len)); // +20
                    PageHeader.Slot.Read(rdr);

                    /// TODO: Bufferten måste vara lika stor som chunken, inte bara en slot
                    var memrdr = new MemoryReader();
                    memrdr.Open(PageHeader.Slot.Value);
                    PolyChunk.Read(memrdr);
                    ///
                }
                else
                {
                    Parser.Dumper.OnInfo(".");
                }
            }
        }
Esempio n. 6
0
        private void AdvancedMiner()
        {
            var reader = new MemoryReader();

            reader.Open(ActiveProcess, true);
            miner = new MemoryProvider(reader);

            var scanner = new MemorySignatureScanner(reader);

            scanner.Enable();
            var staticAddr   = scanner.Scan <int>(MemoryRegionType.READWRITE, "75E98B0D????????5F5E");
            var staticOffset = scanner.Scan <byte>(MemoryRegionType.READWRITE, "578B7E??8D04973BF8742F");
            var ptr1Offset   = 0;
            var spdOffset    = scanner.Scan <byte>(MemoryRegionType.READWRITE, "DEC9D947??DECADEC1D955FC");
            var cxOffset     = scanner.Scan <byte>(MemoryRegionType.READWRITE, "F30F5C4E??F30F59C0F30F59");
            var cyOffset     = cxOffset + 4; // scanner.Scan<byte>(MemoryRegionType.READWRITE, "5F8B0A890E8B4A??894EXX8B4AXX894EXX");
            var czOffset     = cxOffset + 8; // scanner.Scan<byte>(MemoryRegionType.READWRITE, "8B4A08??894EXXD9420CD95E0C");

            scanner.Disable();

            var carsPool = new MemoryPool("Cars", MemoryAddress.StaticAbsolute, staticAddr, new int[] { 0, staticOffset }, 64 * 4);

            miner.Add(carsPool);

            for (int k = 0; k < 64; k++)
            {
                var carPool = new MemoryPool("Car " + k, MemoryAddress.Dynamic, carsPool, k * 4, 512);
                carPool.Add(new MemoryField <float>("Speed", MemoryAddress.Dynamic, carPool, spdOffset, 4));
                carPool.Add(new MemoryField <float>("CoordinateX", MemoryAddress.Dynamic, carPool, cxOffset, 4));
                carPool.Add(new MemoryField <float>("CoordinateY", MemoryAddress.Dynamic, carPool, cyOffset, 4));
                carPool.Add(new MemoryField <float>("CoordinateZ", MemoryAddress.Dynamic, carPool, czOffset, 4));

                miner.Add(carPool);

                Cars.Add(new Ets2Car {
                    ID = k
                });
            }
        }
Esempio n. 7
0
        public static double GetTorque(double RPM, double throttle, double boost)
        {
            int BaseEngineCurve = 0x00ADD94C; // TODO: MAP TO SIMULATOR MAPPING

            // get engine torque figures (at this engine RPM)
            // this is directly from memory based engine curves.
            double Rads   = (RPM);
            double Th_L   = 0;
            double Th_H   = 0;
            double Tl_L   = 0;
            double Tl_H   = 0;
            double R_L    = 0;
            double R_H    = 0;
            int    offset = 0;

            double Th_Prev = 0;
            double Tl_Prev = 0;
            double R_Prev  = 0;
            bool   Cached  = ((DoubleList.Count <= 25) ? false : true);

            if (!Cached)
            {
                lock (rf)
                {
                    if (DoubleList.Count > 25)
                    {
                        return(0);
                    }
                    bool rfOpen = false;
                    try
                    {
                        rf.ReadProcess = Process.GetProcessesByName(Telemetry.m.Sim.ProcessName)[0];
                        rf.Open();
                        rfOpen = true;
                        DoubleList.Clear();
                        for (offset = 0; offset < 500; offset++)
                        {
                            double curve_rpm = 0, Tl_Now = 0, Th_Now = 0;
                            // read rpm
                            // TOOD: RFACTOR ONLY
                            // TODO: these operations need to be moved to game DLL's!!!
                            curve_rpm = Rotations.Rads_RPM(rf.ReadDouble(new IntPtr(BaseEngineCurve + 0x8 * 3 * offset)));
                            Tl_Now    = rf.ReadDouble(new IntPtr(BaseEngineCurve + 0x8 * 1 + 0x8 * 3 * offset));
                            Th_Now    = rf.ReadDouble(new IntPtr(BaseEngineCurve + 0x8 * 2 + 0x8 * 3 * offset));

                            DoubleList.Add(curve_rpm);
                            DoubleList.Add(Tl_Now);
                            DoubleList.Add(Th_Now);
                        }
                        Cached = true;
                        offset = 0;
                    }
                    catch (Exception ex)
                    {
                        Cached = false;
                        DoubleList.Clear();
                    }
                    if (rfOpen)
                    {
                        rf.Close();
                    }
                }
            }

            while (Th_H == 0)
            {
                double curve_rpm, Tl_Now, Th_Now;
                curve_rpm = DoubleList[offset * 3];
                Tl_Now    = DoubleList[offset * 3 + 1];
                Th_Now    = DoubleList[offset * 3 + 2];


                if (curve_rpm >= Rads)
                {
                    Th_L = Th_Prev;
                    Th_H = Th_Now;

                    Tl_L = Tl_Prev;
                    Tl_H = Tl_Now;


                    R_H = curve_rpm;
                    R_L = R_Prev;
                    break;
                }

                R_Prev  = curve_rpm;
                Th_Prev = Th_Now;
                Tl_Prev = Tl_Now;
                offset++;
            }
            if (Th_H == 0)
            {
            }
            // calculate duty cycle and determine torque.
            double RPM_Part = (Rads - R_L) / (R_H - R_L); // factor in rpm curve.
            double TorqueH  = Th_L + RPM_Part * (Th_H - Th_L);
            double TorqueL  = Tl_L + RPM_Part * (Tl_H - Tl_L);

            //return TorqueH * throttle * boost + TorqueL * boost;
            return((TorqueH - TorqueL) * throttle * boost + TorqueL);
        }