Skip to content

Commit a037f52

Browse files
committed
Add ElfToElfPatchPipeline
1 parent 124708a commit a037f52

File tree

6 files changed

+98
-1
lines changed

6 files changed

+98
-1
lines changed

Refresher.Core/Pipelines/CommonStepInputs.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public static class CommonStepInputs
3131
Placeholder = "(leave empty to randomize)",
3232
};
3333

34+
internal static readonly StepInput ElfInput = new("elf-input", "Input .ELF", StepInputType.OpenFile)
35+
{
36+
Placeholder = @"C:\path\to\EBOOT.elf",
37+
};
38+
39+
internal static readonly StepInput ElfOutput = new("elf-output", "Output .ELF", StepInputType.SaveFile)
40+
{
41+
Placeholder = @"C:\path\to\EBOOT.elf",
42+
};
43+
3444
// TODO: Cache the last used location for easier entry
3545
private static string? DetermineDefaultRpcs3Path()
3646
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Refresher.Core.Pipelines.Steps;
2+
3+
namespace Refresher.Core.Pipelines;
4+
5+
public class ElfToElfPatchPipeline : Pipeline
6+
{
7+
public override string Id => "elf-elf-patch";
8+
public override string Name => ".elf->.elf Patch";
9+
10+
protected override List<Type> StepTypes =>
11+
[
12+
typeof(InputElfStep),
13+
14+
typeof(PrepareEbootPatcherAndVerifyStep),
15+
typeof(ApplyPatchToEbootStep),
16+
17+
typeof(OutputElfStep),
18+
];
19+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Refresher.Core.Patching;
2+
3+
namespace Refresher.Core.Pipelines.Steps;
4+
5+
public class InputElfStep : Step
6+
{
7+
public InputElfStep(Pipeline pipeline) : base(pipeline)
8+
{}
9+
10+
public override List<StepInput> Inputs =>
11+
[
12+
CommonStepInputs.ElfInput,
13+
];
14+
15+
public override float Progress { get; protected set; }
16+
public override Task ExecuteAsync(CancellationToken cancellationToken = default)
17+
{
18+
string elfInput = this.Inputs.First().GetValueFromPipeline(this.Pipeline);
19+
if (!File.Exists(elfInput))
20+
throw new FileNotFoundException("The Input .ELF could not be found.");
21+
22+
string temp = Path.GetTempFileName();
23+
24+
{
25+
using FileStream write = File.OpenWrite(temp);
26+
using FileStream read = File.OpenRead(elfInput);
27+
read.CopyTo(write);
28+
}
29+
30+
this.Pipeline.GameInformation = new GameInformation
31+
{
32+
DecryptedEbootPath = temp,
33+
Name = Path.GetFileName(elfInput),
34+
TitleId = "UNKN12345",
35+
};
36+
37+
return Task.CompletedTask;
38+
}
39+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace Refresher.Core.Pipelines.Steps;
2+
3+
public class OutputElfStep : Step
4+
{
5+
public OutputElfStep(Pipeline pipeline) : base(pipeline)
6+
{}
7+
8+
public override List<StepInput> Inputs =>
9+
[
10+
CommonStepInputs.ElfOutput,
11+
];
12+
13+
public override float Progress { get; protected set; }
14+
public override Task ExecuteAsync(CancellationToken cancellationToken = default)
15+
{
16+
string elfOutput = this.Inputs.First().GetValueFromPipeline(this.Pipeline);
17+
// if (File.Exists(elfOutput))
18+
// TODO: ask user if they want to replace
19+
20+
File.Copy(this.Game.DecryptedEbootPath!, Path.GetFullPath(elfOutput));
21+
22+
return Task.CompletedTask;
23+
}
24+
}

Refresher/UI/MainForm.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ public class MainForm : RefresherForm
2424
this.PipelineButton<PatchworkRPCS3ConfigPipeline>("Reconfigure Patch for RPCS3"),
2525

2626
new Label { Text = "General (for non-LBP games):" },
27-
new Button((_, _) => this.ShowChild<FilePatchForm>()) { Text = "File Patch (using a .ELF)" },
2827
this.PipelineButton<RPCS3PatchPipeline>("Patch any RPCS3 game"),
2928
this.PipelineButton<PS3PatchPipeline>("Patch any PS3 game"),
3029

30+
new Label { Text = "Advanced (for experts):" },
31+
new Button((_, _) => this.ShowChild<FilePatchForm>()) { Text = "File Patch (using a .ELF)" },
32+
this.PipelineButton<ElfToElfPatchPipeline>(".elf->.elf Patch"),
33+
3134
#if DEBUG
3235
new Label { Text = "Debugging options:" },
3336
this.PipelineButton<ExamplePipeline>("Example Pipeline"),

Refresher/UI/PipelineForm.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ private void InitializePipeline()
144144
row = AddField<TextBox>(input, value);
145145
break;
146146
case StepInputType.Directory:
147+
case StepInputType.OpenFile:
148+
case StepInputType.SaveFile:
147149
row = AddField<FilePicker>(input, value);
148150
if (input.ShouldCauseGameDownloadWhenChanged)
149151
{

0 commit comments

Comments
 (0)