Skip to content

Commit

Permalink
-Added ModdedLobbyTag patch, to show which lobbies have mods.
Browse files Browse the repository at this point in the history
-Credit for this patch goes to myself and Badryuner
  • Loading branch information
Nagord committed Feb 7, 2022
1 parent f3e9299 commit 07a262a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions PulsarModLoader/Patches/ModdedLobbyTag.cs
Original file line number Diff line number Diff line change
@@ -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<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> targetSequence = new List<CodeInstruction>()
{
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<CodeInstruction> injectedSequence = new List<CodeInstruction>()
{
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 = "<size=20><color=yellow>M</color></size> " + formattedResultInputString;
}
else jge.GameName.text = formattedResultInputString;
}
}
}
1 change: 1 addition & 0 deletions PulsarModLoader/PulsarModLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
<Compile Include="Injections\LoggingInjections.cs" />
<Compile Include="Patches\DebugReadout.cs" />
<Compile Include="Patches\GameVersion.cs" />
<Compile Include="Patches\ModdedLobbyTag.cs" />
<Compile Include="Patches\PLGlobalStart.cs" />
<Compile Include="Patches\PhotonProperties.cs" />
<Compile Include="PMLConfig.cs" />
Expand Down

0 comments on commit 07a262a

Please sign in to comment.