Internals rewritten. PHoton config can now be fetched from the server, and if it fails, fallback to the local configuration.

This commit is contained in:
2025-08-16 21:04:26 -04:00
parent 8ca37170e4
commit 087d9a900e
20 changed files with 393 additions and 234 deletions

View File

@@ -0,0 +1,67 @@
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<PhotonConfigDTO>(HTTPMethods.Get, RecNet.Service.API, "/api/undead/v1/photon", ApplyPhotonConfig, OnServerConfigFailed);
}
}