separated Lua source by client, server and shared

github desktop bugged
This commit is contained in:
Evil Factory
2021-09-15 12:59:19 -03:00
parent 5678f81326
commit 4075e71f7a
12 changed files with 750 additions and 612 deletions
@@ -1,21 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using MoonSharp.Interpreter;
using Microsoft.Xna.Framework;
namespace Barotrauma.Networking
{
partial class Client
{
public static List<Client> ClientList
{
get
{
return GameMain.Server.ConnectedClients;
}
}
public void SetClientCharacter(Character character)
{
GameMain.Server.SetClientCharacter(this, character);
@@ -48,88 +38,30 @@ namespace Barotrauma.Networking
return this.Permissions.HasFlag(permissions);
}
}
}
namespace Barotrauma
namespace Barotrauma
{
using Barotrauma.Networking;
using System.Linq;
using System.Reflection;
partial class Character
{
}
partial class AfflictionPrefab
{
public static AfflictionPrefab[] ListArray
{
get
{
return List.ToArray();
}
}
}
partial class CharacterInfo
{
public static CharacterInfo Create(string speciesName, string name = "", JobPrefab jobPrefab = null, string ragdollFileName = null, int variant = 0, Rand.RandSync randSync = Rand.RandSync.Unsynced, string npcIdentifier = "")
{
return new CharacterInfo(speciesName, name, name, jobPrefab, ragdollFileName, variant, randSync, npcIdentifier);
}
}
partial class Item
{
public static void AddToRemoveQueue(Item item)
{
EntitySpawner.Spawner.AddToRemoveQueue(item);
}
public object GetComponentString(string component)
{
Type type = Type.GetType("Barotrauma.Items.Components." + component);
if (type == null)
return null;
MethodInfo method = typeof(Item).GetMethod(nameof(Item.GetComponent));
MethodInfo generic = method.MakeGenericMethod(type);
return generic.Invoke(this, null);
}
}
using Microsoft.Xna.Framework;
partial class ItemPrefab
{
public static void AddToSpawnQueue(ItemPrefab itemPrefab, Vector2 position, object spawned = null)
{
EntitySpawner.Spawner.AddToSpawnQueue(itemPrefab, position, onSpawned: (Item item) => {
EntitySpawner.Spawner.AddToSpawnQueue(itemPrefab, position, onSpawned: (Item item) =>
{
GameMain.Lua.CallFunction(spawned, new object[] { item });
});
}
public static void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, object spawned = null)
{
EntitySpawner.Spawner.AddToSpawnQueue(itemPrefab, inventory, onSpawned: (Item item) => {
EntitySpawner.Spawner.AddToSpawnQueue(itemPrefab, inventory, onSpawned: (Item item) =>
{
GameMain.Lua.CallFunction(spawned, new object[] { item });
});
}
public static ItemPrefab GetItemPrefab(string itemNameOrId)
{
ItemPrefab itemPrefab =
(MapEntityPrefab.Find(itemNameOrId, identifier: null, showErrorMessages: false) ??
MapEntityPrefab.Find(null, identifier: itemNameOrId, showErrorMessages: false)) as ItemPrefab;
return itemPrefab;
}
}
}
namespace Barotrauma.Items.Components
@@ -159,4 +91,6 @@ namespace Barotrauma.Items.Components
return new Signal(value, stepsTaken, sender, source, power, strength);
}
}
}
@@ -11,27 +11,71 @@ using System.Net;
using System.Linq;
using System.Xml.Linq;
namespace Barotrauma
{
partial class LuaSetup
{
private static Vector2 CreateVector2(float x, float y)
partial class LuaGame
{
return new Vector2(x, y);
public bool IsDedicated
{
get
{
return GameMain.Server.ServerPeer is LidgrenServerPeer;
}
}
public ServerSettings ServerSettings => GameMain.Server.ServerSettings;
public static void SendMessage(string msg, ChatMessageType? messageType = null, Client sender = null, Character character = null)
{
GameMain.Server.SendChatMessage(msg, messageType, sender, character);
}
public static void SendMessage(string msg, int messageType, Client sender = null, Character character = null)
{
GameMain.Server.SendChatMessage(msg, (ChatMessageType)messageType, sender, character);
}
public static void SendTraitorMessage(Client client, string msg, string missionid, TraitorMessageType type)
{
GameMain.Server.SendTraitorMessage(client, msg, missionid, type);
}
public static void SendDirectChatMessage(string sendername, string text, Character sender, ChatMessageType messageType = ChatMessageType.Private, Client client = null, string iconStyle = "")
{
ChatMessage cm = ChatMessage.Create(sendername, text, messageType, sender, client);
cm.IconStyle = iconStyle;
GameMain.Server.SendDirectChatMessage(cm, client);
}
public static void SendDirectChatMessage(ChatMessage chatMessage, Client client)
{
GameMain.Server.SendDirectChatMessage(chatMessage, client);
}
public static void Log(string message, ServerLog.MessageType type)
{
GameServer.Log(message, type);
}
public static void DispatchRespawnSub()
{
GameMain.Server.RespawnManager.DispatchShuttle();
}
public static void StartGame()
{
GameMain.Server.StartGame();
}
}
private static Vector3 CreateVector3(float x, float y, float z)
{
return new Vector3(x, y, z);
}
private static Vector4 CreateVector4(float x, float y, float z, float w)
{
return new Vector4(x, y, z, w);
}
private class LuaPlayer
partial class LuaPlayer
{
public static List<Character> GetAllCharacters()
@@ -89,22 +133,22 @@ namespace Barotrauma
public static void SetSpectatorPos(Client client, Vector2 pos)
{
}
public static void SetRadioRange(Character character, float range)
{
if(character.Inventory == null) { return; }
if (character.Inventory == null) { return; }
foreach(Item item in character.Inventory.AllItems)
foreach (Item item in character.Inventory.AllItems)
{
if(item == null) { continue; }
if (item == null) { continue; }
if(item.Name == "Headset")
if (item.Name == "Headset")
{
item.GetComponent<Items.Components.WifiComponent>().Range = range;
}
}
}
}
public static bool CheckPermission(Client client, ClientPermissions permissions)
@@ -112,521 +156,5 @@ namespace Barotrauma
return client.Permissions.HasFlag(permissions);
}
}
public class LuaGame
{
LuaSetup env;
public LuaGame(LuaSetup e)
{
env = e;
}
public bool allowWifiChat = false;
public bool overrideTraitors = false;
public bool overrideRespawnSub = false;
public bool overrideSignalRadio = false;
public bool disableSpamFilter = false;
public bool RoundStarted
{
get
{
return GameMain.Server.GameStarted;
}
}
public bool IsDedicated
{
get
{
return GameMain.Server.ServerPeer is LidgrenServerPeer;
}
}
public ServerSettings Settings => GameMain.Server.ServerSettings;
public static void SendMessage(string msg, ChatMessageType? messageType = null, Client sender = null, Character character = null)
{
GameMain.Server.SendChatMessage(msg, messageType, sender, character);
}
public static void SendMessage(string msg, int messageType, Client sender = null, Character character = null)
{
GameMain.Server.SendChatMessage(msg, (ChatMessageType)messageType, sender, character);
}
public static void SendTraitorMessage(Client client, string msg, string missionid, TraitorMessageType type)
{
GameMain.Server.SendTraitorMessage(client, msg, missionid, type);
}
public static void SendDirectChatMessage(string sendername, string text, Character sender, ChatMessageType messageType = ChatMessageType.Private, Client client = null, string iconStyle = "")
{
ChatMessage cm = ChatMessage.Create(sendername, text, messageType, sender, client);
cm.IconStyle = iconStyle;
GameMain.Server.SendDirectChatMessage(cm, client);
}
public static void SendDirectChatMessage(ChatMessage chatMessage, Client client)
{
GameMain.Server.SendDirectChatMessage(chatMessage, client);
}
public void OverrideTraitors(bool o)
{
overrideTraitors = o;
}
public void OverrideRespawnSub(bool o)
{
overrideRespawnSub = o;
}
public void AllowWifiChat(bool o)
{
allowWifiChat = o;
}
public void OverrideSignalRadio(bool o)
{
overrideSignalRadio = o;
}
public void DisableSpamFilter(bool o)
{
disableSpamFilter = o;
}
public static void Log(string message, ServerLog.MessageType type)
{
GameServer.Log(message, type);
}
public static void Explode(Vector2 pos, float range = 100, float force = 30, float damage = 30, float structureDamage = 30, float itemDamage = 30, float empStrength = 0, float ballastFloraStrength = 0)
{
new Explosion(range, force, damage, structureDamage, itemDamage, empStrength, ballastFloraStrength).Explode(pos, null);
}
public static Character Spawn(string name, Vector2 worldPos)
{
Character spawnedCharacter = null;
Vector2 spawnPosition = worldPos;
string characterLowerCase = name.ToLowerInvariant();
JobPrefab job = null;
if (!JobPrefab.Prefabs.ContainsKey(characterLowerCase))
{
job = JobPrefab.Prefabs.Find(jp => jp.Name != null && jp.Name.Equals(characterLowerCase, StringComparison.OrdinalIgnoreCase));
}
else
{
job = JobPrefab.Prefabs[characterLowerCase];
}
bool human = job != null || characterLowerCase == CharacterPrefab.HumanSpeciesName;
if (string.IsNullOrWhiteSpace(name)) { return null; }
if (human)
{
var variant = job != null ? Rand.Range(0, job.Variants, Rand.RandSync.Server) : 0;
CharacterInfo characterInfo = new CharacterInfo(CharacterPrefab.HumanSpeciesName, jobPrefab: job, variant: variant);
spawnedCharacter = Character.Create(characterInfo, spawnPosition, ToolBox.RandomSeed(8));
if (GameMain.GameSession != null)
{
//TODO: a way to select which team to spawn to?
spawnedCharacter.TeamID = Character.Controlled != null ? Character.Controlled.TeamID : CharacterTeamType.Team1;
#if CLIENT
GameMain.GameSession.CrewManager.AddCharacter(spawnedCharacter);
#endif
}
spawnedCharacter.GiveJobItems(null);
spawnedCharacter.Info.StartItemsGiven = true;
}
else
{
if (CharacterPrefab.FindBySpeciesName(name) != null)
{
spawnedCharacter = Character.Create(name, spawnPosition, ToolBox.RandomSeed(8));
}
}
return spawnedCharacter;
}
public static string SpawnItem(string name, Vector2 pos, bool inventory = false, Character character = null)
{
string error;
DebugConsole.SpawnItem(new string[] { name, inventory ? "inventory" : "cursor" }, pos, character, out error);
return error;
}
public static void RemoveItem(Item item)
{
EntitySpawner.Spawner.AddToRemoveQueue(item);
}
public static ItemPrefab GetItemPrefab(string itemNameOrId)
{
ItemPrefab itemPrefab =
(MapEntityPrefab.Find(itemNameOrId, identifier: null, showErrorMessages: false) ??
MapEntityPrefab.Find(null, identifier: itemNameOrId, showErrorMessages: false)) as ItemPrefab;
return itemPrefab;
}
public void AddItemPrefabToSpawnQueue(ItemPrefab itemPrefab, Vector2 position, DynValue spawned = null)
{
EntitySpawner.Spawner.AddToSpawnQueue(itemPrefab, position, onSpawned: (Item item) => {
if (spawned?.Type == DataType.Function) env.lua.Call(spawned, UserData.Create(item));
});
}
public void AddItemPrefabToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, DynValue spawned = null)
{
EntitySpawner.Spawner.AddToSpawnQueue(itemPrefab, inventory, onSpawned: (Item item) => {
if (spawned?.Type == DataType.Function) env.lua.Call(spawned, UserData.Create(item));
});
}
public static Submarine GetRespawnSub()
{
if (GameMain.Server.RespawnManager == null)
return null;
return GameMain.Server.RespawnManager.RespawnShuttle;
}
public static Items.Components.Steering GetSubmarineSteering(Submarine sub)
{
foreach (Item item in Item.ItemList)
{
if (item.Submarine != sub) continue;
var steering = item.GetComponent<Items.Components.Steering>();
if (steering != null)
{
return steering;
}
}
return null;
}
public static WifiComponent GetWifiComponent(Item item)
{
if (item == null) return null;
return item.GetComponent<WifiComponent>();
}
public static LightComponent GetLightComponent(Item item)
{
if (item == null) return null;
return item.GetComponent<LightComponent>();
}
public static CustomInterface GetCustomInterface(Item item)
{
if (item == null) return null;
return item.GetComponent<CustomInterface>();
}
public static Fabricator GetFabricatorComponent(Item item)
{
if (item == null) return null;
return item.GetComponent<Fabricator>();
}
public static Holdable GetHoldableComponent(Item item)
{
if (item == null) return null;
return item.GetComponent<Holdable>();
}
public static void DispatchRespawnSub()
{
GameMain.Server.RespawnManager.DispatchShuttle();
}
public static void SetRespawnSubTeam(int team)
{
GameMain.Server.RespawnManager.RespawnShuttle.TeamID = (CharacterTeamType)team;
}
public static void ExecuteCommand(string command)
{
DebugConsole.ExecuteCommand(command);
}
public static void StartGame()
{
GameMain.Server.StartGame();
}
public static Signal CreateSignal(string value, int stepsTaken = 1, Character sender = null, Item source = null, float power = 0, float strength = 1)
{
return new Signal(value, stepsTaken, sender, source, power, strength);
}
public static ContentPackage[] GetEnabledContentPackages()
{
return GameMain.Config.AllEnabledPackages.ToArray();
}
public static List<string> GetEnabledPackagesDirectlyFromFile()
{
List<string> enabledPackages = new List<string>();
XDocument doc = XMLExtensions.LoadXml("config_player.xml");
var contentPackagesElement = doc.Root.Element("contentpackages");
string coreName = contentPackagesElement.Element("core")?.GetAttributeString("name", "");
enabledPackages.Add(coreName);
XElement regularElement = contentPackagesElement.Element("regular");
List<XElement> subElements = regularElement?.Elements()?.ToList();
foreach (var subElement in subElements)
{
if (!bool.TryParse(subElement.GetAttributeString("enabled", "false"), out bool enabled) || !enabled) { continue; }
string name = subElement.GetAttributeString("name", null);
enabledPackages.Add(name);
}
return enabledPackages;
}
}
private class LuaTimer
{
public LuaSetup env;
public LuaTimer(LuaSetup e)
{
env = e;
}
public static double GetTime()
{
return Timing.TotalTime;
}
}
private class LuaRandom
{
Random random;
public LuaRandom()
{
random = new Random();
}
public int Range(int min, int max)
{
return random.Next(min, max);
}
public float RangeFloat(float min, float max)
{
double range = (double)max - (double)min;
double sample = random.NextDouble();
double scaled = (sample * range) + min;
float f = (float)scaled;
return f;
}
}
private class LuaFile
{
// TODO: SANDBOXING
public static string Read(string path)
{
return File.ReadAllText(path);
}
public static void Write(string path, string text)
{
File.WriteAllText(path, text);
}
public static bool Exists(string path)
{
return File.Exists(path);
}
public static bool DirectoryExists(string path)
{
return Directory.Exists(path);
}
public static string[] GetFiles(string path)
{
return Directory.GetFiles(path);
}
public static string[] GetDirectories(string path)
{
return Directory.GetDirectories(path);
}
public static string[] DirSearch(string sDir)
{
List<string> files = new List<string>();
try
{
foreach (string f in Directory.GetFiles(sDir))
{
files.Add(f);
}
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d))
{
files.Add(f);
}
DirSearch(d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
return files.ToArray();
}
}
private class LuaNetworking
{
public LuaSetup env;
public LuaNetworking(LuaSetup e)
{
env = e;
}
public string RequestPostHTTP(string url, string data, string contentType = "application/json")
{
try
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = contentType;
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
streamWriter.Write(data);
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
return streamReader.ReadToEnd();
}catch(Exception e)
{
return e.ToString();
}
}
public string RequestGetHTTP(string url)
{
try
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
return streamReader.ReadToEnd();
}catch(Exception e)
{
return e.ToString();
}
}
}
public class LuaHook
{
public LuaSetup env;
public LuaHook(LuaSetup e)
{
env = e;
}
public class HookFunction
{
public string name;
public string hookName;
public object function;
public HookFunction(string n, string hn, object func)
{
name = n;
hookName = hn;
function = func;
}
}
public Dictionary<string, Dictionary<string, HookFunction>> hookFunctions = new Dictionary<string, Dictionary<string, HookFunction>>();
public void Add(string name, string hookName, object function)
{
if (name == null && hookName == null && function == null) return;
if (!hookFunctions.ContainsKey(name))
hookFunctions.Add(name, new Dictionary<string, HookFunction>());
hookFunctions[name][hookName] = new HookFunction(name, hookName, function);
}
public void Remove(string name, string hookName)
{
if (name == null && hookName == null) return;
if (!hookFunctions.ContainsKey(name))
return;
if(hookFunctions[name].ContainsKey(hookName))
hookFunctions[name].Remove(hookName);
}
public object Call(string name, object[] args)
{
if (name == null) return null;
if (!hookFunctions.ContainsKey(name))
return null;
object lastResult = null;
foreach (HookFunction hf in hookFunctions[name].Values)
{
try
{
if (hf.function is Closure)
lastResult = env.lua.Call(hf.function, args);
// else if (hf.function is NLua.LuaFunction luaFunction)
// lastResult = luaFunction.Call(args);
}
catch (Exception e)
{
env.HandleLuaException(e);
}
}
return lastResult;
}
}
}
}
}
@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using MoonSharp.Interpreter;
using Microsoft.Xna.Framework;
namespace Barotrauma
{
public static class LuaCustomConverters
{
public static void RegisterAll()
{
}
}
}
@@ -1,88 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Loaders;
namespace Barotrauma
{
partial class LuaSetup {
public class LuaScriptLoader : ScriptLoaderBase
{
public LuaSetup lua;
public LuaScriptLoader(LuaSetup l)
{
lua = l;
}
public override object LoadFile(string file, Table globalContext)
{
return File.ReadAllText(file);
}
public override bool ScriptFileExists(string file)
{
return File.Exists(file);
}
public void RunFolder(string folder)
{
foreach (var str in DirSearch(folder))
{
var s = str.Replace("\\", "/");
if (s.EndsWith(".lua"))
{
lua.PrintMessage(s);
try
{
lua.DoFile(s);
}
catch (Exception e)
{
lua.HandleLuaException(e);
}
}
}
}
static string[] DirSearch(string sDir)
{
List<string> files = new List<string>();
try
{
foreach (string f in Directory.GetFiles(sDir))
{
files.Add(f);
}
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d))
{
files.Add(f);
}
DirSearch(d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
return files.ToArray();
}
}
}
}
@@ -1,343 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Barotrauma.Networking;
using MoonSharp.Interpreter;
using Microsoft.Xna.Framework;
using System.Threading.Tasks;
using Barotrauma.Items.Components;
using System.Diagnostics;
namespace Barotrauma
{
partial class LuaSetup
{
public static LuaSetup luaSetup;
public Script lua;
public LuaHook hook;
public LuaGame game;
public LuaScriptLoader luaScriptLoader;
public void HandleLuaException(Exception ex)
{
if (ex is InterpreterException)
{
if (((InterpreterException)ex).DecoratedMessage == null)
PrintMessage(((InterpreterException)ex).Message);
else
PrintMessage(((InterpreterException)ex).DecoratedMessage);
}
else
{
PrintMessage(ex.ToString());
}
}
public void PrintMessage(object message)
{
if (message == null) { message = "nil"; }
Console.WriteLine(message.ToString());
if (GameMain.Server != null)
{
foreach (var c in GameMain.Server.ConnectedClients)
{
GameMain.Server.SendDirectChatMessage(message.ToString(), c, ChatMessageType.Console);
}
GameServer.Log("[LUA] " + message.ToString(), ServerLog.MessageType.ServerMessage);
}
}
public void PrintMessageNoLog(object message)
{
if (message == null) { message = "nil"; }
Console.WriteLine(message.ToString());
}
public DynValue DoString(string code, Table globalContext = null, string codeStringFriendly = null)
{
try
{
return lua.DoString(code, globalContext, codeStringFriendly);
}
catch (Exception e)
{
HandleLuaException(e);
}
return null;
}
public DynValue DoFile(string file, Table globalContext = null, string codeStringFriendly = null)
{
try
{
return lua.DoFile(file, globalContext, codeStringFriendly);
}
catch (Exception e)
{
HandleLuaException(e);
}
return null;
}
public DynValue LoadString(string file, Table globalContext = null, string codeStringFriendly = null)
{
try
{
return lua.LoadString(file, globalContext, codeStringFriendly);
}
catch (Exception e)
{
HandleLuaException(e);
}
return null;
}
public DynValue LoadFile(string file, Table globalContext = null, string codeStringFriendly = null)
{
try
{
return lua.LoadFile(file, globalContext, codeStringFriendly);
}
catch (Exception e)
{
HandleLuaException(e);
}
return null;
}
public DynValue Require(string modname, Table globalContext)
{
try
{
return lua.Call(lua.RequireModule(modname, globalContext));
}
catch (Exception e)
{
HandleLuaException(e);
}
return null;
}
public static DynValue CreateUserDataSafe(object o)
{
if (o == null)
return DynValue.Nil;
return UserData.Create(o);
}
public object CallFunction(object function, object[] arguments)
{
return lua.Call(function, arguments);
}
public void SetModulePaths(string[] str)
{
luaScriptLoader.ModulePaths = str;
}
public float TestFunction(float value)
{
return value * 2;
}
public void Initialize()
{
luaSetup = this;
PrintMessage("Lua!");
luaScriptLoader = new LuaScriptLoader(this);
luaScriptLoader.ModulePaths = new string[] { };
LuaCustomConverters.RegisterAll();
UserData.RegisterType<TraitorMessageType>();
UserData.RegisterType<JobPrefab>();
UserData.RegisterType<CharacterInfo>();
UserData.RegisterType<Rectangle>();
UserData.RegisterType<Point>();
UserData.RegisterType<Level.InterestingPosition>();
UserData.RegisterType<Level.PositionType>();
UserData.RegisterType<Level>();
UserData.RegisterType<Items.Components.Steering>();
UserData.RegisterType<ServerLog.MessageType>();
UserData.RegisterType<SpawnType>();
UserData.RegisterType<ChatMessageType>();
UserData.RegisterType<WayPoint>();
UserData.RegisterType<Character>();
UserData.RegisterType<Item>();
UserData.RegisterType<Submarine>();
UserData.RegisterType<Client>();
UserData.RegisterType<LuaPlayer>();
UserData.RegisterType<LuaHook>();
UserData.RegisterType<LuaGame>();
UserData.RegisterType<LuaRandom>();
UserData.RegisterType<LuaTimer>();
UserData.RegisterType<LuaFile>();
UserData.RegisterType<LuaNetworking>();
UserData.RegisterType<Vector2>();
UserData.RegisterType<Vector3>();
UserData.RegisterType<Vector4>();
UserData.RegisterType<CauseOfDeathType>();
UserData.RegisterType<AfflictionPrefab>();
UserData.RegisterType<Affliction>();
UserData.RegisterType<CharacterHealth>();
UserData.RegisterType<AnimController>();
UserData.RegisterType<Limb>();
UserData.RegisterType<Ragdoll>();
UserData.RegisterType<ChatMessage>();
UserData.RegisterType<CharacterHealth.LimbHealth>();
UserData.RegisterType<InputType>();
UserData.RegisterType<AttackResult>();
UserData.RegisterType<Entity>();
UserData.RegisterType<MapEntity>();
UserData.RegisterType<MapEntityPrefab>();
UserData.RegisterType<CauseOfDeath>();
UserData.RegisterType<CharacterTeamType>();
UserData.RegisterType<Signal>();
UserData.RegisterType<Connection>();
UserData.RegisterType<ItemComponent>();
UserData.RegisterType<WifiComponent>();
UserData.RegisterType<LightComponent>();
UserData.RegisterType<Holdable>();
UserData.RegisterType<CustomInterface>();
UserData.RegisterType<Inventory>();
UserData.RegisterType<ItemContainer>();
UserData.RegisterType<PowerContainer>();
UserData.RegisterType<Pickable>();
UserData.RegisterType<CharacterInventory>();
UserData.RegisterType<Hull>();
UserData.RegisterType<Gap>();
UserData.RegisterType<PhysicsBody>();
UserData.RegisterType<SubmarineBody>();
UserData.RegisterType<InvSlotType>();
UserData.RegisterType<ItemPrefab>();
UserData.RegisterType<SerializableProperty>();
UserData.RegisterType<StatusEffect>();
UserData.RegisterType<CustomInterface.CustomInterfaceElement>();
UserData.RegisterType<FireSource>();
UserData.RegisterType<Fabricator>();
UserData.RegisterType<Pair<JobPrefab, int>>();
UserData.RegisterType<ContentPackage>();
UserData.RegisterType<SubmarineInfo>();
UserData.RegisterType<SubmarineBody>();
UserData.RegisterType<Explosion>();
UserData.RegisterType<AIController>();
UserData.RegisterType<EnemyAIController>();
UserData.RegisterType<HumanAIController>();
UserData.RegisterType<AITarget>();
UserData.RegisterType<AITargetMemory>();
UserData.RegisterType<ServerSettings>();
lua = new Script(CoreModules.Preset_SoftSandbox);
lua.Options.DebugPrint = PrintMessage;
lua.Options.ScriptLoader = luaScriptLoader;
hook = new LuaHook(this);
game = new LuaGame(this);
lua.Globals["TestFunction"] = (Func<float, float>)TestFunction;
lua.Globals["printNoLog"] = (Action<object>)PrintMessageNoLog;
lua.Globals["dofile"] = (Func<string, Table, string, DynValue>)DoFile;
lua.Globals["loadfile"] = (Func<string, Table, string, DynValue>)LoadFile;
lua.Globals["require"] = (Func<string, Table, DynValue>)Require;
lua.Globals["dostring"] = (Func<string, Table, string, DynValue>)DoString;
lua.Globals["load"] = (Func<string, Table, string, DynValue>)LoadString;
lua.Globals["setmodulepaths"] = (Action<string[]>)SetModulePaths;
lua.Globals["Player"] = new LuaPlayer();
lua.Globals["Game"] = game;
lua.Globals["Hook"] = hook;
lua.Globals["Random"] = new LuaRandom();
lua.Globals["Timer"] = new LuaTimer(this);
lua.Globals["File"] = UserData.CreateStatic<LuaFile>();
lua.Globals["Networking"] = new LuaNetworking(this);
lua.Globals["WayPoint"] = UserData.CreateStatic<WayPoint>();
lua.Globals["SpawnType"] = UserData.CreateStatic<SpawnType>();
lua.Globals["ChatMessageType"] = UserData.CreateStatic<ChatMessageType>();
lua.Globals["ServerLog_MessageType"] = UserData.CreateStatic<ServerLog.MessageType>();
lua.Globals["Submarine"] = UserData.CreateStatic<Submarine>();
lua.Globals["Client"] = UserData.CreateStatic<Client>();
lua.Globals["Character"] = UserData.CreateStatic<Character>();
lua.Globals["CharacterInfo"] = UserData.CreateStatic<CharacterInfo>();
lua.Globals["Item"] = UserData.CreateStatic<Item>();
lua.Globals["ItemPrefab"] = UserData.CreateStatic<ItemPrefab>();
lua.Globals["Level"] = UserData.CreateStatic<Level>();
lua.Globals["PositionType"] = UserData.CreateStatic<Level.PositionType>();
lua.Globals["JobPrefab"] = UserData.CreateStatic<JobPrefab>();
lua.Globals["TraitorMessageType"] = UserData.CreateStatic<TraitorMessageType>();
lua.Globals["CauseOfDeathType"] = UserData.CreateStatic<CauseOfDeathType>();
lua.Globals["AfflictionPrefab"] = UserData.CreateStatic<AfflictionPrefab>();
lua.Globals["CharacterTeamType"] = UserData.CreateStatic<CharacterTeamType>();
lua.Globals["Vector2"] = UserData.CreateStatic<Vector2>();
lua.Globals["Vector3"] = UserData.CreateStatic<Vector3>();
lua.Globals["Vector4"] = UserData.CreateStatic<Vector3>();
lua.Globals["CreateVector2"] = (Func<float, float, Vector2>)CreateVector2;
lua.Globals["CreateVector3"] = (Func<float, float, float, Vector3>)CreateVector3;
lua.Globals["CreateVector4"] = (Func<float, float, float, float, Vector4>)CreateVector4;
lua.Globals["ChatMessage"] = UserData.CreateStatic<ChatMessage>();
lua.Globals["Hull"] = UserData.CreateStatic<Hull>();
lua.Globals["InvSlotType"] = UserData.CreateStatic<InvSlotType>();
lua.Globals["Gap"] = UserData.CreateStatic<Gap>();
lua.Globals["ContentPackage"] = UserData.CreateStatic<ContentPackage>();
lua.Globals["ClientPermissions"] = UserData.CreateStatic<ClientPermissions>();
lua.Globals["Signal"] = UserData.CreateStatic<Signal>();
if (File.Exists("Lua/MoonsharpSetup.lua")) // try the default loader
DoFile("Lua/MoonsharpSetup.lua");
else if (File.Exists("Mods/LuaForBarotrauma/Lua/MoonsharpSetup.lua")) // in case its the workshop version
DoFile("Mods/LuaForBarotrauma/Lua/MoonsharpSetup.lua");
else // fallback to c# script loading
{
List<string> modulePaths = new List<string>();
foreach (string d in Directory.GetDirectories("Mods"))
{
modulePaths.Add(d + "/Lua/?.lua");
if (Directory.Exists(d + "/Lua/Autorun"))
{
luaScriptLoader.RunFolder(d + "/Lua/Autorun");
}
}
luaScriptLoader.ModulePaths = modulePaths.ToArray();
}
}
public LuaSetup()
{
}
}
}
@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Barotrauma
{
partial class LuaSetup
{
//private void NLua_HookException(object sender, NLua.Event.HookExceptionEventArgs e)
//{
// HandleLuaException(e.Exception);
//}
}
}