using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AutoRegion")]
[assembly: AssemblyTitle("AutoRegion")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
[BepInPlugin("com.repo.qol.preferredregion", "Preferred Region (Public & Private)", "1.3.0")]
public class PreferredRegionPlugin : BaseUnityPlugin
{
internal static PreferredRegionPlugin Instance;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<string> PreferredRegionCode;
internal static ConfigEntry<bool> JumpStraightToServerList;
private void Awake()
{
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable auto-selecting your preferred region.");
PreferredRegionCode = ((BaseUnityPlugin)this).Config.Bind<string>("General", "PreferredRegionCode", "", "Saved region code (set automatically on first pick). Valid: asia, au, cae, cn, eu, hk, in, jp, kr, sa, tr, uae, za, us, usw, ussc");
JumpStraightToServerList = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "JumpStraightToServerList", true, "Public flow: if true, pressing Public goes straight to Server List; otherwise to Public Game Choice.");
string text = RegionCodes.Normalize(PreferredRegionCode.Value);
if (RegionCodes.IsValid(text) && text != PreferredRegionCode.Value)
{
PreferredRegionCode.Value = text;
try
{
((BaseUnityPlugin)this).Config.Save();
}
catch
{
}
}
new Harmony("com.repo.qol.preferredregion").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)$"[PreferredRegion] Loaded. Enabled={Enabled.Value} Saved='{PreferredRegionCode.Value}' JumpToList={JumpStraightToServerList.Value}");
}
internal static void SaveRegionToConfig(string code)
{
string text = RegionCodes.Normalize(code);
if (RegionCodes.IsValid(text) && PreferredRegionCode.Value != text)
{
PreferredRegionCode.Value = text;
try
{
((BaseUnityPlugin)Instance).Config.Save();
}
catch (Exception arg)
{
Debug.LogWarning((object)$"[PreferredRegion] Failed to save config: {arg}");
}
Debug.Log((object)("[PreferredRegion] Saved preferred region '" + text + "' to config."));
}
}
}
internal static class RegionCodes
{
private static readonly HashSet<string> Valid = new HashSet<string>
{
"asia", "au", "cae", "cn", "eu", "hk", "in", "jp", "kr", "sa",
"tr", "uae", "za", "us", "usw", "ussc"
};
public static string Normalize(string inputRaw)
{
if (string.IsNullOrWhiteSpace(inputRaw))
{
return "";
}
string text = inputRaw.Trim().ToLowerInvariant();
bool flag;
switch (text)
{
case "usa east":
case "us east":
case "east":
case "usa_east":
case "useast":
flag = true;
break;
default:
flag = false;
break;
}
if (flag)
{
return "us";
}
switch (text)
{
case "usa west":
case "us west":
case "west":
case "usa_west":
case "uswest":
flag = true;
break;
default:
flag = false;
break;
}
if (flag)
{
return "usw";
}
switch (text)
{
case "usa south central":
case "us south central":
case "south central":
case "usa_south_central":
case "ussouthcentral":
flag = true;
break;
default:
flag = false;
break;
}
if (flag)
{
return "ussc";
}
text = text.Replace(" ", "").Replace("-", "").Replace("_", "");
if (text == "brazil" || text == "sa_america" || text == "southamerica")
{
text = "sa";
}
if (text == "uae" || text == "unitedarabemirates")
{
text = "uae";
}
if (text == "japan")
{
text = "jp";
}
if (text == "korea" || text == "southkorea")
{
text = "kr";
}
if (Valid.Contains(text))
{
return text;
}
return text;
}
public static bool IsValid(string code)
{
return !string.IsNullOrWhiteSpace(code) && Valid.Contains(code);
}
}
internal static class NavGuard
{
private static float lastNavAt;
public static bool TryBegin(float cooldown = 0.5f)
{
float unscaledTime = Time.unscaledTime;
if (unscaledTime - lastNavAt < cooldown)
{
return false;
}
lastNavAt = unscaledTime;
return true;
}
}
[HarmonyPatch(typeof(MenuPageMain), "ButtonEventPlayRandom")]
internal static class Patch_PublicButton_Shortcut
{
private static bool Prefix()
{
if (!PreferredRegionPlugin.Enabled.Value)
{
return true;
}
string text = RegionCodes.Normalize(PreferredRegionPlugin.PreferredRegionCode.Value);
if (!RegionCodes.IsValid(text))
{
return true;
}
if (!NavGuard.TryBegin())
{
return false;
}
DataDirector.instance.networkRegion = text;
Debug.Log((object)("[PreferredRegion] Public pressed -> using saved '" + text + "'."));
MenuManager.instance.PageCloseAll();
if (PreferredRegionPlugin.JumpStraightToServerList.Value)
{
MenuManager.instance.PageOpen((MenuPageIndex)14, false);
}
else
{
MenuManager.instance.PageOpen((MenuPageIndex)16, false);
}
return false;
}
}
[HarmonyPatch(typeof(MenuPageMain), "ButtonEventHostGame")]
internal static class Patch_HostButton_Shortcut
{
private static bool Prefix()
{
if (!PreferredRegionPlugin.Enabled.Value)
{
return true;
}
string text = RegionCodes.Normalize(PreferredRegionPlugin.PreferredRegionCode.Value);
if (!RegionCodes.IsValid(text))
{
return true;
}
if (!NavGuard.TryBegin())
{
return false;
}
DataDirector.instance.networkRegion = text;
SemiFunc.MainMenuSetMultiplayer();
Debug.Log((object)("[PreferredRegion] Host pressed -> using saved '" + text + "'."));
MenuManager.instance.PageCloseAll();
MenuManager.instance.PageOpen((MenuPageIndex)11, false);
return false;
}
}
[HarmonyPatch(typeof(MenuPageRegions), "Start")]
internal static class Patch_RegionsStart_AutoPick
{
private static bool Prefix(MenuPageRegions __instance)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Invalid comparison between Unknown and I4
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Invalid comparison between Unknown and I4
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Invalid comparison between Unknown and I4
if (!PreferredRegionPlugin.Enabled.Value)
{
return true;
}
string text = RegionCodes.Normalize(PreferredRegionPlugin.PreferredRegionCode.Value);
if (!RegionCodes.IsValid(text))
{
return true;
}
if ((int)__instance.type != 1 && (int)__instance.type > 0)
{
return true;
}
if (!NavGuard.TryBegin())
{
return false;
}
DataDirector.instance.networkRegion = text;
Debug.Log((object)$"[PreferredRegion] Regions page opened ({__instance.type}) -> auto-picking '{text}'.");
MenuManager.instance.PageCloseAll();
if ((int)__instance.type == 0)
{
SemiFunc.MainMenuSetMultiplayer();
MenuManager.instance.PageOpen((MenuPageIndex)11, false);
}
else if (PreferredRegionPlugin.JumpStraightToServerList.Value)
{
MenuManager.instance.PageOpen((MenuPageIndex)14, false);
}
else
{
MenuManager.instance.PageOpen((MenuPageIndex)16, false);
}
return false;
}
}
[HarmonyPatch(typeof(MenuPageRegions), "PickRegion")]
internal static class Patch_RegionsPick_Save
{
private static void Prefix(ref string _region)
{
PreferredRegionPlugin.SaveRegionToConfig(_region);
}
}
namespace AutoRegion
{
[BepInPlugin("Omniscye.AutoRegion", "AutoRegion", "1.0")]
public class AutoRegion : BaseUnityPlugin
{
internal static AutoRegion Instance { get; private set; }
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
private void Awake()
{
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Patch();
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
}
internal void Patch()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_0026: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void Update()
{
}
}
}