Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
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;
     }
 }
Ejemplo n.º 3
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;
     }
 }