Guest User

samp-launcher

a guest
Jan 16th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.40 KB | None | 0 0
  1. /*
  2.  * Created by SharpDevelop.
  3.  * User: 16122017
  4.  * Date: 15 ene. 2018
  5.  * Time: 3:03 p. m.
  6.  *
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8.  */
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Drawing;
  12. using System.Windows.Forms;
  13. using System.IO;
  14. using System.Collections;
  15. using System.Diagnostics;
  16. using Microsoft.Win32;
  17. using System.Net.NetworkInformation;
  18. using System.Net.Sockets;
  19. using System.Net;
  20. using System.Text;
  21.  
  22. namespace samp_launcher
  23. {
  24.     /// <summary>
  25.     /// Description of MainForm.
  26.     /// </summary>
  27.     public partial class MainForm : Form
  28.     {
  29.        
  30.         string sampPath = (string) Registry.CurrentUser.OpenSubKey(@"Software\SAMP", true).GetValue("gta_sa_exe", null);
  31.         string serverIP = "ls-sw.net";
  32.         int serverPort = 7777, c=0;
  33.         bool moving = false, online = false;
  34.        
  35.         public MainForm()
  36.         {
  37.            
  38.            
  39.         foreach (Process p in Process.GetProcesses()) {
  40.                    
  41.                 if (p.ProcessName == "samp-launcher") {
  42.                     if (c++ == 1)
  43.                     {
  44.                     MessageBox.Show("LAUNCHER ALREADY RUNNING!");
  45.                     System.Environment.Exit(1);
  46.                     }
  47.                 }
  48.             }
  49.            
  50.             InitializeComponent();
  51.            
  52.             label2.Text = DateTime.UtcNow.ToString();
  53.                    
  54.             BackgroundImage = Image.FromFile("cover.jpg");
  55.             button1.Image = Image.FromFile("playnowbutton.jpg");
  56.             button2.Image = Image.FromFile("closebutton.jpg");
  57.             button3.Image = Image.FromFile("donatebutton.jpg");
  58.            
  59.             //BackgroundImage = imgfromfile("cover.ps");
  60.             //button1.Image = imgfromfile("playnowbutton.ps");
  61.             //button2.Image = imgfromfile("closebutton.ps");
  62.             //button3.Image = imgfromfile("donatebutton.ps");
  63.            
  64.             Icon = new Icon("icon.ico");
  65.             Text = "LOS SANTOS STREET WARS";
  66.                        
  67.             readUsername();
  68.            
  69.             checkConnection();
  70.            
  71.             //barray();
  72.            
  73.         }
  74.         /*
  75.         Image imgfromfile(string filename)
  76.         {
  77.             StreamReader r = new StreamReader(filename);
  78.             StringBuilder sb = new StringBuilder();
  79.             string lastLine = null;
  80.             while ((lastLine = r.ReadLine()) != null)
  81.             {
  82.                 lastLine.Trim();
  83.                 sb.Append(lastLine);
  84.             }
  85.             r.Close();
  86.             string fulldata = sb.ToString();
  87.             string[] datapieces = fulldata.Split(',');
  88.             int size = datapieces.Length;
  89.             byte[] data = new byte[size];
  90.             int dcount = 0;
  91.             foreach (string s in datapieces)
  92.             {
  93.                 data[dcount++] = Byte.Parse(s);
  94.             }
  95.             return byteArrayToImage(data);
  96.         }
  97.        
  98.         void barray()
  99.         {
  100.             string here = Environment.CurrentDirectory;
  101.             string[] files = Directory.GetFiles(here);
  102.             foreach(string f in files)
  103.             {
  104.                 //MessageBox.Show(f);
  105.                 if (f.EndsWith(".jpg"))
  106.                 {
  107.                     string fName = Path.GetFileName(f);
  108.                     //byte[] image = System.IO.File.ReadAllBytes ( fName);
  109.                     byte[] image = converterDemo(Image.FromFile(fName));
  110.                     trya(image);
  111.                     MessageBox.Show(image.Length+"");
  112.                    
  113.                     /*string t = Convert.ToBase64String(image);
  114.                     Console.WriteLine(t);
  115.                    
  116.                     MessageBox.Show(t+"");*/
  117.                    
  118.                     /*ArrayList list = new ArrayList();
  119.                     int count = 0;
  120.                     foreach (byte b in image)
  121.                     {
  122.                         if (count++ != (image.Length-1))
  123.                         {
  124.                             list.Add(b+", ");
  125.                         }
  126.                         else
  127.                         {
  128.                             list.Add(""+ b);
  129.                         }
  130.                     }
  131.                     StringBuilder sb = new StringBuilder();
  132.                     foreach (string s in list)
  133.                     {
  134.                         sb.Append(s);
  135.                     }
  136.                    
  137.                     //MessageBox.Show(image[0]+", "+image[1]);
  138.                     MessageBox.Show(sb.ToString());
  139.                    
  140.                     writeDesktop(sb.ToString(), fName.Replace(".jpg", ".ps"));
  141.                    
  142.                     /*string bytes = "";
  143.                     for (int i = 0 ;i < image.Length; i++)
  144.                     {
  145.                         bytes += ""+image[i]+", ";
  146.                     }
  147.                     Console.WriteLine(fName+": " + bytes);*/
  148.             /*  }
  149.             }
  150.            
  151.         }
  152.         */
  153.         /*void writeDesktop(string imgdata, string filename)
  154.         {
  155.             StreamWriter w = new StreamWriter(filename);
  156.             w.Write(imgdata);
  157.             w.Close();
  158.         }
  159.        
  160.        
  161.         public static byte[] converterDemo(Image x)
  162. {
  163.     ImageConverter _imageConverter = new ImageConverter();
  164.     byte[] xByte = (byte[])_imageConverter.ConvertTo(x, typeof(byte[]));
  165.     return xByte;
  166. }
  167.        
  168.         public Image byteArrayToImage(byte[] byteArrayIn)
  169. {
  170.     MemoryStream ms = new MemoryStream(byteArrayIn);
  171.     Image returnImage = Image.FromStream(ms);
  172.     return returnImage;
  173. }
  174.        
  175.         void trya(byte[] imgs)
  176.         {
  177.             Form f = new Form();
  178.             f.Size = new Size(800,600);
  179.             f.BackgroundImage = byteArrayToImage(imgs);
  180.             f.Enabled = true;
  181.             f.Show();
  182.         }
  183.         */
  184.         void Button1Click(object sender, EventArgs e)
  185.         {
  186.            
  187.         }      
  188.        
  189.         void readUsername()
  190.         {
  191.             String username = Registry.CurrentUser.OpenSubKey(@"Software\SAMP", true).GetValue("PlayerName", null).ToString();
  192.            
  193.             if (username != "")
  194.                 textBox1.Text = username;
  195.             else
  196.                 textBox1.Text = "";
  197.         }
  198.        
  199.         void checkConnection()
  200.         {
  201.             if ((online = PingHost(serverIP, serverPort))) {
  202.                 //progressBar1.BackColor = Color.Green;
  203.                 label1.ForeColor = Color.FromArgb(0, 255, 0);
  204.                 label1.Text = "ONLINE";
  205.             }
  206.         }
  207.        
  208.         public static bool PingHost(string _HostURI, int _PortNumber)
  209.         {
  210.             //MessageBox.Show("pinging: " + _HostURI + ":"+_PortNumber);
  211.             if (_HostURI == "") {
  212.                 MessageBox.Show("couldnt ping the host. CAUSE: INVALID IP OR PORT");
  213.                 return false;
  214.             }
  215.                
  216.             try {
  217.                 UdpClient client = new UdpClient();
  218.                 client.Connect(_HostURI, _PortNumber);
  219.                 //MessageBox.Show("CONNECTED!!!!");
  220.                 return true;
  221.             } catch (Exception ex) {
  222.                 //MessageBox.Show("Error pinging host:'" + _HostURI + ":" + _PortNumber.ToString() + "'" + ex.Message);
  223.                 return false;
  224.             }
  225.         }
  226.        
  227.         void MainFormKeyDown(object sender, KeyEventArgs e)
  228.         {
  229.  
  230.         }
  231.         void Button2Click(object sender, EventArgs e)
  232.         {
  233.             button2.Image = Image.FromFile("closebutton2.jpg");
  234.             DialogResult dialogResult = MessageBox.Show("Are you sure you want to close?", "Choose an option", MessageBoxButtons.YesNo);
  235.             if (dialogResult == DialogResult.Yes) {
  236.                 Application.Exit();
  237.                 System.Environment.Exit(1);
  238.             } else if (dialogResult == DialogResult.No) {
  239.                 //do something else
  240.             }
  241.         }
  242.         void TextBox1Enter(object sender, EventArgs e)
  243.         {
  244.         }
  245.         void MainFormMouseDown(object sender, MouseEventArgs e)
  246.         {
  247.             Point relativePoint = this.PointToClient(Cursor.Position);
  248.             if (relativePoint.Y < 50)
  249.                 moving = true;
  250.         }
  251.         void MainFormMouseMove(object sender, MouseEventArgs e)
  252.         {
  253.             if (moving) {
  254.                
  255.                 Point relativePoint = this.PointToClient(Cursor.Position);
  256.                
  257.                 int X = Cursor.Position.X;
  258.                 int Y = Cursor.Position.Y;
  259.            
  260.                
  261.                
  262.                 Location = new Point(X - (Size.Width / 3), Y - 25);
  263.                
  264.                 //Point relativePoint = this.PointToClient(Cursor.Position);
  265.                 //Location = new Point(relativePoint.X, relativePoint.Y);
  266.             }
  267.  
  268.         }
  269.         void MainFormMouseUp(object sender, MouseEventArgs e)
  270.         {
  271.             moving = false;
  272.         }
  273.         void TextBox1TextChanged(object sender, EventArgs e)
  274.         {
  275.             //Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\SAMP", "PlayerName", textBox1.Text);
  276.             Registry.CurrentUser.OpenSubKey(@"Software\SAMP", true).SetValue("PlayerName", textBox1.Text);
  277.         }
  278.         void Button2MouseUp(object sender, MouseEventArgs e)
  279.         {
  280.             button2.Image = Image.FromFile("closebutton.jpg");
  281.         }
  282.         void Button1MouseUp(object sender, MouseEventArgs e)
  283.         {
  284.    
  285.             button1.Image = Image.FromFile("playnowbutton.jpg");
  286.        
  287.             if (!File.Exists(sampPath)) {
  288.                 MessageBox.Show("ERROR: you need to reinstall this game. you need to place launcher in gtasamp path/launcher JUST DOWNLOAD AND INSTALL THE GAME AGAIN.");
  289.                 return;
  290.             }
  291.             if (!online) {
  292.                 MessageBox.Show("ERROR: SERVER IS NOT ONLINE, but i will launch this...");
  293.             }
  294.             if (textBox1.Text == "") {
  295.                 MessageBox.Show("enter your username");
  296.                 return;
  297.             }
  298.            
  299.             foreach (Process p in Process.GetProcesses()) {
  300.                    
  301.                 if (p.ProcessName == "gta_sa") {
  302.                     MessageBox.Show("GAME IS ALREADY RUNNING!");
  303.                     return;
  304.                 }
  305.                 if (p.ProcessName == "samp")
  306.                     p.Close();
  307.                
  308.             }
  309.             Process.Start(sampPath, serverIP + ":" + serverPort);
  310.  
  311.         }
  312.         void Button1MouseDown(object sender, MouseEventArgs e)
  313.         {
  314.             button1.Image = Image.FromFile("playnowbutton2.jpg");
  315.         }
  316.         void Button3Click(object sender, EventArgs e)
  317.         {
  318.             Process.Start("https://paypal.me/lssw/10");
  319.             //your paypal.me link goto paypal.me to create a free one
  320.         }
  321.    
  322.        
  323.         /*
  324.          Now, to use it, simply call:
  325.  
  326. ModifyProgressBarColor.SetState(progressBar1, 2);
  327.  
  328. Note the second parameter in SetState, 1 = normal (green); 2 = error (red); 3 = warning (yellow).
  329.          */
  330.        
  331.     }
  332.    
  333.    
  334. }
Add Comment
Please, Sign In to add comment