private void LoadLUT() { // PREFABS var sii = LUTFolder + "-prefab.sii"; var csv = LUTFolder + "-prefab.csv"; Dictionary <string, string> prefab2file = new Dictionary <string, string>(); Dictionary <int, string> idx2prefab = new Dictionary <int, string>(); var csvLines = File.ReadAllLines(csv); foreach (var k in csvLines) { var d = k.Split(",".ToCharArray()); int idx; if (int.TryParse(d[2], NumberStyles.HexNumber, null, out idx)) { if (idx2prefab.ContainsKey(idx) == false) { idx2prefab.Add(idx, d[1]); } } } var siiLines = File.ReadAllLines(sii); var prefab = string.Empty; var file = string.Empty; foreach (var k in siiLines) { if (k.Trim() == "}") { if (prefab != string.Empty && file != string.Empty) { prefab2file.Add(prefab, file); } prefab = string.Empty; file = string.Empty; } if (k.StartsWith("prefab_model")) { var d = k.Split(":".ToCharArray()).Select(x => x.Trim()).ToArray(); if (d[1].Length > 3) { prefab = d[1].Substring(0, d[1].Length - 1).Trim(); } } if (k.Contains("prefab_desc")) { var d = k.Split("\"".ToCharArray()); file = d[1].Trim(); } } // Link all prefabs foreach (var id2fab in idx2prefab) { if (prefab2file.ContainsKey(id2fab.Value)) { var f = prefab2file[id2fab.Value]; var obj = PrefabsLookup.FirstOrDefault(x => x.IsFile(f)); if (obj != null) { obj.IDX = id2fab.Key; obj.IDSII = id2fab.Value; PrefabLookup.Add(id2fab.Key, obj); } } } // COMPANIES CompaniesLookup = File.ReadAllLines(LUTFolder + "-companies.csv").Select(x => new Ets2Company(x, this)).ToList(); // CITIES CitiesLookup = File.ReadAllLines(LUTFolder + "-cities.csv").Select(x => { var d = x.Split(",".ToCharArray()); var id = ulong.Parse(d[0], NumberStyles.HexNumber); var city = d[1]; return(new KeyValuePair <ulong, string>(id, city)); }).ToDictionary(x => x.Key, x => x.Value); // ROAD LOOKS RoadLookup = File.ReadAllLines(LUTFolder + "-roads.csv").Select(x => { var d = x.Split(",".ToCharArray()); var id = uint.Parse(d[0], NumberStyles.HexNumber); var look = d[1]; var lookObj = new Ets2RoadLook(look, this); return(new KeyValuePair <uint, Ets2RoadLook>(id, lookObj)); }).ToDictionary(x => x.Key, x => x.Value); }
private void LoadLUT() { // PREFABS var sii = LUTFolder + "-prefab.sii"; var csv = LUTFolder + "-prefab.csv"; Dictionary<string, string> prefab2file = new Dictionary<string, string>(); Dictionary<int, string> idx2prefab = new Dictionary<int, string>(); var csvLines = File.ReadAllLines(csv); foreach (var k in csvLines) { var d = k.Split(",".ToCharArray()); int idx; if (int.TryParse(d[2], NumberStyles.HexNumber, null, out idx)) { if (idx2prefab.ContainsKey(idx) == false) idx2prefab.Add(idx, d[1]); } } var siiLines = File.ReadAllLines(sii); var prefab = string.Empty; var file = string.Empty; foreach (var k in siiLines) { if (k.Trim() == "}") { if (prefab != string.Empty && file != string.Empty) { prefab2file.Add(prefab, file); } prefab = string.Empty; file = string.Empty; } if (k.StartsWith("prefab_model")) { var d = k.Split(":".ToCharArray()).Select(x => x.Trim()).ToArray(); if (d[1].Length > 3) { prefab = d[1].Substring(0, d[1].Length - 1).Trim(); } } if (k.Contains("prefab_desc")) { var d = k.Split("\"".ToCharArray()); file = d[1].Trim(); } } // Link all prefabs foreach (var id2fab in idx2prefab) { if (prefab2file.ContainsKey(id2fab.Value)) { var f = prefab2file[id2fab.Value]; var obj = PrefabsLookup.FirstOrDefault(x => x.IsFile(f)); if (obj != null) { obj.IDX = id2fab.Key; obj.IDSII = id2fab.Value; PrefabLookup.Add(id2fab.Key, obj); } } } // COMPANIES CompaniesLookup = File.ReadAllLines(LUTFolder + "-companies.csv").Select(x => new Ets2Company(x, this)).ToList(); // CITIES CitiesLookup = File.ReadAllLines(LUTFolder + "-cities.csv").Select(x => { var d = x.Split(",".ToCharArray()); var id = ulong.Parse(d[0], NumberStyles.HexNumber); var city = d[1]; return new KeyValuePair<ulong, string>(id, city); }).ToDictionary(x => x.Key, x => x.Value); // ROAD LOOKS RoadLookup = File.ReadAllLines(LUTFolder + "-roads.csv").Select(x => { var d = x.Split(",".ToCharArray()); var id = uint.Parse(d[0], NumberStyles.HexNumber); var look = d[1]; var lookObj = new Ets2RoadLook(look,this); return new KeyValuePair<uint, Ets2RoadLook>(id, lookObj); }).ToDictionary(x => x.Key, x => x.Value); }