Files
MMOKitchen/Patches/SteamPlatformPatch.cs
T

48 lines
1.7 KiB
C#
Raw Normal View History

2024-04-01 08:12:01 +11:00
using HarmonyLib;
using System;
2024-08-10 05:00:57 +10:00
using System.Collections.Generic;
2024-04-01 08:12:01 +11:00
using System.Reflection;
2024-08-10 05:00:57 +10:00
using System.Reflection.Emit;
2025-09-25 22:28:35 +10:00
using UnityEngine;
using SteamNetworkService = Kitchen.NetworkSupport.SteamNetworkService;
2024-04-01 08:12:01 +11:00
namespace MMOKitchen.Patches
{
/*
* This patch is used to change how many players can join the lobby using Steam.
*/
2025-09-25 22:28:35 +10:00
[HarmonyPatch(typeof(SteamNetworkService))]
2024-04-01 08:12:01 +11:00
public class SteamPlatformPatch
2025-09-25 22:28:35 +10:00
{
2024-08-10 05:00:57 +10:00
private static MethodBase TargetMethod()
2024-04-01 08:12:01 +11:00
{
2025-09-25 22:28:35 +10:00
Type type = AccessTools.FirstInner(typeof(SteamNetworkService), t => t.Name.Contains("<CreateNewLobby>d__31"));
2024-08-10 05:00:57 +10:00
return AccessTools.FirstMethod(type, method => method.Name.Contains("MoveNext"));
}
2025-09-25 22:28:35 +10:00
2024-08-10 05:00:57 +10:00
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
CodeMatcher matcher = new(instructions);
2025-09-25 22:28:35 +10:00
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))
2024-08-10 05:00:57 +10:00
.Set(OpCodes.Ldc_I4, Mod.MaxPlayers);
return matcher.InstructionEnumeration();
2024-04-01 08:12:01 +11:00
}
}
}