forked from zombieb/undead-universal-patch-il2cpp
67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
using System;
|
|
using BestHTTP;
|
|
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()
|
|
{
|
|
if (ServerPatchesConfig.CustomPhoton.Value) RecNetInteractions.postLocalAccountActions.Add(DownloadServerConfig);
|
|
else if (PhotonConfig.PatchPhotonIds.Value) LocalPatch();
|
|
}
|
|
|
|
void LocalPatch()
|
|
{
|
|
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 OnServerConfigFailed(HTTPResponse res)
|
|
{
|
|
ServerConfigFailed = true;
|
|
if (PhotonConfig.PatchPhotonIds.Value) LocalPatch();
|
|
}
|
|
void ApplyPhotonConfig(HTTPResponse res, PhotonConfigDTO photonConfig)
|
|
{
|
|
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<PhotonConfigDTO>(HTTPMethods.Get, RecNet.Service.API, "/api/undead/v1/photon", ApplyPhotonConfig, OnServerConfigFailed);
|
|
}
|
|
} |