public FancyEventScripter(EventScripter scripter, InstructionDocs docs, EventCFG.CFGOptions options) { if (docs.Translator == null) { throw new ArgumentException($"Internal error: can't use fancy scripting with {docs.ResourceString}"); } this.scripter = scripter; this.docs = docs; this.options = options; }
private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = "EMEVD Files|*.emevd; *.emevd.dcx"; if (ofd.ShowDialog() == DialogResult.OK) { var chooser = new GameChooser(); chooser.ShowDialog(); Scripter = new EventScripter(ofd.FileName, chooser.GameDocs); editor.Text = Scripter.Unpack(); } }
public InfoViewer(EventScripter scripter) { InitializeComponent(); StartPosition = FormStartPosition.CenterParent; BinaryReaderEx reader = new BinaryReaderEx(false, scripter.EVD.StringData); Dictionary <long, string> stringPositions = new Dictionary <long, string>(); while (reader.Position < scripter.EVD.StringData.Length) { long pos = reader.Position; string str = reader.ReadUTF16(); string display = $"{pos}: {str}"; bool isLinkedFile = scripter.EVD.LinkedFileOffsets.Contains(pos); if (isLinkedFile) { display += "*"; } stringBox.Items.Add(display); } }
private bool OpenEMEVDFile( string fileName, string gameDocs, EMEVD evd = null, string jsText = null, bool isFancy = false, Dictionary <string, string> extraFields = null) { // Can reuse docs if for the same game if (!AllDocs.TryGetValue(gameDocs, out InstructionDocs docs)) { docs = AllDocs[gameDocs] = new InstructionDocs(gameDocs); } ScriptSettings settings = new ScriptSettings(docs, extraFields); EventScripter scripter = new EventScripter(fileName, docs, evd); string fileVersion = ProgramVersion.VERSION; if (jsText == null) { try { if (isFancy && docs.Translator != null) { jsText = new FancyEventScripter(scripter, docs, settings.CFGOptions).Unpack(); } else { jsText = scripter.Unpack(); } } catch (Exception ex) { // Also try to do it in compatibility mode, for emevd files which are no longer allowed, such as changing EMEDFs. try { jsText = scripter.Unpack(compatibilityMode: true); } catch { // If this also fails, we only care about the original exception. } if (jsText == null) { MessageBox.Show(ex.Message); } else { StringBuilder sb = new StringBuilder(); sb.AppendLine(ex.Message); sb.AppendLine("Proceed anyway? You will have to fix instruction arguments before resaving."); DialogResult result = MessageBox.Show(sb.ToString(), "Error", MessageBoxButtons.YesNoCancel); if (result != DialogResult.Yes) { jsText = null; } } if (jsText == null) { return(false); } } } else { fileVersion = extraFields != null && extraFields.TryGetValue("version", out string version) ? version : null; } if (Editor != null) { display.Panel2.Controls.Clear(); SharedControls.RemoveEditor(Editor); Editor.Dispose(); } Editor = new EditorGUI(SharedControls, scripter, docs, settings, fileVersion, jsText); SharedControls.AddEditor(Editor); SharedControls.RefreshGlobalStyles(); display.Panel2.Controls.Add(Editor); // PerformLayout(); Text = $"DARKSCRIPT 3 - {scripter.FileName}"; // Notify about possible compatibility issues int versionCmp = ProgramVersion.CompareVersions(ProgramVersion.VERSION, fileVersion); if (versionCmp > 0) { SharedControls.SetStatus("Note: File was previously saved using an earlier version of DarkScript3"); } else if (versionCmp < 0) { SharedControls.SetStatus("Note: File was previously saved using an newer version of DarkScript3. Please update!"); } return(true); }
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); } } }