From 07a262acc1541b1f7bfb251cb190b1b5aa5e6dcd Mon Sep 17 00:00:00 2001 From: DragonFire47 <46509577+DragonFire47@users.noreply.github.com> Date: Mon, 7 Feb 2022 12:47:45 -0800 Subject: [PATCH] -Added ModdedLobbyTag patch, to show which lobbies have mods. -Credit for this patch goes to myself and Badryuner --- PulsarModLoader/Patches/ModdedLobbyTag.cs | 43 +++++++++++++++++++++++ PulsarModLoader/PulsarModLoader.csproj | 1 + 2 files changed, 44 insertions(+) create mode 100644 PulsarModLoader/Patches/ModdedLobbyTag.cs diff --git a/PulsarModLoader/Patches/ModdedLobbyTag.cs b/PulsarModLoader/Patches/ModdedLobbyTag.cs new file mode 100644 index 0000000..e20345f --- /dev/null +++ b/PulsarModLoader/Patches/ModdedLobbyTag.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using static System.Reflection.Emit.OpCodes; +using HarmonyLib; +using static PulsarModLoader.Patches.HarmonyHelpers; + +namespace PulsarModLoader.Patches +{ + [HarmonyPatch(typeof(PLUIPlayMenu), "Update")] + class ModdedLobbyTag + { + static IEnumerable Transpiler(IEnumerable instructions) + { + List targetSequence = new List() + { + new CodeInstruction(Ldfld), + new CodeInstruction(Ldsfld), + new CodeInstruction(Ldloc_S), + new CodeInstruction(Callvirt), + new CodeInstruction(Callvirt, AccessTools.Method(typeof(PLReadableStringManager), "GetFormattedResultFromInputString")), + new CodeInstruction(Callvirt, AccessTools.Method(typeof(UnityEngine.UI.Text), "set_text")) + }; + + List injectedSequence = new List() + { + new CodeInstruction(Call, AccessTools.Method(typeof(ModdedLobbyTag), "PatchMethod")) + }; + return PatchBySequence(instructions, targetSequence, injectedSequence, patchMode: PatchMode.REPLACE, checkMode: CheckMode.NONNULL); + } + static void PatchMethod(PLUIPlayMenu.UIJoinGameElement jge) + { + if (jge == null) + return; + + string formattedResultInputString = PLReadableStringManager.Instance.GetFormattedResultFromInputString(jge.Room.Name); + + if (jge.Room.CustomProperties.TryGetValue("isModded", out object _)) + { + jge.GameName.text = "M " + formattedResultInputString; + } + else jge.GameName.text = formattedResultInputString; + } + } +} diff --git a/PulsarModLoader/PulsarModLoader.csproj b/PulsarModLoader/PulsarModLoader.csproj index 969d7f6..134394f 100644 --- a/PulsarModLoader/PulsarModLoader.csproj +++ b/PulsarModLoader/PulsarModLoader.csproj @@ -204,6 +204,7 @@ +