Skip to content

Commit

Permalink
patch max players in lobby
Browse files Browse the repository at this point in the history
  • Loading branch information
kermeow committed Oct 29, 2023
1 parent 54912cc commit ca86416
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
1 change: 1 addition & 0 deletions BigLobby.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<Version>1.0.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);Harmony003</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
42 changes: 42 additions & 0 deletions Patches/LobbySize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using HarmonyLib;
using Steamworks;
using Steamworks.Data;
using UnityEngine;

namespace BigLobby.Patches
{
[HarmonyPatch(typeof(SteamMatchmaking))]
internal class SteamLobbySize
{
[HarmonyPatch(nameof(SteamMatchmaking.CreateLobbyAsync))]
[HarmonyPrefix]
public static void SetMaxMembers(ref int maxMembers) {
maxMembers = Plugin.MaxPlayers;
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
internal class LobbyJoinable {
[HarmonyPatch(nameof(GameNetworkManager.LobbyDataIsJoinable))]
[HarmonyPrefix]
public static bool SkipLobbySizeCheck(ref GameNetworkManager __instance, ref bool __result, Lobby lobby) {
string data = lobby.GetData("vers");
if (data != __instance.gameVersionNum.ToString())
{
Debug.Log($"Lobby join denied! Attempted to join vers.{data} lobby id: {lobby.Id}");
UnityEngine.Object.FindObjectOfType<MenuManager>().SetLoadingScreen(isLoading: false, RoomEnter.DoesntExist, $"The server host is playing on version {data} while you are on version {__instance.gameVersionNum}.");
__result = false;
return false;
}
if (lobby.GetData("joinable") == "false")
{
Debug.Log("Lobby join denied! Host lobby is not joinable");
UnityEngine.Object.FindObjectOfType<MenuManager>().SetLoadingScreen(isLoading: false, RoomEnter.DoesntExist, "The server host has already landed their ship, or they are still loading in.");
__result = false;
return false;
}
// Lobby member count check is skipped here, see original method
__result = true;
return false;
}
}
}
13 changes: 0 additions & 13 deletions Patches/SteamMatchmaking.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public class Plugin : BaseUnityPlugin
{
public static int MaxPlayers = 8;

private Harmony harmony;
private Harmony _harmony;
private void Awake()
{
Logger.LogInfo($"{PluginInfo.PLUGIN_GUID} loaded");

harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
}
}
}

0 comments on commit ca86416

Please sign in to comment.