void PerformInjection()
        {
            AutoResetEvent injectionEvent = new AutoResetEvent(false);

            string[] processNames = new string[] { "WW1" };

            foreach (string processName in processNames)
            {
                //processName
                Task.Run(delegate()
                {
                    InjectionManager.Monitor(processName, Resources.WarplanesWW1Telemetry, injectionEvent, "WarplanesWW1Telemetry");
                });
            }

            while (true)
            {
                injectionEvent.WaitOne();
                ui.StatusTextChanged(InjectionManager.GetStatus());

                if (InjectionManager.GetState() == InjectionManager.State.Failed || InjectionManager.GetState() == InjectionManager.State.Success)
                {
                    break;
                }
            }
        }
        void PerformInjection()
        {
            AutoResetEvent injectionEvent = new AutoResetEvent(false);

            string[] processNames = new string[] { "NascarHeat5", "NascarHeat4", "AllAmericanRacing", "SprintCarRacing" };

            foreach (string processName in processNames)
            {
                //processName
                Task.Run(delegate()
                {
                    InjectionManager.Monitor(processName, Resources.MonsterGamesTelemetry, injectionEvent, "MonsterGamesTelemetry");
                });
            }

            while (true)
            {
                injectionEvent.WaitOne();
                ui.StatusTextChanged(InjectionManager.GetStatus());

                if (InjectionManager.GetState() == InjectionManager.State.Failed || InjectionManager.GetState() == InjectionManager.State.Success)
                {
                    break;
                }
            }
        }
        void ReadTelemetry()
        {
            PerformInjection();

            if (InjectionManager.GetState() == InjectionManager.State.Failed)
            {
                return;
            }

            UdpClient socket = new UdpClient();

            socket.ExclusiveAddressUse = false;
            socket.Client.Bind(new IPEndPoint(IPAddress.Any, readPort));

            Stopwatch sw = new Stopwatch();

            sw.Start();

            StartSending();

            //read and process
            while (!IsStopped)
            {
                try
                {
                    //wait for telemetry
                    if (socket.Available == 0)
                    {
                        if (sw.ElapsedMilliseconds > 500)
                        {
                            Thread.Sleep(1000);
                        }
                        continue;
                    }

                    Byte[] received = socket.Receive(ref senderIP);

                    while (socket.Available != 0)
                    {
                        received = socket.Receive(ref senderIP);
                        continue;
                    }


                    var alloc = GCHandle.Alloc(received, GCHandleType.Pinned);
                    data = (WarplanesWW1Data)Marshal.PtrToStructure(alloc.AddrOfPinnedObject(), typeof(WarplanesWW1Data));
                    alloc.Free();


                    if (data.packetId < lastPacketId && Math.Abs((long)data.packetId - (long)lastPacketId) < 1000)
                    {
                        continue;
                    }

                    lastPacketId = data.packetId;

                    if (!data.paused)
                    {
                        dt = (float)sw.Elapsed.TotalSeconds;
                        sw.Restart();
                        ProcessWarplanesWW1Data(dt);// data.dt);
                    }
                }
                catch (Exception e)
                {
                    Thread.Sleep(1000);
                }
            }

            StopSending();

            Thread.CurrentThread.Join();
        }
예제 #4
0
        void ReadTelemetry()
        {
            PerformInjection();

            if (InjectionManager.GetState() == InjectionManager.State.Failed)
            {
                return;
            }

            UdpClient socket = new UdpClient();

            socket.ExclusiveAddressUse = false;
            socket.Client.Bind(new IPEndPoint(IPAddress.Any, readPort));

            StartSending();


            //read and process
            while (!IsStopped)
            {
                try
                {
                    //wait for telemetry
                    if (socket.Available == 0)
                    {
                        using (var sleeper = new ManualResetEvent(false))
                        {
                            sleeper.WaitOne(1);
                        }
                        continue;
                    }

                    Byte[] received = socket.Receive(ref senderIP);


                    if (socket.Available == 0)
                    {
                        data = JsonConvert.DeserializeObject <OverloadData>(System.Text.Encoding.UTF8.GetString(received));

                        if (data.packetId < lastPacketId && Math.Abs((long)data.packetId - (long)lastPacketId) < 1000)
                        {
                            continue;
                        }

                        lastPacketId = data.packetId;

                        if (!data.paused)
                        {
                            ProcessOverloadData(data.dt);
                        }
                    }
                }
                catch (Exception e)
                {
                    Thread.Sleep(1000);
                }
            }

            StopSending();

            Thread.CurrentThread.Join();
        }