From a7d5653892ea0782b0810f43d1599fffd979d28c Mon Sep 17 00:00:00 2001 From: MeTonaTOR Date: Sun, 29 Dec 2019 01:05:08 +0100 Subject: [PATCH] Another ModNet Support --- GameLauncher/App/Classes/HashPassword/MD5.cs | 6 +- GameLauncher/App/Classes/JsonScheme.cs | 1 + GameLauncher/App/MainScreen.cs | 113 +++++++++++++++++-- GameLauncher/Properties/AssemblyInfo.cs | 4 +- GameLauncher/Properties/app.manifest | 2 +- 5 files changed, 113 insertions(+), 13 deletions(-) diff --git a/GameLauncher/App/Classes/HashPassword/MD5.cs b/GameLauncher/App/Classes/HashPassword/MD5.cs index 7a23e172..01c24c66 100644 --- a/GameLauncher/App/Classes/HashPassword/MD5.cs +++ b/GameLauncher/App/Classes/HashPassword/MD5.cs @@ -23,7 +23,11 @@ public static string HashFile(string filename) { if (!File.Exists(filename)) return String.Empty; MD5 md5 = new MD5CryptoServiceProvider(); - byte[] retVal = md5.ComputeHash(File.OpenRead(filename)); + byte[] retVal = new byte[] { }; + + using (var test = File.OpenRead(filename)) { + retVal = md5.ComputeHash(test); + } StringBuilder sb = new StringBuilder(); for (int i = 0; i < retVal.Length; i++) { diff --git a/GameLauncher/App/Classes/JsonScheme.cs b/GameLauncher/App/Classes/JsonScheme.cs index 7f839805..2fa22f20 100644 --- a/GameLauncher/App/Classes/JsonScheme.cs +++ b/GameLauncher/App/Classes/JsonScheme.cs @@ -25,6 +25,7 @@ public class GetServerInformation { public string modernAuthSupport { get; set; } public int secondsToShutDown { get; set; } public string modsUrl { get; set; } + public bool rwacallow { get; set; } } public class FreeroamObject { diff --git a/GameLauncher/App/MainScreen.cs b/GameLauncher/App/MainScreen.cs index d0bf1ec9..857144ef 100644 --- a/GameLauncher/App/MainScreen.cs +++ b/GameLauncher/App/MainScreen.cs @@ -85,6 +85,9 @@ public sealed partial class MainScreen : Form { private string _realServernameBanner; private string _OS; + int CountFiles = 0; + int CountFilesTotal = 0; + private Point _startPoint = new Point(38, 144); private Point _endPoint = new Point(562, 144); @@ -1855,7 +1858,7 @@ private void LaunchGame(string userId, string loginToken, string serverIp, Form secondsToShutDownNamed = "Waiting for event to finish."; } - //User32.SetWindowText((IntPtr)p, _realServername + " - Time Remaining: " + secondsToShutDownNamed); + User32.SetWindowText((IntPtr)p, "[" + secondsToShutDownNamed + "] " + _realServername); } } @@ -1980,8 +1983,7 @@ private void playButton_Click(object sender, EventArgs e) { IndexJson json3 = JsonConvert.DeserializeObject(jsonindex); - int CountFiles = 0; - int CountFilesTotal = json3.entries.Count; + CountFilesTotal = json3.entries.Count; String path = Path.Combine(_settingFile.Read("InstallationDirectory"), "MODS", MDFive.HashPassword(json2.serverID).ToLower()); if(!Directory.Exists(path)) Directory.CreateDirectory(path); @@ -2035,8 +2037,7 @@ private void playButton_Click(object sender, EventArgs e) { String jsonindex = new WebClientWithTimeout().DownloadString(newIndexFile); List json3 = JsonConvert.DeserializeObject>(jsonindex); - int CountFiles = 0; - int CountFilesTotal = json3.Count; + CountFilesTotal = json3.Count; String electronpath = (new Uri(_serverIp).Host).Replace(".", "-"); String path = Path.Combine(_settingFile.Read("InstallationDirectory"), "MODS", electronpath); @@ -2064,7 +2065,6 @@ private void playButton_Click(object sender, EventArgs e) { foreach (ElectronIndex modfile in json3) { String directorycreate = Path.GetDirectoryName(path + "/" + modfile.file); Directory.CreateDirectory(directorycreate); - if (ElectronModNet.calculateHash(path + "/" + modfile.file) != modfile.hash) { WebClientWithTimeout client2 = new WebClientWithTimeout(); @@ -2092,7 +2092,102 @@ private void playButton_Click(object sender, EventArgs e) { } } - } else { + } else if(json.rwacallow == true) { + ModManager.ResetModDat(_settingFile.Read("InstallationDirectory")); + + playProgressText.Text = "RWAC support detected, checking mods...".ToUpper(); + + try { + Directory.CreateDirectory(_settingFile.Read("InstallationDirectory")); + File.WriteAllBytes(_settingFile.Read("InstallationDirectory") + "/dinput8.dll", ExtractResource.AsByte("GameLauncher.SoapBoxModules.dinput8.dll")); + Directory.CreateDirectory(_settingFile.Read("InstallationDirectory") + "/scripts"); + File.WriteAllText(_settingFile.Read("InstallationDirectory") + "/scripts/global.ini", ExtractResource.AsString("GameLauncher.SoapBoxModules.global.ini")); + File.WriteAllBytes(_settingFile.Read("InstallationDirectory") + "/ModManager.asi", ExtractResource.AsByte("GameLauncher.SoapBoxModules.ModManager.dll")); + } + catch (Exception) { } + + //First lets assume new path for RWAC Mods + String rwacpath = MDFive.HashPassword(new Uri(_serverIp).Host); + String path = Path.Combine(_settingFile.Read("InstallationDirectory"), "MODS", rwacpath); + + //Then, lets fetch its XML File + Uri rwac_wev2 = new Uri(json.homePageUrl + "/rwac/fileschecker_sbrw.xml"); + String getcontent = new WebClient().DownloadString(rwac_wev2); + + playProgressText.Text = "Got files for RWAC... downloading...".ToUpper(); + + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(getcontent); + var nodes = xmlDoc.SelectNodes("rwac/files/file"); + + CountFilesTotal = nodes.Count; + + //ModManager.dat + using (var fs = new FileStream(Path.Combine(_settingFile.Read("InstallationDirectory"), "ModManager.dat"), FileMode.Create)) + using (var bw = new BinaryWriter(fs)) { + bw.Write(nodes.Count); + + foreach (XmlNode files in nodes) { + //if(!(files.Attributes["name"].Value).Contains(".dll") && !(files.Attributes["name"].Value).Contains(".exe")) { + string realfilepath = Path.Combine(files.Attributes["path"].Value, files.Attributes["name"].Value); + String directorycreate = Path.GetDirectoryName(path + "/" + realfilepath); + + var originalPath = Path.Combine(_settingFile.Read("InstallationDirectory"), realfilepath).Replace("/", "\\").ToUpper(); + var modPath = Path.Combine(path, realfilepath).Replace("/", "\\").ToUpper(); + + bw.Write(originalPath.Length); + bw.Write(originalPath.ToCharArray()); + bw.Write(modPath.Length); + bw.Write(modPath.ToCharArray()); + + Directory.CreateDirectory(directorycreate); + if(files.Attributes["download"].Value != String.Empty) { + if (MDFive.HashFile(path + "/" + realfilepath).ToLower() != files.InnerText) { + WebClientWithTimeout client2 = new WebClientWithTimeout(); + client2.DownloadFileAsync(new Uri(files.Attributes["download"].Value), path + "/" + realfilepath); + + client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); + client2.DownloadFileCompleted += (test, stuff) => { + if (MDFive.HashFile(path + "/" + realfilepath).ToLower() == files.InnerText) { + CountFiles++; + + if (CountFiles == CountFilesTotal) { + LaunchGame(); + } + } else { + String xddd = "Corrupted file found: " + realfilepath; + xddd += "\nGot: " + MDFive.HashFile(path + "/" + realfilepath); + xddd += "\nExpected: " + files.InnerText; + + MessageBox.Show(xddd); + File.Delete(path + "/" + realfilepath); + playButton_Click(sender, e); + } + }; + } else { + CountFiles++; + + if (CountFiles == CountFilesTotal) { + LaunchGame(); + } + } + } else { + CountFiles++; + + if (CountFiles == CountFilesTotal) { + LaunchGame(); + } + } + //} else { + // CountFiles++; + + // if (CountFiles == CountFilesTotal) { + // LaunchGame(); + // } + //} + } + } + } else { playProgressText.Text = "LegacyModNet support detected, checking mods...".ToUpper(); try { @@ -2122,8 +2217,8 @@ void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventA double percentage = bytesIn / totalBytes * 100; playProgressText.Text = ("Downloaded " + FormatFileSize(e.BytesReceived) + " of " + FormatFileSize(e.TotalBytesToReceive)).ToUpper(); - extractingProgress.Value = Convert.ToInt32(Decimal.Divide(e.BytesReceived, e.TotalBytesToReceive) * 100); - extractingProgress.Width = Convert.ToInt32(Decimal.Divide(e.BytesReceived, e.TotalBytesToReceive) * 519); + extractingProgress.Value = Convert.ToInt32(Decimal.Divide(CountFiles, CountFilesTotal) * 100); + extractingProgress.Width = Convert.ToInt32(Decimal.Divide(CountFiles, CountFilesTotal) * 519); }); } diff --git a/GameLauncher/Properties/AssemblyInfo.cs b/GameLauncher/Properties/AssemblyInfo.cs index dcefdc25..a7d67d14 100644 --- a/GameLauncher/Properties/AssemblyInfo.cs +++ b/GameLauncher/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // Możesz określić wszystkie wartości lub użyć domyślnych numerów kompilacji i poprawki // przy użyciu symbolu „*”, tak jak pokazano poniżej: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.7.4")] -[assembly: AssemblyFileVersion("2.0.7.4")] +[assembly: AssemblyVersion("2.0.7.5")] +[assembly: AssemblyFileVersion("2.0.7.5")] diff --git a/GameLauncher/Properties/app.manifest b/GameLauncher/Properties/app.manifest index d9218d44..d4253c3f 100644 --- a/GameLauncher/Properties/app.manifest +++ b/GameLauncher/Properties/app.manifest @@ -4,7 +4,7 @@ - +