// Attaches the DLL to the game.
        public static Boolean AttachToProcess(IntPtr hWnd)
        {
            // Load stored settings.
            SettingsHandler settings = SettingsHandler.GetInstance();

            // This is the process we will be looking for.
            String exe = settings.ExeName;

            // Get all running processes the user has access to.
            Process[] processes = Process.GetProcessesByName(exe);
            foreach (Process process in processes)
            {
                // We won't be able to use a process with no MainWindowHandle.
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    return(false);
                }

                InjectionHelper.processId = process.Id;
                InjectionHelper.process   = process;

                // Inject DLL into the game.
                try
                {
                    RemoteHooking.Inject(
                        process.Id,                                     // Process ID
                        InjectionOptions.Default,                       // InjectionOptions
                        typeof(DotaInjection).Assembly.Location,        // 32-bit DLL
                        typeof(DotaInjection).Assembly.Location,        // 64-bit DLL - Will never be used
                        // Optional parameters.
                        ChannelName,                                    // The name of the IPC channel for the injected assembly to connect to
                        hWnd                                            // A reference to the window handler. Used to create a DirectX device.
                        );
                }
                catch (System.IO.FileNotFoundException)
                {
                    // SlimDX is not installed, inform the user.
                    System.Windows.MessageBox.Show("It appears that SlimDX is not installed, please run the SlimDX installer found in the installation directory and then attempt to add the overlay again. You do NOT have to close this program.\n\nIt should be noted that the installation of SlimDX not always works. Make sure that Dota 2 is closed before attempting to install it.", "Couldn't add overlay");

                    return(false);
                }

                // The game can end up in a state where no user input is received until a double tab out of/into the game. The window is brought to front in order to avoid this.
                BringProcessWindowToFront(process);

                // Make sure that the overlay receives all the settings.
                settings.SendChangesToOverlay();

                return(true);
            }

            return(false);
        }
        // Called when DefaultButton has been clicked.
        private void DefaultButton_Click(object sender, EventArgs args)
        {
            // Check if we want to save this as a default adapter.
            if (AlwaysUseMain.IsChecked.Value)
            {
                // Save the default adapter.
                SettingsHandler handler = SettingsHandler.GetInstance();
                handler.DefaultAdapterMAC = DefaultAdapter.MAC.ToLower();
                handler.UseDefaultAdapter = true;
                handler.SaveSettings();
            }

            // Launch the program using the default adapter.
            LaunchProgram(DefaultAdapter.Index);
        }
Пример #3
0
        private static String requestURL = "http://translate.google.com/translate_a/single?client=t&sl=auto"; // Has to be appended with &hl=LANGUAGE, &tl=LANGUAGE, and &text=STRING"

        // Translates the specified string using an un-official Google Translate API.
        public static String TranslateString(String str)
        {
            SettingsHandler settings = SettingsHandler.GetInstance();

            try
            {
                // Encode the message for use in url.
                String encodedMessage  = Uri.EscapeDataString(str);
                String encodedLanguage = Uri.EscapeDataString(settings.TranslateTo);

                // Create an url.
                String url = requestURL + "&hl=" + encodedLanguage + "&tl=" + encodedLanguage + "&text=" + encodedMessage;

                // Create a request that looks like it came from a normal Google Translate session.
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Proxy     = null;                                                                       // Disable proxy lookup. Saves us around 7 seconds of waiting for one (which might not even exist).
                request.Host      = "translate.google.com";
                request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0"; // Mozilla Firefox 19.0. Windows 7 64-bit. Updated 23/2 - 2013.

                // Get the response.
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                // Read the data.
                Stream stream = response.GetResponseStream();
                String result = "";
                byte[] buf    = new byte[8192];
                int    count  = 0;
                while ((count = stream.Read(buf, 0, buf.Length)) > 0)
                {
                    result += Encoding.UTF8.GetString(buf, 0, count);
                }

                // Parse the received data as a JSON array.
                JArray arr = (JArray)JsonConvert.DeserializeObject(result);
                JValue translatedObject  = (JValue)((JArray)((JArray)arr[0])[0])[0]; //Them casts.
                String translatedMessage = (String)translatedObject.Value;

                return(translatedMessage);
            }
            catch
            {
                // An invalid message, non-existant translation language or network error could cause the main application to crash.
                // Return the original message if any of these erros occurred.

                return(str);
            }
        }
Пример #4
0
        // Constructor.
        public MainWindow(IntPtr devicePointer)
        {
            InitializeComponent();

            // Register window loaded listener.
            Loaded += Window_Loaded;

            // Register window closed listener.
            Closed += Window_Closed;

            // Load the program settings.
            Settings = SettingsHandler.GetInstance();

            // Start the packet capture.
            Device = devicePointer;
            PacketCaptureThread = new Thread(new ThreadStart(StartPacketCapture));
            PacketCaptureThread.Start();
        }
        // Called when SelectButton has been clicked.
        private void SelectButton_Click(object sender, EventArgs args)
        {
            // Check if an adapter has been selected.
            if (AvailableNetworkAdapters.SelectedIndex == -1)
            {
                MessageBox.Show("No adapter selected!");
                return;
            }

            // Start the program using the selected adapter.
            NetworkAdapterItem adapter = (NetworkAdapterItem)AvailableNetworkAdapters.SelectedItem;

            // Check if we want to save this as a default adapter.
            if (AlwaysUseAdvanced.IsChecked.Value)
            {
                // Save the selected adapter.
                SettingsHandler handler = SettingsHandler.GetInstance();
                handler.DefaultAdapterMAC = adapter.MAC;
                handler.UseDefaultAdapter = true;
                handler.SaveSettings();
            }

            LaunchProgram(adapter.AdapterIndex);
        }
        // Called when the window has been loaded.
        private void AdapterChooser_Loaded(object sender, EventArgs args)
        {
            // Check if we have a saved default adapter.
            SettingsHandler handler = SettingsHandler.GetInstance();

            if (handler.UseDefaultAdapter)
            {
                // Attempt to load the default adapter.
                HasDefaultAdapter = true;
                DefaultAdapterMAC = handler.DefaultAdapterMAC;
                LoadingDefaultLayout.Visibility = Visibility.Visible;
                MainLayout.Visibility           = Visibility.Collapsed;
            }

            // Register button listeners.
            DefaultButton.Click  += DefaultButton_Click;
            AdvancedButton.Click += AdvancedButton_Click;
            SelectButton.Click   += SelectButton_Click;

            // Load network devices.
            Thread t = new Thread(new ThreadStart(LoadAdapters));

            t.Start();
        }