using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using HarmonyLib; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using UnityEngine.Events; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")] [assembly: AssemblyCompany("miniduikboot")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Installs regions into your regionInfo.json file")] [assembly: AssemblyFileVersion("1.2.0.0")] [assembly: AssemblyInformationalVersion("1.2.0")] [assembly: AssemblyProduct("Mini.RegionInstall")] [assembly: AssemblyTitle("Mini.RegionInstall")] [assembly: AssemblyVersion("1.2.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string id = null, string name = null, string version = null) { } } } namespace Mini.RegionInstall { [BepInProcess("Among Us.exe")] [BepInPlugin("at.duikbo.regioninstall", "Mini.RegionInstall", "1.2.0")] public class RegionInstallPlugin : BasePlugin { internal static ManualLogSource? Logger; private static ReadOnlyDictionary? parsedRegions; public const string Id = "at.duikbo.regioninstall"; public Harmony Harmony { get; } = new Harmony("at.duikbo.regioninstall"); public static string Name => "Mini.RegionInstall"; public static string Version => "1.2.0"; public override void Load() { Logger = ((BasePlugin)this).Log; ((BasePlugin)this).Log.LogInfo((object)"Starting Mini.RegionInstall"); Harmony.PatchAll(); ConfigEntry regions = ((BasePlugin)this).Config.Bind("General", "Regions", "{\"CurrentRegionIdx\":0,\"Regions\":[]}", "Create an array of regions you want to add/update. To create this array, go to https://impostor.github.io/Impostor/ and put the Regions array from the server file in here"); ConfigEntry removeRegions = ((BasePlugin)this).Config.Bind("General", "RemoveRegions", string.Empty, "Comma-seperated list of region names that should be removed."); SceneManager.sceneLoaded += UnityAction.op_Implicit((Action)delegate(Scene scene, LoadSceneMode _) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown if (((Scene)(ref scene)).name == "MainMenu") { if (removeRegions != null) { string[] array = removeRegions.Value.Split(","); ManualLogSource log = ((BasePlugin)this).Log; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(25, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Removing User Regions: \""); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(string.Join("\", \"", array)); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\""); } log.LogInfo(val); RemoveRegions(array); } if (regions != null && regions.Value.Length != 0) { ((BasePlugin)this).Log.LogInfo((object)"Adding User Regions"); IRegionInfo[] array2 = ParseRegions(regions.Value); AddRegions(array2); Dictionary dictionary = new Dictionary(); IRegionInfo[] array3 = array2; foreach (IRegionInfo val2 in array3) { dictionary[val2.Name] = val2; } parsedRegions = new ReadOnlyDictionary(dictionary); } } }); } private void AddRegions(IRegionInfo[] regions) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown ServerManager instance = DestroyableSingleton.Instance; IRegionInfo val = instance.CurrentRegion; ManualLogSource log = ((BasePlugin)this).Log; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(15, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Adding "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted(regions.Length); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" regions"); } log.LogInfo(val2); foreach (IRegionInfo val3 in regions) { if (val3 == null) { ((BasePlugin)this).Log.LogError((object)"Could not add region"); continue; } if (val != null && val3.Name.Equals(val.Name, StringComparison.OrdinalIgnoreCase)) { val = val3; } instance.AddOrUpdateRegion(val3); } if (val != null) { ((BasePlugin)this).Log.LogDebug((object)"Resetting previous region"); instance.SetRegion(val); } } private IRegionInfo[] ParseRegions(string regions) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown ManualLogSource log = ((BasePlugin)this).Log; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(8, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Parsing "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(regions); } log.LogInfo(val); switch (regions[0]) { case '{': { ((BasePlugin)this).Log.LogInfo((object)"Loading server data"); JsonServerData val2 = JsonConvert.DeserializeObject(regions, new JsonSerializerSettings { TypeNameHandling = (TypeNameHandling)4 }); foreach (IRegionInfo item in (Il2CppArrayBase)(object)val2.Regions) { ManualLogSource log2 = ((BasePlugin)this).Log; val = new BepInExInfoLogInterpolatedStringHandler(13, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Region \""); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(item.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\" @ "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(((Il2CppArrayBase)(object)item.Servers)[0].Ip); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(":"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(((Il2CppArrayBase)(object)item.Servers)[0].Port); } log2.LogInfo(val); } return Il2CppArrayBase.op_Implicit((Il2CppArrayBase)(object)val2.Regions); } case '[': ((BasePlugin)this).Log.LogInfo((object)"Loading region array"); return ParseRegions("{\"CurrentRegionIdx\":0,\"Regions\":" + regions + "}"); default: ((BasePlugin)this).Log.LogError((object)"Could not detect format of configured regions"); return Array.Empty(); } } public static void CorrectCurrentRegion(ServerManager instance) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Expected O, but got Unknown IRegionInfo currentRegion = instance.CurrentRegion; ManualLogSource logger = Logger; bool flag = default(bool); if (logger != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Current region: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(currentRegion.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(((Il2CppArrayBase)(object)currentRegion.Servers).Length); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" servers)"); } logger.LogInfo(val); } logger = Logger; if (logger != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(13, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Region \""); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(((Il2CppArrayBase)(object)currentRegion.Servers)[0].Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\" @ "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(((Il2CppArrayBase)(object)currentRegion.Servers)[0].Ip); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(":"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(((Il2CppArrayBase)(object)currentRegion.Servers)[0].Port); } logger.LogInfo(val); } if (parsedRegions == null || !parsedRegions.ContainsKey(currentRegion.Name)) { return; } instance.CurrentRegion = parsedRegions[currentRegion.Name]; ManualLogSource? logger2 = Logger; if (logger2 != null) { logger2.LogInfo((object)"Loading region from cache instead of from file"); } if (((Il2CppArrayBase)(object)currentRegion.Servers)[0].Port == ((Il2CppArrayBase)(object)instance.CurrentRegion.Servers)[0].Port) { return; } logger = Logger; if (logger != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Port corrected from "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(((Il2CppArrayBase)(object)currentRegion.Servers)[0].Port); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(((Il2CppArrayBase)(object)instance.CurrentRegion.Servers)[0].Port); } logger.LogInfo(val); } } private void RemoveRegions(string[] regionNames) { string[] regionNames2 = regionNames; IEnumerable source = ((IEnumerable)DestroyableSingleton.Instance.AvailableRegions).Where(delegate(IRegionInfo r) { IRegionInfo r2 = r; return Array.FindIndex(regionNames2, (string name) => name.Equals(r2.Name, StringComparison.OrdinalIgnoreCase)) == -1; }); DestroyableSingleton.Instance.AvailableRegions = Il2CppReferenceArray.op_Implicit(source.ToArray()); } } [HarmonyPatch(typeof(DnsRegionInfo), "PopulateServers")] public static class DnsRegionInfoPatch { public static void Postfix(DnsRegionInfo __instance) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown ManualLogSource logger = RegionInstallPlugin.Logger; bool flag = default(bool); if (logger != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("DRI Populate Servers: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(__instance.Fqdn); } logger.LogInfo(val); } foreach (ServerInfo item in (Il2CppArrayBase)(object)__instance.Servers) { logger = RegionInstallPlugin.Logger; if (logger != null) { BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(19, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Configured server: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(((Object)item).ToString()); } logger.LogInfo(val); } } } } [HarmonyPatch(typeof(ServerManager), "ReselectServer")] public static class SMReselectPatch { public static void Prefix(ServerManager __instance) { RegionInstallPlugin.CorrectCurrentRegion(__instance); } public static void Postfix(ServerManager __instance) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown ServerInfo currentUdpServer = __instance.CurrentUdpServer; ManualLogSource logger = RegionInstallPlugin.Logger; if (logger != null) { bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Current server: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(((Object)currentUdpServer).ToString()); } logger.LogInfo(val); } } } [HarmonyPatch(typeof(ServerManager), "LoadServers")] public static class ServerManagerLoadServersPatch { public static void Postfix(ServerManager __instance) { RegionInstallPlugin.CorrectCurrentRegion(__instance); __instance.CurrentUdpServer = ((Il2CppArrayBase)(object)__instance.CurrentRegion.Servers)[0]; } } }