Esempio n. 1
0
        public void Scan()
        {
            if (!ScannedGDB)
            {
                track_gdb = new IniScanner {
                    IniFile = _file
                };
                track_gdb.Read();

                _name       = track_gdb.TryGetString("TrackName");
                _location   = track_gdb.TryGetString("Location");
                _type       = track_gdb.TryGetString("TrackType");
                _imageCache = System.IO.File.Exists(Thumbnail);

                _length = 0; // Read from AIW.

                /******************* QUALIFY DAY *******************/
                _qualifyDay = track_gdb.TryGetString("QualifyDay");
                Int32.TryParse(track_gdb.TryGetString("QualifyLaps"), out _qualifyLaps);
                Int32.TryParse(track_gdb.TryGetString("QualifyDuration"), out _qualifyMinutes);
                int    qualify_start_hr = 0, qualify_start_min = 0;
                string qstart = track_gdb.TryGetString("QualifyStart").Trim();
                if (qstart.Length == 5)
                {
                    Int32.TryParse(qstart.Substring(0, 2), out qualify_start_hr);
                    Int32.TryParse(qstart.Substring(3, 2), out qualify_start_min);
                    _qualifyStart = qualify_start_min * 60 + qualify_start_hr * 3600;
                }


                /******************* RACE DAY *******************/
                _fullRaceDay = track_gdb.TryGetString("RaceDay");
                Int32.TryParse(track_gdb.TryGetString("RaceLaps"), out _fullRaceLaps);
                Int32.TryParse(track_gdb.TryGetString("RaceDuration"), out _fullRaceMinutes);
                int    race_start_hr = 0, race_start_min = 0;
                string rstart = track_gdb.TryGetString("RaceStart").Trim();
                if (rstart.Length == 5)
                {
                    Int32.TryParse(rstart.Substring(0, 2), out race_start_hr);
                    Int32.TryParse(rstart.Substring(3, 2), out race_start_min);
                    _fullRaceMinutes = race_start_min * 60 + race_start_hr * 3600;
                }

                _pitlane = true;
                //Int32.TryParse(scanner.TryGetString("NormalPitKPH"), out _startingGridSize);
                //Int32.TryParse(scanner.TryGetString("NormalPitKPH"), out _pitSpots);
                // TODO: Headlights required.

                Int32.TryParse(track_gdb.TryGetString("NormalPitKPH"), out _pitSpeedPractice);
                Int32.TryParse(track_gdb.TryGetString("RacePitKPH"), out _pitSpeedRace);

                Double.TryParse(track_gdb.TryGetString("Qualify Laptime").Trim(), out _laprecordQualifyTime);
                Double.TryParse(track_gdb.TryGetString("Race Laptime").Trim(), out _laprecordRaceTime);
                // Unfortunately, no driver strings in rFactor for lap records.
            }
        }
Esempio n. 2
0
        public void Scan()
        {
            if (FoundFiles)
            {
                if (!ScannedGDB)
                {
                    ScannedGDB = true;
                    track_gdb  = new IniScanner {
                        IniData = masfile_gdb.Master.ExtractString(masfile_gdb)
                    };
                    track_gdb.Read();

                    _name = track_gdb.TryGetString("eventname");
                    // Extract version number
                    string MASFileDirectory = Path.GetDirectoryName(masfile_gdb.Master.File);
                    _version = ParseVersion(MASFileDirectory);
                }
            }
        }
Esempio n. 3
0
        public void ScanRoute()
        {
            if (!ScannedAIW)
            {
                _Route = new RouteCollection();

                track_aiw = new IniScanner {
                    IniData = masfile_aiw.Master.ExtractString(masfile_aiw)
                };
                track_aiw.HandleCustomKeys += new Signal(Scan_AIWKey);
                track_aiw.FireEventsForKeys = new List <string>();
                track_aiw.FireEventsForKeys.AddRange(new string[6]
                {
                    "Main.wp_pos", "Main.wp_score", "Main.wp_branchid",
                    "Main.wp_perp", "Main.wp_width", "Main.wp_ptrs"
                });
                track_aiw.Read();
                ScannedAIW = true;
            }
        }
Esempio n. 4
0
        public void ScanRoute()
        {
            if (!ScannedAIW)
            {
                _Route = new RouteCollection();

                track_aiw = new IniScanner {
                    IniFile = File.Replace("gdb", "aiw")
                };
                track_aiw.HandleCustomKeys += new Signal(Scan_AIWKey);
                track_aiw.FireEventsForKeys = new List <string>();
                track_aiw.FireEventsForKeys.AddRange(new string[6]
                {
                    "Main.wp_pos", "Main.wp_score", "Main.wp_branchid",
                    "Main.wp_perp", "Main.wp_width", "Main.wp_ptrs"
                });
                track_aiw.Read();
                _Route.Finalize();

                ScannedAIW = true;
            }
        }
Esempio n. 5
0
        public void Scan()
        {
            if (!Scanned)
            {
                Scanned   = true;
                _mScanner = new IniScanner {
                    IniFile = _file
                };
                _mScanner.HandleUnknownLine += new Signal(Handle_TrackLine);
                _mScanner.IgnoreGroups       = false;
                _mScanner.Read();

                // Only name available in rFactor. Or where else?
                _name              = _mScanner.TryGetString("Mod Name");
                _author            = "";
                _description       = "";
                _website           = "";
                _version           = "";
                _directoryVehicles = _mScanner.TryGetString("Main.ConfigOverrides", "VehiclesDir");
                string c = _mScanner.TryGetString("Main", "Vehicle Filter");
                if (c.StartsWith("\""))
                {
                    c = c.Substring(1, c.Length - 2);
                }
                if (c.Contains(" "))
                {
                    _classes = new List <string>(c.Split(" ".ToCharArray()));
                }
                else
                {
                    _classes = new List <string>(c.Split(",".ToCharArray()));
                }

                // Pitspeeds
                Int32.TryParse(_mScanner.TryGetString("Main.DefaultScoring", "RacePitKPH"), out _pitSpeedRaceDefault);
                Int32.TryParse(_mScanner.TryGetString("Main.DefaultScoring", "NormalPitKPH"),
                               out _pitSpeedPracticeDefault);

                // TODO: Add more properties like ParcFerme properties, flag settings, point scoring, etc.
                foreach (KeyValuePair <string, Dictionary <string, string[]> > GroupKey in _mScanner.Data)
                {
                    if (GroupKey.Key.StartsWith("Season"))
                    {
                        // Championship!
                        // TODO: parse track data.
                    }
                }

                Int32.TryParse(_mScanner.TryGetString("Main", "Max Opponents"), out _opponents);

                // Search for all cars in folder.
                List <string> vehicles =
                    rFactor.Garage.Files.SearchFiles(rFactor.Garage.InstallationDirectory + _directoryVehicles,
                                                     "*.veh");

                foreach (string veh in vehicles)
                {
                    ICar car = rFactor.Garage.CarFactory(this, veh);
                    if (car.InClass(Classes))
                    {
                        _models.Add(car);
                    }
                }
                Console.WriteLine("Found " + _models.Count + " vehicles for MOD [" + _name + "]");
            }
        }
Esempio n. 6
0
        public void Scan()
        {
            string rfmData = MASFile.Master.ExtractString(MASFile);

            _teams         = new List <string>();
            _championships = new List <IModChampionship>();
            _classes       = new List <string>();
            _models        = new List <ICar>();

            IniScanner scan = new IniScanner {
                IniData = rfmData
            };

            scan.HandleCustomKeys += new Signal(Scan_AddTeamAndLayout);
            scan.FireEventsForKeys = new List <string>();
            scan.FireEventsForKeys.Add("Main.layout");
            scan.FireEventsForKeys.Add("Main.team");
            scan.Read();

            _name      = scan.TryGetString("Mod Name");
            _version   = scan.TryGetString("Mod Version");
            _opponents = scan.TryGetInt32("Max Opponents");

            _author  = "Henk";
            _website = "";
            _pitSpeedPracticeDefault = scan.TryGetInt32("NormalPitKPH");
            _pitSpeedRaceDefault     = scan.TryGetInt32("RacePitKPH");

            _description       = "";
            _directoryVehicles = "";                           // Irrelevant?!

            _image = "Cache/Mods/rfactor2_ " + _name + ".png"; // Search&extract DDS from RFM file

            if (System.IO.File.Exists(_image) == false)
            {
                // Search in the MAS archive for SMICON.DDS
                foreach (MAS2File masf in MASFile.Master.Files)
                {
                    if (masf.Filename.Contains("SMICON"))
                    {
                        try
                        {
                            MASFile.Master.ExtractFile(masf, "tmp.dds");
                            Bitmap dds_bitmap = DevIL.DevIL.LoadBitmap("tmp.dds");
                            System.IO.File.Delete("tmp.dds");
                            DevIL.DevIL.SaveBitmap(_image, dds_bitmap);
                        }
                        catch (Exception ex)
                        {
                            // Failed

                            _image = "";
                        }
                        break;
                    }
                }
            }
            // Search for vehicles in mod directory
            // rFactor2 works with 'teams' instead of car class filters
            List <MAS2File> vehicles = rFactor2.Garage.Files.SearchFiles("*.veh");

            foreach (MAS2File f in vehicles)
            {
                rFactor2Car c = (rFactor2Car)rFactor2.Garage.CarFactory(this, f.Filename);
                c.Scan();
                if (_teams.Contains(c.Team.Trim().ToLower()))
                {
                    _models.Add(c);
                }
            }
        }
Esempio n. 7
0
        public void Scan()
        {
            if (!Scanned)
            {
                _mScanner = new IniScanner {
                    IniData = masfile.Master.ExtractString(masfile)
                };
                _mScanner.Read();
                Scanned = true;

                _team        = _mScanner.TryGetString("Description");
                _driver      = _mScanner.TryGetString("Driver");
                _description = _mScanner.TryGetString("Team");
                _number      = _mScanner.TryGetInt32("Number");

                if (_team.Length > 3)
                {
                    _team = _team.Substring(1, _team.Length - 2);
                }
                if (_driver.Length > 3)
                {
                    _driver = _driver.Substring(1, _driver.Length - 2);
                }
                if (_description.Length > 3)
                {
                    _description = _description.Substring(1, _description.Length - 2);
                }

                string c = _mScanner.TryGetString("Classes");
                if (c.StartsWith("\""))
                {
                    c = c.Substring(1, c.Length - 2);
                }

                if (c.StartsWith("\""))
                {
                    c = c.Substring(1, c.Length - 2);
                }
                if (c.Contains(" "))
                {
                    _classes = new List <string>(c.Split(" ".ToCharArray()));
                }
                else
                {
                    _classes = new List <string>(c.Split(",".ToCharArray()));
                }

                _files = new Dictionary <string, MAS2File>();
                _files.Add("Vehicle", rFactor2.Garage.Files.SearchFile(_mScanner.TryGetString("HDVehicle")));

                _infoEngineManufacturer = _mScanner.TryGetString("Engine");

                _infoYearFounded   = _mScanner.TryGetInt32("TeamFounded");
                _infoHq            = _mScanner.TryGetString("TeamHeadquarters");
                _infoStarts        = _mScanner.TryGetInt32("TeamStarts");
                _infoPoles         = _mScanner.TryGetInt32("TeamPoles");
                _infoWins          = _mScanner.TryGetInt32("TeamWins");
                _infoChampionships = _mScanner.TryGetInt32("TeamWorldChampionships");

                _mHDV = new IniScanner {
                    IniData = _files["Vehicle"].Master.ExtractString(_files["Vehicle"])
                };
                _mHDV.IgnoreGroups = false;
                _mHDV.Read();
            }
        }
Esempio n. 8
0
        public rFactor2CarEngine(MAS2File file, IniScanner mHdv)
        {
            masfile          = file;
            EngineTorque_Min = new Dictionary <double, double>();
            EngineTorque_Max = new Dictionary <double, double>();

            // Read the engine files.
            scanner = new IniScanner {
                IniData = file.Master.ExtractString(file)
            };
            scanner.FireEventsForKeys = new List <string>();
            scanner.FireEventsForKeys.Add("Main.rpmtorque");
            scanner.HandleCustomKeys += new Signal(HandleEngineLine);
            scanner.Read();

            string[] rpm_idle = scanner.TryGetData("Main", "IdleRPMLogic");
            string[] rpm_max  = scanner.TryGetData("Main", "RevLimitRange");
            _maxRpm   = Convert.ToDouble(rpm_max[0]) + Convert.ToDouble(rpm_max[2]) * Convert.ToDouble(rpm_max[1]); // With maximum limits.
            _idleRpm  = Convert.ToDouble(rpm_idle[0]) + Convert.ToDouble(rpm_idle[1]);
            _idleRpm /= 2.0;

            _inertia = scanner.TryGetDouble("EngineInertia");

            // TODO: add more data like cooling, radiator, etc.

            // Engine modes.

            string[] mode_range   = scanner.TryGetData("Main", "EngineBoostRange");
            string[] mode_effects = scanner.TryGetData("Main", "BoostEffects");

            // Is there any EngineBoost defined?
            if (mode_effects.Length == 3)
            {
                modes       = (int)Convert.ToDouble(mode_range[2]);
                mode_rpm    = Convert.ToDouble(mode_effects[0]);
                mode_fuel   = Convert.ToDouble(mode_effects[1]);
                mode_wear   = Convert.ToDouble(mode_effects[2]);
                mode_torque = scanner.TryGetDouble("BoostTorque");
                mode_power  = scanner.TryGetDouble("BoostPower");
            }
            else
            {
                modes = 1;
            }

            // RAM
            string[] ram_effects = scanner.TryGetData("Main", "RamEffects");
            if (ram_effects.Length == 4)
            {
                ram_torque = Convert.ToDouble(ram_effects[0]);
                ram_power  = Convert.ToDouble(ram_effects[1]);
                ram_fuel   = Convert.ToDouble(ram_effects[2]);
                ram_wear   = Convert.ToDouble(ram_effects[3]);
            }

            _maxRpmMode  = new Dictionary <int, double>();
            _engineModes = new Dictionary <int, string>();
            for (int i = 1; i <= modes; i++)
            {
                _engineModes.Add(i, "Mode " + i);
                _maxRpmMode.Add(i, mode_rpm * i + MaxRPM);
            }
        }
Esempio n. 9
0
        public rFactorCarWheels(IniScanner mHdv)
        {
            try
            {
                File = mHdv.TryGetString("GENERAL", "TireBrand");
                if (File.EndsWith(".tbc") == false)
                {
                    File = File + ".tbc";
                }
                File = rFactor.Garage.Files.SearchFile(rFactor.Garage.GamedataDirectory, File);

                var sides = new string[4] {
                    "FRONTLEFT", "FRONTRIGHT", "REARLEFT", "REARRIGHT"
                };
                IniScanner mTyre = new IniScanner {
                    IniFile = File
                };
                mTyre.Read();

                foreach (var side in sides)
                {
                    var brakeTempInfo = new string[4] {
                        "40", "300", "500", "700"
                    };
                    if (mHdv.Data.ContainsKey(side) && mHdv.Data[side].ContainsKey("brakeresponsecurve"))
                    {
                        brakeTempInfo = mHdv.TryGetData(side, "BrakeResponseCurve");
                    }

                    var brakeTempLow  = double.Parse(brakeTempInfo[1]) + 273;
                    var brakeTempHigh = double.Parse(brakeTempInfo[3]) + 273;

                    var brakeFailureMain = mHdv.TryGetString(side, "BrakeFailure").Split(',');
                    var brakeFailure     = double.Parse(brakeFailureMain[0]);

                    var optimalPressure = 158.25; // TODO
                    var radius          = 0.3261; // TODO

                    rFactorCarWheel rcw = new rFactorCarWheel(radius, brakeTempHigh, brakeTempLow, brakeFailure,
                                                              optimalPressure);
                    switch (side)
                    {
                    case "FRONTLEFT":
                        LeftFront = rcw;
                        break;

                    case "FRONTRIGHT":
                        RightFront = rcw;
                        break;

                    case "REARLEFT":
                        LeftRear = rcw;
                        break;

                    case "REARRIGHT":
                        RightRear = rcw;
                        break;
                    }
                }
            }catch (Exception e)
            {
                LeftFront  = new rFactorCarWheel();
                RightFront = new rFactorCarWheel();
                LeftRear   = new rFactorCarWheel();
                RightRear  = new rFactorCarWheel();
            }
        }
Esempio n. 10
0
        public void Scan()
        {
            if (!Scanned)
            {
                _classes = new List <string>();
                _files   = new Dictionary <string, string>();
                Scanned  = true;
                try
                {
                    _mScanner = new IniScanner {
                        IniFile = _file
                    };

                    _mScanner.Read();

                    _team        = _mScanner.TryGetString("Team");
                    _driver      = _mScanner.TryGetString("Driver");
                    _description = _mScanner.TryGetString("Description");
                    _number      = _mScanner.TryGetInt32("Number");

                    if (_team.Length > 3)
                    {
                        _team = _team.Substring(1, _team.Length - 2);
                    }
                    if (_driver.Length > 3)
                    {
                        _driver = _driver.Substring(1, _driver.Length - 2);
                    }
                    if (_description.Length > 3)
                    {
                        _description = _description.Substring(1, _description.Length - 2);
                    }

                    string c = _mScanner.TryGetString("Classes");
                    if (c.StartsWith("\"") && c.Length > 3)
                    {
                        c = c.Substring(1, c.Length - 2);
                    }

                    if (c.StartsWith("\"") && c.Length > 3)
                    {
                        c = c.Substring(1, c.Length - 2);
                    }
                    if (c.Contains(" "))
                    {
                        _classes = new List <string>(c.Split(" ".ToCharArray()));
                    }
                    else
                    {
                        _classes = new List <string>(c.Split(",".ToCharArray()));
                    }

                    // Add category to classes as well!
                    string _category = _mScanner.TryGetString("Category");
                    if (_category.Length > 3)
                    {
                        if (_category.StartsWith("\"") && _category.Length > 3)
                        {
                            _category = _category.Substring(1, _category.Length - 2);
                        }


                        _classes.AddRange(_category.Split(','));
                    }
                    _mod.AddClasses(_classes);

                    if (_files.ContainsKey("Vehicle") == false)
                    {
                        _files.Add("Vehicle",
                                   rFactor.Garage.Files.SearchFile(rFactor.Garage.GamedataDirectory,
                                                                   _mScanner.TryGetString("HDVehicle")));
                    }

                    _infoEngineManufacturer = _mScanner.TryGetString("Engine");

                    _infoYearFounded   = _mScanner.TryGetInt32("TeamFounded");
                    _infoHq            = _mScanner.TryGetString("TeamHeadquarters");
                    _infoStarts        = _mScanner.TryGetInt32("TeamStarts");
                    _infoPoles         = _mScanner.TryGetInt32("TeamPoles");
                    _infoWins          = _mScanner.TryGetInt32("TeamWins");
                    _infoChampionships = _mScanner.TryGetInt32("TeamWorldChampionships");
                }
                catch (Exception e)
                {
                }
                if (_files.ContainsKey("Vehicle"))
                {
                    try
                    {
                        _mHDV = new IniScanner {
                            IniFile = _files["Vehicle"]
                        };
                        _mHDV.IgnoreGroups = false;
                        _mHDV.Read();

                        int gears = _mHDV.TryGetInt32("DRIVELINE", "forwardgears");

                        _gearbox = new rFactorCarGearbox(gears);
                        _wheels  = new rFactorCarWheels(_mHDV);
                    }
                    catch (Exception e)
                    {
                    }
                }

                // Add additional files.
                //_files.Add("Tyre", rFactor.Garage.Files.SearchFile(rFactor.Garage.GamedataDirectory, _mHDV.TryGetString("GENERAL", "TireBrand") + ".tbc"));

                // TODO: Parse more data.
            }
        }