Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Updated for AU v2020.10.22s;
Browse files Browse the repository at this point in the history
Added domain name resolution;
  • Loading branch information
andruzzzhka committed Nov 3, 2020
1 parent 75a01cc commit 0335a09
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 41 deletions.
4 changes: 0 additions & 4 deletions CustomServersClient/CustomServerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ public class CustomServerInfo
public string ip;
public int port;

public int hash;

public CustomServerInfo(string name, string ip, int port)
{
this.name = name;
this.ip = ip;
this.port = port;

hash = name.GetHashCode() + ip.GetHashCode() + port.GetHashCode();
}

public override string ToString()
Expand Down
3 changes: 1 addition & 2 deletions CustomServersClient/CustomServersClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\unhollowed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Among Us\BepInEx\unhollowed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx.Core">
<HintPath>D:\andru\Desktop\Among Us\BepInEx\core\BepInEx.Core.dll</HintPath>
Expand Down
46 changes: 13 additions & 33 deletions CustomServersClient/CustomServersPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
using UnhollowerBaseLib;
using CustomServersClient.UI;

using RegionMenuLambda = RegionMenu.IOCEJPCJFKF;
using RegionInfo = KMDGIDEDGGM;
using ServerInfo = EEKGADNPDBH;
using RegionMenu = IPCOMKKGKCK;
using RegionMenuLambda = IPCOMKKGKCK.EBGBGOPHHAM;
using RegionInfo = CDLOPBGDBHF;
using ServerInfo = GBBLLNNMEBG;
using ServerManager = FOLCACGIEIK;
using InnerNetClient = DNAFMCDBMCI;
using ObjectPoolBehavior = EGLDLAINKEP;
using PassiveButton = BFBMELJEFCH;

namespace CustomServersClient
{
Expand All @@ -22,31 +27,6 @@ public static class CustomServersPatches
static bool _firstRun = true;
static ServersManagementForm _managementForm;

[HarmonyDebug]
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.SetEndpoint), typeof(string), typeof(ushort))]
public static class InnerNetClientSetEndPointPatch
{
public static bool Prefix(string EMFDKKLLHCL, ushort JOBBGKDMALK, ref InnerNetClient __instance)
{
var customServer = customServers.FirstOrDefault(x => x.ToString() == EMFDKKLLHCL);

if (customServer != default)
{
CustomServersPlugin.Logger.LogDebug($"Setting IP and port for custom server \"{customServer.name}\"!");
__instance.HECFEPIMCOE = customServer.ip;
__instance.DNGDMFHEJBA = customServer.port;
}
else
{
__instance.HECFEPIMCOE = EMFDKKLLHCL;
__instance.DNGDMFHEJBA = JOBBGKDMALK;
}

return false;
}
}

[HarmonyDebug]
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.OnEnable))]
public static class RegionMenuOnEnablePatch
{
Expand Down Expand Up @@ -91,7 +71,7 @@ public static bool Prefix(ref RegionMenu __instance)

for (int i = 0; i < customServers.Count; i++)
{
Il2CppReferenceArray<ServerInfo> servers = new ServerInfo[1] { new ServerInfo(customServers[i].name, customServers[i].ToString(), (ushort)customServers[i].port) };
Il2CppReferenceArray<ServerInfo> servers = new ServerInfo[1] { new ServerInfo(customServers[i].name, customServers[i].ip, (ushort)customServers[i].port) };

regions[i + 4] = new RegionInfo(customServers[i].name, "0", servers);
}
Expand Down Expand Up @@ -120,18 +100,19 @@ public static void ClearOnClickAction(ObjectPoolBehavior buttonPool)
}
}

[HarmonyDebug]

[HarmonyPatch(typeof(RegionMenuLambda), nameof(RegionMenuLambda.Method_Internal_Void_0))]
public static class RegionMenuChooseOptionPatch
{
public static bool Prefix(ref RegionMenuLambda __instance)
{
if (__instance.region.NCDMJOGPKOL == "MANAGE_SERVERS")
if (__instance.region.LCMJAAECKPN == "MANAGE_SERVERS")
{

if(_managementForm == null || _managementForm.IsDisposed)
_managementForm = new ServersManagementForm();

_managementForm.regionMenu = __instance.field_Public_RegionMenu_0;
_managementForm.regionMenu = __instance.field_Public_IPCOMKKGKCK_0;

if (_managementForm.Visible)
_managementForm.Focus();
Expand All @@ -144,7 +125,6 @@ public static bool Prefix(ref RegionMenuLambda __instance)
{
return true;
}

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CustomServersClient/CustomServersPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override void Load()
{
Logger = Log;

_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "andruzzzhka.customserversclient");
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.andruzzzhka.customserversclient");

Logger.LogDebug("Applied Harmony patches!");
}
Expand Down
27 changes: 26 additions & 1 deletion CustomServersClient/UI/EditServerForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Windows.Forms;

namespace CustomServersClient.UI
Expand Down Expand Up @@ -27,7 +28,31 @@ private void EditServerForm_Load(object sender, EventArgs e)

private void saveBtn_Click(object sender, EventArgs e)
{
serverInfo = new CustomServerInfo(nameTextBox.Text, ipTextBox.Text, (ushort)portNumericUD.Value);
string address = ipTextBox.Text;

if (!IPAddress.TryParse(address, out _))
{
try
{
CustomServersPlugin.Logger.LogWarning($"Resolving IP address for domain \"{address}\"...");

var adresses = Dns.GetHostAddresses(address);
if (adresses != null && adresses.Length > 0)
{
address = adresses[0].ToString();
}
else
{
CustomServersPlugin.Logger.LogWarning($"Failed to resolve IP adress from domain name! DNS resolution failed for address \"{address}\"");
}
}
catch (Exception ex)
{
CustomServersPlugin.Logger.LogWarning($"Failed to resolve IP adress from domain name! Exception:\n{ex}");
}
}

serverInfo = new CustomServerInfo(nameTextBox.Text, address, (ushort)portNumericUD.Value);
savePressed?.Invoke(serverInfo);
Hide();
}
Expand Down
2 changes: 2 additions & 0 deletions CustomServersClient/UI/ServersManagementForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.IO;
using System.Windows.Forms;

using RegionMenu = IPCOMKKGKCK;

namespace CustomServersClient.UI
{
public partial class ServersManagementForm : Form
Expand Down

0 comments on commit 0335a09

Please sign in to comment.