fix some of the formatting and remove usage of CsScriptFilter as it's pretty much useless

This commit is contained in:
Evil Factory
2022-06-29 12:12:47 -03:00
parent 95de8a721b
commit 47e0351403
5 changed files with 30 additions and 31 deletions
@@ -20,6 +20,11 @@ namespace Barotrauma
public const string NET_ONE_TIME_SCRIPT_ASSEMBLY = "NetOneTimeScriptAssembly"; public const string NET_ONE_TIME_SCRIPT_ASSEMBLY = "NetOneTimeScriptAssembly";
public const string NET_SCRIPT_ASSEMBLY = "NetScriptAssembly"; 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>() public static Dictionary<string, object> Revision = new Dictionary<string, object>()
{ {
{ NET_SCRIPT_ASSEMBLY, 0}, { NET_SCRIPT_ASSEMBLY, 0},
@@ -1,3 +1,5 @@
// unused
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -151,8 +151,6 @@ namespace Barotrauma
foreach (var file in src) foreach (var file in src)
{ {
var tree = SyntaxFactory.ParseSyntaxTree(File.ReadAllText(file), ParseOptions, file); 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); syntaxTrees.Add(tree);
} }
@@ -189,23 +187,21 @@ namespace Barotrauma
LuaCsSetup.PrintCsError(errStr); LuaCsSetup.PrintCsError(errStr);
} }
else else
{
mem.Seek(0, SeekOrigin.Begin);
var errStr = CsScriptFilter.FilterMetadata(new PEReader(mem).GetMetadataReader());
if (errStr == null)
{ {
mem.Seek(0, SeekOrigin.Begin); mem.Seek(0, SeekOrigin.Begin);
Assembly = LoadFromStream(mem); Assembly = LoadFromStream(mem);
} }
else LuaCsSetup.PrintCsError(errStr);
}
} }
if (Assembly != null) if (Assembly != null)
{
return Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ACsMod))).ToList(); return Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ACsMod))).ToList();
}
else else
{
throw new Exception("Unable to create net mods assembly."); throw new Exception("Unable to create net mods assembly.");
} }
}
private static string[] DirSearch(string sDir) private static string[] DirSearch(string sDir)
{ {
@@ -87,10 +87,6 @@ namespace Barotrauma
LuaCsSetup.PrintCsError(errStr); LuaCsSetup.PrintCsError(errStr);
} }
else else
{
mem.Seek(0, SeekOrigin.Begin);
var errStr = CsScriptFilter.FilterOneTimeMetadata(new PEReader(mem).GetMetadataReader());
if (errStr == null)
{ {
mem.Seek(0, SeekOrigin.Begin); mem.Seek(0, SeekOrigin.Begin);
assembly = LoadFromStream(mem); assembly = LoadFromStream(mem);
@@ -106,11 +102,9 @@ namespace Barotrauma
UserData.UnregisterType(type, true); UserData.UnregisterType(type, true);
} }
} }
else LuaCsSetup.PrintCsError("Script Error - no run method detected"); else { LuaCsSetup.PrintCsError("Script Error - no run method detected"); }
} }
else LuaCsSetup.PrintCsError("Script Error - no runner class detected"); else { LuaCsSetup.PrintCsError("Script Error - no runner class detected"); }
}
else LuaCsSetup.PrintCsError(errStr);
} }
} }
Unload(); Unload();
@@ -15,7 +15,7 @@ namespace Barotrauma
if (type != null) return type; if (type != null) return type;
foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) 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 attrs = a.GetCustomAttributes<AssemblyMetadataAttribute>();
var revision = attrs.FirstOrDefault(attr => attr.Key == "Revision")?.Value; var revision = attrs.FirstOrDefault(attr => attr.Key == "Revision")?.Value;
@@ -23,8 +23,10 @@ namespace Barotrauma
} }
type = a.GetType(typeName); type = a.GetType(typeName);
if (type != null) if (type != null)
{
return type; return type;
} }
}
return null; return null;
} }