File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -322,6 +322,7 @@ private static void InvokeApi(bool isPreload)
322322 {
323323 if ( isPreload )
324324 {
325+ LabApiNullPluginVersionFix . Internal_Init ( ) ;
325326 SwitchContainer . Internal_Init ( ) ;
326327 LogPatch . Internal_Init ( ) ;
327328 }
Original file line number Diff line number Diff line change 1+ using HarmonyLib ;
2+
3+ using LabApi . Loader ;
4+ using LabApi . Loader . Features . Plugins ;
5+
6+ using LabExtended . Core ;
7+ using LabExtended . Extensions ;
8+
9+ using System . Reflection ;
10+
11+ namespace LabExtended . Patches . Fixes
12+ {
13+ /// <summary>
14+ /// Fixes the server hanging on startup when a plugin with a null RequiredApiVersion is present.
15+ /// </summary>
16+ public static class LabApiNullPluginVersionFix
17+ {
18+ private static MethodInfo targetMethod = typeof ( PluginLoader ) . FindMethod ( nameof ( PluginLoader . ValidateVersion ) ) ;
19+ private static MethodInfo patchMethod = typeof ( LabApiNullPluginVersionFix ) . FindMethod ( nameof ( Prefix ) ) ;
20+
21+ private static bool Prefix ( Plugin plugin , ref bool __result )
22+ {
23+ if ( plugin . RequiredApiVersion is null
24+ || plugin . Properties is null )
25+ {
26+ __result = true ;
27+ return false ;
28+ }
29+
30+ return false ;
31+ }
32+
33+ internal static void Internal_Init ( )
34+ {
35+ try
36+ {
37+ if ( ApiPatcher . Harmony . Patch ( targetMethod , new HarmonyMethod ( patchMethod ) ) != null )
38+ {
39+ ApiPatcher . labExPatchCountOffset ++ ;
40+ ApiLog . Debug ( "LabExtended" , $ "Applied &6{ nameof ( LabApiNullPluginVersionFix ) } &r") ;
41+ }
42+ else
43+ {
44+ ApiLog . Error ( "LabExtended" , $ "Failed to apply &3{ nameof ( LabApiNullPluginVersionFix ) } &r!") ;
45+ }
46+ }
47+ catch ( Exception ex )
48+ {
49+ ApiLog . Error ( "LabExtended" , ex ) ;
50+ }
51+ }
52+ }
53+ }
You can’t perform that action at this time.
0 commit comments