From 3d8473129ac64a5f9f9a9a90d4a37a6e355b6916 Mon Sep 17 00:00:00 2001 From: Dagg <32235163+daggintosh@users.noreply.github.com> Date: Tue, 13 Sep 2022 15:15:04 -0700 Subject: [PATCH] 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 --- UnionPatcher/Patcher.cs | 45 +++++++++++------------------------------ 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/UnionPatcher/Patcher.cs b/UnionPatcher/Patcher.cs index 17e3bcb..7593974 100644 --- a/UnionPatcher/Patcher.cs +++ b/UnionPatcher/Patcher.cs @@ -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++) {