mirror of
https://github.com/MoltenMods/Unify.git
synced 2026-10-19 17:56:57 +00:00
Restructured code and added AddRegion() method
This commit is contained in:
3 files changed
+36
-17
No files matched your search
+14
-16
@@ -11,35 +11,30 @@ namespace Unify.Patches
|
||||
{
|
||||
public static class RegionsPatch
|
||||
{
|
||||
private static IRegionInfo[] _oldRegions = ServerManager.DefaultRegions;
|
||||
private static IRegionInfo[] _newRegions = new IRegionInfo[]
|
||||
{
|
||||
new DnsRegionInfo("192.241.154.115", "skeld.net", StringNames.NoTranslation, "192.241.154.115")
|
||||
.Duplicate(),
|
||||
.Cast<IRegionInfo>(),
|
||||
new DnsRegionInfo("localhost", "localhost", StringNames.NoTranslation, "127.0.0.1")
|
||||
.Duplicate(),
|
||||
.Cast<IRegionInfo>(),
|
||||
new DnsRegionInfo("152.228.160.91", "matux.fr", StringNames.NoTranslation, "152.228.160.91")
|
||||
.Duplicate()
|
||||
.Cast<IRegionInfo>()
|
||||
};
|
||||
private static IRegionInfo[] _customRegions = MergeRegions(_newRegions, LoadCustomUserRegions());
|
||||
|
||||
|
||||
public static List<IRegionInfo> ModRegions = new List<IRegionInfo>();
|
||||
|
||||
public static void Patch()
|
||||
{
|
||||
IRegionInfo[] patchedRegions = MergeRegions(ServerManager.DefaultRegions, _customRegions);
|
||||
IRegionInfo[] customRegions = UnifyPlugin.MergeRegions(_newRegions, ModRegions.ToArray());
|
||||
customRegions = UnifyPlugin.MergeRegions(customRegions, LoadCustomUserRegions());
|
||||
IRegionInfo[] patchedRegions = UnifyPlugin.MergeRegions(_oldRegions, customRegions);
|
||||
|
||||
ServerManager.DefaultRegions = patchedRegions;
|
||||
ServerManager.Instance.AvailableRegions = patchedRegions;
|
||||
ServerManager.Instance.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>();
|
||||
@@ -55,7 +50,7 @@ namespace Unify.Patches
|
||||
|
||||
IRegionInfo regionInfo = new DnsRegionInfo(
|
||||
regionIp.Value, regionName.Value, StringNames.NoTranslation, regionIp.Value)
|
||||
.Duplicate();
|
||||
.Cast<IRegionInfo>();
|
||||
|
||||
customRegions.Add(regionInfo);
|
||||
}
|
||||
@@ -70,6 +65,7 @@ namespace Unify.Patches
|
||||
[HarmonyBefore(new string[] { "gg.reactor.api" })]
|
||||
public static void Prefix()
|
||||
{
|
||||
if (UnifyPlugin.HandshakeDisabled) return;
|
||||
if (!UnifyPlugin.NormalHandshake.Contains(ServerManager.Instance.CurrentRegion.Name)) return;
|
||||
|
||||
PluginSingleton<ReactorPlugin>.Instance.ModdedHandshake.Value = false;
|
||||
@@ -77,6 +73,8 @@ namespace Unify.Patches
|
||||
|
||||
public static void Postfix()
|
||||
{
|
||||
if (UnifyPlugin.HandshakeDisabled) return;
|
||||
|
||||
PluginSingleton<ReactorPlugin>.Instance.ModdedHandshake.Value = true;
|
||||
}
|
||||
}
|
||||
|
||||
+22
-1
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.IL2CPP;
|
||||
@@ -20,6 +21,8 @@ namespace Unify
|
||||
|
||||
public static readonly ConfigFile ConfigFile =
|
||||
new ConfigFile(Path.Combine(Paths.ConfigPath, $"{UnifyPlugin.Id}.cfg"), true);
|
||||
|
||||
public static readonly bool HandshakeDisabled = !PluginSingleton<ReactorPlugin>.Instance.ModdedHandshake.Value;
|
||||
|
||||
public static readonly string[] NormalHandshake =
|
||||
new string[] {"North America", "Europe", "Asia", "skeld.net"};
|
||||
@@ -32,5 +35,23 @@ namespace Unify
|
||||
|
||||
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 void AddRegion(string name, string ip)
|
||||
{
|
||||
IRegionInfo newRegion = new DnsRegionInfo(ip, name, StringNames.NoTranslation, ip)
|
||||
.Cast<IRegionInfo>();
|
||||
|
||||
RegionsPatch.ModRegions.Add(newRegion);
|
||||
RegionsPatch.Patch();
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user