public override Object ReadGameDataFromFile(String filename)
 {
     if (dataReadFromFile == null || filename != lastReadFileName)
     {
         dataReadFromFileIndex = 0;
         dataReadFromFile      = DeSerializeObject <ACSStructWrapper[]>(dataFilesPath + filename);
         lastReadFileName      = filename;
     }
     if (dataReadFromFile != null && dataReadFromFile.Length > dataReadFromFileIndex)
     {
         ACSStructWrapper structWrapperData = dataReadFromFile[dataReadFromFileIndex];
         dataReadFromFileIndex++;
         return(structWrapperData);
     }
     else
     {
         return(null);
     }
 }
 public override Object ReadGameDataFromFile(String filename, int pauseBeforeStart)
 {
     if (dataReadFromFile == null || filename != lastReadFileName)
     {
         dataReadFromFileIndex = 0;
         var filePathResolved = Utilities.ResolveDataFile(this.dataFilesPath, filename);
         dataReadFromFile = DeSerializeObject <ACSStructWrapper[]>(filePathResolved);
         lastReadFileName = filename;
         Thread.Sleep(pauseBeforeStart);
     }
     if (dataReadFromFile != null && dataReadFromFile.Length > dataReadFromFileIndex)
     {
         ACSStructWrapper structWrapperData = dataReadFromFile[dataReadFromFileIndex];
         dataReadFromFileIndex++;
         return(structWrapperData);
     }
     else
     {
         return(null);
     }
 }
        public override Object ReadGameData(Boolean forSpotter)
        {
            lock (this)
            {
                AssettoCorsaShared acsShared = new AssettoCorsaShared();
                if (!initialised)
                {
                    if (!InitialiseInternal())
                    {
                        throw new GameDataReadException("Failed to initialise shared memory");
                    }
                }
                try
                {
                    if (!forSpotter)
                    {
                        using (var sharedMemoryStreamView = memoryMappedGraphicFile.CreateViewStream())
                        {
                            BinaryReader _SharedMemoryStream = new BinaryReader(sharedMemoryStreamView);
                            sharedMemoryGraphicReadBuffer = _SharedMemoryStream.ReadBytes(sharedmemoryGraphicsize);
                            handleGraphic        = GCHandle.Alloc(sharedMemoryGraphicReadBuffer, GCHandleType.Pinned);
                            acsShared.acsGraphic = (SPageFileGraphic)Marshal.PtrToStructure(handleGraphic.AddrOfPinnedObject(), typeof(SPageFileGraphic));
                            handleGraphic.Free();
                        }
                        using (var sharedMemoryStreamView = memoryMappedStaticFile.CreateViewStream())
                        {
                            BinaryReader _SharedMemoryStream = new BinaryReader(sharedMemoryStreamView);
                            sharedMemoryStaticReadBuffer = _SharedMemoryStream.ReadBytes(sharedmemoryStaticsize);
                            handleStatic        = GCHandle.Alloc(sharedMemoryStaticReadBuffer, GCHandleType.Pinned);
                            acsShared.acsStatic = (SPageFileStatic)Marshal.PtrToStructure(handleStatic.AddrOfPinnedObject(), typeof(SPageFileStatic));
                            handleStatic.Free();
                        }
                    }

                    using (var sharedMemoryStreamView = memoryMappedPhysicsFile.CreateViewStream())
                    {
                        BinaryReader _SharedMemoryStream = new BinaryReader(sharedMemoryStreamView);
                        sharedMemoryPhysicsReadBuffer = _SharedMemoryStream.ReadBytes(sharedmemoryPhysicssize);
                        handlePhysics        = GCHandle.Alloc(sharedMemoryPhysicsReadBuffer, GCHandleType.Pinned);
                        acsShared.acsPhysics = (SPageFilePhysics)Marshal.PtrToStructure(handlePhysics.AddrOfPinnedObject(), typeof(SPageFilePhysics));
                        handlePhysics.Free();
                    }
                    using (var sharedMemoryStreamView = memoryMappedCrewChiefFile.CreateViewStream())
                    {
                        BinaryReader _SharedMemoryStream = new BinaryReader(sharedMemoryStreamView);
                        sharedMemoryCrewChiefReadBuffer = _SharedMemoryStream.ReadBytes(sharedmemoryCrewChiefsize);
                        handleCrewChief    = GCHandle.Alloc(sharedMemoryCrewChiefReadBuffer, GCHandleType.Pinned);
                        acsShared.acsChief = (SPageFileCrewChief)Marshal.PtrToStructure(handleCrewChief.AddrOfPinnedObject(), typeof(SPageFileCrewChief));
                        handleCrewChief.Free();
                    }

                    ACSStructWrapper structWrapper = new ACSStructWrapper();
                    structWrapper.ticksWhenRead = DateTime.Now.Ticks;
                    structWrapper.data          = acsShared;

                    if (!forSpotter && dumpToFile && dataToDump != null)
                    {
                        dataToDump.Add(structWrapper);
                    }

                    return(structWrapper);
                }
                catch (Exception ex)
                {
                    throw new GameDataReadException(ex.Message, ex);
                }
            }
        }