private void menuItem_encryptscript_Click(object sender, EventArgs e) { try { string source_file, output_file; DialogResult okOrNo;//dialog return value, if it is DialogResult.OK then everything is OK openFileDialog1.Title = "Select source script file"; openFileDialog1.InitialDirectory = Globals.PATH + "\\Scripts"; //Initial dir, where it begins looking at. openFileDialog1.Filter = "Script Files (*.l2s)|*.l2s|Script Classes (*.l2c)|*.l2c"; //this particualr format is for one file type. openFileDialog1.FilterIndex = 1; //this means that the first description is the default one. openFileDialog1.RestoreDirectory = true; //The next dialog box opened will start at the inital dir. okOrNo = openFileDialog1.ShowDialog(); //open the dialog box and save the result. if (okOrNo != DialogResult.OK) //if the dialog box works { return; } source_file = openFileDialog1.FileName; saveFileDialog1.Title = "Select output script file"; saveFileDialog1.InitialDirectory = Globals.PATH + "\\Scripts"; //Initial dir, where it begins looking at. saveFileDialog1.Filter = "Script Files (*.l2s)|*.l2s"; //this particualr format is for one file type. saveFileDialog1.FilterIndex = 1; //this means that the first description is the default one. saveFileDialog1.RestoreDirectory = true; //The next dialog box opened will start at the inital dir. okOrNo = saveFileDialog1.ShowDialog(); //open the dialog box and save the result. if (okOrNo != DialogResult.OK) //if the dialog box works { return; } output_file = saveFileDialog1.FileName; //got our two files... now to encrypt Script_Crypt.Encrypt(source_file, output_file); } catch { Globals.l2net_home.Add_Error("ERROR WHILE ENCYPTING SCRIPT!"); } }
public void ReadScript(System.IO.StreamReader filein) { _ScriptLines.Clear(); string line; while ((line = filein.ReadLine()) != null) { line = line.Trim(); ScriptLine sl = new ScriptLine(); sl.FullLine = line; string cmd = ScriptEngine.Get_String(ref line, false).ToUpperInvariant(); sl.Command = ScriptEngine.GetCommandType(cmd); switch (sl.Command) { case ScriptCommands.ENCRYPTED: //need to scrap everything that has been loaded so far... _ScriptLines.Clear(); int key = Util.GetInt32(line); string encoded_script = filein.ReadLine(); filein = Script_Crypt.Decrypt(encoded_script, key); break; case ScriptCommands.IF: case ScriptCommands.WHILE: case ScriptCommands.LOOP: case ScriptCommands.UNKNOWN: if (Globals.ScriptCompatibilityv386) { sl.UnParsedParams = line.Replace("(", " ( ").Replace(")", " ) "); } else { sl.UnParsedParams = line; } _ScriptLines.Add(sl); break; default: sl.UnParsedParams = line; _ScriptLines.Add(sl); break; } } //need to parse out comments in the file here... bool comment_block = false; for (int i = 0; i < _ScriptLines.Count; i++) { string cmd = ((ScriptLine)_ScriptLines[i]).FullLine.ToUpperInvariant(); //start a comment block if (cmd.StartsWith("/*")) { comment_block = true; } if (comment_block) { ((ScriptLine)_ScriptLines[i]).Command = ScriptCommands.NULL; ((ScriptLine)_ScriptLines[i]).FullLine = ""; } //end of comment block // we end after we clear because we want to clear this line still (inclusive) if (cmd.EndsWith("*/")) { comment_block = false; } //normal line comment if (cmd.StartsWith("//")) { ((ScriptLine)_ScriptLines[i]).Command = ScriptCommands.NULL; ((ScriptLine)_ScriptLines[i]).FullLine = ""; } } }