Skip to content

Commit ded22cd

Browse files
committed
feat(RunData): refine lobby constructor patching and instance tracking
- Enhanced the constructor patching for StartRunLobby to support additional parameters, improving flexibility in lobby initialization. - Updated the Postfix method to utilize type checking for instance tracking, ensuring accurate data handling for StartRunLobby instances. - Improved code clarity and maintainability by restructuring method signatures and enhancing type safety.
1 parent db9b837 commit ded22cd

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

RunData/Patches/RunSavedDataPatches.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Runtime.CompilerServices;
22
using System.Text;
33
using System.Text.Json;
4+
using HarmonyLib;
5+
using MegaCrit.Sts2.Core.Daily;
46
using MegaCrit.Sts2.Core.Entities.Multiplayer;
57
using MegaCrit.Sts2.Core.Entities.Players;
68
using MegaCrit.Sts2.Core.Helpers;
@@ -221,15 +223,30 @@ public static ModPatchTarget[] GetTargets()
221223
{
222224
return
223225
[
224-
new(typeof(StartRunLobby), ".ctor",
225-
[typeof(GameMode), typeof(INetGameService), typeof(IStartRunLobbyListener), typeof(int)]),
226+
new(
227+
typeof(StartRunLobby),
228+
".ctor",
229+
[typeof(GameMode), typeof(INetGameService), typeof(IStartRunLobbyListener), typeof(int)],
230+
MethodType.Constructor),
231+
new(
232+
typeof(StartRunLobby),
233+
".ctor",
234+
[
235+
typeof(GameMode),
236+
typeof(INetGameService),
237+
typeof(IStartRunLobbyListener),
238+
typeof(TimeServerResult),
239+
typeof(int),
240+
],
241+
MethodType.Constructor),
226242
];
227243
}
228244

229245
// ReSharper disable once InconsistentNaming
230-
public static void Postfix(StartRunLobby __instance)
246+
public static void Postfix(object __instance)
231247
{
232-
RunSavedDataStartRunLobbyAccess.Track(__instance);
248+
if (__instance is StartRunLobby lobby)
249+
RunSavedDataStartRunLobbyAccess.Track(lobby);
233250
}
234251
}
235252

0 commit comments

Comments
 (0)