0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/SPT.Core/Patches/WebSocketPatch.cs
2024-05-21 19:10:17 +01:00

27 lines
1.0 KiB
C#

using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using System;
using System.Reflection;
namespace SPT.Core.Patches
{
public class WebSocketPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
var targetInterface = PatchConstants.EftTypes.SingleCustom(x => x == typeof(IConnectionHandler) && x.IsInterface);
var typeThatMatches = PatchConstants.EftTypes.SingleCustom(x => targetInterface.IsAssignableFrom(x) && x.IsAbstract && !x.IsInterface);
return typeThatMatches.GetMethods(BindingFlags.Public | BindingFlags.Instance).SingleCustom(x => x.ReturnType == typeof(Uri));
}
// This is a pass through postfix and behaves a little differently than usual
// https://harmony.pardeike.net/articles/patching-postfix.html#pass-through-postfixes
[PatchPostfix]
private static Uri PatchPostfix(Uri __result)
{
return new Uri(__result.ToString().Replace("wss:", "ws:"));
}
}
}