private void Execute() { Save(); LogBox.Clear(); LogBox.AppendText(DateTime.Now.ToString() + "\n"); MemoryStream ms = new MemoryStream(); EventRaisingStreamWriter outputWr = new EventRaisingStreamWriter(ms); outputWr.StringWritten += sWr_StringWritten; var o = MainForm.QHScriptEngine.Runtime.IO.OutputStream; MainForm.QHScriptEngine.Runtime.IO.SetOutput(ms, outputWr); var scope = HackContext.CreateScriptScope(MainForm.QHScriptEngine); MainForm.QHScriptEngine.Execute(CodeView.Text, scope); MainForm.QHScriptEngine.Runtime.IO.SetOutput(o, Encoding.UTF8); void sWr_StringWritten(object sd, OnWrittenEventArgs <string> ev) { LogBox.AppendText(ev.Value); } }
public PagePanel_Scripts(int Width, int Height) : base(Width, Height) { FilesBox = new MListBox() { Bounds = new Rectangle(3, 3, 210, 364) }; UpdateList(); Controls.Add(FilesBox); Button ExecuteButton = new Button() { Text = MainForm.CurrentLanguage["Execute"], Bounds = new Rectangle(214, 3, 80, 30), FlatStyle = FlatStyle.Flat, BackColor = Color.FromArgb(100, 150, 150, 150) }; ExecuteButton.Click += (s, e) => { if (FilesBox.SelectedIndices.Count <= 0) { return; } var ctx = HackContext.GameContext; if (ctx == null) { MessageBox.Show(MainForm.CurrentLanguage["PleaseLockGame"]); return; } string h = $"./Scripts/{(string)FilesBox.SelectedItem}.qhscript"; string t = File.ReadAllText(($"./Scripts/{(string)FilesBox.SelectedItem}.qhscript")); var scope = HackContext.CreateScriptScope(MainForm.QHScriptEngine); MainForm.QHScriptEngine.Execute(t, scope); }; Controls.Add(ExecuteButton); Button CreateNewButton = new Button() { Text = MainForm.CurrentLanguage["Create"], Bounds = new Rectangle(214, 33, 80, 30), FlatStyle = FlatStyle.Flat, BackColor = Color.FromArgb(100, 150, 150, 150) }; CreateNewButton.Click += (s, e) => { MForm CreateNewMForm = new MForm { BackColor = Color.FromArgb(90, 90, 90), Text = MainForm.CurrentLanguage["Create"], StartPosition = FormStartPosition.CenterParent, ClientSize = new Size(245, 52) }; Label NameTip = new Label() { Text = MainForm.CurrentLanguage["Name"] + ":", Location = new Point(0, 0), Size = new Size(80, 20), TextAlign = ContentAlignment.MiddleCenter }; CreateNewMForm.MainPanel.Controls.Add(NameTip); TextBox NameTextBox = new TextBox { BorderStyle = BorderStyle.FixedSingle, BackColor = Color.FromArgb(120, 120, 120), Text = "", Location = new Point(85, 0), Size = new Size(95, 20) }; CreateNewMForm.MainPanel.Controls.Add(NameTextBox); Button ConfirmButton = new Button(); ConfirmButton.Text = MainForm.CurrentLanguage["Confirm"]; ConfirmButton.FlatStyle = FlatStyle.Flat; ConfirmButton.Size = new Size(65, 20); ConfirmButton.Location = new Point(180, 0); ConfirmButton.Click += (s1, e1) => { string str = $"./Scripts/{NameTextBox.Text}.qhscript"; if (!File.Exists(str)) { File.Create(str).Close(); } else { MessageBox.Show(MainForm.CurrentLanguage["NameRepeated"]); } UpdateList(); CreateNewMForm.Dispose(); }; CreateNewMForm.MainPanel.Controls.Add(ConfirmButton); CreateNewMForm.ShowDialog(this); }; Controls.Add(CreateNewButton); Button EditButton = new Button() { Text = MainForm.CurrentLanguage["Edit"], Bounds = new Rectangle(214, 63, 80, 30), FlatStyle = FlatStyle.Flat, BackColor = Color.FromArgb(100, 150, 150, 150) }; EditButton.Click += (s, e) => { if (FilesBox.SelectedIndices.Count <= 0) { return; } ScriptEditorForm p = new ScriptEditorForm((string)FilesBox.SelectedItem); p.Show(); }; Controls.Add(EditButton); Button RenameButton = new Button() { Text = MainForm.CurrentLanguage["Rename"], Bounds = new Rectangle(214, 93, 80, 30), FlatStyle = FlatStyle.Flat, BackColor = Color.FromArgb(100, 150, 150, 150) }; RenameButton.Click += (s, e) => { if (FilesBox.SelectedIndices.Count <= 0) { return; } MForm CreateNewMForm = new MForm { BackColor = Color.FromArgb(90, 90, 90), Text = MainForm.CurrentLanguage["Rename"], StartPosition = FormStartPosition.CenterParent, ClientSize = new Size(245, 52) }; Label NewNameTip = new Label() { Text = MainForm.CurrentLanguage["NewName"] + ":", Location = new Point(0, 0), Size = new Size(80, 20), TextAlign = ContentAlignment.MiddleCenter }; CreateNewMForm.MainPanel.Controls.Add(NewNameTip); TextBox NewNameTextBox = new TextBox { BorderStyle = BorderStyle.FixedSingle, BackColor = Color.FromArgb(120, 120, 120), Text = "", Location = new Point(85, 0), Size = new Size(95, 20) }; NewNameTextBox.Text = (string)FilesBox.SelectedItem; CreateNewMForm.MainPanel.Controls.Add(NewNameTextBox); Button ConfirmButton = new Button(); ConfirmButton.Text = MainForm.CurrentLanguage["Confirm"]; ConfirmButton.FlatStyle = FlatStyle.Flat; ConfirmButton.Size = new Size(65, 20); ConfirmButton.Location = new Point(180, 0); ConfirmButton.Click += (s1, e1) => { string str = $"./Scripts/{NewNameTextBox.Text}.qhscript"; if (!File.Exists(str)) { File.Move($"./Scripts/{(string)FilesBox.SelectedItem}.qhscript", str); } else { MessageBox.Show(MainForm.CurrentLanguage["NameRepeated"]); } UpdateList(); CreateNewMForm.Dispose(); }; CreateNewMForm.MainPanel.Controls.Add(ConfirmButton); CreateNewMForm.ShowDialog(this); }; Controls.Add(RenameButton); Button DeleteButton = new Button() { Text = MainForm.CurrentLanguage["Delete"], Bounds = new Rectangle(214, 123, 80, 30), FlatStyle = FlatStyle.Flat, BackColor = Color.FromArgb(100, 150, 150, 150) }; DeleteButton.Click += (s, e) => { if (FilesBox.SelectedIndices.Count <= 0) { return; } if (MessageBox.Show(MainForm.CurrentLanguage["SureToDelete"], "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } File.Delete(($"./Scripts/{(string)FilesBox.SelectedItem}.qhscript")); UpdateList(); }; this.Controls.Add(DeleteButton); Button RefreshButton = new Button() { Text = MainForm.CurrentLanguage["Refresh"], Bounds = new Rectangle(214, 153, 80, 30), FlatStyle = FlatStyle.Flat, BackColor = Color.FromArgb(100, 150, 150, 150) }; RefreshButton.Click += (s, e) => { UpdateList(); }; Controls.Add(RefreshButton); }