From 278ff4ad2c70294f71c6fb22f05c29af51790a0e Mon Sep 17 00:00:00 2001 From: Fizo55 Date: Mon, 1 Jul 2024 15:15:07 +0200 Subject: [PATCH] feat: add port update --- src/MulticlientCreator/HexFinder.cs | 8 ++++-- src/MulticlientCreator/Program.cs | 44 +++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/MulticlientCreator/HexFinder.cs b/src/MulticlientCreator/HexFinder.cs index b8e5302..13abc77 100644 --- a/src/MulticlientCreator/HexFinder.cs +++ b/src/MulticlientCreator/HexFinder.cs @@ -7,21 +7,23 @@ public class HexFinder { private readonly string _nostalePath; private readonly string _newIp; + private readonly string _newPort; - public HexFinder(string nostalePath, string newIp) + public HexFinder(string nostalePath, string newIp, string newPort) { _nostalePath = nostalePath; _newIp = newIp; + _newPort = newPort; } - public bool ReplaceIpPattern(string ipPattern) + public bool ReplaceIpPattern(string ipPattern, string portPattern) { byte[] byteData; using (var fileStream = new FileStream(_nostalePath, FileMode.Open, FileAccess.Read)) byteData = DeserializationHelper.ReadFully(fileStream); string oldHex = HexHelper.ToHexString(byteData); - string newHex = oldHex.Replace(ipPattern, _newIp); + string newHex = oldHex.Replace(ipPattern, _newIp).Replace(portPattern, _newPort); if (oldHex == newHex) return false; diff --git a/src/MulticlientCreator/Program.cs b/src/MulticlientCreator/Program.cs index 542a312..04c5b4e 100644 --- a/src/MulticlientCreator/Program.cs +++ b/src/MulticlientCreator/Program.cs @@ -1,7 +1,6 @@ using MulticlientCreator.Helpers; using System; using System.IO; -using System.Linq; using System.Text; namespace MulticlientCreator @@ -10,6 +9,7 @@ public class Program { private const string OfficialName = "NostaleClientX.exe"; private const string Pattern = "0C00000037392E3131302E38342E373500000000"; + private const string PortPattern = "00A00F0000A10F0000A20F0000A00F0000A00F0000A00F0000A30F0000000000000000000000000000"; public static void Main(string[] args) { @@ -24,13 +24,22 @@ public static void Main(string[] args) var newIpPattern = string.Empty; if (fileString.Contains(Pattern)) { - WriteMessage(ConsoleColor.DarkGreen, "Pattern found !"); + WriteMessage(ConsoleColor.DarkGreen, "Ip pattern found !"); var ip = PromptForIpAddress(); newIpPattern = GenerateIpPattern(ip); } - var finder = new HexFinder(finalPath, newIpPattern); - if (finder.ReplaceIpPattern(Pattern)) + var newPortPattern = string.Empty; + if (fileString.Contains(PortPattern)) + { + WriteMessage(ConsoleColor.DarkGreen, "Port pattern found !"); + var port = PromptForPort(); + newPortPattern = GeneratePortPattern(port); + Console.WriteLine($"Port pattern: {newPortPattern}"); + } + + var finder = new HexFinder(finalPath, newIpPattern, newPortPattern); + if (finder.ReplaceIpPattern(Pattern, PortPattern)) { WriteMessage(ConsoleColor.DarkGreen, "Your multiclient has been successfully generated !"); } @@ -52,7 +61,13 @@ private static string PromptForNostalePath() private static string PromptForIpAddress() { - WriteMessage(ConsoleColor.Magenta, "Enter your VPS IP: "); + WriteMessage(ConsoleColor.Magenta, "Enter your ip: "); + return Console.ReadLine()!; + } + + private static string PromptForPort() + { + WriteMessage(ConsoleColor.Magenta, "Enter your port: "); return Console.ReadLine()!; } @@ -62,6 +77,25 @@ private static byte[] ReadBytesFromFile(string path) return DeserializationHelper.ReadFully(fileStream); } + private static string GeneratePortPattern(string basePort) + { + int port = int.Parse(basePort); + string hexPort = port.ToString("X4"); + string hexPortRearranged = hexPort.Substring(2, 2) + hexPort[..2]; + var builder = new StringBuilder(); + + builder.Append("00"); + + for (int i = 0; i < 7; i++) + { + builder.Append(hexPortRearranged).Append("0000"); + } + + builder.Append("000000000000000000000000"); + + return builder.ToString(); + } + private static string GenerateIpPattern(string ip) { var split = ip.Split(".");