diff --git a/CringeLauncher/Patches/ScriptCompilationSettingsPatch.cs b/CringeLauncher/Patches/ScriptCompilationSettingsPatch.cs new file mode 100644 index 0000000..fd825fa --- /dev/null +++ b/CringeLauncher/Patches/ScriptCompilationSettingsPatch.cs @@ -0,0 +1,24 @@ +using System.Reflection.Emit; +using HarmonyLib; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using VRage.Scripting; + +namespace CringeLauncher.Patches; + +[HarmonyPatch(typeof(MyScriptCompiler), nameof(MyScriptCompiler.CreateCompilation))] +public static class ScriptCompilationSettingsPatch +{ + private static readonly CSharpParseOptions Options = new(LanguageVersion.Latest, DocumentationMode.None); + + private static IEnumerable Transpiler(IEnumerable instructions) + { + var field = AccessTools.Field(typeof(MyScriptCompiler), nameof(MyScriptCompiler.m_conditionalParseOptions)); + return new CodeMatcher(instructions) + .Start() + .MatchStartForward(CodeMatch.IsLdarg(0), CodeMatch.LoadsField(field)) + .SetAndAdvance(OpCodes.Nop, null) + .SetInstructionAndAdvance(CodeInstruction.LoadField(typeof(ScriptCompilationSettingsPatch), nameof(Options))) + .Instructions(); + } +} \ No newline at end of file