Advertisement
CloneTrooper1019

RobloxSteamLauncher

Oct 3rd, 2014
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Net;
  11. using System.Diagnostics;
  12. using System.IO;
  13.  
  14. namespace RobloxSteamLauncher
  15. {
  16.     public partial class RbxSteam : Form
  17.     {
  18.         public RbxSteam()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         WebClient http = new System.Net.WebClient();
  24.  
  25.         private void RbxSteam_Load(object sender, EventArgs e)
  26.         {
  27.             // Lets see if we can find RobloxPlayerBeta.exe before-hand to save the user time.
  28.             // If we can't, we'll at least move as close as we can to it.
  29.  
  30.             string myDir = Environment.GetEnvironmentVariable("LocalAppData");
  31.             string version = http.DownloadString("http://setup.roblox.com/version");
  32.             int count = 0;
  33.             if (version != null)
  34.             {
  35.                 List<string> paths = new List<string>(
  36.                     new string[]  { "Roblox", "Versions", version, "RobloxPlayerBeta.exe" }
  37.                 );
  38.                 foreach (string path in paths)
  39.                 {   string nextDir = Path.Combine(myDir, path);
  40.                     bool isExe = path.Contains("exe");
  41.                     if (isExe && File.Exists(nextDir) || Directory.Exists(nextDir))
  42.                     {
  43.                         myDir = nextDir;
  44.                         Console.WriteLine("Found: " + nextDir);
  45.                         count = count + 1;
  46.                     }
  47.                 }
  48.             }
  49.             if (count == 4)
  50.             {
  51.                 this.directoryInput.Text = myDir;
  52.             }
  53.             this.searchDialog.InitialDirectory = myDir;
  54.         }
  55.        
  56.         private void ShowError(string errorMsg)
  57.         {
  58.             MessageBox.Show(errorMsg, "An error occurred!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  59.         }
  60.         private void LaunchButton_Click(object sender, EventArgs e)
  61.         {
  62.             if (this.directoryInput.Text != ""){
  63.                 string text = this.placeInput.Text;
  64.                 int placeId = 0;
  65.                 bool isValid = int.TryParse(text, out placeId);
  66.                 if (isValid == true)
  67.                 {
  68.                     // Check with roblox to see if this is an actual launchable game.
  69.                     string requestGame = http.DownloadString("http://www.roblox.com/Game/PlaceLauncher.ashx?request=RequestGame&placeId=" + text);
  70.                     if (requestGame.Contains("JoinPlace=") || requestGame.Contains("Game/Join.ashx")) // If its joinable, it should contain one of these.
  71.                     {
  72.                         this.Hide();
  73.                         Process Roblox = Process.Start(this.directoryInput.Text, " --id " + text);
  74.                         Roblox.WaitForExit();
  75.                         this.Show();
  76.                     }
  77.                     else
  78.                     {
  79.                         ShowError("Unable to join game! Request was ignored by Roblox. \n(Are you sure this is an actual PlaceId?)");
  80.                     }
  81.                 }
  82.                 else
  83.                 {
  84.                     ShowError("Invalid PlaceId Input!");
  85.                     this.placeInput.Text = "";
  86.                 }
  87.             }
  88.             else
  89.             {
  90.                 ShowError("Roblox's client exe location hasn't been set!");
  91.             }
  92.         }
  93.         bool searchingFor = false;
  94.         private void searchFor_Click(object sender, EventArgs e)
  95.         {
  96.             if (searchingFor == false)
  97.             {
  98.                 searchingFor = true;
  99.                 this.searchDialog.ShowDialog();
  100.                 searchingFor = false;
  101.             }
  102.         }
  103.  
  104.         private void searchDialog_FileOk(object sender, CancelEventArgs e)
  105.         {
  106.             string directory = this.searchDialog.FileName;
  107.             if (directory.Contains("Roblox"))
  108.             {
  109.                 if (directory.Contains("RobloxPlayerBeta"))
  110.                 {
  111.                     this.directoryInput.Text = directory;
  112.                 }
  113.                 else
  114.                 {
  115.                     ShowError("The exe should be named 'RobloxPlayerBeta' (Try again!)");
  116.                 }
  117.             }
  118.             else
  119.             {
  120.                 ShowError("This directory contains no reference to Roblox. Assuming its invalid. (Try again!)");
  121.             };
  122.         }
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement