Start working on http handshake support

This commit is contained in:
js6pak committed 2022-07-30 01:00:58 +02:00
1 parent ff7a80addf
commit 3579ecb89e
3 files changed
+76 -3

No files matched your search

+3 -1
View File
@@ -21,7 +21,7 @@ namespace Reactor.Networking
return _mapByNetId![netId];
}
internal static void Update()
internal static ISet<Mod> Update()
{
var i = (uint) 0;
@@ -37,6 +37,8 @@ namespace Reactor.Networking
_mapById = Current.ToDictionary(mod => mod.Id, mod => mod);
_mapByNetId = Current.ToDictionary(mod => mod.NetId, mod => mod);
return Current;
}
}
}
+2 -2
View File
@@ -165,7 +165,7 @@ namespace Reactor.Networking.Patches
public static void Postfix(ref Il2CppStructArray<byte> __result)
{
ModList.Update();
var mods = ModList.Update();
var handshake = new MessageWriter(1000);
@@ -173,7 +173,7 @@ namespace Reactor.Networking.Patches
ModdedHandshakeC2S.Serialize(
handshake,
ModList.Current!.Count
mods.Count
);
__result = handshake.ToByteArray(true);
+71
View File
@@ -0,0 +1,71 @@
using System;
using System.Linq;
using System.Text;
using HarmonyLib;
using UnhollowerBaseLib;
using UnityEngine.Networking;
namespace Reactor.Networking.Patches;
[HarmonyPatch]
internal static class HttpPatches
{
public const int Version = 1;
public static string BuildHeader()
{
var stringBuilder = new StringBuilder();
stringBuilder.Append(Version);
stringBuilder.Append(";");
var mods = ModList.Update().Where(m => m.Side == PluginSide.Both).OrderBy(m => m.Id, StringComparer.Ordinal).ToArray();
stringBuilder.Append(mods.Length);
foreach (var mod in mods)
{
stringBuilder.Append(";");
stringBuilder.Append(mod.Id);
stringBuilder.Append("=");
stringBuilder.Append(mod.Version);
}
return stringBuilder.ToString();
}
[HarmonyPatch(typeof(UnityWebRequest), nameof(UnityWebRequest.Get), typeof(string))]
[HarmonyPatch(typeof(UnityWebRequest), nameof(UnityWebRequest.Post), typeof(string), typeof(string))]
[HarmonyPatch(typeof(UnityWebRequest), nameof(UnityWebRequest.Put), typeof(string), typeof(Il2CppStructArray<byte>))]
[HarmonyPostfix]
public static void UnityWebRequestPatch(UnityWebRequest __result)
{
var path = __result.uri.AbsolutePath;
if (path == "/api/games")
{
__result.SetRequestHeader("Client-Mods", BuildHeader());
}
}
[HarmonyPatch(typeof(HttpMatchmakerManager._CoRequestGameList_d__7), nameof(HttpMatchmakerManager._CoRequestGameList_d__7.MoveNext))]
public static class CoRequestGameListPatch
{
public static void Prefix(HttpMatchmakerManager._CoRequestGameList_d__7 __instance)
{
if (__instance.__1__state == 2)
{
if (HttpUtils.IsSuccess(__instance._request_5__3.responseCode))
{
var responseHeader = __instance._request_5__3.GetResponseHeader("Client-Mods-Processed");
if (responseHeader == null)
{
AmongUsClient.Instance.LastDisconnectReason = DisconnectReasons.Custom;
AmongUsClient.Instance.LastCustomDisconnect = "This region doesn't support modded handshake.\nThe lobbies shown may not be compatible with your current mods.\nFor more info see https://reactor.gg/handshake";
DisconnectPopup.Instance.Show();
}
}
}
}
}
}