From 0335a0904ef7d66f078ee45dc565ae909d7b48b7 Mon Sep 17 00:00:00 2001 From: andruzzzhka Date: Tue, 3 Nov 2020 16:10:00 +0700 Subject: [PATCH] Updated for AU v2020.10.22s; Added domain name resolution; --- CustomServersClient/CustomServerInfo.cs | 4 -- .../CustomServersClient.csproj | 3 +- CustomServersClient/CustomServersPatches.cs | 46 ++++++------------- CustomServersClient/CustomServersPlugin.cs | 2 +- CustomServersClient/UI/EditServerForm.cs | 27 ++++++++++- .../UI/ServersManagementForm.cs | 2 + 6 files changed, 43 insertions(+), 41 deletions(-) diff --git a/CustomServersClient/CustomServerInfo.cs b/CustomServersClient/CustomServerInfo.cs index 1be0ec7..affb985 100644 --- a/CustomServersClient/CustomServerInfo.cs +++ b/CustomServersClient/CustomServerInfo.cs @@ -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() diff --git a/CustomServersClient/CustomServersClient.csproj b/CustomServersClient/CustomServersClient.csproj index 5416470..3621b53 100644 --- a/CustomServersClient/CustomServersClient.csproj +++ b/CustomServersClient/CustomServersClient.csproj @@ -36,8 +36,7 @@ False - D:\andru\Desktop\Among Us\BepInEx\unhollowed\Assembly-CSharp.dll - False + ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Among Us\BepInEx\unhollowed\Assembly-CSharp.dll D:\andru\Desktop\Among Us\BepInEx\core\BepInEx.Core.dll diff --git a/CustomServersClient/CustomServersPatches.cs b/CustomServersClient/CustomServersPatches.cs index 536be2e..a441acd 100644 --- a/CustomServersClient/CustomServersPatches.cs +++ b/CustomServersClient/CustomServersPatches.cs @@ -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 { @@ -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 { @@ -91,7 +71,7 @@ public static bool Prefix(ref RegionMenu __instance) for (int i = 0; i < customServers.Count; i++) { - Il2CppReferenceArray servers = new ServerInfo[1] { new ServerInfo(customServers[i].name, customServers[i].ToString(), (ushort)customServers[i].port) }; + Il2CppReferenceArray 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); } @@ -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(); @@ -144,7 +125,6 @@ public static bool Prefix(ref RegionMenuLambda __instance) { return true; } - } } } diff --git a/CustomServersClient/CustomServersPlugin.cs b/CustomServersClient/CustomServersPlugin.cs index f6cf7e1..93e3d59 100644 --- a/CustomServersClient/CustomServersPlugin.cs +++ b/CustomServersClient/CustomServersPlugin.cs @@ -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!"); } diff --git a/CustomServersClient/UI/EditServerForm.cs b/CustomServersClient/UI/EditServerForm.cs index 66d8b9d..e299803 100644 --- a/CustomServersClient/UI/EditServerForm.cs +++ b/CustomServersClient/UI/EditServerForm.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Windows.Forms; namespace CustomServersClient.UI @@ -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(); } diff --git a/CustomServersClient/UI/ServersManagementForm.cs b/CustomServersClient/UI/ServersManagementForm.cs index 0fadfe0..cd9de97 100644 --- a/CustomServersClient/UI/ServersManagementForm.cs +++ b/CustomServersClient/UI/ServersManagementForm.cs @@ -4,6 +4,8 @@ using System.IO; using System.Windows.Forms; +using RegionMenu = IPCOMKKGKCK; + namespace CustomServersClient.UI { public partial class ServersManagementForm : Form