mirror of
https://github.com/MoltenMods/Unify.git
synced 2026-10-19 17:56:57 +00:00
Added region menu editor
Added Przebot region Added ability to hide certain regions
This commit is contained in:
1 parent
9c70216a9f
commit
7b4a916d84
10 files changed
+461
-48
No files matched your search
@@ -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
|
# Table of Contents
|
||||||
- [Features](#features)
|
- [Features](#features)
|
||||||
@@ -15,6 +16,7 @@ The following regions have been added:
|
|||||||
- [skeld.net](https://skeld.net/)
|
- [skeld.net](https://skeld.net/)
|
||||||
- localhost *(for playing on a server running on your computer)*
|
- localhost *(for playing on a server running on your computer)*
|
||||||
- matux.fr
|
- matux.fr
|
||||||
|
- Przebot (may be unreliable or outdated)
|
||||||
|
|
||||||
Regions can be connected to directly using an IP address.
|
Regions can be connected to directly using an IP address.
|
||||||
|
|
||||||
@@ -22,7 +24,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, ushort port)` method.
|
`AddRegion(string name, string ip, ushort port)` API method.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+242
-26
@@ -3,8 +3,9 @@ using System.Collections.Generic;
|
|||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Reactor.Extensions;
|
using Reactor.Extensions;
|
||||||
|
using Unify.Controls;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using Button = UnityEngine.UI.Button;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
using String = System.String;
|
using String = System.String;
|
||||||
|
|
||||||
@@ -12,30 +13,32 @@ namespace Unify.Patches
|
|||||||
{
|
{
|
||||||
public static class RegionsPatch
|
public static class RegionsPatch
|
||||||
{
|
{
|
||||||
private static IRegionInfo[] _oldRegions { get; } = ServerManager.DefaultRegions;
|
internal static IRegionInfo[] OldRegions { get; } = ServerManager.DefaultRegions;
|
||||||
|
|
||||||
private static IRegionInfo[] _newRegions { get; } = new IRegionInfo[]
|
internal 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)
|
||||||
.Cast<IRegionInfo>(),
|
.Cast<IRegionInfo>(),
|
||||||
new DnsRegionInfo("localhost", "localhost", StringNames.NoTranslation, "127.0.0.1", 22023)
|
new DnsRegionInfo("localhost", "localhost", StringNames.NoTranslation, "127.0.0.1", 22023)
|
||||||
.Cast<IRegionInfo>(),
|
.Cast<IRegionInfo>(),
|
||||||
new DnsRegionInfo("152.228.160.91", "matux.fr", StringNames.NoTranslation, "152.228.160.91", 22023)
|
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>()
|
.Cast<IRegionInfo>()
|
||||||
};
|
};
|
||||||
|
|
||||||
public static List<IRegionInfo> ModRegions { get; } = new List<IRegionInfo>();
|
internal static List<IRegionInfo> ModRegions { get; } = new List<IRegionInfo>();
|
||||||
|
|
||||||
public static IRegionInfo DirectRegion { get; set; }
|
public static IRegionInfo DirectRegion { get; set; }
|
||||||
|
|
||||||
private static TextBoxTMP DirectConnect { get; set; }
|
internal static TextBoxTMP DirectConnect { get; set; }
|
||||||
|
|
||||||
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())
|
||||||
.AddRangeToArray(LoadCustomUserRegions());
|
.AddRangeToArray(LoadCustomUserRegions());
|
||||||
if (DirectRegion != null) patchedRegions = patchedRegions.AddToArray(DirectRegion);
|
if (DirectRegion != null) patchedRegions = patchedRegions.AddToArray(DirectRegion);
|
||||||
@@ -60,7 +63,7 @@ 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}\n{regionIp.Value} {regionPort.Value}",
|
regionIp.Value, regionName.Value,
|
||||||
StringNames.NoTranslation, regionIp.Value, regionPort.Value)
|
StringNames.NoTranslation, regionIp.Value, regionPort.Value)
|
||||||
.Cast<IRegionInfo>();
|
.Cast<IRegionInfo>();
|
||||||
|
|
||||||
@@ -113,13 +116,86 @@ namespace Unify.Patches
|
|||||||
{
|
{
|
||||||
[HarmonyPatch(nameof(RegionMenu.Open))]
|
[HarmonyPatch(nameof(RegionMenu.Open))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void DirectConnectButtonPatch(RegionMenu __instance)
|
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();
|
if (DirectConnect) DirectConnect.gameObject.Destroy();
|
||||||
|
|
||||||
|
RegionMenu regionMenu = DestroyableSingleton<RegionMenu>.Instance;
|
||||||
JoinGameButton joinGameButton = DestroyableSingleton<JoinGameButton>.Instance;
|
JoinGameButton joinGameButton = DestroyableSingleton<JoinGameButton>.Instance;
|
||||||
|
|
||||||
DirectConnect = Object.Instantiate(joinGameButton.GameIdText, __instance.transform);
|
DirectConnect = Object.Instantiate(joinGameButton.GameIdText, regionMenu.transform);
|
||||||
|
DirectConnect.GetComponentInChildren<TextTranslatorTMP>().Destroy();
|
||||||
|
DirectConnect.outputText.text = "Enter IP";
|
||||||
DirectConnect.IpMode = true;
|
DirectConnect.IpMode = true;
|
||||||
DirectConnect.characterLimit = 15;
|
DirectConnect.characterLimit = 15;
|
||||||
DirectConnect.ClearOnFocus = false;
|
DirectConnect.ClearOnFocus = false;
|
||||||
@@ -127,28 +203,168 @@ namespace Unify.Patches
|
|||||||
DirectConnect.OnEnter = new Button.ButtonClickedEvent();
|
DirectConnect.OnEnter = new Button.ButtonClickedEvent();
|
||||||
DirectConnect.OnEnter.AddListener((Action) UpdateRegion);
|
DirectConnect.OnEnter.AddListener((Action) UpdateRegion);
|
||||||
|
|
||||||
int offset = _newRegions.Length + ModRegions.Count;
|
int offset = NewRegions.Length + ModRegions.Count;
|
||||||
DirectConnect.transform.localPosition = new Vector3(0, 1f - (offset / 2f), -100f);
|
DirectConnect.transform.localPosition = new Vector3(0, 1f - (offset / 2f), -100f);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(nameof(RegionMenu.Open))]
|
private static void PositionMoveButton(Controls.Button button, Vector3 regionButtonPosition, float yOffset=0)
|
||||||
[HarmonyPostfix]
|
|
||||||
public static void RegionMenuLayoutPatch(RegionMenu __instance)
|
|
||||||
{
|
{
|
||||||
var regionButtons = __instance.ButtonPool.activeChildren.ToArray();
|
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;
|
||||||
|
|
||||||
for (int i = 0; i < regionButtons.Length; i++)
|
private static Controls.Button _addRegionButton;
|
||||||
{
|
|
||||||
ServerListButton regionButton = regionButtons[i].Cast<ServerListButton>();
|
internal static Controls.Button MoveUpButton;
|
||||||
|
internal static Controls.Button MoveDownButton;
|
||||||
|
|
||||||
bool isCustomRegion = i >= _oldRegions.Length;
|
private static Popup _addRegionPopup;
|
||||||
bool isCustomUserRegion = i >= _oldRegions.Length + _newRegions.Length + ModRegions.Count;
|
|
||||||
float x = (isCustomRegion ? 3f : 0) + (isCustomUserRegion ? 3f : 0) - 4.25f;
|
internal static bool IsActive;
|
||||||
float y = i - (isCustomRegion ? _oldRegions.Length : 0) -
|
|
||||||
(isCustomUserRegion ? _newRegions.Length + ModRegions.Count : 0);
|
public static async void SetUp()
|
||||||
|
{
|
||||||
regionButton.transform.localPosition = new Vector3(1.25f + x, 2f - 0.5f * y, 0f);
|
_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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-14
@@ -8,6 +8,7 @@ using BepInEx.IL2CPP;
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Hazel.Udp;
|
using Hazel.Udp;
|
||||||
using Reactor;
|
using Reactor;
|
||||||
|
using Unify.Controls;
|
||||||
using Unify.Patches;
|
using Unify.Patches;
|
||||||
|
|
||||||
namespace Unify
|
namespace Unify
|
||||||
@@ -20,32 +21,33 @@ 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.1.0";
|
private const string Version = "4.2.0";
|
||||||
|
|
||||||
public static ConfigFile ConfigFile { get; private set; }
|
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 Harmony Harmony { get; } = new Harmony(Id);
|
||||||
|
|
||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
// ===== For compatibility reasons =====
|
FixCompatibility();
|
||||||
string oldConfigPath = Path.Combine(Paths.ConfigPath, "daemon.unify.reactor.cfg");
|
|
||||||
string newConfigPath = Path.Combine(Paths.ConfigPath, $"{UnifyPlugin.Id}.cfg");
|
ShowOfficialRegions = ConfigFile.Bind("Preferences", "Show Official Regions", true,
|
||||||
bool oldConfigExists = File.Exists(oldConfigPath);
|
"If the official regions should be shown when displaying the regions menu");
|
||||||
if (oldConfigExists)
|
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");
|
||||||
File.Copy(oldConfigPath, newConfigPath, true);
|
|
||||||
File.Delete(oldConfigPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigFile = new ConfigFile(Path.Combine(Paths.ConfigPath, $"{UnifyPlugin.Id}.cfg"), true);
|
|
||||||
// =====================================
|
|
||||||
|
|
||||||
// Unpatches the modded handshake, because Impostor is STILL not fully updated yet
|
// Unpatches the modded handshake, because Impostor is STILL not fully updated yet
|
||||||
Harmony.Unpatch(typeof(UdpConnection).GetMethod("HandleSend"), HarmonyPatchType.Prefix,
|
Harmony.Unpatch(typeof(UdpConnection).GetMethod("HandleSend"), HarmonyPatchType.Prefix,
|
||||||
ReactorPlugin.Id);
|
ReactorPlugin.Id);
|
||||||
|
|
||||||
Harmony.PatchAll();
|
Harmony.PatchAll();
|
||||||
|
|
||||||
|
Button.InitializeBaseButton();
|
||||||
|
// Popup.InitializeBasePopup();
|
||||||
|
RegionsEditor.SetUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IRegionInfo AddRegion(string name, string ip, ushort port)
|
public static IRegionInfo AddRegion(string name, string ip, ushort port)
|
||||||
@@ -56,7 +58,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}\n{ip} {port}", StringNames.NoTranslation, ip, port)
|
IRegionInfo newRegion = new DnsRegionInfo(ip, name, StringNames.NoTranslation, ip, port)
|
||||||
.Cast<IRegionInfo>();
|
.Cast<IRegionInfo>();
|
||||||
|
|
||||||
RegionsPatch.ModRegions.Add(newRegion);
|
RegionsPatch.ModRegions.Add(newRegion);
|
||||||
@@ -79,5 +81,19 @@ namespace Unify
|
|||||||
|
|
||||||
return true;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-5
@@ -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.1.0</Version>
|
<Version>4.2.0</Version>
|
||||||
<Mappings>NuclearPowered/Mappings:0.4.0</Mappings>
|
<Mappings>NuclearPowered/Mappings:0.4.0</Mappings>
|
||||||
|
|
||||||
<Description>Region mod</Description>
|
<Description>Region mod</Description>
|
||||||
@@ -9,12 +9,12 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(GamePlatform)' == 'Steam'">
|
<PropertyGroup Condition="'$(GamePlatform)' == 'Steam'">
|
||||||
<GameVersion>2021.4.12s</GameVersion>
|
<GameVersion>2021.4.14s</GameVersion>
|
||||||
<DefineConstants>$(DefineConstants);STEAM</DefineConstants>
|
<DefineConstants>$(DefineConstants);STEAM</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(GamePlatform)' == 'Itch'">
|
<PropertyGroup Condition="'$(GamePlatform)' == 'Itch'">
|
||||||
<GameVersion>2021.4.12i</GameVersion>
|
<GameVersion>2021.4.14i</GameVersion>
|
||||||
<DefineConstants>$(DefineConstants);ITCH</DefineConstants>
|
<DefineConstants>$(DefineConstants);ITCH</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -32,7 +32,5 @@
|
|||||||
<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.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 145 KiB After Width: | Height: | Size: 268 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 296 KiB |
Reference in new issue
Block a user