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 Photon.Pun;
using PunFixedRegion.Common;
using PunFixedRegion.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PunFixedRegion")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+65f518858a81df5677bcf3f1ad4f084636784e51")]
[assembly: AssemblyProduct("PunFixedRegion")]
[assembly: AssemblyTitle("PunFixedRegion")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace PunFixedRegion
{
[BepInPlugin("PunFixedRegion", "PunFixedRegion", "1.1.2")]
public class PunFixedRegionPlugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<EPhotonRegion> Region;
private readonly Harmony _harmony = new Harmony("PunFixedRegion");
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin PunFixedRegion is loaded!");
SetupConfiguration();
_harmony.PatchAll(typeof(SteamManagerPatch));
Logger.LogInfo((object)"SteamManagerPatch is patched!");
}
private void SetupConfiguration()
{
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Toggle");
Region = ((BaseUnityPlugin)this).Config.Bind<EPhotonRegion>("General", "Region", EPhotonRegion.BestServer, "https://doc.photonengine.com/pun/current/connection-and-authentication/regions");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "PunFixedRegion";
public const string PLUGIN_NAME = "PunFixedRegion";
public const string PLUGIN_VERSION = "1.1.2";
}
}
namespace PunFixedRegion.Patches
{
internal class SteamManagerPatch
{
[HarmonyPatch(typeof(SteamManager), "HostLobby")]
private static bool Prefix()
{
if (!PunFixedRegionPlugin.Enabled.Value)
{
return true;
}
string fixedRegion = PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion;
PunFixedRegionPlugin.Logger.LogInfo((object)"SteamManager.HostLobby called!");
PunFixedRegionPlugin.Logger.LogInfo((object)$"Selected Region: \"{PunFixedRegionPlugin.Region.Value}\"");
PunFixedRegionPlugin.Logger.LogInfo((object)("Current FixedRegion: \"" + fixedRegion + "\""));
if (!PhotonRegion.TryGetValue(PunFixedRegionPlugin.Region.Value, out var value))
{
value = PhotonRegion.BestServer;
}
if (fixedRegion == value.Value)
{
PunFixedRegionPlugin.Logger.LogInfo((object)("Photon Fixed Region is already set to: \"" + value.Value + "\""));
return true;
}
PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = value.Value;
PunFixedRegionPlugin.Logger.LogInfo((object)("Photon Fixed Region changed!: \"" + fixedRegion + "\" -> \"" + value.Value + "\""));
return true;
}
}
}
namespace PunFixedRegion.Common
{
public enum EPhotonRegion
{
BestServer,
Asia,
Australia,
Europe,
Japan,
SouthAfrica,
SouthAmerica,
USA_East,
USA_West
}
internal class PhotonRegion
{
private static readonly Dictionary<EPhotonRegion, PhotonRegion> All = new Dictionary<EPhotonRegion, PhotonRegion>();
internal static readonly PhotonRegion BestServer = new PhotonRegion(EPhotonRegion.BestServer, "");
internal static readonly PhotonRegion Asia = new PhotonRegion(EPhotonRegion.Asia, "asia");
internal static readonly PhotonRegion Australia = new PhotonRegion(EPhotonRegion.Australia, "au");
internal static readonly PhotonRegion Europe = new PhotonRegion(EPhotonRegion.Europe, "eu");
internal static readonly PhotonRegion Japan = new PhotonRegion(EPhotonRegion.Japan, "jp");
internal static readonly PhotonRegion SouthAfrica = new PhotonRegion(EPhotonRegion.SouthAfrica, "za");
internal static readonly PhotonRegion SouthAmerica = new PhotonRegion(EPhotonRegion.SouthAmerica, "sa");
internal static readonly PhotonRegion USA_East = new PhotonRegion(EPhotonRegion.USA_East, "us");
internal static readonly PhotonRegion USA_West = new PhotonRegion(EPhotonRegion.USA_West, "usw");
public EPhotonRegion Key { get; }
public string Value { get; }
private PhotonRegion(EPhotonRegion key, string value)
{
Key = key;
Value = value;
All.TryAdd(key, this);
}
internal static bool TryGetValue(EPhotonRegion region, out PhotonRegion value)
{
return All.TryGetValue(region, out value);
}
}
}