Beispiel #1
0
        public static bool KillMutex(Process process, string mutexName)
        {
            // 4 tries
            for (int i = 1; i < 4; i++)
            {
                Console.WriteLine("Loop " + i);
                var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\", mutexName);
                if (handles.Count == 0)
                {
                    continue;
                }

                foreach (var handle in handles)
                {
                    IntPtr ipHandle = IntPtr.Zero;
                    if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE))
                    {
                        Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error());
                    }

                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        public static bool KillMutex(Process process, string mutexName)
        {
            bool killed = false;

            for (int i = 1; i < 3; i++)
            {
                var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\" + i + "\\BaseNamedObjects\\" + mutexName);
                if (handles.Count == 0)
                {
                    continue;
                }
                foreach (var handle in handles)
                {
                    IntPtr ipHandle = IntPtr.Zero;
                    if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE))
                    {
                        Debug.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error());
                    }

                    Debug.WriteLine("Mutex was killed");
                    killed = true;
                }
            }

            return(killed);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            List <Process> procs = Win32Processes.GetProcessesLockingFile("\\Device\\0000003a");

            foreach (var proc in procs)
            {
                Console.WriteLine(proc.ProcessName);
            }
            Console.ReadLine();
        }
Beispiel #4
0
        public static bool MutexExists(Process process, string mutexType, string mutexName, bool partial)
        {
            Log(string.Format("Checking if mutex '{0}' of type '{1}' exists in process '{2} (pid {3})'", mutexName, mutexType, process.MainWindowTitle, process.Id));
            // 4 tries
            for (int i = 0; i < 4; i++)
            {
                try
                {
                    var handles = Win32Processes.GetHandles(process, mutexType, "", mutexName);

                    if (partial)
                    {
                        bool foundHandle = false;

                        foreach (var handle in handles)
                        {
                            string strObjectName = Win32Processes.getObjectName(handle, Process.GetProcessById(handle.ProcessID));
                            if (!string.IsNullOrWhiteSpace(strObjectName) && strObjectName.Contains(mutexName))
                            {
                                Log(string.Format("Found mutex that contains search criteria. Located at {0}", strObjectName));
                                if (!foundHandle)
                                {
                                    foundHandle = true;
                                }
                            }
                        }

                        return(foundHandle);
                    }
                    else
                    {
                        if (handles.Count > 0)
                        {
                            Log("Found the following mutexes:");
                            foreach (var handle in handles)
                            {
                                string strObjectName = Win32Processes.getObjectName(handle, Process.GetProcessById(handle.ProcessID));
                                Log(strObjectName);
                            }

                            return(true);
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    Log(string.Format("The process name '{0}' is not currently running", process.MainWindowTitle));
                }
                catch (ArgumentException)
                {
                    Log(string.Format("The mutex '{0}' was not found in the process '{1}'", mutexName, process.MainWindowTitle));
                }
            }
            return(false);
        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            // IF THIS DOESNT WORK FOR YOU THEN THIS IS THE PROBLEM
            // var handles = Win32Processes.GetHandles(p, "Mutant", "\\Sessions\\4\\BaseNamedObjects\\" + MutexToRemove);
            // SEE WHERE IT SAYS 4, THIS IS NOT MATCHING THE NUMBER ON YOUR COMPUTER
            // YOU CAN FIND THIS NUMBER USING PROCESS EXPLORER, CHOOSING GAME.BIN, CLICKING CTRL+H AND SCROLLING DOWN A BIT

            // TODO: AUTOMAGICALLY FETCH THE CORRECT SESSION NUMBER XD
            // UPDATE: USE FUNCTION 'determineSession' to automagically get the right string to work with

            String MutexToRemove = "FFClientTag";

            Process[] activeP;


            while (_started == true)
            {
                activeP = Process.GetProcessesByName("game.bin");

                foreach (Process p in activeP)
                {
                    var handles = Win32Processes.GetHandles(p, "Mutant", "\\Sessions\\4\\BaseNamedObjects\\" + MutexToRemove);
                    if (handles.Count < 1)
                    {
                        // ignore
                        // SIMPLY IGNORE OUR PROBLEMS
                    }
                    else
                    {
                        foreach (var handle in handles)
                        {
                            try
                            {
                                IntPtr ipHandle = IntPtr.Zero;
                                if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE))
                                {
                                    Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error());
                                    continue;
                                }

                                //Console.WriteLine(String.Format("Mutex {0} was removed from process '{1}' with PID {2}.\n", MutexToRemove, p.ProcessName, p.Id));
                                listBox1.Items.Add(String.Format("Mutex {0} was removed from process '{1}' with PID {2}.\n", MutexToRemove, p.ProcessName, p.Id));
                            } catch (Exception)
                            {
                                // do nothing
                                // SHITTY ERROR HANDLING
                            }
                        }
                    }
                }
                System.Threading.Thread.Sleep(500); // lets let this bitch rest sum xDDD
            } // END WHILE
        }
Beispiel #6
0
 public static bool MutexExists(Process process, string mutexName)
 {
     // 4 tries
     for (int i = 0; i < 4; i++)
     {
         try {
             var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\", mutexName);
             if (handles.Count > 0)
             {
                 return(true);
             }
         } catch (IndexOutOfRangeException) {
         } catch (ArgumentException) {
         }
     }
     return(false);
 }
        string determineSession()
        {
            String  foundSession;
            Process p = Process.GetProcessesByName("game.bin")[0];

            for (int i = 0; i < 11; i++) // you can make it check for a million session ids, but its probably not gonna be more than 10 xd
            {
                var handles = Win32Processes.GetHandles(p, "Directory", "\\Sessions\\" + i + "\\BaseNamedObjects");
                if (handles.Count > 0)
                {
                    foundSession = "\\Sessions\\" + i + "\\BaseNamedObjects\\";
                    return(foundSession);
                }
            }

            return("n/a");
        }
        public static bool SerializeXML(string path, bool compress, MyObjectBuilder_Base objectBuilder, out ulong sizeInBytes, Type serializeAsType = null)
        {
            try
            {
                using (var fileStream = MyFileSystem.OpenWrite(path))
                    using (var writeStream = compress ? fileStream.WrapGZip() : fileStream)
                    {
                        long          startPos   = fileStream.Position;
                        XmlSerializer serializer = m_serializersByType[serializeAsType ?? objectBuilder.GetType()];
                        serializer.Serialize(writeStream, objectBuilder);
                        sizeInBytes = (ulong)(fileStream.Position - startPos); // Length of compressed stream
                    }
            }
            catch (Exception e)
            {
                MyLog.Default.WriteLine("Error: " + path + " failed to serialize.");
                MyLog.Default.WriteLine(e.ToString());

#if !XB1
#if DEBUG
                var io = e as IOException;
                if (io != null && io.IsFileLocked())
                {
                    MyLog.Default.WriteLine("Files is locked during saving.");
                    MyLog.Default.WriteLine("Xml file locks:");
                    try
                    {
                        foreach (var p in Win32Processes.GetProcessesLockingFile(path))
                        {
                            MyLog.Default.WriteLine(p.ProcessName);
                        }
                    }
                    catch (Exception e2)
                    {
                        MyLog.Default.WriteLine(e2);
                    }
                }
#endif
#endif // !XB1

                sizeInBytes = 0;

                return(false);
            }
            return(true);
        }
        public static bool MutexExists(Process process, string mutexName)
        {
#if WINDOWS
            // 4 tries
            for (int i = 0; i < 4; i++)
            {
                try {
                    var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\", mutexName);
                    if (handles.Count > 0)
                    {
                        return(true);
                    }
                } catch (IndexOutOfRangeException) {
                } catch (ArgumentException) {
                }
            }
            return(false);
#else
            throw new PlatformNotSupportedException();
#endif
        }
Beispiel #10
0
        public static bool KillMutex(Process process, string mutexName)
        {
            var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\", mutexName);

            if (handles.Count == 0)
            {
                return(false);
            }

            foreach (Win32API.SYSTEM_HANDLE_INFORMATION handle in handles)
            {
                IntPtr ipHandle = IntPtr.Zero;
                if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, (IntPtr)handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE))
                {
                    Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error());
                }
                return(true);
            }

            return(false);
        }
Beispiel #11
0
 public static bool MutexExists(Process process, string mutexName)
 {
     // TODO: Does only 1-3 exist? I've only seen these values in the Sessions
     for (int i = 1; i < 3; i++)
     {
         try
         {
             var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\", mutexName);
             if (handles.Count > 0)
             {
                 return(true);
             }
         }
         catch (IndexOutOfRangeException)
         {
         }
         catch (ArgumentException)
         {
         }
     }
     return(false);
 }
Beispiel #12
0
        static void Main(string[] args)
        {
            var ids         = GetCameraIds();
            var machineName = System.Environment.MachineName;
            var ipAddress   = getIP();
            var cameraNames = new List <string>();
            var url         = args.Length > 0 ? args[0] : "";

            List <KeyValuePair <string, Process> > procs = Win32Processes.GetProcessesLockingFile("svchost,atmgr", ids);//"svchost,zoom"

            foreach (var proc in procs)
            {
                Console.WriteLine($"{proc.Key},{proc.Value.ProcessName}");
                cameraNames.Add(proc.Key);
            }

            if (cameraNames.Count > 0)
            {
                object data = new { MachineName = machineName, IPAddress = ipAddress, CameraNames = string.Join(",", cameraNames), TimeStamp = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") };

                try
                {
                    if (!string.IsNullOrEmpty(url))
                    {
                        using (WebClient wc = new WebClient())
                        {
                            var postData = new JavaScriptSerializer().Serialize(data);
                            wc.UploadData(new Uri(url), "POST", Encoding.ASCII.GetBytes(postData));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                    log.Error(new JavaScriptSerializer().Serialize(ex));
                }
                log.Info($"Active Camera(s) Found - {new JavaScriptSerializer().Serialize(data)}");
            }
        }
Beispiel #13
0
        public static bool KillMutex(Process process, string mutexName)
        {
            // session can change ?!?!?! wtf, can have value of 1 or 2
            bool killed = false;

            for (int i = 1; i < 3; i++)
            {
                try
                {
                    var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\" + i + "\\BaseNamedObjects\\" + mutexName);
                    if (handles.Count == 0)
                    {
                        throw new System.ArgumentException("NoMutex", "original");
                    }
                    foreach (var handle in handles)
                    {
                        IntPtr ipHandle = IntPtr.Zero;
                        if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE))
                        {
                            Debug.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error());
                        }

                        Debug.WriteLine("Mutex was killed");
                        killed = true;
                    }
                }
                catch (IndexOutOfRangeException)
                {
                }
                catch (ArgumentException)
                {
                }
            }

            return(killed);
        }
Beispiel #14
0
        public ServerProgram()
        {
            IntPtr  multibotProcess = RosController.GetForegroundWindow();
            string  pathToFile      = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents\\RoS-BoT\\Logs\\logs.txt");
            Process RosBotProcess   = Win32Processes.GetProcessesLockingFile(pathToFile).FirstOrDefault();

            Console.WriteLine("Starting Server Controller");
            ServerController server = new ServerController();

            server.pathToLogFile   = pathToFile;
            server.rosbotProcess   = RosBotProcess;
            server.multibotProcess = multibotProcess;
            server.GetRosRect();
            Console.WriteLine("Choose Port: "); // Prompt
            int serverportInput = Convert.ToInt32(Console.ReadLine());

            server.port = serverportInput;
            Console.WriteLine("Starting Server TCP");
            bool serverStarting = true;

            while (serverStarting)
            {
                try
                {
                    server.StartServerTCP();
                    try
                    {
                        serverStarting = !server.tcpServer.IsStarted;
                    }
                    catch
                    { serverStarting = true; }
                }
                catch
                {
                    Console.WriteLine("Failed to start server TCP, press key to try again");
                    Console.ReadLine();
                }
            }
            Console.WriteLine("Starting Game Modules");
            server.StartModules();
            Console.WriteLine("All modules started: reading game states");
            Console.WriteLine("Server Ready to start, client can connect and start now");

            Thread gameStateDecider = new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        server.gameState.UpdateGameState();
                        if (server.gameState.inMenu & server.rosController.failed)
                        {
                            RosController.BlockInput();
                            Console.WriteLine("Sleeping 20s");
                            Thread.Sleep(20000);
                            Console.WriteLine("Done");
                            server.rosController.InitVariables();
                            RosController.UnBlockInput();
                        }

                        if (server.gameState.acceptgrUiVisible)
                        {
                            // grift accept request: always click cancel
                            server.rosController.Pause();
                            server.rosController.enteredRift = false;
                            var xCoord = server.gameState.acceptgrUiControl.uirect.TranslateToClientRect(server.gameState.clientWidth, server.gameState.clientHeight).Left +
                                         (server.gameState.acceptgrUiControl.uirect.TranslateToClientRect(server.gameState.clientWidth, server.gameState.clientHeight).Width / 2);
                            var yCoord = server.gameState.acceptgrUiControl.uirect.TranslateToClientRect(server.gameState.clientWidth, server.gameState.clientHeight).Top +
                                         (server.gameState.acceptgrUiControl.uirect.TranslateToClientRect(server.gameState.clientWidth, server.gameState.clientHeight).Height * 1.5);
                            RosController.SetCursorPos((int)xCoord, (int)yCoord);
                            RosController.LeftClick();
                            Console.WriteLine("Accept Rift Dialog Detected: Click Cancel");
                        }

                        if (server.gameState.cancelgriftUiVisible)
                        {
                            //click cancel ok
                            server.rosController.Pause();
                            var xCoord = server.gameState.confirmationUiControl.uirect.TranslateToClientRect(server.gameState.clientWidth, server.gameState.clientHeight).Left +
                                         (server.gameState.confirmationUiControl.uirect.TranslateToClientRect(server.gameState.clientWidth, server.gameState.clientHeight).Width / 2);
                            var yCoord = server.gameState.confirmationUiControl.uirect.TranslateToClientRect(server.gameState.clientWidth, server.gameState.clientHeight).Top +
                                         (server.gameState.confirmationUiControl.uirect.TranslateToClientRect(server.gameState.clientWidth, server.gameState.clientHeight).Height / 2);
                            RosController.SetCursorPos((int)xCoord, (int)yCoord);
                            RosController.LeftClick();
                            Console.WriteLine("Rift Cancelled Dialog Detected: Click Cancel");
                        }

                        if (!server.rosController.enteredRift & server.gameState.firstlevelRift & !server.gameState.inMenu & !server.gameState.isLoading & !server.gameState.aloneInGame)
                        {
                            //unpause after entering rift and reinit variables
                            Thread.Sleep(1500);
                            server.rosController.enteredRift = true;
                            server.rosController.Unpause();
                            server.rosController.InitVariables();
                            Console.WriteLine("First Floor Rift Detected: Unpausing and Reiniting variables");
                        }

                        if (server.gameState.haveUrshiActor)
                        {
                            //set Urshi state
                            server.rosController.didUrshi = true;
                            //send have urushi to other if didnt yet
                            if (!server.rosController.sentUrshi)
                            {
                                server.sendMessage("Teleport");
                                server.rosController.sentUrshi = true;
                                Console.WriteLine("Sent Teleport for Urshi");
                            }
                        }

                        if (server.gameState.lastRift.ElapsedMilliseconds > 360000) //Detect timeout, send F7 and restart
                        {
                            Console.WriteLine("Timeout detected");
                            server.rosController.Pause();
                            server.WaitStates();
                            server.GoToMenu();
                            RosController.SendF7();
                            Thread.Sleep(5000);
                            server.gameState.lastRift.Restart();
                            server.rosController.InitVariables();
                            server.ClickRosStart();
                            Thread.Sleep(7000);
                            server.sendMessage("Timeout");
                        }
                    }
                    catch { }
                }
            });

            Thread logFileDecider = new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        var newLogLines = server.rosController.rosLog.NewLines;
                        if (LogFile.LookForString(newLogLines, "Vendor Loop Done"))
                        {
                            //pause after vendor loop done
                            server.rosController.vendorLoopDone = true;
                            server.rosController.enteredRift    = false;
                            server.sendMessage("Server Vendor Loop Done");
                            Console.WriteLine("Vendor Loop Done Detected, server Always Pause here");
                            bool isRiftStarted = false;
                            try //check for rift started for pausing
                            {
                                UXControl riftStartedUiControl = GetControl <UXControl>("Root.NormalLayer.eventtext_bkgrnd.eventtext_region.stackpanel.rift_wrapper");
                                isRiftStarted = riftStartedUiControl.IsVisible();
                            }
                            catch { isRiftStarted = false; }
                            if (!isRiftStarted & !server.gameState.aloneInGame)
                            {
                                server.rosController.Pause();
                            }
                        }

                        if (LogFile.LookForString(newLogLines, "Next rift in different") & !server.gameState.aloneInGame)
                        {
                            //failure detected
                            server.sendMessage("Go to menu");
                            Console.WriteLine("Next rift in different game detected: send Go to menu");
                            server.rosController.failed = true;
                        }

                        if (LogFile.LookForString(newLogLines, "[20] Reseting timeouts") | LogFile.LookForString(newLogLines, "[21] Reseting timeouts")
                            | LogFile.LookForString(newLogLines, "[22] Reseting timeouts") | LogFile.LookForString(newLogLines, "[23] Reseting timeouts")
                            | LogFile.LookForString(newLogLines, "[24] Reseting timeouts") | LogFile.LookForString(newLogLines, "[25] Reseting timeouts")
                            | LogFile.LookForString(newLogLines, "[26] Reseting timeouts") | LogFile.LookForString(newLogLines, "[27] Reseting timeouts")
                            | LogFile.LookForString(newLogLines, "[28] Reseting timeouts") | LogFile.LookForString(newLogLines, "[29] Reseting timeouts")
                            | LogFile.LookForString(newLogLines, "[30] Reseting timeouts") & !server.gameState.aloneInGame)
                        {
                            //paused detected
                            server.rosController.paused = true;
                        }
                    }
                    catch { }
                }
            });

            Console.WriteLine("Starting Threads");
            gameStateDecider.Start();
            logFileDecider.Start();
            Console.ReadKey();
        }
Beispiel #15
0
        public static bool KillMutex(Process process, string mutexType, string mutexName, bool partial)
        {
            Log(string.Format("Attempting to kill mutex"));
            // 4 tries
            for (int i = 1; i < 4; i++)
            {
                Log("Attempt #" + i);
                Console.WriteLine("Loop " + i);

                if (partial)
                {
                    var handles = Win32Processes.GetHandles(process, mutexType);
                    foreach (var handle in handles)
                    {
                        string strObjectName = Win32Processes.getObjectName(handle, Process.GetProcessById(handle.ProcessID));

                        if (!string.IsNullOrWhiteSpace(strObjectName) && strObjectName.Contains(mutexName))
                        {
                            Log(string.Format("Killing mutex located at '{0}'", strObjectName));
                            IntPtr ipHandle = IntPtr.Zero;
                            if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE))
                            {
                                Log(string.Format("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error()));
                                Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error());
                            }
                            else
                            {
                                Log("Mutex was killed successfully");
                                return(true);
                            }
                        }
                        //Log("----------------END-----------------");
                    }
                    return(true);
                }
                else
                {
                    var handles = Win32Processes.GetHandles(process, mutexType, "", mutexName);

                    if (handles.Count == 0)
                    {
                        Log(string.Format("{0} not found in process handles", mutexName));
                        continue;
                    }

                    foreach (var handle in handles)
                    {
                        string strObjectName = Win32Processes.getObjectName(handle, Process.GetProcessById(handle.ProcessID));
                        Log(string.Format("Killing mutex {0}", strObjectName));
                        if (!string.IsNullOrWhiteSpace(strObjectName) && strObjectName.EndsWith(mutexName))
                        {
                            IntPtr ipHandle = IntPtr.Zero;
                            if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE))
                            {
                                Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error());
                            }
                            else
                            {
                                Log("Mutex was killed successfully");
                                return(true);
                            }
                        }
                    }
                }
            }
            Log("Mutex was not killed");
            //Log("----------------END-----------------");
            return(false);
        }
Beispiel #16
0
        public ClientProgram()
        {
            IntPtr  multibotProcess = RosController.GetForegroundWindow();
            string  pathToFile      = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents\\RoS-BoT\\Logs\\logs.txt");
            Process RosBotProcess   = Win32Processes.GetProcessesLockingFile(pathToFile).FirstOrDefault();

            Console.WriteLine("Starting Client controller: Make sure Server is Ready");
            ClientController client = new ClientController();

            client.pathToLogFile   = pathToFile;
            client.rosbotProcess   = RosBotProcess;
            client.multibotProcess = multibotProcess;
            client.GetRosRect();
            Console.WriteLine("Server Ip: "); // Prompt
            string serveripInput = Console.ReadLine();

            Console.WriteLine("Server Port: "); // Prompt
            int serverportInput = Convert.ToInt32(Console.ReadLine());

            client.serverip   = serveripInput;
            client.serverport = serverportInput;
            Console.WriteLine("Connecting to Server");
            bool clientStarting = true;

            while (clientStarting)
            {
                try
                {
                    client.Connect();
                    try
                    {
                        clientStarting = !client.tcpClient.TcpClient.Connected;
                    }
                    catch { clientStarting = true; }
                }
                catch
                {
                    Console.WriteLine("Failed to connect to server, press key to try again");
                    Console.ReadLine();
                    Console.WriteLine("Server Ip: ");   // Prompt
                    serveripInput = Console.ReadLine();
                    Console.WriteLine("Server Port: "); // Prompt
                    serverportInput = Convert.ToInt32(Console.ReadLine());
                }
            }
            Console.WriteLine("Starting Game Modules");
            client.StartModules();
            Console.WriteLine("All modules started: reading game states");
            client.sendMessage("Client started modules");
            client.ClickRosStart();
            client.sendMessage("BeginRosBot");

            Thread gameStateDecider = new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        client.gameState.UpdateGameState();
                        if (client.gameState.inMenu & client.rosController.failed)
                        {
                            //sleeping after going to menu
                            RosController.BlockInput();
                            Console.WriteLine("Sleeping 20s");
                            Thread.Sleep(20000);
                            Console.WriteLine("Done");
                            client.rosController.InitVariables();
                            RosController.UnBlockInput();
                        }

                        if (client.gameState.acceptgrUiVisible & client.rosController.vendorLoopDone)
                        {
                            // click accept grift yes
                            client.rosController.Pause();
                            client.rosController.enteredRift = false;
                            var xCoord = client.gameState.acceptgrUiControl.uirect.TranslateToClientRect(client.gameState.clientWidth, client.gameState.clientHeight).Left +
                                         (client.gameState.acceptgrUiControl.uirect.TranslateToClientRect(client.gameState.clientWidth, client.gameState.clientHeight).Width / 2);
                            var yCoord = client.gameState.acceptgrUiControl.uirect.TranslateToClientRect(client.gameState.clientWidth, client.gameState.clientHeight).Top +
                                         (client.gameState.acceptgrUiControl.uirect.TranslateToClientRect(client.gameState.clientWidth, client.gameState.clientHeight).Height / 2);
                            RosController.SetCursorPos((int)xCoord, (int)yCoord);
                            RosController.LeftClick();
                            Console.WriteLine("Accept Rift Dialog Detected: Click Accept and Send Pause");
                        }

                        if (client.gameState.cancelgriftUiVisible)
                        {
                            //click cancel ok
                            client.rosController.Pause();
                            var xCoord = client.gameState.confirmationUiControl.uirect.TranslateToClientRect(client.gameState.clientWidth, client.gameState.clientHeight).Left +
                                         (client.gameState.confirmationUiControl.uirect.TranslateToClientRect(client.gameState.clientWidth, client.gameState.clientHeight).Width / 2);
                            var yCoord = client.gameState.confirmationUiControl.uirect.TranslateToClientRect(client.gameState.clientWidth, client.gameState.clientHeight).Top +
                                         (client.gameState.confirmationUiControl.uirect.TranslateToClientRect(client.gameState.clientWidth, client.gameState.clientHeight).Height / 2);
                            RosController.SetCursorPos((int)xCoord, (int)yCoord);
                            RosController.LeftClick();
                            client.sendMessage("Start");
                            Console.WriteLine("Rift Cancelled Dialog Detected: Pause, Click Cancel, and Send Start");
                        }

                        if (!client.rosController.enteredRift & client.gameState.firstlevelRift & !client.gameState.inMenu & !client.gameState.isLoading & !client.gameState.aloneInGame)
                        {
                            //unpause after entering rift and reinit variables
                            Thread.Sleep(1500);
                            client.rosController.enteredRift = true;
                            client.rosController.Unpause();
                            client.rosController.InitVariables();
                            Console.WriteLine("First Floor Rift Detected: Unpausing and Reiniting variables");
                        }

                        if (client.gameState.haveUrshiActor)
                        {
                            //set Urshi state
                            client.rosController.didUrshi = true;
                            //send have urushi to other if didnt yet
                            if (!client.rosController.sentUrshi)
                            {
                                client.sendMessage("Teleport");
                                client.rosController.sentUrshi = true;
                                Console.WriteLine("Sent Teleport for Urshi");
                            }
                        }
                    }
                    catch { }
                }
            });

            Thread logFileDecider = new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        var newLogLines = client.rosController.rosLog.NewLines;

                        if (LogFile.LookForString(newLogLines, "Vendor Loop Done"))
                        {
                            //pause after vendor loop done
                            client.rosController.vendorLoopDone = true;
                            client.rosController.enteredRift    = false;
                            client.sendMessage("Client Vendor Loop Done");
                            Console.WriteLine("Vendor Loop Done Detected");
                            if (!client.rosController.otherVendorLoopDone & !client.gameState.aloneInGame)
                            {
                                bool isRiftStarted = false;
                                try //check for rift started for pausing
                                {
                                    UXControl riftStartedUiControl = GetControl <UXControl>("Root.NormalLayer.eventtext_bkgrnd.eventtext_region.stackpanel.rift_wrapper");
                                    isRiftStarted = riftStartedUiControl.IsVisible();
                                }
                                catch { isRiftStarted = false; }
                                if (!isRiftStarted)
                                {
                                    client.rosController.Pause();
                                }
                            }
                            Thread.Sleep(100);
                        }

                        if (LogFile.LookForString(newLogLines, "Next rift in different") & !client.gameState.aloneInGame)
                        {
                            //failure detected
                            client.sendMessage("Go to menu");
                            Console.WriteLine("Next rift in different game detected: send Go to menu");
                            client.rosController.failed = true;
                        }

                        if (LogFile.LookForString(newLogLines, "[20] Reseting timeouts") | LogFile.LookForString(newLogLines, "[21] Reseting timeouts")
                            | LogFile.LookForString(newLogLines, "[22] Reseting timeouts") | LogFile.LookForString(newLogLines, "[23] Reseting timeouts")
                            | LogFile.LookForString(newLogLines, "[24] Reseting timeouts") | LogFile.LookForString(newLogLines, "[25] Reseting timeouts")
                            | LogFile.LookForString(newLogLines, "[26] Reseting timeouts") | LogFile.LookForString(newLogLines, "[27] Reseting timeouts")
                            | LogFile.LookForString(newLogLines, "[28] Reseting timeouts") | LogFile.LookForString(newLogLines, "[29] Reseting timeouts")
                            | LogFile.LookForString(newLogLines, "[30] Reseting timeouts") & !client.gameState.aloneInGame)
                        {
                            //paused detected
                            client.rosController.paused = true;
                            client.sendMessage("Status Check Code 20");
                        }
                    }
                    catch { }
                }
            });

            Console.WriteLine("Starting Threads");
            gameStateDecider.Start();
            logFileDecider.Start();
            Console.ReadKey();
        }
Beispiel #17
0
        public ToolsViewModel()
        {
            InitThings();
            this.BuyCommand = new RelayCommand <MallThing>(
                (t) => this.Buy(t),
                (t) => t != null && SoftContext.Role != null);

            this.StopCommand = new RelayCommand(() =>
            {
                SoftContext.TaskEngine.Stop();
            });
            this.OpenCommand = new RelayCommand(() =>
            {
                try
                {
                    Process[] all = Process.GetProcessesByName("DragonNest");
                    if (all != null)
                    {
                        if (all.Length == 0)
                        {
                            SoftContext.MainWindow.ShowMessageAsync("多开失败", "没有找到游戏进程");
                            return;
                        }
                        foreach (Process process in all)
                        {
                            var handles = Win32Processes.GetHandles(process, "Mutant", "\\BaseNamedObjects\\MutexDragonNest");
                            if (handles.Count == 0)
                            {
                                continue;
                            }
                            foreach (var handle in handles)
                            {
                                IntPtr ipHandle = IntPtr.Zero;
                                if (!MutexCloseHelper.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle,
                                                                      handle.Handle, MutexCloseHelper.GetCurrentProcess(), out ipHandle, 0, false, MutexCloseHelper.DUPLICATE_CLOSE_SOURCE))
                                {
                                    // richTextBox1.AppendText("DuplicateHandle() failed, error =" + Marshal.GetLastWin32Error() + Environment.NewLine);
                                }
                                else
                                {
                                    MutexCloseHelper.CloseHandle(ipHandle);
                                    SoftContext.MainWindow.ShowMessageAsync("多开成功", "进程[" + handle.ProcessID + "]的互斥体句柄关闭成功");
                                }
                            }
                        }
                    }
                    else
                    {
                        SoftContext.MainWindow.ShowMessageAsync("多开失败", "没有找到游戏进程");
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            });

            this.BeginBagClearCommand = new RelayCommand(() =>
            {
                TaskContext context = new TaskContext(SoftContext.Role);

                /// 任务设置,可用属性为:.Thing .Num .UseLB
                context.Settings.BeginPage = BeginPage;
                context.Settings.BeginItem = BeginItem;
                context.Settings.StopPage  = StopPage;
                context.Settings.StopItem  = StopItem;

                TaskBase task = new BagClearTask(context);
                task.Name     = "清理背包";
                SoftContext.TaskEngine.Start(task);
            }, () => SoftContext.Role != null);
            this.AutoOpenEggCommand = new RelayCommand(() =>
            {
                TaskContext context = new TaskContext(SoftContext.Role);

                TaskBase task = new ZidongkaidanTask(context);
                task.Name     = "自动开蛋";
                SoftContext.TaskEngine.Start(task);
            }, () => SoftContext.Role != null);
            this.StopBagClearCommand = new RelayCommand(() =>
            {
                SoftContext.TaskEngine.Stop();
            });
        }