public void Swap(Client client, SlotObject sobj1, SlotObject sobj2, bool all = false) { //Console.WriteLine("Swap called with {0} and {1}", sobj1.SlotId, sobj2.SlotId); InvSwapPacket invSwapPacket = (InvSwapPacket)Packet.Create(PacketType.INVSWAP); invSwapPacket.Time = client.Time; invSwapPacket.Position = client.PlayerData.Pos; invSwapPacket.SlotObject1 = sobj1; invSwapPacket.SlotObject2 = sobj2; client.SendToServer(invSwapPacket); if (all) { if (sobj1.SlotId < 11) { PluginUtils.Delay(600, () => { Swap(client, new SlotObject { ObjectId = client.ObjectId, SlotId = (byte)(sobj1.SlotId + 1), ObjectType = client.PlayerData.Slot[sobj1.SlotId + 1] }, new SlotObject { ObjectId = client.ObjectId, SlotId = (byte)(sobj1.SlotId + 9), ObjectType = client.PlayerData.BackPack[(sobj1.SlotId + 1) - 4] }, true); }); } } }
public void CancelTimerStart() { PluginUtils.Delay(30000, new Action(() => { if (this.InTrade) { client.SendToServer(Packet.Create(PacketType.CANCELTRADE)); InTrade = false; } })); }
private static void GiveItemRetry(PZClient giver, PZClient reciever, PZItem item, int start, int no) { int na = no + 1; bool[] sel = PZClient.GetToSel(giver.client, item); RequestTradePacket req = (RequestTradePacket)Packet.Create(PacketType.REQUESTTRADE); req.Name = reciever.ToString(); giver.client.SendToServer(req); req.Name = giver.ToString(); reciever.client.SendToServer(req); ChangeTradePacket cht = (ChangeTradePacket)Packet.Create(PacketType.CHANGETRADE); cht.Offers = sel; giver.client.SendToServer(cht); AcceptTradePacket atpkt = (AcceptTradePacket)Packet.Create(PacketType.ACCEPTTRADE); atpkt.MyOffers = sel; atpkt.YourOffers = new bool[12]; giver.client.SendToServer(atpkt); atpkt.MyOffers = new bool[12]; atpkt.YourOffers = sel; reciever.client.SendToServer(atpkt); Console.WriteLine(giver.ToString() + " gave " + item + " to " + reciever); PluginUtils.Delay(2000, new Action(() => { int now = reciever.CountItem(item.ID); int addition = now - start; if (addition < item.amount) { Console.WriteLine("[ERROR]" + (item.amount - addition) + " " + item.ActualName() + " failed to be recieved so trying again"); if (na <= 7) { PluginUtils.Delay(500, new Action(() => GiveItemRetry(giver, reciever, item, start, na))); } else { Console.WriteLine("Tried over 7 times, give up!"); } } else { Console.WriteLine("Recieve success!"); PluginUtils.Delay(500, new Action(() => { giver.enabled = true; reciever.enabled = true; reciever.spamenabled = true; giver.spamenabled = true; })); } })); na++; }
private void OnCreateSuccess(Client client, Packet packet) { if (_enabled) { PluginUtils.Delay(2100, () => client.SendToClient(PluginUtils.CreateOryxNotification( "Auto Ability", "Use your ability to Activate Auto Ability"))); } }
private void OnCreateSuccess(Client client, CreateSuccessPacket packet) { PluginUtils.Delay(1000, () => { string message = "Welcome to K Relay!"; string server = ""; if (GameData.GameData.Servers.Map.Where(s => s.Value.Address == client.State.ConTargetAddress).Any()) { server = GameData.GameData.Servers.Match(s => s.Address == client.State.ConTargetAddress).Name; } if (server != "") { message += "\\n" + server; } client.SendToClient(PluginUtils.CreateNotification(client.ObjectId, message)); }); }
public void OnTradeStart(Client client, Packet packet) { TradeStartPacket start = (TradeStartPacket)packet; if (_Enabled[client] && _Started[client]) { Console.WriteLine("Trade Started with \"" + start.YourName + "\""); //CurrentTrade = new Trade(client, start); CurrentTrades[client] = new Trade(client, start); //if (CurrentTrade.HasItems()) if (CurrentTrades[client].HasItems()) { Console.WriteLine("Have Item!"); // Wait 30 seconds and then cancel the trade if it is still going PluginUtils.Delay(30000, new Action(() => { if (CurrentTrades[client].isTrading) { client.SendToServer(Packet.Create(PacketType.CANCELTRADE)); CurrentTrades[client].isTrading = false; Console.WriteLine("Canceling Trade Due To Time!"); } })); } else { Console.WriteLine("No Have Item!"); // Wait 4 seconds and then cancel the trade PluginUtils.Delay(4000, new Action(() => { if (CurrentTrades[client].isTrading) { client.SendToServer(Packet.Create(PacketType.CANCELTRADE)); CurrentTrades[client].isTrading = false; Console.WriteLine("Canceling Trade Due To Missing Items!"); } })); } } }
private void OnUpdate(Client client, UpdatePacket p) { // If the plugin is enabled, player is on a new map and the client is connected if (enabled && newMap && client.Connected) { // Correct map if (currentMapName == "Nexus Explanation") { // Start moving towards the target on a background thread Log("Starting to move"); new Task(() => MoveToTarget(client)).Start(); } // Any other map else { // There needs to be some delay before the teleport to avoid an exception in K-Relay Log("Teleporting to Nexus Explanation"); PluginUtils.Delay(1000, () => client?.SendChatMessage("/nexustutorial")); } // This is no longer a new map newMap = false; } }
private void OnUpdate(Client client, Packet p) { UpdatePacket packet = p as UpdatePacket; foreach (Entity obj in packet.NewObjs) { if (Enum.IsDefined(typeof(Classes), (short)obj.ObjectType)) { PlayerData playerData = new PlayerData(obj.Status.ObjectId); playerData.Class = (Classes)obj.ObjectType; playerData.Pos = obj.Status.Position; foreach (var data in obj.Status.Data) { playerData.Parse(data.Id, data.IntValue, data.StringValue); } if (playerData.Stars < Settings.Default.starsToCluster) { continue; } if (playerPositions.ContainsKey(obj.Status.ObjectId)) { playerPositions.Remove(obj.Status.ObjectId); } playerPositions.Add(obj.Status.ObjectId, new Target(obj.Status.ObjectId, playerData.Name, playerData.Pos)); } if (obj.ObjectType == 1810) { foreach (var data in obj.Status.Data) { if (data.StringValue != null) { string pattern = @"\.(\w+) \((\d+)"; var match = Regex.Match(data.StringValue, pattern); var portal = new Portal(obj.Status.ObjectId, int.Parse(match.Groups[2].Value), match.Groups[1].Value, obj.Status.Position); if (portals.Exists(ptl => ptl.ObjectId == obj.Status.ObjectId)) { portals.RemoveAll(ptl => ptl.ObjectId == obj.Status.ObjectId); } portals.Add(portal); } } } if (currentMapName != "Nexus" /*&& Settings.Default.walkToBags*/) { if ( (obj.ObjectType == Orange || obj.ObjectType == OrangeBoosted || obj.ObjectType == Red || obj.ObjectType == RedBoosted || obj.ObjectType == Blue || obj.ObjectType == BlueBoosted || obj.ObjectType == Gold || obj.ObjectType == GoldBoosted || obj.ObjectType == White || obj.ObjectType == WhiteBoosted)) { followTarget = false; targets.Clear(); target_ = obj.Status.Position; gotoRealm = true; MoveToRealms(connectedClient); PluginUtils.Delay(3000, () => followTarget = true); PluginUtils.Delay(3000, () => gotoRealm = false); PluginUtils.Delay(3000, () => followTarget = true); } } if (Enum.IsDefined(typeof(EnemyId), (int)obj.ObjectType) && config.EnableEnemyAvoidance) { if (enemies.Exists(en => en.ObjectId == obj.Status.ObjectId)) { enemies.RemoveAll(en => en.ObjectId == obj.Status.ObjectId); } enemies.Add(new Enemy(obj.Status.ObjectId, obj.Status.Position)); } if (obstacleIds.Contains(obj.ObjectType)) { if (!obstacles.Exists(obstacle => obstacle.ObjectId == obj.Status.ObjectId)) { obstacles.Add(new Obstacle(obj.Status.ObjectId, obj.Status.Position)); } } } foreach (int dropId in packet.Drops) { if (playerPositions.ContainsKey(dropId)) { if (followTarget && targets.Exists(t => t.ObjectId == dropId)) { targets.Remove(targets.Find(t => t.ObjectId == dropId)); Log(string.Format("Dropping \"{0}\" from targets.", playerPositions[dropId].Name)); if (targets.Count == 0) { Log("No targets left in target list."); if (config.EscapeIfNoTargets) { Escape(client); } } } playerPositions.Remove(dropId); } if (enemies.Exists(en => en.ObjectId == dropId)) { enemies.RemoveAll(en => en.ObjectId == dropId); } if (portals.Exists(ptl => ptl.ObjectId == dropId)) { portals.RemoveAll(ptl => ptl.ObjectId == dropId); } } }
public void Initialize(Proxy proxy) { targets = new List <Target> (); playerPositions = new Dictionary <int, Target> (); portals = new List <Portal> (); enemies = new List <Enemy> (); obstacles = new List <Obstacle> (); obstacleIds = new List <ushort> (); GameData.Objects.Map.ForEach((kvp) => { if (kvp.Value.FullOccupy || kvp.Value.OccupySquare) { obstacleIds.Add(kvp.Key); } }); PluginUtils.Log("FameBot", "Found {0} obstacles.", obstacleIds.Count); gui = new FameBotGUI(); PluginUtils.ShowGUI(gui); config = ConfigManager.GetConfiguration(); Process[] processes = Process.GetProcessesByName(config.FlashPlayerName); if (processes.Length == 1) { Log("Automatically bound to client."); flashPtr = processes[0].MainWindowHandle; gui?.SetHandle(flashPtr); if (config.AutoConnect) { Start(); } } else if (processes.Length > 1) { Log("Multiple flash players running. Use the /bind command on the client you want to use."); } else { Log("Couldn't find flash player. Use the /bind command in game, then start the bot."); } #region Proxy Hooks proxy.HookCommand("bind", ReceiveCommand); proxy.HookCommand("start", ReceiveCommand); proxy.HookCommand("gui", ReceiveCommand); proxy.HookCommand("famebot", ReceiveCommand); proxy.HookCommand("stop1", ReceiveCommand); proxy.HookCommand("options", ReceiveCommand); proxy.HookPacket(PacketType.RECONNECT, OnReconnect); proxy.HookPacket(PacketType.UPDATE, OnUpdate); proxy.HookPacket(PacketType.NEWTICK, OnNewTick); proxy.HookPacket(PacketType.PLAYERHIT, OnHit); proxy.HookPacket(PacketType.MAPINFO, OnMapInfo); proxy.HookPacket(PacketType.TEXT, OnText); proxy.HookPacket(PacketType.GOTOACK, (client, packet) => { if (blockNextAck) { packet.Send = false; blockNextAck = false; } }); #endregion proxy.ClientConnected += (client) => { connectedClient = client; targets.Clear(); playerPositions.Clear(); enemies.Clear(); obstacles.Clear(); followTarget = false; isInNexus = false; ResetAllKeys(); }; proxy.ClientDisconnected += (client) => { Log("Client disconnected. Waiting a few seconds before trying to press play..."); PressPlay(); }; guiEvent += (evt) => { switch (evt) { case GuiEvent.StartBot: Start(); break; case GuiEvent.StopBot: Stop(); break; case GuiEvent.SettingsChanged: Log("Updated config"); config = ConfigManager.GetConfiguration(); break; } }; sendMessage += (message) => { if (!(connectedClient?.Connected ?? false)) { return; } PlayerTextPacket packet = (PlayerTextPacket)Packet.Create(PacketType.PLAYERTEXT); packet.Text = message; connectedClient.SendToServer(packet); }; proxy.HookPacket(PacketType.FAILURE, (client, packet) => { FailurePacket p = packet as FailurePacket; if (p.ErrorId != 9) { Console.WriteLine("<FAILURE> ID: " + p.ErrorId + " Message: " + p.ErrorMessage); } if (p.ErrorMessage == "{\"key\":\"server.realm_full\"}") { Attempts++; if (Attempts >= 2 && bestName != "") { _bestName = bestName; ReconnectPacket reconnect = (ReconnectPacket)Packet.Create(PacketType.RECONNECT); reconnect.Name = "{\"text\":\"server.realm_of_the_mad_god\"}"; reconnect.Host = ""; reconnect.Stats = ""; reconnect.Port = -1; reconnect.GameId = -3; reconnect.KeyTime = -1; reconnect.IsFromArena = false; reconnect.Key = new byte[0]; connectedClient.SendToClient(reconnect); Attempts = 0; loopingforrealm = true; } } }); proxy.HookPacket(PacketType.CREATESUCCESS, (client, packet) => { target_ = null; if (enabled) { PluginUtils.Delay(200, () => Stop()); PluginUtils.Delay(500, () => Stop()); PluginUtils.Delay(1300, () => Stop()); PluginUtils.Delay(2200, () => Start()); } }); }
private void inventorySwap(byte itemSlot) { if (DateTime.Now < lastSwapTime.AddSeconds(2)) { return; } lastSwapTime = DateTime.Now; hotswapping = true; byte equipSlotId = 0; if (_client.PlayerData.Slot[(int)itemSlot] == -1) { return; } switch (GameData.Items.ByID((ushort)_client.PlayerData.Slot[(int)itemSlot]).SlotType) { case 1: case 2: case 3: case 8: case 17: case 24: equipSlotId = 0; break; case 6: case 7: case 14: equipSlotId = 2; break; case 4: case 5: case 11: case 12: case 13: case 15: case 16: case 18: case 19: case 20: case 21: case 22: case 23: case 25: case 27: equipSlotId = 1; break; case 9: equipSlotId = 3; break; } InvSwapPacket invSwap = (InvSwapPacket)Packet.Create(PacketType.INVSWAP); invSwap.Time = _client.Time + 10; invSwap.Position = _client.PlayerData.Pos; invSwap.SlotObject1 = new SlotObject(); invSwap.SlotObject1.ObjectId = _client.ObjectId; invSwap.SlotObject1.SlotId = equipSlotId; invSwap.SlotObject1.ObjectType = _client.PlayerData.Slot[(int)equipSlotId]; invSwap.SlotObject2 = new SlotObject(); invSwap.SlotObject2.ObjectId = _client.ObjectId; invSwap.SlotObject2.SlotId = itemSlot; invSwap.SlotObject2.ObjectType = _client.PlayerData.Slot[(int)itemSlot]; _client.SendToServer(invSwap); PluginUtils.Delay(1000, () => { hotswapping = false; }); }