From 2630c8354c73c2c6419499c322b988b27beb1797 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Tue, 10 May 2022 13:55:10 -0300 Subject: [PATCH] added item.deconstructed hook, misc registers and luacs is now initialized before campaign/sub editor is loaded --- .../ClientSource/Screens/MainMenuScreen.cs | 8 ++++---- .../ClientSource/Screens/SubEditorScreen.cs | 4 ++-- Barotrauma/BarotraumaShared/Lua/DefaultLib/LibShared.lua | 1 + .../Lua/DefaultRegister/RegisterShared.lua | 2 ++ .../Items/Components/Machines/Deconstructor.cs | 3 +++ 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs b/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs index 82405dbd7..8da972389 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs @@ -1115,6 +1115,8 @@ namespace Barotrauma return; } + GameMain.LuaCs.Initialize(); + selectedSub = new SubmarineInfo(Path.Combine(SaveUtil.TempPath, selectedSub.Name + ".sub")); GameMain.GameSession = new GameSession(selectedSub, savePath, GameModePreset.SinglePlayerCampaign, settings, mapSeed); @@ -1124,14 +1126,14 @@ namespace Barotrauma GameMain.GameSession.CrewManager.AddCharacterInfo(characterInfo); } ((SinglePlayerCampaign)GameMain.GameSession.GameMode).LoadNewLevel(); - - GameMain.LuaCs.Initialize(); } private void LoadGame(string saveFile) { if (string.IsNullOrWhiteSpace(saveFile)) return; + GameMain.LuaCs.Initialize(); + try { SaveUtil.LoadGame(saveFile); @@ -1144,8 +1146,6 @@ namespace Barotrauma //TODO //GameMain.LobbyScreen.Select(); - - GameMain.LuaCs.Initialize(); } #region UI Methods diff --git a/Barotrauma/BarotraumaClient/ClientSource/Screens/SubEditorScreen.cs b/Barotrauma/BarotraumaClient/ClientSource/Screens/SubEditorScreen.cs index ffc08ae67..4f66ea3ab 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Screens/SubEditorScreen.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Screens/SubEditorScreen.cs @@ -1034,6 +1034,8 @@ namespace Barotrauma return true; } + GameMain.LuaCs.Initialize(); + CloseItem(); backedUpSubInfo = new SubmarineInfo(MainSub); @@ -1049,8 +1051,6 @@ namespace Barotrauma GameMain.SubEditorScreen.Select(); }; - GameMain.LuaCs.Initialize(); - return true; } diff --git a/Barotrauma/BarotraumaShared/Lua/DefaultLib/LibShared.lua b/Barotrauma/BarotraumaShared/Lua/DefaultLib/LibShared.lua index fd141fe8a..fd13585a7 100644 --- a/Barotrauma/BarotraumaShared/Lua/DefaultLib/LibShared.lua +++ b/Barotrauma/BarotraumaShared/Lua/DefaultLib/LibShared.lua @@ -38,6 +38,7 @@ defaultLib["ContentPackageManager"] = CreateStatic("Barotrauma.ContentPackageMan defaultLib["GameSettings"] = CreateStatic("Barotrauma.GameSettings") defaultLib["RichString"] = CreateStatic("Barotrauma.RichString", true) defaultLib["Identifier"] = CreateStatic("Barotrauma.Identifier", true) +defaultLib["LanguageIdentifier"] = CreateStatic("Barotrauma.LanguageIdentifier", true) defaultLib["ContentPackage"] = CreateStatic("Barotrauma.ContentPackage", true) defaultLib["WayPoint"] = CreateStatic("Barotrauma.WayPoint", true) defaultLib["Submarine"] = CreateStatic("Barotrauma.Submarine", true) diff --git a/Barotrauma/BarotraumaShared/Lua/DefaultRegister/RegisterShared.lua b/Barotrauma/BarotraumaShared/Lua/DefaultRegister/RegisterShared.lua index 03d626833..74a876e1a 100644 --- a/Barotrauma/BarotraumaShared/Lua/DefaultRegister/RegisterShared.lua +++ b/Barotrauma/BarotraumaShared/Lua/DefaultRegister/RegisterShared.lua @@ -11,6 +11,7 @@ RegisterBarotrauma("Level+InterestingPosition") RegisterBarotrauma("RichString") RegisterBarotrauma("Identifier") +RegisterBarotrauma("LanguageIdentifier") RegisterBarotrauma("Job") RegisterBarotrauma("JobPrefab") @@ -34,6 +35,7 @@ RegisterBarotrauma("CharacterParams+SoundParams") RegisterBarotrauma("Item") +RegisterBarotrauma("DeconstructItem") RegisterBarotrauma("Submarine") RegisterBarotrauma("INetSerializableStruct") RegisterBarotrauma("Networking.Client") diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Deconstructor.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Deconstructor.cs index c09526555..c84acde68 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Deconstructor.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Deconstructor.cs @@ -301,6 +301,9 @@ namespace Barotrauma.Items.Components GameAnalyticsManager.AddDesignEvent("ItemDeconstructed:" + (GameMain.GameSession?.GameMode?.Preset.Identifier.Value ?? "none") + ":" + targetItem.Prefab.Identifier); + bool? result = GameMain.LuaCs.Hook.Call("item.deconstructed", targetItem, this, user, allowRemove); + if (result == true) { return; } + if (targetItem.AllowDeconstruct && allowRemove) { //drop all items that are inside the deconstructed item