Merged pull request from dev branch

Added config file for custom user regions
This commit is contained in:
Daemon authored and GitHub committed 2021-03-04 18:50:15 +00:00
commit 8fbb962627
6 files changed
+67 -6

No files matched your search

+23 -1
View File
@@ -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.
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.
+36 -2
View File
@@ -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<RegionInfo> customRegions = new List<RegionInfo>();
for (int x = 0; x < 5; 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;
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();
}
}
}
+7 -2
View File
@@ -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);
+1 -1
View File
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>0.1.0</Version>
<Version>0.1.1</Version>
<Mappings>NuclearPowered/Mappings:0.1.2</Mappings>
<Description>Region mod for Reactor</Description>
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 29 KiB