mirror of
https://github.com/MoltenMods/Unify.git
synced 2026-10-19 17:56:57 +00:00
Merge pull request #29 from MoltenMods/2021
Tidied code, fixed bugs, and added IP and port under custom region names in regions menu
This commit is contained in:
6 files changed
+60
-92
No files matched your search
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ContentModelUserStore">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
|
||||
@@ -22,7 +22,7 @@ Custom regions can be added as detailed below in the
|
||||
[configuration](#configuration) section.
|
||||
|
||||
Other mods can add regions via the
|
||||
`AddRegion(string name, string ip)` method.
|
||||
`AddRegion(string name, string ip, ushort port)` method.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -36,7 +36,8 @@ Other mods can add regions via the
|
||||
> If you are still using 2021.3.5s and Reactor fails to load, try using the Reactor version located
|
||||
> here: https://github.com/NuclearPowered/Reactor/actions/runs/636023321.
|
||||
|
||||
1. Ensure that BepInEx and Reactor are installed ([installation guide](INSTALLATION.md)).
|
||||
1. Ensure that BepInEx and Reactor (Reactor is not required for pre releases) are installed
|
||||
([installation guide](INSTALLATION.md)).
|
||||
2. Download the latest mod on the [releases](https://github.com/DaemonBeast/Unify/releases) page
|
||||
for the version of Among Us you are using.
|
||||
3. Move the mod to the `(Among Us game files)/BepInEx/plugins` folder.
|
||||
|
||||
+50
-85
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using Reactor.Extensions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -12,7 +13,7 @@ namespace Unify.Patches
|
||||
public static class RegionsPatch
|
||||
{
|
||||
private static IRegionInfo[] _oldRegions { get; } = ServerManager.DefaultRegions;
|
||||
|
||||
|
||||
private static IRegionInfo[] _newRegions { get; } = new IRegionInfo[]
|
||||
{
|
||||
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()
|
||||
{
|
||||
ServerManager serverManager = ServerManager.Instance;
|
||||
|
||||
|
||||
IRegionInfo[] patchedRegions = _oldRegions
|
||||
.AddRangeToArray(_newRegions)
|
||||
.AddRangeToArray(ModRegions.ToArray())
|
||||
@@ -41,13 +42,12 @@ namespace Unify.Patches
|
||||
|
||||
ServerManager.DefaultRegions = patchedRegions;
|
||||
serverManager.AvailableRegions = patchedRegions;
|
||||
serverManager.SaveServers();
|
||||
}
|
||||
|
||||
private static IRegionInfo[] LoadCustomUserRegions()
|
||||
{
|
||||
List<IRegionInfo> customRegions = new List<IRegionInfo>();
|
||||
|
||||
|
||||
for (int x = 0; x < 9; x++)
|
||||
{
|
||||
ConfigEntry<string> regionName = UnifyPlugin.ConfigFile.Bind(
|
||||
@@ -60,19 +60,20 @@ namespace Unify.Patches
|
||||
if (String.IsNullOrWhiteSpace(regionIp.Value)) continue;
|
||||
|
||||
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>();
|
||||
|
||||
|
||||
customRegions.Add(regionInfo);
|
||||
}
|
||||
|
||||
return customRegions.ToArray();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
if (!success)
|
||||
@@ -80,84 +81,22 @@ namespace Unify.Patches
|
||||
DirectConnect.StartCoroutine(Effects.SwayX(DirectConnect.transform, 0.75f, 0.25f));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
regionMenu.ChooseOption(newRegion);
|
||||
regionMenu.Close();
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ServerManager), nameof(ServerManager.LoadServers))]
|
||||
public static class PatchRegionMenuPatch
|
||||
public static class LoadNewRegionsPatch
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
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))]
|
||||
public static class DirectConnectEnterButtonPatch
|
||||
{
|
||||
public static class DirectConnectEnterButtonPatch {
|
||||
public static bool Prefix(JoinGameButton __instance)
|
||||
{
|
||||
GameObject regionMenuGameObject = GameObject.Find("RegionMenu");
|
||||
@@ -169,21 +108,47 @@ namespace Unify.Patches
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.Close))]
|
||||
public static class HideDirectConnectPatch
|
||||
[HarmonyPatch(typeof(RegionMenu))]
|
||||
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))]
|
||||
public static class HideDirectConnectOnSelectPatch
|
||||
{
|
||||
public static void Postfix()
|
||||
JoinGameButton joinGameButton = DestroyableSingleton<JoinGameButton>.Instance;
|
||||
|
||||
DirectConnect = Object.Instantiate(joinGameButton.GameIdText, __instance.transform);
|
||||
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";
|
||||
private const string Name = "Unify";
|
||||
private const string Version = "4.0.0";
|
||||
private const string Version = "4.1.0";
|
||||
|
||||
public static ConfigFile ConfigFile { get; private set; }
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Unify
|
||||
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;
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Unify
|
||||
ServerManager.DefaultRegions.ToArray().FirstOrDefault(region => region.PingServer == ip);
|
||||
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>();
|
||||
|
||||
RegionsPatch.ModRegions.Add(newRegion);
|
||||
|
||||
+3
-1
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Version>4.0.0</Version>
|
||||
<Version>4.1.0</Version>
|
||||
<Mappings>NuclearPowered/Mappings:0.4.0</Mappings>
|
||||
|
||||
<Description>Region mod</Description>
|
||||
@@ -32,5 +32,7 @@
|
||||
<Target Name="Copy" AfterTargets="Reobfuscate">
|
||||
<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="$(NewAmongUs)/" />
|
||||
</Target>
|
||||
</Project>
|
||||
Binary file not shown.
Reference in new issue
Block a user