Skip to content

Commit 7f35b14

Browse files
committed
[COTLMP] Fix some bugs
- Fix a regression (introduced by `5914e49`) of which the settings locale strings couldn't be retrieved - Fix a NULL reference exception where StartCoroutine expected a IEnumerator routine to be passed in the `BannerEditionPatch` patch
1 parent a550206 commit 7f35b14

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

COTLMP/Plugin.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Plugin : BaseUnityPlugin
4343
internal static new ConfigFile Config;
4444
internal static ModDataGlobals Globals;
4545
internal static InternalData GlobalsInternal;
46-
private readonly Harmony HarmonyManager = new(MyPluginInfo.PLUGIN_GUID);
46+
private Harmony HarmonyInstance;
4747

4848
/*
4949
* @brief
@@ -57,6 +57,12 @@ private void Awake()
5757
string ServerName, PlayerName, GameMode;
5858
bool ToggleMod, VoiceChat;
5959

60+
/*
61+
* Start patching the game assembly with our code
62+
* and cache a harmony instance of this mod.
63+
*/
64+
HarmonyInstance = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
65+
6066
/* Cache the plugin class methods so that the COTL MP mod can use them across different modules */
6167
Logger = base.Logger;
6268
Config = base.Config;
@@ -80,7 +86,7 @@ private void Awake()
8086
if (SettingData == null)
8187
{
8288
Logger.LogFatal("Failed to set default or load the \"Mod Toggle\" setting!");
83-
Harmony.UnpatchAll();
89+
HarmonyInstance.UnpatchSelf();
8490
return;
8591
}
8692

@@ -95,7 +101,7 @@ private void Awake()
95101
if (SettingData == null)
96102
{
97103
Logger.LogFatal("Failed to set default or load the \"Game Mode\" setting!");
98-
Harmony.UnpatchAll();
104+
HarmonyInstance.UnpatchSelf();
99105
return;
100106
}
101107

@@ -110,7 +116,7 @@ private void Awake()
110116
if (SettingData == null)
111117
{
112118
Logger.LogFatal("Failed to set default or load the \"Player Name\" setting!");
113-
Harmony.UnpatchAll();
119+
HarmonyInstance.UnpatchSelf();
114120
return;
115121
}
116122

@@ -125,7 +131,7 @@ private void Awake()
125131
if (SettingData == null)
126132
{
127133
Logger.LogFatal("Failed to set default or load the \"Server Name\" setting!");
128-
Harmony.UnpatchAll();
134+
HarmonyInstance.UnpatchSelf();
129135
return;
130136
}
131137

@@ -140,7 +146,7 @@ private void Awake()
140146
if (SettingData == null)
141147
{
142148
Logger.LogFatal("Failed to set default or load the \"Max Players\" setting!");
143-
Harmony.UnpatchAll();
149+
HarmonyInstance.UnpatchSelf();
144150
return;
145151
}
146152

@@ -155,7 +161,7 @@ private void Awake()
155161
if (SettingData == null)
156162
{
157163
Logger.LogFatal("Failed to set default or load the \"Toggle Voice Chat\" setting!");
158-
Harmony.UnpatchAll();
164+
HarmonyInstance.UnpatchSelf();
159165
return;
160166
}
161167

@@ -179,13 +185,12 @@ private void Awake()
179185

180186
/*
181187
* @brief
182-
* Patches the game assembly with Harmony patches set up
183-
* by the mod.
188+
* Performs additional tasks after the successful initialization
189+
* of the mod.
184190
*/
185191
private void OnEnable()
186192
{
187-
HarmonyManager.PatchAll(Assembly.GetExecutingAssembly());
188-
Logger.LogMessage($"{HarmonyManager.GetPatchedMethods().Count()} patches have been applied!");
193+
Logger.LogMessage($"{HarmonyInstance.GetPatchedMethods().Count()} patches have been applied!");
189194
}
190195

191196
/*
@@ -196,7 +201,7 @@ private void OnEnable()
196201
private void OnDisable()
197202
{
198203
Logger.LogMessage($"Unloading {MyPluginInfo.PLUGIN_GUID}");
199-
HarmonyManager.UnpatchSelf();
204+
HarmonyInstance.UnpatchSelf();
200205
Logger.LogMessage("Mod has been unloaded!");
201206
}
202207
}

COTLMP/Ui/Banner.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
/* IMPORTS ********************************************************************/
99

1010
using COTLMP;
11-
using COTLMP.Debug;
1211
using COTLMP.Data;
1312
using BepInEx;
1413
using HarmonyLib;
1514
using I2.Loc;
1615
using Lamb.UI;
16+
using System.Collections;
1717

1818
/* CLASSES & CODE *************************************************************/
1919

@@ -30,6 +30,17 @@ namespace COTLMP.Ui
3030
[HarmonyPatch]
3131
internal static class Banner
3232
{
33+
34+
/*
35+
* @brief
36+
* A dummy IEnumerator method that is used to replace the
37+
* returned value which represents a coroutine.
38+
*/
39+
private static IEnumerator BannerEnumerator()
40+
{
41+
yield break;
42+
}
43+
3344
/*
3445
* @brief
3546
* Patches the private DLC check edition method, of which it replaces
@@ -38,13 +49,17 @@ internal static class Banner
3849
* @param[in] __instance
3950
* The current instance value of the method being patched.
4051
*
52+
* @param[in] __result
53+
* The current result value being returned. Typically the original
54+
* method returns a IEnumerator.
55+
*
4156
* @return
4257
* Returns TRUE if tthe original method of the game is to be executed.
4358
* FALSE if our method is to be executed instead.
4459
*/
4560
[HarmonyPatch(typeof(ShowIfSpecialEdition), "WaitForDLCCheck")]
4661
[HarmonyPrefix]
47-
private static bool BannerEditionPatch(ShowIfSpecialEdition __instance)
62+
private static bool BannerEditionPatch(ShowIfSpecialEdition __instance, ref IEnumerator __result)
4863
{
4964
/* The mod is currently not executing so run the original method instead */
5065
if (!Plugin.Globals.EnableMod)
@@ -55,6 +70,7 @@ private static bool BannerEditionPatch(ShowIfSpecialEdition __instance)
5570
/* Replace the banner header */
5671
__instance._localize.Term = "UI/Banner";
5772
__instance._text.text = MultiplayerModLocalization.UI.Multiplayer_Banner;
73+
__result = BannerEnumerator();
5874
return false;
5975
}
6076
}

0 commit comments

Comments
 (0)