/// <summary> /// Makes sure that a client is running and starts it if it isn't /// </summary> /// <param name="forceRestart">Set to true to force a client restart even if the client is already running</param> /// <returns>true if client is successfully prepared</returns> public bool PrepareClient(bool forceRestart = false) { if (!forceRestart && ScreenScraper.ProcessExists(Value)) { return(true); } Process client = null; Stopwatch longWatch = new Stopwatch(); longWatch.Start(); while (longWatch.ElapsedMilliseconds < UnitConversions.HoursToMilliseconds(24) && !BotProgram.StopFlag) { if (!ScreenScraper.RestartClient(ref client, RunParams.RuneScapeClient, RunParams.ClientFlags)) { BotProgram.SafeWait(5000); continue; } //Successful restart Value = client; Stopwatch watch = new Stopwatch(); watch.Start(); //Wait for cient to be visually recognized. do { BotProgram.SafeWait(UnitConversions.SecondsToMilliseconds(5)); if (Screen.ReadWindow(false) && (Screen.IsLoggedOut(false) || Screen.IsLoggedIn(false))) { return(true); } }while ((watch.ElapsedMilliseconds < UnitConversions.MinutesToMilliseconds(5)) && !BotProgram.StopFlag); } if (!BotProgram.StopFlag) { const string errorMessage = "Client did not start correctly"; MessageBox.Show(errorMessage); } Value = null; return(false); }