public MapEditor() { try { InitializeComponent(); EntryArrayBox.Load("Chapter List.txt"); Current = new StructFile("Chapter Struct.txt"); Current.Address = Core.GetPointer("Chapter Array"); ArrayFile map_file = new ArrayFile("Map List.txt"); MapData_ArrayBox.Load(map_file); Changes_ArrayBox.Load(map_file); TileAnim1_ArrayBox.Load(map_file); TileAnim2_ArrayBox.Load(map_file); Palette_ArrayBox.Load(map_file); TilesetTSA_ArrayBox.Load(map_file); Tileset1_ArrayBox.Load(map_file); Tileset2_ArrayBox.Load(map_file); Chapter_MagicButton.EditorToOpen = "Module:Chapter Editor"; } catch (Exception ex) { Program.ShowError("Could not properly open the " + this.Text, ex); Core_CloseEditor(this, null); } }
public MapSpriteEditor() { InitializeComponent(); try { Idle_EntryArrayBox.Load("Map Sprite List.txt"); Move_EntryArrayBox.Load("Class List.txt"); CurrentIdle = new StructFile("Map Sprite Idle Struct.txt"); CurrentMove = new StructFile("Map Sprite Move Struct.txt"); CurrentIdle.Address = Core.GetPointer("Map Sprite Idle Array"); CurrentMove.Address = Core.GetPointer("Map Sprite Move Array"); PaletteArrayBox.Load("Map Sprite Palettes.txt"); Idle_Size_ComboBox.DataSource = new KeyValuePair <string, byte>[3] { new KeyValuePair <string, byte>("16x16", 0x00), new KeyValuePair <string, byte>("16x32", 0x01), new KeyValuePair <string, byte>("32x32", 0x02) }; Idle_Size_ComboBox.ValueMember = "Value"; Idle_Size_ComboBox.DisplayMember = "Key"; CurrentPalette = Core.ReadPalette(Core.CurrentROM.Address_MapSpritePalettes(), GBA.Palette.LENGTH); Test_PaletteBox.Load(CurrentPalette); } catch (Exception ex) { Program.ShowError("Could not properly open the " + this.Text, ex); Core_CloseEditor(this, null); } }
private void ParseStructures() { StructParser parser = new StructParser(); try { StructSourceContext context = new StructSourceContext(); context.BaseDirectory = Path.GetDirectoryName(_structFileName); context.AddSourceText(_structFileName, _structEditControl.Text); _structFile = parser.LoadStructs(_structFileName, context); } catch (ParseException ex) { MessageBox.Show(this, "Error in " + ex.Position + ": " + ex.Message); List <ParseException> list = new List <ParseException>(); list.Add(ex); HighlightErrors(list.AsReadOnly()); return; } catch (Exception ex) { MessageBox.Show(this, "Error loading structures: " + ex.Message); } HighlightErrors(parser.Errors); if (parser.Errors.Count > 0) { ParseException ex = parser.Errors[0]; MessageBox.Show(this, "Error in " + ex.Position + ": " + ex.Message); } }
public virtual bool Write2buffer_Instructions(ref List <byte> bf) { try { StructFile sf_operator; OPERAND _operand; for (int j = 0; j < instructionlist.Count; j++) { sf_operator = new StructFile(typeof(OPERATOR)); OPERATOR _operator = instructionlist[j].Operator; //_operator.ReturnType = Common.ntohi(_operator.ReturnType); //_operator.OpCode = Common.ntohi(_operator.OpCode); _operator.Res2 = 2; _operator.Res3 = 3; sf_operator.WriteStructure(ref bf, (object)_operator); for (int k = 0; k < instructionlist[j].OperandList.Count; k++) { sf_operator = new StructFile(typeof(OPERAND)); _operand = instructionlist[j].OperandList[k]; //_operand.Index = Common.ntohl(_operand.Index); instructionlist[j].OperandList[k] = _operand; sf_operator.WriteStructure(ref bf, (object)instructionlist[j].OperandList[k]); } } return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
[Test] public void ParseSingleFieldStruct() { StructParser parser = new StructParser(); StructFile structFile = parser.LoadStructs("struct BITMAPINFOHEADER { u32 biSize; }"); StructDef structDef = structFile.Structs[0]; Assert.AreEqual(1, structDef.Fields.Count); Assert.AreEqual("biSize", structDef.Fields[0].Tag); }
[Test] public void ParseSingleEmptyStruct() { StructParser parser = new StructParser(); StructFile structFile = parser.LoadStructs("struct BITMAPINFOHEADER { }"); Assert.AreEqual(1, structFile.Structs.Count); StructDef structDef = structFile.Structs[0]; Assert.AreEqual("BITMAPINFOHEADER", structDef.Name); }
[Test] public void ParseFieldWithAttributes() { StructParser parser = new StructParser(); StructFile structFile = parser.LoadStructs("struct BITMAPFILEHEADER { str [len=2] bfType; }"); StructDef structDef = structFile.Structs[0]; Assert.AreEqual(1, structDef.Fields.Count); Assert.IsInstanceOfType(typeof(StrField), structDef.Fields [0]); StrField field = (StrField)structDef.Fields[0]; Assert.AreEqual("bfType", field.Tag); Assert.AreEqual("2", field.GetExpressionAttribute("len").ToString()); }
[Test] public void IncludeStructFile() { StructSourceContext context = new StructSourceContext(); context.AddSourceText("a.strs", "include b.strs; struct A { enum8 [enum=E] q; }"); context.AddSourceText("b.strs", "enum E { z, x, c }"); StructParser parser = new StructParser(); StructFile file = parser.LoadStructs("a.strs", context); Assert.IsNotNull(file); Assert.AreEqual(0, parser.Errors.Count); EnumDef e = file.GetEnumByName("E"); Assert.AreEqual("c", e.ValueToString(2)); }
/// <summary> /// Получить тип таблицы из файла /// </summary> /// <param name="path">Путь к файлу</param> /// <returns></returns> public bool GetTableType(string path) { string json; json = File.ReadAllText(path); try { StructFile table = JsonConvert.DeserializeObject <StructFile>(json); return(table.typeGrid); } catch { throw new Exception("Не целостный файл!"); } }
private static InstanceTree PrepareInstanceTree(string structDefs, byte[] data) { StructParser parser = new StructParser(); StructFile structFile = parser.LoadStructs(structDefs); if (structFile == null && parser.Errors.Count > 0) { Assert.IsTrue(false, parser.Errors[0].Message); } else { Assert.IsNotNull(structFile); } MemoryStream dataStream = new MemoryStream(data); return(structFile.Structs[0].LoadData(dataStream)); }
public BattleScreenEditor() { try { InitializeComponent(); EntryArrayBox.Load("Battle Platform List.txt"); Current = new StructFile("Battle Platform Struct.txt"); Current.Address = Core.GetPointer("Battle Platform Array"); } catch (Exception ex) { Program.ShowError("Could not properly open the " + this.Text, ex); Core_CloseEditor(this, null); } }
public MusicEditor() { try { InitializeComponent(); EntryArrayBox.Load("Music List.txt"); Current = new StructFile("Music Struct.txt"); Current.Address = Core.GetPointer("Music Array"); Preview = new Music(); } catch (Exception ex) { Program.ShowError("Could not properly open the " + this.Text, ex); Core_CloseEditor(this, null); } }
public StructFile LoadStructs(string fileName, StructSourceContext context) { StructFile result = new StructFile(fileName.Length > 0 ? Path.GetDirectoryName(fileName) : ""); _curStructFile = result; LoadStructFile(fileName, context); foreach(ReferenceBase reference in result.References) { try { reference.Resolve(); } catch(ParseException ex) { _errors.Add(ex); } } if (_errors.Count == 0) return result; return null; }
public override bool Write2File_OPERATION(BinaryWriter bw) { try { OPERATION _operation = new OPERATION(); StructFile sf_operation = new StructFile(typeof(OPERATION)); _operation.Size1 = QSize(); _operation.Size2 = ThenSize(); _operation.Size3 = ElseSize(); _operation.operationType = (int)OPERATION_TYPE.IF_ELSE_OPERATION; _operation.Size1 = Common.ntohi(_operation.Size1); _operation.Size2 = Common.ntohi(_operation.Size2); _operation.Size3 = Common.ntohi(_operation.Size3); sf_operation.WriteStructure(bw, (object)_operation); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
public BackgroundEditor() { try { InitializeComponent(); EntryArrayBox.Load("Dialog Background List.txt"); CurrentDialog = new StructFile("Dialog Background Struct.txt"); CurrentBattle = new StructFile("Battle Background Struct.txt"); CurrentScreen = new StructFile("Cutscene Screen Struct.txt"); CurrentDialog.Address = Core.GetPointer("Dialog Background Array"); CurrentBattle.Address = Core.GetPointer("Battle Background Array"); CurrentScreen.Address = Core.GetPointer("Cutscene Screen Array"); } catch (Exception ex) { Program.ShowError("Could not properly open the " + this.Text, ex); Core_CloseEditor(this, null); } }
public virtual bool Write2Buffer_OPERATION(ref List <byte> bf) { try { OPERATION _operation = new OPERATION(); StructFile sf_operation = new StructFile(typeof(OPERATION)); _operation.Size1 = Size(); _operation.Size2 = 0; _operation.Size3 = 0; _operation.operationType = (int)OPERATION_TYPE.SIMPLE_OPERATION; //_operation.Size1 = Common.ntohi(_operation.Size1); //_operation.Size2 = Common.ntohi(_operation.Size2); //_operation.Size3 = Common.ntohi(_operation.Size3); sf_operation.WriteStructure(ref bf, (object)_operation); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
public virtual int Size() { int logicprogramSize = 0; StructFile sf1 = new StructFile(typeof(OPERATOR)); StructFile sf2 = new StructFile(typeof(OPERAND)); OPERATION op = new OPERATION(); logicprogramSize += Marshal.SizeOf(op); for (int j = 0; j < instructionlist.Count; j++) { logicprogramSize += sf1.SizeofStructure((object)instructionlist[j].Operator); for (int k = 0; k < instructionlist[j].OperandList.Count; k++) { logicprogramSize += sf2.SizeofStructure((object)instructionlist[j].OperandList[k]); } } return(logicprogramSize); }
public EventEditor() { try { InitializeComponent(); Entry_ArrayBox.Load("Chapter List.txt"); Event_ArrayBox.Load("Map List.txt"); Current = new StructFile("Chapter Struct.txt"); Help_ToolTip_Timer = new Timer(); Help_ToolTip_Timer.Tick += HoverTick; Help_ToolTip_Timer.Interval = 800; Chapter_MagicButton.EditorToOpen = "Module:Chapter Editor"; } catch (Exception ex) { Program.ShowError("Could not properly open the " + this.Text, ex); Core_CloseEditor(this, null); } }
public FindStructureDialog(StructFile structFile) { InitializeComponent(); cmbStructures.Items.AddRange(structFile.Structs.ToArray()); }
private void ParseStructures() { StructParser parser = new StructParser(); try { StructSourceContext context = new StructSourceContext(); context.BaseDirectory = Path.GetDirectoryName(_structFileName); context.AddSourceText(_structFileName, _structEditControl.Text); _structFile = parser.LoadStructs(_structFileName, context); } catch(ParseException ex) { MessageBox.Show(this, "Error in " + ex.Position + ": " + ex.Message); List<ParseException> list = new List<ParseException>(); list.Add(ex); HighlightErrors(list.AsReadOnly()); return; } catch(Exception ex) { MessageBox.Show(this, "Error loading structures: " + ex.Message); } HighlightErrors(parser.Errors); if (parser.Errors.Count > 0) { ParseException ex = parser.Errors[0]; MessageBox.Show(this, "Error in " + ex.Position + ": " + ex.Message); } }
public byte[] SaveCompiledExpressions() { List <byte> buffer = new List <byte>(); //VALUE _value = new VALUE(); //string _valuestr = ""; int size = 0; DrawExpressionCollectionCode drawexpressioncollectioncode = new DrawExpressionCollectionCode(); size = Marshal.SizeOf(drawexpressioncollectioncode); drawexpressioncollectioncode.BufferSize = size; drawexpressioncollectioncode.IsValid = 1; drawexpressioncollectioncode.NoOfDynamicProperties = objDisplayObjectDynamicPropertys.Count; //drawexpressioncollectioncode.NoOfExpressions = 0; // add above structure to buffer StructFile sfDrawExpressionCollectionCode = new StructFile(typeof(DrawExpressionCollectionCode)); sfDrawExpressionCollectionCode.WriteStructure(ref buffer, (object)drawexpressioncollectioncode); // foreach (DisplayObjectDynamicProperty exs in objDisplayObjectDynamicPropertys.list) { ExpressionCode expressioncode = new ExpressionCode(); size = Marshal.SizeOf(expressioncode); expressioncode.Property = (int)exs.ObjectType; expressioncode.NoOfConditions = exs.NoOfConditions; expressioncode.ReturnType = (int)exs.Type; if (exs.IsColor) { expressioncode.IsColor = 1; } else { expressioncode.IsColor = 0; } expressioncode.ExecutionType = 1;// 0 initialization 1 Cyclic expressioncode.IsValid = 0; StructFile sfEcpressionCode = new StructFile(typeof(ExpressionCode)); expressioncode.IsValid = 1; FillPropertyList(ref expressioncode, exs.ObjectType); sfEcpressionCode.WriteStructure(ref buffer, (object)expressioncode); foreach (DisplayObjectDynamicPropertyCondition cs in exs.ConditionList) { ConditionCode conditioncode = new ConditionCode(); //conditioncode.StrValue = new STRINGOBJ(); conditioncode.Size = cs.SimpleOperation.Size1(); if (exs.IsString) { //unsafe { conditioncode.StrValue.Len = cs.m_StrValue.Len; conditioncode.StrValue.Val00 = cs.m_StrValue.Val00; conditioncode.StrValue.Val01 = cs.m_StrValue.Val01; conditioncode.StrValue.Val02 = cs.m_StrValue.Val02; conditioncode.StrValue.Val03 = cs.m_StrValue.Val03; conditioncode.StrValue.Val04 = cs.m_StrValue.Val04; conditioncode.StrValue.Val05 = cs.m_StrValue.Val05; conditioncode.StrValue.Val06 = cs.m_StrValue.Val06; conditioncode.StrValue.Val07 = cs.m_StrValue.Val07; conditioncode.StrValue.Val08 = cs.m_StrValue.Val08; conditioncode.StrValue.Val09 = cs.m_StrValue.Val09; conditioncode.StrValue.Val10 = cs.m_StrValue.Val10; conditioncode.StrValue.Val11 = cs.m_StrValue.Val11; conditioncode.StrValue.Val12 = cs.m_StrValue.Val12; conditioncode.StrValue.Val13 = cs.m_StrValue.Val13; conditioncode.StrValue.Val14 = cs.m_StrValue.Val14; conditioncode.StrValue.Val15 = cs.m_StrValue.Val15; //for (int k = 0; k < cs.m_StrValue.Len; k++) //{ // conditioncode.Val[k] = cs.m_StrValue.Val[k]; //} } } else { conditioncode.Value.ULINT = cs.m_Value.ULINT; } StructFile sfConditionCode = new StructFile(typeof(ConditionCode)); sfConditionCode.WriteStructure(ref buffer, conditioncode); cs.SimpleOperation.Write2Buffer(ref buffer); } } return(buffer.ToArray()); }
/// <summary> /// Открыть файл и добавить его в таблицу /// </summary> /// <param name="grid">Таблица</param> /// <param name="path">Путь к файлу</param> /// <param name="type"> /// <list type="table"> /// <listheader>Тип таблицы:</listheader> /// <item>false - средний взвешенный балл</item> /// <item>true - средний балл</item> /// </list> /// </param> public void OpenFile(DataGridView grid, string path, bool type) { string json; StructFile table = null; json = File.ReadAllText(path); try { table = JsonConvert.DeserializeObject <StructFile>(json); } catch { MessageBox.Show("Таблица не была загружена.\nПроверьте целостность файла.", "Ошибка чтения файла", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (table != null) { if (table.typeGrid != type) { MessageBox.Show("Не совпадают настройки типа вычисления баллов!\rПоменяйте в вкладке тип на средний балл/средний взвешенный бал.", "Ошибка несовместимости", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MarksTable drawTable; if (!type) { drawTable = new MarksTableAverageMass { marks = grid }; drawTable.marks.Rows.Clear(); drawTable.marks.Columns.Clear(); drawTable.DrawGrid((table.columnCount - 2) / 2, table.nameLess); } else { drawTable = new MarksTableAverage { marks = grid }; drawTable.marks.Rows.Clear(); drawTable.marks.Columns.Clear(); drawTable.DrawGrid(table.columnCount - 2, table.nameLess); } int posRow = 0, posColumn = 1; for (int i = 0; i < table.marks.Count; i++) { for (int j = 0; j < table.marks[i].Count; j++) { drawTable.marks[posColumn, posRow].Value = table.marks[i][j]; posColumn++; } posRow++; posColumn = 1; } } } }
/// <summary> /// Сохранить таблицу в файл /// </summary> /// <param name="grid">Таблица</param> /// <param name="startEdit">Начат редактироваться таблица</param> /// <param name="fileName">Имя файла</param> /// <param name="type"> /// <list type="table"> /// <listheader>Тип таблицы:</listheader> /// <item>false - средний взвешенный балл</item> /// <item>true - средний балл</item> /// </list> /// </param> public bool SaveFile(DataGridView grid, bool startEdit, bool type, string fileName) { bool returnBool = true; StructFile table = new StructFile { typeGrid = type, columnCount = grid.ColumnCount }; for (int i = 0; i < grid.RowCount; i++) { if (grid[0, i].Value != null) { table.nameLess.Add(grid[0, i].Value.ToString()); } else { table.nameLess.Add(""); } } for (int i = 0; i < grid.RowCount; i++) { table.marks.Add(new List <string>()); for (int j = 1; j < grid.ColumnCount - 1; j++) { if (grid[j, i].Value != null) { table.marks[i].Add(grid[j, i].Value.ToString()); } } } Stream saveStream; using SaveFileDialog saveLevelDialog = new SaveFileDialog { Filter = "dnv Файл (*.dnv)|*.dnv|txt Файл (*.txt)|*.txt", RestoreDirectory = true, FileName = fileName }; if (saveLevelDialog.ShowDialog() == DialogResult.OK) { if ((saveStream = saveLevelDialog.OpenFile()) != null) { StreamWriter myWriter = new StreamWriter(saveStream); try { myWriter.Write(JsonConvert.SerializeObject(table, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); MessageBox.Show("Таблица сохранена!", "Успех!", MessageBoxButtons.OK, MessageBoxIcon.Information); startEdit = false; returnBool = false; } catch { MessageBox.Show("Таблица не сохранена!\rПопробуйте поменять имя файла или проверить не занят ли файл другим процессом.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { myWriter.Close(); } saveStream.Close(); } } return(returnBool); }
/// <summary> /// Открыть файл и добавить его в таблицу /// </summary> /// <param name="grid">Таблица</param> /// <param name="startEdit">Начат редактироваться таблица</param> /// <param name="fileOpen">Открыт файл</param> /// <param name="type"> /// <list type="table"> /// <listheader>Тип таблицы:</listheader> /// <item>false - средний взвешенный балл</item> /// <item>true - средний балл</item> /// </list> /// </param> public void OpenFile(DataGridView grid, bool startEdit, bool fileOpen, bool type) { if (startEdit) { DialogResult result = MessageBox.Show("Сохранить таблицу перед открытием файла?", "Сохранить?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { SaveFile(grid, startEdit, type, ""); } } using OpenFileDialog loadFileDialog = new OpenFileDialog { Filter = "dnv Файл (*.dnv)|*.dnv|txt Файл (*.txt)|*.txt", RestoreDirectory = true }; string json; StructFile table = null; if (loadFileDialog.ShowDialog() == DialogResult.OK) { string fname = loadFileDialog.FileName; //directory = loadFileDialog.FileName; json = File.ReadAllText(fname); try { table = JsonConvert.DeserializeObject <StructFile>(json); fileOpen = true; } catch { MessageBox.Show("Таблица не была загружена.\nПроверьте целостность файла.", "Ошибка чтения файла", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (table != null) { if (table.typeGrid != type) { MessageBox.Show("Не совпадают настройки типа вычисления баллов!\rПоменяйте в вкладке тип на средний балл/средний взвешенный бал.", "Ошибка несовместимости", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MarksTable drawTable; if (!type) { drawTable = new MarksTableAverageMass { marks = grid }; drawTable.marks.Rows.Clear(); drawTable.marks.Columns.Clear(); drawTable.DrawGrid((table.columnCount - 2) / 2, table.nameLess); } else { drawTable = new MarksTableAverage { marks = grid }; drawTable.marks.Rows.Clear(); drawTable.marks.Columns.Clear(); drawTable.DrawGrid(table.columnCount - 2, table.nameLess); } int posRow = 0, posColumn = 1; for (int i = 0; i < table.marks.Count; i++) { for (int j = 0; j < table.marks[i].Count; j++) { drawTable.marks[posColumn, posRow].Value = table.marks[i][j]; posColumn++; } posRow++; posColumn = 1; } } } }
public StructDef(StructFile structFile, string name) { _structFile = structFile; _name = name; }
public EnumDef(StructFile file, string name) { _structFile = file; _name = name; }