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); } } }
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); } } } } }
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; } } } } }
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 = ""; } } } }