From 704ce90b213223b1805ad884565293b5ffaf4dbc Mon Sep 17 00:00:00 2001 From: Dagg Date: Thu, 8 Sep 2022 14:41:53 -0700 Subject: [PATCH] Use regex to discover existing server urls - Supports LBP PSP and PS3 - Hardcoded length limit, will fix soonTM --- UnionPatcher/Patcher.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/UnionPatcher/Patcher.cs b/UnionPatcher/Patcher.cs index 17e3bcb..6de78d9 100644 --- a/UnionPatcher/Patcher.cs +++ b/UnionPatcher/Patcher.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Text; +using System.Text.RegularExpressions; namespace LBPUnion.UnionPatcher; @@ -72,13 +73,18 @@ public static class Patcher { byte[] serverUrlAsBytes = Encoding.ASCII.GetBytes(serverUrl); bool wroteUrl = false; - foreach(string url in toBePatched) { - if(serverUrl.Length > url.Length) { + + // Find a string including http or https and LITTLEBIGPLANETPS3_XML or LITTLEBIGPLANETPSP_XML + MatchCollection urls = Regex.Matches(dataAsString, "https?.*?LITTLEBIGPLANETPS(3|P)_XML"); + foreach(Match urlMatch in urls) { + string url = urlMatch.Value; + + // Hard coded 79 max length + // TODO: Get length of index to next data in EBOOT to calcuate true maximum length + if(serverUrl.Length > 79) { 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) continue; + int offset = urlMatch.Index; writer.BaseStream.Position = offset; for(int i = 0; i < url.Length; i++) {