using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using HarmonyLib;
namespace undead_universal_patch.Patches
{
[HarmonyPatch]
class LWebSocket
{
static string TargetTypeName = "WebSocketSharp.WebSocket";
static string Description = "Legacy WebSocket (websocket-sharp) URL rewrite patch";
static Type webSocketType = AccessTools.TypeByName(TargetTypeName);
static bool Prepare()
{
if (GenericConfig.IsNameserver.Value) return false;
if (webSocketType == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The type this patch targets was not found.");
return false;
}
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
static MethodBase TargetMethod()
{
return AccessTools.Constructor(webSocketType, [ typeof(string), typeof(string[]) ]);
}
[HarmonyPrefix]
static void Prefix(ref string url)
{
if (PhotonConfig.PatchEvent.Value == "SocketConnect" && PhotonConfig.PatchPhotonIds.Value) Photon.Patch();
url = PatchUtils.RewriteUrlForSocket(url).ToString();
}
}
}