mirror of
https://github.com/LBPUnion/UnionPatcher.git
synced 2025-04-23 13:05:17 +00:00
Add CLI patcher
This commit is contained in:
parent
8957792a80
commit
0c9de325be
6 changed files with 110 additions and 0 deletions
|
@ -13,6 +13,7 @@ namespace UnionPatcher.Gui {
|
|||
|
||||
control.Click += delegate {
|
||||
Console.WriteLine("patch button clicked");
|
||||
// Program.Test();
|
||||
};
|
||||
|
||||
return control;
|
||||
|
|
|
@ -9,4 +9,8 @@
|
|||
<PackageReference Include="Eto.Forms" Version="2.5.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UnionPatcher\UnionPatcher.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -6,6 +6,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnionPatcher.Gui.Windows",
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnionPatcher.Gui.Linux", "UnionPatcher.Gui.Linux\UnionPatcher.Gui.Linux.csproj", "{55DFA962-3EC5-44E4-9F93-FACF3E7EEBB2}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Gui", "Gui", "{59194212-45BB-4A27-A08F-54DB6ADA26B3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnionPatcher", "UnionPatcher\UnionPatcher.csproj", "{1CEC657B-5C05-44FB-941B-3C41411A7BB8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -24,5 +28,14 @@ Global
|
|||
{55DFA962-3EC5-44E4-9F93-FACF3E7EEBB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{55DFA962-3EC5-44E4-9F93-FACF3E7EEBB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{55DFA962-3EC5-44E4-9F93-FACF3E7EEBB2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1CEC657B-5C05-44FB-941B-3C41411A7BB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1CEC657B-5C05-44FB-941B-3C41411A7BB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1CEC657B-5C05-44FB-941B-3C41411A7BB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1CEC657B-5C05-44FB-941B-3C41411A7BB8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{235B4DEC-11A0-42EF-9B8D-16529869ED1A} = {59194212-45BB-4A27-A08F-54DB6ADA26B3}
|
||||
{55DFA962-3EC5-44E4-9F93-FACF3E7EEBB2} = {59194212-45BB-4A27-A08F-54DB6ADA26B3}
|
||||
{5F8CDEA2-B483-40D1-B1FB-EF8EC667185A} = {59194212-45BB-4A27-A08F-54DB6ADA26B3}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
51
UnionPatcher/Patcher.cs
Normal file
51
UnionPatcher/Patcher.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace UnionPatcher {
|
||||
public static class Patcher {
|
||||
private static readonly string[] ToBePatched = {
|
||||
"https://littlebigplanetps3.online.scee.com:10061/LITTLEBIGPLANETPS3_XML",
|
||||
"http://littlebigplanetps3.online.scee.com:10060/LITTLEBIGPLANETPS3_XML",
|
||||
};
|
||||
|
||||
public static void PatchFile(string fileName, string serverUrl, string outputFileName) {
|
||||
File.WriteAllBytes(outputFileName, PatchData(File.ReadAllBytes(fileName), serverUrl));
|
||||
}
|
||||
|
||||
public static byte[] PatchData(byte[] data, string serverUrl) {
|
||||
string dataAsString = Encoding.ASCII.GetString(data);
|
||||
|
||||
using MemoryStream ms = new(data);
|
||||
using BinaryWriter writer = new(ms);
|
||||
|
||||
// using writer.Write(string) writes the length as a byte beforehand which is problematic
|
||||
byte[] serverUrlAsBytes = Encoding.ASCII.GetBytes(serverUrl);
|
||||
|
||||
foreach(string url in ToBePatched) {
|
||||
if(serverUrl.Length > url.Length) {
|
||||
throw new ArgumentOutOfRangeException(nameof(serverUrl), $"Server URL ({serverUrl.Length} characters long) is above maximum length {url.Length}");
|
||||
}
|
||||
|
||||
int offset = dataAsString.IndexOf(url, StringComparison.Ordinal);
|
||||
if(offset < 1) {
|
||||
Console.WriteLine($"URL {url} not found!");
|
||||
continue;
|
||||
}
|
||||
|
||||
writer.BaseStream.Position = offset;
|
||||
for(int i = 0; i < url.Length; i++) {
|
||||
writer.Write((byte)0x00); // Zero out data
|
||||
}
|
||||
|
||||
writer.BaseStream.Position = offset; // Reset position to beginning
|
||||
writer.Write(serverUrlAsBytes);
|
||||
}
|
||||
|
||||
writer.Flush();
|
||||
writer.Close();
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
33
UnionPatcher/Program.cs
Normal file
33
UnionPatcher/Program.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace UnionPatcher {
|
||||
public static class Program {
|
||||
public const string Version = "1.0";
|
||||
|
||||
private static string fileName;
|
||||
|
||||
public static string FileName {
|
||||
get {
|
||||
if(fileName != null) return fileName;
|
||||
|
||||
return fileName = Path.GetFileName(Process.GetCurrentProcess().MainModule?.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Main(string[] args) {
|
||||
Patcher.PatchFile("EBOOT.elf", "https://lighthouse.lbpunion.com:10061/LITTLEBIGPLANETPS3_XML", "EBOOT.new.elf");
|
||||
if(args.Length < 3) {
|
||||
PrintHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void PrintHelp() {
|
||||
Console.WriteLine($"UnionPatcher {Version}");
|
||||
Console.WriteLine($" Usage: {FileName} <Input EBOOT.elf> <Server URL> <Output filename>");
|
||||
}
|
||||
}
|
||||
}
|
8
UnionPatcher/UnionPatcher.csproj
Normal file
8
UnionPatcher/UnionPatcher.csproj
Normal file
|
@ -0,0 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Add table
Reference in a new issue