/// <summary>Loads and parses the map.ini from the current map path.</summary> private void LoadMapData() { if (m_filePath == "") return; if (!File.Exists(m_filePath + Program.MapIniFile)) { Debug.WriteLine("WARNING: map ini does not exist"); return; } try { //Why have the overhead of getprivateprofile when we can just do it ourself? m_lastLoad = m_filePath + Program.MapIniFile; FileStream stream = File.OpenRead(m_lastLoad); StreamReader reader = new StreamReader(stream); string line = ""; string subline = ""; string[] parts; string[] subparts; int zoneid; int mapid; int linenumber = 0; int idx = 0; FFXIZoneMaps zonemaps = null; FFXIImageMap map = null; while ((line = reader.ReadLine()) != null) { linenumber++; try { if (line.Length == 0 || line[0] == ';' || line[0] == '[') //only care about the data continue; //parse the key/value pair of the ini line parts = line.Split('='); if (parts.Length != 2) continue; //parse the zone/map pair subparts = parts[0].Split('_'); if (subparts.Length != 2) continue; zoneid = System.Convert.ToInt16(subparts[0], 16); if (!int.TryParse(subparts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out mapid)) continue; //parse the calc and range data subline = parts[1]; idx = subline.IndexOf(';'); if (idx > -1) subline = subline.Substring(0, idx); //kill comments following the data area subline = subline.Trim(); subparts = subline.Split(','); if (subparts.Length == 0 || ((subparts.Length - 4) % 6 != 0)) //ranges are specified in vector pairs continue; //get the zone object if (zonemaps == null || zonemaps.ZoneID != zoneid) { if (!m_zones.ContainsKey(zoneid)) { zonemaps = new FFXIZoneMaps(this, zoneid); m_zones.Add(zoneid, zonemaps); } else { zonemaps = m_zones[zoneid]; } } if (zonemaps.ContainsKey(mapid)) //only process the same zone/map combo once continue; //create the map object map = new FFXIImageMap(zonemaps, mapid, float.Parse(subparts[0], CultureInfo.InvariantCulture), float.Parse(subparts[1], CultureInfo.InvariantCulture), float.Parse(subparts[2], CultureInfo.InvariantCulture), float.Parse(subparts[3], CultureInfo.InvariantCulture) ); //add each range of values int i = 4; while (i < subparts.Length) { map.addRange( float.Parse(subparts[i], CultureInfo.InvariantCulture), //X1 float.Parse(subparts[i + 2], CultureInfo.InvariantCulture), //Y1 Y/Z swapped to standard vertex order. float.Parse(subparts[i + 1], CultureInfo.InvariantCulture), //Z1 Why must we perpetuate bad coordinate ordering? float.Parse(subparts[i + 3], CultureInfo.InvariantCulture), //X2 float.Parse(subparts[i + 5], CultureInfo.InvariantCulture), //Y2 Y/Z swapped here too. float.Parse(subparts[i + 4], CultureInfo.InvariantCulture) //Z2 ); i += 6; } zonemaps.Add(map); } catch (Exception ex) { Debug.WriteLine("error reading line " + linenumber + ": " + ex.Message); } } reader.Close(); } catch (Exception ex) { Debug.WriteLine("LoadMapData ERROR: " + ex.Message); } }
public FFXIImageMap(FFXIZoneMaps parent, int mapid, float xScale, float xOffset, float yScale, float yOffset) { m_parent = parent; ranges = new List<FFXIImageMapRange>(); m_mapid = mapid; m_xScale = xScale; m_xOffset = xOffset; m_yScale = yScale; m_yOffset = yOffset; }