Skip to content

Commit

Permalink
feat: add port update
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizo55 committed Jul 1, 2024
1 parent a221403 commit 278ff4a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/MulticlientCreator/HexFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 39 additions & 5 deletions src/MulticlientCreator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using MulticlientCreator.Helpers;
using System;
using System.IO;
using System.Linq;
using System.Text;

namespace MulticlientCreator
Expand All @@ -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)
{
Expand All @@ -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 !");
}
Expand All @@ -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()!;
}

Expand All @@ -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(".");
Expand Down

0 comments on commit 278ff4a

Please sign in to comment.