force compiler version to be latest available
All checks were successful
Build / Compute Version (push) Successful in 6s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 54s
Build / Build Nuget package (NuGet) (push) Successful in 53s
Build / Build Nuget package (SharedCringe) (push) Successful in 55s
Build / Build Nuget package (CringePlugins) (push) Successful in 1m18s
Build / Build Launcher (push) Successful in 6m24s

This commit is contained in:
zznty
2025-05-13 01:33:59 +07:00
parent a441498c09
commit 227dcb1869

View File

@@ -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<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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();
}
}