From 0c03daac0e36e084fdd47cc946d89d8575b6b937 Mon Sep 17 00:00:00 2001 From: Nahuel Rocchetti Date: Mon, 28 Aug 2023 22:21:25 -0300 Subject: [PATCH] add test scene for decompiling all lua --- .../OpenTS2/Engine/Tests/LuaTestController.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Assets/Scripts/OpenTS2/Engine/Tests/LuaTestController.cs b/Assets/Scripts/OpenTS2/Engine/Tests/LuaTestController.cs index b74fc25..1b6c94b 100644 --- a/Assets/Scripts/OpenTS2/Engine/Tests/LuaTestController.cs +++ b/Assets/Scripts/OpenTS2/Engine/Tests/LuaTestController.cs @@ -14,6 +14,7 @@ namespace OpenTS2.Engine.Tests { public class LuaTestController : MonoBehaviour { + public bool DumpLuaScripts = true; void Start() { // Initialize lua engine, register a test API so that we can use UnityLog and hook GetSimulatorGlobal to return 27 as day of the month, 8 as month and 2023 as year. @@ -36,6 +37,29 @@ namespace OpenTS2.Engine.Tests msg = (e as InterpreterException).DecoratedMessage; Debug.LogError($"Problem running:{msg}"); } + + if (DumpLuaScripts) + { + var objectScriptsPath = Filesystem.GetLatestFilePath("Res/ObjectScripts/ObjectScripts.package"); + var objectScriptsFile = new DBPFFile(objectScriptsPath); + + foreach(var entry in objectScriptsFile.Entries) + { + if (entry.TGI.TypeID != TypeIDs.LUA_GLOBAL && entry.TGI.TypeID != TypeIDs.LUA_LOCAL) + continue; + var targetPath = "TestFiles/Lua/Global"; + if (entry.TGI.TypeID == TypeIDs.LUA_LOCAL) + targetPath = "TestFiles/Lua/Local"; + if (!Directory.Exists(targetPath)) + Directory.CreateDirectory(targetPath); + try + { + var asset = entry.GetAsset(); + File.WriteAllText(Path.Combine(targetPath, $"{asset.FileName}.lua"), asset.Source); + } + catch (Exception) { } + } + } } } } \ No newline at end of file