mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
using System;
|
|
using HarmonyLib;
|
|
|
|
internal static class WebSocketRedirectPatches
|
|
{
|
|
internal static void Apply(Harmony harmony)
|
|
{
|
|
var type = AccessTools.TypeByName("BestHTTP.WebSocket.WebSocket");
|
|
int count = 0;
|
|
if (type != null)
|
|
foreach (var constructor in AccessTools.GetDeclaredConstructors(type))
|
|
{
|
|
var parameters = constructor.GetParameters();
|
|
if (parameters.Length == 0 || parameters[0].ParameterType != typeof(Il2CppSystem.Uri)) continue;
|
|
harmony.Patch(constructor, prefix: new HarmonyMethod(typeof(WebSocketRedirectPatches), nameof(Prefix)));
|
|
count++;
|
|
}
|
|
RadicadeEacBypassPlugin.LogSource.LogInfo("[Realtime] WebSocket URI hooks installed: " + count);
|
|
}
|
|
private static void Prefix(ref Il2CppSystem.Uri __0)
|
|
{
|
|
if (__0 == null) return;
|
|
var url = NameserverRedirect.RewriteWebSocket(__0.ToString(), RadicadeEacBypassPlugin.ServerUrl.Value);
|
|
if (HubSocketAuth.IsServer(url) && NameserverRedirect.IsHubUrl(url))
|
|
{
|
|
url = NameserverRedirect.EnsureHubToken(url, HubSocketAuth.Token);
|
|
Diag.Trace("[Realtime] Hub socket constructed; token=" +
|
|
(NameserverRedirect.HasHubToken(url) ? "present" : "missing"));
|
|
}
|
|
__0 = new Il2CppSystem.Uri(url);
|
|
}
|
|
}
|