public static void RegisterCommands(RoR2.Console self) { var types = Assembly.GetCallingAssembly()?.GetTypes(); if (types == null) { return; } var catalog = self.GetFieldValue <IDictionary>("concommandCatalog"); const BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; var methods = types.SelectMany(x => x.GetMethods(flags).Where(m => m.GetCustomAttribute <ConCommandAttribute>() != null)); foreach (var methodInfo in methods) { var attributes = methodInfo.GetCustomAttributes <ConCommandAttribute>(); foreach (var attribute in attributes) { var conCommand = Reflection.GetNestedType <RoR2.Console>("ConCommand").Instantiate(); conCommand.SetFieldValue("flags", attribute.flags); conCommand.SetFieldValue("helpText", attribute.helpText); conCommand.SetFieldValue("action", (RoR2.Console.ConCommandDelegate)Delegate.CreateDelegate(typeof(RoR2.Console.ConCommandDelegate), methodInfo)); catalog[attribute.commandName.ToLower()] = conCommand; } } }
// ReSharper disable once UnusedMember.Local private static void LogNetworkCommandsAndCheckPermissions(Console self, NetworkUser sender, string concommandName, List <string> userArgs) { StringBuilder s = new StringBuilder(); userArgs.ForEach((str) => s.AppendLine(str)); if (sender != null && sender.isLocalPlayer == false) { Log.Message(string.Format(Lang.NETWORKING_OTHERPLAYER_4, sender.userName, sender.id.value, concommandName, s.ToString())); } else if (Application.isBatchMode) { Log.Message(string.Format(Lang.NETWORKING_OTHERPLAYER_4, "Server", 0, concommandName, s.ToString())); } var canExecute = true; if (sender != null && !sender.isLocalPlayer && PermissionSystem.IsEnabled.Value) { canExecute = PermissionSystem.CanUserExecute(sender, concommandName, userArgs); } if (canExecute) { _origRunCmd(self, sender, concommandName, userArgs); ScrollConsoleDown(); } }
public static void RegisterCommands(RoR2.Console self) { var types = typeof(CommandHelper).Assembly.GetTypes(); var catalog = self.GetFieldValue <IDictionary>("concommandCatalog"); foreach (var methodInfo in types.SelectMany(x => x.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))) { var customAttributes = methodInfo.GetCustomAttributes(false); foreach (var attribute in customAttributes.OfType <ConCommandAttribute>()) { var conCommand = Reflection.GetNestedType <RoR2.Console>("ConCommand").Instantiate(); if (!DropInMultiplayer.SpawnAsEnabled.Value && attribute.commandName.Equals("spawn_as", StringComparison.CurrentCultureIgnoreCase)) { return; } conCommand.SetFieldValue("flags", attribute.flags); conCommand.SetFieldValue("helpText", attribute.helpText); conCommand.SetFieldValue("action", (RoR2.Console.ConCommandDelegate)Delegate.CreateDelegate(typeof(RoR2.Console.ConCommandDelegate), methodInfo)); catalog[attribute.commandName.ToLower()] = conCommand; } } }
private static void DropItemCommand(ConCommandArgs args) { var itemName = args.GetArgString(0); var itemIndex = ItemNameToIndex(itemName); if (itemIndex == ItemIndex.None) { Console.print("Can't find item specified"); return; } var count = args.TryGetArgInt(1) ?? 1; KookehsDropItemMod.Logger.LogDebug("Item index: " + itemIndex); var master = args.GetSenderMaster(); var inventory = master.inventory; var charTransform = master.GetBody().GetFieldValue <Transform>("transform"); for (int i = 0; i < count; i++) { DropItemHandler.DropItem(charTransform, inventory, PickupCatalog.FindPickupIndex(itemIndex)); } }
private static void ConsoleReady(On.RoR2.Console.orig_InitConVars orig, RoR2.Console self) { orig(self); _console = self; HandleCommandsConvars(); }
public static void GiveMoney(uint howMuch, NetworkUser offender = null) { if (offender == null) { return; } if (_player == null) { var logAct = new Console.Log { message = "No-one to give money to!" }; Console.HandleLog(logAct.message, logAct.stackTrace, logAct.logType); return; } var log = new Console.Log { message = offender != null ? $"Giving {howMuch} currency to {offender.userName}!" : $"Giving {howMuch} currency to anon :o " }; Console.HandleLog(log.message, log.stackTrace, log.logType); _player.GiveMoney(howMuch); }
public static void RegisterCommands(RoR2.Console _) { Assembly assembly = Assembly.GetCallingAssembly(); if (assembly == null) { return; } assemblies.Enqueue(assembly); HandleCommandsConvars(); }
private void CheckChatForJoinRequest(On.RoR2.Console.orig_RunCmd orig, RoR2.Console self, RoR2.Console.CmdSender sender, string concommandName, List <string> userArgs) { orig(self, sender, concommandName, userArgs); if (concommandName.Equals("say", StringComparison.InvariantCultureIgnoreCase)) { var userInput = userArgs.FirstOrDefault().Split(' '); var chatCommand = userInput.FirstOrDefault(); if (chatCommand.IsNullOrWhiteSpace()) { return; } if (chatCommand.Equals("join_as", StringComparison.InvariantCultureIgnoreCase) || chatCommand.Equals("join", StringComparison.InvariantCultureIgnoreCase)) { List <string> data = userInput.ToList(); string bodyString = userInput.ElementAtOrDefault(1) ?? ""; string userString = userInput.LastOrDefault() ?? ""; string newstring = ""; bool open = false; if (bodyString.Contains('"') && userString.Contains('"')) { bodyString = ""; for (int i = 1; i < data.Count; i++) { var str = data.ElementAt(i) ?? ""; if (str == userInput.ElementAtOrDefault(1)) { } foreach (var item in str) { if (item == '"') { open = open == false ? true : false; } else { newstring += item; } } bodyString += open == true ? newstring + " " : newstring; newstring = ""; } userString = ""; } else { bodyString = userInput.ElementAtOrDefault(1) ?? ""; userString = userInput.ElementAtOrDefault(2) ?? ""; } JoinAs(sender.networkUser, bodyString, userString); } } }
private static void LogNetworkCommands(On.RoR2.Console.orig_RunCmd orig, RoR2.Console self, NetworkUser sender, string concommandName, System.Collections.Generic.List <string> userArgs) { if (sender != null && sender.isLocalPlayer == false) { StringBuilder s = new StringBuilder(); userArgs.ForEach((str) => s.AppendLine(str)); Log.Message(string.Format(Lang.NETWORKING_OTHERPLAYER_4, sender.userName, sender.id.value, concommandName, s.ToString())); } orig(self, sender, concommandName, userArgs); ScrollConsoleDown(); }
static void Postfix(RoR2.Console __instance) { Debug.Log("Initializing Infinity mod"); console = __instance; InfinityExtension[] extensions = new InfinityExtension[] { new MiscExtension(), new PermsExtension(), new StatsExtension(), new LobbyExtension(), new ChestsExtension(), new LevelExtension(), new TeleporterExtension(), }; for (int i = 0; i < extensions.Length; i++) { Debug.Log("Initializing " + extensions[i].GetType().Name); extensions[i].Init(); foreach (MethodInfo methodInfo in extensions[i].GetType().GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { object[] attr = methodInfo?.GetCustomAttributes(false); if (attr != null) { foreach (var at in attr) { if (at is InCmd) { registerCmd(at as InCmd, (InCmdDelegate)Delegate.CreateDelegate(typeof(InCmdDelegate), methodInfo)); } } } } foreach (Type subType in extensions[i].GetType().GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic)) { object[] attr = subType?.GetCustomAttributes(false); if (attr != null) { foreach (var at in attr) { if (at is InCmd) { registerVar(at as InCmd, (InVar)subType.GetConstructor(Type.EmptyTypes).Invoke(new object[0])); } } } } } RoR2.Console.instance.SubmitCmd(null, "exec infinity_start", false); }
public static void RegisterCommands(RoR2.Console self) { var types = typeof(CommandHelper).Assembly.GetTypes(); var catalog = self.GetFieldValue <IDictionary>("concommandCatalog"); foreach (var methodInfo in types.SelectMany(x => x.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))) { var customAttributes = methodInfo.GetCustomAttributes(false); foreach (var attribute in customAttributes.OfType <ConCommandAttribute>()) { var conCommand = Reflection.GetNestedType <RoR2.Console>("ConCommand").Instantiate(); conCommand.SetFieldValue("flags", attribute.flags); conCommand.SetFieldValue("helpText", attribute.helpText); conCommand.SetFieldValue("action", (RoR2.Console.ConCommandDelegate)Delegate.CreateDelegate(typeof(RoR2.Console.ConCommandDelegate), methodInfo)); catalog[attribute.commandName.ToLower()] = conCommand; } } }
private void CheckforJoinAsRequest(On.RoR2.Console.orig_RunCmd orig, RoR2.Console self, RoR2.Console.CmdSender sender, string concommandName, List <string> userArgs) { orig(self, sender, concommandName, userArgs); if (concommandName.Equals("say", StringComparison.OrdinalIgnoreCase)) { var userMsg = ArgsHelper.GetValue(userArgs, 0).ToLower(); var isRequest = userMsg.StartsWith("join_as"); if (isRequest) { var argsRequest = userMsg.Split(' ').ToList(); string bodyString = ArgsHelper.GetValue(argsRequest, 1); string userString = ArgsHelper.GetValue(argsRequest, 2); JoinAs(sender.networkUser, bodyString, userString); } } }
private void CheckChatForJoinRequest(On.RoR2.Console.orig_RunCmd orig, RoR2.Console self, RoR2.Console.CmdSender sender, string concommandName, List <string> userArgs) { orig(self, sender, concommandName, userArgs); if (concommandName.Equals("say", StringComparison.InvariantCultureIgnoreCase)) { string[] userInput = userArgs.FirstOrDefault().Split(new char[] { ' ' }, count: 3); string chatCommand = userInput.FirstOrDefault(); if (string.IsNullOrWhiteSpace(chatCommand)) { return; } if (chatCommand.Equals("join_as", StringComparison.InvariantCultureIgnoreCase) || chatCommand.Equals("join", StringComparison.InvariantCultureIgnoreCase)) { string bodyString = userInput.ElementAtOrDefault(1) ?? ""; string userString = userInput.ElementAtOrDefault(2) ?? ""; JoinAs(sender.networkUser, bodyString, userString); } } }
private static void Console_RunCmd(On.RoR2.Console.orig_RunCmd orig, RoR2.Console self, RoR2.Console.CmdSender sender, string concommandName, List <string> userArgs) { orig(self, sender, concommandName, userArgs); if (!NetworkServer.active || Run.instance == null) { return; } if (!concommandName.Equals("say", StringComparison.InvariantCultureIgnoreCase)) { return; } string chatMessage = userArgs.FirstOrDefault(); if (string.IsNullOrWhiteSpace(chatMessage) || !chatMessage.StartsWith("/")) { return; } string[] splitMessage = chatMessage.Split(new char[] { ' ' }); string chatCommandName = splitMessage.FirstOrDefault().Substring(1); // substring removes leading slash string[] commandArgs = splitMessage.Skip(1).ToArray(); if (!_chatCommands.TryGetValue(chatCommandName.ToUpperInvariant(), out ChatCommand chatCommand)) { SendChatMessage("Unable to find command, try /help"); } string resultMessage = chatCommand.Handler(sender.networkUser, commandArgs); if (!string.IsNullOrWhiteSpace(resultMessage)) { SendChatMessage(resultMessage); } }
private static void InitCommandsAndFreeConvars(On.RoR2.Console.orig_InitConVars orig, RoR2.Console self) { void removeCheatFlag(RoR2.ConVar.BaseConVar cv) { cv.flags &= AllFlagsNoCheat; } orig(self); removeCheatFlag(self.FindConVar("sv_time_transmit_interval")); removeCheatFlag(self.FindConVar("run_scene_override")); removeCheatFlag(self.FindConVar("stage1_pod")); self.FindConVar("timescale").helpText += " Use time_scale instead!"; self.FindConVar("director_combat_disable").helpText += " Use no_enemies instead!"; self.FindConVar("timestep").helpText += " Let the ror2cheats team know if you need this convar."; self.FindConVar("cmotor_safe_collision_step_threshold").helpText += " Let the ror2cheats team know if you need this convar."; self.FindConVar("cheats").helpText += " But you already have the RoR2Cheats mod installed..."; }
private static void Console_InitConVars(On.RoR2.Console.orig_InitConVars orig, Console self) { orig(self); var dictionary = (Dictionary <string, BaseConVar>) typeof(Console).GetField("allConVars", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(self); foreach (Settings.BaseCustomSetting customsetting in Settings.listSettings) { if (dictionary.ContainsKey(customsetting.conVar.name)) { dictionary[customsetting.conVar.name] = customsetting.conVar; } else { dictionary.Add(customsetting.conVar.name, customsetting.conVar); } } }
private static void CommandArgsAutoCompletion(On.RoR2.Console.AutoComplete.orig_ctor orig, Console.AutoComplete self, Console console) { orig(self, console); var searchableStrings = self.GetFieldValue<List<string>>("searchableStrings"); var tmp = new List<string>(); tmp.AddRange(ArgsAutoCompletion.CommandsWithStaticArgs); tmp.AddRange(ArgsAutoCompletion.CommandsWithDynamicArgs()); tmp.Sort(); searchableStrings.AddRange(tmp); self.SetFieldValue("searchableStrings", searchableStrings); }
private static void CommandArgsAutoCompletion(On.RoR2.Console.AutoComplete.orig_ctor orig, RoR2.Console.AutoComplete self, RoR2.Console console) { orig(self, console); var searchableStrings = self.GetFieldValue <List <string> >("searchableStrings"); foreach (var item in ArgsAutoCompletion.CommandsWithStaticArgs) { searchableStrings.Add(item); } foreach (var item in ArgsAutoCompletion.CommandsWithDynamicArgs()) { searchableStrings.Add(item); } searchableStrings.Sort(); self.SetFieldValue("searchableStrings", searchableStrings); }
private static void InitCommandsAndFreeConvars(On.RoR2.Console.orig_InitConVars orig, Console self) { void RemoveCheatFlag (BaseConVar cv) { cv.flags &= AllFlagsNoCheat; } orig(self); RemoveCheatFlag(self.FindConVar("sv_time_transmit_interval")); RemoveCheatFlag(self.FindConVar("run_scene_override")); RemoveCheatFlag(self.FindConVar("stage1_pod")); self.FindConVar("timescale").helpText += " Use time_scale instead!"; self.FindConVar("director_combat_disable").helpText += " Use no_enemies instead!"; self.FindConVar("timestep").helpText += " Let the DebugToolkit team know if you need this convar."; self.FindConVar("cmotor_safe_collision_step_threshold").helpText += " Let the DebugToolkit team know if you need this convar."; self.FindConVar("cheats").helpText += " But you already have the DebugToolkit mod installed..."; var mmConvar = (IntConVar) self.FindConVar("max_messages"); if (mmConvar.value == 25) { mmConvar.SetString("100"); } }