From 227dcb18694f56f170fecb1d95a249f60e718d41 Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Tue, 13 May 2025 01:33:59 +0700 Subject: [PATCH] force compiler version to be latest available --- .../Patches/ScriptCompilationSettingsPatch.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 CringeLauncher/Patches/ScriptCompilationSettingsPatch.cs 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