@@ -333,5 +333,56 @@ public static MethodBase GetOriginalMethodFromStackframe(StackFrame frame)
333333 ///
334334 public static Dictionary < string , Version > VersionInfo ( out Version currentVersion )
335335 => PatchProcessor . VersionInfo ( out currentVersion ) ;
336+
337+ /// <summary>Sets a MonoMod switch value (e.g., "DMDDebug", "DMDDumpTo")</summary>
338+ /// <param name="name">The switch name</param>
339+ /// <param name="value">The value to set (bool, string, etc.)</param>
340+ ///
341+ public static void SetSwitch ( string name , object value )
342+ {
343+ var switchesType = AccessTools . TypeByName ( "MonoMod.Switches" ) ;
344+ var method = AccessTools . Method ( switchesType , "SetSwitchValue" ) ;
345+ method . Invoke ( null , [ name , value ] ) ;
346+ }
347+
348+ /// <summary>Clears a MonoMod switch value</summary>
349+ /// <param name="name">The switch name</param>
350+ ///
351+ public static void ClearSwitch ( string name )
352+ {
353+ var switchesType = AccessTools . TypeByName ( "MonoMod.Switches" ) ;
354+ var method = AccessTools . Method ( switchesType , "ClearSwitchValue" ) ;
355+ method . Invoke ( null , [ name ] ) ;
356+ }
357+
358+ /// <summary>Tries to get a MonoMod switch value</summary>
359+ /// <param name="name">The switch name</param>
360+ /// <param name="value">The switch value if found</param>
361+ /// <returns>True if the switch was found, false otherwise</returns>
362+ ///
363+ public static bool TryGetSwitch ( string name , out object value )
364+ {
365+ var switchesType = AccessTools . TypeByName ( "MonoMod.Switches" ) ;
366+ var method = AccessTools . Method ( switchesType , "TryGetSwitchValue" ) ;
367+ var args = new object [ ] { name , null } ;
368+ var result = ( bool ) method . Invoke ( null , args ) ;
369+ value = args [ 1 ] ;
370+ return result ;
371+ }
372+
373+ /// <summary>Tries to determine if a MonoMod switch is enabled</summary>
374+ /// <param name="name">The switch name</param>
375+ /// <param name="isEnabled">True if the switch is enabled, false otherwise</param>
376+ /// <returns>True if the switch enablement state could be determined, false otherwise</returns>
377+ ///
378+ public static bool TryIsSwitchEnabled ( string name , out bool isEnabled )
379+ {
380+ var switchesType = AccessTools . TypeByName ( "MonoMod.Switches" ) ;
381+ var method = AccessTools . Method ( switchesType , "TryGetSwitchEnabled" ) ;
382+ var args = new object [ ] { name , false } ;
383+ var result = ( bool ) method . Invoke ( null , args ) ;
384+ isEnabled = ( bool ) args [ 1 ] ;
385+ return result ;
386+ }
336387 }
337388}
0 commit comments