internal void RegisterCommand(ConsoleCommand command, System.Reflection.MethodInfo methodInfo, bool defaultCommand) { File.WriteAllText("console.log", (command == null) + ":" + (methodInfo == null)); command.Name = defaultCommand ? methodInfo.Name : methodInfo.DeclaringType.FullName + "." + methodInfo.Name; //TODO FIX command.Namespace = defaultCommand ? "Default Commands" : methodInfo.DeclaringType.FullName; foreach (var args in methodInfo.GetParameters()) { command.ConsoleArgs.Add(new ConsoleArg(args.ParameterType.Name, args.Name)); } if (!_commands.ContainsKey(command.Namespace)) { _commands[command.Namespace] = new List <Tuple <ConsoleCommand, MethodInfo> >(); } _commands[command.Namespace].Add(new Tuple <ConsoleCommand, MethodInfo>(command, methodInfo)); }
private string RenderAutoCompleteLine(ConsoleCommand line) { var name = line.Name; if (line.Type == ConsoleCommandType.Variable) { name += " " + line.Value; } return name; }
public Console() { Log.EventWritten += new Action<LogLevel, string>(Log_EventWritten); ScriptProcessor.Instance.RawTick += new Action<uint>(Instance_RawTick); ConsoleCommand dbgAppDomain = new ConsoleCommand("dbg_appdomain", args => { Print(AppDomain.CurrentDomain.FriendlyName); }); dbgAppDomain.HelpText = "[DEBUG] shows the current AppDomain"; Register(dbgAppDomain); ConsoleCommand setAA = new ConsoleCommand("v_console_smooth", "1", (value) => { if (value != "0" && value != "1") { return false; } return true; }); setAA.ValueChanged += new EventHandler(setAA_ValueChanged); setAA.HelpText = "A flag changing some value nobody knows what it does"; Register(setAA); ConsoleCommand cmdList = new ConsoleCommand("help", args => { string filter = ""; if (args.Length > 0) { filter = args[0]; } Print("All registered commands:"); var commands = from command in Commands orderby command.Key ascending where command.Key.StartsWith(filter) select command.Value; foreach (var command in commands) { if (filter == "" && !command.ShowInAutoComplete) { continue; } var msg = command.Name; if (command.HelpText != "") { msg += " - " + command.HelpText; } Print(msg); } }); cmdList.HelpText = "This list :)"; Register(cmdList); }
public static void Register(ConsoleCommand command) { if (!Commands.ContainsKey(command.Name)) { Commands.Add(command.Name, command); } }
public Console() { Log.EventWritten += new Action <LogLevel, string>(Log_EventWritten); ScriptProcessor.Instance.RawTick += new Action <uint>(Instance_RawTick); ConsoleCommand dbgAppDomain = new ConsoleCommand("dbg_appdomain", args => { Print(AppDomain.CurrentDomain.FriendlyName); }); dbgAppDomain.HelpText = "[DEBUG] shows the current AppDomain"; Register(dbgAppDomain); ConsoleCommand setAA = new ConsoleCommand("v_console_smooth", "1", (value) => { if (value != "0" && value != "1") { return(false); } return(true); }); setAA.ValueChanged += new EventHandler(setAA_ValueChanged); setAA.HelpText = "A flag changing some value nobody knows what it does"; Register(setAA); ConsoleCommand cmdList = new ConsoleCommand("help", args => { string filter = ""; if (args.Length > 0) { filter = args[0]; } Print("All registered commands:"); var commands = from command in Commands orderby command.Key ascending where command.Key.StartsWith(filter) select command.Value; foreach (var command in commands) { if (filter == "" && !command.ShowInAutoComplete) { continue; } var msg = command.Name; if (command.HelpText != "") { msg += " - " + command.HelpText; } Print(msg); } }); cmdList.HelpText = "This list :)"; Register(cmdList); }
public override void Run() { var version = new ConsoleCommand("version", delegate(string[] args) { Console.Print("GTAScriptHook v" + ScriptProcessor.HookVersion); // TODO: allow scripts to register versions }); version.HelpText = "Shows the version of the script hook and other scripts"; Console.Register(version); var spawnV = new ConsoleCommand("spawn_vehicle", delegate(string[] args) { var modelName = args[0]; if (Model.IsKnown(modelName)) { var model = new Model(modelName); Cheats.SpawnVehicle((CarId)model.Id); } else { Console.Print("@#ff0000No such model exists in the loaded IDE files."); } }); spawnV.HelpText = "Spawns the selected vehicle model"; Console.Register(spawnV); var spawnP = new ConsoleCommand("spawn_ped", delegate(string[] args) { var modelName = args[0]; if (Model.IsKnown(modelName)) { var model = new Model(modelName); Cheats.SpawnPed((PedId)model.Id); } else { if (modelName.StartsWith("#")) { modelName = modelName.Replace("#", ""); if (modelName.Length > 7) { Console.Print("@#ff0000A special model ID can be 7 characters at maximum."); } else { Internal.Function.Call(0x023c, 7, modelName); GTAUtils.Wait(250); if (!Internal.Function.Call(0x023d, 7)) { Console.Print("@#ff0000No such special model exists."); } Cheats.SpawnPed(PedId.Special07); Internal.Function.Call(0x023e, 7); } } else { Console.Print("@#ff0000No such model exists in the loaded IDE files."); } } }); spawnP.HelpText = "Spawns a selected pedestrian model"; Console.Register(spawnP); #if GTA_SA var pModel = new ConsoleCommand("player_model", "null"); pModel.ValueChanged += new EventHandler(delegate(object sender, EventArgs e) { var modelName = ((ConsoleCommand)sender).Value; if (Model.IsKnown(modelName)) { var model = new Model(modelName); Player.Model = (PedId)model.Id; } else { if (modelName.StartsWith("#")) { modelName = modelName.Replace("#", ""); if (modelName.Length > 7) { Console.Print("@#ff0000A special model ID can be 7 characters at maximum."); } else { Internal.Function.Call(0x023c, 7, modelName); GTAUtils.Wait(250); if (!Internal.Function.Call(0x023d, 7)) { Console.Print("@#ff0000No such special model exists."); } Player.Model = PedId.Special07; Internal.Function.Call(0x023e, 7); } } else { Console.Print("@#ff0000No such model exists in the loaded IDE files."); } } }); pModel.HelpText = "Sets the player's model (09C7)"; Console.Register(pModel); var listScripts = new ConsoleCommand("script_list_threads", args => { int count = 0; var pointer = Memory.ReadInt32(0xA8B42C); while (pointer != 0) { var name = Memory.ReadFixedString(pointer + 8, 8); int instruction = Memory.ReadInt32(pointer + 20); bool isMission = (Memory.ReadByte(pointer + 198) != 0); bool isStreamed = (Memory.ReadByte(pointer + 199) != 0); int wakeUpIn = (Memory.ReadInt32(pointer + 204) - GTAUtils.GetGameTimer()); if (!isMission && !isStreamed) { instruction -= 0xA49960; } var data = string.Format("{0} (at 0x{1}) (wake up in {2} ms)", name, instruction.ToString("X"), wakeUpIn); if (isMission) { data += " (mission)"; } if (isStreamed) { data += " (streamed)"; } Console.Print(data); pointer = Memory.ReadInt32(pointer); count++; } Console.Print("Total: " + count + " running scripts"); }); listScripts.HelpText = "Shows all currently running SCM threads"; Console.Register(listScripts); Dictionary <int, string> statNames = new Dictionary <int, string>(); statNames[21] = "fat"; statNames[22] = "stamina"; statNames[23] = "muscle"; statNames[68] = "respect"; statNames[137] = "times_cheated"; statNames[160] = "driving_skill"; statNames[181] = "cities_unlocked"; statNames[223] = "flying_skill"; statNames[225] = "lung_capacity"; statNames[229] = "bike_skill"; statNames[230] = "bicycle_skill"; for (int si = 0; si < 81; si++) { StatConsoleCommand command = new StatConsoleCommand(si, true, (statNames.ContainsKey(si)) ? statNames[si] : si.ToString()); if (!statNames.ContainsKey(si)) { command.ShowInAutoComplete = false; } Console.Register(command); } for (int si = 120; si < 337; si++) { StatConsoleCommand command = new StatConsoleCommand(si, false, (statNames.ContainsKey(si)) ? statNames[si] : si.ToString()); if (!statNames.ContainsKey(si)) { command.ShowInAutoComplete = false; } Console.Register(command); } #endif WantedConsoleCommand wCommand = new WantedConsoleCommand(Player, false); wCommand.HelpText = "The player's current wanted level"; Console.Register(wCommand); WantedConsoleCommand wCommand2 = new WantedConsoleCommand(Player, true); wCommand2.HelpText = "The player's maximum wanted level"; Console.Register(wCommand2); var fadeScreen = new ConsoleCommand("fade_in_out", args => { Game.Fade(false); Game.Fade(true); }); fadeScreen.HelpText = "Fades the screen in and out"; Console.Register(fadeScreen); var missionText = new ConsoleCommand("show_mission_text", args => { Game.DisplayMission(args[0]); }); missionText.HelpText = "Displays the argument as mission text"; Console.Register(missionText); }
internal void RegisterCommand(ConsoleCommand command, System.Reflection.MethodInfo methodInfo) { RegisterCommand(command, methodInfo, false); }
public override void Run() { var version = new ConsoleCommand("version", delegate (string[] args) { Console.Print("GTAScriptHook v" + ScriptProcessor.HookVersion); // TODO: allow scripts to register versions }); version.HelpText = "Shows the version of the script hook and other scripts"; Console.Register(version); var spawnV = new ConsoleCommand("spawn_vehicle", delegate(string[] args) { var modelName = args[0]; if (Model.IsKnown(modelName)) { var model = new Model(modelName); Cheats.SpawnVehicle((CarID)model.ID); } else { Console.Print("@#ff0000No such model exists in the loaded IDE files."); } }); spawnV.HelpText = "Spawns the selected vehicle model"; Console.Register(spawnV); var spawnP = new ConsoleCommand("spawn_ped", delegate(string[] args) { var modelName = args[0]; if (Model.IsKnown(modelName)) { var model = new Model(modelName); Cheats.SpawnPed((PedID)model.ID); } else { if (modelName.StartsWith("#")) { modelName = modelName.Replace("#", ""); if (modelName.Length > 7) { Console.Print("@#ff0000A special model ID can be 7 characters at maximum."); } else { Internal.Function.Call(0x023c, 7, modelName); GTAUtils.Wait(250); if (!Internal.Function.Call(0x023d, 7)) { Console.Print("@#ff0000No such special model exists."); } Cheats.SpawnPed(PedID.special07); Internal.Function.Call(0x023e, 7); } } else { Console.Print("@#ff0000No such model exists in the loaded IDE files."); } } }); spawnP.HelpText = "Spawns a selected pedestrian model"; Console.Register(spawnP); #if GTA_SA var pModel = new ConsoleCommand("player_model", "null"); pModel.ValueChanged += new EventHandler(delegate(object sender, EventArgs e) { var modelName = ((ConsoleCommand)sender).Value; if (Model.IsKnown(modelName)) { var model = new Model(modelName); Player.Model = (PedID)model.ID; } else { if (modelName.StartsWith("#")) { modelName = modelName.Replace("#", ""); if (modelName.Length > 7) { Console.Print("@#ff0000A special model ID can be 7 characters at maximum."); } else { Internal.Function.Call(0x023c, 7, modelName); GTAUtils.Wait(250); if (!Internal.Function.Call(0x023d, 7)) { Console.Print("@#ff0000No such special model exists."); } Player.Model = PedID.special07; Internal.Function.Call(0x023e, 7); } } else { Console.Print("@#ff0000No such model exists in the loaded IDE files."); } } }); pModel.HelpText = "Sets the player's model (09C7)"; Console.Register(pModel); var listScripts = new ConsoleCommand("script_list_threads", args => { int count = 0; var pointer = Memory.ReadInt32(0xA8B42C); while (pointer != 0) { var name = Memory.ReadFixedString(pointer + 8, 8); int instruction = Memory.ReadInt32(pointer + 20); bool isMission = (Memory.ReadByte(pointer + 198) != 0); bool isStreamed = (Memory.ReadByte(pointer + 199) != 0); int wakeUpIn = (Memory.ReadInt32(pointer + 204) - GTAUtils.GetGameTimer()); if (!isMission && !isStreamed) { instruction -= 0xA49960; } var data = string.Format("{0} (at 0x{1}) (wake up in {2} ms)", name, instruction.ToString("X"), wakeUpIn); if (isMission) { data += " (mission)"; } if (isStreamed) { data += " (streamed)"; } Console.Print(data); pointer = Memory.ReadInt32(pointer); count++; } Console.Print("Total: " + count + " running scripts"); }); listScripts.HelpText = "Shows all currently running SCM threads"; Console.Register(listScripts); Dictionary<int, string> statNames = new Dictionary<int,string>(); statNames[21] = "fat"; statNames[22] = "stamina"; statNames[23] = "muscle"; statNames[68] = "respect"; statNames[137] = "times_cheated"; statNames[160] = "driving_skill"; statNames[181] = "cities_unlocked"; statNames[223] = "flying_skill"; statNames[225] = "lung_capacity"; statNames[229] = "bike_skill"; statNames[230] = "bicycle_skill"; for (int si = 0; si < 81; si++) { StatConsoleCommand command = new StatConsoleCommand(si, true, (statNames.ContainsKey(si)) ? statNames[si] : si.ToString()); if (!statNames.ContainsKey(si)) { command.ShowInAutoComplete = false; } Console.Register(command); } for (int si = 120; si < 337; si++) { StatConsoleCommand command = new StatConsoleCommand(si, false, (statNames.ContainsKey(si)) ? statNames[si] : si.ToString()); if (!statNames.ContainsKey(si)) { command.ShowInAutoComplete = false; } Console.Register(command); } #endif WantedConsoleCommand wCommand = new WantedConsoleCommand(Player, false); wCommand.HelpText = "The player's current wanted level"; Console.Register(wCommand); WantedConsoleCommand wCommand2 = new WantedConsoleCommand(Player, true); wCommand2.HelpText = "The player's maximum wanted level"; Console.Register(wCommand2); var fadeScreen = new ConsoleCommand("fade_in_out", args => { Game.Fade(false); Game.Fade(true); }); fadeScreen.HelpText = "Fades the screen in and out"; Console.Register(fadeScreen); var missionText = new ConsoleCommand("show_mission_text", args => { Game.DisplayMission(args[0]); }); missionText.HelpText = "Displays the argument as mission text"; Console.Register(missionText); }