Example #1
0
        public TsCountry(TsMapper mapper, string path)
        {
            _mapper = mapper;
            var file = _mapper.Rfs.GetFileEntry(path);

            if (file == null)
            {
                return;
            }
            LocalizedNames = new Dictionary <string, string>();
            var fileContent = file.Entry.Read();

            var lines = Encoding.UTF8.GetString(fileContent).Split('\n');

            foreach (var line in lines)
            {
                var(validLine, key, value) = SiiHelper.ParseLine(line);
                if (!validLine)
                {
                    continue;
                }

                if (key == "country_data")
                {
                    Token = ScsHash.StringToToken(SiiHelper.Trim(value.Split('.')[2]));
                }
                else if (key == "country_id")
                {
                    CountryId = int.Parse(value);
                }
                else if (key == "name")
                {
                    Name = value.Split('"')[1];
                }
                else if (key == "name_localized")
                {
                    LocalizationToken = value.Split('"')[1];
                    LocalizationToken = LocalizationToken.Replace("@", "");
                }
                else if (key == "country_code")
                {
                    CountryCode = value.Split('"')[1];
                }
                else if (key == "pos")
                {
                    var vector = value.Split('(')[1].Split(')')[0];
                    var values = vector.Split(',');
                    X = float.Parse(values[0], CultureInfo.InvariantCulture);
                    Y = float.Parse(values[2], CultureInfo.InvariantCulture);
                }
            }
        }
Example #2
0
        public TsCity(TsMapper mapper, string path)
        {
            _mapper = mapper;
            var file = _mapper.Rfs.GetFileEntry(path);

            if (file == null)
            {
                return;
            }
            LocalizedNames = new Dictionary <string, string>();
            var fileContent = file.Entry.Read();

            var lines       = Encoding.UTF8.GetString(fileContent).Split('\n');
            var offsetCount = 0;

            XOffsets = new List <int>();
            YOffsets = new List <int>();

            foreach (var line in lines)
            {
                var(validLine, key, value) = SiiHelper.ParseLine(line);
                if (!validLine)
                {
                    continue;
                }

                if (key == "city_data")
                {
                    Token = ScsHash.StringToToken(SiiHelper.Trim(value.Split('.')[1]));
                }
                else if (key == "city_name")
                {
                    Name = line.Split('"')[1];
                }
                else if (key == "city_name_localized")
                {
                    LocalizationToken = value.Split('"')[1];
                    LocalizationToken = LocalizationToken.Replace("@", "");
                }
                else if (key == "country")
                {
                    Country = value;
                }
                else if (key.Contains("map_x_offsets[]"))
                {
                    if (++offsetCount > 4)
                    {
                        if (int.TryParse(value, out var offset))
                        {
                            XOffsets.Add(offset);
                        }
                    }
                    if (offsetCount == 8)
                    {
                        offsetCount = 0;
                    }
                }
                else if (key.Contains("map_y_offsets[]"))
                {
                    if (++offsetCount > 4)
                    {
                        if (int.TryParse(value, out var offset))
                        {
                            YOffsets.Add(offset);
                        }
                    }
                }
            }
        }
Example #3
0
        private void ParseOverlays() // TODO: Fix Road overlays and company (road_quarry & quarry) from interfering (or however you spell that)
        {
            var uiMapDirectory = Rfs.GetDirectory("material/ui/map");

            if (uiMapDirectory == null)
            {
                Log.Msg("Could not read 'material/ui/map' dir");
                return;
            }

            var matFiles = uiMapDirectory.GetFiles(".mat");

            if (matFiles == null)
            {
                Log.Msg("Could not read .mat files");
                return;
            }

            var uiCompanyDirectory = Rfs.GetDirectory("material/ui/company/small");

            if (uiCompanyDirectory != null)
            {
                var data = uiCompanyDirectory.GetFiles(".mat");
                if (data != null)
                {
                    matFiles.AddRange(data);
                }
            }
            else
            {
                Log.Msg("Could not read 'material/ui/company/small' dir");
            }

            var uiMapRoadDirectory = Rfs.GetDirectory("material/ui/map/road");

            if (uiMapRoadDirectory != null)
            {
                var data = uiMapRoadDirectory.GetFiles(".mat");
                if (data != null)
                {
                    matFiles.AddRange(data);
                }
            }
            else
            {
                Log.Msg("Could not read 'material/ui/map/road' dir");
            }

            foreach (var matFile in matFiles)
            {
                var data  = matFile.Entry.Read();
                var lines = Encoding.UTF8.GetString(data).Split('\n');

                foreach (var line in lines)
                {
                    var(validLine, key, value) = SiiHelper.ParseLine(line);
                    if (!validLine)
                    {
                        continue;
                    }
                    if (key == "texture")
                    {
                        var tobjPath = Helper.CombinePath(matFile.GetLocalPath(), value.Split('"')[1]);

                        var tobjData = Rfs.GetFileEntry(tobjPath)?.Entry?.Read();

                        if (tobjData == null)
                        {
                            break;
                        }

                        var path = Helper.GetFilePath(Encoding.UTF8.GetString(tobjData, 0x30, tobjData.Length - 0x30));

                        var name = matFile.GetFileName();
                        if (name.StartsWith("map"))
                        {
                            continue;
                        }
                        if (name.StartsWith("road_"))
                        {
                            name = name.Substring(5);
                        }

                        var token = ScsHash.StringToToken(name);
                        if (!_overlayLookup.ContainsKey(token))
                        {
                            _overlayLookup.Add(token, new TsMapOverlay(this, path));
                        }
                    }
                }
            }
        }
Example #4
0
        private void ParseFerryConnections()
        {
            var connectionDirectory = Rfs.GetDirectory("def/ferry/connection");

            if (connectionDirectory == null)
            {
                Log.Msg("Could not read 'def/ferry/connection' dir");
                return;
            }

            var ferryConnectionFiles = connectionDirectory.GetFiles("sii");

            if (ferryConnectionFiles == null)
            {
                Log.Msg("Could not read ferry connection files files");
                return;
            }

            foreach (var ferryConnectionFile in ferryConnectionFiles)
            {
                var data  = ferryConnectionFile.Entry.Read();
                var lines = Encoding.UTF8.GetString(data).Split('\n');

                TsFerryConnection conn = null;

                foreach (var line in lines)
                {
                    var(validLine, key, value) = SiiHelper.ParseLine(line);
                    if (validLine)
                    {
                        if (conn != null)
                        {
                            if (key.Contains("connection_positions"))
                            {
                                var index  = int.Parse(key.Split('[')[1].Split(']')[0]);
                                var vector = value.Split('(')[1].Split(')')[0];
                                var values = vector.Split(',');
                                var x      = float.Parse(values[0], CultureInfo.InvariantCulture);
                                var z      = float.Parse(values[2], CultureInfo.InvariantCulture);
                                conn.AddConnectionPosition(index, x, z);
                            }
                            else if (key.Contains("connection_directions"))
                            {
                                var index  = int.Parse(key.Split('[')[1].Split(']')[0]);
                                var vector = value.Split('(')[1].Split(')')[0];
                                var values = vector.Split(',');
                                var x      = float.Parse(values[0], CultureInfo.InvariantCulture);
                                var z      = float.Parse(values[2], CultureInfo.InvariantCulture);
                                conn.AddRotation(index, Math.Atan2(z, x));
                            }
                        }

                        if (key == "ferry_connection")
                        {
                            var portIds = value.Split('.');
                            conn = new TsFerryConnection
                            {
                                StartPortToken = ScsHash.StringToToken(portIds[1]),
                                EndPortToken   = ScsHash.StringToToken(portIds[2].TrimEnd('{').Trim())
                            };
                        }
                    }

                    if (!line.Contains("}") || conn == null)
                    {
                        continue;
                    }
                    ;

                    var existingItem = _ferryConnectionLookup.FirstOrDefault(item =>
                                                                             (item.StartPortToken == conn.StartPortToken && item.EndPortToken == conn.EndPortToken) ||
                                                                             (item.StartPortToken == conn.EndPortToken && item.EndPortToken == conn.StartPortToken)); // Check if connection already exists
                    if (existingItem == null)
                    {
                        _ferryConnectionLookup.Add(conn);
                    }
                    conn = null;
                }
            }
        }
Example #5
0
        private void ParseRoadLookFiles()
        {
            var worldDirectory = Rfs.GetDirectory("def/world");

            if (worldDirectory == null)
            {
                Log.Msg("Could not read 'def/world' dir");
                return;
            }

            var roadLookFiles = worldDirectory.GetFiles("road_look");

            if (roadLookFiles == null)
            {
                Log.Msg("Could not read road look files");
                return;
            }

            foreach (var roadLookFile in roadLookFiles)
            {
                if (!roadLookFile.GetFileName().StartsWith("road"))
                {
                    continue;
                }
                var        data     = roadLookFile.Entry.Read();
                var        lines    = Encoding.UTF8.GetString(data).Split('\n');
                TsRoadLook roadLook = null;

                foreach (var line in lines)
                {
                    var(validLine, key, value) = SiiHelper.ParseLine(line);
                    if (validLine)
                    {
                        if (key == "road_look")
                        {
                            roadLook = new TsRoadLook(ScsHash.StringToToken(SiiHelper.Trim(value.Split('.')[1].Trim('{'))));
                        }
                        if (roadLook == null)
                        {
                            continue;
                        }
                        if (key == "lanes_left[]")
                        {
                            roadLook.LanesLeft.Add(value);
                        }
                        else if (key == "lanes_right[]")
                        {
                            roadLook.LanesRight.Add(value);
                        }
                        else if (key == "road_offset")
                        {
                            roadLook.Offset = float.Parse(value, CultureInfo.InvariantCulture);
                        }
                    }

                    if (line.Contains("}") && roadLook != null)
                    {
                        if (roadLook.Token != 0 && !_roadLookup.ContainsKey(roadLook.Token))
                        {
                            _roadLookup.Add(roadLook.Token, roadLook);
                            roadLook = null;
                        }
                    }
                }
            }
        }
Example #6
0
        private void ParsePrefabFiles()
        {
            var worldDirectory = Rfs.GetDirectory("def/world");

            if (worldDirectory == null)
            {
                Log.Msg("Could not read 'def/world' dir");
                return;
            }

            var prefabFiles = worldDirectory.GetFiles("prefab");

            if (prefabFiles == null)
            {
                Log.Msg("Could not read prefab files");
                return;
            }

            foreach (var prefabFile in prefabFiles)
            {
                if (!prefabFile.GetFileName().StartsWith("prefab"))
                {
                    continue;
                }
                var data  = prefabFile.Entry.Read();
                var lines = Encoding.UTF8.GetString(data).Split('\n');

                var token    = 0UL;
                var path     = "";
                var category = "";
                foreach (var line in lines)
                {
                    var(validLine, key, value) = SiiHelper.ParseLine(line);
                    if (validLine)
                    {
                        if (key == "prefab_model")
                        {
                            token = ScsHash.StringToToken(SiiHelper.Trim(value.Split('.')[1]));
                        }
                        else if (key == "prefab_desc")
                        {
                            path = Helper.GetFilePath(value.Split('"')[1]);
                        }
                        else if (key == "category")
                        {
                            category = value.Split('"')[1];
                        }
                    }

                    if (line.Contains("}") && token != 0 && path != "")
                    {
                        var prefab = new TsPrefab(this, path, token, category);
                        if (prefab.Token != 0 && !_prefabLookup.ContainsKey(prefab.Token))
                        {
                            _prefabLookup.Add(prefab.Token, prefab);
                        }

                        token    = 0;
                        path     = "";
                        category = "";
                    }
                }
            }
        }