Esempio n. 1
0
 public static void setPrivateProperty(object obj, string propertyName, object value)
 {
     try
     {
         obj
         .GetType()
         .GetProperty(
             propertyName,
             BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static
             )
         .GetSetMethod().Invoke(obj, new object[] { value });
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error setting private property {propertyName}. Has it been removed?");
         Console.WriteLine($"Error: {e}");
         if (GeneralUtilities.isHost())
         {
             MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(GeneralUtilities.localClient()));
             MessageUtilities.sendMessage("[FF1010]ServerMod encountered an error and could not complete a task.[-]");
             MessageUtilities.sendMessage("[FF1010]ServerMod might not work properly from this point onwards.[-]");
             MessageUtilities.sendMessage("[FF1010]Check the console for information. You can turn on the console with the -console launch parameter.[-]");
             MessageUtilities.sendMessage($"[FF1010]Error accessing private property {propertyName}. Has it been removed?[-]");
             MessageUtilities.popMessageOptions();
         }
         throw e;
     }
 }
Esempio n. 2
0
 public static object callPrivateMethod(object obj, string methodName, params object[] args)
 {
     try
     {
         return(obj.GetType().GetMethod(
                    methodName,
                    BindingFlags.NonPublic | BindingFlags.Instance
                    ).Invoke(obj, args));
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error calling private method {methodName}. Has it been removed?");
         Console.WriteLine($"Error: {e}");
         if (GeneralUtilities.isHost())
         {
             MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(GeneralUtilities.localClient()));
             MessageUtilities.sendMessage("[FF1010]ServerMod encountered an error and could not complete a task.[-]");
             MessageUtilities.sendMessage("[FF1010]ServerMod might not work properly from this point onwards.[-]");
             MessageUtilities.sendMessage("[FF1010]Check the console for information. You can turn on the console with the -console launch parameter.[-]");
             MessageUtilities.sendMessage($"[FF1010]Error calling private method {methodName}. Has it been removed?[-]");
             MessageUtilities.popMessageOptions();
         }
         throw e;
     }
 }
Esempio n. 3
0
        public static void sendFailures(List <string> failures, int max)
        {
            var count = 0;

            foreach (string failure in failures)
            {
                if (count >= max - 1 && failures.Count > max)
                {
                    MessageUtilities.sendMessage($"[A00000]and {failures.Count - count} more.[-]");
                    break;
                }
                MessageUtilities.sendMessage("[A00000]" + failure + "[-]");
                count++;
            }
        }
Esempio n. 4
0
 public static void logExceptionsThrow(TestFuncD f)
 {
     try
     {
         f();
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error: {e}");
         if (isHost())
         {
             MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(GeneralUtilities.localClient()));
             MessageUtilities.sendMessage("[FF1010]ServerMod encountered an error and could not complete a task.[-]");
             MessageUtilities.sendMessage("[FF1010]ServerMod might not work properly from this point onwards.[-]");
             MessageUtilities.sendMessage("[FF1010]Check the console for information. You can turn on the console with the -console launch parameter.[-]");
             MessageUtilities.popMessageOptions();
         }
         throw e;
     }
 }
Esempio n. 5
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);
        }