mirror of
https://github.com/MoltenMods/Unify.git
synced 2026-10-19 17:56:57 +00:00
Added direct connect in regions menu
This commit is contained in:
1 parent
083ac31586
commit
26142c72d4
3 files changed
+130
-3
No files matched your search
@@ -1,10 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using Hazel.Udp;
|
||||
using Reactor;
|
||||
using Array = System.Array;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
using String = System.String;
|
||||
|
||||
namespace Unify.Patches
|
||||
@@ -12,6 +15,7 @@ namespace Unify.Patches
|
||||
public static class RegionsPatch
|
||||
{
|
||||
private static IRegionInfo[] _oldRegions = ServerManager.DefaultRegions;
|
||||
|
||||
private static IRegionInfo[] _newRegions = new IRegionInfo[]
|
||||
{
|
||||
new DnsRegionInfo("192.241.154.115", "skeld.net", StringNames.NoTranslation, "192.241.154.115")
|
||||
@@ -24,10 +28,15 @@ namespace Unify.Patches
|
||||
|
||||
public static List<IRegionInfo> ModRegions = new List<IRegionInfo>();
|
||||
|
||||
public static IRegionInfo DirectRegion;
|
||||
|
||||
private static TextBox directConnect;
|
||||
|
||||
public static void Patch()
|
||||
{
|
||||
IRegionInfo[] customRegions = UnifyPlugin.MergeRegions(_newRegions, ModRegions.ToArray());
|
||||
customRegions = UnifyPlugin.MergeRegions(customRegions, LoadCustomUserRegions());
|
||||
if (DirectRegion != null) customRegions = customRegions.AddToArray(DirectRegion);
|
||||
IRegionInfo[] patchedRegions = UnifyPlugin.MergeRegions(_oldRegions, customRegions);
|
||||
|
||||
ServerManager.DefaultRegions = patchedRegions;
|
||||
@@ -57,6 +66,82 @@ namespace Unify.Patches
|
||||
|
||||
return customRegions.ToArray();
|
||||
}
|
||||
|
||||
private static void UpdateRegion()
|
||||
{
|
||||
RegionMenu regionMenu = GameObject.Find("RegionMenu").GetComponent<RegionMenu>();
|
||||
|
||||
IRegionInfo newRegion = UnifyPlugin.SetDirectRegion(directConnect.text);
|
||||
|
||||
regionMenu.ChooseOption(newRegion);
|
||||
regionMenu.Close();
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(NameTextBehaviour), nameof(NameTextBehaviour.Start))]
|
||||
public static class DirectConnectButtonPatch
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
if (directConnect) return;
|
||||
|
||||
JoinGameButton joinGameButton = DestroyableSingleton<JoinGameButton>.Instance;
|
||||
RegionMenu regionMenu = DestroyableSingleton<RegionMenu>.Instance;
|
||||
|
||||
directConnect = Object.Instantiate(joinGameButton.GameIdText, regionMenu.transform);
|
||||
directConnect.gameObject.SetActive(false);
|
||||
directConnect.SetText("");
|
||||
directConnect.IpMode = true;
|
||||
directConnect.characterLimit = 15;
|
||||
directConnect.ClearOnFocus = false;
|
||||
|
||||
directConnect.OnEnter = new Button.ButtonClickedEvent();
|
||||
directConnect.OnEnter.AddListener((Action) UpdateRegion);
|
||||
|
||||
float offset = (float) 0.5 * ServerManager.DefaultRegions.Length;
|
||||
directConnect.transform.localPosition = new Vector3(0, 2 - offset, -100);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(JoinGameButton), nameof(JoinGameButton.OnClick))]
|
||||
public static class DirectConnectEnterButtonPatch
|
||||
{
|
||||
public static bool Prefix(JoinGameButton __instance)
|
||||
{
|
||||
GameObject regionMenuGameObject = GameObject.Find("RegionMenu");
|
||||
if (!regionMenuGameObject) return true;
|
||||
|
||||
UpdateRegion();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.Open))]
|
||||
public static class ShowDirectConnectPatch
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
directConnect.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.Close))]
|
||||
public static class HideDirectConnectPatch
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
directConnect.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ServerManager), nameof(ServerManager.SaveServers))]
|
||||
public static class HideDirectConnectOnSelectPatch
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
directConnect.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(UdpConnection), nameof(UdpConnection.HandleSend))]
|
||||
|
||||
+43
-1
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.IL2CPP;
|
||||
using BepInEx.Logging;
|
||||
using HarmonyLib;
|
||||
using Reactor;
|
||||
using Unify.Patches;
|
||||
@@ -45,13 +48,52 @@ namespace Unify
|
||||
return patchedRegions;
|
||||
}
|
||||
|
||||
public static void AddRegion(string name, string ip)
|
||||
public static IRegionInfo AddRegion(string name, string ip)
|
||||
{
|
||||
if (Uri.CheckHostName(ip) != UriHostNameType.IPv4) return ServerManager.Instance.CurrentRegion;
|
||||
|
||||
IRegionInfo existingRegion =
|
||||
ServerManager.DefaultRegions.ToArray().FirstOrDefault(region => region.PingServer == ip);
|
||||
if (existingRegion != null) return existingRegion;
|
||||
|
||||
IRegionInfo newRegion = new DnsRegionInfo(ip, name, StringNames.NoTranslation, ip)
|
||||
.Cast<IRegionInfo>();
|
||||
|
||||
RegionsPatch.ModRegions.Add(newRegion);
|
||||
RegionsPatch.Patch();
|
||||
|
||||
return newRegion;
|
||||
}
|
||||
|
||||
public static IRegionInfo SetDirectRegion(string ip)
|
||||
{
|
||||
if (Uri.CheckHostName(ip) != UriHostNameType.IPv4) return ServerManager.Instance.CurrentRegion;
|
||||
|
||||
IRegionInfo newRegion = new DnsRegionInfo(ip, ip, StringNames.NoTranslation, ip)
|
||||
.Cast<IRegionInfo>();
|
||||
|
||||
RegionsPatch.DirectRegion = newRegion;
|
||||
RegionsPatch.Patch();
|
||||
|
||||
return newRegion;
|
||||
}
|
||||
|
||||
public static void SetRegionIp(string ip)
|
||||
{
|
||||
IRegionInfo existingRegion =
|
||||
ServerManager.DefaultRegions.ToArray().FirstOrDefault(region => region.PingServer == ip);
|
||||
if (existingRegion != null) return;
|
||||
|
||||
RegionMenu regionMenu = DestroyableSingleton<RegionMenu>.Instance;
|
||||
IRegionInfo newRegion = AddRegion(ip, ip);
|
||||
|
||||
// ChatLanguageButton lastRegionButton = regionMenu.ButtonPool.activeChildren[^1].Cast<ChatLanguageButton>();
|
||||
|
||||
// regionMenu.ChooseOption(ServerManager.DefaultRegions[^1]);
|
||||
// regionMenu.ButtonPool.activeChildren[^1].Cast<ChatLanguageButton>().Button.ReceiveClickDown();
|
||||
// lastRegionButton.gameObject.SetActive(true);
|
||||
// lastRegionButton.Button.OnClick.Invoke();
|
||||
regionMenu.ChooseOption(newRegion);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user