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:
@@ -121,6 +121,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Lib.Harmony" Version="2.1.1" />
|
||||||
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
||||||
<PackageReference Include="NVorbis" Version="0.8.6" />
|
<PackageReference Include="NVorbis" Version="0.8.6" />
|
||||||
<PackageReference Include="RestSharp" Version="106.6.10" />
|
<PackageReference Include="RestSharp" Version="106.6.10" />
|
||||||
|
|||||||
@@ -122,6 +122,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Lib.Harmony" Version="2.1.1" />
|
||||||
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
||||||
<PackageReference Include="NVorbis" Version="0.8.6" />
|
<PackageReference Include="NVorbis" Version="0.8.6" />
|
||||||
<PackageReference Include="RestSharp" Version="106.6.10" />
|
<PackageReference Include="RestSharp" Version="106.6.10" />
|
||||||
|
|||||||
@@ -125,6 +125,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Lib.Harmony" Version="2.1.1" />
|
||||||
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
||||||
<PackageReference Include="NVorbis" Version="0.8.6" />
|
<PackageReference Include="NVorbis" Version="0.8.6" />
|
||||||
<PackageReference Include="RestSharp" Version="106.6.10" />
|
<PackageReference Include="RestSharp" Version="106.6.10" />
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
<ProjectReference Include="..\..\Libraries\Lidgren.Network\Lidgren.NetStandard.csproj" AdditionalProperties="Configuration=Debug" />
|
<ProjectReference Include="..\..\Libraries\Lidgren.Network\Lidgren.NetStandard.csproj" AdditionalProperties="Configuration=Debug" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Lib.Harmony" Version="2.1.1" />
|
||||||
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@
|
|||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Lib.Harmony" Version="2.1.1" />
|
||||||
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Target Name="GetGitRevision" BeforeTargets="WriteGitRevision" Condition="'$(BuildHash)' == ''">
|
<Target Name="GetGitRevision" BeforeTargets="WriteGitRevision" Condition="'$(BuildHash)' == ''">
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
DebugConsole.NewMessage("WARNING: Stopwatch frequency under 1500 ticks per second. Expect significant syncing accuracy issues.", Color.Yellow);
|
DebugConsole.NewMessage("WARNING: Stopwatch frequency under 1500 ticks per second. Expect significant syncing accuracy issues.", Color.Yellow);
|
||||||
}
|
}
|
||||||
|
Stopwatch performanceMeasurement = new Stopwatch();
|
||||||
stopwatch = Stopwatch.StartNew();
|
stopwatch = Stopwatch.StartNew();
|
||||||
long prevTicks = stopwatch.ElapsedTicks;
|
long prevTicks = stopwatch.ElapsedTicks;
|
||||||
while (ShouldRun)
|
while (ShouldRun)
|
||||||
@@ -380,6 +380,8 @@ namespace Barotrauma
|
|||||||
prevTicks = currTicks;
|
prevTicks = currTicks;
|
||||||
while (Timing.Accumulator >= Timing.Step)
|
while (Timing.Accumulator >= Timing.Step)
|
||||||
{
|
{
|
||||||
|
performanceMeasurement.Start();
|
||||||
|
|
||||||
Timing.TotalTime += Timing.Step;
|
Timing.TotalTime += Timing.Step;
|
||||||
DebugConsole.Update();
|
DebugConsole.Update();
|
||||||
if (GameSession?.GameMode == null || !GameSession.GameMode.Paused)
|
if (GameSession?.GameMode == null || !GameSession.GameMode.Paused)
|
||||||
@@ -393,6 +395,9 @@ namespace Barotrauma
|
|||||||
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
|
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
|
||||||
|
|
||||||
GameMain.Lua.hook.Call("think", new object[] { });
|
GameMain.Lua.hook.Call("think", new object[] { });
|
||||||
|
performanceMeasurement.Stop();
|
||||||
|
LuaSetup.LuaTimer.LastUpdateTime = performanceMeasurement.ElapsedMilliseconds;
|
||||||
|
performanceMeasurement.Reset();
|
||||||
|
|
||||||
Timing.Accumulator -= Timing.Step;
|
Timing.Accumulator -= Timing.Step;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Lib.Harmony" Version="2.1.1" />
|
||||||
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "MoonSharp Attach",
|
||||||
|
"type": "moonsharp-debug",
|
||||||
|
"debugServer": 41912,
|
||||||
|
"request": "attach"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"Lua.diagnostics.globals": [
|
||||||
|
"Game",
|
||||||
|
"Player",
|
||||||
|
"Random",
|
||||||
|
"Hook",
|
||||||
|
"Timer",
|
||||||
|
"bit32",
|
||||||
|
"TotalTime",
|
||||||
|
"DoFile",
|
||||||
|
"WayPoint",
|
||||||
|
"SpawnType",
|
||||||
|
"Level",
|
||||||
|
"Submarine",
|
||||||
|
"Vector2",
|
||||||
|
"PositionType",
|
||||||
|
"ServerLog_MessageType",
|
||||||
|
"Character",
|
||||||
|
"TraitorMessageType",
|
||||||
|
"ChatMessageType",
|
||||||
|
"CauseOfDeathType",
|
||||||
|
"CreateVector2",
|
||||||
|
"Item",
|
||||||
|
"ChatMessage",
|
||||||
|
"AfflictionPrefab",
|
||||||
|
"Gap",
|
||||||
|
"File",
|
||||||
|
"Networking",
|
||||||
|
"printNoLog",
|
||||||
|
"Client",
|
||||||
|
"SERVER",
|
||||||
|
"setmodulepaths",
|
||||||
|
"Type",
|
||||||
|
"BindingFlags",
|
||||||
|
"UserData",
|
||||||
|
"LuaUserData",
|
||||||
|
"CLIENT"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
local defaultLib = {}
|
||||||
|
|
||||||
|
require("DefaultRegister")
|
||||||
|
|
||||||
|
local CreateStatic = function (typeName)
|
||||||
|
return LuaUserData.CreateStatic("Barotrauma." .. typeName)
|
||||||
|
end
|
||||||
|
|
||||||
|
defaultLib["WayPoint"] = CreateStatic("WayPoint")
|
||||||
|
defaultLib["SpawnType"] = CreateStatic("SpawnType")
|
||||||
|
defaultLib["ChatMessageType"] = CreateStatic("Networking.ChatMessageType")
|
||||||
|
defaultLib["ServerLog_MessageType"] = CreateStatic("Networking.ServerLog+MessageType")
|
||||||
|
defaultLib["ServerLogMessageType"] = CreateStatic("Networking.ServerLog+MessageType")
|
||||||
|
defaultLib["Submarine"] = CreateStatic("Submarine")
|
||||||
|
defaultLib["Client"] = CreateStatic("Networking.Client")
|
||||||
|
defaultLib["Character"] = CreateStatic("Character")
|
||||||
|
defaultLib["CharacterInfo"] = CreateStatic("CharacterInfo")
|
||||||
|
defaultLib["Item"] = CreateStatic("Item")
|
||||||
|
defaultLib["ItemPrefab"] = CreateStatic("ItemPrefab")
|
||||||
|
defaultLib["Level"] = CreateStatic("Level")
|
||||||
|
defaultLib["PositionType"] = CreateStatic("Level+PositionType")
|
||||||
|
defaultLib["JobPrefab"] = CreateStatic("JobPrefab")
|
||||||
|
defaultLib["TraitorMessageType"] = CreateStatic("Networking.TraitorMessageType")
|
||||||
|
defaultLib["CauseOfDeathType"] = CreateStatic("CauseOfDeathType")
|
||||||
|
defaultLib["AfflictionPrefab"] = CreateStatic("AfflictionPrefab")
|
||||||
|
defaultLib["CharacterTeamType"] = CreateStatic("CharacterTeamType")
|
||||||
|
defaultLib["Vector2"] = LuaUserData.RegisterType("Microsoft.Xna.Framework.Vector2")
|
||||||
|
defaultLib["Vector3"] = LuaUserData.RegisterType("Microsoft.Xna.Framework.Vector3")
|
||||||
|
defaultLib["Vector4"] = LuaUserData.RegisterType("Microsoft.Xna.Framework.Vector4")
|
||||||
|
defaultLib["Color"] = LuaUserData.RegisterType("Microsoft.Xna.Framework.Color")
|
||||||
|
defaultLib["Point"] = LuaUserData.RegisterType("Microsoft.Xna.Framework.Point")
|
||||||
|
defaultLib["ChatMessage"] = CreateStatic("Networking.ChatMessage")
|
||||||
|
defaultLib["Hull"] = CreateStatic("Hull")
|
||||||
|
defaultLib["InvSlotType"] = CreateStatic("InvSlotType")
|
||||||
|
defaultLib["Gap"] = CreateStatic("Gap")
|
||||||
|
defaultLib["ContentPackage"] = CreateStatic("ContentPackage")
|
||||||
|
defaultLib["ClientPermissions"] = CreateStatic("Networking.ClientPermissions")
|
||||||
|
defaultLib["Signal"] = CreateStatic("Items.Components.Signal")
|
||||||
|
defaultLib["DeliveryMethod"] = CreateStatic("Networking.DeliveryMethod")
|
||||||
|
defaultLib["ClientPacketHeader"] = CreateStatic("Networking.ClientPacketHeader")
|
||||||
|
defaultLib["ServerPacketHeader"] = CreateStatic("Networking.ServerPacketHeader")
|
||||||
|
defaultLib["RandSync"] = CreateStatic("Rand+RandSync")
|
||||||
|
defaultLib["SubmarineInfo"] = CreateStatic("SubmarineInfo")
|
||||||
|
defaultLib["Rectangle"] = LuaUserData.RegisterType("Microsoft.Xna.Framework.Rectangle")
|
||||||
|
defaultLib["Entity"] = CreateStatic("Entity")
|
||||||
|
defaultLib["Physics"] = CreateStatic("Physics")
|
||||||
|
|
||||||
|
if SERVER then
|
||||||
|
|
||||||
|
elseif CLIENT then
|
||||||
|
defaultLib["Sprite"] = CreateStatic("Sprite")
|
||||||
|
defaultLib["Keys"] = LuaUserData.RegisterType("Microsoft.Xna.Framework.Input.Keys")
|
||||||
|
defaultLib["PlayerInput"] = CreateStatic("PlayerInput")
|
||||||
|
end
|
||||||
|
|
||||||
|
return defaultLib
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
local function RegisterBarotrauma(typeName)
|
||||||
|
return LuaUserData.RegisterType("Barotrauma." .. typeName)
|
||||||
|
end
|
||||||
|
|
||||||
|
local AddCallMetaMember = LuaUserData.AddCallMetaMember
|
||||||
|
|
||||||
|
RegisterBarotrauma("CauseOfDeathType")
|
||||||
|
RegisterBarotrauma("Level+InterestingPosition")
|
||||||
|
RegisterBarotrauma("Level+PositionType")
|
||||||
|
RegisterBarotrauma("Networking.TraitorMessageType")
|
||||||
|
RegisterBarotrauma("SpawnType")
|
||||||
|
RegisterBarotrauma("Networking.ChatMessageType")
|
||||||
|
RegisterBarotrauma("InputType")
|
||||||
|
|
||||||
|
RegisterBarotrauma("Job")
|
||||||
|
RegisterBarotrauma("JobPrefab")
|
||||||
|
RegisterBarotrauma("Level")
|
||||||
|
RegisterBarotrauma("Items.Components.Steering")
|
||||||
|
RegisterBarotrauma("Networking.ServerLog+MessageType")
|
||||||
|
RegisterBarotrauma("WayPoint")
|
||||||
|
RegisterBarotrauma("Character")
|
||||||
|
RegisterBarotrauma("Item")
|
||||||
|
RegisterBarotrauma("Submarine")
|
||||||
|
RegisterBarotrauma("Networking.Client")
|
||||||
|
RegisterBarotrauma("AfflictionPrefab")
|
||||||
|
RegisterBarotrauma("Affliction")
|
||||||
|
RegisterBarotrauma("CharacterHealth")
|
||||||
|
RegisterBarotrauma("AnimController")
|
||||||
|
RegisterBarotrauma("Limb")
|
||||||
|
RegisterBarotrauma("Ragdoll")
|
||||||
|
RegisterBarotrauma("Networking.ChatMessage")
|
||||||
|
RegisterBarotrauma("CharacterHealth+LimbHealth")
|
||||||
|
RegisterBarotrauma("AttackResult")
|
||||||
|
RegisterBarotrauma("Entity")
|
||||||
|
RegisterBarotrauma("EntitySpawner")
|
||||||
|
RegisterBarotrauma("MapEntity")
|
||||||
|
RegisterBarotrauma("MapEntityPrefab")
|
||||||
|
RegisterBarotrauma("CauseOfDeath")
|
||||||
|
RegisterBarotrauma("CharacterTeamType")
|
||||||
|
RegisterBarotrauma("Items.Components.Connection")
|
||||||
|
RegisterBarotrauma("CharacterInventory")
|
||||||
|
RegisterBarotrauma("Hull")
|
||||||
|
RegisterBarotrauma("Gap")
|
||||||
|
RegisterBarotrauma("PhysicsBody")
|
||||||
|
RegisterBarotrauma("InvSlotType")
|
||||||
|
RegisterBarotrauma("ItemPrefab")
|
||||||
|
RegisterBarotrauma("SerializableProperty")
|
||||||
|
RegisterBarotrauma("StatusEffect")
|
||||||
|
RegisterBarotrauma("FireSource")
|
||||||
|
RegisterBarotrauma("ContentPackage")
|
||||||
|
RegisterBarotrauma("SubmarineBody")
|
||||||
|
RegisterBarotrauma("Explosion")
|
||||||
|
RegisterBarotrauma("Networking.ServerSettings")
|
||||||
|
RegisterBarotrauma("Inventory")
|
||||||
|
RegisterBarotrauma("ItemInventory")
|
||||||
|
|
||||||
|
RegisterBarotrauma("Items.Components.Fabricator")
|
||||||
|
RegisterBarotrauma("Items.Components.ItemComponent")
|
||||||
|
RegisterBarotrauma("Items.Components.WifiComponent")
|
||||||
|
RegisterBarotrauma("Items.Components.LightComponent")
|
||||||
|
RegisterBarotrauma("Items.Components.Holdable")
|
||||||
|
RegisterBarotrauma("Items.Components.CustomInterface")
|
||||||
|
RegisterBarotrauma("Items.Components.CustomInterface+CustomInterfaceElement")
|
||||||
|
RegisterBarotrauma("Items.Components.ItemContainer")
|
||||||
|
RegisterBarotrauma("Items.Components.PowerContainer")
|
||||||
|
RegisterBarotrauma("Items.Components.Pickable")
|
||||||
|
RegisterBarotrauma("Items.Components.Reactor")
|
||||||
|
RegisterBarotrauma("Items.Components.RelayComponent")
|
||||||
|
RegisterBarotrauma("Items.Components.MemoryComponent")
|
||||||
|
RegisterBarotrauma("Items.Components.Engine")
|
||||||
|
|
||||||
|
RegisterBarotrauma("AIController")
|
||||||
|
RegisterBarotrauma("EnemyAIController")
|
||||||
|
RegisterBarotrauma("HumanAIController")
|
||||||
|
RegisterBarotrauma("AICharacter")
|
||||||
|
RegisterBarotrauma("AITarget")
|
||||||
|
RegisterBarotrauma("AITargetMemory")
|
||||||
|
|
||||||
|
RegisterBarotrauma("TalentPrefab")
|
||||||
|
RegisterBarotrauma("TalentOption")
|
||||||
|
RegisterBarotrauma("TalentSubTree")
|
||||||
|
RegisterBarotrauma("TalentTree")
|
||||||
|
RegisterBarotrauma("CharacterTalent")
|
||||||
|
|
||||||
|
RegisterBarotrauma("Screen")
|
||||||
|
RegisterBarotrauma("GameScreen")
|
||||||
|
RegisterBarotrauma("GameSession")
|
||||||
|
RegisterBarotrauma("CampaignMode")
|
||||||
|
|
||||||
|
local descriptor = RegisterBarotrauma("NetLobbyScreen")
|
||||||
|
LuaUserData.MakeFieldAccessible(descriptor, "subs")
|
||||||
|
|
||||||
|
RegisterBarotrauma("Networking.IWriteMessage")
|
||||||
|
RegisterBarotrauma("Networking.IReadMessage")
|
||||||
|
RegisterBarotrauma("Networking.ServerPacketHeader")
|
||||||
|
RegisterBarotrauma("Networking.ClientPacketHeader")
|
||||||
|
RegisterBarotrauma("Networking.DeliveryMethod")
|
||||||
|
RegisterBarotrauma("Rand+RandSync")
|
||||||
|
RegisterBarotrauma("Skill")
|
||||||
|
RegisterBarotrauma("SkillPrefab")
|
||||||
|
RegisterBarotrauma("TraitorMissionPrefab")
|
||||||
|
RegisterBarotrauma("TraitorMissionResult")
|
||||||
|
|
||||||
|
LuaUserData.RegisterType("FarseerPhysics.Dynamics.World")
|
||||||
|
LuaUserData.RegisterType("FarseerPhysics.Dynamics.Fixture")
|
||||||
|
RegisterBarotrauma("Physics")
|
||||||
|
|
||||||
|
RegisterBarotrauma("Camera")
|
||||||
|
RegisterBarotrauma("InputType")
|
||||||
|
RegisterBarotrauma("Key")
|
||||||
|
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("CharacterInfo"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("Items.Components.Signal"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("SubmarineInfo"))
|
||||||
|
|
||||||
|
AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Vector2"))
|
||||||
|
AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Vector3"))
|
||||||
|
AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Vector4"))
|
||||||
|
AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Color"))
|
||||||
|
AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Point"))
|
||||||
|
AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Rectangle"))
|
||||||
|
|
||||||
|
if SERVER then
|
||||||
|
|
||||||
|
RegisterBarotrauma("Traitor")
|
||||||
|
RegisterBarotrauma("Traitor+TraitorMission")
|
||||||
|
|
||||||
|
elseif CLIENT then
|
||||||
|
|
||||||
|
RegisterBarotrauma("LuaSetup+LuaGUI")
|
||||||
|
RegisterBarotrauma("ChatBox")
|
||||||
|
RegisterBarotrauma("GUICanvas")
|
||||||
|
RegisterBarotrauma("Anchor")
|
||||||
|
RegisterBarotrauma("Alignment")
|
||||||
|
RegisterBarotrauma("Pivot")
|
||||||
|
RegisterBarotrauma("Key")
|
||||||
|
RegisterBarotrauma("PlayerInput")
|
||||||
|
|
||||||
|
LuaUserData.RegisterType("Microsoft.Xna.Framework.Graphics.Texture2D")
|
||||||
|
LuaUserData.RegisterType("EventInput.KeyEventArgs")
|
||||||
|
LuaUserData.RegisterType("Microsoft.Xna.Framework.Input.Keys")
|
||||||
|
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("Sprite"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUILayoutGroup"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUITextBox"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUITextBlock"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUIButton"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("RectTransform"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUIFrame"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUITickBox"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUICustomComponent"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUIImage"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUIListBox"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUIScrollBar"))
|
||||||
|
AddCallMetaMember(RegisterBarotrauma("GUIDropDown"))
|
||||||
|
|
||||||
|
end
|
||||||
+10
-2
@@ -1,4 +1,14 @@
|
|||||||
|
-- Config
|
||||||
|
|
||||||
local runDisabledMods = false
|
local runDisabledMods = false
|
||||||
|
local modulePaths = {"Lua/?.lua"}
|
||||||
|
setmodulepaths(modulePaths)
|
||||||
|
|
||||||
|
local defaultLib = require("DefaultLib")
|
||||||
|
|
||||||
|
for key, value in pairs(defaultLib) do
|
||||||
|
_G[key] = value
|
||||||
|
end
|
||||||
|
|
||||||
if SERVER and Game.IsDedicated then
|
if SERVER and Game.IsDedicated then
|
||||||
runDisabledMods = true
|
runDisabledMods = true
|
||||||
@@ -30,8 +40,6 @@ local function runFolder(folder)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local modulePaths = {}
|
|
||||||
|
|
||||||
if not runDisabledMods then
|
if not runDisabledMods then
|
||||||
|
|
||||||
for _, package in pairs(enabledPackages) do
|
for _, package in pairs(enabledPackages) do
|
||||||
@@ -11,6 +11,10 @@ using System.Net;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using FarseerPhysics.Dynamics;
|
using FarseerPhysics.Dynamics;
|
||||||
|
using System.Reflection;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MoonSharp.Interpreter.Interop;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
@@ -32,7 +36,82 @@ namespace Barotrauma
|
|||||||
return new Vector4(x, y, z, w);
|
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 LuaSetup env;
|
||||||
|
|
||||||
public LuaTimer(LuaSetup e)
|
public LuaTimer(LuaSetup e)
|
||||||
@@ -331,12 +412,27 @@ namespace Barotrauma
|
|||||||
env = e;
|
env = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double Time
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GetTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static double GetTime()
|
public static double GetTime()
|
||||||
{
|
{
|
||||||
return Timing.TotalTime;
|
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
|
private partial class LuaRandom
|
||||||
@@ -592,6 +688,7 @@ namespace Barotrauma
|
|||||||
public LuaHook(LuaSetup e)
|
public LuaHook(LuaSetup e)
|
||||||
{
|
{
|
||||||
env = e;
|
env = e;
|
||||||
|
methodNameToHookName = new Dictionary<string, string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class HookFunction
|
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)
|
public void Add(string name, string hookName, object function)
|
||||||
{
|
{
|
||||||
@@ -632,7 +782,7 @@ namespace Barotrauma
|
|||||||
hookFunctions[name].Remove(hookName);
|
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 (env == null) return null;
|
||||||
if (name == null) return null;
|
if (name == null) return null;
|
||||||
@@ -653,12 +803,16 @@ namespace Barotrauma
|
|||||||
if (!result.IsNil())
|
if (!result.IsNil())
|
||||||
lastResult = result;
|
lastResult = result;
|
||||||
}
|
}
|
||||||
//else if (hf.function is NLua.LuaFunction luaFunction)
|
|
||||||
// lastResult = luaFunction.Call(args);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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 System.Reflection;
|
||||||
using FarseerPhysics.Dynamics;
|
using FarseerPhysics.Dynamics;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using HarmonyLib;
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
@@ -31,11 +32,15 @@ namespace Barotrauma
|
|||||||
public LuaHook hook;
|
public LuaHook hook;
|
||||||
public LuaGame game;
|
public LuaGame game;
|
||||||
public LuaNetworking networking;
|
public LuaNetworking networking;
|
||||||
|
public Harmony harmony;
|
||||||
|
|
||||||
public LuaScriptLoader luaScriptLoader;
|
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 (ex is InterpreterException)
|
||||||
{
|
{
|
||||||
if (((InterpreterException)ex).DecoratedMessage == null)
|
if (((InterpreterException)ex).DecoratedMessage == null)
|
||||||
@@ -197,8 +202,9 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
// messy solution
|
// 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 what = arg3.RawGet(0, true);
|
||||||
|
|
||||||
var code = "return " + what.UserData.Descriptor.Type.Name + ".__new(";
|
var code = "return " + what.UserData.Descriptor.Type.Name + ".__new(";
|
||||||
@@ -230,12 +236,6 @@ namespace Barotrauma
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddCallMetaMember(IUserDataDescriptor IUDD)
|
|
||||||
{
|
|
||||||
var descriptor = (StandardUserDataDescriptor)IUDD;
|
|
||||||
descriptor.RemoveMetaMember("__call");
|
|
||||||
descriptor.AddMetaMember("__call", new ObjectCallbackMemberDescriptor("__call", HandleCall));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SERVER
|
#if SERVER
|
||||||
public static void InstallClientSideLua()
|
public static void InstallClientSideLua()
|
||||||
@@ -301,6 +301,17 @@ namespace Barotrauma
|
|||||||
|
|
||||||
LuaCustomConverters.RegisterAll();
|
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<LuaPlayer>();
|
||||||
UserData.RegisterType<LuaHook>();
|
UserData.RegisterType<LuaHook>();
|
||||||
UserData.RegisterType<LuaGame>();
|
UserData.RegisterType<LuaGame>();
|
||||||
@@ -308,83 +319,8 @@ namespace Barotrauma
|
|||||||
UserData.RegisterType<LuaTimer>();
|
UserData.RegisterType<LuaTimer>();
|
||||||
UserData.RegisterType<LuaFile>();
|
UserData.RegisterType<LuaFile>();
|
||||||
UserData.RegisterType<LuaNetworking>();
|
UserData.RegisterType<LuaNetworking>();
|
||||||
|
UserData.RegisterType<LuaUserData>();
|
||||||
UserData.RegisterType<CauseOfDeathType>();
|
UserData.RegisterType<IUserDataDescriptor>();
|
||||||
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<PrefabCollection<ItemPrefab>>();
|
UserData.RegisterType<PrefabCollection<ItemPrefab>>();
|
||||||
UserData.RegisterType<PrefabCollection<JobPrefab>>();
|
UserData.RegisterType<PrefabCollection<JobPrefab>>();
|
||||||
@@ -392,90 +328,10 @@ namespace Barotrauma
|
|||||||
UserData.RegisterType<PrefabCollection<AfflictionPrefab>>();
|
UserData.RegisterType<PrefabCollection<AfflictionPrefab>>();
|
||||||
UserData.RegisterType<PrefabCollection<TalentPrefab>>();
|
UserData.RegisterType<PrefabCollection<TalentPrefab>>();
|
||||||
|
|
||||||
UserData.RegisterType<Screen>();
|
UserData.RegisterType<Pair<JobPrefab, int>>();
|
||||||
UserData.RegisterType<GameScreen>();
|
|
||||||
UserData.RegisterType<GameSession>();
|
|
||||||
UserData.RegisterType<CampaignMode>();
|
|
||||||
|
|
||||||
{
|
|
||||||
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>();
|
lua.Globals["setmodulepaths"] = (Action<string[]>)SetModulePaths;
|
||||||
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["TestFunction"] = (Func<float, float>)TestFunction;
|
lua.Globals["TestFunction"] = (Func<float, float>)TestFunction;
|
||||||
|
|
||||||
@@ -488,8 +344,7 @@ namespace Barotrauma
|
|||||||
lua.Globals["dostring"] = (Func<string, Table, string, DynValue>)DoString;
|
lua.Globals["dostring"] = (Func<string, Table, string, DynValue>)DoString;
|
||||||
lua.Globals["load"] = (Func<string, Table, string, DynValue>)LoadString;
|
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["Player"] = new LuaPlayer();
|
||||||
lua.Globals["Game"] = game;
|
lua.Globals["Game"] = game;
|
||||||
lua.Globals["Hook"] = hook;
|
lua.Globals["Hook"] = hook;
|
||||||
@@ -497,56 +352,17 @@ namespace Barotrauma
|
|||||||
lua.Globals["Timer"] = new LuaTimer(this);
|
lua.Globals["Timer"] = new LuaTimer(this);
|
||||||
lua.Globals["File"] = UserData.CreateStatic<LuaFile>();
|
lua.Globals["File"] = UserData.CreateStatic<LuaFile>();
|
||||||
lua.Globals["Networking"] = networking;
|
lua.Globals["Networking"] = networking;
|
||||||
lua.Globals["WayPoint"] = UserData.CreateStatic<WayPoint>();
|
|
||||||
lua.Globals["SpawnType"] = UserData.CreateStatic<SpawnType>();
|
// obsolete
|
||||||
lua.Globals["ChatMessageType"] = UserData.CreateStatic<ChatMessageType>();
|
lua.Globals["CreateVector2"] = (Func<float, float, Vector2>)CreateVector2;
|
||||||
lua.Globals["ServerLog_MessageType"] = UserData.CreateStatic<ServerLog.MessageType>();
|
lua.Globals["CreateVector3"] = (Func<float, float, float, Vector3>)CreateVector3;
|
||||||
lua.Globals["Submarine"] = UserData.CreateStatic<Submarine>();
|
lua.Globals["CreateVector4"] = (Func<float, float, float, float, Vector4>)CreateVector4;
|
||||||
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));
|
|
||||||
|
|
||||||
#if SERVER
|
#if SERVER
|
||||||
|
|
||||||
#elif CLIENT
|
#elif CLIENT
|
||||||
lua.Globals["GUI"] = new LuaGUI(this);
|
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
|
#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;
|
bool isServer = true;
|
||||||
|
|
||||||
@@ -561,13 +377,13 @@ namespace Barotrauma
|
|||||||
|
|
||||||
// LuaDocs.GenerateDocs(typeof(EntitySpawner));
|
// LuaDocs.GenerateDocs(typeof(EntitySpawner));
|
||||||
|
|
||||||
if (File.Exists("Lua/MoonsharpSetup.lua")) // try the default loader
|
if (File.Exists("Lua/LuaSetup.lua")) // try the default loader
|
||||||
DoFile("Lua/MoonsharpSetup.lua");
|
DoFile("Lua/LuaSetup.lua");
|
||||||
else if (File.Exists("Mods/LuaForBarotrauma/Lua/MoonsharpSetup.lua")) // in case its the workshop version
|
else if (File.Exists("Mods/LuaForBarotrauma/Lua/LuaSetup.lua")) // in case its the workshop version
|
||||||
DoFile("Mods/LuaForBarotrauma/Lua/MoonsharpSetup.lua");
|
DoFile("Mods/LuaForBarotrauma/Lua/LuaSetup.lua");
|
||||||
else // fallback to c# script loading
|
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>();
|
List<string> modulePaths = new List<string>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user