Skip to content

Commit e9d0922

Browse files
Enable Workshop page button for Main Menu levels (v1.1.2.0)
* Prevent the Visit Workshop page button from being hidden when in the Choose Main Menu level display type. * Some commented out code added to handle future hiding of unused Leaderboards menu button for Main Menu levels.
1 parent fe197f3 commit e9d0922

File tree

7 files changed

+198
-2
lines changed

7 files changed

+198
-2
lines changed

Distance.LevelSelectAdditions/ConfigurationLogic.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ public bool EnableTheOtherSideSprintCampaign
127127

128128
public bool FixLevelSelectScrollBug => true;
129129

130+
public bool EnableChooseMainMenuVisitWorkshopButton => true;
131+
132+
public bool HideChooseMainMenuUnusedButtons => true;
133+
130134
#endregion
131135

132136
#region Helpers

Distance.LevelSelectAdditions/Distance.LevelSelectAdditions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\Initialize.cs" />
109109
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\OnLevelPlaylistMenuClickLoad.cs" />
110110
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\OnLevelPlaylistMenuClickSave.cs" />
111+
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\SetDisplayedInfoForSelectedLevel.cs" />
111112
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\SetupLevelPlaylistVisuals.cs" />
112113
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\Start.cs" />
113114
<Compile Include="Harmony\Assembly-CSharp\OptionsMenuLogic\GetSubmenus.cs" />

Distance.LevelSelectAdditions/Harmony/Assembly-CSharp/LevelSelectMenuLogic/Initialize.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ internal static void Prefix(LevelSelectMenuLogic __instance)
3434
__instance.searchInput_.OnSelect(false);
3535
}
3636
}
37+
38+
// Don't implement this until Playlist Mode is ready,
39+
// since we'll want to make the this visible for the "REMOVE LEVEL" button.
40+
/*if (Mod.Instance.Config.HideChooseMainMenuUnusedButtons)
41+
{
42+
// Keep the Playlist Mode button, since there are plans to restore that functionality for Choose Main Menu levels.
43+
bool isMainMenu = __instance.displayType_ == LevelSelectMenuAbstract.DisplayType.ChooseMainMenuLevel;
44+
__instance.showLeaderboardsButton_.SetActive(!isMainMenu);
45+
}*/
3746
}
3847
}
3948
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using HarmonyLib;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Reflection.Emit;
6+
7+
namespace Distance.LevelSelectAdditions.Harmony
8+
{
9+
/// <summary>
10+
/// Patch to make the Visit Workshop page button visible for the Choose Main Menu display type
11+
/// (when changing selection in the level select menu).
12+
/// </summary>
13+
[HarmonyPatch(typeof(LevelSelectMenuLogic), nameof(LevelSelectMenuLogic.SetDisplayedInfoForSelectedLevel))]
14+
internal static class LevelSelectMenuLogic__SetDisplayedInfoForSelectedLevel
15+
{
16+
[HarmonyTranspiler]
17+
internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
18+
{
19+
var codes = new List<CodeInstruction>(instructions);
20+
21+
Mod.Instance.Logger.Info("Transpiling...");
22+
// VISUAL:
23+
//if (this.displayType_ != LevelSelectMenuAbstract.DisplayType.ChooseMainMenuLevel && ...)
24+
// -to-
25+
//if (AllowMainMenuDisplayTypeForVisitWorkshop_(this) && ...)
26+
27+
for (int i = 3; i < codes.Count; i++)
28+
{
29+
if ((codes[i - 3].opcode == OpCodes.Ldarg_0) &&
30+
(codes[i - 2].opcode == OpCodes.Ldfld && ((FieldInfo)codes[i - 2].operand).Name == "displayType_") &&
31+
(codes[i - 1].opcode == OpCodes.Ldc_I4_2) && // (LevelSelectMenuAbstract.DisplayType.ChooseMainMenuLevel)
32+
(codes[i ].opcode == OpCodes.Beq))
33+
{
34+
Mod.Instance.Logger.Info($"ldfld displayType_ @ {i-2}");
35+
Mod.Instance.Logger.Info($"ldc.i4.2 @ {i-1}");
36+
37+
// After: ldarg.0
38+
// Replace: ldfld displayType_
39+
// Replace: ldc.i4.2
40+
// Replace: beq (preserve jump label)
41+
// With: call AllowMainMenuDisplayTypeForVisitWorkshop_
42+
// With: brfalse (preserve jump label)
43+
codes.RemoveRange(i - 2, 2);
44+
codes.InsertRange(i - 2, new CodeInstruction[]
45+
{
46+
new CodeInstruction(OpCodes.Call, typeof(LevelSelectMenuLogic__SetDisplayedInfoForSelectedLevel).GetMethod(nameof(AllowMainMenuDisplayTypeForVisitWorkshop_))),
47+
});
48+
i -= 1; // preserve i instruction offset
49+
50+
codes[i].opcode = OpCodes.Brfalse; // preserve jump operand, just change the opcode
51+
52+
break;
53+
}
54+
}
55+
56+
return codes.AsEnumerable();
57+
}
58+
59+
#region Helper Functions
60+
61+
public static bool AllowMainMenuDisplayTypeForVisitWorkshop_(LevelSelectMenuLogic levelSelectMenu)
62+
{
63+
if (Mod.Instance.Config.EnableChooseMainMenuVisitWorkshopButton)
64+
{
65+
return true;
66+
}
67+
return levelSelectMenu.displayType_ != LevelSelectMenuAbstract.DisplayType.ChooseMainMenuLevel;
68+
}
69+
70+
#endregion
71+
}
72+
}

Distance.LevelSelectAdditions/Harmony/Assembly-CSharp/LevelSelectMenuLogic/SetupLevelPlaylistVisuals.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
using Distance.LevelSelectAdditions.Extensions;
22
using Distance.LevelSelectAdditions.Scripts;
33
using HarmonyLib;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Reflection.Emit;
48

59
namespace Distance.LevelSelectAdditions.Harmony
610
{
711
/// <summary>
812
/// Patch to fix "QUICK PLAYLIST..." text overwriting playlist name after adding a level (even in vanilla).
13+
/// <para/>
14+
/// Also includes patch to make the Visit Workshop page button visible for the Choose Main Menu display type
15+
/// (when first opening the level select menu).
916
/// </summary>
1017
[HarmonyPatch(typeof(LevelSelectMenuLogic), nameof(LevelSelectMenuLogic.SetupLevelPlaylistVisuals))]
1118
internal static class LevelSelectMenuLogic__SetupLevelPlaylistVisuals
@@ -21,5 +28,107 @@ internal static void Postfix(LevelSelectMenuLogic __instance)
2128
__instance.quickPlaylistLabel_.text = __instance.tempPlaylist_.Name_;
2229
}
2330
}
31+
32+
[HarmonyTranspiler]
33+
internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
34+
{
35+
var codes = new List<CodeInstruction>(instructions);
36+
37+
Mod.Instance.Logger.Info("Transpiling...");
38+
// VISUAL:
39+
//if (... && this.displayType_ != LevelSelectMenuAbstract.DisplayType.ChooseMainMenuLevel && ...)
40+
// -to-
41+
//if (... && AllowMainMenuDisplayTypeForVisitWorkshop_(this) && ...)
42+
43+
for (int i = 3; i < codes.Count; i++)
44+
{
45+
if ((codes[i - 3].opcode == OpCodes.Ldarg_0) &&
46+
(codes[i - 2].opcode == OpCodes.Ldfld && ((FieldInfo)codes[i - 2].operand).Name == "displayType_") &&
47+
(codes[i - 1].opcode == OpCodes.Ldc_I4_2) && // (LevelSelectMenuAbstract.DisplayType.ChooseMainMenuLevel)
48+
(codes[i].opcode == OpCodes.Beq))
49+
{
50+
Mod.Instance.Logger.Info($"ldfld displayType_ @ {i-2}");
51+
Mod.Instance.Logger.Info($"ldc.i4.2 @ {i-1}");
52+
53+
// After: ldarg.0
54+
// Replace: ldfld displayType_
55+
// Replace: ldc.i4.2
56+
// Replace: beq (preserve jump label)
57+
// With: call AllowMainMenuDisplayTypeForVisitWorkshop_
58+
// With: brfalse (preserve jump label)
59+
codes.RemoveRange(i - 2, 2);
60+
codes.InsertRange(i - 2, new CodeInstruction[]
61+
{
62+
new CodeInstruction(OpCodes.Call, typeof(LevelSelectMenuLogic__SetupLevelPlaylistVisuals).GetMethod(nameof(AllowMainMenuDisplayTypeForVisitWorkshop_))),
63+
});
64+
i -= 1; // preserve i instruction offset
65+
66+
codes[i].opcode = OpCodes.Brfalse; // preserve jump operand, just change the opcode
67+
68+
break;
69+
}
70+
}
71+
72+
/*Mod.Instance.Logger.Info("Transpiling (2/2)...");
73+
// VISUAL:
74+
//bool active = playlist_.Count > 0;
75+
//this.startPlaylistButton_.SetActive(active);
76+
// -to-
77+
//bool active = playlist_.Count > 0;
78+
//SetStartPlaylistButtonActive_(this, active);
79+
80+
for (int i = 3; i < codes.Count; i++)
81+
{
82+
if ((codes[i - 3].opcode == OpCodes.Ldarg_0) &&
83+
(codes[i - 2].opcode == OpCodes.Ldfld && ((FieldInfo) codes[i - 2].operand).Name == "startPlaylistButton_") &&
84+
(codes[i ].opcode == OpCodes.Callvirt && ((MethodInfo)codes[i ].operand).Name == "SetActive"))
85+
{
86+
Mod.Instance.Logger.Info($"callvirt SetActive @ {i}");
87+
88+
// Replace: ldarg.0
89+
// Replace: ldfld startPlaylistButton_
90+
// Ignore: ldloc.
91+
// Replace: callvirt SetActive
92+
// With: ldarg.0
93+
// Ignore: ldloc.
94+
// With: call SetStartPlaylistButtonActive_
95+
codes.RemoveAt(i - 2);
96+
i -= 1; // preserve i instruction offset
97+
98+
codes.RemoveAt(i);
99+
codes.InsertRange(i, new CodeInstruction[]
100+
{
101+
new CodeInstruction(OpCodes.Call, typeof(LevelSelectMenuLogic__SetupLevelPlaylistVisuals).GetMethod(nameof(SetStartPlaylistButtonActive_))),
102+
});
103+
104+
break;
105+
}
106+
}*/
107+
108+
return codes.AsEnumerable();
109+
}
110+
111+
#region Helper Functions
112+
113+
public static bool AllowMainMenuDisplayTypeForVisitWorkshop_(LevelSelectMenuLogic levelSelectMenu)
114+
{
115+
if (Mod.Instance.Config.EnableChooseMainMenuVisitWorkshopButton)
116+
{
117+
return true;
118+
}
119+
return levelSelectMenu.displayType_ != LevelSelectMenuAbstract.DisplayType.ChooseMainMenuLevel;
120+
}
121+
122+
/*public static void SetStartPlaylistButtonActive_(LevelSelectMenuLogic levelSelectMenu, bool active)
123+
{
124+
// Never allow starting a playlist while in ChooseMainMenuLevel display type.
125+
if (levelSelectMenu.displayType_ == LevelSelectMenuAbstract.DisplayType.ChooseMainMenuLevel)
126+
{
127+
active = false;
128+
}
129+
levelSelectMenu.startPlaylistButton_.SetActive(active);
130+
}*/
131+
132+
#endregion
24133
}
25134
}

Distance.LevelSelectAdditions/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.1.0")]
36-
[assembly: AssemblyFileVersion("1.1.1.0")]
35+
[assembly: AssemblyVersion("1.1.2.0")]
36+
[assembly: AssemblyFileVersion("1.1.2.0")]
3737

3838

3939

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Distance mod that extends the level selection UI by adding more options.
1111
* Delete Playlist File
1212
* Remember the last-accessed level set/playlist, so that the game will return to your original place after playing a level appearing in multiple playlists.
1313
* Fix scrolling bug in level list where you could only scroll to the very top or bottom entry.
14+
* Make the Visit Workshop page button visible when Choosing Main Menu levels.
1415

1516
## Current Options
1617

0 commit comments

Comments
 (0)