using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Realtime;
[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("BepInEx-Photon")]
[assembly: AssemblyConfiguration("release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d1ee8e3edec11c4588de18c4c49463e9be46a075")]
[assembly: AssemblyProduct("BepInEx-Photon")]
[assembly: AssemblyTitle("BepInEx-Photon")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PhotonAppIDRedirector;
[BepInPlugin("photon-redirect", "Photon Redirector", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
public static string PhotonAppid { get; private set; }
public static string PhotonRegion { get; private set; }
private void Awake()
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
PhotonAppid = ((BaseUnityPlugin)this).Config.Bind<string>("General", "PhotonAppID", "PASTE_HERE", "Set your Photon App ID here.").Value;
PhotonRegion = ((BaseUnityPlugin)this).Config.Bind<string>("General", "PhotonRegion", "", "Set your Photon region here (e.g., us, eu, tr), see https://doc.photonengine.com/pun/current/connection-and-authentication/regions#photon-cloud-for-gaming for more.").Value;
if (string.IsNullOrWhiteSpace(PhotonAppid) || PhotonAppid == "PASTE_HERE")
{
((BaseUnityPlugin)this).Logger.LogError((object)"PhotonAppID is missing or invalid!!");
((BaseUnityPlugin)this).Logger.LogInfo((object)"Skipping Redirection.");
return;
}
new Harmony("auth.patch").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Loaded!");
((BaseUnityPlugin)this).Logger.LogInfo((object)("Using AppID: " + PhotonAppid));
if (string.IsNullOrWhiteSpace(PhotonRegion))
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"PhotonRegion is not set. Using default region.");
}
else
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Using Region: " + PhotonRegion));
}
}
}
[HarmonyPatch(typeof(LoadBalancingClient), "ConnectToRegionMaster")]
public class RegionPatch
{
private static bool Prefix(LoadBalancingClient __instance, ref string region)
{
if (!string.IsNullOrWhiteSpace(Plugin.PhotonRegion))
{
Logger.CreateLogSource("Photon Redirector").LogWarning((object)("Overriding region from '" + region + "' to '" + Plugin.PhotonRegion + "'"));
region = Plugin.PhotonRegion;
}
return true;
}
}
[HarmonyPatch(typeof(LoadBalancingPeer), "OpAuthenticate")]
public class PhotonPatch
{
private static void Prefix(ref string appId, ref AuthenticationValues authValues)
{
appId = Plugin.PhotonAppid;
Logger.CreateLogSource("Photon Redirector").LogInfo((object)"Redirecting Photon Traffic");
if (authValues != null)
{
authValues.AuthType = (CustomAuthenticationType)255;
}
}
}