using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Photon.Pun;
using UnityEngine;
using Zorro.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PhotonRedirector")]
[assembly: AssemblyDescription("Emulate Photon to use custom Photon servers.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Kirigiri")]
[assembly: AssemblyProduct("PhotonRedirector")]
[assembly: AssemblyCopyright("Kirigiri © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("be8d4052-15e4-4cc0-8481-034b8dd0e20d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PhotonRedirector;
[BepInPlugin("kirigiri.peak.photonredirector", "Photon Redirector", "1.0.0.0")]
public class PhotonRedirector : BaseUnityPlugin
{
[HarmonyPatch(typeof(NetworkConnector), "ConnectToPhoton")]
public class PhotonConnectOverridePatch
{
[HarmonyPrefix]
public static bool Prefix()
{
try
{
BuildVersion val = default(BuildVersion);
((BuildVersion)(ref val))..ctor(Application.version);
PhotonNetwork.AutomaticallySyncScene = true;
PhotonNetwork.GameVersion = ((object)(BuildVersion)(ref val)).ToString();
ServerSettings val2 = Object.FindObjectOfType<ServerSettings>() ?? Resources.Load<ServerSettings>("PhotonServerSettings");
if ((Object)(object)val2 != (Object)null)
{
val2.AppSettings.AppIdRealtime = AppIdRealtime;
val2.AppSettings.AppIdVoice = AppIdVoice;
val2.AppSettings.AppVersion = ((BuildVersion)(ref val)).ToMatchmaking();
PhotonNetwork.ConnectUsingSettings();
Debug.Log((object)("[PhotonRedirector] Connected to Photon with AppIdRealtime=" + AppIdRealtime + ", AppIdVoice=" + AppIdVoice));
Debug.Log((object)("[PhotonRedirector] Using app version: " + ((BuildVersion)(ref val)).ToMatchmaking()));
}
else
{
Debug.LogError((object)"[PhotonRedirector] Failed to find ServerSettings. Cannot connect to Photon.");
}
}
catch (Exception ex)
{
Debug.LogError((object)("[PhotonRedirector] Exception in ConnectToPhoton override: " + ex));
}
return false;
}
}
private const string PhotonConfigFile = "PhotonRedirector.txt";
public static string AppIdRealtime { get; private set; } = "2be03cc8-3633-4033-a22e-7ef1c243b1fd";
public static string AppIdVoice { get; private set; } = "ba60e90a-af6f-4965-80cf-ff783c91c992";
private void Awake()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
((BaseUnityPlugin)this).Logger.LogInfo((object)"Photon Redirector has loaded!");
LoadPhotonAppIds();
new Harmony("kirigiri.peak.photonredirector").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Made with <3 By Kirigiri");
}
private void LoadPhotonAppIds()
{
string text = Path.Combine(Paths.ConfigPath, "PhotonRedirector.txt");
if (!File.Exists(text))
{
File.WriteAllLines(text, new string[2] { "AppIdRealtime=2be03cc8-3633-4033-a22e-7ef1c243b1fd", "AppIdVoice=ba60e90a-af6f-4965-80cf-ff783c91c992" });
((BaseUnityPlugin)this).Logger.LogWarning((object)("PhotonRedirector.txt not found. Created default at: " + text));
return;
}
string[] array = File.ReadAllLines(text);
foreach (string text2 in array)
{
if (text2.StartsWith("AppIdRealtime="))
{
AppIdRealtime = text2.Substring("AppIdRealtime=".Length).Trim();
}
else if (text2.StartsWith("AppIdVoice="))
{
AppIdVoice = text2.Substring("AppIdVoice=".Length).Trim();
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded Photon AppIds: Realtime=" + AppIdRealtime + ", Voice=" + AppIdVoice));
}
}