void Ammo(object sender, CommandEventArgs e) { if (e.length != 1) { PrintError("Syntax: ammo <item ID>"); return; } int ammo; if (!int.TryParse(e[0], out ammo)) { PrintError("Invalid ammo."); return; } Main.currItem.useAmmo = ammo; PrintNotification("Set selected item's ammo to " + ammo + "."); }
/// <summary> /// Executes a string as a command. /// </summary> public static void Execute(string str, bool repeat = true) { CommandEventArgs args = new CommandEventArgs(str); foreach (Command c in commands) { if (args[0].ToLower() == c.name || (c.aliases != null && c.aliases.Contains<string>(args[0].ToLower()))) { if (c.name != "repeat" && repeat) { lastCommand = str; } c.callback(c, new CommandEventArgs(str.Substring(args[0].Length))); if (c.alert) { NetMessage.SendData(25, "*ALERT*: used " + str); } return; } } Client.PrintError("Invalid command."); }
static void NetSend(object sender, CommandEventArgs e) { if (e.length < 1 || e.length > 7) { PrintError("Syntax: netsend <packet ID> [<arg1>] [<arg2>] [<arg3>] [<arg4>] [<arg5>] [<arg6>]"); return; } int packet; if (!int.TryParse(e[0], out packet)) { PrintError("Invalid packet ID."); return; } int num1 = 0, num5 = 0; float num2 = 0, num3 = 0, num4 = 0; string str = ""; try { if (!int.TryParse(e[2], out num1)) { PrintError("Invalid integer."); return; } if (!float.TryParse(e[3], out num2) || !float.TryParse(e[4], out num3) || !float.TryParse(e[5], out num4)) { PrintError("Invalid float."); return; } if (!int.TryParse(e[6], out num5)) { PrintError("Invalid integer."); return; } } catch (IndexOutOfRangeException) { } finally { NetMessage.SendData(packet, str, num1, num2, num3, num4, num5); PrintNotification("Sent " + packet + ", " + (str == "" ? "\"\"" : str) + ", " + num1 + ", " + num2 + ", " + num3 + ", " + num4 + ", " + num5); } }
void Track(object sender, CommandEventArgs e) { track = !track; PrintNotification((track ? "En" : "Dis") + "abled player tracking."); }
void ShootSpeed(object sender, CommandEventArgs e) { if (e.length != 1) { PrintError("Syntax: shootspeed <speed>"); return; } float shootSpeed; if (!float.TryParse(e[0], out shootSpeed)) { PrintError("Invalid shoot speed."); return; } Main.currItem.shootSpeed = shootSpeed; PrintNotification("Set selected item's shoot speed to " + shootSpeed + "."); }
void Ruler(object sender, CommandEventArgs e) { ruler = !ruler; PrintNotification((ruler ? "En" : "Dis") + "abled ruler."); }
void MaxStack(object sender, CommandEventArgs e) { if (e.length > 1) { PrintError("Syntax: maxstack [all|ammo]"); return; } if (e.length == 0) { Main.currItem.stack = Main.currItem.maxStack; PrintNotification("Maximized selected item's stack size."); } else { switch (e[0]) { case "all": for (int i = 0; i < Main.currPlayer.inventory.Length; i++) { Main.currPlayer.inventory[i].stack = Main.currPlayer.inventory[i].maxStack; } PrintNotification("Maximized all items' stack size."); break; case "ammo": for (int i = 0; i < Main.currPlayer.inventory.Length; i++) { if (Main.currPlayer.inventory[i].ammo != 0) { Main.currPlayer.inventory[i].stack = Main.currPlayer.inventory[i].maxStack; } } PrintNotification("Maximized all ammos' stack size."); break; default: PrintError("Invalid maxstack option."); return; } } }
void Jump(object sender, CommandEventArgs e) { Main.currPlayer.position = Main.screenPosition + new Vector2(Input.mX, Input.mY); }
void Fullbright(object sender, CommandEventArgs e) { fullbright = !fullbright; PrintNotification((fullbright ? "En" : "Dis") + "abled fullbright."); }
void Damage(object sender, CommandEventArgs e) { if (e.length != 1) { PrintError("Syntax: damage <damage>"); return; } int damage; if (!int.TryParse(e[0], out damage) || damage <= 0) { PrintError("Invalid damage."); return; } Main.currItem.damage = damage; PrintNotification("Set selected item's damage to " + damage + "."); }
void ClearInv(object sender, CommandEventArgs e) { for (int i = 10; i < Main.currPlayer.inventory.Length; i++) { Main.currPlayer.inventory[i] = TerrariAPI.Hooking.Item.New(); } PrintNotification("Cleared inventory."); }
void Buff(object sender, CommandEventArgs e) { if (e.length != 1 && e.length != 2) { PrintError("Syntax: buff <buff> [<time>]"); return; } Match match = Command.GetBuff(e[0]); if (match.ID > 0) { int time = 300; if (e.length == 2 && !int.TryParse(e[1], out time)) { PrintError("Invalid time."); return; } Main.currPlayer.AddBuff(match.ID, time * 60); PrintNotification("Buffed " + match.name + " for " + time + " seconds."); } }
static void Say(object sender, CommandEventArgs e) { if (e.plainText == "") { PrintError("No text to send."); return; } if (Main.multiplayer) { NetMessage.SendData(25, e.plainText.Substring(1)); } else { PrintError("Not connected to a server."); } }
static void Repeat(object sender, CommandEventArgs e) { if (Command.lastCommand == null) { PrintError("No last command."); return; } Command.Execute(Command.lastCommand); }
void Item(object sender, CommandEventArgs e) { if (e.length != 1 && e.length != 2) { PrintError("Syntax: item <item> [<stack>]"); return; } Match match = Command.GetItem(e[0]); if (match.ID > 0) { dynamic item = TerrariAPI.Hooking.Item.New(); item.SetDefaults(match.ID); int stack = item.maxStack; if (e.length == 2 && !int.TryParse(e[1], out stack)) { PrintError("Invalid stack size."); return; } int index = TerrariAPI.Hooking.Item.NewItem((int)Main.currPlayer.position.X, (int)Main.currPlayer.position.Y, Main.currPlayer.width, Main.currPlayer.height, match.ID, stack); Main.items[index] = Main.currPlayer.GetItem(Main.playerIndex, Main.items[index]); PrintNotification("Spawned " + stack + " " + match.name + "(s)."); } }
void God(object sender, CommandEventArgs e) { godMode = !godMode; PrintNotification((godMode ? "En" : "Dis") + "abled god mode."); }
void ItemPickup(object sender, CommandEventArgs e) { pickupItems = !pickupItems; PrintNotification((pickupItems ? "Dis" : "En") + "abled item pickups."); }
void GPS(object sender, CommandEventArgs e) { gps = !gps; PrintNotification((gps ? "En" : "Dis") + "abled GPS."); }
void ListInv(object sender, CommandEventArgs e) { if (e.length != 1) { PrintError("Syntax: listinv <player>"); return; } Match match = Command.GetPlayer(e[0]); if (match.ID >= 0) { for (int i = 0; i < Main.players[match.ID].inventory.Length; i++) { dynamic item = Main.players[match.ID].inventory[i]; PrintNotification("Index " + i + ": " + item.stack + " " + item.name + "."); } } }
void Heal(object sender, CommandEventArgs e) { PrintNotification("Healed " + (Main.currPlayer.statLifeMax - Main.currPlayer.statLife) + " HP."); if (Main.currPlayer.statLife != Main.currPlayer.statLifeMax) { for (int i = 0; i <= (Main.currPlayer.statLifeMax - Main.currPlayer.statLife) / 20; i++) { int index = TerrariAPI.Hooking.Item.NewItem((int)Main.currPlayer.position.X, (int)Main.currPlayer.position.Y, Main.currPlayer.width, Main.currPlayer.height, 58); } } }
void Noclip(object sender, CommandEventArgs e) { noclip = !noclip; PrintNotification((noclip ? "En" : "Dis") + "abled noclip."); }
void InfBuff(object sender, CommandEventArgs e) { if (e.length != 1 && e.length != 2) { PrintError("Syntax: infbuff <buff>"); return; } Match match = Command.GetBuff(e[0]); if (match.ID > 0) { infBuff[match.ID] = !infBuff[match.ID]; PrintNotification((infBuff[match.ID] ? "En" : "Dis") + "abled infinite buff for " + match.name + "."); } }
void Shoot(object sender, CommandEventArgs e) { if (e.length != 1) { PrintError("Syntax: shoot <projectile>"); return; } Match match = Command.GetProjectile(e[0]); if (match.ID >= 0) { Main.currItem.shoot = match.ID; PrintNotification("Set selected item to shoot " + match.name + "."); } }
void InfMana(object sender, CommandEventArgs e) { infMana = !infMana; PrintNotification((infMana ? "En" : "Dis") + "abled infinite mana."); }
void Tp(object sender, CommandEventArgs e) { if (e.length != 1) { PrintError("Syntax: tp <player>"); return; } Match match = Command.GetPlayer(e[0]); if (match.ID >= 0) { Main.currPlayer.position = Main.players[match.ID].position; NetMessage.SendData(13, "", Main.playerIndex); PrintNotification("Teleported to " + match.name + "."); } }
void InfRange(object sender, CommandEventArgs e) { bool infRange = Player.tileRangeX == 10000; infRange = !infRange; if (infRange) { Player.tileRangeX = Player.tileRangeY = 10000; } else { Player.tileRangeX = 5; Player.tileRangeY = 4; } PrintNotification((infRange ? "En" : "Dis") + "abled infinite range."); }
void Usetime(object sender, CommandEventArgs e) { if (e.length != 1) { PrintError("Syntax: usetime <time>"); return; } int useTime; if (!int.TryParse(e[0], out useTime)) { PrintError("Invalid usetime."); return; } Main.currItem.useTime = useTime; PrintNotification("Set selected item's usetime to " + useTime + "."); }
void InfWings(object sender, CommandEventArgs e) { infWings = !infWings; PrintNotification((infWings ? "En" : "Dis") + "abled infinite wings."); }
void AutoReuse(object sender, CommandEventArgs e) { Main.currItem.autoReuse = !Main.currItem.autoReuse; PrintNotification((Main.currItem.autoReuse ? "En" : "Dis") + "abled autoreuse for the selected item."); }
static void Macro(object sender, CommandEventArgs e) { if (e.length == 0) { PrintError("Syntax: macro <name> [<args>]"); return; } if (!File.Exists(e[0] + ".macro")) { PrintError("Invalid macro."); return; } string[] args = new string[e.length - 1]; for (int i = 0; i < args.Length; i++) { args[i] = e[i + 1]; } using (StreamReader reader = new StreamReader(e[0] + ".macro")) { string line; while ((line = reader.ReadLine()) != null) { Command.Execute(string.Format(line, args)); } } PrintNotification("Executed macro '" + e[0] + ".'"); }