Set TopLevelBinderFlags to IgnoreAccessibility for CsMods, so they are able to access non-public members by default

This commit is contained in:
EvilFactory
2023-04-28 14:45:45 -03:00
parent 5de8d0293f
commit 29a2e07b1f

View File

@@ -193,7 +193,11 @@ namespace Barotrauma
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
.WithMetadataImportOptions(MetadataImportOptions.All)
.WithOptimizationLevel(OptimizationLevel.Release)
.WithAllowUnsafe(true);
.WithAllowUnsafe(true);
var topLevelBinderFlagsProperty = typeof(CSharpCompilationOptions).GetProperty("TopLevelBinderFlags", BindingFlags.Instance | BindingFlags.NonPublic);
topLevelBinderFlagsProperty.SetValue(options, (uint)1 << 22);
var compilation = CSharpCompilation.Create(CsScriptAssembly, syntaxTrees, defaultReferences, options);
using (var mem = new MemoryStream())