mirror of
https://github.com/LBPUnion/UnionPatcher.git
synced 2025-04-23 13:05:17 +00:00
Added regex matching to find index of LBP server URLs (#27)
* Use regex to discover existing server urls - Supports LBP PSP and PS3 - Hardcoded length limit, will fix soonTM * Get maximum length for server URL from EBOOT * Potential fix for LBP3 - Matches all but NULL instead of just all * Potentially extend maximum length Thanks slendy * Leave a NULL character of padding
This commit is contained in:
parent
8f6ba8b535
commit
3d8473129a
1 changed files with 12 additions and 33 deletions
|
@ -1,37 +1,11 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace LBPUnion.UnionPatcher;
|
||||
|
||||
public static class Patcher {
|
||||
private static readonly string[] toBePatched = {
|
||||
// Normal LittleBigPlanet gameserver URLs
|
||||
"https://littlebigplanetps3.online.scee.com:10061/LITTLEBIGPLANETPS3_XML",
|
||||
"http://littlebigplanetps3.online.scee.com:10060/LITTLEBIGPLANETPS3_XML",
|
||||
// LittleBigPlanet 3 Presence URLs
|
||||
"http://live.littlebigplanetps3.online.scee.com:10060/LITTLEBIGPLANETPS3_XML",
|
||||
"http://presence.littlebigplanetps3.online.scee.com:10060/LITTLEBIGPLANETPS3_XML",
|
||||
#region Spinoff URLs
|
||||
// LittleBigPlanet PSP URLs
|
||||
"http://lbppsp.online.scee.com:10060/LITTLEBIGPLANETPSP_XML",
|
||||
"https://lbppsp.online.scee.com:10061/LITTLEBIGPLANETPSP_XML",
|
||||
// LittleBigPlanet Vita URLs
|
||||
"http://lbpvita.online.scee.com:10060/LITTLEBIGPLANETPS3_XML",
|
||||
"https://lbpvita.online.scee.com:10061/LITTLEBIGPLANETPS3_XML",
|
||||
#endregion
|
||||
#region Beta URLS
|
||||
// LittleBigPlanet 2 Beta URLs
|
||||
"http://lbp2ps3-beta.online.scee.com:10060/LITTLEBIGPLANETPS3_XML",
|
||||
"https://lbp2ps3-beta.online.scee.com:10061/LITTLEBIGPLANETPS3_XML",
|
||||
// LittleBigPlanet (3?) Beta URLs
|
||||
"http://littlebigplanetps3-beta.online.scee.com:10060/LITTLEBIGPLANETPS3_XML",
|
||||
"https://littlebigplanetps3-beta.online.scee.com:10061/LITTLEBIGPLANETPS3_XML",
|
||||
// LittleBigPlanet Vita Beta URLs
|
||||
"http://lbpvita-beta.online.scee.com:10060/LITTLEBIGPLANETPS3_XML",
|
||||
"https://lbpvita-beta.online.scee.com:10061/LITTLEBIGPLANETPS3_XML",
|
||||
#endregion
|
||||
};
|
||||
|
||||
public static void PatchFile(string fileName, Uri serverUrl, string outputFileName) {
|
||||
PatchFile(fileName, serverUrl.ToString(), outputFileName);
|
||||
|
@ -72,13 +46,18 @@ public static class Patcher {
|
|||
byte[] serverUrlAsBytes = Encoding.ASCII.GetBytes(serverUrl);
|
||||
|
||||
bool wroteUrl = false;
|
||||
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}");
|
||||
|
||||
// Find a string including http or https and LITTLEBIGPLANETPS3_XML or LITTLEBIGPLANETPSP_XML,
|
||||
// then match any additional NULL characters to dynamically gague the maximum length on a per-title basis
|
||||
// without a hardcoded array of known server URLs
|
||||
MatchCollection urls = Regex.Matches(dataAsString, "http?[^\x00]*?LITTLEBIGPLANETPS(3|P)_XML\x00*");
|
||||
foreach(Match urlMatch in urls) {
|
||||
string url = urlMatch.Value;
|
||||
|
||||
if(serverUrl.Length > url.Length - 1) {
|
||||
throw new ArgumentOutOfRangeException(nameof(serverUrl), $"Server URL ({serverUrl.Length} characters long) is above maximum length {url.Length - 1}");
|
||||
}
|
||||
|
||||
int offset = dataAsString.IndexOf(url, StringComparison.Ordinal);
|
||||
if(offset < 1) continue;
|
||||
int offset = urlMatch.Index;
|
||||
|
||||
writer.BaseStream.Position = offset;
|
||||
for(int i = 0; i < url.Length; i++) {
|
||||
|
|
Loading…
Add table
Reference in a new issue