Пример #1
0
        // Static access to SettingsHandler.SendChangesToOverlay().
        public static void SendToOverlay()
        {
            // Make sure there is an instance available.
            GetInstance();

            // Send the changes to the overlay.
            Instance.SendChangesToOverlay();
        }
        // 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);
        }