fix some of the formatting and remove usage of CsScriptFilter as it's pretty much useless
This commit is contained in:
@@ -20,6 +20,11 @@ namespace Barotrauma
|
||||
public const string NET_ONE_TIME_SCRIPT_ASSEMBLY = "NetOneTimeScriptAssembly";
|
||||
public const string NET_SCRIPT_ASSEMBLY = "NetScriptAssembly";
|
||||
|
||||
public static readonly string[] LoadedAssemblyName = {
|
||||
CsScriptBase.NET_SCRIPT_ASSEMBLY,
|
||||
CsScriptBase.NET_ONE_TIME_SCRIPT_ASSEMBLY
|
||||
};
|
||||
|
||||
public static Dictionary<string, object> Revision = new Dictionary<string, object>()
|
||||
{
|
||||
{ NET_SCRIPT_ASSEMBLY, 0},
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// unused
|
||||
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
@@ -151,8 +151,6 @@ namespace Barotrauma
|
||||
foreach (var file in src)
|
||||
{
|
||||
var tree = SyntaxFactory.ParseSyntaxTree(File.ReadAllText(file), ParseOptions, file);
|
||||
var error = CsScriptFilter.FilterSyntaxTree(tree as CSharpSyntaxTree); // Check file content for prohibited stuff
|
||||
if (error != null) throw new Exception(error);
|
||||
|
||||
syntaxTrees.Add(tree);
|
||||
}
|
||||
@@ -166,15 +164,15 @@ namespace Barotrauma
|
||||
return syntaxTrees;
|
||||
}
|
||||
|
||||
public List<Type> Compile()
|
||||
{
|
||||
public List<Type> Compile()
|
||||
{
|
||||
IEnumerable<SyntaxTree> syntaxTrees = ParseSources();
|
||||
|
||||
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
|
||||
.WithMetadataImportOptions(MetadataImportOptions.All)
|
||||
.WithOptimizationLevel(OptimizationLevel.Release)
|
||||
.WithAllowUnsafe(false);
|
||||
var compilation = CSharpCompilation.Create(NET_SCRIPT_ASSEMBLY,syntaxTrees, defaultReferences, options);
|
||||
var compilation = CSharpCompilation.Create(NET_SCRIPT_ASSEMBLY, syntaxTrees, defaultReferences, options);
|
||||
|
||||
using (var mem = new MemoryStream())
|
||||
{
|
||||
@@ -191,20 +189,18 @@ namespace Barotrauma
|
||||
else
|
||||
{
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
var errStr = CsScriptFilter.FilterMetadata(new PEReader(mem).GetMetadataReader());
|
||||
if (errStr == null)
|
||||
{
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
Assembly = LoadFromStream(mem);
|
||||
}
|
||||
else LuaCsSetup.PrintCsError(errStr);
|
||||
Assembly = LoadFromStream(mem);
|
||||
}
|
||||
}
|
||||
|
||||
if (Assembly != null)
|
||||
{
|
||||
return Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ACsMod))).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unable to create net mods assembly.");
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] DirSearch(string sDir)
|
||||
|
||||
@@ -89,28 +89,22 @@ namespace Barotrauma
|
||||
else
|
||||
{
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
var errStr = CsScriptFilter.FilterOneTimeMetadata(new PEReader(mem).GetMetadataReader());
|
||||
if (errStr == null)
|
||||
assembly = LoadFromStream(mem);
|
||||
var runner = assembly.CreateInstance("NetOneTimeScript.NetOneTimeScriptRunner");
|
||||
if (runner != null)
|
||||
{
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
assembly = LoadFromStream(mem);
|
||||
var runner = assembly.CreateInstance("NetOneTimeScript.NetOneTimeScriptRunner");
|
||||
if (runner != null)
|
||||
{
|
||||
var method = runner.GetType().GetMethod("Run", BindingFlags.Public | BindingFlags.Instance);
|
||||
if (method != null)
|
||||
{
|
||||
scriptResilt = method.Invoke(runner, null);
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
UserData.UnregisterType(type, true);
|
||||
}
|
||||
var method = runner.GetType().GetMethod("Run", BindingFlags.Public | BindingFlags.Instance);
|
||||
if (method != null)
|
||||
{
|
||||
scriptResilt = method.Invoke(runner, null);
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
UserData.UnregisterType(type, true);
|
||||
}
|
||||
else LuaCsSetup.PrintCsError("Script Error - no run method detected");
|
||||
}
|
||||
else LuaCsSetup.PrintCsError("Script Error - no runner class detected");
|
||||
else { LuaCsSetup.PrintCsError("Script Error - no run method detected"); }
|
||||
}
|
||||
else LuaCsSetup.PrintCsError(errStr);
|
||||
else { LuaCsSetup.PrintCsError("Script Error - no runner class detected"); }
|
||||
}
|
||||
}
|
||||
Unload();
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Barotrauma
|
||||
if (type != null) return type;
|
||||
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if (CsScriptFilter.LoadedAssemblyName.Contains(a.GetName().Name))
|
||||
if (CsScriptBase.LoadedAssemblyName.Contains(a.GetName().Name))
|
||||
{
|
||||
var attrs = a.GetCustomAttributes<AssemblyMetadataAttribute>();
|
||||
var revision = attrs.FirstOrDefault(attr => attr.Key == "Revision")?.Value;
|
||||
@@ -23,7 +23,9 @@ namespace Barotrauma
|
||||
}
|
||||
type = a.GetType(typeName);
|
||||
if (type != null)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user