상속: IDataProvider
예제 #1
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);
        }
예제 #2
0
        public void PoolContainerNonZeroSize()
        {
            InitTest();

            var p = new MemoryPool("MyPool", MemoryAddress.StaticAbsolute, 0, 0, 4);

            var provider = new MemoryProvider(reader);
            provider.Add(p);
            provider.Refresh();

            Assert.AreEqual("MyPool", p.Name);
            Assert.AreEqual(MemoryAddress.StaticAbsolute, p.AddressType);
            Assert.AreEqual(0, p.Address);
            Assert.AreEqual(4, p.Size);
            Assert.AreEqual(0, p.Offset);
            Assert.False(p.IsDynamic);
            Assert.False(p.IsConstant);
            Assert.True(p.IsStatic);
            Assert.False(p.IsSignature);
            Assert.False(p.IsTemplate);

            Assert.AreEqual(1, actionLogbook.Count);

            Assert.AreEqual(0, actionLogbook[0].Address);
            Assert.AreEqual(4, actionLogbook[0].Size);
        }
 public bool CheckDriverQuick(MemoryProvider provider, int ptr)
 {
     var position = provider.Reader.ReadInt32(ptr + DriverPositionOffset);
     var name = provider.Reader.ReadString(ptr + NamePositionOffset, 8);
     //Debug.WriteLine(ptr +  " = P" +position.ToString("000"));
     return position>0 && name != "";
 }
        public void InitTest()
        {
            if (Process.GetProcessesByName("rfactor").Length == 0) Assert.Ignore();

            actionLogbook = new List<MemoryReadAction>();
            GlobalEvents.Hook<MemoryReadAction>(x =>
            {
                actionLogbook.Add(x);
                Debug.WriteLine(string.Format("Reading 0x{0:X}[0x{1:X}]", x.Address, x.Size));
            }, true);

            reader = new DiagnosticMemoryReader();
            reader.Open(Process.GetProcessesByName("rfactor")[0]);

            memory = new MemoryProvider(reader);

            drvPool = new MemoryPool("Test", MemoryAddress.StaticAbsolute, 0, 0);
            memory.Add(drvPool);
        }
예제 #5
0
 public MemorySignatureScanner(MemoryProvider provider)
 {
     Reader = provider.Reader;
 }
예제 #6
0
        public void PoolDynamic()
        {
            InitTest();

            var driversPool = new MemoryPool("Drivers", MemoryAddress.Static, 0x315298, 0x200);

            var provider = new MemoryProvider(reader);
            provider.Add(driversPool);
            provider.Refresh();

            Assert.AreEqual("Drivers", driversPool.Name);
            Assert.AreEqual(MemoryAddress.Static, driversPool.AddressType);
            Assert.AreEqual(0x315298, driversPool.Address);
            Assert.AreEqual(0x200, driversPool.Size);
            Assert.AreEqual(0, driversPool.Offset);
            Assert.False(driversPool.IsDynamic);
            Assert.False(driversPool.IsConstant);
            Assert.True(driversPool.IsStatic);
            Assert.False(driversPool.IsSignature);
            Assert.False(driversPool.IsTemplate);

            Assert.AreEqual(1, actionLogbook.Count);

            Assert.AreEqual(0x715298, actionLogbook[0].Address);
            Assert.AreEqual(0x200, actionLogbook[0].Size);

            var driver1 = new MemoryPool("Driver1", MemoryAddress.Dynamic, driversPool, 0x0, 0x6000);
            var driver2 = new MemoryPool("Driver2", MemoryAddress.Dynamic, driversPool, 0x4, 0x6000);

            provider.Add(driver1);
            provider.Add(driver2);
            provider.Refresh();

            Assert.AreEqual("Driver1", driver1.Name);
            Assert.AreEqual(MemoryAddress.Dynamic, driver1.AddressType);
            Assert.AreEqual(0, driver1.Address);
            Assert.AreEqual(0x6000, driver1.Size);
            Assert.AreEqual(0, driver1.Offset);
            Assert.AreEqual(driversPool, driver1.Pool);
            Assert.True(driver1.IsDynamic);
            Assert.False(driver1.IsConstant);
            Assert.False(driver1.IsStatic);
            Assert.False(driver1.IsSignature);
            Assert.False(driver1.IsTemplate);

            Assert.AreEqual("Driver2", driver2.Name);
            Assert.AreEqual(MemoryAddress.Dynamic, driver2.AddressType);
            Assert.AreEqual(0, driver2.Address);
            Assert.AreEqual(0x6000, driver2.Size);
            Assert.AreEqual(4, driver2.Offset);
            Assert.AreEqual(driversPool, driver2.Pool);
            Assert.True(driver2.IsDynamic);
            Assert.False(driver2.IsConstant);
            Assert.False(driver2.IsStatic);
            Assert.False(driver2.IsSignature);
            Assert.False(driver2.IsTemplate);

            Assert.AreEqual(4, actionLogbook.Count);

            Assert.AreEqual(0x715298, actionLogbook[0].Address);
            Assert.AreEqual(0x200, actionLogbook[0].Size);
            Assert.AreEqual(0x715298, actionLogbook[1].Address);
            Assert.AreEqual(0x200, actionLogbook[1].Size);
            Assert.AreEqual(0x7154c0, actionLogbook[2].Address);
            Assert.AreEqual(0x6000, actionLogbook[2].Size);
            Assert.AreEqual(0x71b408, actionLogbook[3].Address);
            Assert.AreEqual(0x6000, actionLogbook[3].Size);
        }
예제 #7
0
        public void PoolTemplate()
        {
            InitTest();

            var driversPool = new MemoryPool("Drivers", MemoryAddress.Static, 0x315298, 0x200);
            driversPool.SetTemplate(true);

            var provider = new MemoryProvider(reader);
            provider.Add(driversPool);
            provider.Refresh();

            Assert.AreEqual("Drivers", driversPool.Name);
            Assert.AreEqual(MemoryAddress.Static, driversPool.AddressType);
            Assert.AreEqual(0x315298, driversPool.Address);
            Assert.AreEqual(0x200, driversPool.Size);
            Assert.AreEqual(0, driversPool.Offset);
            Assert.False(driversPool.IsDynamic);
            Assert.False(driversPool.IsConstant);
            Assert.True(driversPool.IsStatic);
            Assert.False(driversPool.IsSignature);
            Assert.True(driversPool.IsTemplate);

            Assert.AreEqual(0, actionLogbook.Count);

            for (int i = 0; i < 100; i++)
                provider.Refresh();
            Assert.AreEqual(0, actionLogbook.Count);

            driversPool.SetTemplate(false);

            provider.Refresh();

            Assert.AreEqual(0x715298, actionLogbook[0].Address);
            Assert.AreEqual(0x200, actionLogbook[0].Size);
        }
예제 #8
0
        public void PoolStaticPointer()
        {
            InitTest();

            var p = new MemoryPool("MyPool", MemoryAddress.Static, 0x315298, new[] { 0 }, 0x6000);

            var provider = new MemoryProvider(reader);
            provider.Add(p);
            provider.Refresh();

            Assert.AreEqual("MyPool", p.Name);
            Assert.AreEqual(MemoryAddress.Static, p.AddressType);
            Assert.AreEqual(0x315298, p.Address);
            Assert.AreEqual(0x6000, p.Size);
            Assert.AreEqual(0, p.Offset);
            Assert.AreEqual(1, p.Pointers.Count());
            Assert.AreEqual(0, p.Pointers.FirstOrDefault().Offset);
            Assert.False(p.IsDynamic);
            Assert.False(p.IsConstant);
            Assert.True(p.IsStatic);
            Assert.False(p.IsSignature);
            Assert.False(p.IsTemplate);
            Assert.AreEqual(2, p.AddressTree.Length);
            Assert.AreEqual(0x715298, p.AddressTree[0]);
            Assert.AreEqual(0x7154C0, p.AddressTree[1]);

            Assert.AreEqual(2, actionLogbook.Count);

            Assert.AreEqual(0x715298, actionLogbook[0].Address);
            Assert.AreEqual(0x7154C0, actionLogbook[1].Address);

            Assert.AreEqual(0x4, actionLogbook[0].Size);
            Assert.AreEqual(0x6000, actionLogbook[1].Size);

            // re-read
            // it will follow the pointer every refresh cycle.
            provider.Refresh();

            Assert.AreEqual(4, actionLogbook.Count);

            Assert.AreEqual(0x715298, actionLogbook[0].Address);
            Assert.AreEqual(0x7154C0, actionLogbook[1].Address);
            Assert.AreEqual(0x715298, actionLogbook[2].Address);
            Assert.AreEqual(0x7154C0, actionLogbook[3].Address);

            Assert.AreEqual(0x4, actionLogbook[0].Size);
            Assert.AreEqual(0x6000, actionLogbook[1].Size);
            Assert.AreEqual(0x4, actionLogbook[2].Size);
            Assert.AreEqual(0x6000, actionLogbook[3].Size);
        }
 public bool CheckDriverQuick(MemoryProvider provider, int ptr)
 {
     return false;
 }
        public void Initialize(MemoryProvider provider)
        {
            MemoryPool simulator = new MemoryPool("Simulator", MemoryAddress.Static, 0, 0);
            simulator.Add(new MemoryFieldLazy<int>("CarPlayer", MemoryAddress.Static, 0x31528c, 4));
            simulator.Add(new MemoryFieldLazy<int[]>("Drivers", MemoryAddress.Static, 0x315298, 0x19C));

            simulator.Add(new MemoryFieldLazy<string>("LocationGame", MemoryAddress.Static, 0x6EB320, 0, 256));

            MemoryPool session = new MemoryPool("Session", MemoryAddress.Static, 0, 0);
            session.Add(new MemoryFieldLazy<int>("Cars", MemoryAddress.Static, 0x315290, 4));
            session.Add(new MemoryFieldLazy<float>("Time", MemoryAddress.Static, 0x60022C, 4));
            session.Add(new MemoryFieldLazy<float>("Clock", MemoryAddress.Static, 0x6E2CD8, 4));

            session.Add(new MemoryFieldLazy<string>("LocationTrack", MemoryAddress.Static, 0x309D28, 0, 256));

            session.Add(new MemoryFieldLazy<bool>("IsOffline", MemoryAddress.Static, 0x315444, 1, (x) => !x));
            session.Add(new MemoryFieldLazy<bool>("IsActive", MemoryAddress.Static, 0x30FEE4, 1));
            session.Add(new MemoryFieldLazy<bool>("IsReplay", MemoryAddress.Static, 0x315444, 1));
            session.Add(new MemoryFieldFunc<bool>("IsLoading", (pool) => !pool.ReadAs<bool>("IsActive") && pool.ReadAs<int>("Cars") > 0 && pool.ReadAs<string>("LocationTrack").Length != 0 ));

            MemoryPool templateDriver = new MemoryPool("DriverTemplate", MemoryAddress.StaticAbsolute, 0, 0x5F48); // base, 0x5F48 size
            templateDriver.Add(new MemoryFieldConstant<bool>("IsActive", true));

            templateDriver.Add(new MemoryFieldLazy<int>("Index", MemoryAddress.Dynamic, 0, 0x8, 32));

            templateDriver.Add(new MemoryFieldLazy<string>("Name", MemoryAddress.Dynamic, 0, 0x5B08, 32));
            templateDriver.Add(new MemoryFieldLazy<string>("CarTeam", MemoryAddress.Dynamic, 0, 0x5C22, 64));
            templateDriver.Add(new MemoryFieldLazy<string>("CarModel", MemoryAddress.Dynamic, 0, 0x5C62, 64));
            templateDriver.Add(new MemoryFieldLazy<string>("CarClasses", MemoryAddress.Dynamic, 0, 0x39BC, 64));

            templateDriver.Add(new MemoryFieldLazy<float>("Meter", MemoryAddress.Dynamic, 0, 0x3D04, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("Speed", MemoryAddress.Dynamic, 0, 0x57C0, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("RPM", MemoryAddress.Dynamic, 0, 0x317C, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("RPMMax", MemoryAddress.Dynamic, 0, 0x3180, 4));
            templateDriver.Add(new MemoryFieldLazy<int>("Gear", MemoryAddress.Dynamic, 0, 0x321C, 1));

            templateDriver.Add(new MemoryFieldLazy<float>("Mass", MemoryAddress.Dynamic, 0, 0x28DC, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("Fuel", MemoryAddress.Dynamic, 0, 0x315C, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("FuelCapacity", MemoryAddress.Dynamic, 0, 0x3160, 4));

            templateDriver.Add(new MemoryFieldLazy<float>("TyreWearLF", MemoryAddress.Dynamic, 0, 0x2A34, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("TyreWearRF", MemoryAddress.Dynamic, 0, 0x2C1C, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("TyreWearLR", MemoryAddress.Dynamic, 0, 0x2E04, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("TyreWearRR", MemoryAddress.Dynamic, 0, 0x2FEC, 4));

            templateDriver.Add(new MemoryFieldLazy<float>("InputThrottle", MemoryAddress.Dynamic, 0, 0x2938, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("InputBrake", MemoryAddress.Dynamic, 0, 0x2940, 4));

            templateDriver.Add(new MemoryFieldLazy<float>("CoordinateX", MemoryAddress.Dynamic, 0, 0x289C, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("CoordinateY", MemoryAddress.Dynamic, 0, 0x28A4, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("CoordinateZ", MemoryAddress.Dynamic, 0, 0x28A0, 4));

            templateDriver.Add(new MemoryFieldLazy<float>("CoordinateX-Replay", MemoryAddress.Dynamic, 0, 0x10, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("CoordinateY-Replay", MemoryAddress.Dynamic, 0, 0x18, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("CoordinateZ-Replay", MemoryAddress.Dynamic, 0, 0x14, 4));

            templateDriver.Add(new MemoryFieldLazy<float>("RotationX", MemoryAddress.Dynamic, 0, 0x40, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("RotationY", MemoryAddress.Dynamic, 0, 0x48, 4));
            templateDriver.Add(new MemoryFieldLazy<float>("RotationZ", MemoryAddress.Dynamic, 0, 0x44, 4));
            templateDriver.Add(new MemoryFieldFunc<float>("Yaw", (pool) => (float)Math.Atan2(pool.ReadAs<float>("RotationX"), pool.ReadAs<float>("RotationY")), true));
            templateDriver.Add(new MemoryFieldLazy<float>("AccelerationX", MemoryAddress.Dynamic, 0, 0x57C8, 4));

            templateDriver.Add(new MemoryFieldLazy<int>("Pitstops", MemoryAddress.Dynamic, 0, 0x3D2C, 4));
            templateDriver.Add(new MemoryFieldLazy<int>("Position", MemoryAddress.Dynamic, 0, 0x3D20, 4));
            templateDriver.Add(new MemoryFieldLazy<int>("Laps", MemoryAddress.Dynamic, 0, 0x3CF8, 1));

            templateDriver.Add(new MemoryFieldLazy<bool>("IsAI", MemoryAddress.Dynamic, 0, 0x59C8, 1));
            templateDriver.Add(new MemoryFieldLazy<bool>("IsRetired", MemoryAddress.Dynamic, 0, 0x4160, 1));
            templateDriver.Add(new MemoryFieldLazy<bool>("IsLimiter", MemoryAddress.Dynamic, 0, 0x17B1, 1));
            templateDriver.Add(new MemoryFieldLazy<bool>("IsPits", MemoryAddress.Dynamic, 0, 0x27A8, 1));
            templateDriver.Add(new MemoryFieldLazy<bool>("IsDriving", MemoryAddress.Dynamic, 0, 0x3CBF, 1));
            templateDriver.Add(new MemoryFieldLazy<byte>("IsDisqualified", MemoryAddress.Dynamic, 0x3D24, 1,
                                                         (v) => (byte)((v == 3) ? 1 : 0)));

            templateDriver.Add(new MemoryFieldLazy<bool>("FlagYellow", MemoryAddress.Dynamic, 0, 0x104, 1, (x) => !x));
            templateDriver.Add(new MemoryFieldLazy<bool>("FlagBlue", MemoryAddress.Dynamic, 0, 0x3E39, 1));
            templateDriver.Add(new MemoryFieldLazy<bool>("FlagBlack", MemoryAddress.Dynamic, 0, 0x3D24, 1));
            templateDriver.Add(new MemoryFieldLazy<bool>("Ignition", MemoryAddress.Dynamic, 0, 0xAA, 1));

            var laps = new MemoryPool("Laps", MemoryAddress.Dynamic, templateDriver, 0x3D90, 6 * 4 * 200);
            // 200 laps, 6 floats each.
            templateDriver.Add(laps);

            provider.Add(simulator);
            provider.Add(session);
            provider.Add(templateDriver);

            provider.Refresh();
            templateDriver.SetTemplate(true);

            DriverPositionOffset = templateDriver.Fields["Position"].Offset;
            NamePositionOffset = templateDriver.Fields["Name"].Offset;
        }
예제 #11
0
        public void PoolSignaturePointerWithSignature()
        {
            InitTest();

            var p = new MemoryPool("MyPool", MemoryAddress.StaticAbsolute,
                                   "A0XXXXXXXX8B0D????????F6D81BC0",
                                   new[]
                                       {
                                           new MemoryFieldSignaturePointer(0, false),
                                           new MemoryFieldSignaturePointer("7CD5D9XX????????518BCFD91C24E8", true),
                                       }, 0x4);

            var provider = new MemoryProvider(reader);
            provider.Add(p);
            provider.Scanner.Enable();
            provider.Refresh();
            provider.Scanner.Disable();

            Assert.AreEqual("MyPool", p.Name);
            Assert.AreEqual(MemoryAddress.StaticAbsolute, p.AddressType);
            Assert.AreEqual(0x71528C, p.Address);
            Assert.AreEqual(0x4, p.Size);
            Assert.AreEqual(0, p.Offset);
            Assert.AreEqual(2, p.Pointers.Count());
            Assert.AreEqual(0, p.Pointers.FirstOrDefault().Offset);
            Assert.AreEqual(0x317C, p.Pointers.ToList()[1].Offset);
            Assert.False(p.IsDynamic);
            Assert.False(p.IsConstant);
            Assert.True(p.IsSignature);
            Assert.True(p.IsStatic);
            Assert.False(p.IsTemplate);
            Assert.AreEqual(3, p.AddressTree.Length);
            Assert.AreEqual(0x71528C, p.AddressTree[0]);
            Assert.AreEqual(0x7154c0, p.AddressTree[1]);
            Assert.AreEqual(0x71863C, p.AddressTree[2]);

            Assert.Greater(actionLogbook.Count, 2);
            var preRefreshCount = actionLogbook.Count;

            Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 2].Address);
            Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count - 1].Address);

            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 2].Size);
            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size);

            // re-read
            // it will only read what was initially found by the signatures.
            provider.Refresh();

            var postRefreshCount = actionLogbook.Count;
            Assert.AreEqual(2, postRefreshCount - preRefreshCount);

            Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 4].Address);
            Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count - 3].Address);
            Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 2].Address);
            Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count - 1].Address);

            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 4].Size);
            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 3].Size);
            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 2].Size);
            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size);
        }
예제 #12
0
        public void PoolSignature()
        {
            InitTest();

            var p = new MemoryPool("MyPool", MemoryAddress.StaticAbsolute, "A0XXXXXXXX8B0D????????F6D81BC0", 0x4);

            var provider = new MemoryProvider(reader);
            provider.Add(p);
            provider.Scanner.Enable();
            provider.Refresh();
            provider.Scanner.Disable();

            Assert.AreEqual("MyPool", p.Name);
            Assert.AreEqual(MemoryAddress.StaticAbsolute, p.AddressType);
            Assert.AreEqual(0x71528C, p.Address);
            Assert.AreEqual(0x4, p.Size);
            Assert.AreEqual(0, p.Offset);
            Assert.AreEqual(0, p.Pointers.Count());
            Assert.False(p.IsDynamic);
            Assert.False(p.IsConstant);
            Assert.True(p.IsSignature);
            Assert.True(p.IsStatic);
            Assert.False(p.IsTemplate);
            Assert.AreEqual(1, p.AddressTree.Length);
            Assert.AreEqual(0x71528C, p.AddressTree[0]);

            Assert.Greater(actionLogbook.Count, 1);
            var preRefreshCount = actionLogbook.Count;

            Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 1].Address);
            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size);

            // re-read
            // it will only read what was initially found by the signature.
            provider.Refresh();

            var postRefreshCount = actionLogbook.Count;
            Assert.AreEqual(1, postRefreshCount - preRefreshCount);

            Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 2].Address);
            Assert.AreEqual(0x71528C, actionLogbook[actionLogbook.Count - 1].Address);

            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 2].Size);
            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size);
        }
예제 #13
0
 public void SetProvider(MemoryProvider provider)
 {
     Memory = provider;
 }
예제 #14
0
 public void SetProvider(MemoryProvider provider)
 {
     Memory = provider; // don't care
 }
 public void Initialize(MemoryProvider provider)
 {
 }
예제 #16
0
        public void RecordTestData()
        {
            float[] rpmWave;
            float[] speedWave;
            GetWaves(out rpmWave, out speedWave);
            int index = 0;

            var provider = new MemoryProvider(null);
            var fakePool = new MemoryPool("Driver", MemoryAddress.StaticAbsolute, 0, 0);
            fakePool.Add(new MemoryFieldFunc<float>("Speed", (pool) => speedWave[index], true));
            fakePool.Add(new MemoryFieldFunc<float>("RPM", (pool) => rpmWave[index++], true));
            fakePool.Add(new MemoryFieldConstant<bool>("IsAI", false));
            fakePool.Add(new MemoryFieldConstant<bool>("IsPlayer", true));
            provider.Add(fakePool);

            var fakeDriver = new TelemetryDriver(fakePool);
            var fakeDrivers = new List<TelemetryDriver>(new[] {fakeDriver});

            TelemetryLogger logger = new TelemetryLogger("testSim", new TelemetryLoggerConfiguration(true, true, true, true));
            logger.SetDatasource(provider);
            logger.SetAnnotater( new TelemetryArchive());
            GlobalEvents.Fire(new SessionStarted(), true);
            GlobalEvents.Fire(new DriversAdded(null, fakeDrivers), true);

            for(int i = 0 ; i  <1024;i++)
                logger.Update(i*25);

            GlobalEvents.Fire(new SessionStopped(), true);
            Thread.Sleep(500);

            ZipStorer checkFile = ZipStorer.Open("tmp.zip", FileAccess.Read);

            var files = checkFile.ReadCentralDir();
            Assert.AreEqual(3, files.Count);
            Assert.AreEqual(1024 * 2 * 12 + 2 * 8, files.Where(x => x.FilenameInZip.Contains("Data.bin")).FirstOrDefault().FileSize);
            Assert.AreEqual(1024*8, files.Where(x => x.FilenameInZip.Contains("Time.bin")).FirstOrDefault().FileSize);
        }
예제 #17
0
        public void PoolStaticAbsolute()
        {
            InitTest();

            var p = new MemoryPool("MyPool", MemoryAddress.StaticAbsolute, 0x7154c0, 0x6000);

            var provider = new MemoryProvider(reader);
            provider.Add(p);
            provider.Refresh();

            Assert.AreEqual("MyPool", p.Name);
            Assert.AreEqual(MemoryAddress.StaticAbsolute, p.AddressType);
            Assert.AreEqual(0x7154c0, p.Address);
            Assert.AreEqual(0x6000, p.Size);
            Assert.AreEqual(0, p.Offset);
            Assert.False(p.IsDynamic);
            Assert.False(p.IsConstant);
            Assert.True(p.IsStatic);
            Assert.False(p.IsSignature);
            Assert.False(p.IsTemplate);
            Assert.AreEqual(1, p.AddressTree.Length);
            Assert.AreEqual(0x7154C0, p.AddressTree[0]);

            Assert.AreEqual(1, actionLogbook.Count);

            Assert.AreEqual(0x7154C0, actionLogbook[0].Address);
            Assert.AreEqual(0x6000, actionLogbook[0].Size);

            provider.Refresh();

            Assert.AreEqual(2, actionLogbook.Count);

            Assert.AreEqual(0x7154C0, actionLogbook[0].Address);
            Assert.AreEqual(0x6000, actionLogbook[0].Size);
            Assert.AreEqual(0x7154C0, actionLogbook[1].Address);
            Assert.AreEqual(0x6000, actionLogbook[1].Size);
        }
예제 #18
0
        public void PoolStaticAbsolutePointerSignature()
        {
            InitTest();

            var p = new MemoryPool("MyPool", MemoryAddress.StaticAbsolute, 0x715298,
                                   new[]
                                       {
                                           new MemoryFieldSignaturePointer(0, false),
                                           new MemoryFieldSignaturePointer("7CD5D9XX????????518BCFD91C24E8", true),
                                       }, 0x4);

            var provider = new MemoryProvider(reader);
            provider.Add(p);
            provider.Scanner.Enable();
            provider.Refresh();
            provider.Scanner.Disable();

            Assert.AreEqual("MyPool", p.Name);
            Assert.AreEqual(MemoryAddress.StaticAbsolute, p.AddressType);
            Assert.AreEqual(0x715298, p.Address);
            Assert.AreEqual(0x4, p.Size);
            Assert.AreEqual(0, p.Offset);
            Assert.AreEqual(2, p.Pointers.Count());
            Assert.AreEqual(0, p.Pointers.FirstOrDefault().Offset);
            Assert.AreEqual(0x317C, p.Pointers.ToList()[1].Offset);
            Assert.False(p.IsDynamic);
            Assert.False(p.IsConstant);
            Assert.True(p.IsStatic);
            Assert.False(p.IsSignature);
            Assert.False(p.IsTemplate);
            Assert.AreEqual(3, p.AddressTree.Length);
            Assert.AreEqual(0x715298, p.AddressTree[0]);
            Assert.AreEqual(0x7154C0, p.AddressTree[1]);
            Assert.AreEqual(0x71863C, p.AddressTree[2]);

            Assert.Greater(actionLogbook.Count, 2);
            int preLogBookSize = actionLogbook.Count;

            Assert.AreEqual(0x715298, actionLogbook[actionLogbook.Count-2].Address);
            Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count-1].Address);

            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 2].Size);
            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size);

            // re-read
            // it will follow the pointer every refresh cycle.
            provider.Refresh();
            int postLogBookSize = actionLogbook.Count;
            Assert.AreEqual(postLogBookSize - preLogBookSize, 2);

            Assert.AreEqual(0x715298, actionLogbook[actionLogbook.Count - 4].Address);
            Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count - 3].Address);
            Assert.AreEqual(0x715298, actionLogbook[actionLogbook.Count - 2].Address);
            Assert.AreEqual(0x71863C, actionLogbook[actionLogbook.Count - 1].Address);

            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 4].Size);
            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 3].Size);
            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 2].Size);
            Assert.AreEqual(0x4, actionLogbook[actionLogbook.Count - 1].Size);
        }
예제 #19
0
        public void LapTests()
        {
            var lapsRecorded = new List<Lap>();

            GlobalEvents.Hook<TelemetryLapComplete>(lap => lapsRecorded.Add(lap.Lap),true);

            float[] rpmWave;
            float[] speedWave;
            GetWaves(out rpmWave, out speedWave);
            int index = 0;

            var provider = new MemoryProvider(null);
            var fakePool = new MemoryPool("Driver", MemoryAddress.StaticAbsolute, 0, 0);
            fakePool.Add(new MemoryFieldFunc<float>("Speed", (pool) => speedWave[index], true));
            fakePool.Add(new MemoryFieldFunc<float>("RPM", (pool) => rpmWave[index++], true));
            fakePool.Add(new MemoryFieldFunc<float>("Laps", (pool) =>
                                                                {
                                                                    if(index <= 100)
                                                                        return 0;
                                                                    if (index > 100 && index <= 225)
                                                                        return 1;
                                                                    if (index > 225 && index <= 325)
                                                                        return 2;
                                                                    if (index > 325 && index <= 500)
                                                                        return 3;
                                                                    if (index > 500 && index <= 575)
                                                                        return 4;
                                                                    if (index > 575 && index <= 1024)
                                                                        return 5;

                                                                        return -1;
                                                                }, true));
            fakePool.Add(new MemoryFieldConstant<bool>("IsAI", false));
            fakePool.Add(new MemoryFieldConstant<bool>("IsPlayer", true));
            provider.Add(fakePool);

            var fakeDriver = new TelemetryDriver(fakePool);
            var fakeDrivers = new List<TelemetryDriver>(new[] { fakeDriver });

            var logger = new TelemetryLogger("testSim", new TelemetryLoggerConfiguration(true, true, true, true));
            logger.SetDatasource(provider);
            //logger.SetAnnotater(new TelemetryArchive());
            GlobalEvents.Fire(new SessionStarted(), true);
            GlobalEvents.Fire(new DriversAdded(null, fakeDrivers), true);

            for (int i = 0; i < 1024; i++)
                logger.Update(i * 25);

            GlobalEvents.Fire(new SessionStopped(), true);
            Thread.Sleep(500);

            Assert.AreEqual(6, lapsRecorded.Count);
            Assert.AreEqual(0, lapsRecorded[0].LapNumber);
            Assert.AreEqual(1, lapsRecorded[1].LapNumber);
            Assert.AreEqual(2, lapsRecorded[2].LapNumber);
            Assert.AreEqual(3, lapsRecorded[3].LapNumber);
            Assert.AreEqual(4, lapsRecorded[4].LapNumber);
            Assert.AreEqual(5, lapsRecorded[5].LapNumber);

            Assert.AreEqual(100, lapsRecorded[0].Total);
            Assert.AreEqual(125, lapsRecorded[1].Total);
            Assert.AreEqual(100, lapsRecorded[2].Total);
            Assert.AreEqual(175, lapsRecorded[3].Total);
            Assert.AreEqual(75, lapsRecorded[4].Total);
            Assert.AreEqual(-1, lapsRecorded[5].Total);
        }