Exemplo n.º 1
0
        public bool Load(string track, string layout = "")
        {
            string assistLocation;
            string acLocation = Environment.GetEnvironmentVariable("AC_ROOT");

            if (acLocation == null)
            {
                acLocation = AcRootFinder.TryToFind();
            }

            Console.WriteLine("Found AC : {0}", acLocation);
            if (layout == "")
            {
                assistLocation = string.Format(@"{0}\content\tracks\{1}\ai\fast_lane.ai", acLocation, track);
            }
            else
            {
                assistLocation = string.Format(@"{0}\content\tracks\{1}\{2}\ai\fast_lane.ai", acLocation, track, layout);
            }
            aiSpline = AiSpline.FromFile(assistLocation);

            if (layout == "")
            {
                assistLocation = string.Format(@"{0}\content\tracks\{1}\ai\pit_lane.ai", acLocation, track);
            }
            else
            {
                assistLocation = string.Format(@"{0}\content\tracks\{1}\{2}\ai\pit_lane.ai", acLocation, track, layout);
            }
            aiSplinePits = AiSpline.FromFile(assistLocation);

            Console.WriteLine("Loaded AI Line. N points = {0}.", aiSpline.Points.Length);
            return(true);
        }
Exemplo n.º 2
0
 private static string PitySolution()
 {
     return(AcRootFinder.TryToFind());
 }
Exemplo n.º 3
0
        private static void Run(Options options)
        {
            var rulesFiles = options.RulesFiles.ToList();

            if (rulesFiles.Count == 0)
            {
                rulesFiles.Add("Rules.txt");
            }

            Console.WriteLine($"Rules:\n  {string.Join("\n  ", rulesFiles)}");
            var rules = rulesFiles.SelectMany(File.ReadAllLines).Select(x => x.Split('#')[0].Split(':'))
                        .Where(x => x.Length == 2 || x.Length == 3).GroupBy(x => x[0].Trim()).ToDictionary(
                x => x.Key,
                x => x.Select(y => new TextureRef {
                TextureName     = y[1].Trim(),
                PreferredFormat = ParseFormat(y.ElementAtOrDefault(2))
            }).ToList());

            // AC root
            var carsDirectory = options.Directory;

            if (carsDirectory == null)
            {
                var acRoot = AcRootFinder.TryToFind();
                if (acRoot == null)
                {
                    throw new Exception("Fail to find AC root directory");
                }

                carsDirectory = FileUtils.GetCarsDirectory(acRoot);
            }

            // List of cars to process
            var carIds = options.Cars.ToList();

            if (carIds.Count == 0)
            {
                carIds = rules.Keys.ToList();
            }

            carIds = carIds.Where(x => Directory.Exists(Path.Combine(carsDirectory, x))).ToList();

            // Car names for description
            var carNames    = carIds.Select(x => GetCarName(x, carsDirectory)).ToList();
            var description =
                $"Replaces skin textures to make windscreen banners non-transparent based on set of rules. Affects: {JoinToReadableString(carNames)}.";

            // How to pack
            string modPrefix, pathPrefix;

            if (options.PackAsMod)
            {
                modPrefix = Path.Combine("MODS", carIds.Count == 1 ? $"Transparency Banner Patch For {FileUtils.EnsureFileNameIsValid(carNames[0])}" :
                                         "Transparency Banner Patch") + Path.DirectorySeparatorChar;
                pathPrefix = Path.Combine(modPrefix, "content", "cars") + Path.DirectorySeparatorChar;
            }
            else
            {
                modPrefix  = "";
                pathPrefix = "";
            }

            // Copy global options to static variables
            _preserveGradients  = options.PreserveGradients;
            _gradientsThreshold = options.GradientsThreshold;
            _dxt1Mode           = options.Dxt1Mode;
            _mipMaps            = options.MipMaps;
            _productionQuality  = options.ProductionQuality;

            // Result filename
            var outputFilename = FileUtils.EnsureUnique(options.OutputFile ?? Path.Combine(Environment.CurrentDirectory,
                                                                                           carIds.Count == 1 ? $"transparencyPatch_{carIds[0]}.zip" : $"transparencyPatch_{carIds.Count}.zip"));

            // Packing
            using (var zip = ZipFile.Open(outputFilename, ZipArchiveMode.Create)) {
                if (options.PackAsMod)
                {
                    using (var writer = new StreamWriter(zip.CreateEntry(modPrefix + "Description.jsgme", CompressionLevel.Optimal).Open(),
                                                         Encoding.UTF8, 2048, false)) {
                        writer.Write(description.WordWrap(120));
                    }
                }

                foreach (var carId in carIds)
                {
                    if (rules.TryGetValue(carId, out var carRules))
                    {
                        ProcessKn5(carId, carsDirectory, carRules, zip, pathPrefix);
                    }
                }
            }

            // Adding archive description
            using (var stream = new FileStream(outputFilename, FileMode.Open, FileAccess.ReadWrite)) {
                stream.Seek(-2, SeekOrigin.End);
                var bytes  = Encoding.GetEncoding(1252).GetBytes(description.WordWrap(80));
                var length = Math.Min((ushort)bytes.Length, ushort.MaxValue);
                stream.Write(BitConverter.GetBytes(length), 0, 2);
                stream.Write(bytes, 0, length);
            }

            // Debug
#if DEBUG
            Process.Start(outputFilename);
#endif
        }
Exemplo n.º 4
0
        private static int MainInner(string[] args)
        {
            var presets    = args.Where(x => x.EndsWith(".pu-preset")).ToList();
            var actualList = new List <string>();

            foreach (var preset in presets)
            {
                try {
                    actualList.AddRange(
                        File.ReadAllLines(preset)
                        .Where(x => !x.StartsWith("#"))
                        .Select(x => x.Split(new[] { " #" }, StringSplitOptions.None)[0].Trim())
                        .Where(x => x.Length > 0));
                } catch (Exception e) {
                    Console.Error.WriteLine($"Can't load preset {preset}: {e.Message}.");
                }
            }

            actualList.AddRange(args.ApartFrom(presets));

            var options = new Options();

            if (!Parser.Default.ParseArguments(actualList.ToArray(), options))
            {
                return(1);
            }

            if (options.ColorGradingFilename != null && presets.Count > 0 && !File.Exists(options.ColorGradingFilename))
            {
                var locations = presets.Select(Path.GetDirectoryName).ToList();
                var current   = Environment.CurrentDirectory;
                foreach (var location in locations)
                {
                    Environment.CurrentDirectory = location;
                    var path = Path.GetFullPath(options.ColorGradingFilename);
                    if (File.Exists(path))
                    {
                        options.ColorGradingFilename = path;
                    }
                }

                Environment.CurrentDirectory = current;
            }

            var acRoot = options.AcRoot == null?AcRootFinder.TryToFind() : Path.GetFullPath(options.AcRoot);

            if (acRoot == null)
            {
                Console.Error.WriteLine("Can't find AC root directory, you need to specify it manually.");
                Console.ReadLine();
                return(1);
            }

            var ids = options.Ids.ApartFrom(presets).ToList();

            if (ids.Count == 0)
            {
                Console.Error.WriteLine("You forgot to specify what cars to update: either list their IDs or filters.");
                Console.Error.WriteLine("To process all cars, use filter \"*\".");
                Console.ReadLine();
                return(1);
            }

            IFilter <string> filter;

            try {
                filter = Filter.Create(new CarTester(acRoot), ids.Select(x =>
                                                                         "(" + (x.EndsWith("/") ? x.Substring(0, x.Length - 1) : x) + ")").JoinToString("|"), true);
                if (options.FilterTest)
                {
                    Console.WriteLine(Directory.GetDirectories(FileUtils.GetCarsDirectory(acRoot))
                                      .Select(Path.GetFileName).Where(x => filter.Test(x)).JoinToString(", "));
                    return(0);
                }

                if (options.Verbose)
                {
                    Console.WriteLine("Filter: " + filter);
                }
            } catch (Exception e) {
                Console.Error.WriteLine("Can't parse filter: " + e.Message + ".");
                Console.ReadLine();
                return(2);
            }

            if (options.Verbose)
            {
                Console.WriteLine("AC root: " + acRoot);
                Console.WriteLine("ImageMagick: " + ImageUtils.IsMagickSupported);
                Console.WriteLine("Starting shoting...");
            }

            var sw = Stopwatch.StartNew();
            int i = 0, j = 0;

            using (var thing = new DarkPreviewsUpdater(acRoot, new DarkPreviewsOptions {
                PreviewName = options.FileName,
                Showroom = options.Showroom,
                AlignCar = options.AlignCar,
                AlignCameraHorizontally = options.AlignCamera,
                AlignCameraHorizontallyOffset = options.AlignCameraOffset.Split(',').Select(x => FlexibleParser.TryParseDouble(x) ?? 0d).ToArray()[0], // TODO
                SsaaMultiplier = options.SsaaMultiplier,
                UseFxaa = options.UseFxaa,
                UseMsaa = options.UseMsaa,
                SoftwareDownsize = options.SoftwareDownsize,
                MsaaSampleCount = options.MsaaSampleCount,
                PreviewWidth = options.PreviewWidth,
                PreviewHeight = options.PreviewHeight,
                BloomRadiusMultiplier = options.BloomRadiusMultiplier,
                FlatMirror = options.FlatMirror,
                WireframeMode = options.WireframeMode,
                MeshDebugMode = options.MeshDebugMode,
                SuspensionDebugMode = options.SuspensionDebugMode,
                HeadlightsEnabled = options.HeadlightsEnabled,
                BrakeLightsEnabled = options.BrakeLightsEnabled,
                LeftDoorOpen = options.LeftDoorOpen,
                RightDoorOpen = options.RightDoorOpen,
                SteerDeg = options.SteerAngle,
                CameraPosition = options.CameraPosition.Split(',').Select(x => FlexibleParser.TryParseDouble(x) ?? 0d).ToArray(),
                CameraLookAt = options.LookAt.Split(',').Select(x => FlexibleParser.TryParseDouble(x) ?? 0d).ToArray(),
                CameraFov = options.Fov,
                BackgroundColor = ParseColor(options.BackgroundColor),
                LightColor = ParseColor(options.LightColor),
                AmbientUp = ParseColor(options.AmbientUp),
                AmbientDown = ParseColor(options.AmbientDown),
                AmbientBrightness = options.AmbientBrightness,
                LightBrightness = options.LightBrightness,
                DelayedConvertation = !options.SingleThread,
                UseSslr = options.UseSslr,
                UseAo = options.UseSsao,
                UsePcss = options.UsePcss,
                EnableShadows = options.EnableShadows,
                ShadowMapSize = options.ShadowMapSize,
                MaterialsReflectiveness = options.ReflectionMultiplier,
                ReflectionCubemapAtCamera = options.ReflectionCubemapAtCamera,
                ReflectionsWithShadows = !options.NoShadowsWithReflections,
                FlatMirrorBlurred = options.FlatMirrorBlurred,
                FlatMirrorReflectiveness = options.FlatMirrorReflectiveness,
                LightDirection = options.LightDirection.Split(',').Select(x => FlexibleParser.TryParseDouble(x) ?? 0d).ToArray(),
            })) {
                foreach (var carId in Directory.GetDirectories(FileUtils.GetCarsDirectory(acRoot))
                         .Select(Path.GetFileName).Where(x => filter.Test(x)))
                {
                    Console.WriteLine($"  {carId}...");
                    j++;

                    foreach (var skinId in Directory.GetDirectories(FileUtils.GetCarSkinsDirectory(acRoot, carId))
                             .Where(x => !options.WithoutPreviews || !File.Exists(Path.Combine(x, options.FileName)))
                             .Select(Path.GetFileName))
                    {
                        var success = false;
                        for (var a = 0; a < options.AttemptsCount || a == 0; a++)
                        {
                            try {
                                if (options.Verbose)
                                {
                                    Console.Write($"    {skinId}... ");
                                }
                                thing.Shot(carId, skinId);
                                success = true;
                                break;
                            } catch (Exception e) {
                                Console.Error.WriteLine(e.Message);

                                if (options.Verbose)
                                {
                                    Console.Error.WriteLine(e.StackTrace);
                                }
                            }
                        }

                        if (success)
                        {
                            i++;
                            if (options.Verbose)
                            {
                                Console.WriteLine("OK");
                            }
                        }
                    }

                    if (options.Verbose && j % 10 == 0)
                    {
                        Console.WriteLine(
                            $"At this moment done: {i} skins ({sw.Elapsed.TotalMilliseconds / j:F1} ms per car; {sw.Elapsed.TotalMilliseconds / i:F1} ms per skin)");
                        Console.WriteLine($"Time taken: {ToMillisecondsString(sw.Elapsed)}");
                    }
                }

                Console.Write("Finishing convertation... ");
            }

            Console.WriteLine("OK");
            Console.WriteLine($"Done: {i} skins ({sw.Elapsed.TotalMilliseconds / j:F1} ms per car; {sw.Elapsed.TotalMilliseconds / i:F1} ms per skin)");
            Console.WriteLine($"Time taken: {ToMillisecondsString(sw.Elapsed)}");

            return(0);
        }
Exemplo n.º 5
0
 public static string TryToFind()
 {
     return(AcRootFinder.TryToFind());
 }