2024-05-21 19:10:17 +01:00
|
|
|
using SPT.Reflection.Patching;
|
|
|
|
using SPT.Reflection.Utils;
|
2023-03-03 18:52:31 +00:00
|
|
|
using System;
|
|
|
|
using System.Reflection;
|
|
|
|
|
2024-05-21 19:10:17 +01:00
|
|
|
namespace SPT.Core.Patches
|
2023-03-03 18:52:31 +00:00
|
|
|
{
|
|
|
|
public class WebSocketPatch : ModulePatch
|
|
|
|
{
|
|
|
|
protected override MethodBase GetTargetMethod()
|
|
|
|
{
|
2024-01-13 22:08:29 +00:00
|
|
|
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));
|
2023-03-03 18:52:31 +00:00
|
|
|
}
|
|
|
|
|
2024-01-13 22:08:29 +00:00
|
|
|
// This is a pass through postfix and behaves a little differently than usual
|
|
|
|
// https://harmony.pardeike.net/articles/patching-postfix.html#pass-through-postfixes
|
2023-03-03 18:52:31 +00:00
|
|
|
[PatchPostfix]
|
2024-01-13 22:08:29 +00:00
|
|
|
private static Uri PatchPostfix(Uri __result)
|
2023-03-03 18:52:31 +00:00
|
|
|
{
|
2024-01-13 22:08:29 +00:00
|
|
|
return new Uri(__result.ToString().Replace("wss:", "ws:"));
|
2023-03-03 18:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|