Example #1
0
 public ChunkInfo(Range Addr = null, string Description = null)
 {
     if(string.IsNullOrEmpty(Description)) Description = "Data chunk";
     this.Description = Description;
     this.Addr = Addr;
 }
Example #2
0
        /// <summary>
        /// Validates the address range text boxes and creates a Range object
        /// </summary>
        /// <param name="Addr"></param>
        /// <returns></returns>
        private bool TryValidateInput(out Range Addr)
        {
            try
            {
                Addr = null;
                if (this.strip_txtStart.Text == string.Empty || this.strip_txtEnd.Text == string.Empty)
                {
                    Program.Alert("Start/End value is blank");
                    return false;
                }

                long start; int end;
                start = long.Parse(this.strip_txtStart.Text, System.Globalization.NumberStyles.HexNumber);
                end = int.Parse(this.strip_txtEnd.Text, System.Globalization.NumberStyles.HexNumber);

                // well duh start and end can be the same, happens when length = 1
                /*if (start == end)
                {
                    Program.Alert("Start and End are the same");
                    return false;
                }*/

                if (start > this.Image.Datastream.Length)
                {
                    Program.Alert("Start offset goes past end of image");
                    return false;
                }

                if (end > this.Image.Datastream.Length)
                {
                    Program.Alert((this.UseLength ? "Length" : "End offset") + " goes past end of image");
                    return false;
                }

                if (this.UseLength)
                {
                    if (end < 1)
                    {
                        Program.Alert("Length must be at least 1");
                        return false;
                    }
                    Addr = new Range(start, end);
                }
                else
                {
                    if (end < start)
                    {
                        Program.Alert("End offset cannot be before start offset");
                        return false;
                    }
                    Addr = new Range(start, (end - (int)start) + 1);
                }
                return true;
            }
            catch (FormatException)
            {
                Addr = null;
                Program.Alert("Invalid character(s) in address");
                return false;
            }
            catch (ArgumentException ex)
            {
                Addr = null;
                Program.Alert(ex.Message);
                return false;
            }
            catch (Exception ex)
            {
                Addr = null;
                Program.ExH.Extended(ex);
                return false;
            }
        }
Example #3
0
 public GfxChunkInfo(Range Addr = null, string Description = null)
 {
     if (Description == null) Description = string.Format("Graphics chunk");
     this.Description = Description;
     this.Addr = Addr;
     this.TilesPerRow = null;
     this.Subpalette = null;
 }
Example #4
0
 // Block of in-game text
 public TextChunkInfo(Range Addr = null, string Description = null)
 {
     this.UseTextTable = true;
     this.Addr = Addr;
     if (string.IsNullOrEmpty(Description)) Description = "Text chunk";
     this.Description = Description;
     this.Encoding = null;
     this.UseTextTable = null;
     this.TableID = null;
 }
Example #5
0
 public List<Range> Search_Sequence(byte[] Sequence, Range Addr)
 {
     return dumplib.Search.Sequence(GetBytes(Addr), Sequence);
 }
Example #6
0
 // Block of compiled code
 public CodeChunkInfo(Range Addr = null, string Description = null)
 {
     this.Addr = Addr;
     if (string.IsNullOrEmpty(Description)) Description = "Machine code chunk";
     this.Description = Description;
 }
Example #7
0
 /// <summary>
 /// Extracts a graphics tile from the Data buffer
 /// </summary>
 /// <param name="Addr">Chunk address of the tile data</param>
 /// <param name="Converter">Converter to use</param>
 /// <param name="Palette">Color palette to apply</param>
 /// <param name="TilesPerRow">Number of tiles to render per row in the final image</param>
 /// <returns>Bitmapped image of all tiles extracted</returns>
 public Bitmap GetTileGfx(Range Addr, ITileConverter Converter, ColorPalette Palette, int TilesPerRow)
 {
     return dumplib.Gfx.TileGfx.GetTiles(GetBytes(Addr), Converter, Palette, TilesPerRow);
 }
Example #8
0
 /// <summary>
 /// Performs a pattern search (aka relative search) on the specified chunk
 /// </summary>
 /// <param name="Pattern">Array of signed integers representing the variance between byte values</param>
 /// <param name="Addr">Chunk address to search</param>
 /// <returns></returns>
 public List<Range> Search_Pattern(int[] Pattern, Range Addr)
 {
     return dumplib.Search.Pattern(GetBytes(Addr), Pattern);
 }
Example #9
0
 /// <summary>
 /// Extracts a string of text from the Data buffer using SJIS (Japanese) encoding
 /// </summary>
 /// <param name="Addr">Chunk address of the text string</param>
 /// <returns>Unicode formatted string</returns>
 public string GetText_SJIS(Range Addr)
 {
     return dumplib.Text.Transcode.UsingSJIS(GetBytes(Addr));
 }
Example #10
0
 /// <summary>
 /// Extracts a string of text from the Data buffer using the specified text table
 /// </summary>
 /// <param name="Addr">Chunk address of the text string</param>
 /// <returns>Unicode formatted string</returns>
 public string GetText_Table(Range Addr, dumplib.Text.Table Table, uint StartOffset, string StartTable = "{main}")
 {
     return dumplib.Text.Transcode.UsingTable(GetBytes(Addr), Table, StartTable, true, StartOffset);
 }
Example #11
0
 /// <summary>
 /// Extracts a string of text from the Data buffer using the specified text encoding
 /// </summary>
 /// <param name="Addr">Chunk address of the text string</param>
 /// <param name="Encoding">Encoding of the source string</param>
 /// <returns>Unicode formatted string</returns>
 public string GetText_Encoding(Range Addr, Encoding Encoding)
 {
     return dumplib.Text.Transcode.UsingEncoding(GetBytes(Addr), Encoding);
 }
Example #12
0
 /// <summary>
 /// Extracts a string of text from the Data buffer using ASCII encoding
 /// </summary>
 /// <param name="Addr">Chunk address of the text string</param>
 /// <returns>Unicode formatted string</returns>
 public string GetText_ASCII(Range Addr)
 {
     return dumplib.Text.Transcode.UsingASCII(GetBytes(Addr));
 }
Example #13
0
 public DataChunk GetChunk(Range Addr)
 {
     return this.GetChunk(new ChunkInfo(Addr));
 }
Example #14
0
 /// <summary>
 /// Returns an array of bytes from the specified offset
 /// </summary>
 /// <param name="Addr">Chunk address</param>
 /// <returns></returns>
 public byte[] GetBytes(Range Addr)
 {
     return this.GetBytes(Addr.StartOffset, Addr.Length);
 }
Example #15
0
        private Layout.IChunkInfo ParseLine(string text)
        {
            // returns a ChunkEntry object from a line in the imp file

            // May 2014 - oh boy more uncommented code. At least this is relatively simple
            // time to rewrite and comment!

            // do some simple checks to make sure the line is valid
            if (!text.Contains("[") || !text.Contains("]") ||
                !(text.Contains("-") || text.Contains("+")) ||
                text.Length < 6)
                throw new FormatException("Entry not properly formatted");

            //get the text between the [] brackets, which should be the address and any arguments
            string offsets = dumplib.Text.Table.GetLabel(text);
            string[] args = null;

            // a comma delimits the address and all args, so if there's a comma in the text between []...
            if (offsets.Contains(","))
            {
                //... then split by args, set the first result to offsets and the rest to the args array
                string[] temp = offsets.Split(',');
                args = new string[temp.Length-1];
                offsets = temp[0];
                //Buffer.BlockCopy(temp, 1, args, 0, args.Length);
                Array.Copy(temp, 1, args, 0, args.Length);
            }

            // the offset string can have a - or + to delimit between the two numbers
            long first; int second;
            if (offsets.IndexOf('-') > 0)
            {
                string[] offsetsplit = offsets.Split('-');
                first = long.Parse(offsetsplit[0], System.Globalization.NumberStyles.HexNumber);
                second = int.Parse(offsetsplit[1], System.Globalization.NumberStyles.HexNumber);
                if (second < first) throw new ArgumentOutOfRangeException("Ending offset cannot be less than start offset");
                second = (second - (int)first) + 1;
            }
            else if (offsets.IndexOf('+') > 0)
            {
                string[] offsetsplit = offsets.Split('+');
                first = long.Parse(offsetsplit[0], System.Globalization.NumberStyles.HexNumber);
                second = int.Parse(offsetsplit[1], System.Globalization.NumberStyles.HexNumber);
                if (second < 1) throw new ArgumentOutOfRangeException("Length cannot be less than 1");
            }
            else throw new FormatException("Offsets incorrectly formatted");

            string desc = text.Substring(text.IndexOf(']') + 1);
            //if (!ChunkTypes.ContainsKey(text.Substring(0, 1).ToUpper())) throw new ArgumentException("Specified chunk type not found");
            object[] thisinfo = new object[2];
            thisinfo[0] = new Range(first, second);
            thisinfo[1] = desc;
            IChunkInfo _out = Activator.CreateInstance(chunktypes[text.Substring(0, 1).ToUpper()],thisinfo) as IChunkInfo;

            if(args != null && args.Length > 0) _out.ParseArgs(args);

            return _out;
        }