mirror of
https://github.com/MoltenMods/Unify.git
synced 2026-10-20 11:40:00 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04711c4369 | ||
|
|
f0010bf13e | ||
|
|
1e7bc25ba8 | ||
|
|
d5de86c1e8 | ||
|
|
7c1e2533b2 | ||
|
|
913a02ddb6 | ||
|
|
1da6af54a9 | ||
|
|
e26fbccdb9 | ||
|
|
6f8a657fd0 | ||
|
|
5a4d501b9e | ||
|
|
ea4be527b7 | ||
|
|
6f266f7f93 | ||
|
|
1f5736c7f8 | ||
|
|
6df20f83c8 | ||
|
|
4c8866a33e | ||
|
|
fd5a11394a | ||
|
|
5b63d7cd0c |
No files matched your search
@@ -1,9 +1,3 @@
|
||||
> **⚠ WARNING**
|
||||
>
|
||||
> To play on a custom server on 2021.3.31.3s, you must compile the
|
||||
> *airship* branch of Impostor located here:
|
||||
> https://github.com/Impostor/Impostor/tree/airship.
|
||||
|
||||
# Unify
|
||||
|
||||
An Among Us mod to add extra regions to the regions menu.
|
||||
@@ -27,6 +21,9 @@ Regions can be connected to directly using an IP address.
|
||||
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.
|
||||
|
||||
## Installation
|
||||
|
||||
> **⚠ WARNING**
|
||||
@@ -60,7 +57,7 @@ The configuration file is located at
|
||||
### Custom regions
|
||||
|
||||
Custom regions can be added by modifying the `[Region 1]`,
|
||||
`[Region 2]` ... `[Region 10]` sections of the configuration file.
|
||||
`[Region 2]` ... `[Region 9]` sections of the configuration file.
|
||||
You can modify the display name of the region,
|
||||
the IP address of the region and the port of the region.
|
||||
|
||||
|
||||
+56
-26
@@ -27,16 +27,17 @@ namespace Unify.Patches
|
||||
|
||||
public static IRegionInfo DirectRegion { get; set; }
|
||||
|
||||
private static TextBox directConnect { get; set; }
|
||||
private static TextBoxTMP DirectConnect { get; set; }
|
||||
|
||||
public static void Patch()
|
||||
{
|
||||
ServerManager serverManager = ServerManager.Instance;
|
||||
|
||||
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);
|
||||
IRegionInfo[] patchedRegions = _oldRegions
|
||||
.AddRangeToArray(_newRegions)
|
||||
.AddRangeToArray(ModRegions.ToArray())
|
||||
.AddRangeToArray(LoadCustomUserRegions());
|
||||
if (DirectRegion != null) patchedRegions = patchedRegions.AddToArray(DirectRegion);
|
||||
|
||||
ServerManager.DefaultRegions = patchedRegions;
|
||||
serverManager.AvailableRegions = patchedRegions;
|
||||
@@ -47,7 +48,7 @@ namespace Unify.Patches
|
||||
{
|
||||
List<IRegionInfo> customRegions = new List<IRegionInfo>();
|
||||
|
||||
for (int x = 0; x < 10; x++)
|
||||
for (int x = 0; x < 9; x++)
|
||||
{
|
||||
ConfigEntry<string> regionName = UnifyPlugin.ConfigFile.Bind(
|
||||
$"Region {x + 1}", $"Name", "custom region");
|
||||
@@ -72,17 +73,26 @@ namespace Unify.Patches
|
||||
{
|
||||
RegionMenu regionMenu = GameObject.Find("RegionMenu").GetComponent<RegionMenu>();
|
||||
|
||||
bool success = UnifyPlugin.SetDirectRegion(directConnect.text, out IRegionInfo newRegion);
|
||||
bool success = UnifyPlugin.SetDirectRegion(DirectConnect.text, out IRegionInfo newRegion);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
directConnect.StartCoroutine(Effects.FIJHCJMBGFP(directConnect.transform, 0.75f, 0.25f));
|
||||
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 void Postfix()
|
||||
{
|
||||
Patch();
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.Open))]
|
||||
public static class DirectConnectButtonPatch
|
||||
@@ -92,17 +102,17 @@ namespace Unify.Patches
|
||||
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 = 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);
|
||||
DirectConnect.OnEnter = new Button.ButtonClickedEvent();
|
||||
DirectConnect.OnEnter.AddListener((Action) UpdateRegion);
|
||||
|
||||
int offset = ((ServerManager.DefaultRegions.Length + 1) / 2) + 1;
|
||||
directConnect.transform.localPosition = new Vector3(0, 2f - (offset / 2f), -100f);
|
||||
int offset = _newRegions.Length + ModRegions.Count;
|
||||
DirectConnect.transform.localPosition = new Vector3(0, 1f - (offset / 2f), -100f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,18 +121,38 @@ namespace Unify.Patches
|
||||
{
|
||||
public static void Postfix(RegionMenu __instance)
|
||||
{
|
||||
directConnect.gameObject.SetActive(true);
|
||||
DirectConnect.gameObject.SetActive(true);
|
||||
|
||||
var regionButtons = __instance.ButtonPool.activeChildren.ToArray();
|
||||
int half = (regionButtons.Length + 1) / 2;
|
||||
|
||||
for (int x = 0; x < regionButtons.Length; x++)
|
||||
{
|
||||
ServerListButton regionButton = regionButtons[x].Cast<ServerListButton>();
|
||||
|
||||
regionButton.transform.localPosition = new Vector3(1.25f * ((x < half)? -1: 1), 2f - 0.5f * (x - ((x < half)? 0 : half)), 0f);
|
||||
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))]
|
||||
@@ -144,7 +174,7 @@ namespace Unify.Patches
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
directConnect.gameObject.SetActive(false);
|
||||
DirectConnect.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +183,7 @@ namespace Unify.Patches
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
directConnect.gameObject.SetActive(false);
|
||||
DirectConnect.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-19
@@ -6,6 +6,7 @@ using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.IL2CPP;
|
||||
using HarmonyLib;
|
||||
using Hazel.Udp;
|
||||
using Reactor;
|
||||
using Unify.Patches;
|
||||
|
||||
@@ -19,15 +20,10 @@ namespace Unify
|
||||
{
|
||||
public const string Id = "daemon.unify";
|
||||
private const string Name = "Unify";
|
||||
private const string Version = "3.0.0";
|
||||
private const string Version = "4.0.0";
|
||||
|
||||
public static ConfigFile ConfigFile { get; private set; }
|
||||
|
||||
// public static readonly bool HandshakeDisabled = !PluginSingleton<ReactorPlugin>.Instance.ModdedHandshake.Value;
|
||||
|
||||
/*public static readonly string[] NormalHandshake =
|
||||
new string[] {"North America", "Europe", "Asia", "skeld.net"};*/
|
||||
|
||||
public Harmony Harmony { get; } = new Harmony(Id);
|
||||
|
||||
public override void Load()
|
||||
@@ -44,23 +40,14 @@ namespace Unify
|
||||
|
||||
ConfigFile = new ConfigFile(Path.Combine(Paths.ConfigPath, $"{UnifyPlugin.Id}.cfg"), true);
|
||||
// =====================================
|
||||
|
||||
RegionsPatch.Patch();
|
||||
|
||||
Harmony.UnpatchAll(ReactorPlugin.Id);
|
||||
|
||||
// Unpatches the modded handshake, because Impostor is STILL not fully updated yet
|
||||
Harmony.Unpatch(typeof(UdpConnection).GetMethod("HandleSend"), HarmonyPatchType.Prefix,
|
||||
ReactorPlugin.Id);
|
||||
|
||||
Harmony.PatchAll();
|
||||
}
|
||||
|
||||
public static IRegionInfo[] MergeRegions(IRegionInfo[] oldRegions, IRegionInfo[] newRegions)
|
||||
{
|
||||
IRegionInfo[] patchedRegions = new IRegionInfo[oldRegions.Length + newRegions.Length];
|
||||
Array.Copy(oldRegions, patchedRegions, oldRegions.Length);
|
||||
Array.Copy(newRegions, 0, patchedRegions, oldRegions.Length, newRegions.Length);
|
||||
|
||||
return patchedRegions;
|
||||
}
|
||||
|
||||
public static IRegionInfo AddRegion(string name, string ip)
|
||||
{
|
||||
if (Uri.CheckHostName(ip) != UriHostNameType.IPv4) return ServerManager.Instance.CurrentRegion;
|
||||
|
||||
+4
-4
@@ -1,20 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Version>3.0.0</Version>
|
||||
<Mappings>NuclearPowered/Mappings:0.3.0</Mappings>
|
||||
<Version>4.0.0</Version>
|
||||
<Mappings>NuclearPowered/Mappings:0.4.0</Mappings>
|
||||
|
||||
<Description>Region mod</Description>
|
||||
<Authors>Daemon</Authors>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(GamePlatform)' == 'Steam'">
|
||||
<GameVersion>2021.3.31.3s</GameVersion>
|
||||
<GameVersion>2021.4.12s</GameVersion>
|
||||
<DefineConstants>$(DefineConstants);STEAM</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(GamePlatform)' == 'Itch'">
|
||||
<GameVersion>2021.3.31.3i</GameVersion>
|
||||
<GameVersion>2021.4.12i</GameVersion>
|
||||
<DefineConstants>$(DefineConstants);ITCH</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user