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++) {