Newer
Older
undead-universal-patch-mono / Patches / OWebSocket.cs
@zombieb zombieb on 10 Jun 2024 1 KB Initial commit
using System;
using System.Reflection;
using HarmonyLib;

namespace undead_universal_patch.Patches
{
    [HarmonyPatch]
    class OWebSocket
    {
        static string TargetTypeName = "BestHTTP.WebSocket.IJADBHMBMPG";
        static string Description = "2017/mid-2018 WebSocket (non-signalr) URL rewrite patch";
        static readonly Type targetType = AccessTools.TypeByName(TargetTypeName);

        static bool Prepare()
        {
            if (GenericConfig.IsNameserver.Value) return false;
            if (targetType == null)
            {
                Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
                return false;
            }

            Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
            return true;
        }

        static MethodBase TargetMethod()
        {
            return AccessTools.Constructor(targetType, [ typeof(Uri) ]);
        }

        [HarmonyPrefix]
        static void Prefix(ref Uri CAGBGCGKOKD)
        {
            if (PhotonConfig.PatchEvent.Value == "SocketConnect" && PhotonConfig.PatchPhotonIds.Value) Photon.Patch();
            CAGBGCGKOKD = PatchUtils.RewriteUrlForSocket(CAGBGCGKOKD);
        }
    }
}