Skip to content

Commit

Permalink
Another ModNet Support
Browse files Browse the repository at this point in the history
  • Loading branch information
MeTonaTOR committed Dec 29, 2019
1 parent bc921dd commit a7d5653
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 13 deletions.
6 changes: 5 additions & 1 deletion GameLauncher/App/Classes/HashPassword/MD5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions GameLauncher/App/Classes/JsonScheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
113 changes: 104 additions & 9 deletions GameLauncher/App/MainScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -1980,8 +1983,7 @@ private void playButton_Click(object sender, EventArgs e) {

IndexJson json3 = JsonConvert.DeserializeObject<IndexJson>(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);
Expand Down Expand Up @@ -2035,8 +2037,7 @@ private void playButton_Click(object sender, EventArgs e) {
String jsonindex = new WebClientWithTimeout().DownloadString(newIndexFile);
List<ElectronIndex> json3 = JsonConvert.DeserializeObject<List<ElectronIndex>>(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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
});
}

Expand Down
4 changes: 2 additions & 2 deletions GameLauncher/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 1 addition & 1 deletion GameLauncher/Properties/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
Expand Down

0 comments on commit a7d5653

Please sign in to comment.