-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuaInterop.cs
More file actions
68 lines (66 loc) · 2.15 KB
/
Copy pathLuaInterop.cs
File metadata and controls
68 lines (66 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
namespace RobloxScriptCompiler
{
class LuaInterop
{
private Random rand = new Random();
private string bindir = Directory.GetCurrentDirectory() + "\\bin";
private string tmpdir = Directory.GetCurrentDirectory() + "\\tmp";
public LuaInterop()
{
if (!Directory.Exists(bindir)) Directory.CreateDirectory(bindir);
if (Directory.Exists(tmpdir))
{
foreach (FileInfo file in new DirectoryInfo(tmpdir).GetFiles())
{
try
{
file.Delete();
}
catch { }
}
} else Directory.CreateDirectory(tmpdir);
}
public string Compile(string src, string name = "luau", int offset = 0)
{
string fn = rand.Next(100000, 999999).ToString() + ".bin";
File.WriteAllText(tmpdir + "\\" + fn, src);
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = bindir + "\\compiler.exe",
Arguments = "\"./tmp/" + fn + "\" \"" + name + "\" " + offset.ToString(),
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
try
{
proc.Start();
} catch(Exception e)
{
Logger.Error(e.ToString());
}
string data = "";
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadLine();
data += line;
}
if (proc.ExitCode != 0)
{
return "-- [!] This script failed to compile due to an error in the original script.\nreturn{0x0;};";
}
File.Delete(tmpdir + "\\" + fn);
return data;
}
}
}