public EMEVD Pack(string code, string documentName = null) { FancyJSCompiler.CompileOutput output = new FancyJSCompiler(options).Compile(code, docs); try { return(scripter.Pack(output.Code, documentName)); } catch (JSScriptException ex) { output.RewriteStackFrames(ex, documentName); throw ex; } }
private void SaveToolStripMenuItem_Click(object sender, EventArgs e) { try { Scripter.Pack(editor.Text).Write("output/test.emevd.dcx", DCX.Type.DarkSouls3); } catch (Exception ex) { var scriptException = ex as IScriptEngineException; if (scriptException != null) { string details = scriptException.ErrorDetails; Console.WriteLine(details); //details = Regex.Replace(details, @"(\s+)at Script\s*\[.*\]:", "$1at "); MessageBox.Show(details); } else { MessageBox.Show(ex.ToString()); } } }
public static void Run(string[] args) { string game = args[0]; string inDir = args[1]; if (defaultGameDirs.TryGetValue(inDir, out string gameDir)) { inDir = gameDir; } string outDir = args[2]; // Fancy recompilation List <string> emevdPaths = Directory.GetFiles(inDir, "*.emevd").Concat(Directory.GetFiles(inDir, "*.emevd.dcx")).ToList(); InstructionDocs docs = new InstructionDocs($"{game}-common.emedf.json"); if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } Dictionary <string, StringBuilder> contents = new Dictionary <string, StringBuilder>(); string recordText(string type, string name, Func <object> func) { if (!contents.TryGetValue(type, out StringBuilder sb)) { contents[type] = sb = new StringBuilder(); } try { object ret = func(); if (ret is string text) { sb.AppendLine($"/* ------------------- {name} ------------------- */"); sb.AppendLine(text); return(text); } else { // Do nothing other than indicate success return(""); } } catch (Exception e) { sb.AppendLine($"/* ------------------- {name} ------------------- */"); sb.AppendLine($"/* {e} */"); Console.WriteLine(name + ": " + e + "\n"); return(null); } } foreach (string emevdPath in emevdPaths) { string name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(emevdPath)); if (game == "ds3" && name.StartsWith("m2")) { continue; } Console.WriteLine("--------------------------" + name); EventScripter scripter = new EventScripter(emevdPath, docs); string reg1 = recordText("reg1", name, () => scripter.Unpack()); if (reg1 == null) { continue; } if (args.Contains("reg")) { if (recordText("reg2", name + "-compile", () => scripter.Pack(reg1, name)) != null) { recordText("reg2", name, () => scripter.Unpack()); } } if (args.Contains("fancy")) { EventCFG.CFGOptions options = args.Contains("min") ? EventCFG.CFGOptions.GetMin() : EventCFG.CFGOptions.GetDefault(); scripter = new EventScripter(emevdPath, docs); FancyEventScripter fes = new FancyEventScripter(scripter, docs, options); if (args.Contains("unit")) { string testCases = Resource.Text("test.js"); fes.Pack(testCases); Console.WriteLine(scripter.Unpack()); Console.WriteLine(fes.Repack(testCases)); return; } string fancy1 = recordText("fancy1", name, () => fes.Unpack()); if (fancy1 != null) { if (args.Contains("repack")) { recordText("fancy2", name, () => fes.Repack(fancy1)); } else { if (recordText("reg3", name + "-compile", () => fes.Pack(fancy1, name)) != null) { recordText("reg3", name, () => scripter.Unpack()); } } } } } foreach (KeyValuePair <string, StringBuilder> entry in contents) { using (TextWriter writer = File.CreateText($@"{outDir}\{game}_{entry.Key}.js")) { writer.Write(entry.Value); } } }