move most of the registration code to Lua, include harmony, add useful perf methods to Time and a more useful(but still useless) error handling in the hook call
This commit is contained in:
@@ -11,6 +11,10 @@ using System.Net;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using MoonSharp.Interpreter.Interop;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -32,7 +36,82 @@ namespace Barotrauma
|
||||
return new Vector4(x, y, z, w);
|
||||
}
|
||||
|
||||
private partial class LuaPlayer
|
||||
partial class LuaUserData
|
||||
{
|
||||
public static Type GetType(string typeName)
|
||||
{
|
||||
var type = Type.GetType(typeName);
|
||||
if (type != null) return type;
|
||||
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
type = a.GetType(typeName);
|
||||
if (type != null)
|
||||
return type;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IUserDataDescriptor RegisterType(string typeName)
|
||||
{
|
||||
Type type = GetType(typeName);
|
||||
|
||||
MethodInfo method = typeof(UserData).GetMethod(nameof(UserData.RegisterType), new Type[2] { typeof(InteropAccessMode), typeof(string) });
|
||||
MethodInfo generic = method.MakeGenericMethod(type);
|
||||
return (IUserDataDescriptor)generic.Invoke(null, new object[] { null, null });
|
||||
}
|
||||
|
||||
public static object CreateStatic(string typeName)
|
||||
{
|
||||
Type type = GetType(typeName);
|
||||
|
||||
MethodInfo method = typeof(UserData).GetMethod(nameof(UserData.CreateStatic), 1, new Type[0]);
|
||||
MethodInfo generic = method.MakeGenericMethod(type);
|
||||
return generic.Invoke(null, null);
|
||||
}
|
||||
|
||||
public static void AddCallMetaMember(IUserDataDescriptor IUDD)
|
||||
{
|
||||
var descriptor = (StandardUserDataDescriptor)IUDD;
|
||||
descriptor.RemoveMetaMember("__call");
|
||||
descriptor.AddMetaMember("__call", new ObjectCallbackMemberDescriptor("__call", LuaSetup.luaSetup.HandleCall));
|
||||
}
|
||||
|
||||
public static void MakeFieldAccessible(IUserDataDescriptor IUUD, string methodName)
|
||||
{
|
||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||
var field = IUUD.Type.GetField(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
descriptor.RemoveMember(methodName);
|
||||
descriptor.AddMember(methodName, new FieldMemberDescriptor(field, InteropAccessMode.Default));
|
||||
}
|
||||
|
||||
public static void MakeMethodAccessible(IUserDataDescriptor IUUD, string methodName)
|
||||
{
|
||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||
var method = IUUD.Type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
descriptor.RemoveMember(methodName);
|
||||
descriptor.AddMember(methodName, new MethodMemberDescriptor(method, InteropAccessMode.Default));
|
||||
}
|
||||
|
||||
public static void AddMethod(IUserDataDescriptor IUUD, string methodName, object function)
|
||||
{
|
||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||
descriptor.RemoveMember(methodName);
|
||||
descriptor.AddMember(methodName, new ObjectCallbackMemberDescriptor(methodName, (object arg1, ScriptExecutionContext arg2, CallbackArguments arg3) =>
|
||||
{
|
||||
if (luaSetup != null)
|
||||
return luaSetup.CallFunction(function, arg3.GetArray());
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
|
||||
public static void RemoveMember(IUserDataDescriptor IUUD, string memberName)
|
||||
{
|
||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||
descriptor.RemoveMember(memberName);
|
||||
}
|
||||
}
|
||||
|
||||
public partial class LuaPlayer
|
||||
{
|
||||
|
||||
}
|
||||
@@ -322,8 +401,10 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
|
||||
private partial class LuaTimer
|
||||
public partial class LuaTimer
|
||||
{
|
||||
public static long LastUpdateTime = 0;
|
||||
|
||||
public LuaSetup env;
|
||||
|
||||
public LuaTimer(LuaSetup e)
|
||||
@@ -331,12 +412,27 @@ namespace Barotrauma
|
||||
env = e;
|
||||
}
|
||||
|
||||
public static double Time
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetTime();
|
||||
}
|
||||
}
|
||||
|
||||
public static double GetTime()
|
||||
{
|
||||
return Timing.TotalTime;
|
||||
}
|
||||
|
||||
public static float GetUsageMemory()
|
||||
{
|
||||
Process proc = Process.GetCurrentProcess();
|
||||
float memory = MathF.Round(proc.PrivateMemorySize64 / (1024 * 1024), 2);
|
||||
proc.Dispose();
|
||||
|
||||
return memory;
|
||||
}
|
||||
}
|
||||
|
||||
private partial class LuaRandom
|
||||
@@ -592,6 +688,7 @@ namespace Barotrauma
|
||||
public LuaHook(LuaSetup e)
|
||||
{
|
||||
env = e;
|
||||
methodNameToHookName = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public class HookFunction
|
||||
@@ -608,7 +705,60 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, Dictionary<string, HookFunction>> hookFunctions = new Dictionary<string, Dictionary<string, HookFunction>>();
|
||||
private Dictionary<string, Dictionary<string, HookFunction>> hookFunctions = new Dictionary<string, Dictionary<string, HookFunction>>();
|
||||
|
||||
private static Dictionary<string, string> methodNameToHookName;
|
||||
|
||||
public enum HookMethodType
|
||||
{
|
||||
Before, After
|
||||
}
|
||||
|
||||
static void HookLuaPatchPrefix(MethodBase __originalMethod)
|
||||
{
|
||||
luaSetup.hook.Call(methodNameToHookName[__originalMethod.Name]);
|
||||
}
|
||||
|
||||
static void HookLuaPatchPostfix(MethodBase __originalMethod)
|
||||
{
|
||||
luaSetup.hook.Call(methodNameToHookName[__originalMethod.Name]);
|
||||
}
|
||||
|
||||
// not very useful until i find a way to use the transpiler to inject arguments into the call
|
||||
|
||||
public void HookMethod(string className, string methodName, string hookName, HookMethodType hookMethodType = HookMethodType.Before)
|
||||
{
|
||||
var classType = Type.GetType(className);
|
||||
var methodInfos = classType.GetMethods();
|
||||
HarmonyMethod harmonyMethod = new HarmonyMethod();
|
||||
|
||||
if (hookMethodType == HookMethodType.Before)
|
||||
{
|
||||
harmonyMethod = new HarmonyMethod(GetType().GetMethod("HookLuaPatchPrefix", BindingFlags.NonPublic | BindingFlags.Static));
|
||||
}
|
||||
else if (hookMethodType == HookMethodType.After)
|
||||
{
|
||||
harmonyMethod = new HarmonyMethod(GetType().GetMethod("HookLuaPatchPostfix", BindingFlags.NonPublic | BindingFlags.Static));
|
||||
}
|
||||
|
||||
var foundAny = false;
|
||||
|
||||
foreach (var methodInfo in methodInfos)
|
||||
{
|
||||
if(methodInfo.Name == methodName)
|
||||
{
|
||||
if (hookMethodType == HookMethodType.Before)
|
||||
env.harmony.Patch(methodInfo, harmonyMethod);
|
||||
else if (hookMethodType == HookMethodType.After)
|
||||
env.harmony.Patch(methodInfo, postfix: harmonyMethod);
|
||||
|
||||
foundAny = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(foundAny)
|
||||
methodNameToHookName.Add(methodName, hookName);
|
||||
}
|
||||
|
||||
public void Add(string name, string hookName, object function)
|
||||
{
|
||||
@@ -632,7 +782,7 @@ namespace Barotrauma
|
||||
hookFunctions[name].Remove(hookName);
|
||||
}
|
||||
|
||||
public object Call(string name, object[] args)
|
||||
public object Call(string name, params object[] args)
|
||||
{
|
||||
if (env == null) return null;
|
||||
if (name == null) return null;
|
||||
@@ -653,12 +803,16 @@ namespace Barotrauma
|
||||
if (!result.IsNil())
|
||||
lastResult = result;
|
||||
}
|
||||
//else if (hf.function is NLua.LuaFunction luaFunction)
|
||||
// lastResult = luaFunction.Call(args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
env.HandleLuaException(e);
|
||||
StringBuilder argsSb = new StringBuilder();
|
||||
foreach(var arg in args)
|
||||
{
|
||||
argsSb.Append(arg + " ");
|
||||
}
|
||||
|
||||
env.HandleLuaException(e, $"Error in Hook '{name}'->'{hf.hookName}', with args '{argsSb}'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ using MoonSharp.Interpreter.Interop;
|
||||
using System.Reflection;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using System.IO.Compression;
|
||||
using HarmonyLib;
|
||||
|
||||
#if CLIENT
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
@@ -31,11 +32,15 @@ namespace Barotrauma
|
||||
public LuaHook hook;
|
||||
public LuaGame game;
|
||||
public LuaNetworking networking;
|
||||
public Harmony harmony;
|
||||
|
||||
public LuaScriptLoader luaScriptLoader;
|
||||
|
||||
public void HandleLuaException(Exception ex)
|
||||
public void HandleLuaException(Exception ex, string extra = "")
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(extra))
|
||||
PrintMessage(extra);
|
||||
|
||||
if (ex is InterpreterException)
|
||||
{
|
||||
if (((InterpreterException)ex).DecoratedMessage == null)
|
||||
@@ -197,8 +202,9 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
// messy solution
|
||||
private object HandleCall(object arg1, ScriptExecutionContext arg2, CallbackArguments arg3)
|
||||
public object HandleCall(object arg1, ScriptExecutionContext arg2, CallbackArguments arg3)
|
||||
{
|
||||
|
||||
var what = arg3.RawGet(0, true);
|
||||
|
||||
var code = "return " + what.UserData.Descriptor.Type.Name + ".__new(";
|
||||
@@ -230,12 +236,6 @@ namespace Barotrauma
|
||||
return null;
|
||||
}
|
||||
|
||||
private void AddCallMetaMember(IUserDataDescriptor IUDD)
|
||||
{
|
||||
var descriptor = (StandardUserDataDescriptor)IUDD;
|
||||
descriptor.RemoveMetaMember("__call");
|
||||
descriptor.AddMetaMember("__call", new ObjectCallbackMemberDescriptor("__call", HandleCall));
|
||||
}
|
||||
|
||||
#if SERVER
|
||||
public static void InstallClientSideLua()
|
||||
@@ -301,6 +301,17 @@ namespace Barotrauma
|
||||
|
||||
LuaCustomConverters.RegisterAll();
|
||||
|
||||
lua = new Script(CoreModules.Preset_SoftSandbox);
|
||||
lua.Options.DebugPrint = PrintMessage;
|
||||
lua.Options.ScriptLoader = luaScriptLoader;
|
||||
|
||||
harmony = new Harmony("com.LuaForBarotrauma");
|
||||
harmony.UnpatchAll();
|
||||
|
||||
hook = new LuaHook(this);
|
||||
game = new LuaGame(this);
|
||||
networking = new LuaNetworking(this);
|
||||
|
||||
UserData.RegisterType<LuaPlayer>();
|
||||
UserData.RegisterType<LuaHook>();
|
||||
UserData.RegisterType<LuaGame>();
|
||||
@@ -308,83 +319,8 @@ namespace Barotrauma
|
||||
UserData.RegisterType<LuaTimer>();
|
||||
UserData.RegisterType<LuaFile>();
|
||||
UserData.RegisterType<LuaNetworking>();
|
||||
|
||||
UserData.RegisterType<CauseOfDeathType>();
|
||||
UserData.RegisterType<Level.InterestingPosition>();
|
||||
UserData.RegisterType<Level.PositionType>();
|
||||
UserData.RegisterType<TraitorMessageType>();
|
||||
UserData.RegisterType<SpawnType>();
|
||||
UserData.RegisterType<ChatMessageType>();
|
||||
UserData.RegisterType<InputType>();
|
||||
|
||||
UserData.RegisterType<JobPrefab>();
|
||||
UserData.RegisterType<Job>();
|
||||
UserData.RegisterType<Point>();
|
||||
UserData.RegisterType<Level>();
|
||||
UserData.RegisterType<Items.Components.Steering>();
|
||||
UserData.RegisterType<ServerLog.MessageType>();
|
||||
UserData.RegisterType<WayPoint>();
|
||||
UserData.RegisterType<Character>();
|
||||
UserData.RegisterType<Item>();
|
||||
UserData.RegisterType<Submarine>();
|
||||
UserData.RegisterType<Client>();
|
||||
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<AttackResult>();
|
||||
UserData.RegisterType<Entity>();
|
||||
UserData.RegisterType<EntitySpawner>();
|
||||
UserData.RegisterType<MapEntity>();
|
||||
UserData.RegisterType<MapEntityPrefab>();
|
||||
UserData.RegisterType<CauseOfDeath>();
|
||||
UserData.RegisterType<CharacterTeamType>();
|
||||
UserData.RegisterType<Connection>();
|
||||
UserData.RegisterType<CharacterInventory>();
|
||||
UserData.RegisterType<Hull>();
|
||||
UserData.RegisterType<Gap>();
|
||||
UserData.RegisterType<PhysicsBody>();
|
||||
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<SubmarineBody>();
|
||||
UserData.RegisterType<Explosion>();
|
||||
UserData.RegisterType<ServerSettings>();
|
||||
|
||||
UserData.RegisterType<ItemComponent>();
|
||||
UserData.RegisterType<WifiComponent>();
|
||||
UserData.RegisterType<LightComponent>();
|
||||
UserData.RegisterType<Holdable>();
|
||||
UserData.RegisterType<CustomInterface>();
|
||||
UserData.RegisterType<Inventory>();
|
||||
UserData.RegisterType<ItemInventory>();
|
||||
UserData.RegisterType<ItemContainer>();
|
||||
UserData.RegisterType<PowerContainer>();
|
||||
UserData.RegisterType<Pickable>();
|
||||
UserData.RegisterType<Reactor>();
|
||||
|
||||
UserData.RegisterType<AIController>();
|
||||
UserData.RegisterType<EnemyAIController>();
|
||||
UserData.RegisterType<HumanAIController>();
|
||||
UserData.RegisterType<AICharacter>();
|
||||
UserData.RegisterType<AITarget>();
|
||||
UserData.RegisterType<AITargetMemory>();
|
||||
|
||||
UserData.RegisterType<TalentPrefab>();
|
||||
UserData.RegisterType<TalentOption>();
|
||||
UserData.RegisterType<TalentSubTree>();
|
||||
UserData.RegisterType<TalentTree>();
|
||||
UserData.RegisterType<CharacterTalent>();
|
||||
UserData.RegisterType<LuaUserData>();
|
||||
UserData.RegisterType<IUserDataDescriptor>();
|
||||
|
||||
UserData.RegisterType<PrefabCollection<ItemPrefab>>();
|
||||
UserData.RegisterType<PrefabCollection<JobPrefab>>();
|
||||
@@ -392,90 +328,10 @@ namespace Barotrauma
|
||||
UserData.RegisterType<PrefabCollection<AfflictionPrefab>>();
|
||||
UserData.RegisterType<PrefabCollection<TalentPrefab>>();
|
||||
|
||||
UserData.RegisterType<Screen>();
|
||||
UserData.RegisterType<GameScreen>();
|
||||
UserData.RegisterType<GameSession>();
|
||||
UserData.RegisterType<CampaignMode>();
|
||||
UserData.RegisterType<Pair<JobPrefab, int>>();
|
||||
|
||||
{
|
||||
var descriptor = (StandardUserDataDescriptor)UserData.RegisterType<NetLobbyScreen>();
|
||||
var type = typeof(NetLobbyScreen);
|
||||
var field = type.GetField("subs", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
descriptor.RemoveMember("subs");
|
||||
descriptor.AddMember("subs", new FieldMemberDescriptor(field, InteropAccessMode.Default));
|
||||
}
|
||||
|
||||
UserData.RegisterType<IWriteMessage>();
|
||||
UserData.RegisterType<IReadMessage>();
|
||||
UserData.RegisterType<ServerPacketHeader>();
|
||||
UserData.RegisterType<ClientPacketHeader>();
|
||||
UserData.RegisterType<DeliveryMethod>();
|
||||
UserData.RegisterType<RelayComponent>();
|
||||
UserData.RegisterType<MemoryComponent>();
|
||||
UserData.RegisterType<Engine>();
|
||||
UserData.RegisterType<Rand.RandSync>();
|
||||
UserData.RegisterType<Skill>();
|
||||
UserData.RegisterType<SkillPrefab>();
|
||||
UserData.RegisterType<TraitorMissionPrefab>();
|
||||
UserData.RegisterType<TraitorMissionResult>();
|
||||
|
||||
UserData.RegisterType<World>();
|
||||
UserData.RegisterType<Fixture>();
|
||||
UserData.RegisterType(typeof(Physics));
|
||||
|
||||
UserData.RegisterType<Camera>();
|
||||
UserData.RegisterType<InputType>();
|
||||
UserData.RegisterType<Key>();
|
||||
|
||||
AddCallMetaMember(UserData.RegisterType<Vector2>());
|
||||
AddCallMetaMember(UserData.RegisterType<Vector3>());
|
||||
AddCallMetaMember(UserData.RegisterType<Vector4>());
|
||||
AddCallMetaMember(UserData.RegisterType<CharacterInfo>());
|
||||
AddCallMetaMember(UserData.RegisterType<Signal>());
|
||||
AddCallMetaMember(UserData.RegisterType<Color>());
|
||||
AddCallMetaMember(UserData.RegisterType<Point>());
|
||||
AddCallMetaMember(UserData.RegisterType<Rectangle>());
|
||||
AddCallMetaMember(UserData.RegisterType<SubmarineInfo>());
|
||||
|
||||
#if SERVER
|
||||
UserData.RegisterType<Traitor>();
|
||||
UserData.RegisterType<Traitor.TraitorMission>();
|
||||
#elif CLIENT
|
||||
UserData.RegisterType<LuaGUI>();
|
||||
UserData.RegisterType<ChatBox>();
|
||||
UserData.RegisterType<GUICanvas>();
|
||||
UserData.RegisterType<Anchor>();
|
||||
UserData.RegisterType<Alignment>();
|
||||
UserData.RegisterType<Pivot>();
|
||||
UserData.RegisterType<Texture2D>();
|
||||
UserData.RegisterType<KeyEventArgs>();
|
||||
UserData.RegisterType<Key>();
|
||||
UserData.RegisterType<Keys>();
|
||||
UserData.RegisterType<PlayerInput>();
|
||||
|
||||
AddCallMetaMember(UserData.RegisterType<Sprite>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUILayoutGroup>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUITextBox>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUITextBlock>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUIButton>());
|
||||
AddCallMetaMember(UserData.RegisterType<RectTransform>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUIFrame>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUITickBox>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUICustomComponent>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUIImage>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUIListBox>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUIScrollBar>());
|
||||
AddCallMetaMember(UserData.RegisterType<GUIDropDown>());
|
||||
#endif
|
||||
lua = new Script(CoreModules.Preset_SoftSandbox);
|
||||
|
||||
lua.Options.DebugPrint = PrintMessage;
|
||||
|
||||
lua.Options.ScriptLoader = luaScriptLoader;
|
||||
|
||||
hook = new LuaHook(this);
|
||||
game = new LuaGame(this);
|
||||
networking = new LuaNetworking(this);
|
||||
lua.Globals["setmodulepaths"] = (Action<string[]>)SetModulePaths;
|
||||
|
||||
lua.Globals["TestFunction"] = (Func<float, float>)TestFunction;
|
||||
|
||||
@@ -487,9 +343,8 @@ namespace Barotrauma
|
||||
|
||||
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["LuaUserData"] = UserData.CreateStatic<LuaUserData>();
|
||||
lua.Globals["Player"] = new LuaPlayer();
|
||||
lua.Globals["Game"] = game;
|
||||
lua.Globals["Hook"] = hook;
|
||||
@@ -497,56 +352,17 @@ namespace Barotrauma
|
||||
lua.Globals["Timer"] = new LuaTimer(this);
|
||||
lua.Globals["File"] = UserData.CreateStatic<LuaFile>();
|
||||
lua.Globals["Networking"] = networking;
|
||||
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<Vector4>();
|
||||
lua.Globals["Color"] = UserData.CreateStatic<Color>();
|
||||
lua.Globals["Point"] = UserData.CreateStatic<Point>();
|
||||
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>();
|
||||
lua.Globals["DeliveryMethod"] = UserData.CreateStatic<DeliveryMethod>();
|
||||
lua.Globals["ClientPacketHeader"] = UserData.CreateStatic<ClientPacketHeader>();
|
||||
lua.Globals["ServerPacketHeader"] = UserData.CreateStatic<ServerPacketHeader>();
|
||||
lua.Globals["RandSync"] = UserData.CreateStatic<Rand.RandSync>();
|
||||
lua.Globals["SubmarineInfo"] = UserData.CreateStatic<SubmarineInfo>();
|
||||
lua.Globals["Rectangle"] = UserData.CreateStatic<Rectangle>();
|
||||
lua.Globals["Entity"] = UserData.CreateStatic<Entity>();
|
||||
lua.Globals["Physics"] = UserData.CreateStatic(typeof(Physics));
|
||||
|
||||
// obsolete
|
||||
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;
|
||||
|
||||
#if SERVER
|
||||
|
||||
#elif CLIENT
|
||||
lua.Globals["GUI"] = new LuaGUI(this);
|
||||
lua.Globals["Sprite"] = UserData.CreateStatic<Sprite>();
|
||||
lua.Globals["Keys"] = UserData.CreateStatic<Keys>();
|
||||
lua.Globals["PlayerInput"] = UserData.CreateStatic<PlayerInput>();
|
||||
#endif
|
||||
// obsolete
|
||||
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;
|
||||
|
||||
bool isServer = true;
|
||||
|
||||
@@ -561,13 +377,13 @@ namespace Barotrauma
|
||||
|
||||
// LuaDocs.GenerateDocs(typeof(EntitySpawner));
|
||||
|
||||
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");
|
||||
if (File.Exists("Lua/LuaSetup.lua")) // try the default loader
|
||||
DoFile("Lua/LuaSetup.lua");
|
||||
else if (File.Exists("Mods/LuaForBarotrauma/Lua/LuaSetup.lua")) // in case its the workshop version
|
||||
DoFile("Mods/LuaForBarotrauma/Lua/LuaSetup.lua");
|
||||
else // fallback to c# script loading
|
||||
{
|
||||
PrintMessage("Lua/MoonSharp.lua not found, loading Mods directly, things can break!");
|
||||
PrintMessage("Lua/LuaSetup.lua not found, loading Mods directly, things can break!");
|
||||
|
||||
List<string> modulePaths = new List<string>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user