Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
.vs/*
packages/*

[Bb]in/
[Oo]bj/

.idea/
*.user

packages/
*.nupkg
117 changes: 117 additions & 0 deletions LuaToolkit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,170 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Recompiler", "demo\Recompil
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web", "demo\LuaDecompiler-Web\Web.csproj", "{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cli", "cli", "{342A349A-D343-8551-4064-2E2800C39E13}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuaToolkit.Cli", "cli\LuaToolkit.Cli.csproj", "{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
TestDebug|Any CPU = TestDebug|Any CPU
TestDebug|x64 = TestDebug|x64
TestDebug|x86 = TestDebug|x86
WebRelease|Any CPU = WebRelease|Any CPU
WebRelease|x64 = WebRelease|x64
WebRelease|x86 = WebRelease|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3C38C968-E485-4154-B6BD-E8446651307F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Debug|x64.ActiveCfg = Debug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Debug|x64.Build.0 = Debug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Debug|x86.ActiveCfg = Debug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Debug|x86.Build.0 = Debug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Release|Any CPU.Build.0 = Release|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Release|x64.ActiveCfg = Release|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Release|x64.Build.0 = Release|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Release|x86.ActiveCfg = Release|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.Release|x86.Build.0 = Release|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.TestDebug|Any CPU.ActiveCfg = TestDebug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.TestDebug|Any CPU.Build.0 = TestDebug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.TestDebug|x64.ActiveCfg = TestDebug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.TestDebug|x64.Build.0 = TestDebug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.TestDebug|x86.ActiveCfg = TestDebug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.TestDebug|x86.Build.0 = TestDebug|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.WebRelease|Any CPU.ActiveCfg = WebRelease|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.WebRelease|Any CPU.Build.0 = WebRelease|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.WebRelease|x64.ActiveCfg = WebRelease|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.WebRelease|x64.Build.0 = WebRelease|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.WebRelease|x86.ActiveCfg = WebRelease|Any CPU
{3C38C968-E485-4154-B6BD-E8446651307F}.WebRelease|x86.Build.0 = WebRelease|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Debug|x64.ActiveCfg = Debug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Debug|x64.Build.0 = Debug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Debug|x86.ActiveCfg = Debug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Debug|x86.Build.0 = Debug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Release|Any CPU.Build.0 = Release|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Release|x64.ActiveCfg = Release|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Release|x64.Build.0 = Release|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Release|x86.ActiveCfg = Release|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.Release|x86.Build.0 = Release|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.TestDebug|Any CPU.ActiveCfg = TestDebug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.TestDebug|Any CPU.Build.0 = TestDebug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.TestDebug|x64.ActiveCfg = TestDebug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.TestDebug|x64.Build.0 = TestDebug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.TestDebug|x86.ActiveCfg = TestDebug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.TestDebug|x86.Build.0 = TestDebug|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.WebRelease|Any CPU.ActiveCfg = WebRelease|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.WebRelease|Any CPU.Build.0 = WebRelease|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.WebRelease|x64.ActiveCfg = WebRelease|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.WebRelease|x64.Build.0 = WebRelease|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.WebRelease|x86.ActiveCfg = WebRelease|Any CPU
{9A45374E-5548-4C3A-AF06-C31A962295DD}.WebRelease|x86.Build.0 = WebRelease|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Debug|x64.ActiveCfg = Debug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Debug|x64.Build.0 = Debug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Debug|x86.ActiveCfg = Debug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Debug|x86.Build.0 = Debug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Release|Any CPU.Build.0 = Release|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Release|x64.ActiveCfg = Release|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Release|x64.Build.0 = Release|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Release|x86.ActiveCfg = Release|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.Release|x86.Build.0 = Release|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.TestDebug|Any CPU.ActiveCfg = TestDebug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.TestDebug|Any CPU.Build.0 = TestDebug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.TestDebug|x64.ActiveCfg = TestDebug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.TestDebug|x64.Build.0 = TestDebug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.TestDebug|x86.ActiveCfg = TestDebug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.TestDebug|x86.Build.0 = TestDebug|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.WebRelease|Any CPU.ActiveCfg = WebRelease|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.WebRelease|Any CPU.Build.0 = WebRelease|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.WebRelease|x64.ActiveCfg = WebRelease|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.WebRelease|x64.Build.0 = WebRelease|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.WebRelease|x86.ActiveCfg = WebRelease|Any CPU
{C10726C0-8D2C-4F92-9961-5008D1B6940E}.WebRelease|x86.Build.0 = WebRelease|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Debug|x64.ActiveCfg = Debug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Debug|x64.Build.0 = Debug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Debug|x86.ActiveCfg = Debug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Debug|x86.Build.0 = Debug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Release|Any CPU.Build.0 = Release|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Release|x64.ActiveCfg = Release|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Release|x64.Build.0 = Release|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Release|x86.ActiveCfg = Release|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.Release|x86.Build.0 = Release|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.TestDebug|Any CPU.ActiveCfg = TestDebug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.TestDebug|Any CPU.Build.0 = TestDebug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.TestDebug|x64.ActiveCfg = TestDebug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.TestDebug|x64.Build.0 = TestDebug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.TestDebug|x86.ActiveCfg = TestDebug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.TestDebug|x86.Build.0 = TestDebug|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.WebRelease|Any CPU.ActiveCfg = WebRelease|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.WebRelease|Any CPU.Build.0 = WebRelease|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.WebRelease|x64.ActiveCfg = WebRelease|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.WebRelease|x64.Build.0 = WebRelease|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.WebRelease|x86.ActiveCfg = WebRelease|Any CPU
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB}.WebRelease|x86.Build.0 = WebRelease|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Debug|x64.ActiveCfg = Debug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Debug|x64.Build.0 = Debug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Debug|x86.ActiveCfg = Debug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Debug|x86.Build.0 = Debug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Release|Any CPU.Build.0 = Release|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Release|x64.ActiveCfg = Release|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Release|x64.Build.0 = Release|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Release|x86.ActiveCfg = Release|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.Release|x86.Build.0 = Release|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.TestDebug|Any CPU.ActiveCfg = Debug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.TestDebug|Any CPU.Build.0 = Debug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.TestDebug|x64.ActiveCfg = TestDebug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.TestDebug|x64.Build.0 = TestDebug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.TestDebug|x86.ActiveCfg = TestDebug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.TestDebug|x86.Build.0 = TestDebug|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.WebRelease|Any CPU.ActiveCfg = Release|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.WebRelease|Any CPU.Build.0 = Release|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.WebRelease|x64.ActiveCfg = WebRelease|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.WebRelease|x64.Build.0 = WebRelease|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.WebRelease|x86.ActiveCfg = WebRelease|Any CPU
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77}.WebRelease|x86.Build.0 = WebRelease|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Debug|x64.ActiveCfg = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Debug|x64.Build.0 = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Debug|x86.ActiveCfg = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Debug|x86.Build.0 = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Release|Any CPU.Build.0 = Release|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Release|x64.ActiveCfg = Release|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Release|x64.Build.0 = Release|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Release|x86.ActiveCfg = Release|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.Release|x86.Build.0 = Release|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.TestDebug|Any CPU.ActiveCfg = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.TestDebug|Any CPU.Build.0 = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.TestDebug|x64.ActiveCfg = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.TestDebug|x64.Build.0 = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.TestDebug|x86.ActiveCfg = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.TestDebug|x86.Build.0 = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.WebRelease|Any CPU.ActiveCfg = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.WebRelease|Any CPU.Build.0 = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.WebRelease|x64.ActiveCfg = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.WebRelease|x64.Build.0 = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.WebRelease|x86.ActiveCfg = Debug|Any CPU
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C}.WebRelease|x86.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -75,6 +191,7 @@ Global
{C10726C0-8D2C-4F92-9961-5008D1B6940E} = {6645C52B-19A3-4114-81F8-DEBA70779569}
{CE7FDAB8-2F8A-4E39-AFC9-900D3458B9CB} = {6645C52B-19A3-4114-81F8-DEBA70779569}
{30E34A9B-E065-4E33-BB4F-4F3B23C9DB77} = {6645C52B-19A3-4114-81F8-DEBA70779569}
{BE269D79-DA30-4DBB-8C84-7D5978E70C0C} = {342A349A-D343-8551-4064-2E2800C39E13}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CA86C95D-BB88-475B-B999-4332121C087F}
Expand Down
2 changes: 2 additions & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Bb]in/
[Oo]bj/
12 changes: 12 additions & 0 deletions cli/LuaToolkit.Cli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RollForward>LatestMajor</RollForward>
<ImplicitUsings>disable</ImplicitUsings>
<AssemblyName>luadec</AssemblyName>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../src/LuaToolkit.csproj" />
</ItemGroup>
</Project>
36 changes: 36 additions & 0 deletions cli/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.IO;
using LuaToolkit.Core;
using LuaToolkit.Disassembler;
using LuaToolkit.Decompiler;

namespace LuaToolkit.Cli
{
class Program
{
static int Main(string[] args)
{
if (args.Length < 1)
{
Console.Error.WriteLine("usuage: luadec <file.luac> [more.luac ...]");
Console.Error.WriteLine(" decompiles compiled Lua 5.1 (.luac) back to source code.");
return 1;
}

foreach(var path in args)
{
if (!File.Exists(path))
{
Console.Error.WriteLine($"[!] File not found: {path}");
continue;
}

var luac = new LuaCFile(File.ReadAllBytes(path));
var decoder = new LuaDecoder(luac);
var decompiler = new LuaDecompiler(decoder);
Console.WriteLine(decompiler.LuaScript);
}
return 0;
}
}
}
35 changes: 30 additions & 5 deletions src/Decompiler/LuaDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,28 @@ public LuaDecompiler(LuaDecoder decoder)
WriteFile();
}

private void ResClosureNames()
{
// walk every function we built and point each CLOSURE line at its child's name
// GetFunctionRef() got hooked up by the child in HandleUpvalues(), so by now its set
foreach (var f in this.LuaFunctions)
foreach (var line in f.GetLines())
if (line.Instr != null && line.Instr.OpCode == LuaOpcode.CLOSURE && line.GetFunctionRef() != null)
line.Op3 = line.GetFunctionRef().ScriptFunction.Name;
}

private void WriteFile()
{
// create Script Functions
this.Decoder.File.Function.Name = "CRoot"; // or main?
WriteF(this.Decoder.File.Function);

// NOTE: closures point at child functions that didnt exist yet while
// building the parent lines, so UpdateClosures ran too early and left them as
// 'IDK_SHIT_WENT_MISSING_BRO' lol, now that every function is created we loop
// back over the closure lines and finally fill in their names
ResClosureNames();

// NOTE: this is done on GetText
//// allign/format/whatever each function
//foreach (var f in this.LuaFunctions)
Expand All @@ -45,14 +61,23 @@ private void WriteF(LuaFunction func)
{
CreateScripFunction(func); // root first and then inside ?
// TODO: write functions on CLOSURE and not each list?
// for (int i = 0; i < func.Functions.Count; i++)
// {
// func.Functions[i].Name = func.Name + "_" + i; // set default name
// CreateScripFunction(func.Functions[i], func.ScriptFunction.Depth+1);
// foreach (var f in func.Functions[i].Functions)
// {
// WriteF(f); // children NOTE: write children in body of parent?
// }
// }

for (int i = 0; i < func.Functions.Count; i++)
{
func.Functions[i].Name = func.Name + "_" + i; // set default name
CreateScripFunction(func.Functions[i], func.ScriptFunction.Depth+1);
foreach (var f in func.Functions[i].Functions)
{
WriteF(f); // children NOTE: write children in body of parent?
}
// NOTE: recurse into the child itself so it (and any of ITS children) get
// created and named too. before this only the direct children were getting a name
// but grand children came out as "IDK_SHIT_WENT_MISSING_BRO"
WriteF(func.Functions[i]);
}
}

Expand Down
Loading