only run cs mods if package is present

This commit is contained in:
Evil Factory
2022-04-17 15:09:24 -03:00
parent 6277a6ce5d
commit edb665a22c
3 changed files with 30 additions and 26 deletions
@@ -43,11 +43,11 @@ namespace Barotrauma
}
public static ContentPackage GetPackage()
public static ContentPackage GetPackage(Identifier name)
{
foreach (ContentPackage package in ContentPackageManager.LocalPackages)
{
if (package.NameMatches(new Identifier("LuaCsForBarotraumaUnstable")))
if (package.NameMatches(name))
{
return package;
}
@@ -55,7 +55,7 @@ namespace Barotrauma
foreach (ContentPackage package in ContentPackageManager.AllPackages)
{
if (package.NameMatches(new Identifier("LuaCsForBarotraumaUnstable")))
if (package.NameMatches(name))
{
return package;
}
@@ -302,8 +302,6 @@ namespace Barotrauma
LuaScriptLoader = new LuaScriptLoader();
LuaScriptLoader.ModulePaths = new string[] { };
NetScriptLoader = new CsScriptLoader(this);
LuaCustomConverters.RegisterAll();
lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.Debug);
@@ -358,21 +356,27 @@ namespace Barotrauma
// LuaDocs.GenerateDocsAll();
ContentPackage csPackage = GetPackage("CsForBarotrauma");
NetScriptLoader.SearchFolders();
if (NetScriptLoader == null) throw new Exception("LuaCsSetup was not properly initialized.");
try
if (csPackage != null)
{
var modTypes = NetScriptLoader.Compile();
modTypes.ForEach(t => t.GetConstructor(new Type[] { })?.Invoke(null));
}
catch (Exception ex)
{
HandleException(ex, exceptionType: ExceptionType.CSharp);
NetScriptLoader = new CsScriptLoader(this);
NetScriptLoader.SearchFolders();
try
{
var modTypes = NetScriptLoader.Compile();
modTypes.ForEach(t => t.GetConstructor(new Type[] { })?.Invoke(null));
}
catch (Exception ex)
{
HandleException(ex, exceptionType: ExceptionType.CSharp);
}
}
ContentPackage luaCsPackage = GetPackage();
ContentPackage luaPackage = GetPackage("LuaForBarotraumaUnstable");
if (File.Exists(LUASETUP_FILE))
{
@@ -385,9 +389,9 @@ namespace Barotrauma
HandleException(e);
}
}
else if (luaCsPackage != null)
else if (luaPackage != null)
{
string path = Path.GetDirectoryName(luaCsPackage.Path);
string path = Path.GetDirectoryName(luaPackage.Path);
try
{