14 Commits
Author SHA1 Message Date
Daemon 76a25f8107 Merge pull request #18 from MoltenMods/2021
Updated code to work with Reactor and modified custom regions config to allow more regions
2021-04-09 21:10:54 +01:00
Daemon 339f4f2c33 Updated code to use reactor
Updated code to use fields instead of properties

Updated README

Modified custom regions config to allow 10 custom regions instead of 5
2021-04-09 21:03:28 +01:00
Daemon ec7eda2fa7 Merge pull request #17 from MoltenMods/2021-pre
Merge features from pre-release branch
2021-04-04 12:03:47 +01:00
Daemon 8ac9ff247d Merge pull request #16 from MoltenMods/2021-pre
Added direct connect option, restructured regions menu and updated code to work with 2021.3.31.3s
2021-04-02 12:58:47 +01:00
Daemon b22393625f Merge branch 'master' into 2021-pre 2021-04-02 12:58:32 +01:00
Daemon 5f0decd34f Updated code to work with 2021.3.31.3s
Modified way regions menu is displayed

Changed GUID and added code to automatically transfer old config
2021-04-02 12:54:15 +01:00
Daemon c7af5d5c9c Removed attempt to set input placeholder text 2021-03-30 21:36:41 +01:00
Daemon 26142c72d4 Added direct connect in regions menu 2021-03-30 21:15:08 +01:00
Daemon 083ac31586 Updated README 2021-03-19 22:00:09 +00:00
Daemon 81b058178c Updated version number 2021-03-19 21:56:53 +00:00
Daemon a7b0774f9d Restructured code and added AddRegion() method 2021-03-19 21:49:09 +00:00
Daemon ab57814ee3 Added new AddRegion() method for external mods
`AddRegion()` method allows mods to add new regions
2021-03-19 21:43:43 +00:00
Daemon c861abbb4f Modified modded handshake disable patch
Stopped reactor handshake option getting set true automatically
2021-03-19 19:26:51 +00:00
Daemon d2a59980b0 Changed use of .Duplicate() method to .Cast<IRegionInfo>() 2021-03-19 19:10:44 +00:00
8 changed files with 226 additions and 75 deletions

No files matched your search

+23 -12
View File
@@ -1,8 +1,14 @@
> **⚠ 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.
![Regions menu](images/RegionsMenu.jpg)
![Regions menu](images/RegionsMenu.png)
# Table of Contents
- [Features](#features)
@@ -14,23 +20,28 @@ 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
Regions can be connected to directly using an IP address.
Custom regions can be added as detailed below in the
[configuration](#configuration) section.
## Installation
> **⚠ WARNING**
>
> This mod is only compatible with the steam release of the game.
> 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.
> 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 using 2021.3.5s and Reactor fails to load, ensure you have the latest version of Reactor installed.
> 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 (more information above).
2. Download the latest mod on the [releases](https://github.com/DaemonBeast/Unify/releases) page.
1. Ensure that BepInEx and Reactor 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.
@@ -44,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 10]` 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.
+122 -42
View File
@@ -1,83 +1,163 @@
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections.Generic;
using BepInEx.Configuration;
using HarmonyLib;
using Hazel.Udp;
using Reactor;
using Array = System.Array;
using UnityEngine;
using UnityEngine.UI;
using Object = UnityEngine.Object;
using String = System.String;
namespace Unify.Patches
{
public static class RegionsPatch
{
private static IRegionInfo[] _newRegions = new IRegionInfo[]
{
new DnsRegionInfo("192.241.154.115", "skeld.net", StringNames.NoTranslation, "192.241.154.115")
.Duplicate(),
new DnsRegionInfo("localhost", "localhost", StringNames.NoTranslation, "127.0.0.1")
.Duplicate(),
new DnsRegionInfo("152.228.160.91", "matux.fr", StringNames.NoTranslation, "152.228.160.91")
.Duplicate()
};
private static IRegionInfo[] _customRegions = MergeRegions(_newRegions, LoadCustomUserRegions());
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)
.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>()
};
public static List<IRegionInfo> ModRegions { get; } = new List<IRegionInfo>();
public static IRegionInfo DirectRegion { get; set; }
private static TextBox directConnect { get; set; }
public static void Patch()
{
IRegionInfo[] patchedRegions = MergeRegions(ServerManager.DefaultRegions, _customRegions);
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);
ServerManager.DefaultRegions = patchedRegions;
ServerManager.Instance.AvailableRegions = patchedRegions;
ServerManager.Instance.SaveServers();
serverManager.AvailableRegions = patchedRegions;
serverManager.SaveServers();
}
private 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;
}
private static IRegionInfo[] LoadCustomUserRegions()
{
List<IRegionInfo> customRegions = new List<IRegionInfo>();
for (int x = 0; x < 5; x++)
for (int x = 0; x < 10; 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);
if (String.IsNullOrWhiteSpace(regionIp.Value)) continue;
IRegionInfo regionInfo = new DnsRegionInfo(
regionIp.Value, regionName.Value, StringNames.NoTranslation, regionIp.Value)
.Duplicate();
regionIp.Value, regionName.Value, StringNames.NoTranslation, regionIp.Value, regionPort.Value)
.Cast<IRegionInfo>();
customRegions.Add(regionInfo);
}
return customRegions.ToArray();
}
}
[HarmonyPatch(typeof(UdpConnection), nameof(UdpConnection.HandleSend))]
public static class DisableModdedHandshakePatch
{
[HarmonyBefore(new string[] { "gg.reactor.api" })]
public static void Prefix()
private static void UpdateRegion()
{
if (!UnifyPlugin.NormalHandshake.Contains(ServerManager.Instance.CurrentRegion.Name)) return;
RegionMenu regionMenu = GameObject.Find("RegionMenu").GetComponent<RegionMenu>();
PluginSingleton<ReactorPlugin>.Instance.ModdedHandshake.Value = false;
bool success = UnifyPlugin.SetDirectRegion(directConnect.text, out IRegionInfo newRegion);
if (!success)
{
directConnect.StartCoroutine(Effects.FIJHCJMBGFP(directConnect.transform, 0.75f, 0.25f));
return;
}
regionMenu.ChooseOption(newRegion);
regionMenu.Close();
}
[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 = ((ServerManager.DefaultRegions.Length + 1) / 2) + 1;
directConnect.transform.localPosition = new Vector3(0, 2f - (offset / 2f), -100f);
}
}
public static void Postfix()
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.Open))]
public static class RegionMenuLayoutPatch
{
PluginSingleton<ReactorPlugin>.Instance.ModdedHandshake.Value = true;
public static void Postfix(RegionMenu __instance)
{
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);
}
}
}
[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), nameof(RegionMenu.Close))]
public static class HideDirectConnectPatch
{
public static void Postfix()
{
directConnect.gameObject.SetActive(false);
}
}
[HarmonyPatch(typeof(RegionMenu), nameof(RegionMenu.ChooseOption))]
public static class HideDirectConnectOnSelectPatch
{
public static void Postfix()
{
directConnect.gameObject.SetActive(false);
}
}
}
}
}
// TODO:
// Store custom servers in a JSON file
+68 -8
View File
@@ -1,4 +1,7 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.IL2CPP;
@@ -14,23 +17,80 @@ namespace Unify
[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 = "2.0.3";
private const string Version = "3.0.0";
public static ConfigFile ConfigFile { get; private set; }
// public static readonly bool HandshakeDisabled = !PluginSingleton<ReactorPlugin>.Instance.ModdedHandshake.Value;
public static readonly ConfigFile ConfigFile =
new ConfigFile(Path.Combine(Paths.ConfigPath, $"{UnifyPlugin.Id}.cfg"), true);
public static readonly string[] NormalHandshake =
new string[] {"North America", "Europe", "Asia", "skeld.net"};
/*public static readonly string[] NormalHandshake =
new string[] {"North America", "Europe", "Asia", "skeld.net"};*/
public Harmony Harmony { get; } = new Harmony(Id);
public override void Load()
{
// ===== For compatibility reasons =====
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);
// =====================================
RegionsPatch.Patch();
Harmony.UnpatchAll(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;
IRegionInfo existingRegion =
ServerManager.DefaultRegions.ToArray().FirstOrDefault(region => region.PingServer == ip);
if (existingRegion != null) return existingRegion;
IRegionInfo newRegion = new DnsRegionInfo(ip, name, StringNames.NoTranslation, ip, 22023)
.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;
}
}
}
+13 -13
View File
@@ -1,34 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>2.0.3</Version>
<Mappings>NuclearPowered/Mappings:0.2.0</Mappings>
<Version>3.0.0</Version>
<Mappings>NuclearPowered/Mappings:0.3.0</Mappings>
<Description>Region mod for Reactor</Description>
<Description>Region mod</Description>
<Authors>Daemon</Authors>
</PropertyGroup>
<PropertyGroup Condition="'$(GamePlatform)' == 'Steam'">
<GameVersion>2021.3.5s</GameVersion>
<GameVersion>2021.3.31.3s</GameVersion>
<DefineConstants>$(DefineConstants);STEAM</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(GamePlatform)' == 'Itch'">
<GameVersion>2021.11.17i</GameVersion>
<GameVersion>2021.3.31.3i</GameVersion>
<DefineConstants>$(DefineConstants);ITCH</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Deobfuscate Include="$(AmongUs)\BepInEx\plugins\Reactor-$(GameVersion).dll" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Reactor.OxygenFilter.MSBuild" Version="0.2.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<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.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB