mirror of
https://github.com/MoltenMods/Unify.git
synced 2026-10-19 17:56:57 +00:00
Tidied code and fixed bugs
Tidied code and removed redundant code Fixed region file getting spam reloaded Fixed multiple direct connect buttons existing at once Added IP and port under names of custom regions in regions menu
This commit is contained in:
1 parent
a16eb79973
commit
9c70216a9f
6 files changed
+58
-91
No files matched your search
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ContentModelUserStore">
|
<component name="UserContentModel">
|
||||||
<attachedFolders />
|
<attachedFolders />
|
||||||
<explicitIncludes />
|
<explicitIncludes />
|
||||||
<explicitExcludes />
|
<explicitExcludes />
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ Custom regions can be added as detailed below in the
|
|||||||
[configuration](#configuration) section.
|
[configuration](#configuration) section.
|
||||||
|
|
||||||
Other mods can add regions via the
|
Other mods can add regions via the
|
||||||
`AddRegion(string name, string ip)` method.
|
`AddRegion(string name, string ip, ushort port)` method.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
+50
-85
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using Reactor.Extensions;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
@@ -12,7 +13,7 @@ namespace Unify.Patches
|
|||||||
public static class RegionsPatch
|
public static class RegionsPatch
|
||||||
{
|
{
|
||||||
private static IRegionInfo[] _oldRegions { get; } = ServerManager.DefaultRegions;
|
private static IRegionInfo[] _oldRegions { get; } = ServerManager.DefaultRegions;
|
||||||
|
|
||||||
private static IRegionInfo[] _newRegions { get; } = new IRegionInfo[]
|
private static IRegionInfo[] _newRegions { get; } = new IRegionInfo[]
|
||||||
{
|
{
|
||||||
new DnsRegionInfo("192.241.154.115", "skeld.net", StringNames.NoTranslation, "192.241.154.115", 22023)
|
new DnsRegionInfo("192.241.154.115", "skeld.net", StringNames.NoTranslation, "192.241.154.115", 22023)
|
||||||
@@ -32,7 +33,7 @@ namespace Unify.Patches
|
|||||||
public static void Patch()
|
public static void Patch()
|
||||||
{
|
{
|
||||||
ServerManager serverManager = ServerManager.Instance;
|
ServerManager serverManager = ServerManager.Instance;
|
||||||
|
|
||||||
IRegionInfo[] patchedRegions = _oldRegions
|
IRegionInfo[] patchedRegions = _oldRegions
|
||||||
.AddRangeToArray(_newRegions)
|
.AddRangeToArray(_newRegions)
|
||||||
.AddRangeToArray(ModRegions.ToArray())
|
.AddRangeToArray(ModRegions.ToArray())
|
||||||
@@ -41,13 +42,12 @@ namespace Unify.Patches
|
|||||||
|
|
||||||
ServerManager.DefaultRegions = patchedRegions;
|
ServerManager.DefaultRegions = patchedRegions;
|
||||||
serverManager.AvailableRegions = patchedRegions;
|
serverManager.AvailableRegions = patchedRegions;
|
||||||
serverManager.SaveServers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegionInfo[] LoadCustomUserRegions()
|
private static IRegionInfo[] LoadCustomUserRegions()
|
||||||
{
|
{
|
||||||
List<IRegionInfo> customRegions = new List<IRegionInfo>();
|
List<IRegionInfo> customRegions = new List<IRegionInfo>();
|
||||||
|
|
||||||
for (int x = 0; x < 9; x++)
|
for (int x = 0; x < 9; x++)
|
||||||
{
|
{
|
||||||
ConfigEntry<string> regionName = UnifyPlugin.ConfigFile.Bind(
|
ConfigEntry<string> regionName = UnifyPlugin.ConfigFile.Bind(
|
||||||
@@ -60,19 +60,20 @@ namespace Unify.Patches
|
|||||||
if (String.IsNullOrWhiteSpace(regionIp.Value)) continue;
|
if (String.IsNullOrWhiteSpace(regionIp.Value)) continue;
|
||||||
|
|
||||||
IRegionInfo regionInfo = new DnsRegionInfo(
|
IRegionInfo regionInfo = new DnsRegionInfo(
|
||||||
regionIp.Value, regionName.Value, StringNames.NoTranslation, regionIp.Value, regionPort.Value)
|
regionIp.Value, $"{regionName.Value}\n{regionIp.Value} {regionPort.Value}",
|
||||||
|
StringNames.NoTranslation, regionIp.Value, regionPort.Value)
|
||||||
.Cast<IRegionInfo>();
|
.Cast<IRegionInfo>();
|
||||||
|
|
||||||
customRegions.Add(regionInfo);
|
customRegions.Add(regionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return customRegions.ToArray();
|
return customRegions.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateRegion()
|
private static void UpdateRegion()
|
||||||
{
|
{
|
||||||
RegionMenu regionMenu = GameObject.Find("RegionMenu").GetComponent<RegionMenu>();
|
RegionMenu regionMenu = DestroyableSingleton<RegionMenu>.Instance;
|
||||||
|
|
||||||
bool success = UnifyPlugin.SetDirectRegion(DirectConnect.text, out IRegionInfo newRegion);
|
bool success = UnifyPlugin.SetDirectRegion(DirectConnect.text, out IRegionInfo newRegion);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
@@ -80,84 +81,22 @@ namespace Unify.Patches
|
|||||||
DirectConnect.StartCoroutine(Effects.SwayX(DirectConnect.transform, 0.75f, 0.25f));
|
DirectConnect.StartCoroutine(Effects.SwayX(DirectConnect.transform, 0.75f, 0.25f));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
regionMenu.ChooseOption(newRegion);
|
regionMenu.ChooseOption(newRegion);
|
||||||
regionMenu.Close();
|
regionMenu.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(typeof(ServerManager), nameof(ServerManager.LoadServers))]
|
[HarmonyPatch(typeof(ServerManager), nameof(ServerManager.LoadServers))]
|
||||||
public static class PatchRegionMenuPatch
|
public static class LoadNewRegionsPatch
|
||||||
{
|
{
|
||||||
public static void Postfix()
|
public static void Postfix()
|
||||||
{
|
{
|
||||||
Patch();
|
Patch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.Open))]
|
|
||||||
public static class DirectConnectButtonPatch
|
|
||||||
{
|
|
||||||
public static void Postfix()
|
|
||||||
{
|
|
||||||
JoinGameButton joinGameButton = DestroyableSingleton<JoinGameButton>.Instance;
|
|
||||||
RegionMenu regionMenu = DestroyableSingleton<RegionMenu>.Instance;
|
|
||||||
|
|
||||||
DirectConnect = Object.Instantiate(joinGameButton.GameIdText, regionMenu.transform);
|
|
||||||
DirectConnect.gameObject.SetActive(false);
|
|
||||||
DirectConnect.IpMode = true;
|
|
||||||
DirectConnect.characterLimit = 15;
|
|
||||||
DirectConnect.ClearOnFocus = false;
|
|
||||||
|
|
||||||
DirectConnect.OnEnter = new Button.ButtonClickedEvent();
|
|
||||||
DirectConnect.OnEnter.AddListener((Action) UpdateRegion);
|
|
||||||
|
|
||||||
int offset = _newRegions.Length + ModRegions.Count;
|
|
||||||
DirectConnect.transform.localPosition = new Vector3(0, 1f - (offset / 2f), -100f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.Open))]
|
|
||||||
public static class RegionMenuLayoutPatch
|
|
||||||
{
|
|
||||||
public static void Postfix(RegionMenu __instance)
|
|
||||||
{
|
|
||||||
DirectConnect.gameObject.SetActive(true);
|
|
||||||
|
|
||||||
var regionButtons = __instance.ButtonPool.activeChildren.ToArray();
|
|
||||||
|
|
||||||
for (int i = 0; i < regionButtons.Length; i++)
|
|
||||||
{
|
|
||||||
ServerListButton regionButton = regionButtons[i].Cast<ServerListButton>();
|
|
||||||
|
|
||||||
(float x, float y) = CalculatePosition(i);
|
|
||||||
regionButton.transform.localPosition = new Vector3(1.25f + x, 2f - 0.5f * y, 0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static (float x, float y) CalculatePosition(int index)
|
|
||||||
{
|
|
||||||
// currently broken
|
|
||||||
/*if (DirectRegion != null && ServerManager.DefaultRegions[index].Name == DirectRegion.Name)
|
|
||||||
{
|
|
||||||
int offset = Math.Max(
|
|
||||||
Math.Max(LoadCustomUserRegions().Length, _newRegions.Length + ModRegions.Count),
|
|
||||||
_oldRegions.Length);
|
|
||||||
return (1.25f, 2f - offset);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
bool isCustomRegion = index >= _oldRegions.Length;
|
|
||||||
bool isCustomUserRegion = index >= _oldRegions.Length + _newRegions.Length + ModRegions.Count;
|
|
||||||
float x = (isCustomRegion ? 3f : 0) + (isCustomUserRegion ? 3f : 0) - 4.25f;
|
|
||||||
float y = index - (isCustomRegion ? _oldRegions.Length : 0) -
|
|
||||||
(isCustomUserRegion ? _newRegions.Length + ModRegions.Count : 0);
|
|
||||||
|
|
||||||
return (x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(JoinGameButton), nameof(JoinGameButton.OnClick))]
|
[HarmonyPatch(typeof(JoinGameButton), nameof(JoinGameButton.OnClick))]
|
||||||
public static class DirectConnectEnterButtonPatch
|
public static class DirectConnectEnterButtonPatch {
|
||||||
{
|
|
||||||
public static bool Prefix(JoinGameButton __instance)
|
public static bool Prefix(JoinGameButton __instance)
|
||||||
{
|
{
|
||||||
GameObject regionMenuGameObject = GameObject.Find("RegionMenu");
|
GameObject regionMenuGameObject = GameObject.Find("RegionMenu");
|
||||||
@@ -169,21 +108,47 @@ namespace Unify.Patches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.Close))]
|
[HarmonyPatch(typeof(RegionMenu))]
|
||||||
public static class HideDirectConnectPatch
|
public static class RegionMenuPatches
|
||||||
{
|
{
|
||||||
public static void Postfix()
|
[HarmonyPatch(nameof(RegionMenu.Open))]
|
||||||
|
[HarmonyPostfix]
|
||||||
|
public static void DirectConnectButtonPatch(RegionMenu __instance)
|
||||||
{
|
{
|
||||||
DirectConnect.gameObject.SetActive(false);
|
if (DirectConnect) DirectConnect.gameObject.Destroy();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.ChooseOption))]
|
JoinGameButton joinGameButton = DestroyableSingleton<JoinGameButton>.Instance;
|
||||||
public static class HideDirectConnectOnSelectPatch
|
|
||||||
{
|
DirectConnect = Object.Instantiate(joinGameButton.GameIdText, __instance.transform);
|
||||||
public static void Postfix()
|
DirectConnect.IpMode = true;
|
||||||
|
DirectConnect.characterLimit = 15;
|
||||||
|
DirectConnect.ClearOnFocus = false;
|
||||||
|
|
||||||
|
DirectConnect.OnEnter = new Button.ButtonClickedEvent();
|
||||||
|
DirectConnect.OnEnter.AddListener((Action) UpdateRegion);
|
||||||
|
|
||||||
|
int offset = _newRegions.Length + ModRegions.Count;
|
||||||
|
DirectConnect.transform.localPosition = new Vector3(0, 1f - (offset / 2f), -100f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(nameof(RegionMenu.Open))]
|
||||||
|
[HarmonyPostfix]
|
||||||
|
public static void RegionMenuLayoutPatch(RegionMenu __instance)
|
||||||
{
|
{
|
||||||
DirectConnect.gameObject.SetActive(false);
|
var regionButtons = __instance.ButtonPool.activeChildren.ToArray();
|
||||||
|
|
||||||
|
for (int i = 0; i < regionButtons.Length; i++)
|
||||||
|
{
|
||||||
|
ServerListButton regionButton = regionButtons[i].Cast<ServerListButton>();
|
||||||
|
|
||||||
|
bool isCustomRegion = i >= _oldRegions.Length;
|
||||||
|
bool isCustomUserRegion = i >= _oldRegions.Length + _newRegions.Length + ModRegions.Count;
|
||||||
|
float x = (isCustomRegion ? 3f : 0) + (isCustomUserRegion ? 3f : 0) - 4.25f;
|
||||||
|
float y = i - (isCustomRegion ? _oldRegions.Length : 0) -
|
||||||
|
(isCustomUserRegion ? _newRegions.Length + ModRegions.Count : 0);
|
||||||
|
|
||||||
|
regionButton.transform.localPosition = new Vector3(1.25f + x, 2f - 0.5f * y, 0f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -20,7 +20,7 @@ namespace Unify
|
|||||||
{
|
{
|
||||||
public const string Id = "daemon.unify";
|
public const string Id = "daemon.unify";
|
||||||
private const string Name = "Unify";
|
private const string Name = "Unify";
|
||||||
private const string Version = "4.0.1";
|
private const string Version = "4.1.0";
|
||||||
|
|
||||||
public static ConfigFile ConfigFile { get; private set; }
|
public static ConfigFile ConfigFile { get; private set; }
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ namespace Unify
|
|||||||
Harmony.PatchAll();
|
Harmony.PatchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IRegionInfo AddRegion(string name, string ip)
|
public static IRegionInfo AddRegion(string name, string ip, ushort port)
|
||||||
{
|
{
|
||||||
if (Uri.CheckHostName(ip) != UriHostNameType.IPv4) return ServerManager.Instance.CurrentRegion;
|
if (Uri.CheckHostName(ip) != UriHostNameType.IPv4) return ServerManager.Instance.CurrentRegion;
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ namespace Unify
|
|||||||
ServerManager.DefaultRegions.ToArray().FirstOrDefault(region => region.PingServer == ip);
|
ServerManager.DefaultRegions.ToArray().FirstOrDefault(region => region.PingServer == ip);
|
||||||
if (existingRegion != null) return existingRegion;
|
if (existingRegion != null) return existingRegion;
|
||||||
|
|
||||||
IRegionInfo newRegion = new DnsRegionInfo(ip, name, StringNames.NoTranslation, ip, 22023)
|
IRegionInfo newRegion = new DnsRegionInfo(ip, $"{name}\n{ip} {port}", StringNames.NoTranslation, ip, port)
|
||||||
.Cast<IRegionInfo>();
|
.Cast<IRegionInfo>();
|
||||||
|
|
||||||
RegionsPatch.ModRegions.Add(newRegion);
|
RegionsPatch.ModRegions.Add(newRegion);
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<Version>4.0.1</Version>
|
<Version>4.1.0</Version>
|
||||||
<Mappings>NuclearPowered/Mappings:0.4.0</Mappings>
|
<Mappings>NuclearPowered/Mappings:0.4.0</Mappings>
|
||||||
|
|
||||||
<Description>Region mod</Description>
|
<Description>Region mod</Description>
|
||||||
@@ -32,5 +32,7 @@
|
|||||||
<Target Name="Copy" AfterTargets="Reobfuscate">
|
<Target Name="Copy" AfterTargets="Reobfuscate">
|
||||||
<Copy SourceFiles="$(OutputPath)reobfuscated/$(AssemblyName)-$(GameVersion).dll" DestinationFolder="$(AmongUs)/BepInEx/plugins/" />
|
<Copy SourceFiles="$(OutputPath)reobfuscated/$(AssemblyName)-$(GameVersion).dll" DestinationFolder="$(AmongUs)/BepInEx/plugins/" />
|
||||||
<Copy SourceFiles="$(OutputPath)reobfuscated/$(AssemblyName)-$(GameVersion).dll" DestinationFolder="../build/" />
|
<Copy SourceFiles="$(OutputPath)reobfuscated/$(AssemblyName)-$(GameVersion).dll" DestinationFolder="../build/" />
|
||||||
|
|
||||||
|
<Copy SourceFiles="$(OutputPath)reobfuscated/$(AssemblyName)-$(GameVersion).dll" DestinationFolder="$(NewAmongUs)/" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
Binary file not shown.
Reference in new issue
Block a user