This commit is contained in:
Lachlan Leone
2025-09-25 22:28:35 +10:00
parent 3c7f88f427
commit d196cbcf9f
4 changed files with 28 additions and 8 deletions
+21 -7
View File
@@ -1,30 +1,44 @@
using HarmonyLib;
using Kitchen.NetworkSupport;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;
using SteamNetworkService = Kitchen.NetworkSupport.SteamNetworkService;
namespace MMOKitchen.Patches
{
/*
* This patch is used to change how many players can join the lobby using Steam.
*/
[HarmonyPatch(typeof(SteamPlatform))]
[HarmonyPatch(typeof(SteamNetworkService))]
public class SteamPlatformPatch
{
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.FirstInner(typeof(SteamPlatform), t => t.Name.Contains("<CreateNewLobby>d__26"));
Type type = AccessTools.FirstInner(typeof(SteamNetworkService), t => t.Name.Contains("<CreateNewLobby>d__31"));
return AccessTools.FirstMethod(type, method => method.Name.Contains("MoveNext"));
}
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
CodeMatcher matcher = new(instructions);
matcher.MatchForward(false, new CodeMatch(OpCodes.Ldc_I4_2), new CodeMatch(OpCodes.Bne_Un), new CodeMatch(OpCodes.Ldc_I4_4))
.Advance(2)
foreach (var instruction in matcher.InstructionEnumeration())
{
if (instruction.operand != null)
{
Debug.Log($"{instruction.opcode} : {instruction.operand}");
}
else
{
Debug.Log($"{instruction.opcode}");
}
}
matcher.MatchForward(false, new CodeMatch(OpCodes.Ldc_I4_4), new CodeMatch(OpCodes.Call), new CodeMatch(OpCodes.Callvirt), new CodeMatch(OpCodes.Stloc_S), new CodeMatch(OpCodes.Ldloca_S), new CodeMatch(OpCodes.Call), new CodeMatch(OpCodes.Brtrue))
.Set(OpCodes.Ldc_I4, Mod.MaxPlayers);
return matcher.InstructionEnumeration();