using System; using BestHTTP; using Il2CppInterop.Runtime; using undead_universal_patch_il2cpp.Core.Config; using undead_universal_patch_il2cpp.Patches.Photon; using UnityEngine; namespace undead_universal_patch_il2cpp.Core.Content.CustomRecNet.CustomPhoton; public class PhotonConfigDTO { public bool Logging { get; set; } public string AppID { get; set; } public string VoiceAppID { get; set; } public bool SelfHosted { get; set; } public string ServerAddress { get; set; } public int ServerPort { get; set; } public byte ConnectionProtocol { get; set; } } public class CustomPhoton : MonoBehaviour { public static bool ServerConfigFailed { get; set; } = false; public void Start() { RecNetInteractions.postLocalAccountActions.Add(DownloadServerConfig); } void OnServerConfigFailed(HTTPResponse res) { ServerConfigFailed = true; if (PhotonConfig.PatchPhotonIds.Value) { UniversalPatchPlugin.Log.LogInfo("Attempting Photon patch from local configuration"); PhotonPatch.Patch(new PhotonConfigDTO { Logging = PhotonConfig.PunLogging.Value, AppID = PhotonConfig.AppID.Value, VoiceAppID = PhotonConfig.VoiceAppID.Value, SelfHosted = PhotonConfig.SelfHosted.Value, ServerAddress = PhotonConfig.ServerAddress.Value, ServerPort = PhotonConfig.ServerPort.Value, ConnectionProtocol = PhotonConfig.ConnectionProtocol.Value }); } } void ApplyPhotonConfig(HTTPResponse res, PhotonConfigDTO photonConfig) { if (!ServerPatchesConfig.CustomPhoton.Value) return; try { UniversalPatchPlugin.Log.LogInfo("Attempting Photon patch from server configuration"); PhotonPatch.Patch(photonConfig); } catch (Exception err) { UniversalPatchPlugin.Log.LogError($"Failed to apply Photon configuration from server: {err}"); OnServerConfigFailed(res); } } void DownloadServerConfig() { RecNetInteractions.SendRequest(HTTPMethods.Get, RecNet.Service.API, "/api/undead/v1/photon", ApplyPhotonConfig, OnServerConfigFailed); } }