add test scene for decompiling all lua

This commit is contained in:
Nahuel Rocchetti 2023-08-28 22:21:25 -03:00
parent 0fdadc72db
commit 0c03daac0e

View file

@ -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<LuaAsset>();
File.WriteAllText(Path.Combine(targetPath, $"{asset.FileName}.lua"), asset.Source);
}
catch (Exception) { }
}
}
}
}
}