Beispiel #1
0
        public void TestFS13_1()
        {
            var gameFolder = SteamHelper.GetGameDirectory("Farming Simulator 2013");

            Skip.If(gameFolder == null);

            var file = new ShapesFile();

            file.Load(Path.Combine(gameFolder, @"data\vehicles\tools\kuhn\kuhnGA4521GM.i3d.shapes"));
            AssertShapesFile(file, 68, 2, 32);
            AssertShape(file.Shapes[0], "blanketBarShape2", 26, 68, 44);
        }
Beispiel #2
0
        public void TestFS17_1()
        {
            var gameFolder = SteamHelper.GetGameDirectory("Farming Simulator 17");

            Skip.If(gameFolder == null);

            var file = new ShapesFile();

            file.Load(Path.Combine(gameFolder, @"data\vehicles\tools\magsi\wheelLoaderLogFork.i3d.shapes"));
            AssertShapesFile(file, 49, 5, 12);
            AssertShape(file.Shapes[0], "wheelLoaderLogForkShape", 1, 24, 12);
        }
Beispiel #3
0
        public void TestFS15_1()
        {
            var gameFolder = SteamHelper.GetGameDirectory("Farming Simulator 15");

            Skip.If(gameFolder == null);

            var file = new ShapesFile();

            file.Load(Path.Combine(gameFolder, @"data\vehicles\tools\grimme\grimmeFT300.i3d.shapes"));
            AssertShapesFile(file, 188, 3, 16);
            AssertShape(file.Shapes[0], "grimmeFTShape300", 1, 40, 20);
        }
Beispiel #4
0
    IEnumerator loadData()
    {
        // loadingText += "Loading Default Physics... ";
        // Wadfile physicsFile = new Wadfile();
        loadingText += "\n";
        SoundsFile sounds = new SoundsFile();

        sounds.Load(GlobalData.soundsFilePath);
        yield return(makeAudioDefinitionsFromSoundsFile(sounds));

        // AudioSource aud = GetComponent<AudioSource>();
        // aud.clip = audioDefinitions[29].sounds[0];
        // aud.Play();

        loadingText   += "\n";
        GlobalData.map = this;
        ShapesFile shapes = new ShapesFile();

        shapes.Load(GlobalData.shapesFilePath);
        yield return(StartCoroutine(makeMaterialsFromShapesFile(shapes)));

        loadingText += "\nLoading Map... ";
        Wadfile wadfile = new Wadfile();

        wadfile.Load(GlobalData.mapsFilePath);
        foreach (var kvp in wadfile.Directory)
        {
            if (kvp.Value.Chunks.ContainsKey(MapInfo.Tag))
            {
                string String      = kvp.Value.LevelName;
                int    levelNumber = kvp.Key;
            }
        }
        Level Level = new Level();

        Level.Load(wadfile.Directory[mapNo]);

        Debug.Log(Level.Name);
        // Debug.Log(Level.Environment);

        yield return(createLightsFromMarathonMap(Level));

        yield return(StartCoroutine(makeWorldFromMarathonMap(Level)));

        loadingText += "\nSpawing Entities... ";
        yield return(StartCoroutine(spawnEntitiesFromMarathonMap(Level, shapes)));

        loadingText = null;
        GameObject.Find("LoadingDisplay").SetActive(false);


        GameObject.Find("worldLight").SetActive(GlobalData.globalLighting);
    }
Beispiel #5
0
        public void TestFS19()
        {
            var gameFolder = SteamHelper.GetGameDirectory("Farming Simulator 19");

            Skip.If(gameFolder == null);

            var file = new ShapesFile();

            file.Load(Path.Combine(gameFolder, @"data\vehicles\magsi\telehandlerBaleFork\telehandlerBaleFork.i3d.shapes"));
            AssertShapesFile(file, 201, 5, 9);
            AssertShape(file.Shapes[0], "colPartBackShape1", 4, 24, 12);
        }
Beispiel #6
0
        private static ShapesFile LoadFile(CommandLineOptions options)
        {
            var file = new ShapesFile(Logger);

            Logger.LogInformation($"Loading file: {Path.GetFileName(options.File)}");
            try
            {
                file.Load(options.File);
            }
            catch (DecryptFailureException)
            {
                Logger.LogInformation("Failed decrypting file. Attempting to brute-force the seed...");
                return(LoadFileBruteForce(options));
            }

            return(file);
        }
Beispiel #7
0
        private static void ExtractFile(CommandLineOptions options)
        {
            var file = new ShapesFile(Logger);

            file.Load(options.File);

            string folder;

            if (options.CreateDir)
            {
                folder = Path.Combine(options.Out, "extract_" + Path.GetFileName(file.FilePath));
                Directory.CreateDirectory(folder);
            }
            else
            {
                folder = options.Out;
            }

            foreach (var shape in file.Shapes)
            {
                if (options.DumpBinary)
                {
                    var binFileName = $"shape_{shape.Name}.bin";
                    File.WriteAllBytes(Path.Combine(folder, CleanFileName(binFileName)), shape.RawData);
                }

                var mdlFileName = Path.Combine(folder, CleanFileName(shape.Name + ".obj"));

                var objfile = shape.ToObj();
                objfile.Name = Path.GetFileName(file.FilePath).Replace(".i3d.shapes", "");
                var dataBlob = objfile.ExportToBlob();

                if (File.Exists(mdlFileName))
                {
                    File.Delete(mdlFileName);
                }

                File.WriteAllBytes(mdlFileName, dataBlob);
            }
        }
Beispiel #8
0
        private static ShapesFile LoadFileBruteForce(CommandLineOptions options)
        {
            var file    = new ShapesFile(Logger);
            var success = false;

            byte seed;

            for (seed = 0; seed < 0xFF; seed++)
            {
                try
                {
                    file.Load(options.File, seed);
                }
                catch (DecryptFailureException)
                {
                    continue;
                }

                if (!IsFileLoadSuccessful(file))
                {
                    continue;
                }

                success = true;
                break;
            }

            if (!success)
            {
                Logger.LogWarning("Failed to find any matching seed for this file.");
                return(null);
            }

            Logger.LogInformation($"Found successful seed {seed}");
            return(file);
        }
Beispiel #9
0
 private static void AssertShapesFile(ShapesFile file, int seed, int version, int shapeCount)
 {
     Assert.Equal(seed, file.Seed);
     Assert.Equal(version, file.Version);
     Assert.Equal(shapeCount, file.ShapeCount);
 }
Beispiel #10
0
    IEnumerator makeMaterialsFromShapesFile(ShapesFile shapes)
    {
        string load = loadingText;

        for (int col = 0; col < 32; col++)
        {
            //if (col != 20) {	collectionMapping.Add(0);continue;}
            //bool landscape = col >= 27;
            Collection coll = shapes.GetCollection(col);
            collectionMapping.Add(coll.BitmapCount);
            // Debug.Log(collectionMapping[col]);
            ShapeDescriptor d = new ShapeDescriptor();
            d.CLUT       = 0;
            d.Collection = (byte)col;

            for (byte i = 0; i < coll.BitmapCount; ++i)
            {
                d.Bitmap = i;

                Texture2D bitmap = shapes.GetShape(d);


                if (GlobalData.landscapeCollections.Contains(col))
                {
                    bitmap = rotateTexture(bitmap, false);
                    //extend landscape image to make skybox distortion less
                    if (GlobalData.landscapeType > 0)
                    {
                        Color32[] original   = bitmap.GetPixels32();
                        Color32[] stretched  = new Color32[bitmap.width * bitmap.width];
                        int       difference = stretched.Length - original.Length;
                        int       top        = difference / 2;

                        if (GlobalData.landscapeType == 2)
                        {
                            Color32 fill = new Color32(255, 255, 255, 0);
                            for (int pos = 0; pos < stretched.Length; pos++)
                            {
                                stretched[pos] = fill;
                            }
                        }

                        if (GlobalData.landscapeType == 3)
                        {
                            int       row        = bitmap.width;
                            Color32[] fillTop    = new Color32[row];
                            Color32[] fillBottom = new Color32[row];
                            for (int pos = 0; pos < row; pos++)
                            {
                                fillBottom[pos] = original[pos];
                                fillTop[pos]    = original[pos + original.Length - row];
                            }

                            for (int y = 0; y < top / row; y++)
                            {
                                for (int x = 0; x < row; x++)
                                {
                                    stretched[y * row + x + original.Length + top] = fillTop[x];
                                    stretched[y * row + x] = fillBottom[x];
                                }
                            }
                        }
                        if (GlobalData.landscapeType == 4 || GlobalData.landscapeType == 5)
                        {
                            int       row        = bitmap.width;
                            Color32[] fillTop    = new Color32[row];
                            Color32[] fillBottom = new Color32[row];
                            int       rt         = 0;
                            int       gt         = 0;
                            int       bt         = 0;
                            int       rb         = 0;
                            int       gb         = 0;
                            int       bb         = 0;
                            for (int pos = 0; pos < row; pos++)
                            {
                                rb += original[pos].r;
                                gb += original[pos].g;
                                bb += original[pos].b;
                                rt += original[pos + original.Length - row].r;
                                gt += original[pos + original.Length - row].g;
                                bt += original[pos + original.Length - row].b;
                            }
                            rt = rt / row;
                            gt = gt / row;
                            bt = bt / row;
                            rb = rb / row;
                            gb = gb / row;
                            bb = bb / row;

                            for (int pos = 0; pos < row; pos++)
                            {
                                fillBottom[pos] = new Color32((byte)rb, (byte)gb, (byte)bb, 255);
                                fillTop[pos]    = new Color32((byte)rt, (byte)gt, (byte)bt, 255);
                            }

                            for (int y = 0; y < top / row; y++)
                            {
                                for (int x = 0; x < row; x++)
                                {
                                    stretched[y * row + x + original.Length + top] = fillTop[x];
                                    stretched[y * row + x] = fillBottom[x];
                                }
                            }
                        }
                        for (int pos = 0; pos < original.Length; pos++)
                        {
                            stretched[pos + top] = original[pos];
                        }

                        if (GlobalData.landscapeType == 5)
                        {
                            Color32[] restretched = new Color32[bitmap.width * bitmap.width - top];
                            for (int pos = top / 2; pos < stretched.Length - top / 2; pos++)
                            {
                                restretched[pos - top / 2] = stretched[pos];
                            }
                            bitmap = new Texture2D(bitmap.width, bitmap.width - top / bitmap.width);
                            bitmap.SetPixels32(restretched);
                        }
                        else
                        {
                            bitmap = new Texture2D(bitmap.width, bitmap.width);
                            bitmap.SetPixels32(stretched);
                        }
                    }
                    bitmap.wrapMode = TextureWrapMode.Clamp;
                }

                bitmap.Apply();

                Material material = new Material(Shader.Find("Custom/StandardClippableV2"));

                material.SetFloat("_Glossiness", 0.0f);
                if (bitmap.format == TextureFormat.ARGB32)
                {
                    material.SetFloat("_Mode", 1f);
                    material.SetFloat("_Cutoff", 0.85f);
                    material.EnableKeyword("_ALPHABLEND_ON");
                    material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
                    material.EnableKeyword("_ALPHATEST_ON");
                }
                else
                {
                    //Debug.Log("noalpha");
                }
                material.mainTexture = bitmap;
                material.SetTexture("_EmissionMap", bitmap);
                material.SetColor("_EmissionColor", Color.white);
                material.EnableKeyword("_EMISSION");
                materials.Add(material);
                //	Debug.Log(material);
            }
            loadingText = load + "Loading Shapes... " + col + "/31";
            if (col % 7 == 0)
            {
                yield return(null);
            }
        }
        loadingText = load + "Loading Shapes... 31/31";
    }
Beispiel #11
0
 /// <summary>
 /// Tests if the shapes loaded from this file are valid shapes
 /// </summary>
 /// <param name="file"></param>
 /// <returns></returns>
 private static bool IsFileLoadSuccessful(ShapesFile file)
 {
     // All shape names should contain only valid ASCII characters, if they don't we know something has gone wrong
     return(file.Shapes.SelectMany(shape => shape.Name).All(c => c >= 0x20 && c <= 0x7E));
 }
Beispiel #12
0
        static void Main(string[] args)
        {
            /* TODO DO NOT FORGET TO PUT THIS BACK
             * string path = "";
             *
             * if (args.Length > 0) path = args[0];
             * else {
             * Console.WriteLine("Current directory is " + Directory.GetCurrentDirectory());
             * Console.Write("Enter a directory or leave blank for the above: ");
             * path = Console.ReadLine();
             * } */

            string path = @"C:\Users\Nixill\Documents\Git\NXS-GTFS";

            if (path != "")
            {
                Directory.SetCurrentDirectory(path);
            }

            // Get the configuration
            Console.WriteLine("Reading config...");
            Config.Load();

            // Make sure we have directories
            Console.WriteLine("Creating folders...");
            Directory.CreateDirectory("gtfs");
            Directory.CreateDirectory("shapes");
            Directory.CreateDirectory("trip-times");
            Directory.CreateDirectory("trips");

            // Initialize lists of things
            List <CompleteRelation>          agencies = new List <CompleteRelation>();
            List <ICompleteOsmGeo>           stops    = new List <ICompleteOsmGeo>();
            Dictionary <long, RouteRelation> routes   = new Dictionary <long, RouteRelation>();

            Console.WriteLine("Reading map file...");
            using (FileStream fileStream = File.OpenRead("map.osm")) {
                // Open the map file
                XmlOsmStreamSource xmlSrc = new XmlOsmStreamSource(fileStream);

                // We'll keep the whole thing so we can iterate over it multiple times
                var src = (from osmGeo in xmlSrc select osmGeo).ToComplete();

                // Iterate through the file to get all the agencies
                // Other things will be added later
                foreach (var obj in src)
                {
                    if (obj.Tags != null)
                    {
                        // Get agencies
                        // Routes are added within each agency
                        if (obj.Type == OsmGeoType.Relation && obj.Tags.Contains("type", "network"))
                        {
                            agencies.Add((CompleteRelation)obj);
                        }

                        // Get stops
                        else if (obj.Type != OsmGeoType.Relation && obj.Tags.Contains("public_transport", "platform"))
                        {
                            stops.Add(obj);
                        }
                    }
                }

                Console.WriteLine("");

                // Now make the agency file
                Console.WriteLine("Found " + agencies.Count + " agency(ies).");
                Console.WriteLine("Writing agency.txt...");
                AgencyFile.Create(agencies, routes);
                Console.WriteLine("Done.");

                Console.WriteLine("");

                // Now make the stops file
                Console.WriteLine("Found " + stops.Count + " stop(s).");
                Console.WriteLine("Writing stops.txt...");
                StopFile.Create(stops);
                Console.WriteLine("Done.");

                Console.WriteLine("");

                // Now make the routes file
                Console.WriteLine("Found " + routes.Count + " route(s).");
                Console.WriteLine("Writing routes.txt...");
                RoutesFile.Create(routes.Values);
                Console.WriteLine("Done.");

                Console.WriteLine("");

                // Now make the trips file
                Console.WriteLine("Writing trips.txt by merging existing files...");
                TripsFile.Create();
                Console.WriteLine("Done.");

                Console.WriteLine("");

                // Now make the times file
                Console.WriteLine("Writing stop_times.txt by merging existing files...");
                TimesFile.Create();
                Console.WriteLine("Done.");

                Console.WriteLine("");

                // Now make the trips file
                Console.WriteLine("Writing shapes.txt by merging existing files...");
                ShapesFile.Create();
                Console.WriteLine("Done.");

                Console.WriteLine("");

                // Now the calendar files
                Console.WriteLine("Writing calendar.txt and calendar_dates.txt...");
                CalendarFile.Create();
                Console.WriteLine("Done.");
            }
        }