Skip to content

Commit

Permalink
Merge UnionRemotePatcher into UnionPatcher
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit db54f75
Author: jvyden <jvyden@jvyden.xyz>
Date:   Tue Jun 14 21:50:24 2022 -0400

    Fix warnings in Program.cs, remove version

commit abab75e
Author: jvyden <jvyden@jvyden.xyz>
Date:   Tue Jun 14 21:45:08 2022 -0400

    Enforce file-scoped namespaces

commit d004b8d
Author: jvyden <jvyden@jvyden.xyz>
Date:   Tue Jun 14 21:43:53 2022 -0400

    Cleanup remote patching

commit d611df7
Author: jvyden <jvyden@jvyden.xyz>
Date:   Tue Jun 14 21:25:57 2022 -0400

    Theoretically working state

commit 18b362e
Author: jvyden <jvyden@jvyden.xyz>
Date:   Tue Jun 14 21:10:58 2022 -0400

    Import code from UnionRemotePatcher

Co-authored-by: Logan Lowe <loganr.lowe@gmail.com>
  • Loading branch information
jvyden and logantgt committed Jun 15, 2022
1 parent ff38cd2 commit 447ca7b
Show file tree
Hide file tree
Showing 11 changed files with 2,287 additions and 65 deletions.
403 changes: 398 additions & 5 deletions .gitignore

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions UnionPatcher.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System.Diagnostics;
using LBPUnion.UnionPatcher;

namespace LBPUnion.UnionPatcher.Cli;
namespace UnionPatcher.Cli;

public static class Program {
public const string Version = "1.0";

private static string fileName;


private static string? fileName;
public static string FileName {
get {
if(fileName != null) return fileName;

return fileName = Path.GetFileName(Process.GetCurrentProcess().MainModule?.FileName);
return fileName = (Path.GetFileName(Process.GetCurrentProcess().MainModule?.FileName) ?? "");
}
}

Expand Down Expand Up @@ -46,7 +45,7 @@ public static void Main(string[] args) {
}

public static void PrintHelp() {
Console.WriteLine($"UnionPatcher {Version}");
Console.WriteLine("UnionPatcher");
Console.WriteLine($" Usage: {FileName} <Input EBOOT.elf> <Server URL> <Output filename>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,21 @@
using Eto.Drawing;
using Eto.Forms;

namespace LBPUnion.UnionPatcher.Gui;
namespace LBPUnion.UnionPatcher.Gui.Forms;

public class MainForm : Form {
public class FilePatchForm : Form {
#region UI
private readonly FilePicker filePicker;
private readonly TextBox serverUrl;
private readonly FilePicker outputFileName;

public Dialog CreateOkDialog(string title, string errorMessage) {
DynamicLayout layout = new();
Button button;

layout.Spacing = new Size(5, 5);
layout.MinimumSize = new Size(350, 100);

layout.BeginHorizontal();
layout.Add(new Label {
Text = errorMessage,
});

layout.BeginHorizontal();
layout.BeginVertical();
layout.Add(null);
layout.Add(button = new Button {
Text = "OK",
});

layout.EndVertical();
layout.EndHorizontal();
layout.EndHorizontal();

Dialog dialog = new() {
Content = layout,
Padding = new Padding(10, 10, 10, 10),
Title = title,
};

button.Click += delegate {
dialog.Close();
};

return dialog;
}

public Control CreatePatchButton(int tabIndex = 0) {
Button control = new() {
Text = "Patch!",
TabIndex = tabIndex,
};

control.Click += Patch;
control.Click += this.Patch;

return control;
}
Expand All @@ -76,8 +40,8 @@ public Control CreateHelpButton(int tabIndex = 0) {
return control;
}

public MainForm() {
this.Title = "Union Patcher";
public FilePatchForm() {
this.Title = "UnionPatcher - File Patch";
this.ClientSize = new Size(500, -1);
this.Content = new TableLayout {
Spacing = new Size(5,5),
Expand Down Expand Up @@ -109,27 +73,27 @@ private void Patch(object sender, EventArgs e) {

private void Patch() {
if(string.IsNullOrWhiteSpace(this.filePicker.FilePath)) {
this.CreateOkDialog("Form Error", "No file specified!").ShowModal();
Gui.CreateOkDialog("Form Error", "No file specified!").ShowModal();
return;
}

if(string.IsNullOrWhiteSpace(this.serverUrl.Text)) {
this.CreateOkDialog("Form Error", "No server URL specified!").ShowModal();
Gui.CreateOkDialog("Form Error", "No server URL specified!").ShowModal();
return;
}

if(string.IsNullOrWhiteSpace(this.outputFileName.FilePath)) {
this.CreateOkDialog("Form Error", "No output file specified!").ShowModal();
Gui.CreateOkDialog("Form Error", "No output file specified!").ShowModal();
return;
}

if(this.filePicker.FilePath == this.outputFileName.FilePath) {
this.CreateOkDialog("Form Error", "Input and output filename are the same! Please save the patched file with a different name so you have a backup of your the original EBOOT.ELF.").ShowModal();
Gui.CreateOkDialog("Form Error", "Input and output filename are the same! Please save the patched file with a different name so you have a backup of your the original EBOOT.ELF.").ShowModal();
return;
}

if(!Uri.TryCreate(this.serverUrl.Text, UriKind.Absolute, out _)) {
this.CreateOkDialog("Form Error", "Server URL is invalid! Please enter a valid URL.").ShowModal();
Gui.CreateOkDialog("Form Error", "Server URL is invalid! Please enter a valid URL.").ShowModal();
return;
}

Expand All @@ -138,28 +102,28 @@ private void Patch() {
ElfFile eboot = new(this.filePicker.FilePath);

if(eboot.IsValid == false) {
this.CreateOkDialog("EBOOT Error", $"{eboot.Name} is not a valid ELF file (magic number mismatch)\n" + "The EBOOT must be decrypted before using this tool").ShowModal();
Gui.CreateOkDialog("EBOOT Error", $"{eboot.Name} is not a valid ELF file (magic number mismatch)\n" + "The EBOOT must be decrypted before using this tool").ShowModal();
return;
}

if(eboot.Is64Bit == null) {
this.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid system").ShowModal();
Gui.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid system").ShowModal();
return;
}

if(string.IsNullOrWhiteSpace(eboot.Architecture)) {
this.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid architecture (PowerPC or ARM)").ShowModal();
Gui.CreateOkDialog("EBOOT Error", $"{eboot.Name} does not target a valid architecture (PowerPC or ARM)").ShowModal();
return;
}

try {
Patcher.PatchFile(this.filePicker.FilePath, this.serverUrl.Text, this.outputFileName.FilePath);
}
catch(Exception e) {
this.CreateOkDialog("Error occurred while patching", "An error occured while patching:\n" + e).ShowModal();
Gui.CreateOkDialog("Error occurred while patching", "An error occured while patching:\n" + e).ShowModal();
return;
}

this.CreateOkDialog("Success!", "The Server URL has been patched to " + this.serverUrl.Text).ShowModal();
Gui.CreateOkDialog("Success!", "The Server URL has been patched to " + this.serverUrl.Text).ShowModal();
}
}
42 changes: 42 additions & 0 deletions UnionPatcher.Gui/Forms/ModeSelectionForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using Eto.Drawing;
using Eto.Forms;

namespace LBPUnion.UnionPatcher.Gui.Forms;

public class ModeSelectionForm : Form {
#region UI
public ModeSelectionForm() {
this.Title = "Welcome to UnionPatcher";
this.ClientSize = new Size(500, -1);
this.Content = new TableLayout {
Spacing = new Size(5, 5),
Padding = new Padding(10, 10, 10, 10),
Rows = {
new TableRow(
new TableCell(new Button(openRemotePatcher) { Text = "Remote Patcher (PS3)" })
),
new TableRow(
new TableCell(new Button(openLocalPatcher) { Text = "Local Patch (RPCS3)", Enabled = false })
),
new TableRow(
new TableCell(new Button(openFilePatcher) { Text = "File Patch (PS3/RPCS3)" })
),
},
};
}

private void openRemotePatcher(object sender, EventArgs e) {
new RemotePatchForm().Show();
this.Close();
}
private void openLocalPatcher(object sender, EventArgs e) {
throw new NotImplementedException();
}
private void openFilePatcher(object sender, EventArgs e) {
new FilePatchForm().Show();
this.Close();
}

#endregion
}
Loading

0 comments on commit 447ca7b

Please sign in to comment.