Example #1
0
        public GameControl(GenericGameInfo game, UserGameInfo userGame)
        {
            GameInfo     = game;
            UserGameInfo = userGame;

            picture          = new PictureBox();
            picture.SizeMode = PictureBoxSizeMode.StretchImage;

            title = new Label();
            if (game == null)
            {
                title.Text = "No games";
            }
            else
            {
                title.Text = GameInfo.GameName;
            }

            BackColor = Color.FromArgb(30, 30, 30);
            Size      = new Size(200, 52);

            Controls.Add(picture);
            Controls.Add(title);

            DPIManager.Register(this);
        }
Example #2
0
        public HookPipe(IntPtr hWnd, Window window, bool needWritePipe, Action onClosed, GenericGameInfo gameInfo)
        {
            pipeNameRead = GenerateName();
            if (needWritePipe)
            {
                pipeNameWrite = GenerateName();
            }
            sharedMemName = pipeNameRead + "_mem";

            this.hWnd     = hWnd;
            this.window   = window;
            this.onClosed = onClosed;
            this.gameInfo = gameInfo;

            serverThread = new Thread(Start);
            serverThread.IsBackground = true;
            serverThread.Start();

            if (needWritePipe)
            {
                receiveThread = new Thread(ReceiveMessages);
                receiveThread.IsBackground = true;
                receiveThread.Start();
            }

            StartSharedMemory();
        }
Example #3
0
        public BackupFile BackupFile(GenericGameInfo game, string path)
        {
            string appData     = GetAppDataPath();
            string gamePath    = Path.Combine(appData, game.GUID);
            string destination = Path.Combine(gamePath, Path.GetFileName(path));

            if (!File.Exists(path))
            {
                if (File.Exists(destination))
                {
                    // we f****d up and the backup exists? maybe, so restore
                    File.Copy(destination, path);
                }
            }
            else
            {
                if (File.Exists(destination))
                {
                    File.Delete(destination);
                }
                File.Copy(path, destination);
            }

            BackupFile bkp = new BackupFile(path, destination);

            backupFiles.Add(bkp);

            return(bkp);
        }
Example #4
0
        /// <summary>
        /// Initializes the User Game Info with known information from a game,
        /// and the path to the game's executable in the end user machine
        /// </summary>
        /// <param name="game">A reference to the </param>
        /// <param name="exePath"></param>
        public void InitializeDefault(GenericGameInfo game, string exePath)
        {
            this.game = game;
            gameGUID  = game.GUID;

            this.exePath  = exePath;
            this.profiles = new List <GameProfile>();
        }
Example #5
0
        public void BeginBackup(GenericGameInfo game)
        {
            string appData  = GetAppDataPath();
            string gamePath = Path.Combine(appData, game.GUID);

            Directory.CreateDirectory(gamePath);

            backupFiles = new List <BackupFile>();
        }
Example #6
0
        public UserGameInfo AddGame(GenericGameInfo game, string exePath)
        {
            UserGameInfo gInfo = new UserGameInfo();

            gInfo.InitializeDefault(game, exePath);
            user.Games.Add(gInfo);

            SaveUserProfile();

            return(gInfo);
        }
Example #7
0
        public GameControl(GenericGameInfo game, UserGameInfo userGame)
        {
            GameInfo     = game;
            UserGameInfo = userGame;

            picture          = new PictureBox();
            picture.SizeMode = PictureBoxSizeMode.StretchImage;

            playerIcon          = new PictureBox();
            playerIcon.SizeMode = PictureBoxSizeMode.StretchImage;
            playerIcon.Image    = Gaming.Properties.Resources.players;

            numPlayersTt = new ToolTip();
            numPlayersTt.SetToolTip(playerIcon, "Number of players");

            title        = new Label();
            title.Font   = new Font("Segoe UI", 11, FontStyle.Bold);
            players      = new Label();
            players.Font = new Font("Segoe UI", 9);
            if (game == null)
            {
                title.Text   = "No games";
                players.Text = string.Empty;
                title.Font   = new Font("Segoe UI", 11, FontStyle.Regular);
            }
            else
            {
                title.Text = GameInfo.GameName;
                if (GameInfo.MaxPlayers > 2)
                {
                    players.Text = "2-" + GameInfo.MaxPlayers;
                }
                else
                {
                    players.Text = GameInfo.MaxPlayers.ToString();
                }
                //players.Text = "Players: " + GameInfo.MaxPlayers;
            }
            TitleText  = title.Text;
            PlayerText = players.Text;

            BackColor = Color.FromArgb(30, 30, 30);
            Size      = new Size(200, 52);

            Controls.Add(picture);
            Controls.Add(title);
            Controls.Add(players);
            Controls.Add(playerIcon);

            DPIManager.Register(this);
        }
Example #8
0
        private void list_Games_SelectedChanged(object arg1, Control arg2)
        {
            currentControl  = (GameControl)arg1;
            currentGameInfo = currentControl.UserGameInfo;
            if (currentGameInfo == null)
            {
                btn_delete.Visible     = false;
                btn_details.Visible    = false;
                btn_openScript.Visible = false;
                btn_open_data.Visible  = false;
                return;
            }

            StepPanel.Visible = true;

            currentGame = currentGameInfo.Game;

            btn_Play.Enabled = false;

            stepsList = new List <UserInputControl>();
            stepsList.Add(positionsControl);
            stepsList.Add(optionsControl);
            for (int i = 0; i < currentGame.CustomSteps.Count; i++)
            {
                stepsList.Add(jsControl);
            }

            currentProfile = new GameProfile();
            currentProfile.InitializeDefault(currentGame);

            gameNameControl.GameInfo = currentGameInfo;

            btn_delete.Location     = new Point(384 + (gameNameControl.Width - 100), 39);
            btn_delete.Visible      = true;
            btn_details.Location    = new Point(384 + (gameNameControl.Width - 100), 8);
            btn_details.Visible     = true;
            btn_openScript.Location = new Point(450 + (gameNameControl.Width - 100), 8);
            btn_openScript.Visible  = true;
            btn_open_data.Location  = new Point(450 + (gameNameControl.Width - 100), 39);
            btn_open_data.Visible   = true;

            if (content != null)
            {
                content.Dispose();
            }

            // contnet manager is shared withing the same game
            content = new ContentManager(currentGame);
            GoToStep(0);
        }
Example #9
0
        public static void InjectRuntime(
            bool easyHookMethod,
            bool easyHookStealthMethod,
            bool remoteLoadLibMethod,
            uint pid,
            string dllFolderPath,
            int instanceIndex,
            GenericGameInfo gen,
            PlayerInfo player,
            int mouseHandle      = -1,
            int keyboardHandle   = -1,
            int controllerIndex  = 0,
            int controllerIndex2 = 0,
            int controllerIndex3 = 0,
            int controllerIndex4 = 0
            )
        {
            if (!dllFolderPath.EndsWith("\\"))
            {
                dllFolderPath += "\\";
            }

            uint instanceHandle = 0;

            if (easyHookStealthMethod)
            {
                instanceHandle = ProtoInput.protoInput.EasyHookStealthInjectRuntime(pid, dllFolderPath);
            }
            else if (easyHookMethod)
            {
                instanceHandle = ProtoInput.protoInput.EasyHookInjectRuntime(pid, dllFolderPath);
            }
            else if (remoteLoadLibMethod)
            {
                instanceHandle = ProtoInput.protoInput.RemoteLoadLibraryInjectRuntime(pid, dllFolderPath);
            }

            if (instanceHandle == 0)
            {
                MessageBox.Show("ProtoInput failed to runtime inject", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            {
                SetupInstance(instanceHandle, instanceIndex, gen, player, mouseHandle, keyboardHandle,
                              controllerIndex, controllerIndex2, controllerIndex3, controllerIndex4);
            }
        }
Example #10
0
        /// <summary>
        /// Tries adding a game to the collection with the provided IGameInfo
        /// </summary>
        /// <param name="exePath"></param>
        /// <returns></returns>
        public UserGameInfo TryAddGame(string exePath, GenericGameInfo game)
        {
            string lower = exePath.ToLower();

            // search for the same exe on the user profile
            if (GameManager.Instance.User.Games.Any(c => c.ExePath.ToLower() == lower))
            {
                return(null);
            }

            Log.WriteLine($"Found game: {game.GameName}, full path: {exePath}");
            UserGameInfo uinfo = new UserGameInfo();

            uinfo.InitializeDefault(game, exePath);
            GameManager.Instance.User.Games.Add(uinfo);
            GameManager.Instance.SaveUserProfile();

            return(uinfo);
        }
Example #11
0
        public void ExecuteBackup(GenericGameInfo game)
        {
            // we didnt backup anything
            if (backupFiles == null)
            {
                return;
            }

            string appData  = GetAppDataPath();
            string gamePath = Path.Combine(appData, game.GUID);

            for (int i = 0; i < backupFiles.Count; i++)
            {
                BackupFile bkp = backupFiles[i];
                if (File.Exists(bkp.BackupPath))
                {
                    File.Delete(bkp.Source);
                    File.Move(bkp.BackupPath, bkp.Source);
                }
            }
        }
Example #12
0
        public void InitializeDefault(GenericGameInfo game)
        {
            if (playerData == null)
            {
                playerData = new List <PlayerInfo>();
            }

            if (screens == null)
            {
                screens = new List <UserScreen>();
            }

            if (options == null)
            {
                options = new Dictionary <string, object>();

                foreach (var opt in game.Options)
                {
                    options.Add(opt.Key, opt.Value);
                }
            }
        }
Example #13
0
        public static void InjectStartup(
            string exePath,
            string commandLine,
            uint processCreationFlags,
            string dllFolderPath,
            int instanceIndex,
            GenericGameInfo gen,
            PlayerInfo player,
            out uint pid,
            IntPtr environment,
            int mouseHandle      = -1,
            int keyboardHandle   = -1,
            int controllerIndex  = 0,
            int controllerIndex2 = 0,
            int controllerIndex3 = 0,
            int controllerIndex4 = 0
            )
        {
            if (!dllFolderPath.EndsWith("\\"))
            {
                dllFolderPath += "\\";
            }

            uint instanceHandle = ProtoInput.protoInput.EasyHookInjectStartup(exePath, commandLine, 0, dllFolderPath, out pid, environment);

            if (instanceHandle == 0)
            {
                MessageBox.Show("ProtoInput failed to startup inject", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            {
                SetupInstance(instanceHandle, instanceIndex, gen, player, mouseHandle, keyboardHandle, controllerIndex, controllerIndex2, controllerIndex3, controllerIndex4);

                ProtoInput.protoInput.WakeUpProcess(instanceHandle);
            }
        }
Example #14
0
 public IGameHandler MakeHandler(GenericGameInfo game)
 {
     return((IGameHandler)Activator.CreateInstance(game.HandlerType));
 }
Example #15
0
 private void Con_Click(object sender, EventArgs e)
 {
     clicked       = ((GameControl)sender).GameInfo;
     btnOk.Enabled = true;
 }
Example #16
0
        private void SearchDrive(object state)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            try
            {
                for (int i = 0; i < pathsToSearch.Count; i++)
                {
                    txt_Stage.Text = i + 1 + " of " + pathsToSearch.Count;
                    string currentPath = pathsToSearch[i];

                    float totalDiskPc = 1 / (float)pathsToSearch.Count;
                    float thirdDiskPc = totalDiskPc / 3.0f;

                    // 1/3 done, we started the operation
                    UpdateProgress(thirdDiskPc);

                    List <string> result = new List <string>();
                    //if(IsElevated)
                    //{
                    //result = Directory.EnumerateFiles(currentPath, "*.exe", SearchOption.AllDirectories).ToList();
                    //result = Directory.GetFiles(currentPath, "*.exe", SearchOption.AllDirectories).ToList();
                    //}
                    //else
                    //{
                    //result = GetFiles(currentPath).ToList();
                    //}


                    //result = GetFiles(currentPath, "*.exe").ToList();
                    result = GetFiles(currentPath).ToList();


                    float increment = thirdDiskPc / result.Count;

                    foreach (string exeFilePath in result)
                    {
                        if (closed)
                        {
                            return;
                        }

                        //UpdateProgress(increment);

                        if (GameManager.Instance.User.Games.Any(c => c.ExePath.ToLower() == exeFilePath.ToLower()))
                        {
                            continue;
                        }

                        if (GameManager.Instance.AnyGame(Path.GetFileName(exeFilePath).ToLower()))
                        {
                            if (exeFilePath.Contains("$Recycle.Bin") ||
                                exeFilePath.Contains(@"\Instance"))
                            {
                                // noope
                                continue;
                            }

                            GenericGameInfo uinfo = GameManager.Instance.GetGame(exeFilePath);

                            if (uinfo != null)
                            {
#if RELEASE
                                if (uinfo.Game.Debug)
                                {
                                    continue;
                                }
#endif
                                //LogManager.Log("> Found new game {0} on drive {1}", uinfo.Game.GameName, info.drive.Name);
                                Invoke(new Action(delegate
                                {
                                    bool exists = false;
                                    foreach (var item in checkboxFoundGames.Items)
                                    {
                                        if (item.ToString() == uinfo.GameName + " | " + exeFilePath)
                                        {
                                            exists = true;
                                        }
                                    }
                                    if (!exists)
                                    {
                                        checkboxFoundGames.Items.Add(uinfo.GameName + " | " + exeFilePath, true);
                                        checkboxFoundGames.Refresh();
                                    }
                                }));
                            }
                        }
                    }

                    if (closed)
                    {
                        return;
                    }
                }

                searching      = false;
                btnSearch.Text = "Search";


                watch.Stop();

                var elapsedMs = watch.ElapsedMilliseconds / 1000;

                if (checkboxFoundGames.Items.Count == 0)
                {
                    btn_customPath.Enabled = true;
                    btn_delPath.Enabled    = true;
                    disksBox.Enabled       = true;

                    MessageBox.Show("Operation completed in " + elapsedMs + "s. No new games found.");
                    progressBar1.Value = 0;
                    return;
                }

                progress = 1;
                UpdateProgress(0);
                btn_addSelection.Enabled   = true;
                btn_selectAll.Enabled      = true;
                btn_deselectAll.Enabled    = true;
                checkboxFoundGames.Enabled = true;
                btnSearch.Enabled          = false;
                label2.Enabled             = true;
                label1.Enabled             = false;
                txt_Stage.Text             = "Done";
                txt_Path.Text = "";
                Refresh();
                Invalidate();
                MessageBox.Show("Search has completed, operation took " + elapsedMs + "s. Select the games you wish to add from the right-hand side.", "Search finished");
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                MessageBox.Show(ex.Message);
            }
        }
Example #17
0
        static void StartGame(string path, string args = "", string workingDir = null)
        {
            System.IO.Stream str = new System.IO.MemoryStream();
            GenericGameInfo  gen = new GenericGameInfo(null, null, str);

            if (!Path.IsPathRooted(path))
            {
                string root = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                path = Path.Combine(root, path);
            }

            int tri = 0;
            ProcessStartInfo startInfo;

            startInfo           = new ProcessStartInfo();
            startInfo.FileName  = path;
            startInfo.Arguments = args;

            if (!string.IsNullOrWhiteSpace(workingDir))
            {
                startInfo.WorkingDirectory = workingDir;
            }

#if RELEASE
            try
#endif
            {
                //proc = Process.Start(startInfo);
                string currDir = Directory.GetCurrentDirectory();

                //bool is64 = EasyHook.RemoteHooking.IsX64Process((int)pi.dwProcessId);

                if (isHook || renameMutex || setWindow)
                {
                    var targetsBytes       = Encoding.Unicode.GetBytes(mutexToRename);
                    int targetsBytesLength = targetsBytes.Length;
                    int size = 7 + targetsBytesLength;
                    var data = new byte[size];
                    data[0] = isHook == true ? (byte)1 : (byte)0;
                    data[1] = renameMutex == true ? (byte)1 : (byte)0;
                    data[2] = setWindow == true ? (byte)1 : (byte)0;

                    data[3] = (byte)(targetsBytesLength >> 24);
                    data[4] = (byte)(targetsBytesLength >> 16);
                    data[5] = (byte)(targetsBytesLength >> 8);
                    data[6] = (byte)targetsBytesLength;

                    Array.Copy(targetsBytes, 0, data, 7, targetsBytesLength);

                    IntPtr ptr = Marshal.AllocHGlobal(size);
                    Marshal.Copy(data, 0, ptr, size);

                    if (!isDelay) // CreateandInject method
                    {
                        if (Is64Bit(path) == true)
                        {
                            try
                            {
                                IntPtr pid = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(uint)));
                                RhCreateAndInject(path, args, 0, 0, Path.Combine(currDir, "Nucleus.SHook32.dll"), Path.Combine(currDir, "Nucleus.SHook64.dll"), ptr, (uint)size, pid);
                                pOutPID = Marshal.ReadInt32(pid);
                                Marshal.FreeHGlobal(pid);
                            }
                            catch (Exception ex)
                            {
                                using (StreamWriter writer = new StreamWriter("error-log.txt", true))
                                {
                                    writer.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]" + "ex msg: {0}, ex str: {1}", ex.Message, ex.ToString());
                                }
                            }
                        }
                        else if (Is64Bit(path) == false)
                        {
                            try
                            {
                                //pidTest = gen.Inject(path, args, 0, 0, Path.Combine(currDir, "Nucleus.Hook32.dll"), null, IntPtr.Zero, 0);
                                string           injectorPath = Path.Combine(currDir, "Nucleus.Inject32.exe");
                                ProcessStartInfo injstartInfo = new ProcessStartInfo();
                                injstartInfo.FileName = injectorPath;
                                object[] injargs = new object[]
                                {
                                    0, path, args, 0, 0, Path.Combine(currDir, "Nucleus.SHook32.dll"), null, isHook, renameMutex, mutexToRename, setWindow
                                };
                                var sbArgs = new StringBuilder();
                                foreach (object arg in injargs)
                                {
                                    sbArgs.Append(" \"");
                                    sbArgs.Append(arg);
                                    sbArgs.Append("\"");
                                }

                                string arguments = sbArgs.ToString();
                                injstartInfo.Arguments = arguments;
                                //injstartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                                //injstartInfo.CreateNoWindow = true;
                                injstartInfo.UseShellExecute        = false;
                                injstartInfo.RedirectStandardOutput = true;

                                Process injectProc = Process.Start(injstartInfo);
                                injectProc.OutputDataReceived += proc_OutputDataReceived;
                                injectProc.BeginOutputReadLine();

                                //using (StreamWriter writer = new StreamWriter("important.txt", true))
                                //{
                                //    writer.WriteLine("readtoend: {0}, readline: {1}", injectProc.StandardOutput.ReadToEnd(), injectProc.StandardOutput.ReadLine());
                                //}


                                injectProc.WaitForExit();

                                //GenericGameHandler.RhCreateAndInject(path, args, 0, 0, Path.Combine(currDir, "Nucleus.Hook32.dll"), Path.Combine(currDir, "Nucleus.Hook64.dll"), IntPtr.Zero, 0, pid);
                                //pidTest = Nucleus.Injector32.Injector32.RhCreateAndInject(path, args, 0, 0, Path.Combine(currDir, "Nucleus.Hook32.dll"), Path.Combine(currDir, "Nucleus.Hook64.dll"), IntPtr.Zero, 0, pid);
                            }
                            catch (Exception ex)
                            {
                                using (StreamWriter writer = new StreamWriter("error-log.txt", true))
                                {
                                    writer.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]" + "is64: false, ex msg: {0}, ex str: {1}", ex.Message, ex.ToString());
                                }
                            }
                        }
                        else
                        {
                            using (StreamWriter writer = new StreamWriter("error-log.txt", true))
                            {
                                writer.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]" + "Machine type: '{0}' not implemented.", GetDllMachineType(path));
                            }
                        }
                    }
                    else // delay method
                    {
                        string              directoryPath = Path.GetDirectoryName(path);
                        STARTUPINFO         si            = new STARTUPINFO();
                        PROCESS_INFORMATION pi            = new PROCESS_INFORMATION();
                        bool success = CreateProcess(path, args, IntPtr.Zero, IntPtr.Zero, false, ProcessCreationFlags.CREATE_SUSPENDED, IntPtr.Zero, directoryPath, ref si, out pi);

                        if (!success)
                        {
                            using (StreamWriter writer = new StreamWriter("error-log.txt", true))
                            {
                                writer.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]" + "createprocess failed - startGamePath: {0}, startArgs: {1}, dirpath: {2}", path, args, directoryPath);
                            }
                            return;
                        }

                        ResumeThread(pi.hThread);

                        WaitForInputIdle(pi.hProcess, uint.MaxValue);

                        SuspendThread(pi.hThread);

                        if (Is64Bit(path) == true)
                        {
                            NativeAPI.RhInjectLibrary((int)pi.dwProcessId, 0, 0, null, Path.Combine(currDir, "Nucleus.Hook64.dll"), ptr, size);
                            pOutPID = (int)pi.dwProcessId;
                        }
                        else if (Is64Bit(path) == false)
                        {
                            try
                            {
                                string           injectorPath = Path.Combine(currDir, "Nucleus.Inject32.exe");
                                ProcessStartInfo injstartInfo = new ProcessStartInfo();
                                injstartInfo.FileName = injectorPath;
                                object[] injargs = new object[]
                                {
                                    1, (int)pi.dwProcessId, 0, 0, Path.Combine(currDir, "Nucleus.SHook32.dll"), null, isHook, renameMutex, mutexToRename, setWindow
                                };
                                var sbArgs = new StringBuilder();
                                foreach (object arg in injargs)
                                {
                                    sbArgs.Append(" \"");
                                    sbArgs.Append(arg);
                                    sbArgs.Append("\"");
                                }

                                string arguments = sbArgs.ToString();
                                injstartInfo.Arguments = arguments;
                                //injstartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                                //injstartInfo.CreateNoWindow = true;
                                injstartInfo.UseShellExecute        = false;
                                injstartInfo.RedirectStandardOutput = true;
                                Process injectProc = Process.Start(injstartInfo);
                                //injectProc.OutputDataReceived += proc_OutputDataReceived;
                                //injectProc.BeginOutputReadLine();

                                //using (StreamWriter writer = new StreamWriter("important.txt", true))
                                //{
                                //    writer.WriteLine("readtoend: {0}, readline: {1}", injectProc.StandardOutput.ReadToEnd(), injectProc.StandardOutput.ReadLine());
                                //}


                                injectProc.WaitForExit();
                            }
                            catch (Exception ex)
                            {
                                using (StreamWriter writer = new StreamWriter("error-log.txt", true))
                                {
                                    writer.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]" + "ex msg: {0}, ex str: {1}", ex.Message, ex.ToString());
                                }
                            }
                        }
                        ResumeThread(pi.hThread);
                        pOutPID = (int)pi.dwProcessId;
                    }
                }
                else // regular method (no hooks)
                {
                    proc = Process.Start(startInfo);

                    pOutPID = proc.Id;
                }

                ConsoleU.WriteLine("Game started, process ID:" + pOutPID /*Marshal.ReadInt32(pid)*/ /*proc.Id*/ /*(int)pi.dwProcessId*/, Palette.Success);
            }
#if RELEASE
            catch
            {
                tri++;
                if (tri < tries)
                {
                    ConsoleU.WriteLine("Failed to start process. Retrying...");
                    StartGame(path, args);
                }
            }
#endif
        }
Example #18
0
        private static void SetupInstance(uint instanceHandle, int instanceIndex, GenericGameInfo gen, PlayerInfo player, int mouseHandle, int keyboardHandle, int controllerIndex, int controllerIndex2, int controllerIndex3, int controllerIndex4)
        {
            Debug.WriteLine("Setting up ProtoInput instance " + instanceIndex);

            player.ProtoInputInstanceHandle = instanceHandle;

            ProtoInput.protoInput.SetupState(instanceHandle, instanceIndex);

            if (gen.ProtoInput.RegisterRawInputHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.RegisterRawInputHookID);
            }
            if (gen.ProtoInput.GetRawInputDataHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.GetRawInputDataHookID);
            }
            if (gen.ProtoInput.MessageFilterHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.MessageFilterHookID);
            }
            if (gen.ProtoInput.GetCursorPosHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.GetCursorPosHookID);
            }
            if (gen.ProtoInput.SetCursorPosHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.SetCursorPosHookID);
            }
            if (gen.ProtoInput.GetKeyStateHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.GetKeyStateHookID);
            }
            if (gen.ProtoInput.GetAsyncKeyStateHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.GetAsyncKeyStateHookID);
            }
            if (gen.ProtoInput.GetKeyboardStateHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.GetKeyboardStateHookID);
            }

            ProtoInput.protoInput.SetShowCursorWhenImageUpdated(instanceHandle, !gen.ProtoInput.DontShowCursorWhenImageUpdated);
            if (gen.ProtoInput.CursorVisibilityHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.CursorVisibilityStateHookID);
            }

            ProtoInput.protoInput.SetCursorClipOptions(instanceHandle, gen.ProtoInput.ClipCursorHookCreatesFakeClip);
            if (gen.ProtoInput.ClipCursorHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.ClipCursorHookID);
            }

            if (gen.ProtoInput.FocusHooks)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.FocusHooksHookID);
            }
            if (gen.ProtoInput.RenameHandlesHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.RenameHandlesHookID);
            }
            if (gen.ProtoInput.BlockRawInputHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.BlockRawInputHookID);
            }
            if (gen.ProtoInput.FindWindowHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.FindWindowHookID);
            }

            ProtoInput.protoInput.SetCreateSingleHIDName(instanceHandle, player.RawHID);
            if (gen.ProtoInput.CreateSingleHIDHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.CreateSingleHIDHookID);
            }

            if (gen.ProtoInput.SetWindowStyleHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.WindowStyleHookID);
            }

            ProtoInput.protoInput.SetUseOpenXinput(instanceHandle, gen.ProtoInput.UseOpenXinput);
            ProtoInput.protoInput.SetUseDinputRedirection(instanceHandle, gen.ProtoInput.UseDinputRedirection);
            if (gen.ProtoInput.XinputHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.XinputHookID);
            }

            if (player.IsDInput)
            {
                ProtoInput.protoInput.SetDinputDeviceGUID(instanceHandle, player.GamepadGuid);
            }
            if (gen.ProtoInput.DinputHookAlsoHooksGetDeviceState)
            {
                ProtoInput.protoInput.SetDinputHookAlsoHooksGetDeviceState(instanceHandle, true);
            }
            if (gen.ProtoInput.DinputDeviceHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.DinputOrderHookID);
            }

            ProtoInput.protoInput.SetSetWindowPosSettings(instanceHandle, player.MonitorBounds.X, player.MonitorBounds.Y, player.MonitorBounds.Width, player.MonitorBounds.Height);
            if (gen.ProtoInput.SetWindowPosHook)
            {
                ProtoInput.protoInput.InstallHook(instanceHandle, ProtoInput.ProtoHookIDs.SetWindowPosHookID);
            }

            if (gen.ProtoInput.RawInputFilter)
            {
                ProtoInput.protoInput.EnableMessageFilter(instanceHandle, ProtoInput.ProtoMessageFilterIDs.RawInputFilterID);
            }
            if (gen.ProtoInput.MouseMoveFilter)
            {
                ProtoInput.protoInput.EnableMessageFilter(instanceHandle, ProtoInput.ProtoMessageFilterIDs.MouseMoveFilterID);
            }
            if (gen.ProtoInput.MouseActivateFilter)
            {
                ProtoInput.protoInput.EnableMessageFilter(instanceHandle, ProtoInput.ProtoMessageFilterIDs.MouseActivateFilterID);
            }
            if (gen.ProtoInput.WindowActivateFilter)
            {
                ProtoInput.protoInput.EnableMessageFilter(instanceHandle, ProtoInput.ProtoMessageFilterIDs.WindowActivateFilterID);
            }
            if (gen.ProtoInput.WindowActvateAppFilter)
            {
                ProtoInput.protoInput.EnableMessageFilter(instanceHandle, ProtoInput.ProtoMessageFilterIDs.WindowActivateAppFilterID);
            }
            if (gen.ProtoInput.MouseWheelFilter)
            {
                ProtoInput.protoInput.EnableMessageFilter(instanceHandle, ProtoInput.ProtoMessageFilterIDs.MouseWheelFilterID);
            }
            if (gen.ProtoInput.MouseButtonFilter)
            {
                ProtoInput.protoInput.EnableMessageFilter(instanceHandle, ProtoInput.ProtoMessageFilterIDs.MouseButtonFilterID);
            }
            if (gen.ProtoInput.KeyboardButtonFilter)
            {
                ProtoInput.protoInput.EnableMessageFilter(instanceHandle, ProtoInput.ProtoMessageFilterIDs.KeyboardButtonFilterID);
            }

            if (gen.ProtoInput.BlockedMessages != null)
            {
                foreach (uint blockedMessage in gen.ProtoInput.BlockedMessages)
                {
                    ProtoInput.protoInput.EnableMessageBlock(instanceHandle, blockedMessage);
                }
            }

            ProtoInput.protoInput.SetupMessagesToSend(instanceHandle,
                                                      gen.ProtoInput.SendMouseWheelMessages,
                                                      gen.ProtoInput.SendMouseButtonMessages,
                                                      gen.ProtoInput.SendMouseMovementMessages,
                                                      gen.ProtoInput.SendKeyboardButtonMessages);

            if (gen.ProtoInput.EnableFocusMessageLoop)
            {
                ProtoInput.protoInput.StartFocusMessageLoop(instanceHandle,
                                                            gen.ProtoInput.FocusLoopIntervalMilliseconds,
                                                            gen.ProtoInput.FocusLoop_WM_ACTIVATE,
                                                            gen.ProtoInput.FocusLoop_WM_ACTIVATEAPP,
                                                            gen.ProtoInput.FocusLoop_WM_NCACTIVATE,
                                                            gen.ProtoInput.FocusLoop_WM_SETFOCUS,
                                                            gen.ProtoInput.FocusLoop_WM_MOUSEACTIVATE);
            }

            ProtoInput.protoInput.SetDrawFakeCursor(instanceHandle, gen.ProtoInput.DrawFakeCursor);
            ProtoInput.protoInput.AllowFakeCursorOutOfBounds(instanceHandle, gen.ProtoInput.AllowFakeCursorOutOfBounds, gen.ProtoInput.ExtendFakeCursorBounds);
            ProtoInput.protoInput.SetToggleFakeCursorVisibilityShortcut(instanceHandle,
                                                                        gen.ProtoInput.EnableToggleFakeCursorVisibilityShortcut,
                                                                        gen.ProtoInput.ToggleFakeCursorVisibilityShortcutVkey);

            if (gen.ProtoInput.RenameHandles != null)
            {
                foreach (string renameHandle in gen.ProtoInput.RenameHandles)
                {
                    ProtoInput.protoInput.AddHandleToRename(instanceHandle, renameHandle);
                }
            }

            if (gen.ProtoInput.RenameNamedPipes != null)
            {
                foreach (string renamePipe in gen.ProtoInput.RenameNamedPipes)
                {
                    ProtoInput.protoInput.AddNamedPipeToRename(instanceHandle, renamePipe);
                }
            }

            if (mouseHandle != -1)
            {
                ProtoInput.protoInput.AddSelectedMouseHandle(instanceHandle, (uint)mouseHandle);
            }

            if (keyboardHandle != -1)
            {
                ProtoInput.protoInput.AddSelectedKeyboardHandle(instanceHandle, (uint)keyboardHandle);
            }

            ProtoInput.protoInput.SetControllerIndex(instanceHandle,
                                                     controllerIndex < 0 ? 0 : (uint)controllerIndex,
                                                     controllerIndex2 < 0 ? 0 : (uint)controllerIndex2,
                                                     controllerIndex3 < 0 ? 0 : (uint)controllerIndex3,
                                                     controllerIndex4 < 0 ? 0 : (uint)controllerIndex4
                                                     );

            //SetExternalFreezeFakeInput(instanceHandle, !isInputCurrentlyLocked && freezeGameInputWhileInputNotLocked);

            trackedInstanceHandles.Add(instanceHandle);

            if (gen.ProtoInput.FreezeExternalInputWhenInputNotLocked)
            {
                NotifyInputLockChange();
            }
        }
Example #19
0
        private void GamepadTimer_Tick(object sender, EventArgs e)
        {
            List <PlayerInfo> data = profile.PlayerData;
            bool changed           = false;

            GenericGameInfo g = game.Game;

            if (g.Hook.DInputEnabled ||
                g.Hook.XInputReroute)
            {
                IList <DeviceInstance> devices = dinput.GetDevices(SlimDX.DirectInput.DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly);

                // first search for disconnected gamepads
                for (int j = 0; j < data.Count; j++)
                {
                    PlayerInfo p = data[j];
                    if (!p.IsDInput || p.IsFake)
                    {
                        continue;
                    }

                    //if (!p.DInputJoystick.Acquire().IsFailure)
                    //{
                    //    if (!p.DInputJoystick.Poll().IsFailure)
                    //    {
                    //        JoystickState state = p.DInputJoystick.GetCurrentState();
                    //    }
                    //}

                    bool foundGamepad = false;
                    for (int i = 0; i < devices.Count; i++)
                    {
                        DeviceInstance device = devices[i];
                        if (device.InstanceGuid == p.GamepadGuid)
                        {
                            foundGamepad = true;
                            break;
                        }
                    }

                    if (!foundGamepad)
                    {
                        changed = true;
                        data.RemoveAt(j);
                        j--;
                    }
                }

                for (int i = 0; i < devices.Count; i++)
                {
                    DeviceInstance device  = devices[i];
                    bool           already = false;


                    // see if this gamepad is already on a player
                    for (int j = 0; j < data.Count; j++)
                    {
                        PlayerInfo p = data[j];
                        if (p.GamepadGuid == device.InstanceGuid)
                        {
                            already = true;
                            break;
                        }
                    }

                    if (already)
                    {
                        continue;
                    }

                    changed = true;

                    // new gamepad
                    PlayerInfo player = new PlayerInfo();
                    player.GamepadProductGuid = device.ProductGuid;
                    player.GamepadGuid        = device.InstanceGuid;
                    player.GamepadName        = device.InstanceName;
                    player.IsDInput           = true;
                    player.DInputJoystick     = new Joystick(dinput, device.InstanceGuid);

                    //data.Add(player);
                    data.Insert(0, player);
                }
            }

            if (g.Hook.XInputEnabled && !g.Hook.XInputReroute)
            {
                // XInput is only really enabled inside Nucleus Coop when
                // we have 4 or less players, else we need to force DirectInput to grab everything

                for (int j = 0; j < data.Count; j++)
                {
                    PlayerInfo p = data[j];
                    if (p.IsXInput)
                    {
                        Controller c = xinputControllers[p.GamepadId];
                        if (!c.IsConnected)
                        {
                            changed = true;
                            data.RemoveAt(j);
                            j--;
                        }
                    }
                }

                for (int i = 0; i < 4; i++)
                {
                    Controller c       = xinputControllers[i];
                    bool       already = false;

                    if (c.IsConnected)
                    {
                        // see if this gamepad is already on a player
                        for (int j = 0; j < data.Count; j++)
                        {
                            PlayerInfo p = data[j];
                            if (p.IsXInput && p.GamepadId == i)
                            {
                                State s       = c.GetState();
                                int   newmask = (int)s.Gamepad.Buttons;
                                if (p.GamepadMask != newmask)
                                {
                                    changed       = true;
                                    p.GamepadMask = newmask;
                                }

                                already = true;
                                break;
                            }
                        }
                        if (already)
                        {
                            continue;
                        }

                        changed = true;

                        // new gamepad
                        PlayerInfo player = new PlayerInfo();
                        player.IsXInput  = true;
                        player.GamepadId = i;
                        data.Add(player);
                    }
                }
            }

            if (changed)
            {
                UpdatePlayers();
                Refresh();
            }
        }
Example #20
0
        public string GempTempFolder(GenericGameInfo game)
        {
            string appData = GetAppDataPath();

            return(Path.Combine(appData, game.GUID));
        }