Esempio n. 1
0
        private void ReceiveCommand(Client client, string cmd, string[] args)
        {
            switch (cmd)
            {
            case "bind":
                flashPtr = GetForegroundWindow();
                gui?.SetHandle(flashPtr);
                client.Notify("FameBot is now active");
                break;

            case "start":
                Start();
                client.Notify("FameBot is starting");
                break;

            case "gui":
                if (gui == null)
                {
                    gui = new FameBotGUI();
                }
                gui.Show();
                gui.SetHandle(flashPtr);
                break;
            }
        }
Esempio n. 2
0
        public void Initialize(Proxy proxy)
        {
            // Initialize lists so they are empty instead of null.
            targets = new List <Target>();

            playerPositions = new Dictionary <int, Target>();
            portals         = new List <Portal>();
            enemies         = new List <Enemy>();
            rocks           = new List <Rock>();

            // Initialize and display gui.
            gui = new FameBotGUI();
            PluginUtils.ShowGUI(gui);

            // Get the config.
            config = ConfigManager.GetConfiguration();

            // Look for all processes with the name "flash.exe".
            Process[] processes = Process.GetProcessesByName("flash");
            if (processes.Length == 1)
            {
                // If there is one client open, bind to it.
                Log("Automatically bound to client.");
                flashPtr = processes[0].MainWindowHandle;
                gui?.SetHandle(flashPtr);
                if (config.AutoConnect)
                {
                    Start();
                }
            }
            // If there are multiple or no clients running, log a message.
            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.HookPacket(PacketType.UPDATE, OnUpdate);
            proxy.HookPacket(PacketType.NEWTICK, OnNewTick);
            proxy.HookPacket(PacketType.PLAYERHIT, OnHit);
            proxy.HookPacket(PacketType.MAPINFO, OnMapInfo);
            proxy.HookPacket(PacketType.TEXT, OnText);
            #endregion

            // Runs every time a client connects.
            proxy.ClientConnected += (client) =>
            {
                // Clear all lists and reset keys.
                connectedClient = client;
                targets.Clear();
                playerPositions.Clear();
                enemies.Clear();
                rocks.Clear();
                followTarget = false;
                isInNexus    = false;
                A_PRESSED    = false;
                D_PRESSED    = false;
                W_PRESSED    = false;
                S_PRESSED    = false;
            };

            // Runs every time a client disconnects.
            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:
                    config = ConfigManager.GetConfiguration();
                    break;
                }
            };

            // Send an in game message when the gui fires the event.
            sendMessage += (message) =>
            {
                if (!(connectedClient?.Connected ?? false))
                {
                    return;
                }
                PlayerTextPacket packet = (PlayerTextPacket)Packet.Create(PacketType.PLAYERTEXT);
                packet.Text = message;
                connectedClient.SendToServer(packet);
            };
        }
Esempio n. 3
0
        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());
                }
            });
        }
Esempio n. 4
0
        private void ReceiveCommand(Client client, string cmd, string[] args)
        {
            switch (cmd)
            {
            case "bind":
                flashPtr = WinApi.GetForegroundWindow();

                try {
                    var flashProcess = Process.GetProcesses().Single(p => p.Id != 0 && p.MainWindowHandle == flashPtr);
                    if (flashProcess.ProcessName != config.FlashPlayerName)
                    {
                        gui?.ShowChangeFlashNameMessage(flashProcess.ProcessName, config.FlashPlayerName, () => {
                            config.FlashPlayerName = flashProcess.ProcessName;
                            client.Notify("Updated config!");
                            ConfigManager.WriteXML(config);
                        });
                    }
                } catch {
                }

                gui?.SetHandle(flashPtr);
                client.Notify("FameBot is now active");
                break;

            case "start":
                Start();
                client.Notify("FameBot is starting");
                break;

            case "stop1":
                Stop();
                client.Notify("FameBot is stopping");
                break;

            case "gui":
                gui?.Close();
                gui = new FameBotGUI();
                gui.Show();
                break;

            case "options":
                PluginUtils.ShowGenericSettingsGUI(Settings.Default, "Bot Settings");
                break;

            case "famebot":
                if (args.Length >= 1)
                {
                    if (string.Compare("set", args[0], true) == 0)
                    {
                        if (args.Length < 2 || string.IsNullOrEmpty(args[1]))
                        {
                            client.Notify("No argument to set was provided");
                            return;
                        }
                        var setting = args[1].ToLower();
                        switch (setting)
                        {
                        case "realmposition":
                        case "rp":
                            config.RealmLocation = client.PlayerData.Pos;
                            ConfigManager.WriteXML(config);
                            client.Notify("Successfully changed realm position!");
                            break;

                        case "fountainposition":
                        case "fp":
                            config.FountainLocation = client.PlayerData.Pos;
                            ConfigManager.WriteXML(config);
                            client.Notify("Successfully changed fountain position!");
                            break;

                        default:
                            client.Notify("Unrecognized setting.");
                            break;
                        }
                    }
                    if (string.Compare("prefer", args[0], true) == 0)
                    {
                        if (args.Length < 2 || string.IsNullOrEmpty(args[1]))
                        {
                            client.Notify("No realm name was provided");
                            return;
                        }
                        preferredRealmName = args[1];
                        client.Notify("Set preferred realm to " + args[1]);
                    }
                }
                break;
            }
        }
Esempio n. 5
0
        public void Initialize(Proxy proxy)
        {
            // Initialize lists so they are empty instead of null.
            targets         = new List <Target>();
            playerPositions = new Dictionary <int, Target>();
            portals         = new List <Portal>();
            enemies         = new List <Enemy>();
            obstacles       = new List <Obstacle>();

            // get obstacles
            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);

            // Initialize and display gui.
            gui = new FameBotGUI();
            PluginUtils.ShowGUI(gui);

            // Initialize and display gui if K-Relay is not in stealth mode.
            if (!StealthConfig.Default.StealthEnabled)
            {
                ShowGUI();
            }

            // Hide / show gui based on the stealth mode status.
            proxy.StealthStateChanged += enabled => { if (enabled)
                                                      {
                                                          HideGUI();
                                                      }
                                                      else
                                                      {
                                                          ShowGUI();
                                                      } };

            // Get the config.
            config = ConfigManager.GetConfiguration();

            // Look for all processes with the configured flash player name.
            Process[] processes = Process.GetProcessesByName(config.FlashPlayerName);
            if (processes.Length == 1)
            {
                // If there is one client open, bind to it.
                Log("Automatically bound to client.");
                flashPtr = processes[0].MainWindowHandle;
                gui?.SetHandle(flashPtr);
                if (config.AutoConnect)
                {
                    Start();
                }
            }
            // If there are multiple or no clients running, log a message.
            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.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

            // Runs every time a client connects.
            proxy.ClientConnected += (client) =>
            {
                // Clear all lists and reset keys.
                connectedClient = client;
                targets.Clear();
                playerPositions.Clear();
                enemies.Clear();
                obstacles.Clear();
                followTarget = false;
                isInNexus    = false;
                ResetAllKeys();
            };

            // Runs every time a client disconnects.
            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;
                }
            };

            // Send an in game message when the gui fires the event.
            sendMessage += (message) =>
            {
                if (!(connectedClient?.Connected ?? false))
                {
                    return;
                }
                PlayerTextPacket packet = (PlayerTextPacket)Packet.Create(PacketType.PLAYERTEXT);
                packet.Text = message;
                connectedClient.SendToServer(packet);
            };
        }