/// <summary> /// Loads map information from a TS/RA2 map INI file. /// Returns true if succesful, otherwise false. /// </summary> /// <param name="path">The full path to the map INI file.</param> public bool SetInfoFromMap(string path) { if (!File.Exists(path)) { return(false); } try { IniFile iniFile = new IniFile(); iniFile.FileName = path; iniFile.AddSection("Basic"); iniFile.AddSection("Map"); iniFile.AddSection("Waypoints"); iniFile.AddSection("Preview"); iniFile.AddSection("PreviewPack"); iniFile.AddSection("ForcedOptions"); iniFile.AddSection("ForcedSpawnIniOptions"); iniFile.AllowNewSections = false; iniFile.Parse(); mapIni = iniFile; var basicSection = iniFile.GetSection("Basic"); Name = basicSection.GetStringValue("Name", "Unnamed map"); Author = basicSection.GetStringValue("Author", "Unknown author"); string gameModesString = basicSection.GetStringValue("GameModes", string.Empty); if (string.IsNullOrEmpty(gameModesString)) { gameModesString = basicSection.GetStringValue("GameMode", "Default"); } GameModes = gameModesString.Split(','); if (GameModes.Length == 0) { Logger.Log("Custom map " + path + " has no game modes!"); return(false); } for (int i = 0; i < GameModes.Length; i++) { string gameMode = GameModes[i].Trim(); GameModes[i] = gameMode.Substring(0, 1).ToUpperInvariant() + gameMode.Substring(1); } MinPlayers = 0; if (basicSection.KeyExists("ClientMaxPlayer")) { MaxPlayers = basicSection.GetIntValue("ClientMaxPlayer", 0); } else { MaxPlayers = basicSection.GetIntValue("MaxPlayer", 0); } EnforceMaxPlayers = basicSection.GetBooleanValue("EnforceMaxPlayers", true); //PreviewPath = Path.GetDirectoryName(BaseFilePath) + "/" + // iniFile.GetStringValue(BaseFilePath, "PreviewImage", Path.GetFileNameWithoutExtension(BaseFilePath) + ".png"); Briefing = basicSection.GetStringValue("Briefing", string.Empty).Replace("@", Environment.NewLine); SHA1 = Utilities.CalculateSHA1ForFile(path); IsCoop = basicSection.GetBooleanValue("IsCoopMission", false); Credits = basicSection.GetIntValue("Credits", -1); UnitCount = basicSection.GetIntValue("UnitCount", -1); NeutralHouseColor = basicSection.GetIntValue("NeutralColor", -1); SpecialHouseColor = basicSection.GetIntValue("SpecialColor", -1); HumanPlayersOnly = basicSection.GetBooleanValue("HumanPlayersOnly", false); ForceRandomStartLocations = basicSection.GetBooleanValue("ForceRandomStartLocations", false); ForceNoTeams = basicSection.GetBooleanValue("ForceNoTeams", false); PreviewPath = Path.ChangeExtension(path.Substring(ProgramConstants.GamePath.Length), ".png"); MultiplayerOnly = basicSection.GetBooleanValue("ClientMultiplayerOnly", false); string bases = basicSection.GetStringValue("Bases", string.Empty); if (!string.IsNullOrEmpty(bases)) { Bases = Convert.ToInt32(Conversions.BooleanFromString(bases, false)); } if (IsCoop) { CoopInfo = new CoopMapInfo(); string[] disallowedSides = iniFile.GetStringValue("Basic", "DisallowedPlayerSides", string.Empty).Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string sideIndex in disallowedSides) { CoopInfo.DisallowedPlayerSides.Add(int.Parse(sideIndex)); } string[] disallowedColors = iniFile.GetStringValue("Basic", "DisallowedPlayerColors", string.Empty).Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string colorIndex in disallowedColors) { CoopInfo.DisallowedPlayerColors.Add(int.Parse(colorIndex)); } CoopInfo.SetHouseInfos(basicSection); } localSize = iniFile.GetStringValue("Map", "LocalSize", "0,0,0,0").Split(','); actualSize = iniFile.GetStringValue("Map", "Size", "0,0,0,0").Split(','); for (int i = 0; i < MAX_PLAYERS; i++) { string waypoint = mapIni.GetStringValue("Waypoints", i.ToString(), string.Empty); if (string.IsNullOrEmpty(waypoint)) { break; } waypoints.Add(waypoint); } ParseForcedOptions(iniFile, "ForcedOptions"); ParseSpawnIniOptions(iniFile, "ForcedSpawnIniOptions"); return(true); } catch { Logger.Log("Loading custom map " + path + " failed!"); return(false); } }
/// <summary> /// Loads map information from a TS/RA2 map INI file. /// Returns true if succesful, otherwise false. /// </summary> /// <param name="path">The full path to the map INI file.</param> public bool SetInfoFromMap(string path) { try { IniFile iniFile = new IniFile(); iniFile.FileName = path; iniFile.AddSection("Basic"); iniFile.AddSection("Map"); iniFile.AddSection("Waypoints"); iniFile.AddSection("Preview"); iniFile.AddSection("PreviewPack"); iniFile.AllowNewSections = false; iniFile.Parse(); mapIni = iniFile; Name = iniFile.GetStringValue("Basic", "Name", "Unnamed map"); Author = iniFile.GetStringValue("Basic", "Author", "Unknown author"); GameModes = iniFile.GetStringValue("Basic", "GameMode", "Default").Split(','); for (int i = 0; i < GameModes.Length; i++) { string gameMode = GameModes[i].Trim(); gameMode = gameMode.Substring(0, 1).ToUpperInvariant() + gameMode.Substring(1); GameModes[i] = gameMode; } MinPlayers = 0; MaxPlayers = iniFile.GetIntValue("Basic", "MaxPlayer", 0); EnforceMaxPlayers = iniFile.GetBooleanValue("Basic", "EnforceMaxPlayers", true); //PreviewPath = Path.GetDirectoryName(BaseFilePath) + "\\" + // iniFile.GetStringValue(BaseFilePath, "PreviewImage", Path.GetFileNameWithoutExtension(BaseFilePath) + ".png"); Briefing = iniFile.GetStringValue("Basic", "Briefing", string.Empty).Replace("@", Environment.NewLine); SHA1 = Utilities.CalculateSHA1ForFile(path); IsCoop = iniFile.GetBooleanValue("Basic", "IsCoopMission", false); Credits = iniFile.GetIntValue("Basic", "Credits", -1); UnitCount = iniFile.GetIntValue("Basic", "UnitCount", -1); NeutralHouseColor = iniFile.GetIntValue("Basic", "NeutralColor", -1); SpecialHouseColor = iniFile.GetIntValue("Basic", "SpecialColor", -1); PreviewPath = Path.ChangeExtension(path.Substring(ProgramConstants.GamePath.Length + 1), ".png"); string bases = iniFile.GetStringValue("Basic", "Bases", string.Empty); if (!string.IsNullOrEmpty(bases)) { Bases = Convert.ToInt32(Conversions.BooleanFromString(bases, false)); } if (IsCoop) { CoopInfo = new CoopMapInfo(); string[] disallowedSides = iniFile.GetStringValue("Basic", "DisallowedPlayerSides", string.Empty).Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string sideIndex in disallowedSides) { CoopInfo.DisallowedPlayerSides.Add(Int32.Parse(sideIndex)); } string[] disallowedColors = iniFile.GetStringValue("Basic", "DisallowedPlayerColors", string.Empty).Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string colorIndex in disallowedColors) { CoopInfo.DisallowedPlayerColors.Add(Int32.Parse(colorIndex)); } CoopInfo.SetHouseInfos(iniFile, "Basic"); } localSize = iniFile.GetStringValue("Map", "LocalSize", "0,0,0,0").Split(','); actualSize = iniFile.GetStringValue("Map", "Size", "0,0,0,0").Split(','); RefreshStartingLocationPositions(); //string forcedOptionsSection = iniFile.GetStringValue("Basic", "ForcedOptions", String.Empty); //if (!string.IsNullOrEmpty(forcedOptionsSection)) //{ // string[] sections = forcedOptionsSection.Split(','); // foreach (string section in sections) // ParseForcedOptions(iniFile, section); //} //string forcedSpawnIniOptionsSection = iniFile.GetStringValue("Basic", "ForcedSpawnIniOptions", String.Empty); //if (!string.IsNullOrEmpty(forcedSpawnIniOptionsSection)) //{ // string[] sections = forcedSpawnIniOptionsSection.Split(','); // foreach (string section in sections) // ParseSpawnIniOptions(iniFile, section); //} return(true); } catch { Logger.Log("Loading custom map " + path + " failed!"); return(false); } }
public bool SetInfoFromINI(IniFile iniFile) { try { string baseSectionName = iniFile.GetStringValue(BaseFilePath, "BaseSection", string.Empty); if (!string.IsNullOrEmpty(baseSectionName)) { iniFile.CombineSections(baseSectionName, BaseFilePath); } var section = iniFile.GetSection(BaseFilePath); Name = section.GetStringValue("Description", "Unnamed map"); Author = section.GetStringValue("Author", "Unknown author"); GameModes = section.GetStringValue("GameModes", "Default").Split(','); MinPlayers = section.GetIntValue("MinPlayers", 0); MaxPlayers = section.GetIntValue("MaxPlayers", 0); EnforceMaxPlayers = section.GetBooleanValue("EnforceMaxPlayers", false); PreviewPath = Path.GetDirectoryName(BaseFilePath) + "/" + section.GetStringValue("PreviewImage", Path.GetFileNameWithoutExtension(BaseFilePath) + ".png"); Briefing = section.GetStringValue("Briefing", string.Empty).Replace("@", Environment.NewLine); SHA1 = Utilities.CalculateSHA1ForFile(CompleteFilePath); IsCoop = section.GetBooleanValue("IsCoopMission", false); Credits = section.GetIntValue("Credits", -1); UnitCount = section.GetIntValue("UnitCount", -1); NeutralHouseColor = section.GetIntValue("NeutralColor", -1); SpecialHouseColor = section.GetIntValue("SpecialColor", -1); MultiplayerOnly = section.GetBooleanValue("MultiplayerOnly", false); HumanPlayersOnly = section.GetBooleanValue("HumanPlayersOnly", false); ForceRandomStartLocations = section.GetBooleanValue("ForceRandomStartLocations", false); ForceNoTeams = section.GetBooleanValue("ForceNoTeams", false); ExtraININame = section.GetStringValue("ExtraININame", string.Empty); string bases = section.GetStringValue("Bases", string.Empty); if (!string.IsNullOrEmpty(bases)) { Bases = Convert.ToInt32(Conversions.BooleanFromString(bases, false)); } if (IsCoop) { CoopInfo = new CoopMapInfo(); string[] disallowedSides = section.GetStringValue("DisallowedPlayerSides", string.Empty).Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string sideIndex in disallowedSides) { CoopInfo.DisallowedPlayerSides.Add(int.Parse(sideIndex)); } string[] disallowedColors = section.GetStringValue("DisallowedPlayerColors", string.Empty).Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string colorIndex in disallowedColors) { CoopInfo.DisallowedPlayerColors.Add(int.Parse(colorIndex)); } CoopInfo.SetHouseInfos(section); } localSize = section.GetStringValue("LocalSize", "0,0,0,0").Split(','); actualSize = section.GetStringValue("Size", "0,0,0,0").Split(','); for (int i = 0; i < MAX_PLAYERS; i++) { string waypoint = section.GetStringValue("Waypoint" + i, string.Empty); if (String.IsNullOrEmpty(waypoint)) { break; } waypoints.Add(waypoint); } #if !WINDOWSGL if (UserINISettings.Instance.PreloadMapPreviews) { PreviewTexture = LoadPreviewTexture(); } #endif // Parse forced options string forcedOptionsSections = iniFile.GetStringValue(BaseFilePath, "ForcedOptions", string.Empty); if (!string.IsNullOrEmpty(forcedOptionsSections)) { string[] sections = forcedOptionsSections.Split(','); foreach (string foSection in sections) { ParseForcedOptions(iniFile, foSection); } } string forcedSpawnIniOptionsSections = iniFile.GetStringValue(BaseFilePath, "ForcedSpawnIniOptions", string.Empty); if (!string.IsNullOrEmpty(forcedSpawnIniOptionsSections)) { string[] sections = forcedSpawnIniOptionsSections.Split(','); foreach (string fsioSection in sections) { ParseSpawnIniOptions(iniFile, fsioSection); } } return(true); } catch (Exception ex) { Logger.Log("Setting info for " + BaseFilePath + " failed! Reason: " + ex.Message); return(false); } }
/// <summary> /// This is used to load a map from the MPMaps.ini (default name) file. /// </summary> /// <param name="iniFile"></param> /// <returns></returns> public bool SetInfoFromMpMapsINI(IniFile iniFile) { try { string baseSectionName = iniFile.GetStringValue(BaseFilePath, "BaseSection", string.Empty); if (!string.IsNullOrEmpty(baseSectionName)) { iniFile.CombineSections(baseSectionName, BaseFilePath); } var section = iniFile.GetSection(BaseFilePath); Name = section.GetStringValue("Description", "Unnamed map"); Author = section.GetStringValue("Author", "Unknown author"); GameModes = section.GetStringValue("GameModes", "Default").Split(','); MinPlayers = section.GetIntValue("MinPlayers", 0); MaxPlayers = section.GetIntValue("MaxPlayers", 0); EnforceMaxPlayers = section.GetBooleanValue("EnforceMaxPlayers", false); PreviewPath = Path.GetDirectoryName(BaseFilePath) + "/" + section.GetStringValue("PreviewImage", Path.GetFileNameWithoutExtension(BaseFilePath) + ".png"); Briefing = section.GetStringValue("Briefing", string.Empty).Replace("@", Environment.NewLine); CalculateSHA(); IsCoop = section.GetBooleanValue("IsCoopMission", false); Credits = section.GetIntValue("Credits", -1); UnitCount = section.GetIntValue("UnitCount", -1); NeutralHouseColor = section.GetIntValue("NeutralColor", -1); SpecialHouseColor = section.GetIntValue("SpecialColor", -1); MultiplayerOnly = section.GetBooleanValue("MultiplayerOnly", false); HumanPlayersOnly = section.GetBooleanValue("HumanPlayersOnly", false); ForceRandomStartLocations = section.GetBooleanValue("ForceRandomStartLocations", false); ForceNoTeams = section.GetBooleanValue("ForceNoTeams", false); ExtraININame = section.GetStringValue("ExtraININame", string.Empty); string bases = section.GetStringValue("Bases", string.Empty); if (!string.IsNullOrEmpty(bases)) { Bases = Convert.ToInt32(Conversions.BooleanFromString(bases, false)); } int i = 0; while (true) { // Format example: // ExtraTexture0=oilderrick.png,200,150,1 // Last value is map cell level and is optional, defaults to 0 if unspecified. string value = section.GetStringValue("ExtraTexture" + i, null); if (string.IsNullOrWhiteSpace(value)) { break; } string[] parts = value.Split(','); if (parts.Length < 3 || parts.Length > 4) { Logger.Log($"Invalid format for ExtraTexture{i} in map " + BaseFilePath); continue; } bool success = int.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out int x); success &= int.TryParse(parts[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out int y); int level = 0; if (parts.Length > 3) { int.TryParse(parts[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out level); } extraTextures.Add(new ExtraMapPreviewTexture(parts[0], new Point(x, y), level)); i++; } if (IsCoop) { CoopInfo = new CoopMapInfo(); string[] disallowedSides = section.GetStringValue("DisallowedPlayerSides", string.Empty).Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string sideIndex in disallowedSides) { CoopInfo.DisallowedPlayerSides.Add(int.Parse(sideIndex)); } string[] disallowedColors = section.GetStringValue("DisallowedPlayerColors", string.Empty).Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string colorIndex in disallowedColors) { CoopInfo.DisallowedPlayerColors.Add(int.Parse(colorIndex)); } CoopInfo.SetHouseInfos(section); } localSize = section.GetStringValue("LocalSize", "0,0,0,0").Split(','); actualSize = section.GetStringValue("Size", "0,0,0,0").Split(','); for (i = 0; i < MAX_PLAYERS; i++) { string waypoint = section.GetStringValue("Waypoint" + i, string.Empty); if (String.IsNullOrEmpty(waypoint)) { break; } waypoints.Add(waypoint); } #if !WINDOWSGL if (UserINISettings.Instance.PreloadMapPreviews) { PreviewTexture = LoadPreviewTexture(); } #endif // Parse forced options string forcedOptionsSections = iniFile.GetStringValue(BaseFilePath, "ForcedOptions", string.Empty); if (!string.IsNullOrEmpty(forcedOptionsSections)) { string[] sections = forcedOptionsSections.Split(','); foreach (string foSection in sections) { ParseForcedOptions(iniFile, foSection); } } string forcedSpawnIniOptionsSections = iniFile.GetStringValue(BaseFilePath, "ForcedSpawnIniOptions", string.Empty); if (!string.IsNullOrEmpty(forcedSpawnIniOptionsSections)) { string[] sections = forcedSpawnIniOptionsSections.Split(','); foreach (string fsioSection in sections) { ParseSpawnIniOptions(iniFile, fsioSection); } } return(true); } catch (Exception ex) { Logger.Log("Setting info for " + BaseFilePath + " failed! Reason: " + ex.Message); return(false); } }