Skip to content

Commit

Permalink
Remove modded indicator from displayed lobby names, while retaining a…
Browse files Browse the repository at this point in the history
…s much data as possible
  • Loading branch information
legoandmars committed Feb 19, 2024
1 parent d8a0599 commit 618d6d4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions LobbyCompatibility/Enums/LobbyMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public static class LobbyMetadata
/// The required plugins checksum to filter against.
/// </summary>
public const string RequiredChecksum = "checksum";

/// <summary>
/// The prefix added before modded lobbies.
/// </summary>
public const string ModdedLobbyPrefix = "[MOD]";
}
28 changes: 26 additions & 2 deletions LobbyCompatibility/Patches/LoadLobbyListAndFilterTranspiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Reflection.Emit;
using HarmonyLib;
using LobbyCompatibility.Behaviours;
using LobbyCompatibility.Enums;
using Steamworks.Data;
using UnityEngine;

Expand Down Expand Up @@ -30,14 +31,27 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

var levelListContainerField =
AccessTools.Field(typeof(SteamLobbyManager), nameof(SteamLobbyManager.levelListContainer));
var initializeLobbySlotMethod =
var initializeLobbySlotMethod =
AccessTools.Method(typeof(LoadLobbyListAndFilterTranspiler), nameof(InitializeLobbySlot));


var lobbyGetDataMethod =
AccessTools.Method(typeof(Lobby), nameof(Lobby.GetData));
var replaceLobbyNameMethod =
AccessTools.Method(typeof(LoadLobbyListAndFilterTranspiler), nameof(ReplaceLobbyName));

// Does the following:
// - Calls ReplaceLobbyName(lobbyName) the line before lobbyName local variable is set
// - Adds dup before last componentInChildren line to keep componentInChildren value on the stack
// - Loads SteamLobbyManager.levelListContainer onto the stack
// - Calls InitializeLobbySlot(lobbySlot, levelListContainer)
return new CodeMatcher(instructions)
.MatchForward(false, new[] {
new CodeMatch(OpCodes.Ldstr, "name"),
new CodeMatch(OpCodes.Call, lobbyGetDataMethod) })
.ThrowIfNotMatch("Unable to find Lobby.GetData(name) line.")
.Advance(2)
.InsertAndAdvance(new[] {
new CodeInstruction(OpCodes.Call, replaceLobbyNameMethod)})
.MatchForward(false, new [] {
new CodeMatch(OpCodes.Ldloc_1),
new CodeMatch(OpCodes.Ldfld, currentLobbyListField),
Expand Down Expand Up @@ -66,4 +80,14 @@ private static void InitializeLobbySlot(LobbySlot lobbySlot, Transform levelList
// Set container parent for hover tooltip position math
moddedLobbySlot.SetParentContainer(levelListContainer.parent);
}

// Replace any modded text indicators as they're redundant
// This is run before the string is truncated to 40 characters
private static string ReplaceLobbyName(string lobbyName)
{
if (lobbyName.Length == 0)
return lobbyName;

return lobbyName.Replace(LobbyMetadata.ModdedLobbyPrefix, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static void Postfix(Result result, ref Lobby lobby)
if (pluginInfo.Any(plugin => plugin.CompatibilityLevel is CompatibilityLevel.ServerOnly
or CompatibilityLevel.Everyone or CompatibilityLevel.ClientOptional) &&
!lobby.GetData(LobbyMetadata.Name).ToLower().Contains("modded"))
lobby.SetData(LobbyMetadata.Name, "modded // " + lobby.GetData(LobbyMetadata.Name));
lobby.SetData(LobbyMetadata.Name, LobbyMetadata.ModdedLobbyPrefix + lobby.GetData(LobbyMetadata.Name));

// Check if there are any required plugins in the lobby
if (pluginInfo.Any(plugin => plugin.CompatibilityLevel == CompatibilityLevel.Everyone))
Expand Down

0 comments on commit 618d6d4

Please sign in to comment.