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(); }
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(); }