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,51 @@
using UnityEngine;
using System.Collections.Generic;
using System.Collections.Concurrent;
using Mapster;
using System;
using System.Linq;
using BestHTTP;
namespace undead_universal_patch_il2cpp.Core.Content.CustomRecNet.CustomEmotes;
public class EmoteConfigDTO
{
public string UniqueName { get; set; }
public string NewText { get; set; }
public string RoomChatText { get; set; }
public string FacialExpression { get; set; }
public bool ForceEmoteBubble { get; set; }
public bool OnlyBroadcastToTeam { get; set; }
}
public class CustomEmotes : MonoBehaviour
{
public void Start()
{
RecNetInteractions.postLocalAccountActions.Add(DownloadCustomEmotes);
}
void Patch(HTTPResponse _res, List<EmoteConfigDTO> emotes)
{
UniversalPatchPlugin.Log.LogInfo("Setting new emotes");
var internalEmotes = RecRoom.AGUI.Expresso.ContextualEmotesSettings.ConfigAsset.Emotes.ToList();
foreach (var emote in emotes)
{
var internalEmote = internalEmotes.Find(match => match.emoteUniqueName == emote.UniqueName);
if (internalEmote != null)
{
emote.Adapt(internalEmote);
}
}
Util.ConditionalDebug($"{emotes.Count} new emote configurations");
}
void DownloadCustomEmotes()
{
RecNetInteractions.SendRequest<List<EmoteConfigDTO>>(HTTPMethods.Get, RecNet.Service.API, "/api/undead/v1/emotes", Patch);
}
}

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);
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using BestHTTP;
using Il2CppInterop.Runtime;
using RecNet;
namespace undead_universal_patch_il2cpp.Core.Content.CustomRecNet;
public class RecNetInteractions
{
public static int AccountId { get; set; }
public static string AccessToken { get; set; }
public static List<Action> postNameServerActions = [];
public static List<Action> postAuthenticationActions = [];
public static List<Action> postLocalAccountActions = [];
public static Il2CppSystem.Uri CreateServiceUri(Service service, string pathAndQuery)
{
Il2CppSystem.Uri uri = RecNet.Core.GetServiceUri(service) ?? throw new Exception("Service is not available");
var newUri = new Il2CppSystem.Uri(uri, pathAndQuery);
return newUri;
}
public static bool HasNameserverConnected()
{
return RecNet.Core.ServiceUris.Count > 1;
}
public static void SendRequest<T>(HTTPMethods method, Service service, string requestUri, Action<HTTPResponse, T> reqFinished, Action<HTTPResponse>? reqFailed = null)
{
var res = RecNet.Core.SendRequest(method, service, requestUri);
res.Then(DelegateSupport.ConvertDelegate<Il2CppSystem.Action<HTTPResponse>>((HTTPResponse res) =>
{
try
{
var data = JsonSerializer.Deserialize<T>(res.DataAsText);
reqFinished(res, data);
}
catch (Exception ex)
{
UniversalPatchPlugin.Log.LogError($"'{requestUri}' failed\n{ex}");
if (reqFailed != null) reqFailed(res);
}
}));
}
}