Beispiel #1
0
        void ScanComplete()
        {
            ProcessMemoryReader reader = new ProcessMemoryReader();

            reader.ReadProcess = mainProcess;
            UInt64 readSize = 4 * 4 * 4;

            byte[] readBuffer = new byte[readSize];
            reader.OpenProcess();


            Stopwatch sw = new Stopwatch();

            sw.Start();

            StartSending();

            double frameDT = 0;

            while (!IsStopped)
            {
                try
                {
                    //temp



                    /*
                     * //Loop until the StopWatch has exceeded updateDelay. This uses up all of the CPU time on this thread!
                     * while (true)
                     * {
                     *  frameDT = sw.Elapsed.TotalSeconds;
                     *  if (frameDT >= (updateDelay / 1000.0f))
                     *      break;
                     * }*/

                    //Instead; sleep by the remaining amount. This releases CPU time to the system.
                    double lrSleepMS = (updateDelay - sw.Elapsed.TotalMilliseconds);

                    if (lrSleepMS < 0)
                    {
                        //We overran!
                    }
                    else
                    {
                        if (lrSleepMS < 1f)
                        {
                            lrSleepMS = 1f;                //do not allow strangling of the CPU
                        }
                        Thread.Sleep((int)lrSleepMS);
                    }

                    frameDT += sw.Elapsed.TotalSeconds;//this should hopefully just be exactly updateDelay * 1000
                    sw.Restart();

                    Int64 byteReadSize;
                    reader.ReadProcessMemory((IntPtr)memoryAddress, readSize, out byteReadSize, readBuffer);

                    if (byteReadSize == 0)
                    {
                        continue;
                    }

                    float[] floats = new float[4 * 4];

                    Buffer.BlockCopy(readBuffer, 0, floats, 0, readBuffer.Length);

                    Matrix4x4 transform = new Matrix4x4(floats[0], floats[1], floats[2], floats[3]
                                                        , floats[4], floats[5], floats[6], floats[7]
                                                        , floats[8], floats[9], floats[10], floats[11]
                                                        , floats[12], floats[13], floats[14], floats[15]);

                    if (ProcessTransform(transform, (float)frameDT))
                    {
                        //success! - reset DT
                        frameDT = 0;
                    }
                    else
                    {
                        //duplicate data from WF - keep frameDT and accumlate
                    }

                    //debug
//                    TrackedValues.Add((float)filteredData.gforce_longitudinal);


                    updateDelay = (double)ui.SleepTime;//push this into the base class (todo, this not like this)
                }
                catch (Exception e)
                {
                    Thread.Sleep(1000);
                }
            }
            reader.CloseHandle();

            Console.WriteLine("Ending WreckFest Telemetry Provider");

            StopSending();

            //  Thread.CurrentThread.Join();//this seems to crash everything

            Console.WriteLine("Closing WreckFest Telemetry Provider");
        }
Beispiel #2
0
        void ReadTelemetry()
        {
            ProcessMemoryReader reader = new ProcessMemoryReader();

            reader.ReadProcess = mainProcess;
            UInt64 readSize = 4 * 4 * 4;

            byte[] readBuffer = new byte[readSize];
            reader.OpenProcess();


            StartSending();

            Stopwatch sw = new Stopwatch();

            sw.Start();


            //read and process
            while (!IsStopped)
            {
                try
                {
                    //dis is super accurate for timing
                    float frameDT = 0;
                    while (true)
                    {
                        frameDT = (float)sw.Elapsed.TotalSeconds;
                        if (frameDT >= (updateDelay / 1000.0f))
                        {
                            break;
                        }
                    }
                    sw.Restart();

                    if (droppedSampleCount >= 100)
                    {
                        FindMatrixPointerAddress();
                        droppedSampleCount = 0;
                        //Debug.WriteLine("Finding Pointer");
                    }

                    Int64 byteReadSize;
                    reader.ReadProcessMemory((IntPtr)matrixAddress, readSize, out byteReadSize, readBuffer);

                    if (byteReadSize == 0)
                    {
                        FindMatrixPointerAddress();
                        droppedSampleCount = 0;
                        //Debug.WriteLine("Finding Pointer");
                        continue;
                    }

                    float[] floats = new float[4 * 4];

                    Buffer.BlockCopy(readBuffer, 0, floats, 0, readBuffer.Length);

                    Matrix4x4 trans = new Matrix4x4(
                        floats[2], floats[1], floats[0], 0.0f
                        , floats[6], floats[5], floats[4], 0.0f
                        , floats[10], floats[9], floats[8], 0.0f
                        , floats[14], floats[13], floats[12], 1.0f);



                    ProcessSquadronsData(trans, frameDT);
                }
                catch (Exception e)
                {
                    Thread.Sleep(1000);
                }
            }

            reader.CloseHandle();

            StopSending();
            Thread.CurrentThread.Join();
        }
Beispiel #3
0
        void ReadTelemetry()
        {
            ProcessMemoryReader reader = new ProcessMemoryReader();

            reader.ReadProcess = mainProcess;
            UInt64 wheelGroupReadSize = (UInt64)Marshal.SizeOf(typeof(WRCWheelGroupData));

            byte[] wheelGroupReadBuffer = new byte[wheelGroupReadSize];
            reader.OpenProcess();


            StartSending();

            Stopwatch sw = new Stopwatch();

            sw.Start();


            //read and process
            while (!IsStopped)
            {
                try
                {
                    //dis is super accurate for timing
                    double frameDT = 0;
                    while (true)
                    {
                        frameDT = sw.Elapsed.TotalSeconds;
                        if (frameDT >= (updateDelay / 1000.0f))
                        {
                            break;
                        }
                    }
                    sw.Restart();

//                    mainProcess.Suspend();
                    if (droppedSampleCount >= 100)
                    {
                        FindWheelGroupPointerAddress();
                        droppedSampleCount = 0;
                        Debug.WriteLine("Finding Pointer");
                    }

                    Int64 byteReadSize;
                    reader.ReadProcessMemory((IntPtr)wheelGroupMemoryAddress, wheelGroupReadSize, out byteReadSize, wheelGroupReadBuffer);
//                    mainProcess.Resume();

                    if (byteReadSize == 0)
                    {
                        FindWheelGroupPointerAddress();
                        droppedSampleCount = 0;
                        Debug.WriteLine("Finding Pointer");
                        continue;
                    }

                    var alloc = GCHandle.Alloc(wheelGroupReadBuffer, GCHandleType.Pinned);
                    wheelsGroupData = (WRCWheelGroupData)Marshal.PtrToStructure(alloc.AddrOfPinnedObject(), typeof(WRCWheelGroupData));
                    alloc.Free();

                    ProcessWRCData((float)frameDT);
                }
                catch (Exception e)
                {
                    Thread.Sleep(1000);
                }
            }

            reader.CloseHandle();

            StopSending();
            Thread.CurrentThread.Join();
        }
Beispiel #4
0
        List <long> NarrowMemoryAddresses(long[] addresses)
        {
            if (addresses == null || addresses.Length == 0)
            {
                return(null);
            }

            List <long> returnList = new List <long>();

            ProcessMemoryReader reader = new ProcessMemoryReader();

            reader.ReadProcess = mainProcess;

            UInt64 readSize = ((4 * 4 * 4) * 3) + ((4 * 4 * 6) * 2);

            byte[] readBuffer = new byte[readSize];
            reader.OpenProcess();
            float[] floats = new float[4 * 4];


            foreach (long address in addresses)
            {
                Int64 byteReadSize;
                reader.ReadProcessMemory((IntPtr)address, readSize, out byteReadSize, readBuffer);

                if (byteReadSize == 0)
                {
                    continue;
                }

                Buffer.BlockCopy(readBuffer, 0, floats, 0, (4 * 4 * 4));

                Vector3 r = new Vector3(floats[0], floats[1], floats[2]);
                Vector3 u = new Vector3(floats[4], floats[5], floats[6]);
                Vector3 f = new Vector3(floats[8], floats[9], floats[10]);

                float rl = r.Length();
                float ul = u.Length();
                float fl = f.Length();

                float minVal = 0.9f;
                float maxVal = 1.1f;
                if (rl >= minVal && rl <= maxVal && ul >= minVal && ul <= maxVal && fl >= minVal && fl <= maxVal)
                {
                    byte[] a = readBuffer.Take((4 * 4 * 4)).ToArray();

                    byte[] b = readBuffer.Skip((4 * 4 * 4) + (4 * 4 * 6)).Take((4 * 4 * 4)).ToArray();

                    byte[] c = readBuffer.Skip(((4 * 4 * 4) + (4 * 4 * 6)) * 2).Take((4 * 4 * 4)).ToArray();

                    if (ArraysEqual(a, b))
                    {
                        if (ArraysEqual(a, c))
                        {
                            returnList.Add(address);
                        }
                    }
                }
            }

            reader.CloseHandle();

            return(returnList);
        }
Beispiel #5
0
        void ScanComplete()
        {
            ProcessMemoryReader reader = new ProcessMemoryReader();

            reader.ReadProcess = mainProcess;
            UInt64 readSize = 4 * 4 * 4;

            byte[] readBuffer = new byte[readSize];
            reader.OpenProcess();


            Stopwatch sw = new Stopwatch();

            sw.Start();

            StartSending();

            while (!IsStopped)
            {
                try
                {
                    double frameDT = 0;
                    while (true)
                    {
                        frameDT = sw.Elapsed.TotalSeconds;
                        if (frameDT >= (updateDelay / 1000.0f))
                        {
                            break;
                        }
                    }
                    sw.Restart();

                    Int64 byteReadSize;
                    reader.ReadProcessMemory((IntPtr)memoryAddress, readSize, out byteReadSize, readBuffer);

                    if (byteReadSize == 0)
                    {
                        continue;
                    }

                    float[] floats = new float[4 * 4];

                    Buffer.BlockCopy(readBuffer, 0, floats, 0, readBuffer.Length);

                    Matrix4x4 transform = new Matrix4x4(floats[0], floats[1], floats[2], floats[3]
                                                        , floats[4], floats[5], floats[6], floats[7]
                                                        , floats[8], floats[9], floats[10], floats[11]
                                                        , floats[12], floats[13], floats[14], floats[15]);

                    ProcessTransform(transform, (float)frameDT);
                }
                catch (Exception e)
                {
                    Thread.Sleep(1000);
                }
            }
            reader.CloseHandle();

            StopSending();

            Thread.CurrentThread.Join();
        }