private void _TestCompile_Button_Click(object sender, EventArgs e) { ExcelScript script = new ExcelScript(_fileManager); try { script.Compile(_scriptEditor_RichTextBox.Text); } catch (Exception ex) { MessageBox.Show("Failed to compile script!\n\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void _Save_Button_Click(object sender, EventArgs e) { DialogResult dr = DialogResult.Yes; if (_textChanged) { dr = MessageBox.Show("Changes to the script have been made, attempt to compile the script and save befor exiting?", "Save Changes?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); } if (dr == DialogResult.Cancel) { return; } if (dr == DialogResult.No) { Close(); return; } ExcelScript script = new ExcelScript(_fileManager); try { script.Compile(_scriptEditor_RichTextBox.Text); } catch (Exception ex) { MessageBox.Show("Failed to compile script!\n\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); dr = MessageBox.Show("Do you wish to still quit?", "Quit without saving?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.No) { return; } if (dr == DialogResult.Yes) { Close(); return; } } _dataGridViewCell.Value = _scriptEditor_RichTextBox.Text; }
private void AddFoldersAndFiles(Node n, string path) { string[] directories; try { directories = Directory.GetDirectories(path); } catch (UnauthorizedAccessException ex) { return; } catch (DirectoryNotFoundException ex) { return; } foreach (string path1 in directories) { Node node = new Node(new object[4] { Path.GetFileName(path1), null, null, null }); AddFoldersAndFiles(node, path1); n.Nodes.Add(node); } string[] files; try { files = Directory.GetFiles(path, "*.xls"); } catch (UnauthorizedAccessException ex) { return; } catch (DirectoryNotFoundException ex) { return; } foreach (string path1 in files) { try { FileInfo fileInfo = ExcelScript.GetFileInfo(path1); int num = 1; Node newnode = new Node(new object[4] { Path.GetFileName(path1), fileInfo.Title, string.Empty, fileInfo.LinesLeft }); newnode.Tag = path1; foreach (EpisodeInfo episode in fileInfo.Episodes) { newnode.Nodes.Add(new Node(new object[4] { string.Empty, episode.Title, episode.Number, episode.LinesLeft }) { Tag = num++ }); } n.Nodes.Add(newnode); } catch (InvalidDataException ex) { } catch (IOException ex) { } } }
private DataTable _LoadExcelTable(ExcelFile excelFile, bool doRelations, bool force) { String tableName = excelFile.StringId; DataTable dataTable = XlsDataSet.Tables[tableName]; if (dataTable != null && !force) { return(dataTable); } if (dataTable != null) { XlsDataSet.Relations.Clear(); XlsDataSet.Tables.Remove(tableName); } dataTable = XlsDataSet.Tables.Add(tableName); dataTable.TableName = tableName; dataTable.ExtendedProperties.Add("FileHeader", excelFile._excelFileHeader.DeepClone()); Type dataType = excelFile.Attributes.RowType; List <OutputAttribute> outputAttributes = new List <OutputAttribute>(); #region Generate Columns DataColumn indexColumn = dataTable.Columns.Add("Index"); indexColumn.AutoIncrement = true; indexColumn.Unique = true; dataTable.PrimaryKey = new[] { indexColumn }; outputAttributes.Add(null); FieldInfo[] fieldInfos = dataType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fieldInfos) { OutputAttribute excelAttribute = ExcelFile.GetExcelAttribute(fieldInfo); // The only private field we add is the TableHeader if (fieldInfo.IsPrivate) { if (fieldInfo.FieldType != typeof(ExcelFile.RowHeader)) { continue; } outputAttributes.Add(null); dataTable.Columns.Add(fieldInfo.Name, typeof(String)); continue; } Type fieldType = fieldInfo.FieldType; bool isArray = false; bool isEnum = false; if (fieldInfo.FieldType.BaseType == typeof(Array)) { fieldType = typeof(String); isArray = true; } else if (fieldInfo.FieldType.BaseType == typeof(Enum) && excelAttribute == null) { fieldType = fieldInfo.FieldType; isEnum = true; } DataColumn dataColumn = dataTable.Columns.Add(fieldInfo.Name, fieldType); if (isArray) { dataColumn.ExtendedProperties.Add(ColumnKeys.IsArray, true); } else if (isEnum) { dataColumn.ExtendedProperties.Add(ColumnKeys.IsEnum, true); } if (excelAttribute == null) { outputAttributes.Add(null); continue; } outputAttributes.Add(excelAttribute); if (excelAttribute.IsStringOffset) { dataColumn.DataType = typeof(String); dataColumn.ExtendedProperties.Add(ColumnKeys.IsStringOffset, true); dataColumn.DefaultValue = String.Empty; } if (excelAttribute.IsScript) { dataColumn.DataType = typeof(String); dataColumn.ExtendedProperties.Add(ColumnKeys.IsScript, true); dataColumn.DefaultValue = String.Empty; } if (excelAttribute.IsSecondaryString) { dataColumn.DataType = typeof(String); dataColumn.ExtendedProperties.Add(ColumnKeys.IsSecondaryString, true); dataColumn.DefaultValue = String.Empty; } if (excelAttribute.IsStringIndex) { dataColumn.ExtendedProperties.Add(ColumnKeys.IsStringIndex, true); // Add new column for the string DataColumn dataColumnString = dataTable.Columns.Add(fieldInfo.Name + "_string", typeof(String)); dataColumnString.DefaultValue = String.Empty; outputAttributes.Add(null); dataColumnString.ExtendedProperties.Add(ColumnKeys.IsRelationGenerated, true); } if (excelAttribute.IsTableIndex) { dataColumn.ExtendedProperties.Add(ColumnKeys.IsTableIndex, true); // Add new column for the string DataColumn dataColumnString = dataTable.Columns.Add(fieldInfo.Name + "_string", typeof(String)); dataColumnString.DefaultValue = String.Empty; outputAttributes.Add(null); dataColumnString.ExtendedProperties.Add(ColumnKeys.IsRelationGenerated, true); } if (excelAttribute.IsBitmask) { dataColumn.ExtendedProperties.Add(ColumnKeys.IsBitmask, true); } if (excelAttribute.IsBool) { dataColumn.ExtendedProperties.Add(ColumnKeys.IsBool, true); } } if (excelFile.Attributes.HasStats) // items, missiles, monsters, objects, players { DataColumn extendedDataColumn = dataTable.Columns.Add("Stats"); extendedDataColumn.DataType = typeof(String); extendedDataColumn.ExtendedProperties.Add(ExcelFile.ColumnTypeKeys.IsStats, true); outputAttributes.Add(null); } #endregion #region Generate Rows int row = 1; object[] baseRow = new object[outputAttributes.Count]; ObjectDelegator objectDelegator = new ObjectDelegator(fieldInfos); foreach (Object tableRow in excelFile.Rows) { int col = 1; foreach (FieldInfo fieldInfo in fieldInfos) { Object value = objectDelegator[fieldInfo.Name](tableRow); if (fieldInfo.IsPrivate) { if (fieldInfo.FieldType != typeof(ExcelFile.RowHeader)) { continue; } baseRow[col++] = FileTools.ObjectToStringGeneric(value, ","); continue; } OutputAttribute excelOutputAttribute = outputAttributes[col]; if (excelOutputAttribute == null) { if (value.GetType().BaseType == typeof(Array)) { value = ((Array)value).ToString(","); } baseRow[col++] = value; continue; } if (excelOutputAttribute.IsStringOffset) { int valueInt = (int)value; baseRow[col++] = (valueInt != -1) ? excelFile.ReadStringTable(valueInt) : String.Empty; continue; } if (excelOutputAttribute.IsSecondaryString) { int valueInt = (int)value; baseRow[col++] = (valueInt != -1) ? excelFile.ReadSecondaryStringTable(valueInt) : String.Empty; continue; } if (excelOutputAttribute.IsScript) { int scriptOffset = (int)value; if (scriptOffset == 0) { baseRow[col++] = String.Empty; continue; } String script; if (scriptOffset == 9649 && excelFile.StringId == "SKILLS") // todo: not sure what's with this script... { /* Compiled Bytes: * 26,30,700,6,26,1,399,358,669,616562688,711,26,62,3,17,669,641728512,26,8,711,26,62,3,17,358,669,322961408,26,5,700,6,26,1,399,358,388,0 * * Ending Stack (FIFO): * SetStat669('sfx_attack_pct', 'all', 30 * ($sklvl - 1)) * SetStat669('sfx_duration_pct', 'all', get_skill_level(@unit, 'Shield_Mastery')) * SetStat669('damage_percent_skill', 8 * get_skill_level(@unit, 'Shield_Mastery')) * SetStat669('damage_percent_skill', 8 * get_skill_level(@unit, 'Shield_Mastery')) + 5 * ($sklvl - 1) * * The last SetStat has strange overhang - decompiling wrong? * Or is it "supposed" to be there? * i.e. It's actually decompiling correctly, but because I've assumed such scripts to be wrong (as the end +5... segment is useless) we get the Stack exception */ int[] scriptCode = excelFile.ReadScriptTable(scriptOffset); script = scriptCode != null?FileTools.ArrayToStringGeneric(scriptCode, ",") : "ScriptError"; baseRow[col++] = script; continue; } //if (fieldInfo.Name == "props1" && row == 45) //{ // int bp = 0; //} ExcelScript excelScript = new ExcelScript(this); try { if (ExcelScript.DebugEnabled) { int[] scriptCode = excelFile.ReadScriptTable(scriptOffset); script = scriptCode != null?FileTools.ArrayToStringGeneric(scriptCode, ",") : String.Empty; script = excelScript.Decompile(excelFile.ScriptBuffer, scriptOffset, script, excelFile.StringId, row, col, fieldInfo.Name); } else { script = excelScript.Decompile(excelFile.ScriptBuffer, scriptOffset); } //if (script.StartsWith("GetStat666('skill_points_bonus_total', '') > -1;")) //{ // int bp = 0; //} } catch (Exception) { int[] scriptCode = excelFile.ReadScriptTable(scriptOffset); script = scriptCode != null?FileTools.ArrayToStringGeneric(scriptCode, ",") : "ScriptError"; } baseRow[col++] = script; continue; } if (excelOutputAttribute.IsTableIndex || excelOutputAttribute.IsStringIndex) { if (value.GetType().BaseType == typeof(Array)) { value = ((Array)value).ToString(","); } else { value = (int)value; } baseRow[col++] = value; col++; // for _strings relational column continue; } // Else its something else, ie bitmask, bool, table/string index baseRow[col++] = value; } // stats, only a component of the UnitData row type if (excelFile.Attributes.HasStats) { baseRow[col++] = FileTools.ArrayToStringGeneric(excelFile.ReadStats(row - 1), ","); } dataTable.Rows.Add(baseRow); row++; } #endregion // Generate Relationships as required if (doRelations) { _GenerateRelations(excelFile); } return(dataTable); }