mirror of
https://github.com/MoltenMods/Unify.git
synced 2026-10-20 11:40:00 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
216a639303 | ||
|
|
7b4a916d84 | ||
|
|
f44179c040 | ||
|
|
9c70216a9f | ||
|
|
a16eb79973 | ||
|
|
04711c4369 | ||
|
|
f0010bf13e | ||
|
|
1e7bc25ba8 | ||
|
|
d5de86c1e8 | ||
|
|
7c1e2533b2 | ||
|
|
913a02ddb6 | ||
|
|
1da6af54a9 | ||
|
|
e26fbccdb9 | ||
|
|
6f8a657fd0 | ||
|
|
5a4d501b9e | ||
|
|
ea4be527b7 | ||
|
|
6f266f7f93 | ||
|
|
1f5736c7f8 | ||
|
|
6df20f83c8 | ||
|
|
4c8866a33e | ||
|
|
fd5a11394a | ||
|
|
5b63d7cd0c | ||
|
|
76a25f8107 | ||
|
|
339f4f2c33 | ||
|
|
ec7eda2fa7 | ||
|
|
8ac9ff247d | ||
|
|
b22393625f | ||
|
|
5f0decd34f | ||
|
|
c7af5d5c9c | ||
|
|
26142c72d4 | ||
|
|
083ac31586 | ||
|
|
81b058178c | ||
|
|
a7b0774f9d | ||
|
|
ab57814ee3 | ||
|
|
c861abbb4f | ||
|
|
d2a59980b0 | ||
|
|
be49899a27 | ||
|
|
071b49f85d | ||
|
|
fbc1751172 | ||
|
|
25ccc7124c | ||
|
|
cd5093407a | ||
|
|
489d1c85a7 | ||
|
|
c0d8638a27 | ||
|
|
50c678901f | ||
|
|
3dbf2befc1 | ||
|
|
3b9db051c9 | ||
|
|
6d18d01eb9 | ||
|
|
e91ea01777 | ||
|
|
bb69bbddfd | ||
|
|
8560fb6a55 | ||
|
|
5668255792 | ||
|
|
af6e7f4b4c | ||
|
|
f35196d68c | ||
|
|
fe8f24ce98 | ||
|
|
7fc26d8b92 | ||
|
|
80051f9ec2 | ||
|
|
999fb61e5e | ||
|
|
907b2f9fe1 | ||
|
|
5675dab961 | ||
|
|
b426eb5243 |
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 />
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# Unify
|
||||
# Unify
|
||||
|
||||
An Among Us mod to add extra regions to the regions menu.
|
||||
An Among Us mod to add extra regions to the region menu.
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
# Table of Contents
|
||||
- [Features](#features)
|
||||
@@ -14,16 +15,33 @@ An Among Us mod to add extra regions to the regions menu.
|
||||
The following regions have been added:
|
||||
- [skeld.net](https://skeld.net/)
|
||||
- localhost *(for playing on a server running on your computer)*
|
||||
- matux.fr
|
||||
- Przebot (may be unreliable or outdated)
|
||||
|
||||
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, ushort port)` API method.
|
||||
|
||||
## Installation
|
||||
|
||||
> **⚠ WARNING**
|
||||
>
|
||||
> This mod requires you to have BepInEx and Reactor installed. You can install BepInEx and Reactor by following [this guide](INSTALLATION.md) or by following the steps on the
|
||||
> following two pages: https://docs.reactor.gg/docs/basic/install_bepinex and https://docs.reactor.gg/docs/basic/install_reactor.
|
||||
> This mod only has compiled releases for the steam release of the game.
|
||||
|
||||
1. Ensure that BepInEx and Reactor are installed (more information above).
|
||||
2. Download the latest mod on the [releases](https://github.com/DaemonBeast/Unify/releases) page.
|
||||
> If you are still using 2020.12.9s and Reactor fails to load, try using the Reactor version located
|
||||
> here: https://github.com/NuclearPowered/Reactor/actions/runs/593649307.
|
||||
|
||||
> 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 (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.
|
||||
4. Launch the game.
|
||||
|
||||
@@ -37,13 +55,13 @@ The following regions have been added:
|
||||
> file creates itself.
|
||||
|
||||
The configuration file is located at
|
||||
`(Among Us game files)/BepInEx/config/daemon.unify.reactor.cfg`.
|
||||
`(Among Us game files)/BepInEx/config/daemon.unify.cfg`.
|
||||
|
||||
### Custom regions
|
||||
|
||||
Custom regions can be added by modifying the `[Region 1]`,
|
||||
`[Region 2]` ... `[Region 5]` sections of the configuration file.
|
||||
The sections allow you to modify the display name of the region,
|
||||
the IP address of the region, and the port of the region.
|
||||
`[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.
|
||||
|
||||
If the IP field is left empty, the region will not show up in game.
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Reactor.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Unify.Controls
|
||||
{
|
||||
public class Button
|
||||
{
|
||||
private static readonly TaskCompletionSource<bool> Initialized = new TaskCompletionSource<bool>();
|
||||
private static GameObject _instance;
|
||||
|
||||
private readonly SpriteRenderer _spriteRenderer;
|
||||
private readonly BoxCollider2D _boxCollider2D;
|
||||
|
||||
public GameObject GameObject { get; }
|
||||
public TextMeshPro Text { get; }
|
||||
public Vector2 Size
|
||||
{
|
||||
get => _spriteRenderer.size;
|
||||
set
|
||||
{
|
||||
Text.rectTransform.sizeDelta = value;
|
||||
_spriteRenderer.size = value;
|
||||
_boxCollider2D.size = value;
|
||||
}
|
||||
}
|
||||
public AspectPosition Position { get; }
|
||||
public UnityEngine.UI.Button.ButtonClickedEvent OnClick { get; }
|
||||
|
||||
private Button(string text, Vector2 size, Vector2 position)
|
||||
{
|
||||
GameObject = Object.Instantiate(_instance).DontDestroy();
|
||||
|
||||
Text = GameObject.GetComponentInChildren<TextMeshPro>();
|
||||
Position = GameObject.GetComponent<AspectPosition>();
|
||||
OnClick = GameObject.GetComponent<PassiveButton>().OnClick;
|
||||
_spriteRenderer = GameObject.GetComponent<SpriteRenderer>();
|
||||
_boxCollider2D = GameObject.GetComponent<BoxCollider2D>();
|
||||
|
||||
Text.text = text;
|
||||
Text.rectTransform.sizeDelta = size;
|
||||
Position.DistanceFromEdge = new Vector3(position.x, position.y, -100f);
|
||||
_spriteRenderer.size = size;
|
||||
_boxCollider2D.size = size;
|
||||
}
|
||||
|
||||
public static async Task<Button> Create(string text, Vector2 size, Vector2 position)
|
||||
{
|
||||
await Initialized.Task;
|
||||
|
||||
return new Button(text, size, position);
|
||||
}
|
||||
|
||||
public static async void Create(string text, Vector2 size, Vector2 position, Action<Button> callback)
|
||||
{
|
||||
var newButton = await Create(text, size, position);
|
||||
callback(newButton);
|
||||
}
|
||||
|
||||
public static void InitializeBaseButton()
|
||||
{
|
||||
BaseButton.Initialize();
|
||||
}
|
||||
|
||||
private static class BaseButton
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
SceneManager.add_sceneLoaded((Action<Scene, LoadSceneMode>) OnSceneLoaded);
|
||||
}
|
||||
|
||||
private static void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
|
||||
{
|
||||
Instantiate();
|
||||
|
||||
SceneManager.remove_sceneLoaded((Action<Scene, LoadSceneMode>) OnSceneLoaded);
|
||||
}
|
||||
|
||||
private static void Instantiate()
|
||||
{
|
||||
if (Initialized.Task.IsCompleted) return;
|
||||
|
||||
var exitButton = GameObject.Find("ExitGameButton");
|
||||
if (!exitButton) return;
|
||||
|
||||
_instance = Object.Instantiate(exitButton).DontDestroy();
|
||||
_instance.SetActive(false);
|
||||
_instance.name = "Button";
|
||||
|
||||
_instance.GetComponent<PassiveButton>().OnClick = new UnityEngine.UI.Button.ButtonClickedEvent();
|
||||
_instance.GetComponent<SceneChanger>().Destroy();
|
||||
_instance.GetComponent<ConditionalHide>().Destroy();
|
||||
_instance.GetComponentInChildren<TextTranslatorTMP>().Destroy();
|
||||
_instance.GetComponentInChildren<TextMeshPro>().text = "Button";
|
||||
|
||||
Initialized.SetResult(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Reactor.Extensions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Unify.Controls
|
||||
{
|
||||
public class Popup
|
||||
{
|
||||
private static readonly TaskCompletionSource<bool> Initialized = new TaskCompletionSource<bool>();
|
||||
private static GameObject _instance;
|
||||
|
||||
public GameObject GameObject { get; }
|
||||
public TextMeshPro Text { get; }
|
||||
|
||||
private Popup(string text)
|
||||
{
|
||||
GameObject = Object.Instantiate(_instance).DontDestroy();
|
||||
|
||||
Text = GameObject.GetComponentInChildren<TextMeshPro>();
|
||||
|
||||
Text.text = text;
|
||||
}
|
||||
|
||||
public static async Task<Popup> Create(string text)
|
||||
{
|
||||
await Initialized.Task;
|
||||
|
||||
return new Popup(text);
|
||||
}
|
||||
|
||||
public static async void Create(string text, Action<Popup> callback)
|
||||
{
|
||||
var newPopup = await Create(text);
|
||||
callback(newPopup);
|
||||
}
|
||||
|
||||
public static void InitializeBasePopup()
|
||||
{
|
||||
BasePopup.Initialize();
|
||||
}
|
||||
|
||||
private static class BasePopup
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
SceneManager.add_sceneLoaded((Action<Scene, LoadSceneMode>) OnSceneLoaded);
|
||||
}
|
||||
|
||||
private static void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
|
||||
{
|
||||
Instantiate();
|
||||
|
||||
SceneManager.remove_sceneLoaded((Action<Scene, LoadSceneMode>) OnSceneLoaded);
|
||||
}
|
||||
|
||||
private static void Instantiate()
|
||||
{
|
||||
if (Initialized.Task.IsCompleted) return;
|
||||
|
||||
var disconnectPopup = GameObject.Find("DisconnectPopup");
|
||||
if (!disconnectPopup) return;
|
||||
|
||||
_instance = Object.Instantiate(disconnectPopup).DontDestroy();
|
||||
_instance.SetActive(false);
|
||||
_instance.name = "Popup";
|
||||
|
||||
_instance.GetComponentInChildren<TextMeshPro>().text = "Popup";
|
||||
|
||||
Initialized.SetResult(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+348
-39
@@ -2,64 +2,373 @@
|
||||
using System.Collections.Generic;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using Reactor.Extensions;
|
||||
using Unify.Controls;
|
||||
using UnityEngine;
|
||||
using Button = UnityEngine.UI.Button;
|
||||
using Object = UnityEngine.Object;
|
||||
using String = System.String;
|
||||
|
||||
namespace Unify.Patches
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public static class RegionsPatch
|
||||
{
|
||||
internal static IRegionInfo[] OldRegions { get; } = ServerManager.DefaultRegions;
|
||||
|
||||
internal static IRegionInfo[] NewRegions { get; } = new IRegionInfo[]
|
||||
{
|
||||
new DnsRegionInfo("192.241.154.115", "skeld.net", StringNames.NoTranslation, "192.241.154.115", 22023)
|
||||
.Cast<IRegionInfo>(),
|
||||
new DnsRegionInfo("localhost", "localhost", StringNames.NoTranslation, "127.0.0.1", 22023)
|
||||
.Cast<IRegionInfo>(),
|
||||
new DnsRegionInfo("152.228.160.91", "matux.fr", StringNames.NoTranslation, "152.228.160.91", 22023)
|
||||
.Cast<IRegionInfo>(),
|
||||
new DnsRegionInfo("77.55.217.159", "Przebot", StringNames.NoTranslation, "77.55.217.159", 22023)
|
||||
.Cast<IRegionInfo>()
|
||||
};
|
||||
|
||||
internal static List<IRegionInfo> ModRegions { get; } = new List<IRegionInfo>();
|
||||
|
||||
public static IRegionInfo DirectRegion { get; set; }
|
||||
|
||||
internal static TextBoxTMP DirectConnect { get; set; }
|
||||
|
||||
public static void Patch()
|
||||
{
|
||||
RegionInfo[] newRegions = new RegionInfo[]
|
||||
{
|
||||
new RegionInfo("skeld.net", "192.241.154.115", new ServerInfo[]
|
||||
{
|
||||
new ServerInfo("skeld.net-Master-1", "192.241.154.115", 22023)
|
||||
}),
|
||||
new RegionInfo("localhost", "127.0.0.1", new ServerInfo[]
|
||||
{
|
||||
new ServerInfo("localhost-Master-1", "127.0.0.1", 22023)
|
||||
})
|
||||
};
|
||||
|
||||
RegionInfo[] customRegions = LoadCustomRegions();
|
||||
|
||||
RegionInfo[] patchedRegions = MergeRegions(ServerManager.DefaultRegions, newRegions);
|
||||
patchedRegions = MergeRegions(patchedRegions, customRegions);
|
||||
ServerManager serverManager = ServerManager.Instance;
|
||||
|
||||
IRegionInfo[] patchedRegions = OldRegions
|
||||
.AddRangeToArray(NewRegions)
|
||||
.AddRangeToArray(ModRegions.ToArray())
|
||||
.AddRangeToArray(LoadCustomUserRegions());
|
||||
if (DirectRegion != null) patchedRegions = patchedRegions.AddToArray(DirectRegion);
|
||||
|
||||
ServerManager.DefaultRegions = patchedRegions;
|
||||
serverManager.AvailableRegions = patchedRegions;
|
||||
}
|
||||
|
||||
private static RegionInfo[] MergeRegions(RegionInfo[] oldRegions, RegionInfo[] newRegions)
|
||||
private static IRegionInfo[] LoadCustomUserRegions()
|
||||
{
|
||||
RegionInfo[] patchedRegions = new RegionInfo[oldRegions.Length + newRegions.Length];
|
||||
Array.Copy(oldRegions, patchedRegions, oldRegions.Length);
|
||||
Array.Copy(newRegions, 0, patchedRegions, oldRegions.Length, newRegions.Length);
|
||||
List<IRegionInfo> customRegions = new List<IRegionInfo>();
|
||||
|
||||
return patchedRegions;
|
||||
}
|
||||
|
||||
private static RegionInfo[] LoadCustomRegions()
|
||||
{
|
||||
List<RegionInfo> customRegions = new List<RegionInfo>();
|
||||
|
||||
for (int x = 0; x < 5; x++)
|
||||
for (int x = 0; x < 9; x++)
|
||||
{
|
||||
ConfigEntry<string> regionName = UnifyPlugin.ConfigFile.Bind($"Region {x + 1}", $"Name", "custom region");
|
||||
ConfigEntry<string> regionIp = UnifyPlugin.ConfigFile.Bind($"Region {x + 1}", "IP", "");
|
||||
ConfigEntry<ushort> regionPort = UnifyPlugin.ConfigFile.Bind($"Region {x + 1}", "Port", (ushort) 22023);
|
||||
|
||||
ConfigEntry<string> regionName = UnifyPlugin.ConfigFile.Bind(
|
||||
$"Region {x + 1}", $"Name", "custom region");
|
||||
ConfigEntry<string> regionIp = UnifyPlugin.ConfigFile.Bind(
|
||||
$"Region {x + 1}", "IP", "");
|
||||
ConfigEntry<ushort> regionPort = UnifyPlugin.ConfigFile.Bind(
|
||||
$"Region {x + 1}", "Port", (ushort) 22023);
|
||||
|
||||
if (String.IsNullOrWhiteSpace(regionIp.Value)) continue;
|
||||
|
||||
RegionInfo regionInfo = new RegionInfo(regionName.Value, regionIp.Value, new ServerInfo[]
|
||||
{
|
||||
new ServerInfo($"{regionName.Value}-Master-1", regionIp.Value, regionPort.Value)
|
||||
});
|
||||
|
||||
IRegionInfo regionInfo = new DnsRegionInfo(
|
||||
regionIp.Value, regionName.Value,
|
||||
StringNames.NoTranslation, regionIp.Value, regionPort.Value)
|
||||
.Cast<IRegionInfo>();
|
||||
|
||||
customRegions.Add(regionInfo);
|
||||
}
|
||||
|
||||
return customRegions.ToArray();
|
||||
}
|
||||
|
||||
private static void UpdateRegion()
|
||||
{
|
||||
RegionMenu regionMenu = DestroyableSingleton<RegionMenu>.Instance;
|
||||
|
||||
bool success = UnifyPlugin.SetDirectRegion(DirectConnect.text, out IRegionInfo newRegion);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
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 LoadNewRegionsPatch
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
Patch();
|
||||
}
|
||||
}
|
||||
|
||||
[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))]
|
||||
public static class RegionMenuPatches
|
||||
{
|
||||
[HarmonyPatch(nameof(RegionMenu.Open))]
|
||||
[HarmonyPostfix]
|
||||
public static void DirectConnectButtonPatch()
|
||||
{
|
||||
RefreshDirectConnectButton();
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(RegionMenu.Open))]
|
||||
[HarmonyPostfix]
|
||||
public static void RegionMenuLayoutPatch()
|
||||
{
|
||||
RefreshRegionMenu();
|
||||
}
|
||||
|
||||
internal static void RefreshRegionMenu()
|
||||
{
|
||||
var regionButtons = DestroyableSingleton<RegionMenu>.Instance.ButtonPool.activeChildren.ToArray();
|
||||
var defaultRegions = ServerManager.DefaultRegions;
|
||||
var showOfficials = UnifyPlugin.ShowOfficialRegions.Value;
|
||||
var showExtras = UnifyPlugin.ShowExtraRegions.Value;
|
||||
var firstCustomRegionIndex = OldRegions.Length + NewRegions.Length + ModRegions.Count;
|
||||
|
||||
for (int i = 0; i < regionButtons.Length; i++)
|
||||
{
|
||||
ServerListButton regionButton = regionButtons[i].Cast<ServerListButton>();
|
||||
IRegionInfo region = defaultRegions[i];
|
||||
|
||||
var textTranslatorTemp = regionButton.GetComponentInChildren<TextTranslatorTMP>();
|
||||
if (textTranslatorTemp) textTranslatorTemp.Destroy();
|
||||
|
||||
bool isCustomRegion = i >= OldRegions.Length;
|
||||
bool isCustomUserRegion = i >= OldRegions.Length + NewRegions.Length + ModRegions.Count;
|
||||
float x = (!isCustomRegion && !showExtras ? 3f : 0) + (isCustomRegion ? 3f : 0) +
|
||||
(isCustomUserRegion ? 3f : 0) - 4.25f - (showOfficials ? 0 : 1.5f) - (showExtras ? 0 : 1.5f);
|
||||
float y = i - (isCustomRegion ? OldRegions.Length : 0) -
|
||||
(isCustomUserRegion ? NewRegions.Length + ModRegions.Count : 0);
|
||||
|
||||
var regionButtonPosition = new Vector3(1.25f + x, 2f - 0.5f * y, 0);
|
||||
regionButton.transform.localPosition = regionButtonPosition;
|
||||
|
||||
regionButton.gameObject.SetActive(
|
||||
(showOfficials || i >= OldRegions.Length) &&
|
||||
(showExtras || !isCustomRegion || isCustomUserRegion));
|
||||
|
||||
var buttonRolloverHandler = regionButton.GetComponent<ButtonRolloverHandler>();
|
||||
|
||||
if (RegionsEditor.IsActive)
|
||||
{
|
||||
buttonRolloverHandler.OverColor =
|
||||
ServerManager.Instance.CurrentRegion.Name == region.Name ? Color.white : Color.black;
|
||||
regionButton.Text.color = Color.gray;
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonRolloverHandler.OverColor = Color.green;
|
||||
regionButton.Text.color = Color.white;
|
||||
}
|
||||
|
||||
if (isCustomUserRegion)
|
||||
{
|
||||
regionButton.Text.text =
|
||||
RegionsEditor.IsActive ? $"{region.Name}\n{region.PingServer} {region.Servers[0].Port}" :
|
||||
region.Name;
|
||||
|
||||
if (i != firstCustomRegionIndex) continue;
|
||||
|
||||
PositionMoveButton(RegionsEditor.MoveUpButton, regionButtonPosition);
|
||||
PositionMoveButton(RegionsEditor.MoveDownButton, regionButtonPosition, -0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RefreshDirectConnectButton()
|
||||
{
|
||||
if (DirectConnect) DirectConnect.gameObject.Destroy();
|
||||
|
||||
RegionMenu regionMenu = DestroyableSingleton<RegionMenu>.Instance;
|
||||
JoinGameButton joinGameButton = DestroyableSingleton<JoinGameButton>.Instance;
|
||||
|
||||
DirectConnect = Object.Instantiate(joinGameButton.GameIdText, regionMenu.transform);
|
||||
DirectConnect.GetComponentInChildren<TextTranslatorTMP>().Destroy();
|
||||
DirectConnect.outputText.text = "Enter IP";
|
||||
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);
|
||||
}
|
||||
|
||||
private static void PositionMoveButton(Controls.Button button, Vector3 regionButtonPosition, float yOffset=0)
|
||||
{
|
||||
button.GameObject.transform.localPosition =
|
||||
new Vector3(regionButtonPosition.x + 1.45f, regionButtonPosition.y + yOffset, -100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static class RegionsEditor
|
||||
{
|
||||
private static Controls.Button _switchButton;
|
||||
|
||||
private static Controls.Button _toggleOfficialsButton;
|
||||
private static Controls.Button _toggleExtrasButton;
|
||||
|
||||
private static Controls.Button _addRegionButton;
|
||||
|
||||
internal static Controls.Button MoveUpButton;
|
||||
internal static Controls.Button MoveDownButton;
|
||||
|
||||
private static Popup _addRegionPopup;
|
||||
|
||||
internal static bool IsActive;
|
||||
|
||||
public static async void SetUp()
|
||||
{
|
||||
_addRegionPopup = await Popup.Create("Some text");
|
||||
|
||||
Controls.Button.Create("Edit", new Vector2(0.8f, 0.4f), new Vector2(0.5f, 0.3f), SetUpSwitchButton);
|
||||
|
||||
Controls.Button.Create("Toggle Official Regions", new Vector2(2f, 0.4f), new Vector2(1.1f, 1.3f),
|
||||
SetUpToggleOfficialsButton);
|
||||
Controls.Button.Create("Toggle Extra Regions", new Vector2(2f, 0.4f), new Vector2(1.1f, 1.8f),
|
||||
SetUpToggleExtrasButton);
|
||||
|
||||
Controls.Button.Create("Add Region", new Vector2(2f, 0.4f), new Vector2(1.1f, 2.3f), SetUpAddRegionButton);
|
||||
|
||||
Controls.Button.Create("↑", new Vector2(0.4f, 0.4f), Vector2.zero, SetUpMoveUpButton);
|
||||
Controls.Button.Create("↓", new Vector2(0.4f, 0.4f), Vector2.zero, SetUpMoveDownButton);
|
||||
}
|
||||
|
||||
public static void ShowRegionsEditor()
|
||||
{
|
||||
IsActive = true;
|
||||
_switchButton.Text.text = "Back";
|
||||
_toggleOfficialsButton.GameObject.SetActive(true);
|
||||
_toggleExtrasButton.GameObject.SetActive(true);
|
||||
/*MoveUpButton.GameObject.SetActive(true);
|
||||
MoveDownButton.GameObject.SetActive(true);
|
||||
_addRegionButton.GameObject.SetActive(true);*/
|
||||
|
||||
RegionsPatch.RegionMenuPatches.RefreshRegionMenu();
|
||||
RegionsPatch.DirectConnect.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public static void HideRegionsEditor()
|
||||
{
|
||||
IsActive = false;
|
||||
_switchButton.Text.text = "Edit";
|
||||
_toggleOfficialsButton.GameObject.SetActive(false);
|
||||
_toggleExtrasButton.GameObject.SetActive(false);
|
||||
/*MoveUpButton.GameObject.SetActive(false);
|
||||
MoveDownButton.GameObject.SetActive(false);
|
||||
_addRegionButton.GameObject.SetActive(false);*/
|
||||
|
||||
RegionsPatch.RegionMenuPatches.RefreshRegionMenu();
|
||||
RegionsPatch.RegionMenuPatches.RefreshDirectConnectButton();
|
||||
}
|
||||
|
||||
private static void SetUpSwitchButton(Controls.Button button)
|
||||
{
|
||||
_switchButton = button;
|
||||
|
||||
_switchButton.OnClick.AddListener((Action) (() =>
|
||||
{
|
||||
if (IsActive) HideRegionsEditor();
|
||||
else ShowRegionsEditor();
|
||||
}));
|
||||
}
|
||||
|
||||
private static void SetUpToggleOfficialsButton(Controls.Button button)
|
||||
{
|
||||
_toggleOfficialsButton = button;
|
||||
|
||||
_toggleOfficialsButton.OnClick.AddListener((Action) (() =>
|
||||
{
|
||||
UnifyPlugin.ShowOfficialRegions.Value = !UnifyPlugin.ShowOfficialRegions.Value;
|
||||
RegionsPatch.RegionMenuPatches.RefreshRegionMenu();
|
||||
}));
|
||||
}
|
||||
|
||||
private static void SetUpToggleExtrasButton(Controls.Button button)
|
||||
{
|
||||
_toggleExtrasButton = button;
|
||||
|
||||
_toggleExtrasButton.OnClick.AddListener((Action) (() =>
|
||||
{
|
||||
UnifyPlugin.ShowExtraRegions.Value = !UnifyPlugin.ShowExtraRegions.Value;
|
||||
RegionsPatch.RegionMenuPatches.RefreshRegionMenu();
|
||||
}));
|
||||
}
|
||||
|
||||
private static void SetUpMoveUpButton(Controls.Button button)
|
||||
{
|
||||
MoveUpButton = button;
|
||||
|
||||
MoveUpButton.GameObject.transform.position = DestroyableSingleton<RegionMenu>.Instance.transform.position;
|
||||
}
|
||||
|
||||
private static void SetUpMoveDownButton(Controls.Button button)
|
||||
{
|
||||
MoveDownButton = button;
|
||||
|
||||
MoveDownButton.GameObject.transform.position = DestroyableSingleton<RegionMenu>.Instance.transform.position;
|
||||
}
|
||||
|
||||
private static void SetUpAddRegionButton(Controls.Button button)
|
||||
{
|
||||
_addRegionButton = button;
|
||||
|
||||
_addRegionButton.OnClick.AddListener((Action) (() =>
|
||||
{
|
||||
_addRegionPopup.GameObject.SetActive(true);
|
||||
}));
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.Open))]
|
||||
public static class OpenRegionsEditorPatch
|
||||
{
|
||||
public static void Postfix()
|
||||
{
|
||||
_switchButton.GameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(RegionMenu))]
|
||||
public static class HideRegionsEditorPatch
|
||||
{
|
||||
[HarmonyPatch(nameof(RegionMenu.Close))]
|
||||
[HarmonyPostfix]
|
||||
public static void HideOnClosePatch()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(RegionMenu.ChooseOption))]
|
||||
[HarmonyPrefix]
|
||||
public static bool DisableRegionButtonsPatch()
|
||||
{
|
||||
return !IsActive;
|
||||
}
|
||||
|
||||
private static void Hide()
|
||||
{
|
||||
HideRegionsEditor();
|
||||
|
||||
_switchButton.GameObject.SetActive(false);
|
||||
RegionsPatch.DirectConnect.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// Store custom servers in a JSON file
|
||||
+74
-7
@@ -1,9 +1,14 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.IL2CPP;
|
||||
using HarmonyLib;
|
||||
using Hazel.Udp;
|
||||
using Reactor;
|
||||
using Unify.Controls;
|
||||
using Unify.Patches;
|
||||
|
||||
namespace Unify
|
||||
@@ -11,22 +16,84 @@ namespace Unify
|
||||
[BepInPlugin(Id, Name, Version)]
|
||||
[BepInProcess("Among Us.exe")]
|
||||
[BepInDependency(ReactorPlugin.Id)]
|
||||
[ReactorPluginSide(PluginSide.ClientOnly)]
|
||||
public class UnifyPlugin : BasePlugin
|
||||
{
|
||||
public const string Id = "daemon.unify.reactor";
|
||||
public const string Id = "daemon.unify";
|
||||
private const string Name = "Unify";
|
||||
private const string Version = "0.1.1";
|
||||
|
||||
public static readonly ConfigFile ConfigFile =
|
||||
new ConfigFile(Path.Combine(Paths.ConfigPath, $"{UnifyPlugin.Id}.cfg"), true);
|
||||
private const string Version = "4.2.0";
|
||||
|
||||
public static ConfigFile ConfigFile { get; private set; }
|
||||
|
||||
internal static ConfigEntry<bool> ShowOfficialRegions;
|
||||
internal static ConfigEntry<bool> ShowExtraRegions;
|
||||
|
||||
public Harmony Harmony { get; } = new Harmony(Id);
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
RegionsPatch.Patch();
|
||||
FixCompatibility();
|
||||
|
||||
ShowOfficialRegions = ConfigFile.Bind("Preferences", "Show Official Regions", true,
|
||||
"If the official regions should be shown when displaying the regions menu");
|
||||
ShowExtraRegions = ConfigFile.Bind("Preferences", "Show Extra Regions", true,
|
||||
"If the extra regions added by default in Unify should be shown when displaying the regions menu");
|
||||
|
||||
// Unpatches the modded handshake, because Impostor is STILL not fully updated yet
|
||||
Harmony.Unpatch(typeof(UdpConnection).GetMethod("HandleSend"), HarmonyPatchType.Prefix,
|
||||
ReactorPlugin.Id);
|
||||
|
||||
Harmony.PatchAll();
|
||||
|
||||
Button.InitializeBaseButton();
|
||||
// Popup.InitializeBasePopup();
|
||||
RegionsEditor.SetUp();
|
||||
}
|
||||
|
||||
public static IRegionInfo AddRegion(string name, string ip, ushort port)
|
||||
{
|
||||
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, port)
|
||||
.Cast<IRegionInfo>();
|
||||
|
||||
RegionsPatch.ModRegions.Add(newRegion);
|
||||
RegionsPatch.Patch();
|
||||
|
||||
return newRegion;
|
||||
}
|
||||
|
||||
public static bool SetDirectRegion(string ip, out IRegionInfo newRegion)
|
||||
{
|
||||
newRegion = null;
|
||||
|
||||
if (!Regex.IsMatch(ip, @"^(\d{1,3}\.){3}\d{1,3}$")) return false;
|
||||
|
||||
newRegion = new DnsRegionInfo(ip, ip, StringNames.NoTranslation, ip, 22023)
|
||||
.Cast<IRegionInfo>();
|
||||
|
||||
RegionsPatch.DirectRegion = newRegion;
|
||||
RegionsPatch.Patch();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void FixCompatibility()
|
||||
{
|
||||
string oldConfigPath = Path.Combine(Paths.ConfigPath, "daemon.unify.reactor.cfg");
|
||||
string newConfigPath = Path.Combine(Paths.ConfigPath, $"{UnifyPlugin.Id}.cfg");
|
||||
bool oldConfigExists = File.Exists(oldConfigPath);
|
||||
if (oldConfigExists)
|
||||
{
|
||||
File.Copy(oldConfigPath, newConfigPath, true);
|
||||
File.Delete(oldConfigPath);
|
||||
}
|
||||
|
||||
ConfigFile = new ConfigFile(Path.Combine(Paths.ConfigPath, $"{UnifyPlugin.Id}.cfg"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-10
@@ -1,29 +1,34 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Version>0.1.1</Version>
|
||||
<Mappings>NuclearPowered/Mappings:0.1.2</Mappings>
|
||||
<Version>4.2.0</Version>
|
||||
<Mappings>NuclearPowered/Mappings:0.4.0</Mappings>
|
||||
|
||||
<Description>Region mod for Reactor</Description>
|
||||
<Description>Region mod</Description>
|
||||
<Authors>Daemon</Authors>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(GamePlatform)' == 'Steam'">
|
||||
<GameVersion>2020.12.9s</GameVersion>
|
||||
<GameVersion>2021.4.14s</GameVersion>
|
||||
<DefineConstants>$(DefineConstants);STEAM</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<PropertyGroup Condition="'$(GamePlatform)' == 'Itch'">
|
||||
<GameVersion>2020.11.17i</GameVersion>
|
||||
<GameVersion>2021.4.14i</GameVersion>
|
||||
<DefineConstants>$(DefineConstants);ITCH</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Deobfuscate Include="$(AmongUs)\BepInEx\plugins\Reactor-$(GameVersion).dll" />
|
||||
|
||||
<PackageReference Include="Reactor.OxygenFilter.MSBuild" Version="0.2.5" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Reactor.OxygenFilter.MSBuild" Version="0.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<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/" />
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 29 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 268 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 296 KiB |
Reference in new issue
Block a user