Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: 16122017
- * Date: 15 ene. 2018
- * Time: 3:03 p. m.
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using System.IO;
- using System.Collections;
- using System.Diagnostics;
- using Microsoft.Win32;
- using System.Net.NetworkInformation;
- using System.Net.Sockets;
- using System.Net;
- using System.Text;
- namespace samp_launcher
- {
- /// <summary>
- /// Description of MainForm.
- /// </summary>
- public partial class MainForm : Form
- {
- string sampPath = (string) Registry.CurrentUser.OpenSubKey(@"Software\SAMP", true).GetValue("gta_sa_exe", null);
- string serverIP = "ls-sw.net";
- int serverPort = 7777, c=0;
- bool moving = false, online = false;
- public MainForm()
- {
- foreach (Process p in Process.GetProcesses()) {
- if (p.ProcessName == "samp-launcher") {
- if (c++ == 1)
- {
- MessageBox.Show("LAUNCHER ALREADY RUNNING!");
- System.Environment.Exit(1);
- }
- }
- }
- InitializeComponent();
- label2.Text = DateTime.UtcNow.ToString();
- BackgroundImage = Image.FromFile("cover.jpg");
- button1.Image = Image.FromFile("playnowbutton.jpg");
- button2.Image = Image.FromFile("closebutton.jpg");
- button3.Image = Image.FromFile("donatebutton.jpg");
- //BackgroundImage = imgfromfile("cover.ps");
- //button1.Image = imgfromfile("playnowbutton.ps");
- //button2.Image = imgfromfile("closebutton.ps");
- //button3.Image = imgfromfile("donatebutton.ps");
- Icon = new Icon("icon.ico");
- Text = "LOS SANTOS STREET WARS";
- readUsername();
- checkConnection();
- //barray();
- }
- /*
- Image imgfromfile(string filename)
- {
- StreamReader r = new StreamReader(filename);
- StringBuilder sb = new StringBuilder();
- string lastLine = null;
- while ((lastLine = r.ReadLine()) != null)
- {
- lastLine.Trim();
- sb.Append(lastLine);
- }
- r.Close();
- string fulldata = sb.ToString();
- string[] datapieces = fulldata.Split(',');
- int size = datapieces.Length;
- byte[] data = new byte[size];
- int dcount = 0;
- foreach (string s in datapieces)
- {
- data[dcount++] = Byte.Parse(s);
- }
- return byteArrayToImage(data);
- }
- void barray()
- {
- string here = Environment.CurrentDirectory;
- string[] files = Directory.GetFiles(here);
- foreach(string f in files)
- {
- //MessageBox.Show(f);
- if (f.EndsWith(".jpg"))
- {
- string fName = Path.GetFileName(f);
- //byte[] image = System.IO.File.ReadAllBytes ( fName);
- byte[] image = converterDemo(Image.FromFile(fName));
- trya(image);
- MessageBox.Show(image.Length+"");
- /*string t = Convert.ToBase64String(image);
- Console.WriteLine(t);
- MessageBox.Show(t+"");*/
- /*ArrayList list = new ArrayList();
- int count = 0;
- foreach (byte b in image)
- {
- if (count++ != (image.Length-1))
- {
- list.Add(b+", ");
- }
- else
- {
- list.Add(""+ b);
- }
- }
- StringBuilder sb = new StringBuilder();
- foreach (string s in list)
- {
- sb.Append(s);
- }
- //MessageBox.Show(image[0]+", "+image[1]);
- MessageBox.Show(sb.ToString());
- writeDesktop(sb.ToString(), fName.Replace(".jpg", ".ps"));
- /*string bytes = "";
- for (int i = 0 ;i < image.Length; i++)
- {
- bytes += ""+image[i]+", ";
- }
- Console.WriteLine(fName+": " + bytes);*/
- /* }
- }
- }
- */
- /*void writeDesktop(string imgdata, string filename)
- {
- StreamWriter w = new StreamWriter(filename);
- w.Write(imgdata);
- w.Close();
- }
- public static byte[] converterDemo(Image x)
- {
- ImageConverter _imageConverter = new ImageConverter();
- byte[] xByte = (byte[])_imageConverter.ConvertTo(x, typeof(byte[]));
- return xByte;
- }
- public Image byteArrayToImage(byte[] byteArrayIn)
- {
- MemoryStream ms = new MemoryStream(byteArrayIn);
- Image returnImage = Image.FromStream(ms);
- return returnImage;
- }
- void trya(byte[] imgs)
- {
- Form f = new Form();
- f.Size = new Size(800,600);
- f.BackgroundImage = byteArrayToImage(imgs);
- f.Enabled = true;
- f.Show();
- }
- */
- void Button1Click(object sender, EventArgs e)
- {
- }
- void readUsername()
- {
- String username = Registry.CurrentUser.OpenSubKey(@"Software\SAMP", true).GetValue("PlayerName", null).ToString();
- if (username != "")
- textBox1.Text = username;
- else
- textBox1.Text = "";
- }
- void checkConnection()
- {
- if ((online = PingHost(serverIP, serverPort))) {
- //progressBar1.BackColor = Color.Green;
- label1.ForeColor = Color.FromArgb(0, 255, 0);
- label1.Text = "ONLINE";
- }
- }
- public static bool PingHost(string _HostURI, int _PortNumber)
- {
- //MessageBox.Show("pinging: " + _HostURI + ":"+_PortNumber);
- if (_HostURI == "") {
- MessageBox.Show("couldnt ping the host. CAUSE: INVALID IP OR PORT");
- return false;
- }
- try {
- UdpClient client = new UdpClient();
- client.Connect(_HostURI, _PortNumber);
- //MessageBox.Show("CONNECTED!!!!");
- return true;
- } catch (Exception ex) {
- //MessageBox.Show("Error pinging host:'" + _HostURI + ":" + _PortNumber.ToString() + "'" + ex.Message);
- return false;
- }
- }
- void MainFormKeyDown(object sender, KeyEventArgs e)
- {
- }
- void Button2Click(object sender, EventArgs e)
- {
- button2.Image = Image.FromFile("closebutton2.jpg");
- DialogResult dialogResult = MessageBox.Show("Are you sure you want to close?", "Choose an option", MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.Yes) {
- Application.Exit();
- System.Environment.Exit(1);
- } else if (dialogResult == DialogResult.No) {
- //do something else
- }
- }
- void TextBox1Enter(object sender, EventArgs e)
- {
- }
- void MainFormMouseDown(object sender, MouseEventArgs e)
- {
- Point relativePoint = this.PointToClient(Cursor.Position);
- if (relativePoint.Y < 50)
- moving = true;
- }
- void MainFormMouseMove(object sender, MouseEventArgs e)
- {
- if (moving) {
- Point relativePoint = this.PointToClient(Cursor.Position);
- int X = Cursor.Position.X;
- int Y = Cursor.Position.Y;
- Location = new Point(X - (Size.Width / 3), Y - 25);
- //Point relativePoint = this.PointToClient(Cursor.Position);
- //Location = new Point(relativePoint.X, relativePoint.Y);
- }
- }
- void MainFormMouseUp(object sender, MouseEventArgs e)
- {
- moving = false;
- }
- void TextBox1TextChanged(object sender, EventArgs e)
- {
- //Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\SAMP", "PlayerName", textBox1.Text);
- Registry.CurrentUser.OpenSubKey(@"Software\SAMP", true).SetValue("PlayerName", textBox1.Text);
- }
- void Button2MouseUp(object sender, MouseEventArgs e)
- {
- button2.Image = Image.FromFile("closebutton.jpg");
- }
- void Button1MouseUp(object sender, MouseEventArgs e)
- {
- button1.Image = Image.FromFile("playnowbutton.jpg");
- if (!File.Exists(sampPath)) {
- 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.");
- return;
- }
- if (!online) {
- MessageBox.Show("ERROR: SERVER IS NOT ONLINE, but i will launch this...");
- }
- if (textBox1.Text == "") {
- MessageBox.Show("enter your username");
- return;
- }
- foreach (Process p in Process.GetProcesses()) {
- if (p.ProcessName == "gta_sa") {
- MessageBox.Show("GAME IS ALREADY RUNNING!");
- return;
- }
- if (p.ProcessName == "samp")
- p.Close();
- }
- Process.Start(sampPath, serverIP + ":" + serverPort);
- }
- void Button1MouseDown(object sender, MouseEventArgs e)
- {
- button1.Image = Image.FromFile("playnowbutton2.jpg");
- }
- void Button3Click(object sender, EventArgs e)
- {
- Process.Start("https://paypal.me/lssw/10");
- //your paypal.me link goto paypal.me to create a free one
- }
- /*
- Now, to use it, simply call:
- ModifyProgressBarColor.SetState(progressBar1, 2);
- Note the second parameter in SetState, 1 = normal (green); 2 = error (red); 3 = warning (yellow).
- */
- }
- }
Add Comment
Please, Sign In to add comment