diff --git a/README.md b/README.md index 906521c..163e0db 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ An Among Us mod to add extra regions to the regions menu. # Table of Contents - [Features](#features) - [Installation](#installation) +- [Configuration](#configuration) ## Features @@ -24,4 +25,25 @@ The following regions have been added: 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. 3. Move the mod to the `(Among Us game files)/BepInEx/plugins` folder. -4. Launch the game. \ No newline at end of file +4. Launch the game. + +## Configuration + +> **⚠ WARNING** +> +> The configuration file will be generated when loading the mod for +> the first time. If the configuration file is not there, try +> launching the game and closing it to see if the configuration +> file creates itself. + +The configuration file is located at +`(Among Us game files)/BepInEx/config/daemon.unify.reactor.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. + +If the IP field is left empty, the region will not show up in game. diff --git a/Unify/Patches/Regions.cs b/Unify/Patches/Regions.cs index c044488..71d57d8 100644 --- a/Unify/Patches/Regions.cs +++ b/Unify/Patches/Regions.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using BepInEx.Configuration; using HarmonyLib; namespace Unify.Patches @@ -20,12 +22,44 @@ namespace Unify.Patches }) }; - RegionInfo[] oldRegions = ServerManager.DefaultRegions; + RegionInfo[] customRegions = LoadCustomRegions(); + + RegionInfo[] patchedRegions = MergeRegions(ServerManager.DefaultRegions, newRegions); + patchedRegions = MergeRegions(patchedRegions, customRegions); + + ServerManager.DefaultRegions = patchedRegions; + } + + private static RegionInfo[] MergeRegions(RegionInfo[] oldRegions, RegionInfo[] newRegions) + { RegionInfo[] patchedRegions = new RegionInfo[oldRegions.Length + newRegions.Length]; Array.Copy(oldRegions, patchedRegions, oldRegions.Length); Array.Copy(newRegions, 0, patchedRegions, oldRegions.Length, newRegions.Length); - ServerManager.DefaultRegions = patchedRegions; + return patchedRegions; + } + + private static RegionInfo[] LoadCustomRegions() + { + List customRegions = new List(); + + for (int x = 0; x < 5; x++) + { + ConfigEntry regionName = UnifyPlugin.ConfigFile.Bind($"Region {x + 1}", $"Name", "custom region"); + ConfigEntry regionIp = UnifyPlugin.ConfigFile.Bind($"Region {x + 1}", "IP", ""); + ConfigEntry 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) + }); + + customRegions.Add(regionInfo); + } + + return customRegions.ToArray(); } } } \ No newline at end of file diff --git a/Unify/Unify.cs b/Unify/Unify.cs index 84890ca..6c96c29 100644 --- a/Unify/Unify.cs +++ b/Unify/Unify.cs @@ -1,4 +1,6 @@ -using BepInEx; +using System.IO; +using BepInEx; +using BepInEx.Configuration; using BepInEx.IL2CPP; using HarmonyLib; using Reactor; @@ -13,7 +15,10 @@ namespace Unify { public const string Id = "daemon.unify.reactor"; private const string Name = "Unify"; - private const string Version = "0.1.0"; + private const string Version = "0.1.1"; + + public static readonly ConfigFile ConfigFile = + new ConfigFile(Path.Combine(Paths.ConfigPath, $"{UnifyPlugin.Id}.cfg"), true); public Harmony Harmony { get; } = new Harmony(Id); diff --git a/Unify/Unify.csproj b/Unify/Unify.csproj index e232de8..ae562bc 100644 --- a/Unify/Unify.csproj +++ b/Unify/Unify.csproj @@ -1,7 +1,7 @@ netstandard2.1 - 0.1.0 + 0.1.1 NuclearPowered/Mappings:0.1.2 Region mod for Reactor diff --git a/build/Unify-2020.12.9s.dll b/build/Unify-2020.12.9s.dll index 2f8402c..f6315be 100644 Binary files a/build/Unify-2020.12.9s.dll and b/build/Unify-2020.12.9s.dll differ diff --git a/images/RegionsMenu.jpg b/images/RegionsMenu.jpg index 0d169bd..5ad7fb7 100644 Binary files a/images/RegionsMenu.jpg and b/images/RegionsMenu.jpg differ