Skip to content

Commit e16277a

Browse files
committed
nestusfj
1 parent ddf3b4c commit e16277a

3 files changed

Lines changed: 47 additions & 18 deletions

File tree

LuaInterop.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public LuaInterop()
2020
{
2121
foreach (FileInfo file in new DirectoryInfo(tmpdir).GetFiles())
2222
{
23-
file.Delete();
23+
try
24+
{
25+
file.Delete();
26+
}
27+
catch { }
2428
}
2529
} else Directory.CreateDirectory(tmpdir);
2630
}
@@ -34,19 +38,29 @@ public string Compile(string src, string name = "luau", int offset = 0)
3438
StartInfo = new ProcessStartInfo
3539
{
3640
FileName = bindir + "\\compiler.exe",
37-
Arguments = "./tmp/" + fn + " " + name + " " + offset.ToString(),
41+
Arguments = "\"./tmp/" + fn + "\" \"" + name + "\" " + offset.ToString(),
3842
UseShellExecute = false,
3943
RedirectStandardOutput = true,
4044
CreateNoWindow = true
4145
}
4246
};
43-
proc.Start();
47+
try
48+
{
49+
proc.Start();
50+
} catch(Exception e)
51+
{
52+
Logger.Error(e.ToString());
53+
}
4454
string data = "";
4555
while (!proc.StandardOutput.EndOfStream)
4656
{
4757
string line = proc.StandardOutput.ReadLine();
4858
data += line;
4959
}
60+
if (proc.ExitCode != 0)
61+
{
62+
return "-- [!] This script failed to compile due to an error in the original script.\nreturn{0x0;};";
63+
}
5064
File.Delete(tmpdir + "\\" + fn);
5165
return data;
5266
}

Program.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static class Program
2727
static string base_dir = Path.Combine(Directory.GetCurrentDirectory(), "bin");
2828
static Random random = new Random();
2929
static string[] args;
30+
static string build_id = Guid.NewGuid().ToString().Replace("-", "");
3031

3132
[STAThread]
3233
static void Main(string[] argv)
@@ -87,22 +88,24 @@ enum ScriptType
8788
LocalScript,
8889
ModuleScript
8990
}
90-
static void ParseScripts(XmlDocument doc, int offset, ScriptType type = ScriptType.LocalScript)
91+
static void ParseScripts(XmlNodeList scripts, int offset, ScriptType type = ScriptType.LocalScript)
9192
{
9293
bool isModule = type == ScriptType.ModuleScript;
93-
string scriptTypeString = isModule ? "ModuleScript" : "LocalScript";
94-
string baseMatch = "//Item[@class='" + scriptTypeString + "']";
95-
string propertiesMatch = baseMatch + "/Properties";
96-
XmlNodeList localscripts = doc.DocumentElement.SelectNodes(baseMatch);
9794
int count = 0;
98-
foreach (XmlNode script in localscripts)
95+
foreach (XmlNode script in scripts)
9996
{
10097
count++;
101-
XmlNode name = script.SelectSingleNode(propertiesMatch + "/string[@name='Name']");
102-
XmlNode source = script.SelectSingleNode(propertiesMatch + "/ProtectedString[@name='Source']");
103-
XmlNode guid = script.SelectSingleNode(propertiesMatch + "/string[@name='ScriptGuid']");
98+
XmlNode properties = script.SelectSingleNode("./Properties[1]");
99+
XmlNode name = properties.SelectSingleNode("./string[@name='Name'][1]");
100+
XmlNode source = properties.SelectSingleNode("./ProtectedString[@name='Source'][1]");
101+
XmlNode guid = properties.SelectSingleNode("./string[@name='ScriptGuid'][1]");
104102
XmlNode referent = script.Attributes.GetNamedItem("referent");
105-
Logger.Info(count.ToString() + "/" + localscripts.Count.ToString() + " Loading \"" + name.InnerText.ToString() + "\"");
103+
if (name == null || source == null || guid == null || referent == null)
104+
{
105+
Logger.Debug("Script attribute was null or ignored!");
106+
continue;
107+
}
108+
Logger.Info(count.ToString() + "/" + scripts.Count.ToString() + " - Loading \"" + name.InnerText.ToString() + "\"");
106109
if (referent != null
107110
&& source != null
108111
&& guid != null
@@ -122,12 +125,22 @@ static void ParseScripts(XmlDocument doc, int offset, ScriptType type = ScriptTy
122125
{
123126
Logger.Warn("Skipping script");
124127
}
128+
ParseScripts(script.SelectNodes("./Item[@class='" + (isModule ? "ModuleScript" : "LocalScript") + "']"), offset, type);
125129
}
126130
}
127131

132+
static void SetClientMetadata(XmlDocument doc, Dictionary<string, object> metadata)
133+
{
134+
XmlNode buildData = doc.SelectSingleNode("//Item[@class='StringValue'][1]");
135+
XmlNode properties = buildData.SelectSingleNode("./Properties[1]");
136+
XmlNode value = properties.SelectSingleNode("./string[@name='Value'][1]");
137+
value.InnerText = JsonConvert.SerializeObject(metadata);
138+
}
139+
128140
static void CompileFile(string fileName, int offset)
129141
{
130142
var build_options = new Dictionary<string, object> { };
143+
build_options.Add("BuildId", build_id);
131144
build_options.Add("Version", ver + "b");
132145
build_options.Add("Offset", offset);
133146
//build_options.Add("Arguments", args);
@@ -138,16 +151,17 @@ static void CompileFile(string fileName, int offset)
138151
string outfile = Path.GetDirectoryName(infile) + "\\Compiled_" + Path.GetFileName(infile);
139152
doc.Load(infile);
140153
Logger.Info("Loading ModuleScripts");
141-
ParseScripts(doc, offset, ScriptType.ModuleScript);
154+
ParseScripts(doc.DocumentElement.SelectNodes("//Item[@class='ModuleScript']"), offset, ScriptType.ModuleScript);
142155
Logger.Ok("All ModuleScripts compiled");
143156
Logger.Info("Loading LocalScripts");
144-
ParseScripts(doc, offset, ScriptType.LocalScript);
157+
ParseScripts(doc.DocumentElement.SelectNodes("//Item[@class='LocalScript']"), offset, ScriptType.LocalScript);
145158
Logger.Ok("All LocalScripts compiled");
146159
doc.Save(outfile);
147160
Logger.Info("Adding client script");
148-
string client_data = File.ReadAllText(Path.Combine(base_dir, "client.xml")).Replace("%builddata%", JsonConvert.SerializeObject(build_options));
161+
string client_data = File.ReadAllText(Path.Combine(base_dir, "client.xml"));
149162
XmlDocument client_xml = new XmlDocument();
150163
client_xml.LoadXml(client_data);
164+
SetClientMetadata(client_xml, build_options);
151165
XmlNode replicated_first = doc.DocumentElement.SelectSingleNode("//Item[@class='ReplicatedFirst']");
152166
var emptyNamepsaces = new XmlSerializerNamespaces(new[] {
153167
XmlQualifiedName.Empty
@@ -187,6 +201,7 @@ static void PromptToCompile(string openfile = null)
187201
{
188202
var offset = 0;//random.Next(26, 255);
189203
Logger.Debug("Using an offset of " + offset.ToString());
204+
Logger.Debug("Build id " + build_id);
190205
if (openfile == null)
191206
{
192207
using (OpenFileDialog openFileDialog = new OpenFileDialog())

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.11.6.0")]
36-
[assembly: AssemblyFileVersion("1.11.6.0")]
35+
[assembly: AssemblyVersion("1.12.0.0")]
36+
[assembly: AssemblyFileVersion("1.12.0.0")]

0 commit comments

Comments
 (0)