using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.IO.Compression; using System.Linq; using System.Net.Http; using System.Reflection; using System.Security.Cryptography; using System.Text; using System.Text.Json; using System.Threading.Tasks; using System.Windows.Forms; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace HelloWorld { public partial class Form1 : Form { private const string UpdateURL = "https://ibatv.xyz/data/lnch/hy.txt"; private string SanSessionID; private string SanTokenID; public Form1() { InitializeComponent(); btnLauncherUpdate.Visible = false; LoadComboBoxItems(); LoadDownloadedFiles(); string path = ".ibalaunch"; string uuidsave = ".ibalaunch\\uuid"; string usersave = ".ibalaunch\\username"; string verssave = ".ibalaunch\\lastplayedversion"; string HytaleUserData = "UserData"; Version localVersion = GetLocalVersion(); string localversionstring = localVersion.ToString(); //Console.WriteLine("Version" + localversionstring); labelLauncherVersion.Text = localversionstring; try { DirectoryInfo di = Directory.CreateDirectory(path); Console.WriteLine($"Ensured directory exists: {di.FullName}"); } catch (Exception) { Console.WriteLine($"An error occurred: idfk probably rw permission error?"); } try { DirectoryInfo Hdi = Directory.CreateDirectory(HytaleUserData); Console.WriteLine($"Ensured directory exists: {Hdi.FullName}"); } catch (Exception) { Console.WriteLine($"An error occurred: idfk probably rw permission error?"); } // Username File Checking if (File.Exists(usersave)) { FileInfo fileInfo = new FileInfo(usersave); if (fileInfo.Length == 0) { Console.WriteLine("Username file is empty. Not setting anything."); } else { Console.WriteLine("Username file is not empty. Size: " + fileInfo.Length + " bytes."); textBoxUsername.Text = File.ReadAllText(usersave); checkUsername.Checked = true; } } else { } // UUID File Checking if (File.Exists(uuidsave)) { FileInfo fileInfo = new FileInfo(uuidsave); if (fileInfo.Length == 0) { Console.WriteLine("UUID file is empty. Not setting anything."); } else { Console.WriteLine("UUID file is not empty. Size: " + fileInfo.Length + " bytes."); textBoxUUID.Text = File.ReadAllText(uuidsave); checkUUID.Checked = true; } } else { } // UUID File Checking if (File.Exists(verssave)) { FileInfo fileInfo = new FileInfo(verssave); if (fileInfo.Length == 0) { Console.WriteLine("Last Played file is empty. Not setting anything."); } else { Console.WriteLine("Last Played file is not empty. Size: " + fileInfo.Length + " bytes."); comboBox2Play.Text = File.ReadAllText(verssave); } } else { } } private async Task CheckForUpdateAsync() { try { Version localVersion = GetLocalVersion(); Version onlineVersion = await GetOnlineVersionAsync(); if (onlineVersion > localVersion) { btnLauncherUpdate.Visible = true; } } catch (Exception ex) { // Optional: log or ignore Debug.WriteLine(ex.Message); } } private Version GetLocalVersion() { return Assembly.GetExecutingAssembly().GetName().Version; } private async Task GetOnlineVersionAsync() { using (HttpClient client = new HttpClient()) { string versionText = await client.GetStringAsync(UpdateURL); return new Version(versionText.Trim()); } } private void button1_Click(object sender, EventArgs e) { } private void lblHelloWorld_Click(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { } private async void button2_Click(object sender, EventArgs e) { // All of this shit for username data string TextBoxUsername = textBoxUsername.Text; if (checkUsername.Checked == true) { Console.WriteLine("Username Checkbox true, saving."); string usersave = ".ibalaunch\\username"; File.Create(usersave).Dispose(); Console.WriteLine("Username File exists, comparing textbox"); string UsernameFileText = File.ReadAllText(usersave); if (UsernameFileText != TextBoxUsername) { Console.WriteLine("Username mismatch, writing!"); try { File.WriteAllText(usersave, TextBoxUsername); Console.WriteLine("Username file saved."); } catch (Exception) { Console.WriteLine("An error occurred: idfk probably rw permission error?"); } } else { Console.WriteLine("Username already saved."); } } else { Console.WriteLine("Username Checkbox false, not saving."); } Console.WriteLine("Username Shit done."); // All of this shit is uuid data. string TextBoxUUID = textBoxUUID.Text; if (checkUUID.Checked == true) { Console.WriteLine("UUID Checkbox true, saving."); string uuidsave = ".ibalaunch\\uuid"; File.Create(uuidsave).Dispose(); Console.WriteLine("UUID File exists, comparing textbox"); string UUIDFileText = File.ReadAllText(uuidsave); if (UUIDFileText != TextBoxUUID) { Console.WriteLine("UUID mismatch, writing!"); try { File.WriteAllText(uuidsave, TextBoxUUID); Console.WriteLine("UUID file saved."); } catch (Exception) { Console.WriteLine("An error occurred: idfk probably rw permission error?"); } } else { Console.WriteLine("UUID already saved."); } } else { Console.WriteLine("UUID Checkbox false, not saving."); } Console.WriteLine("UUID Shit done."); // All of this shit is Last Played version data. string DropDownGameVers = comboBox2Play.Text; string verssave = ".ibalaunch\\lastplayedversion"; File.Create(verssave).Dispose(); Console.WriteLine("LastPlayedVersion File exists, comparing textbox"); string VersFileText = File.ReadAllText(verssave); if (VersFileText != DropDownGameVers) { Console.WriteLine("LastPlayedVersion mismatch, writing!"); try { File.WriteAllText(verssave, DropDownGameVers); Console.WriteLine("LastPlayedVersion file saved."); } catch (Exception) { Console.WriteLine("An error occurred: idfk probably rw permission error?"); } } else { Console.WriteLine("LastPlayedVersion already saved."); } Console.WriteLine("LastPlayedVersion Shit done."); var payload = new { uuid = "13371337-1337-1337-1337-1337" + textBoxUUID.Text, name = textBoxUsername.Text, scopes = new[] { "hytale:server", "hytale:client" } }; //textBoxUUID.Text + " --name \"" + textBoxUsername.Text string json = JsonSerializer.Serialize(payload); using (HttpClient client = new HttpClient()) { using (HttpContent content = new StringContent(json, Encoding.UTF8, "application/json")) { HttpResponseMessage response = await client.PostAsync( "https://sessions.sanasol.ws/game-session/child", content ); response.EnsureSuccessStatusCode(); string responseJson = await response.Content.ReadAsStringAsync(); // Deserialize response SessionResponse session = JsonSerializer.Deserialize(responseJson); SanSessionID = session.sessionToken; SanTokenID = session.identityToken; //MessageBox.Show("Session created!"); Console.WriteLine("Session: " + SanSessionID + "\n\nToken: " + SanTokenID); } } // Genuinely FUCK windows and C# and fucking whatever else to make this shit work // I swear to fucking god I spent a solid 3 hours trying to make this thing // OPEN A FUCKING EXE AND PASS ARGS CORRECTLY string relativeExePath = Path.Combine("install\\release\\package\\game\\latest\\Client\\", "HytaleClient.exe"); string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; string workingDirectory = Path.Combine(baseDirectory, "Versions"); string Hytaleappdir = "\\install\\release\\package\\game\\latest"; string HytaleJava = "\\install\\release\\package\\jre\\latest\\bin\\java.exe"; string LaunchVersion = comboBox2Play.Text; string GamePath = "\"" + workingDirectory + "\\" + LaunchVersion + "\\" + relativeExePath + "\""; //hytale.exe string AppPath = "\"" + workingDirectory + "\\" + LaunchVersion + Hytaleappdir + "\""; // game\latest string UserdataPath = "\"" + baseDirectory + "UserData" + "\""; string JavaPath = "\"" + workingDirectory + "\\" + LaunchVersion + HytaleJava + "\""; // java string arguments = " --app-dir " + AppPath + " --user-dir " + UserdataPath + " --java-exec " + JavaPath + " --auth-mode authenticated --uuid 13371337-1337-1337-1337-1337" + textBoxUUID.Text + " --name \"" + textBoxUsername.Text + "\"" + " --identity-token " + SanTokenID + " --session-token " + SanSessionID; // Command-line arguments for the VB app ProcessStartInfo startInfo = new ProcessStartInfo { FileName = GamePath, Arguments = arguments, UseShellExecute = true, }; Console.WriteLine("Launching:"); Console.WriteLine(GamePath + arguments); try { Process.Start(startInfo); } catch (Exception ex) { MessageBox.Show($"Error starting the application: {ex.Message}\n" + GamePath + arguments); } } private void checkBox1_CheckedChanged(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } private void button1_Click_1(object sender, EventArgs e) { Random random = new Random(); int GeneratedUUIDVal = random.Next(10000000, 100000000); textBoxUUID.Text = GeneratedUUIDVal.ToString(); } private void checkUUID_CheckedChanged(object sender, EventArgs e) { } private async void LoadComboBoxItems() { string url = "https://ibatv.xyz/data/list.txt"; try { using (HttpClient client = new HttpClient()) { string fileContents = await client.GetStringAsync(url); string[] lines = fileContents .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); comboBox1.Items.Clear(); comboBox1.Items.AddRange(lines); } } catch (Exception ex) { MessageBox.Show("Failed to load items: " + ex.Message); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } private async void btnInstallVersion_Click(object sender, EventArgs e) { if (comboBox1.SelectedItem == null) { MessageBox.Show("Please select a version first."); return; } string baseUrl = "https://ibatv.xyz/data/files/"; string rawName = comboBox1.SelectedItem.ToString(); string fileName = rawName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) ? rawName : rawName + ".zip"; string fileUrl = baseUrl + fileName; string InstallBaseDirectory = AppDomain.CurrentDomain.BaseDirectory; string savePath = Path.Combine(InstallBaseDirectory, fileName); string installDir = Path.Combine(InstallBaseDirectory, "Versions"); string localListPath = Path.Combine(installDir, "versions.txt"); try { using (HttpClient client = new HttpClient()) using (HttpResponseMessage response = await client.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead)) { response.EnsureSuccessStatusCode(); long? totalBytes = response.Content.Headers.ContentLength; using (var contentStream = await response.Content.ReadAsStreamAsync()) using (var fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.None, 41943040, true)) { var buffer = new byte[41943040]; //40MiB apparently. :shrug: long totalRead = 0; int bytesRead; installProgressBar1.Value = 0; while ((bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0) { await fileStream.WriteAsync(buffer, 0, bytesRead); totalRead += bytesRead; if (totalBytes.HasValue) { int progress = (int)((totalRead * 100L) / totalBytes.Value); installProgressBar1.Value = Math.Min(progress, 100); } } } } string folderName = Path.GetFileNameWithoutExtension(fileName); string extractPath = Path.Combine(installDir, folderName); Directory.CreateDirectory(extractPath); ZipFile.ExtractToDirectory(savePath, extractPath); File.Delete(savePath); string baseName = Path.GetFileNameWithoutExtension(fileName); List downloadedFiles = new List(); if (File.Exists(localListPath)) downloadedFiles = File.ReadAllLines(localListPath).ToList(); // Append only if not already in the list if (!downloadedFiles.Contains(baseName, StringComparer.OrdinalIgnoreCase)) { File.AppendAllText(localListPath, baseName + Environment.NewLine); LoadDownloadedFiles(); } MessageBox.Show("Download complete:\n" + savePath + "\n" + "Extracted to:\n" + installDir); } catch (Exception ex) { MessageBox.Show("Download failed:\n" + ex.Message); } } private void comboBox2Play_SelectedIndexChanged(object sender, EventArgs e) { } private void LoadDownloadedFiles() { string InstallBaseDirectory = AppDomain.CurrentDomain.BaseDirectory; string installDir = Path.Combine(InstallBaseDirectory, "Versions"); string localListPath = Path.Combine(installDir, "versions.txt"); comboBox2Play.Items.Clear(); // Clear old items if (File.Exists(localListPath)) { var downloadedFiles = File.ReadAllLines(localListPath); foreach (var file in downloadedFiles) { if (!string.IsNullOrWhiteSpace(file)) comboBox2Play.Items.Add(file); } } } private void btnUninstallVersion_Click(object sender, EventArgs e) { //string baseUrl = "https://ibatv.xyz/data/files/"; string rawName = comboBox1.SelectedItem.ToString(); string fileName = rawName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) ? rawName : rawName + ".zip"; //string fileUrl = baseUrl + fileName; string InstallBaseDirectory = AppDomain.CurrentDomain.BaseDirectory; string savePath = Path.Combine(InstallBaseDirectory, fileName); string installDir = Path.Combine(InstallBaseDirectory, "Versions"); string localListPath = Path.Combine(installDir, "versions.txt"); if (comboBox2Play.SelectedItem == null) { MessageBox.Show("Please select a version to delete.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string selectedVersion = comboBox2Play.SelectedItem.ToString(); // Confirm deletion var result = MessageBox.Show( $"Are you sure you want to delete the version '{selectedVersion}'?", "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question ); if (result != DialogResult.Yes) return; try { // Delete installed folder //string installDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string versionPath = Path.Combine(installDir, selectedVersion); if (Directory.Exists(versionPath)) Directory.Delete(versionPath, true); // true = recursive delete // Update local list // string localListPath = Path.Combine(installDir, "downloaded_files.txt"); if (File.Exists(localListPath)) { var downloadedFiles = File.ReadAllLines(localListPath).ToList(); downloadedFiles.RemoveAll(f => string.Equals(f, selectedVersion, StringComparison.OrdinalIgnoreCase)); File.WriteAllLines(localListPath, downloadedFiles); } // Remove from ComboBox comboBox2Play.Items.Remove(selectedVersion); LoadDownloadedFiles(); MessageBox.Show($"Version '{selectedVersion}' has been deleted.", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Error deleting version:\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private async void btnLauncherUpdate_Click(object sender, EventArgs e) { string tempExe = Path.Combine(Path.GetTempPath(), "latest.exe"); await DownloadUpdateAsync(tempExe); StartUpdaterAndExit(tempExe); } private async Task DownloadUpdateAsync(string destinationPath) { using (HttpClient client = new HttpClient()) using (var response = await client.GetAsync("https://ibatv.xyz/data/lnch/hy/latest.exe", HttpCompletionOption.ResponseHeadersRead)) { response.EnsureSuccessStatusCode(); using (var fs = new FileStream( destinationPath, FileMode.Create, FileAccess.Write, FileShare.None)) { await response.Content.CopyToAsync(fs); } } } private void StartUpdaterAndExit(string newExePath) { string currentExe = Application.ExecutablePath; string cmd = $"/C timeout 2 >nul && " + $"copy /Y \"{newExePath}\" \"{currentExe}\" && " + $"start \"\" \"{currentExe}\""; Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = cmd, WindowStyle = ProcessWindowStyle.Normal, CreateNoWindow = true }); Application.Exit(); } private async void Form1_Load(object sender, EventArgs e) { await CheckForUpdateAsync(); } private void labelLauncherVersion_Click(object sender, EventArgs e) { } public class SessionResponse { public string sessionToken { get; set; } public string identityToken { get; set; } } } }