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 TextEditor() { try { InitializeComponent(); TextCommands1 = new ArrayFile("Text Commands.txt"); TextCommands2 = new ArrayFile("Text Commands 2.txt"); PortraitList = new ArrayFile("Portrait List.txt"); Text_CodeBox.KeyDown += new KeyEventHandler(TextBox_SelectAll); Text_CodeBox.AddSyntax(@"\[(.*?)\]", System.Drawing.SystemColors.Highlight); Font_ComboBox.DataSource = new string[] { "Menu Font", "Text Bubble Font" }; } catch (Exception ex) { Program.ShowError("Could not properly open the " + this.Text, ex); Core_CloseEditor(this, null); } }
public Module(string[] file) { if (file[0] != Program.Core.CurrentROM.GetIdentifier()) { throw new Exception("this Emblem Magic Module is meant for another ROM: " + file[0]); } if (file[7] != "NULL") { Entries = new ArrayFile(file[7]); } else { Entries = null; } Pointer = new Repoint(file[1], ReadAddress(file[3], Entries)); EntryLength = int.Parse(file[5]); Property module = new Property(1, file[1], file[2], "0", "0", file[6], file[7]); Name = module.Name; Author = module.Section; Entry = module.GetControl(); if (Entry is NumericUpDown) { ((NumericUpDown)Entry).Maximum = ReadNumber(file[4]); } Entry.Name = "EntrySelector"; Entry.TabIndex = 2; Entry.Location = new Point(80, (Entries == null) ? 2 : 0); Entry.MaximumSize = new Size(10000, 26); Entry.MinimumSize = new Size(30, 26); Entry.Anchor = AnchorStyles.Top | AnchorStyles.Left; Entry.AutoSize = true; List <Property> properties = new List <Property>(); for (int i = 8; i < file.Length; i += 6) { while (file[i] == "") { i++; } properties.Add(new Property( i, file[i], file[i + 1], file[i + 2], file[i + 3], file[i + 4], file[i + 5])); } Properties = properties.ToArray(); }
public void Load(List <Track> tracks) { foreach (ProgressBar bar in Volumes) { bar.Dispose(); } Volumes.Clear(); Columns.Clear(); Controls.Clear(); try { ArrayFile notes = new ArrayFile("Music Notes.txt"); int width = RowHeadersWidth; for (int i = 0; i < tracks.Count; i++) { Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "Track " + i + "\n\n" + "Notes |Vol|Ins|Pan| Effects", MinimumWidth = 200, SortMode = DataGridViewColumnSortMode.Programmatic }); width += Columns[i].HeaderCell.Size.Width; ProgressBar volume = new ProgressBar(); Volumes.Add(volume); Controls.Add(volume); string[][] track = tracks[i].GetTrackerString(notes); const int height = 14; for (int j = 0; j < track.Length; j++) { if (RowCount <= j) { Rows.Add(new DataGridViewRow() { Height = height }); } Rows[j].HeaderCell.Value = Util.IntToHex((uint)j); Rows[j].Cells[i].Value = track[j]; Rows[j].Height = Math.Max( (track[j][0] == null) ? height : track[j][0].Split('\n').Length *height, (track[j][4] == null) ? height : track[j][4].Split('\n').Length *height); } } PlaceVolumeBars(this, null); } catch (Exception ex) { Program.ShowError("Error while loading tracker datagrid.", ex); } }
/// <summary> /// Reads a string hex address and returns the corresponding GBA.Pointer /// </summary> static Pointer ReadAddress(string pointer, ArrayFile entries) { Pointer result = Util.StringToAddress(pointer); if (result == new Pointer()) { string caption = "Specify Module Pointer"; string text = "This module has no address specified.\n Please enter the address of the data to edit."; result = (entries == null) ? Prompt.ShowPointerDialog(text, caption) : Prompt.ShowPointerArrayBoxDialog(text, caption); } return(result); }
string Core_GetAllArrayDefines() { string result = "#define None 0\r\n"; string define; ArrayFile definitions; string[] files = new string[] { "Dialog Background List.txt", "Cutscene Screen List.txt", "Music List.txt", "Chapter List.txt", "Character List.txt", "Class List.txt", "Item List.txt", }; //FileInfo[] files = new DirectoryInfo(Core.Path_Arrays).GetFiles("*.txt"); //foreach (FileInfo file in files) foreach (string file in files) { if (file.EndsWith("Commands.txt")) { continue; } definitions = new ArrayFile(file); result += "\r\n"; result += "// " + "file.Name\r\n"; for (uint i = 0; i <= definitions.LastEntry; i++) { define = EventAssemblerIO.ReplaceSpacesAndSpecialChars(definitions[i]); if (define.Equals("None")) { continue; } if (define.Length > 1) { result += "#define " + define + "\t" + i + "\r\n"; } } } return(result); }
public void Load(ArrayFile file) { File = file; int longestString = 0; for (uint i = 0; i <= File.LastEntry; i++) { if (File[i].Length > longestString) { longestString = File[i].Length; } } if (AutoSize) { this.Size = new Size(EntryValueBox.Width + 30 + longestString * 5, 26); EntryComboBox.Width = this.Width - EntryValueBox.Width - 10; this.AutoSize = false; } //if (File.LastEntry != 0) EntryValueBox.Maximum = File.LastEntry; EntryValueBox.MouseWheel += delegate(object sender, MouseEventArgs e) { ((HandledMouseEventArgs)e).Handled = true; }; EntryComboBox.DataSource = File.ToList(); EntryComboBox.ValueMember = "Key"; EntryComboBox.DisplayMember = "Value"; EntryComboBox.SelectedValueChanged += UpdateEntryValueBox; EntryComboBox.TextUpdate += UpdateArrayFileText; EntryComboBox.MouseWheel += delegate(object sender, MouseEventArgs e) { ((HandledMouseEventArgs)e).Handled = true; }; UpdateEntryComboBox(this, null); }
public MapTilesetEditor() { try { InitializeComponent(); Terrain_ArrayBox.Load("Terrain List.txt"); Terrain_Stat_PointerArrayBox.Load("Terrain Stat Pointers.txt"); Terrain_Class_PointerArrayBox.Load("Terrain Move Cost Pointers.txt"); string[] file; try { file = File.ReadAllLines(Core.Path_Arrays + "Map List.txt"); } catch (Exception ex) { throw new Exception("Could not open the array file:\n" + Core.Path_Arrays + "Map List.txt", ex); } List <string> list_palettes = new List <string>(); List <string> list_tilesets = new List <string>(); List <string> list_tsa_array = new List <string>(); List <string> list_tile_anim = new List <string>(); foreach (string entry in file) { if (entry == null || entry == "" || entry.Length < 10) { continue; } else { switch (entry.Substring(5, 5)) { case "[PAL]": list_palettes.Add(entry); break; case "[IMG]": list_tilesets.Add(entry); break; case "[TSA]": list_tsa_array.Add(entry); break; case "[ANM]": list_tile_anim.Add(entry); break; } } } ArrayFile palettes = new ArrayFile(list_palettes.ToArray()); ArrayFile tilesets = new ArrayFile(list_tilesets.ToArray()); ArrayFile tsa_array = new ArrayFile(list_tsa_array.ToArray()); ArrayFile tile_anim = new ArrayFile(list_tile_anim.ToArray()); Palette_ArrayBox.Load(palettes); Tileset1_ArrayBox.Load(tilesets); Tileset2_ArrayBox.Load(tilesets); TilesetTSA_ArrayBox.Load(tsa_array); TileAnim_ArrayBox.Load(tile_anim); Terrain_Name_MagicButton.EditorToOpen = "Text Editor"; } catch (Exception ex) { Program.ShowError("Could not properly open the " + this.Text, ex); Core_CloseEditor(this, null); } }
public string[][] GetTrackerString(ArrayFile notes) { const int subcolumns = 5; const int col_notes = 0; const int col_vol = 1; const int col_ins = 2; const int col_pan = 3; const int col_effects = 4; List <string[]> result = new List <string[]>(); byte length = 0; // used for all the time-tick relevant commands byte repeat = 0; // stores the last repeatable command byte note = 0; // stores the last note key played int index = 0; result.Add(new string[subcolumns]); for (int i = 0; i < Data.Length; i++) { if (Data[i] < 0x80) // repeat command { if (repeat >= 0xD0) // note-on command { if (result[index][col_notes] != null) { result[index][col_notes] += '\n'; } length = GetLength(repeat, false); result[index][col_notes] += notes[Data[i]]; note = Data[i]; if ((sbyte)Data[i + 1] >= 0) { result[index][col_notes] += ", " + Util.ByteToHex(Data[++i]); } if ((sbyte)Data[i + 1] >= 0) { length += Data[++i]; } for (int j = 0; j < length; j++) { result.Add(new string[subcolumns]); index++; } } else { switch (repeat) { case 0xBD: // Set Instrument (1-byte arg) result[index][col_ins] = Util.ByteToHex(Data[i]); break; case 0xBE: // Set Volume (1-byte arg) result[index][col_vol] = Util.ByteToHex(Data[i]); break; case 0xBF: // Set Panning (1-byte arg) result[index][col_pan] = Util.ByteToHex(Data[i]); break; case 0xC0: // Pitch bend value (1-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "pitch:" + (Data[i] - 0x40); break; case 0xC1: // Pitch bend semitones (1-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "slide:" + (Data[i] - 0x40); break; case 0xC4: // LFO Depth (1-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "lfo_depth:" + Data[i]; break; case 0xC8: // Detune (1-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "tuning:" + (Data[i] - 0x40); break; case 0xCD: // Echo (two 1-byte args) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } switch (Data[i]) { case 0x08: result[index][col_effects] += "echo_vol:" + Data[++i]; break; case 0x09: result[index][col_effects] += "echo_len:" + Data[++i]; break; default:; break; } break; case 0xCE: // Note Off (two optional args) if (result[index][col_notes] != null) { result[index][col_notes] += '\n'; } result[index][col_notes] += "___"; if ((sbyte)Data[i + 1] >= 0) { result[index][col_notes] += ", " + notes[Data[i]]; note = Data[i]; } if ((sbyte)Data[i + 1] >= 0) { result[index][col_notes] += ", " + Util.ByteToHex(Data[++i]); } break; case 0xCF: // Note On (two optional args) if (result[index][col_notes] != null) { result[index][col_notes] += '\n'; } if ((sbyte)Data[i + 1] >= 0) { result[index][col_notes] += notes[Data[i]]; note = Data[i]; } else { result[index][col_notes] += note; } if ((sbyte)Data[i + 1] >= 0) { result[index][col_notes] += ", " + Util.ByteToHex(Data[++i]); } break; default: throw new Exception("No repeatable command to execute."); } } } else if (Data[i] <= 0xB0) // wait command { length = GetLength(Data[i], true); for (int j = 0; j < length; j++) { result.Add(new string[subcolumns]); index++; } /* * if (length % ticks != 0) * { * if (result[index][col_effects] != null) * result[index][col_effects] += '\n'; * result[index][col_effects] += "timing:" + (length % ticks); * }*/ } else if (Data[i] >= 0xD0) // note-on command { repeat = Data[i]; if (result[index][col_notes] != null) { result[index][col_notes] += '\n'; } length = GetLength(Data[i], false); result[index][col_notes] += notes[Data[++i]]; note = Data[i]; if ((sbyte)Data[i + 1] >= 0) { result[index][col_notes] += ", " + Util.ByteToHex(Data[++i]); } if ((sbyte)Data[i + 1] >= 0) { length += Data[++i]; } for (int j = 0; j < length; j++) { result.Add(new string[subcolumns]); index++; } } else { switch (Data[i]) { case 0xB1: // End of track if (i != Data.Length - 1) { throw new Exception("There shouldn't be any data after an end of track command (0xB1)"); } if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "end"; break; case 0xB2: // Jump to address (4-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } if (i + 4 >= Data.Length) { result[index][col_effects] += "loop"; } else { result[index][col_effects] += "jump:" + GetAddress(Data.GetUInt32((uint)++i, true)); } i += 3; break; case 0xB3: // Call subsection (4-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } if (i + 4 >= Data.Length) { result[index][col_effects] += "call"; } else { result[index][col_effects] += "call:" + GetAddress(Data.GetUInt32((uint)++i, true)); } i += 3; break; case 0xB4: // End subsection if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "done"; break; case 0xB5: // Call and repeat subsection. (1-byte and 4-byte args) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "loop:" + Data[++i] + "*" + GetAddress(Data.GetUInt32((uint)++i, true)); i += 4; break; case 0xB9: // Conditional jump based on memory content (3 bytes..?) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "jump:" + Data[++i] + "*" + Data[++i] + "*" + Data[++i]; break; case 0xBA: // Set track priority (1-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "priority:" + Data[++i]; break; case 0xBB: // Set tempo (1-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "tempo:" + Data[++i]; break; case 0xBC: // Transpose (1 signed byte) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "transpose:" + (sbyte)Data[++i]; break; case 0xBD: // Set Instrument (1-byte arg) repeat = Data[i]; result[index][col_ins] = Util.ByteToHex(Data[++i]); break; case 0xBE: // Set Volume (1-byte arg) repeat = Data[i]; result[index][col_vol] = Util.ByteToHex(Data[++i]); break; case 0xBF: // Set Panning (1-byte arg) repeat = Data[i]; result[index][col_pan] = Util.ByteToHex(Data[++i]); break; case 0xC0: // Pitch bend value (1-byte arg) repeat = Data[i]; if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "pitch:" + (Data[++i] - 0x40); break; case 0xC1: // Pitch bend semitones (1-byte arg) repeat = Data[i]; if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "slide:" + (Data[++i] - 0x40); break; case 0xC2: // LFO Speed (1-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "lfo_speed:" + Data[++i]; break; case 0xC3: // LFO Delay (1-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "lfo_delay:" + Data[++i]; break; case 0xC4: // LFO Depth (1-byte arg) repeat = Data[i]; if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "lfo_depth:" + Data[++i]; break; case 0xC5: // LFO Type (1-byte arg) if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "lfo_type:" + Data[++i]; break; case 0xC8: // Detune (1-byte arg) repeat = Data[i]; if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } result[index][col_effects] += "detune:" + (Data[++i] - 0x40); break; case 0xCD: // Echo (two 1-byte args) repeat = Data[i]; if (result[index][col_effects] != null) { result[index][col_effects] += '\n'; } switch (Data[++i]) { case 0x08: result[index][col_effects] += "echo_vol:" + Data[++i]; break; case 0x09: result[index][col_effects] += "echo_len:" + Data[++i]; break; default:; break; } break; case 0xCE: // Note Off (two optional args) repeat = Data[i]; if (result[index][col_notes] != null) { result[index][col_notes] += '\n'; } result[index][col_notes] += "___"; if ((sbyte)Data[i + 1] >= 0) { result[index][col_notes] += ", " + notes[Data[++i]]; note = Data[i]; } if ((sbyte)Data[i + 1] >= 0) { result[index][col_notes] += ", " + Util.ByteToHex(Data[++i]); } break; case 0xCF: // Note On (two optional args) repeat = Data[i]; if (result[index][col_notes] != null) { result[index][col_notes] += '\n'; } if ((sbyte)Data[i + 1] >= 0) { result[index][col_notes] += notes[Data[++i]]; note = Data[i]; } else { result[index][col_notes] += note; } if ((sbyte)Data[i + 1] >= 0) { result[index][col_notes] += ", " + Util.ByteToHex(Data[++i]); } break; default: throw new Exception("Unsupported command: " + Util.ByteToHex(Data[i])); } } } return(result.ToArray()); }
static void LoadEventCode_ArrayDefinitionsForCommand(ref string code, string command, int arg_index, ArrayFile definitions, string prefix = "") { const string separators = " \t\r\n,[]"; string define; byte value; int index = 0; int line_length; int occurence; int length; while ((occurence = code.IndexOf(command + " ", index)) > 0) { index = occurence + command.Length + 1; line_length = code.IndexOf("\r\n", index) - occurence; if (line_length < 0) { line_length = code.Length - occurence; } for (int i = 1; i < arg_index; i++) { // iteratively parse through the event code string, along the command's arguments, to reach 'arg_index' index = IndexOfCharset(code, separators, index, line_length); if (index >= occurence + line_length) { break; } if (index < 0) { return; } index++; while (separators.Contains(code[index].ToString())) { index++; } } index = code.IndexOf("0x", index) + 2; if (index < 0) { continue; } length = 0; while (index + length < code.Length && Util.IsHexDigit(code[index + length])) { length++; } value = (byte)Util.HexToInt(code.Substring(index, length)); index -= 2; length += 2; define = ReplaceSpacesAndSpecialChars(definitions[value]); if (define.Length > 1) { code = code.Remove(index, length); code = code.Insert(index, prefix + define); } } }
public static void LoadEventCode_ArrayDefinitions(ref string code) { ArrayFile backgrounds = new ArrayFile("Dialog Background List.txt"); ArrayFile cutscenes = new ArrayFile("Cutscene Screen List.txt"); ArrayFile songs = new ArrayFile("Music List.txt"); ArrayFile chapters = new ArrayFile("Chapter List.txt"); ArrayFile characters = new ArrayFile("Character List.txt"); ArrayFile classes = new ArrayFile("Class List.txt"); ArrayFile items = new ArrayFile("Item List.txt"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "UNIT", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "UNIT", 2, classes); // "Class_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "UNIT", 8, items); // "Item_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "UNIT", 9, items); // "Item_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "UNIT", 10, items); // "Item_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "UNIT", 11, items); // "Item_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "MNCH", 1, chapters); // "Chapter_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "MNC2", 1, chapters); // "Chapter_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "MNC3", 1, chapters); // "Chapter_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "NEXTCH", 1, chapters); // "Chapter_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "NEXTCH_NOSAVE", 1, chapters); // "Chapter_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "NEXTCH_DUNGEON", 1, chapters); // "Chapter_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "LOMA", 1, chapters); // "Chapter_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "LOADMAP", 1, chapters); // "Chapter_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "LOEV", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "LOEV", 2, classes); // "Class_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "LOADUNIT", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "LOADUNIT", 2, classes); // "Class_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "MOVE", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "DISA", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "UNIT_DISSAPPEAR", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "REPA", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "UNIT_REAPPEAR", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "CAM1", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "CAM2", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "CHAR", 3, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "CHAR", 4, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "CHAR", 5, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "CHAR", 6, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "CURF", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "GOTO_IFCL", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "ITGC", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "ITGC", 2, items); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "ITGV", 1, items); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "ITGM", 1, items); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "GIVEITEM", 1, characters); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "GIVEITEM", 2, items); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "GIVEITEM_TOCURRENT", 1, items); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "GIVEITEM_TOMAIN", 1, items); // "Character_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "BACG", 1, backgrounds); // "BG_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "SHOWBG", 1, backgrounds); // "BG_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "SHCG", 1, cutscenes); // "Cutscene_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "SHOWCG", 1, cutscenes); // "Cutscene_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "TEXTCG", 2, cutscenes); // "Cutscene_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "MUSC", 1, songs); // "Music_"); LoadEventCode_ArrayDefinitionsForCommand(ref code, "PLAY", 1, songs); // "Music_"); }
static bool GetArrayData() { Console.WriteLine("Loading data from (1-5)."); Console.WriteLine("File: (1)"); Console.WriteLine("Console: (2)"); Console.WriteLine("Random array: (3)"); Console.WriteLine("Database (ADO.NET): (4)"); Console.WriteLine("Database (EF): (5)"); int key = ParseInteger(); switch (key) { case 0: return(false); case 1: { string filePath; while (!FileIsExist(out filePath)) { ; } _array = ArrayFile.GetArray(filePath); break; } case 2: { Console.WriteLine("Enter the integer values of the array"); Console.WriteLine("To finish, type any letter"); _array = ArrayConsole.GetArray(); break; } case 3: { Console.WriteLine("Enter count of numbers: "); int numCount = ParseInteger(); Console.WriteLine("Enter minimum number: "); int min = ParseInteger(); Console.WriteLine("Enter maximum number: "); int max = ParseInteger(); _array = ArrayRandom.GetArray(numCount, min, max); break; } case 4: { Console.WriteLine("Enter array ID: "); int id = ParseInteger(); _connection = new SqlConnection(ConfigurationManager.AppSettings.Get("ConnectionString")); ArrayADO ado = new ArrayADO(_connection); _array = ado.GetArray(id); _dbInsert = ado; _dbInsert.ArrayId = id; break; } case 5: { Console.WriteLine("Enter array ID: "); int id = ParseInteger(); ArrayEF ef = new ArrayEF(ConfigurationManager.AppSettings.Get("ConnectionString")); _array = ef.GetArray(id); _dbInsert = ef; _dbInsert.ArrayId = id; break; } } return(false); }
public virtual void SaveRaw(string fn) { var rawData = new ArrayFile<RgbSpectrum>(this.pixelData.Select(item => item.Weight.NearZero() ? RgbSpectrum.ZeroSpectrum() : item.Radiance / item.Weight).ToArray()); rawData.Save(fn + ".raw"); ImageFactory.FreeImageSaveExrBitmap(fn, Width, Height, this.pixelData.Select(item => item.Weight > 0f ? item.Radiance / item.Weight : RgbSpectrum.ZeroSpectrum()).ToArray()); //ImageFactory.FreeImageSaveExrBitmap(fn, Width, Height, this.frameBuffer.GetPixelData().ToSpectrumList().ToArray()); }
/// <summary> /// Loads command codes on ASCII-encoded FE game text, and returns the final string /// </summary> public static String BytesToText( byte[] data, bool bytecodes, ArrayFile commands_list, ArrayFile commands_0x80, ArrayFile portrait_list) { string result = ""; string command; for (int i = 0; i < data.Length; i++) { if (data[i] < 0x20) { command = commands_list[data[i]].Trim(' '); if (i != 0 && data[i] >= 0x08 && data[i] < 0x10) { result += "\r\n"; } if (data[i] == 0x10) { UInt16 index = Util.BytesToUInt16(new byte[2] { data[i + 1], data[i + 2] }, true); if (index < 0x100) { throw new Exception( "Invalid portrait index read in the text data" + " at byte " + i + ": " + Util.UInt32ToHex(index)); } if (bytecodes || command.Length == 0) { result += "[0x10:0x" + Util.UInt16ToHex(index) + ']'; } else { result += '[' + command + ':'; result += (index == 0xFFFF ? "Current" : portrait_list[(UInt16)(index - 0x100)]) + ']'; } i += 2; } else if (command == "\\n") { result += "\r\n"; } else if (bytecodes || command.Length == 0) { result += "[0x" + Util.ByteToHex(data[i]) + ']'; } else { result += '[' + command + ']'; } } else if (data[i] == 0x80) { i++; command = commands_0x80[data[i]].Trim(' '); if (bytecodes || command.Length == 0) { result += "[0x" + Util.ByteToHex(data[i]) + ']'; } else { result += '[' + command + ']'; } } else { if (Core.CurrentROM.Version == GameVersion.JAP) { byte[] buffer = System.Text.Encoding.Convert( System.Text.Encoding.GetEncoding(932), // Shift-JIS System.Text.Encoding.Unicode, data, i++, 2); //UInt16 symbol = data.GetUInt16((uint)i++, false); //Program.ShowMessage(Util.UInt16ToHex(symbol)); result += (char)(Util.BytesToNumber(buffer, true)); } else { result += (char)data[i]; } } } return(result); }
/// <summary> /// Takes text with command codes and returns the corresponding ASCII-encoded byte array /// </summary> public static byte[] TextToBytes(string text, ArrayFile commands_list, ArrayFile commands_0x80, ArrayFile portrait_list) { List <byte> result = new List <byte>(); for (int i = 0; i < text.Length; i++) { if (text[i] == '[') { i++; int length = 0; while (text[i + length] != ']') { length++; } string command = text.Substring(i, length); i += length; if (command.StartsWith(commands_list[0x10])) { // Load portrait command is pretty special string portrait = command.Substring(commands_list[0x10].Length + 1); result.Add(0x10); if (portrait.Equals("Current")) { result.AddRange(new byte[2] { 0xFF, 0xFF }); } else { uint index = portrait_list.FindEntry(portrait); if (index == 0xFFFFFFFF) { throw new Exception("Invalid portrait name: " + portrait); } result.AddRange(Util.UInt16ToBytes((UInt16)(index + 0x100), true)); } } else { uint index = commands_list.FindEntry(command); if (index == uint.MaxValue) { // so it's not a regular byte command index = commands_0x80.FindEntry(command); if (index == uint.MaxValue) { // it wasn't found in the command lists if (command.StartsWith("0x")) { result.Add(Util.HexToByte(command.Substring(2))); } else { throw new Exception("Invalid text command: [" + command + ']'); } } else { result.Add(0x80); result.Add((byte)index); } } else { result.Add((byte)index); } } } else if (text[i] == '\n' || (text[i] == '\r' && text[++i] == '\n')) { result.Add(0x01); } else { result.Add((byte)text[i]); } } return(result.ToArray()); }