Rename field and remove unnecessary usings
This commit is contained in:
@@ -1,16 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Barotrauma.Networking;
|
using Barotrauma.Networking;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using MoonSharp.Interpreter.Interop;
|
using MoonSharp.Interpreter.Interop;
|
||||||
using System.IO.Compression;
|
|
||||||
using HarmonyLib;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch;
|
using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch;
|
||||||
|
|
||||||
@@ -57,24 +52,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private static int executionNumber = 0;
|
private static int executionNumber = 0;
|
||||||
|
|
||||||
private Script lua;
|
|
||||||
public Script Lua
|
|
||||||
{
|
|
||||||
get { return lua; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public Script Lua { get; private set; }
|
||||||
public CsScriptRunner CsScript { get; private set; }
|
public CsScriptRunner CsScript { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// due to there's a race on the process and the unloaded AssemblyLoadContexts,
|
|
||||||
/// should recreate runner after the script runs
|
|
||||||
/// </summary>
|
|
||||||
public void RecreateCsScript()
|
|
||||||
{
|
|
||||||
CsScript = new CsScriptRunner(CsScript.setup);
|
|
||||||
lua.Globals["CsScript"] = CsScript;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LuaScriptLoader LuaScriptLoader { get; private set; }
|
public LuaScriptLoader LuaScriptLoader { get; private set; }
|
||||||
|
|
||||||
public LuaGame Game { get; private set; }
|
public LuaGame Game { get; private set; }
|
||||||
@@ -111,6 +91,15 @@ namespace Barotrauma
|
|||||||
file.Close();
|
file.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// due to there's a race on the process and the unloaded AssemblyLoadContexts,
|
||||||
|
/// should recreate runner after the script runs
|
||||||
|
/// </summary>
|
||||||
|
public void RecreateCsScript()
|
||||||
|
{
|
||||||
|
CsScript = new CsScriptRunner(CsScript.setup);
|
||||||
|
Lua.Globals["CsScript"] = CsScript;
|
||||||
|
}
|
||||||
|
|
||||||
public static ContentPackage GetPackage(ContentPackageId id, bool fallbackToAll = true, bool useBackup = false)
|
public static ContentPackage GetPackage(ContentPackageId id, bool fallbackToAll = true, bool useBackup = false)
|
||||||
{
|
{
|
||||||
@@ -303,7 +292,7 @@ namespace Barotrauma
|
|||||||
throw new ScriptRuntimeException($"dofile: File {file} not found.");
|
throw new ScriptRuntimeException($"dofile: File {file} not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return lua.DoFile(file, globalContext, codeStringFriendly);
|
return Lua.DoFile(file, globalContext, codeStringFriendly);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DynValue LoadFile(string file, Table globalContext = null, string codeStringFriendly = null)
|
private DynValue LoadFile(string file, Table globalContext = null, string codeStringFriendly = null)
|
||||||
@@ -318,20 +307,20 @@ namespace Barotrauma
|
|||||||
throw new ScriptRuntimeException($"loadfile: File {file} not found.");
|
throw new ScriptRuntimeException($"loadfile: File {file} not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return lua.LoadFile(file, globalContext, codeStringFriendly);
|
return Lua.LoadFile(file, globalContext, codeStringFriendly);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynValue CallLuaFunction(object function, params object[] args)
|
public DynValue CallLuaFunction(object function, params object[] args)
|
||||||
{
|
{
|
||||||
// XXX: `lua` might be null if `LuaCsSetup.Stop()` is called while
|
// XXX: `lua` might be null if `LuaCsSetup.Stop()` is called while
|
||||||
// a patched function is still running.
|
// a patched function is still running.
|
||||||
if (lua == null) return null;
|
if (Lua == null) return null;
|
||||||
|
|
||||||
lock (lua)
|
lock (Lua)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return lua.Call(function, args);
|
return Lua.Call(function, args);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -382,7 +371,7 @@ namespace Barotrauma
|
|||||||
Steam = new LuaCsSteam();
|
Steam = new LuaCsSteam();
|
||||||
PerformanceCounter = new LuaCsPerformanceCounter();
|
PerformanceCounter = new LuaCsPerformanceCounter();
|
||||||
LuaScriptLoader = null;
|
LuaScriptLoader = null;
|
||||||
lua = null;
|
Lua = null;
|
||||||
CsScript = null;
|
CsScript = null;
|
||||||
Config = null;
|
Config = null;
|
||||||
|
|
||||||
@@ -418,13 +407,13 @@ namespace Barotrauma
|
|||||||
|
|
||||||
RegisterLuaConverters();
|
RegisterLuaConverters();
|
||||||
|
|
||||||
lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.Debug);
|
Lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.Debug);
|
||||||
lua.Options.DebugPrint = PrintMessage;
|
Lua.Options.DebugPrint = PrintMessage;
|
||||||
lua.Options.ScriptLoader = LuaScriptLoader;
|
Lua.Options.ScriptLoader = LuaScriptLoader;
|
||||||
lua.Options.CheckThreadAccess = false;
|
Lua.Options.CheckThreadAccess = false;
|
||||||
CsScript = new CsScriptRunner(this);
|
CsScript = new CsScriptRunner(this);
|
||||||
|
|
||||||
require = new LuaRequire(lua);
|
require = new LuaRequire(Lua);
|
||||||
|
|
||||||
Game = new LuaGame();
|
Game = new LuaGame();
|
||||||
Networking = new LuaCsNetworking();
|
Networking = new LuaCsNetworking();
|
||||||
@@ -450,33 +439,33 @@ namespace Barotrauma
|
|||||||
UserData.RegisterType<LuaCsPerformanceCounter>();
|
UserData.RegisterType<LuaCsPerformanceCounter>();
|
||||||
UserData.RegisterType<IUserDataDescriptor>();
|
UserData.RegisterType<IUserDataDescriptor>();
|
||||||
|
|
||||||
lua.Globals["printerror"] = (Action<object>)PrintLuaError;
|
Lua.Globals["printerror"] = (Action<object>)PrintLuaError;
|
||||||
|
|
||||||
lua.Globals["setmodulepaths"] = (Action<string[]>)SetModulePaths;
|
Lua.Globals["setmodulepaths"] = (Action<string[]>)SetModulePaths;
|
||||||
|
|
||||||
lua.Globals["dofile"] = (Func<string, Table, string, DynValue>)DoFile;
|
Lua.Globals["dofile"] = (Func<string, Table, string, DynValue>)DoFile;
|
||||||
lua.Globals["loadfile"] = (Func<string, Table, string, DynValue>)LoadFile;
|
Lua.Globals["loadfile"] = (Func<string, Table, string, DynValue>)LoadFile;
|
||||||
lua.Globals["require"] = (Func<string, Table, DynValue>)require.Require;
|
Lua.Globals["require"] = (Func<string, Table, DynValue>)require.Require;
|
||||||
|
|
||||||
lua.Globals["dostring"] = (Func<string, Table, string, DynValue>)lua.DoString;
|
Lua.Globals["dostring"] = (Func<string, Table, string, DynValue>)Lua.DoString;
|
||||||
lua.Globals["load"] = (Func<string, Table, string, DynValue>)lua.LoadString;
|
Lua.Globals["load"] = (Func<string, Table, string, DynValue>)Lua.LoadString;
|
||||||
|
|
||||||
lua.Globals["CsScript"] = CsScript;
|
Lua.Globals["CsScript"] = CsScript;
|
||||||
lua.Globals["LuaUserData"] = UserData.CreateStatic<LuaUserData>();
|
Lua.Globals["LuaUserData"] = UserData.CreateStatic<LuaUserData>();
|
||||||
lua.Globals["Game"] = Game;
|
Lua.Globals["Game"] = Game;
|
||||||
lua.Globals["Hook"] = Hook;
|
Lua.Globals["Hook"] = Hook;
|
||||||
lua.Globals["ModStore"] = ModStore;
|
Lua.Globals["ModStore"] = ModStore;
|
||||||
lua.Globals["Timer"] = Timer;
|
Lua.Globals["Timer"] = Timer;
|
||||||
lua.Globals["File"] = UserData.CreateStatic<LuaCsFile>();
|
Lua.Globals["File"] = UserData.CreateStatic<LuaCsFile>();
|
||||||
lua.Globals["Networking"] = Networking;
|
Lua.Globals["Networking"] = Networking;
|
||||||
lua.Globals["Steam"] = Steam;
|
Lua.Globals["Steam"] = Steam;
|
||||||
lua.Globals["PerformanceCounter"] = PerformanceCounter;
|
Lua.Globals["PerformanceCounter"] = PerformanceCounter;
|
||||||
|
|
||||||
lua.Globals["ExecutionNumber"] = executionNumber;
|
Lua.Globals["ExecutionNumber"] = executionNumber;
|
||||||
lua.Globals["CSActive"] = csActive;
|
Lua.Globals["CSActive"] = csActive;
|
||||||
|
|
||||||
lua.Globals["SERVER"] = IsServer;
|
Lua.Globals["SERVER"] = IsServer;
|
||||||
lua.Globals["CLIENT"] = IsClient;
|
Lua.Globals["CLIENT"] = IsClient;
|
||||||
|
|
||||||
if (csActive)
|
if (csActive)
|
||||||
{
|
{
|
||||||
@@ -526,7 +515,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DynValue function = lua.LoadFile(LuaSetupFile);
|
DynValue function = Lua.LoadFile(LuaSetupFile);
|
||||||
CallLuaFunction(function, Path.GetDirectoryName(Path.GetFullPath(LuaSetupFile)));
|
CallLuaFunction(function, Path.GetDirectoryName(Path.GetFullPath(LuaSetupFile)));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -543,7 +532,7 @@ namespace Barotrauma
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string luaPath = Path.Combine(path, "Binary/Lua/LuaSetup.lua");
|
string luaPath = Path.Combine(path, "Binary/Lua/LuaSetup.lua");
|
||||||
CallLuaFunction(lua.LoadFile(luaPath), Path.GetDirectoryName(Path.GetFullPath(luaPath)));
|
CallLuaFunction(Lua.LoadFile(luaPath), Path.GetDirectoryName(Path.GetFullPath(luaPath)));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user