From 53db76c2156f9da4aa3903393666d9beb4df338b Mon Sep 17 00:00:00 2001 From: dginovker Date: Sat, 6 Jan 2024 13:28:43 +0900 Subject: [PATCH] Add .cs version --- 2009scape.cs | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 2009scape.cs diff --git a/2009scape.cs b/2009scape.cs new file mode 100644 index 0000000..da314f9 --- /dev/null +++ b/2009scape.cs @@ -0,0 +1,76 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Net; + +class Program +{ + static void Main() + { + string jarUrl = "https://gitlab.com/2009scape/rt4-client/-/jobs/5406815814/artifacts/raw/client/build/libs/rt4-client.jar"; + string jarPath = "rt4-client.jar"; + string javaInstallerUrl = "https://github.com/ojdkbuild/ojdkbuild/releases/download/java-1.8.0-openjdk-1.8.0.332-1.b09-x86/java-1.8.0-openjdk-1.8.0.332-1.b09.ojdkbuild.windows.x86.msi"; + string javaInstallerPath = "java_installer.msi"; + + // Download rt4-client.jar + DownloadFile(jarUrl, jarPath); + + // Write content to config.json + string jsonContent = @"{ + ""ip_management"": ""play.2009scape.org"", + ""ip_address"": ""play.2009scape.org"", + ""world"": 1, + ""server_port"": 43594, + ""wl_port"": 43595, + ""js5_port"": 43595, + ""ui_scale"": 1, + ""fps"": 0 +}"; + File.WriteAllText("config.json", jsonContent); + + // Check if Java is installed + if (!IsJavaInstalled()) + { + // Download Java installer + DownloadFile(javaInstallerUrl, javaInstallerPath); + + // Run Java installer + Process javaInstallProcess = Process.Start(javaInstallerPath); + javaInstallProcess.WaitForExit(); + } + + // Run rt4-client.jar with Java + Process.Start("java", "-jar " + jarPath); + } + + static void DownloadFile(string url, string outputPath) + { + using (WebClient client = new WebClient()) + { + client.DownloadFile(url, outputPath); + } + } + + static bool IsJavaInstalled() + { + try + { + ProcessStartInfo psi = new ProcessStartInfo + { + FileName = "java", + Arguments = "-version", + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + }; + Process proc = Process.Start(psi); + string output = proc.StandardError.ReadToEnd(); + proc.WaitForExit(); + return output.Contains("version"); + } + catch + { + return false; + } + } +}