private void btnPublishMap_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(plugin.Map.BasicSection.Name))
            {
                plugin.Map.BasicSection.Name = titleTxt.Text;
            }

            if (string.IsNullOrEmpty(plugin.Map.BasicSection.Author))
            {
                plugin.Map.BasicSection.Author = SteamFriends.GetPersonaName();
            }

            plugin.Map.SteamSection.PreviewFile = previewTxt.Text;
            plugin.Map.SteamSection.Title       = titleTxt.Text;
            plugin.Map.SteamSection.Description = descriptionTxt.Text;
            plugin.Map.SteamSection.Visibility  = (ERemoteStoragePublishedFileVisibility)visibilityComboBox.SelectedValue;

            var tempPath = Path.Combine(Path.GetTempPath(), "CnCRCMapEditorPublishUGC");

            Directory.CreateDirectory(tempPath);
            foreach (var file in new DirectoryInfo(tempPath).EnumerateFiles())
            {
                file.Delete();
            }

            var pgmPath = Path.Combine(tempPath, "MAPDATA.PGM");

            plugin.Save(pgmPath, FileType.PGM);

            var tags = new List <string>();

            switch (plugin.GameType)
            {
            case GameType.TiberianDawn:
                tags.Add("TD");
                break;

            case GameType.RedAlert:
                tags.Add("RA");
                break;
            }

            if (plugin.Map.BasicSection.SoloMission)
            {
                tags.Add("SinglePlayer");
            }
            else
            {
                tags.Add("MultiPlayer");
            }

            if (SteamworksUGC.PublishUGC(tempPath, plugin.Map.SteamSection, tags, OnPublishSuccess, OnOperationFailed))
            {
                statusLbl.Text = SteamworksUGC.CurrentOperation.Status;
                EnableControls(false);
            }
        }
        static void Main()
        {
            // Change current culture to en-US
            if (Thread.CurrentThread.CurrentCulture.Name != "en-US")
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            }

            // Initialize megafiles
            var runPath = Environment.CurrentDirectory;

            Globals.TheMegafileManager = new MegafileManager(runPath);

            var megafilesLoaded = true;
            var megafilePath    = Path.Combine(runPath, "DATA");

            megafilesLoaded &= Globals.TheMegafileManager.Load(Path.Combine(megafilePath, "CONFIG.MEG"));
            megafilesLoaded &= Globals.TheMegafileManager.Load(Path.Combine(megafilePath, "TEXTURES_COMMON_SRGB.MEG"));
            megafilesLoaded &= Globals.TheMegafileManager.Load(Path.Combine(megafilePath, "TEXTURES_RA_SRGB.MEG"));
            megafilesLoaded &= Globals.TheMegafileManager.Load(Path.Combine(megafilePath, "TEXTURES_SRGB.MEG"));
            megafilesLoaded &= Globals.TheMegafileManager.Load(Path.Combine(megafilePath, "TEXTURES_TD_SRGB.MEG"));
#if !DEVELOPER
            if (!megafilesLoaded)
            {
                MessageBox.Show("Required data is missing or corrupt, please validate your installation.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
#endif

            // Initialize texture, tileset, team color, and game text managers
            Globals.TheTextureManager   = new TextureManager(Globals.TheMegafileManager);
            Globals.TheTilesetManager   = new TilesetManager(Globals.TheMegafileManager, Globals.TheTextureManager, Globals.TilesetsXMLPath, Globals.TexturesPath);
            Globals.TheTeamColorManager = new TeamColorManager(Globals.TheMegafileManager);

            var cultureName      = CultureInfo.CurrentUICulture.Name;
            var gameTextFilename = string.Format(Globals.GameTextFilenameFormat, cultureName.ToUpper());
            if (!Globals.TheMegafileManager.Exists(gameTextFilename))
            {
                gameTextFilename = string.Format(Globals.GameTextFilenameFormat, "EN-US");
            }
            Globals.TheGameTextManager = new GameTextManager(Globals.TheMegafileManager, gameTextFilename);

            // Initialize Steam if this is a Steam build
            if (SteamworksUGC.IsSteamBuild)
            {
                if (!SteamworksUGC.Init())
                {
#if !DEVELOPER
                    MessageBox.Show("Unable to initialize Steam interface.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
#endif
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (Properties.Settings.Default.ShowInviteWarning)
            {
                var inviteMessageBox = new InviteMessageBox();
                inviteMessageBox.ShowDialog();

                Properties.Settings.Default.ShowInviteWarning = !inviteMessageBox.DontShowAgain;
                Properties.Settings.Default.Save();
            }

            Application.Run(new MainForm());

            if (SteamworksUGC.IsSteamBuild)
            {
                SteamworksUGC.Shutdown();
            }

            Globals.TheMegafileManager.Dispose();
        }
Exemple #3
0
        public string LevelInfo()
        {
            GameManager game_manager = G.Sys.GameManager_;

            string    level_path = game_manager.LevelPath_;
            LevelInfo level_info = G.Sys.LevelSets_.GetLevelInfo(level_path);

            ProfileProgress progress = G.Sys.ProfileManager_.CurrentProfile_.Progress_;
            GameMode        mode     = G.Sys.GameManager_.Mode_;


            string out_result = "";


            int    best          = progress.GetTopResultWithRelativePath(level_info.relativePath_, mode.GameModeID_);
            string personal_best = Language.GetLine("levelinfo.personalbest.none");

            if (best != -1)
            {
                if (mode.ResultsDisplayType_ == ResultsDisplayType.Time)
                {
                    personal_best = GUtils.GetFormattedMS(best);
                }
                else
                {
                    personal_best = $"{GUtils.GetFormattedPoints(best)} eV";
                }
            }
            string out_personal_best = string.Format(Language.GetLine("levelinfo.personalbest"), personal_best);


            bool        supports_medals = level_info.SupportsMedals(mode.GameModeID_);
            MedalStatus medal_status    = MedalStatus.None;
            string      medal           = Language.GetLine($"medal.none");

            if (mode.SupportsMedals_ && supports_medals && level_path != null)
            {
                medal_status = progress.GetMedalStatusWithRelativePath(level_info.relativePath_, mode.GameModeID_);
                medal        = Language.GetLine($"medal.{medal_status.ToString().DOWN().Replace("_", "")}");
            }
            string out_medal_earned = string.Format(Language.GetLine("levelinfo.medalearned"), medal);


            string out_difficulty = string.Format(Language.GetLine("levelinfo.difficulty"), Language.GetLine($"difficulty.{level_info.difficulty_.ToString().DOWN()}"));


            out_result = $"{out_personal_best}\n{out_medal_earned}\n{out_difficulty}";

            if (level_info.levelType_ == LevelType.Workshop)
            {
                string rating, vote;
                rating = vote = "";
                if (SteamworksManager.IsSteamBuild_ && G.Sys.SteamworksManager_.UGC_.TryGetWorkshopLevelData(level_info.relativePath_, out WorkshopLevelInfo level_data))
                {
                    rating = SteamworksUGC.GetWorkshopRatingText(level_data);
                    vote   = Language.GetLine("levelinfo.workshop.vote.none");
                    switch (level_data.workshopVote_)
                    {
                    case EWorkshopVote.k_EWorkshopVoteFor:
                        vote = Language.GetLine("levelinfo.workshop.vote.for");
                        break;

                    case EWorkshopVote.k_EWorkshopVoteAgainst:
                        vote = Language.GetLine("levelinfo.workshop.vote.against");
                        break;
                    }
                }
                else
                {
                    rating = Language.GetLine("levelinfo.workshop.rating.unknown");
                    vote   = Language.GetLine("levelinfo.workshop.vote.unknown");
                }

                string out_rating = string.Format(Language.GetLine("levelinfo.workshop.rating"), rating);
                string out_vote   = string.Format(Language.GetLine("levelinfo.workshop.vote"), vote);

                out_result = $"{out_result}\n{out_rating}\n{out_vote}";
            }

            return(out_result);
        }
Exemple #4
0
        public static string formatLevelInfoText(LevelNameAndPathPair level, GameModeID mode, int index, string levelInfoText)
        {
            var resText = levelInfoText;
            var success = GeneralUtilities.logExceptions(() =>
            {
                bool isPointsMode    = G.Sys.GameManager_.Mode_ is PointsBasedMode;
                var levelSetsManager = G.Sys.LevelSets_;
                var levelInfo        = levelSetsManager.GetLevelInfo(level.levelPath_);
                WorkshopLevelInfo workshopLevelInfo = null;
                if (SteamworksManager.IsSteamBuild_)
                {
                    G.Sys.SteamworksManager_.UGC_.TryGetWorkshopLevelData(levelInfo.relativePath_, out workshopLevelInfo);
                }
                resText = resText
                          .Replace("%NAME%", levelInfo.levelName_)
                          .Replace("%DIFFICULTY%", levelInfo.difficulty_.ToString())
                          .Replace("%AUTHOR%", getAuthorName(levelInfo))
                          .Replace("%MODE%", mode.ToString())
                          .Replace("%INDEX%", index.ToString());
                if (levelInfo.SupportsMedals(mode))
                {
                    resText = resText
                              .Replace("%MBRONZE%", levelInfo.GetMedalRequirementString(MedalStatus.Bronze, isPointsMode))
                              .Replace("%MSILVER%", levelInfo.GetMedalRequirementString(MedalStatus.Silver, isPointsMode))
                              .Replace("%MGOLD%", levelInfo.GetMedalRequirementString(MedalStatus.Gold, isPointsMode))
                              .Replace("%MDIAMOND%", levelInfo.GetMedalRequirementString(MedalStatus.Diamond, isPointsMode));
                }
                else
                {
                    resText = resText
                              .Replace("%MBRONZE%", "None")
                              .Replace("%MSILVER%", "None")
                              .Replace("%MGOLD%", "None")
                              .Replace("%MDIAMOND%", "None");
                }
                if (workshopLevelInfo != null)
                {
                    resText = resText
                              .Replace("%STARS%", SteamworksUGC.GetWorkshopRatingText(workshopLevelInfo))
                              .Replace("%STARSINT%", ((int)(workshopLevelInfo.voteScore_ / 0.2f + 0.5f)).ToString())
                              .Replace("%STARSDEC%", (workshopLevelInfo.voteScore_ / 0.2f).ToString("F2"))
                              .Replace("%STARSPCT%", ((int)(workshopLevelInfo.voteScore_ * 100f)).ToString())
                              .Replace("%CREATED%", GeneralUtilities.ConvertFromUnixTimestamp(workshopLevelInfo.timeCreated_).ToString("d", CultureInfo.CurrentCulture))
                              .Replace("%UPDATED%", GeneralUtilities.ConvertFromUnixTimestamp(workshopLevelInfo.timeUpdated_).ToString("d", CultureInfo.CurrentCulture));
                }
                else
                {
                    resText = resText
                              .Replace("%STARS%", "None")
                              .Replace("%STARSINT%", "X")
                              .Replace("%STARSDEC%", "X")
                              .Replace("%STARSPCT%", "X")
                              .Replace("%CREATED%", "")
                              .Replace("%UPDATED%", "");
                }
                var replacements = Cmds.Cmd.all.getCommand <Cmds.LevelCmd>().levelFormatReplacements;
                foreach (var pair in replacements)
                {
                    try
                    {
                        resText = Regex.Replace(resText, pair.Key, pair.Value);
                    }
                    catch (ArgumentException)
                    {
                        Console.WriteLine($"Invalid regex replace ({pair.Key}) => ({pair.Value}). You can test your regex at regex101.com.");
                        MessageUtilities.sendMessage(GeneralUtilities.localClient(), $"Invalid regex replace ({pair.Key}) => ({pair.Value}).\nYou can test your regex at regex101.com.");
                    }
                }
            });

            if (!success)
            {
                logExceptions(() =>
                {
                    MessageUtilities.sendMessage(GeneralUtilities.localClient(), "Please check your console and report the level format debug info to a ServerMod developer.");
                    Console.WriteLine("Level format debug info:");
                    Console.WriteLine($"    produced string: {resText}");
                    Console.WriteLine($"    level: {level}; {level?.levelName_}; {level?.levelPath_}");
                    Console.WriteLine($"    mode: {mode};");
                    Console.WriteLine($"    index: {index};");
                    Console.WriteLine($"    levelInfoText: {levelInfoText};");
                    Console.WriteLine($"    G.Sys.GameManager_.Mode_: {G.Sys?.GameManager_?.Mode_};");
                    Console.WriteLine($"    G.Sys.LevelSets_: {G.Sys?.LevelSets_};");
                    var levelSetsManager = G.Sys?.LevelSets_;
                    var levelInfo        = levelSetsManager?.GetLevelInfo(level.levelPath_);
                    Console.WriteLine($"    levelInfo: {levelInfo};");
                    WorkshopLevelInfo workshopLevelInfo = null;
                    if (SteamworksManager.IsSteamBuild_)
                    {
                        G.Sys.SteamworksManager_.UGC_.TryGetWorkshopLevelData(levelInfo.relativePath_, out workshopLevelInfo);
                    }
                    Console.WriteLine($"    workshopLevelInfo: {workshopLevelInfo};");
                });
            }
            return(resText);
        }